/* ========================================
   WhatsApp Agent Dashboard — Theme
   ======================================== */

:root {
  --wa-green: #25D366;
  --wa-dark: #075E54;
  --wa-darker: #054d44;
  --wa-teal: #128C7E;
  --wa-light-bg: #ECE5DD;
  --wa-chat-bg: #E5DDD5;
  --white: #FFFFFF;
  --text-dark: #111B21;
  --text-secondary: #667781;
  --text-light: #8696A0;
  --red-alert: #FF3B30;
  --blue-info: #007AFF;
  --green-success: #34C759;
  --orange-warning: #FF9500;
  --border: #E9EDEF;
  --bubble-out: #D9FDD3;
  --bubble-in: #FFFFFF;
  --bubble-human: #D4E4F7;
  --sidebar-width: 360px;
  --header-height: 56px;
  --nav-height: 48px;
  --bottom-nav-height: 56px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
  background: var(--wa-light-bg);
  color: var(--text-dark);
  font-size: 14px;
  min-height: 100vh;
}

body:has(.chats-container) {
  height: 100vh;
  overflow: hidden;
}

/* ---- SCROLLBAR ---- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }

/* ---- HEADER ---- */
.header {
  background: var(--wa-dark);
  color: white;
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
}

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

.header-title {
  font-size: 16px;
  font-weight: 600;
}

.bot-status {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.bot-status.on {
  background: rgba(37, 211, 102, 0.2);
  color: var(--wa-green);
}

.bot-status.off {
  background: rgba(255, 59, 48, 0.2);
  color: var(--red-alert);
}

.bot-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}

.bot-status.on .bot-status-dot { background: var(--wa-green); }
.bot-status.off .bot-status-dot { background: var(--red-alert); }

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

.header-badge {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  color: rgba(255,255,255,0.8);
  font-size: 13px;
}

.badge-count {
  background: var(--red-alert);
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.btn-logout {
  background: none;
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  padding: 5px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}

.btn-logout:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.5);
}

/* ---- NAV BAR ---- */
.nav-bar {
  background: white;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: var(--header-height);
  left: 0;
  right: 0;
  z-index: 99;
  overflow-x: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 16px;
  height: 100%;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.nav-item:hover {
  color: var(--wa-dark);
  background: rgba(0,0,0,0.02);
}

.nav-item.active {
  color: var(--wa-dark);
  border-bottom-color: var(--wa-dark);
  font-weight: 600;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

/* ---- MAIN CONTENT ---- */
.main-content {
  margin-top: calc(var(--header-height) + var(--nav-height));
  min-height: calc(100vh - var(--header-height) - var(--nav-height));
}

/* ---- LOGIN PAGE ---- */
.login-container {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background: linear-gradient(135deg, var(--wa-dark) 0%, var(--wa-teal) 100%);
}

.login-card {
  background: white;
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.15);
  text-align: center;
}

.login-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  background: var(--wa-green);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.login-logo svg {
  width: 36px;
  height: 36px;
  fill: white;
}

.login-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 4px;
  color: var(--text-dark);
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.login-input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  margin-bottom: 16px;
}

.login-input:focus {
  border-color: var(--wa-teal);
}

.login-error {
  color: var(--red-alert);
  font-size: 13px;
  margin-bottom: 12px;
  display: none;
}

/* ---- BUTTONS ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  text-decoration: none;
}

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

.btn-primary:hover { background: var(--wa-darker); }

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

.btn-green:hover { background: #1fba59; }

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

.btn-red:hover { background: #e0332a; }

.btn-outline {
  background: white;
  color: var(--text-dark);
  border: 1px solid var(--border);
}

.btn-outline:hover { background: #f5f5f5; }

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-full {
  width: 100%;
  padding: 12px;
  font-size: 15px;
  font-weight: 600;
}

/* ---- CHATS PAGE (Split Layout) ---- */
.chats-container {
  display: flex;
  height: calc(100vh - var(--header-height) - var(--nav-height));
}

