/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #25d366;
  --primary-dark: #1ea952;
  --secondary: #128c7e;
  --danger: #dc3545;
  --warning: #ffc107;
  --light: #f0f2f5;
  --dark: #111b21;
  --text: #54656f;
  --text-dark: #202c33;
  --border: #e9edef;
  --white: #ffffff;
  --shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.15);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  background: var(--light);
  color: var(--text-dark);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.header {
  background: var(--white);
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 20px 0;
}

.header-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
}

.header h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text-dark);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-info {
  background: var(--light);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
}

/* Main Content */
.main-content {
  padding: 40px 0;
  min-height: calc(100vh - 84px);
}

/* Sessions Grid */
.sessions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 24px;
}

.session-card {
  background: var(--white);
  border-radius: 12px;
  padding: 24px;
  box-shadow: var(--shadow);
  transition: all 0.3s ease;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.session-card:hover {
  box-shadow: var(--shadow-lg);
  transform: translateY(-4px);
}

.session-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.session-name {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 4px;
}

.session-phone {
  font-size: 14px;
  color: var(--text);
}

.status-badge {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  text-transform: uppercase;
}

.status-badge.connected {
  background: #d1f4e0;
  color: #0a8754;
}

.status-badge.qr_ready {
  background: #fff3cd;
  color: #997404;
}

.status-badge.disconnected {
  background: #f8d7da;
  color: #721c24;
}

.session-info {
  display: flex;
  gap: 16px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.info-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text);
}

.info-icon {
  font-size: 18px;
}

/* Empty State */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 80px 20px;
}

.empty-icon {
  font-size: 80px;
  margin-bottom: 20px;
  opacity: 0.5;
}

.empty-state h2 {
  font-size: 24px;
  color: var(--text-dark);
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 16px;
  color: var(--text);
  margin-bottom: 24px;
}

.empty-state-small {
  text-align: center;
  padding: 40px 20px;
  color: var(--text);
}

