/* ─── BASE ─── */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --ink: #0a0a0a;
  --paper: #fafaf9;
  --accent: #16a34a;
  --accent-hover: #15803d;
  --accent-light: #dcfce7;
  --accent-lighter: #f0fdf4;
  --muted: #78716c;
  --muted-light: #a8a29e;
  --border: #e7e5e4;
  --border-dark: #d6d3d1;
  --glow: rgba(22, 163, 74, 0.08);
  --danger: #ef4444;
  --danger-light: #fef2f2;
  --warning: #f59e0b;
  --warning-light: #fffbeb;
  --info: #3b82f6;
  --info-light: #eff6ff;
  --sidebar-w: 240px;
}
body {
  font-family: 'DM Sans', sans-serif;
  background: var(--paper);
  color: var(--ink);
  line-height: 1.6;
}
h1, h2, h3, h4 { font-family: 'Space Grotesk', sans-serif; line-height: 1.2; }

/* ─── AUTH PAGES ─── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper);
}
.auth-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 3rem;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.04);
}
.auth-card .logo {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.5rem;
  text-align: center;
  margin-bottom: 0.5rem;
}
.auth-card .logo-dot { color: var(--accent); }
.auth-card .subtitle {
  text-align: center;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 2rem;
}
.auth-card h2 {
  font-size: 1.3rem;
  margin-bottom: 1.5rem;
  text-align: center;
}

/* ─── FORMS ─── */
.form-group {
  margin-bottom: 1rem;
}
.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
  color: var(--ink);
}
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: 'DM Sans', sans-serif;
  background: white;
  transition: border-color 0.15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--glow);
}
.form-group textarea { resize: vertical; min-height: 80px; }
.form-group .hint {
  font-size: 0.78rem;
  color: var(--muted);
  margin-top: 0.25rem;
}

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.25rem;
  border: none;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  font-family: 'DM Sans', sans-serif;
  cursor: pointer;
  transition: all 0.15s;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary {
  background: white;
  color: var(--ink);
  border: 1px solid var(--border);
}
.btn-secondary:hover { border-color: var(--border-dark); background: var(--paper); }
.btn-danger {
  background: var(--danger-light);
  color: var(--danger);
  border: 1px solid #fecaca;
}
.btn-danger:hover { background: #fee2e2; }
.btn-sm { padding: 0.4rem 0.75rem; font-size: 0.82rem; }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── LAYOUT ─── */
.app-layout {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: var(--sidebar-w);
  background: white;
  border-right: 1px solid var(--border);
  padding: 1.5rem 0;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  overflow-y: auto;
  z-index: 100;
}
.sidebar .logo {
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 700;
  font-size: 1.3rem;
  padding: 0 1.5rem;
  margin-bottom: 2rem;
}
.sidebar .logo-dot { color: var(--accent); }
.sidebar-nav { list-style: none; }
.sidebar-nav li { margin-bottom: 2px; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 1.5rem;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  transition: all 0.15s;
  border-left: 3px solid transparent;
}
.sidebar-nav a:hover { color: var(--ink); background: var(--paper); }
.sidebar-nav a.active {
  color: var(--accent);
  background: var(--accent-lighter);
  border-left-color: var(--accent);
}
.sidebar-nav .nav-icon { font-size: 1.1rem; width: 20px; text-align: center; }
.sidebar-bottom {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
}
.sidebar-bottom .user-email {
  font-size: 0.78rem;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 0.5rem;
}

.main-content {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 2rem;
  max-width: calc(100% - var(--sidebar-w));
}
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 2rem;
}
.page-header h1 { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.5px; }