.chat-list {
  width: var(--sidebar-width);
  border-right: 1px solid var(--border);
  background: white;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.chat-list-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-filters {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-chip {
  padding: 4px 10px;
  border-radius: 14px;
  font-size: 12px;
  cursor: pointer;
  border: 1px solid var(--border);
  background: white;
  color: var(--text-secondary);
  transition: all 0.2s;
  white-space: nowrap;
}

.filter-chip:hover,
.filter-chip.active {
  background: var(--wa-dark);
  color: white;
  border-color: var(--wa-dark);
}

.chat-search {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  outline: none;
  background: #F0F2F5;
}

.chat-search:focus {
  background: white;
  border-color: var(--wa-teal);
}

.chat-list-items {
  flex: 1;
  overflow-y: auto;
}

.chat-item {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  gap: 12px;
  cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  transition: background 0.15s;
  position: relative;
}

.chat-item:hover { background: #F5F6F6; }
.chat-item.active { background: #F0F2F5; }

.chat-item.has-unreplied { border-left: 3px solid var(--red-alert); }
.chat-item.has-complaint { border-left: 3px solid var(--orange-warning); }

.chat-avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--wa-teal);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  flex-shrink: 0;
}

.chat-item-info {
  flex: 1;
  min-width: 0;
}

.chat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2px;
}

.chat-item-name {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
  min-width: 0;
  flex: 1;
  margin-right: 8px;
}

.chat-item-time {
  font-size: 11px;
  color: var(--text-light);
  white-space: nowrap;
}

.chat-item-preview {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status-icon {
  font-size: 12px;
}

.chat-item-labels {
  display: flex;
  gap: 4px;
  margin-top: 2px;
}

.label-badge {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
  flex-shrink: 0;
}

.label-complaint {
  background: #FFF3CD;
  color: #856404;
}

.label-unreplied {
  background: #F8D7DA;
  color: #721C24;
}

.label-order {
  background: #D4EDDA;
  color: #155724;
}

.label-spam {
  background: #E2E3E5;
  color: #6C757D;
}

.label-human {
  background: #D4E4F7;
  color: #1a4a7a;
}

.label-cancel {
  background: #F8D7DA;
  color: #DC3545;
  font-weight: 600;
}

.unread-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--wa-green);
  flex-shrink: 0;
}

/* ---- CHAT VIEW (Right Panel) ---- */
.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--wa-chat-bg);
  position: relative;
}

.chat-view-empty {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 12px;
  color: var(--text-secondary);
}

.chat-view-empty svg {
  width: 80px;
  height: 80px;
  opacity: 0.3;
}

.chat-view-header {
  background: white;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  min-height: 56px;
}

.chat-view-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-view-name {
  font-weight: 600;
  font-size: 15px;
}

.chat-view-meta {
  font-size: 12px;
  color: var(--text-secondary);
}

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

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.msg-bubble {
  max-width: 65%;
  padding: 6px 12px 4px;
  border-radius: 8px;
  font-size: 14px;
  line-height: 1.4;
  position: relative;
  word-wrap: break-word;
}

.msg-incoming {
  align-self: flex-start;
  background: var(--bubble-in);
  border-top-left-radius: 0;
}

.msg-outgoing {
  align-self: flex-end;
  background: var(--bubble-out);
  border-top-right-radius: 0;
}

.msg-outgoing.human {
  background: var(--bubble-human);
}

.msg-sender {
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 2px;
}