/* Buttons */
.btn {
  padding: 12px 24px;
  border: none;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.btn-secondary {
  background: var(--light);
  color: var(--text-dark);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover {
  background: #c82333;
}

.btn-small {
  padding: 8px 16px;
  font-size: 14px;
}

/* Modal */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  justify-content: center;
  align-items: center;
  animation: fadeIn 0.2s ease;
}

.modal.show {
  display: flex;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.modal-content {
  background: var(--white);
  border-radius: 16px;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.3s ease;
}

.modal-large {
  max-width: 900px;
}

@keyframes slideUp {
  from {
    transform: translateY(50px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  padding: 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h2 {
  font-size: 20px;
  font-weight: 600;
  color: var(--text-dark);
}

.close-btn {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: var(--text);
  padding: 4px 8px;
  transition: color 0.2s;
}

.close-btn:hover {
  color: var(--text-dark);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

.modal-footer {
  padding: 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* Form */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: 500;
  color: var(--text-dark);
}

.form-input {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  transition: border-color 0.2s;
  font-family: inherit;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
}

.form-group small {
  display: block;
  margin-top: 4px;
  font-size: 13px;
  color: var(--text);
}

.help-text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.5;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}

.tab-btn {
  padding: 12px 20px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--text);
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  margin-bottom: -2px;
}

.tab-btn:hover {
  color: var(--primary);
}

.tab-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

.tab-header {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

/* QR Code */
.qr-container {
  display: flex;
  gap: 32px;
  align-items: flex-start;
}

.qr-display {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 300px;
  background: var(--light);
  border-radius: 12px;
  padding: 20px;
}

.qr-display img {
  max-width: 100%;
  border-radius: 8px;
}

.qr-info {
  flex: 1;
  padding: 20px;
  background: var(--light);
  border-radius: 12px;
}

.qr-info h3 {
  font-size: 18px;
  margin-bottom: 16px;
  color: var(--text-dark);
}

.qr-info ol {
  padding-left: 20px;
}

.qr-info li {
  margin-bottom: 12px;
  color: var(--text);
}

/* Loading */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--text);
}

.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Messages List */
.messages-list {
  max-height: 500px;
  overflow-y: auto;
  background: var(--light);
  border-radius: 12px;
  padding: 16px;
}

.message-item {
  background: var(--white);
  padding: 16px;
  margin-bottom: 12px;
  border-radius: 8px;
  border-left: 4px solid var(--primary);
}

.message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.message-from {
  font-weight: 600;
  color: var(--text-dark);
}

.message-time {
  font-size: 12px;
  color: var(--text);
}

.message-body {
  color: var(--text-dark);
  line-height: 1.5;
  word-wrap: break-word;
}

.message-meta {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text);
}

/* Chats List */
.chats-list {
  max-height: 500px;
  overflow-y: auto;
}

.chat-item {
  background: var(--white);
  padding: 16px;
  margin-bottom: 12px;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border: 2px solid transparent;
}

.chat-item:hover {
  background: var(--light);
  transform: translateX(4px);
  border-color: var(--primary);
}

.chat-info {
  flex: 1;
}

.chat-name {
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 4px;
}

.chat-type {
  font-size: 13px;
  color: var(--text);
}

.unread-badge {
  background: var(--primary);
  color: white;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

/* Chat Messages */
.chat-messages {
  margin-top: 16px;
}

.chat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 2px solid var(--border);
}

.chat-header h3 {
  color: var(--text-dark);
  font-size: 18px;
  margin: 0;
}

.chat-actions {
  display: flex;
  gap: 8px;
}

/* Message Item Styles for Chat */
.chat-messages .message-item {
  background: var(--white);
  padding: 16px;
  margin-bottom: 12px;
  border-radius: 8px;
  border-left: 4px solid var(--primary);
  position: relative;
}

.chat-messages .message-item.from-me {
  border-left-color: var(--primary);
  background: #f0f8ff;
}

.chat-messages .message-item.from-other {
  border-left-color: #6c757d;
}

.chat-messages .message-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.chat-messages .message-from {
  font-weight: 600;
  color: var(--text-dark);
}

.chat-messages .message-time {
  font-size: 12px;
  color: var(--text);
}

.chat-messages .message-body {
  color: var(--text-dark);
  line-height: 1.5;
  word-wrap: break-word;
}

.chat-messages .message-meta {
  display: flex;
  gap: 12px;
  margin-top: 8px;
  font-size: 12px;
  color: var(--text);
}

/* Send Message Form */
.send-message-form {
  max-width: 600px;
}

.send-result {
  margin-top: 16px;
  padding: 12px;
  border-radius: 8px;
}

.send-result.success {
  background: #d1f4e0;
  color: #0a8754;
  border: 1px solid #a3e7c1;
}

.send-result.error {
  background: #f8d7da;
  color: #721c24;
  border: 1px solid #f5c6cb;
}

/* Button disabled state */
.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none !important;
}

.btn:disabled:hover {
  transform: none !important;
  box-shadow: none !important;
}

/* Load More Container */
.load-more-container {
  text-align: center;
  padding: 20px;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}

.load-more-container .btn {
  min-width: 200px;
}

/* Loading State for Load More */
.load-more-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 16px;
  color: var(--text);
}

.load-more-loading .spinner {
  width: 20px;
  height: 20px;
}

/* Message Count Info */
.message-count-info {
  background: var(--light);
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--text);
  margin-bottom: 16px;
  text-align: center;
}

/* Scroll to Top Button */
.scroll-to-top {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 50%;
  width: 50px;
  height: 50px;
  font-size: 20px;
  cursor: pointer;
  box-shadow: var(--shadow-lg);
  transition: all 0.3s ease;
  z-index: 1000;
}

.scroll-to-top:hover {
  background: var(--primary-dark);
  transform: scale(1.1);
}

.scroll-to-top.hidden {
  opacity: 0;
  pointer-events: none;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 16px 24px;
  background: var(--text-dark);
  color: white;
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 2000;
  max-width: 400px;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success {
  background: var(--primary);
}

.toast.error {
  background: var(--danger);
}

/* Responsive */
@media (max-width: 768px) {
  .header h1 {
    font-size: 18px;
  }

  .sessions-grid {
    grid-template-columns: 1fr;
  }

  .qr-container {
    flex-direction: column;
  }

  .modal-content {
    width: 95%;
    max-height: 95vh;
  }

  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tab-btn {
    white-space: nowrap;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: var(--light);
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text);
}