/* ─── STAT CARDS ─── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 2rem;
}
.stat-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  transition: box-shadow 0.2s;
}
.stat-card:hover { box-shadow: 0 4px 20px var(--glow); }
.stat-card .stat-label {
  font-size: 0.78rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
  margin-bottom: 0.25rem;
}
.stat-card .stat-value {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--ink);
}
.stat-card .stat-value.green { color: var(--accent); }
.stat-card .stat-value.orange { color: var(--warning); }
.stat-card .stat-value.red { color: var(--danger); }
.stat-card .stat-value.blue { color: var(--info); }

/* ─── CARDS / PANELS ─── */
.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.card-header h3 { font-size: 1rem; font-weight: 600; }

/* ─── TABLE ─── */
.table-wrapper { overflow-x: auto; }
table {
  width: 100%;
  border-collapse: collapse;
}
th {
  text-align: left;
  padding: 0.6rem 0.75rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  font-weight: 600;
  border-bottom: 1px solid var(--border);
}
td {
  padding: 0.75rem;
  font-size: 0.88rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
tr:hover td { background: var(--paper); }
tr.clickable { cursor: pointer; }

/* ─── BADGES ─── */
.badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 6px;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.badge-faq { background: #dbeafe; color: #1d4ed8; }
.badge-shipping { background: #fef3c7; color: #92400e; }
.badge-returns { background: #fce7f3; color: #9d174d; }
.badge-billing { background: #ede9fe; color: #6d28d9; }
.badge-complaint { background: #fee2e2; color: #b91c1c; }
.badge-partnership { background: #dcfce7; color: #166534; }
.badge-spam { background: #f5f5f4; color: #78716c; }
.badge-escalation { background: #fee2e2; color: #dc2626; }
.badge-general { background: #f5f5f4; color: #57534e; }
.badge-uncategorized { background: #f5f5f4; color: #78716c; }

.badge-status-pending { background: #fef3c7; color: #92400e; }
.badge-status-auto_responded { background: #dcfce7; color: #166534; }
.badge-status-flagged { background: #fee2e2; color: #dc2626; }
.badge-status-manual_response { background: #dbeafe; color: #1d4ed8; }
.badge-status-ignored { background: #f5f5f4; color: #78716c; }
.badge-status-archived { background: #f5f5f4; color: #57534e; }

/* ─── FILTERS ─── */
.filters {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.filter-btn {
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  font-size: 0.82rem;
  font-family: 'DM Sans', sans-serif;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.filter-btn:hover { border-color: var(--accent); color: var(--accent); }
.filter-btn.active { background: var(--accent); color: white; border-color: var(--accent); }

/* ─── EMAIL DETAIL ─── */
.email-detail {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
}
.email-detail .email-header {
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.email-detail .email-from {
  font-weight: 600;
  font-size: 0.95rem;
}
.email-detail .email-meta {
  font-size: 0.82rem;
  color: var(--muted);
  margin-top: 0.25rem;
}
.email-detail .email-subject {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0.75rem 0;
}
.email-detail .email-body {
  font-size: 0.9rem;
  line-height: 1.7;
  color: #44403c;
  white-space: pre-wrap;
  max-height: 400px;
  overflow-y: auto;
}
.email-detail .ai-section {
  margin-top: 1.5rem;
  padding: 1.25rem;
  background: var(--accent-lighter);
  border: 1px solid #bbf7d0;
  border-radius: 10px;
}
.email-detail .ai-section h4 {
  font-size: 0.85rem;
  color: var(--accent);
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.email-detail .ai-response {
  font-size: 0.88rem;
  line-height: 1.65;
  color: #166534;
  white-space: pre-wrap;
}
.email-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

/* ─── RULE CARDS ─── */
.rule-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 0.75rem;
  background: white;
  transition: border-color 0.15s;
}
.rule-card:hover { border-color: var(--accent); }
.rule-info { flex: 1; }
.rule-info .rule-name { font-weight: 600; font-size: 0.92rem; }
.rule-info .rule-desc { font-size: 0.8rem; color: var(--muted); margin-top: 0.15rem; }
.rule-actions { display: flex; gap: 0.4rem; align-items: center; }

/* ─── TOGGLE ─── */
.toggle {
  position: relative;
  width: 44px;
  height: 24px;
  cursor: pointer;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle .slider {
  position: absolute;
  inset: 0;
  background: var(--border-dark);
  border-radius: 24px;
  transition: background 0.2s;
}
.toggle .slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  top: 3px;
  left: 3px;
  transition: transform 0.2s;
}
.toggle input:checked + .slider { background: var(--accent); }
.toggle input:checked + .slider::before { transform: translateX(20px); }

/* ─── EMPTY STATE ─── */
.empty-state {
  text-align: center;
  padding: 3rem;
  color: var(--muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; }
.empty-state h3 { font-size: 1.1rem; margin-bottom: 0.5rem; color: var(--ink); }
.empty-state p { font-size: 0.9rem; max-width: 400px; margin: 0 auto; }

/* ─── MODAL ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-overlay.active { opacity: 1; pointer-events: auto; }
.modal {
  background: white;
  border-radius: 16px;
  padding: 2rem;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}
.modal h3 {
  font-size: 1.15rem;
  margin-bottom: 1.25rem;
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

/* ─── TOAST ─── */
.toast-container {
  position: fixed;
  top: 1.5rem;
  right: 1.5rem;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1.25rem;
  font-size: 0.88rem;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  animation: slideIn 0.3s ease;
}
.toast.success { border-left: 3px solid var(--accent); }
.toast.error { border-left: 3px solid var(--danger); }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ─── LOADING ─── */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-text { color: var(--muted); font-size: 0.88rem; }

/* ─── ACCOUNT CARD ─── */
.account-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem;
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 0.75rem;
  background: white;
}
.account-card .account-info { flex: 1; }
.account-card .account-email { font-weight: 600; font-size: 0.95rem; }
.account-card .account-host { font-size: 0.8rem; color: var(--muted); margin-top: 0.15rem; }
.account-card .account-status { margin-top: 0.3rem; }
.dot-indicator {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 0.3rem;
}
.dot-indicator.active { background: var(--accent); }
.dot-indicator.inactive { background: var(--muted-light); }

/* ─── CONNECT FORM ─── */
.connect-form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}
.connect-form-grid .form-group.full { grid-column: 1 / -1; }

/* ─── RESPONSIVE ─── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s;
    z-index: 200;
  }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; max-width: 100%; padding: 1rem; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .connect-form-grid { grid-template-columns: 1fr; }
  .mobile-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    background: white;
    position: sticky;
    top: 0;
    z-index: 150;
  }
  .mobile-nav .logo { font-size: 1.2rem; }
  .hamburger {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
  }
}
@media (min-width: 769px) {
  .mobile-nav { display: none; }
  .sidebar-overlay { display: none !important; }
}
.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 150;
  display: none;
}
.sidebar-overlay.active { display: block; }

/* ─── PRESET BUTTONS ─── */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.preset-btn {
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  cursor: pointer;
  text-align: center;
  font-size: 0.8rem;
  font-family: 'DM Sans', sans-serif;
  transition: all 0.15s;
}
.preset-btn:hover { border-color: var(--accent); color: var(--accent); }
.preset-btn .preset-name { font-weight: 600; font-size: 0.82rem; }
.preset-btn .preset-desc { color: var(--muted); font-size: 0.72rem; margin-top: 0.15rem; }

/* ─── SEARCH ─── */
.search-input {
  position: relative;
}
.search-input input {
  width: 100%;
  padding: 0.55rem 0.85rem 0.55rem 2.2rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.88rem;
  font-family: 'DM Sans', sans-serif;
}
.search-input input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--glow);
}
.search-input::before {
  content: '\1F50D';
  position: absolute;
  left: 0.65rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.85rem;
}

/* ─── BACK BUTTON ─── */
.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  border: none;
  background: none;
  font-family: 'DM Sans', sans-serif;
  margin-bottom: 1rem;
}
.back-btn:hover { color: var(--accent); }
