:root {
  --font: 'Montserrat', sans-serif;
  --radius: 10px;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-alt: #171a23;
  --card: #1b1f2a;
  --border: #2a2f3d;
  --text: #e7e9ee;
  --text-muted: #9aa1b2;
  --primary: #6366f1;
  --primary-hover: #7c7ff4;
  --danger: #ef4444;
  --high: #ef4444;
  --medium: #f59e0b;
  --low: #10b981;
  --shadow: 0 4px 16px rgba(0,0,0,0.35);
}

[data-theme="light"] {
  --bg: #f4f5f9;
  --bg-alt: #ffffff;
  --card: #ffffff;
  --border: #e3e5ec;
  --text: #171923;
  --text-muted: #6b7280;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --danger: #dc2626;
  --high: #dc2626;
  --medium: #d97706;
  --low: #059669;
  --shadow: 0 4px 14px rgba(0,0,0,0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  transition: background .2s, color .2s;
}

a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); }

/* ---------- Top bar / hamburger nav ---------- */
.topbar {
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 50;
}
.topbar-inner {
  max-width: 1200px; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px;
}
.brand { font-weight: 700; font-size: 19px; color: var(--text); display: flex; align-items: center; gap: 6px; }
.brand span { color: var(--primary); }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.icon-btn {
  background: none; border: 1px solid var(--border); color: var(--text);
  width: 38px; height: 38px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-btn:hover { border-color: var(--primary); color: var(--primary); }

.hamburger {
  width: 40px; height: 40px; background: none; border: 1px solid var(--border); border-radius: 8px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 5px; cursor: pointer;
}
.hamburger span { width: 20px; height: 2px; background: var(--text); transition: transform .2s, opacity .2s; }
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.main-nav {
  max-height: 0; overflow: hidden; background: var(--bg-alt);
  display: flex; flex-direction: column;
  border-top: 1px solid transparent;
  transition: max-height .25s ease;
}
.main-nav.open { max-height: 400px; border-top-color: var(--border); }
.nav-link {
  padding: 14px 20px; color: var(--text); border-bottom: 1px solid var(--border);
  font-weight: 500; font-size: 14px;
}
.nav-link.active { color: var(--primary); }
.nav-logout { color: var(--danger); }

@media (min-width: 860px) {
  .main-nav {
    max-height: none; flex-direction: row; justify-content: center;
    border-top: 1px solid var(--border);
  }
  .nav-link { border-bottom: none; padding: 12px 18px; }
  .hamburger { display: none; }
}

/* ---------- Layout ---------- */
.page-wrap { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 22px; margin-bottom: 22px; box-shadow: var(--shadow);
}
.card-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; }
.card h2, .card h3 { margin: 0 0 4px; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stats-grid.compact { margin-bottom: 0; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat-card.highlight { border-color: var(--high); }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-label { color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 6px; color: var(--text-muted); }
input, textarea, select {
  width: 100%; padding: 11px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-family: var(--font); font-size: 14px;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--primary); }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px; }
legend { padding: 0 8px; font-weight: 600; color: var(--primary); }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-actions { display: flex; gap: 10px; margin-top: 10px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block; padding: 10px 18px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg-alt); color: var(--text); cursor: pointer; font-family: var(--font);
  font-weight: 600; font-size: 13px; text-align: center;
}
.btn:hover { border-color: var(--primary); color: var(--primary); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-block { width: 100%; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th, .table td { text-align: left; padding: 11px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { color: var(--text-muted); font-weight: 600; }
.actions { display: flex; gap: 6px; }
.nowrap { white-space: nowrap; }

/* ---------- Badges / Pills ---------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11.5px; font-weight: 700; color: #fff; }
.badge-high { background: var(--high); }
.badge-medium { background: var(--medium); }
.badge-low { background: var(--low); }

.filter-pills { display: flex; gap: 8px; flex-wrap: wrap; }
.pill { padding: 6px 14px; border-radius: 20px; border: 1px solid var(--border); font-size: 12.5px; font-weight: 600; color: var(--text); }
.pill.active, .pill:hover { border-color: var(--primary); color: var(--primary); }
.pill-high.active { border-color: var(--high); color: var(--high); }
.pill-medium.active { border-color: var(--medium); color: var(--medium); }
.pill-low.active { border-color: var(--low); color: var(--low); }

/* ---------- Response items ---------- */
.response-item { border-bottom: 1px solid var(--border); padding: 16px 0; }
.response-item:last-child { border-bottom: none; }
.response-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 4px; }
.muted { color: var(--text-muted); font-size: 12.5px; }
.response-subject { font-weight: 600; margin-bottom: 6px; }
.ai-summary { background: var(--bg); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; }
.response-body { font-size: 13.5px; color: var(--text-muted); white-space: pre-wrap; }
.followup-draft { background: var(--bg); border-radius: 8px; padding: 10px 12px; font-size: 13.5px; margin-top: 8px; }
details summary { cursor: pointer; color: var(--primary); font-size: 13px; margin-top: 6px; }

/* ---------- Misc ---------- */
.empty-state { color: var(--text-muted); text-align: center; padding: 30px 0; }
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 18px; font-size: 14px; }
.alert-success { background: rgba(16,185,129,.12); color: var(--low); border: 1px solid var(--low); }
.alert-error { background: rgba(239,68,68,.12); color: var(--high); border: 1px solid var(--high); }
.pagination { display: flex; gap: 10px; justify-content: center; margin-top: 16px; }
.trace { white-space: pre-wrap; font-size: 11px; background: var(--bg); padding: 10px; border-radius: 6px; max-height: 200px; overflow: auto; }

/* ---------- Auth page ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 36px; width: 100%; max-width: 380px; box-shadow: var(--shadow); }
.auth-title { margin: 0 0 4px; font-size: 22px; }
.auth-sub { color: var(--text-muted); margin: 0 0 20px; font-size: 14px; }