.msg-sender.bot-sender { color: var(--wa-teal); }
.msg-sender.human-sender { color: var(--blue-info); }
.msg-sender.customer-sender { color: #E67E22; }

.msg-source-badge {
  display: inline-block;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 4px;
  border-radius: 3px;
  margin-left: 5px;
  vertical-align: middle;
  line-height: 1;
}
.msg-source-badge.src-tpl { background: #E8F5E9; color: #2E7D32; }
.msg-source-badge.src-ai { background: #E3F2FD; color: #1565C0; }

.ai-cost-badge {
  display: inline-block;
  font-size: 8px;
  font-weight: 600;
  padding: 1px 3px;
  border-radius: 3px;
  margin-left: 2px;
  vertical-align: middle;
  line-height: 1;
  background: #FFF3E0;
  color: #E65100;
}

.chat-ai-cost {
  font-size: 11px;
  font-weight: 600;
  color: #E65100;
  margin-top: 1px;
}

.msg-time {
  font-size: 11px;
  color: var(--text-light);
  text-align: right;
  margin-top: 2px;
}

/* Feedback on bot messages */
.msg-feedback-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
  margin-top: 2px;
}

.msg-feedback-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  padding: 2px;
  border-radius: 3px;
  display: flex;
  align-items: center;
  opacity: 0.4;
  transition: all 0.15s;
}

.msg-bubble:hover .msg-feedback-btn { opacity: 1; }
.msg-feedback-btn:hover { color: var(--orange-warning); background: rgba(255,149,0,0.1); }
.msg-feedback-btn.has-feedback { opacity: 1; color: var(--orange-warning); }

.msg-feedback-text {
  background: #FFF3E0;
  color: #E65100;
  font-size: 11px;
  padding: 4px 8px;
  border-radius: 4px;
  margin-top: 4px;
  line-height: 1.3;
  border-left: 3px solid var(--orange-warning);
}

.msg-feedback-form {
  margin-top: 4px;
}

.msg-feedback-form textarea {
  width: 100%;
  min-height: 40px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 12px;
  resize: vertical;
  outline: none;
  font-family: inherit;
}

.msg-feedback-form textarea:focus { border-color: var(--orange-warning); }

.msg-feedback-actions {
  display: flex;
  gap: 4px;
  margin-top: 4px;
  justify-content: flex-end;
}

.fb-save-btn {
  background: var(--orange-warning);
  color: white;
  border: none;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  font-weight: 600;
}

.fb-save-btn:hover { background: #e68600; }

.fb-cancel-btn {
  background: none;
  border: 1px solid var(--border);
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  color: var(--text-secondary);
}

.fb-cancel-btn:hover { background: #f5f5f5; }

/* WhatsApp-style ticks */
.msg-ticks {
  display: block;
  text-align: right;
  font-size: 12px;
  margin-top: 2px;
  line-height: 1;
}
.msg-ticks.sent { color: #8696A0; }
.msg-ticks.delivered { color: #8696A0; }
.msg-ticks.read { color: #53BDEB; }

/* Chat Input */
.chat-input-area {
  background: white;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-input-area.disabled {
  opacity: 0.6;
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  outline: none;
  background: #F0F2F5;
}

.chat-input:focus { background: white; border-color: var(--wa-teal); }

.chat-input-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
  background: none;
  color: var(--text-secondary);
}

.chat-input-btn:hover { background: #f0f0f0; }

.chat-send-btn {
  background: var(--wa-green);
  color: white;
}

.chat-send-btn:hover { background: #1fba59; }

/* ---- TABLES (Customers, Orders) ---- */
.page-container {
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

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

.page-title {
  font-size: 20px;
  font-weight: 700;
}

.filter-bar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
  align-items: center;
}

.filter-select {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: white;
  outline: none;
  cursor: pointer;
}

.filter-search {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: white;
  outline: none;
  min-width: 200px;
}

.filter-search:focus,
.filter-select:focus {
  border-color: var(--wa-teal);
}

.data-table {
  width: 100%;
  background: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.data-table table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  background: #F8F9FA;
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 10px 14px;
  border-bottom: 1px solid #f5f5f5;
  font-size: 13px;
}

.data-table tr:hover td {
  background: #FAFAFA;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.table-footer {
  padding: 12px 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
  background: white;
  border-radius: 0 0 8px 8px;
}

/* Status badges */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}

.status-confirmed { background: #FFF3CD; color: #856404; }
.status-shipped { background: #CCE5FF; color: #004085; }
.status-delivered { background: #D4EDDA; color: #155724; }
.status-cancelled { background: #F8D7DA; color: #721C24; }

.sync-icon { font-size: 14px; }
.sync-ok { color: var(--green-success); }
.sync-fail { color: var(--red-alert); }

/* ---- STAT CARDS ---- */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.stat-card-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-dark);
}

.stat-card-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.stat-card-trend {
  font-size: 12px;
  margin-top: 6px;
  font-weight: 500;
}

.trend-up { color: var(--green-success); }
.trend-down { color: var(--red-alert); }

/* Chart container */
.chart-container {
  background: white;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  margin-bottom: 24px;
}

.chart-title {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 16px;
}

/* ---- PRODUCT CARDS ---- */
.product-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.product-card {
  background: white;
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  display: flex;
  gap: 16px;
  align-items: flex-start;
}

.product-img {
  width: 80px;
  height: 80px;
  border-radius: 8px;
  background: #F0F2F5;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  font-size: 12px;
  flex-shrink: 0;
}

.product-info {
  flex: 1;
}

.product-name {
  font-weight: 600;
  font-size: 15px;
  margin-bottom: 4px;
}

.product-meta {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 8px;
}

.product-actions {
  display: flex;
  gap: 6px;
}

/* ---- SETTINGS SECTIONS ---- */
.settings-grid {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.settings-section {
  background: white;
  border-radius: 10px;
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.settings-section-title {
  font-size: 15px;
  font-weight: 700;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
}

.settings-row + .settings-row {
  border-top: 1px solid #f5f5f5;
}

.settings-label {
  font-size: 14px;
  font-weight: 500;
}

.settings-desc {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

.settings-input {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  min-width: 200px;
}

.settings-input:focus { border-color: var(--wa-teal); }

.settings-input-wide {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  margin-top: 6px;
  font-family: monospace;
}

.settings-input-wide:focus { border-color: var(--wa-teal); }

/* Toggle Switch */
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  cursor: pointer;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #ccc;
  border-radius: 24px;
  transition: 0.2s;
}

.toggle-slider:before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--wa-green);
}

.toggle input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

/* Danger zone */
.danger-zone {
  border: 1px solid var(--red-alert);
  border-radius: 10px;
  padding: 20px;
  background: #FFF5F5;
}

.danger-zone .settings-section-title {
  color: var(--red-alert);
}

/* ---- API KEY INPUT GROUP ---- */
.api-key-group {
  margin-bottom: 12px;
}

.api-key-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 4px;
}

.api-key-group .api-key-hint {
  font-size: 11px;
  color: var(--text-light);
  margin-bottom: 4px;
}

.api-key-input-wrap {
  display: flex;
  gap: 6px;
}

.api-key-input-wrap input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: monospace;
  outline: none;
}

.api-key-input-wrap input:focus { border-color: var(--wa-teal); }

.api-key-saved {
  color: var(--green-success);
  font-size: 12px;
  margin-top: 4px;
  display: none;
}

/* ---- FOLLOW-UP MANAGER ---- */
.followup-step {
  background: #F8F9FA;
  border-radius: 8px;
  padding: 14px;
  margin-bottom: 10px;
}

.followup-step-title {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 8px;
}

.followup-step textarea {
  width: 100%;
  min-height: 60px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  resize: vertical;
  outline: none;
}

.followup-step textarea:focus { border-color: var(--wa-teal); }

.followup-row {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-top: 8px;
}

/* ---- TEST CHAT ---- */
.test-chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - var(--header-height) - var(--nav-height));
  background: var(--wa-chat-bg);
}

.test-chat-header {
  background: white;
  padding: 10px 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 8px;
}

.test-chat-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.test-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.test-chat-input-area {
  background: white;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
}

.test-chat-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.quick-messages {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding: 8px 0 0;
}

.quick-msg-btn {
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 12px;
  cursor: pointer;
  background: white;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.quick-msg-btn:hover {
  background: var(--wa-dark);
  color: white;
  border-color: var(--wa-dark);
}

/* Debug panel */
.debug-panel {
  background: #1E1E1E;
  color: #D4D4D4;
  padding: 12px 16px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12px;
  max-height: 120px;
  overflow-y: auto;
  border-top: 2px solid var(--wa-dark);
}

.debug-panel .debug-label {
  color: #569CD6;
}

.debug-panel .debug-value {
  color: #CE9178;
}

.debug-panel .debug-ok {
  color: var(--wa-green);
}

/* ---- MODALS ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  display: none;
}

.modal-overlay.show { display: flex; }

.modal {
  background: white;
  border-radius: 12px;
  width: 90%;
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 16px;
}

/* ---- MOBILE RESPONSIVE ---- */
@media (max-width: 768px) {
  :root {
    --sidebar-width: 100%;
  }

  .nav-bar { display: none; }

  .main-content {
    margin-top: var(--header-height);
    margin-bottom: var(--bottom-nav-height);
  }

  /* Mobile bottom nav */
  .mobile-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--bottom-nav-height);
    background: white;
    border-top: 1px solid var(--border);
    z-index: 100;
  }

  .mobile-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 10px;
  }

  .mobile-nav-item.active {
    color: var(--wa-dark);
  }

  .mobile-nav-item svg {
    width: 22px;
    height: 22px;
  }

  /* Chat split → full width */
  .chats-container {
    flex-direction: column;
  }

  .chat-list {
    width: 100%;
    height: 100%;
  }

  .chat-view {
    position: fixed;
    inset: 0;
    top: var(--header-height);
    z-index: 98;
    display: none;
  }

  .chat-view.show { display: flex; }

  .chat-view-back {
    display: flex;
  }

  /* Stat cards */
  .stat-cards {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Tables → cards */
  .data-table { overflow-x: auto; }

  .header-title { font-size: 13px; }

  .header {
    padding: 0 10px;
    gap: 6px;
    flex-wrap: wrap;
    height: auto;
    min-height: var(--header-height);
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .header-left { gap: 8px; }

  .header-right {
    gap: 6px;
  }

  .header-badge span:first-child {
    display: none;
  }

  .badge-count {
    font-size: 10px;
    padding: 1px 5px;
  }

  .bot-status {
    padding: 3px 8px;
    font-size: 11px;
  }

  .btn-logout {
    padding: 4px 8px;
    font-size: 11px;
  }

  .page-container { padding: 12px; }

  .filter-bar { flex-direction: column; }
  .filter-search { min-width: 100%; }

  /* Chat filters scrollable on mobile */
  .chat-filters {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }

  .chat-filters::-webkit-scrollbar { display: none; }
}

@media (min-width: 769px) {
  .mobile-nav { display: none; }
  .chat-view-back { display: none; }
}

/* ---- PAGE CONTENT (non-chat pages) ---- */
.main-content:not(:has(.chats-container)):not(:has(.test-chat-container)) {
  padding: 16px;
  max-width: 1200px;
  margin-left: auto;
  margin-right: auto;
}

.page-header h2 {
  font-size: 20px;
  font-weight: 700;
}

/* Table container */
.table-container {
  background: white;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
  overflow-x: auto;
}

.table-container table {
  width: 100%;
  border-collapse: collapse;
}

.table-container th {
  background: #F8F9FA;
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table-container td {
  padding: 10px 14px;
  border-bottom: 1px solid #f5f5f5;
  font-size: 13px;
}

.table-container tr:hover td { background: #FAFAFA; }
.table-container tr:last-child td { border-bottom: none; }

.table-footer {
  padding: 12px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  background: white;
  border-radius: 0 0 10px 10px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* Order filters row */
.order-filters {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.order-filters select {
  padding: 7px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  background: white;
  outline: none;
  cursor: pointer;
}

.order-filters select:focus { border-color: var(--wa-teal); }

/* ---- STAT CARDS (extended) ---- */
.stat-value {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-dark);
}

.stat-label {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ---- PRODUCTS GRID ---- */
.products-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* ---- SETTINGS EXTRAS ---- */
.settings-group-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--wa-dark);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}

.settings-row label {
  font-size: 14px;
  color: var(--text-dark);
}

.settings-row input[type="number"] {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  outline: none;
  text-align: center;
}

.settings-row input[type="number"]:focus { border-color: var(--wa-teal); }

.settings-textarea {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  resize: vertical;
  outline: none;
  font-family: inherit;
}

.settings-textarea:focus { border-color: var(--wa-teal); }

/* API key input row */
.api-key-input {
  display: flex;
  gap: 6px;
}

.api-key-input input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: monospace;
  outline: none;
}

.api-key-input input:focus { border-color: var(--wa-teal); }

/* ---- FOLLOW-UP STEP ---- */
.followup-step-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.followup-step-footer {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-top: 8px;
}

.followup-step-footer label {
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.followup-step-footer select {
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
}

/* ---- TEST CHAT EXTRAS ---- */
.test-quick-messages {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  padding-top: 8px;
}

.test-debug-panel {
  background: #1E1E1E;
  border-top: 2px solid var(--wa-dark);
}

.test-debug-toggle {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 16px;
  cursor: pointer;
  color: #D4D4D4;
  font-size: 12px;
  font-weight: 600;
}

.test-debug-toggle svg { color: #D4D4D4; }

.test-debug-content {
  padding: 0 16px 12px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 12px;
}

.debug-row {
  display: flex;
  gap: 8px;
  padding: 3px 0;
}

.debug-label {
  color: #569CD6;
  min-width: 110px;
}

.debug-value {
  color: #CE9178;
  word-break: break-all;
}

/* ---- MOBILE — non-chat pages ---- */
@media (max-width: 768px) {
  .main-content:not(:has(.chats-container)):not(:has(.test-chat-container)) {
    padding: 12px;
    margin-top: var(--header-height);
  }

  .page-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }

  .order-filters {
    width: 100%;
  }

  .order-filters select,
  .order-filters .chat-search {
    flex: 1;
    min-width: 0;
  }

  .settings-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .api-key-input {
    width: 100%;
  }

  .test-chat-container {
    height: calc(100vh - var(--header-height) - var(--bottom-nav-height));
  }
}

/* ---- UTILITY ---- */
.hidden { display: none !important; }
.text-center { text-align: center; }
.text-muted { color: var(--text-secondary); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.flex { display: flex; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.flex-1 { flex: 1; }
.font-mono { font-family: monospace; }
