/* ── Design tokens ───────────────────────────────────────────────────────── */
:root {
  --bg:          #0f1117;
  --bg-card:     #181c27;
  --bg-input:    #1e2333;
  --border:      #2a3045;
  --text:        #e8eaf0;
  --text-muted:  #7a84a0;
  --accent:      #6ee7b7;
  --accent-dim:  #2d5a47;
  --warn:        #f59e0b;
  --danger:      #f87171;
  --danger-dim:  #4a1f1f;
  --up-color:    #6ee7b7;
  --down-color:  #f87171;
  --radius:      8px;
  --font-mono:   'JetBrains Mono', 'Fira Code', monospace;
  --font-body:   'DM Sans', 'Segoe UI', sans-serif;
  --font-display:'Syne', 'DM Sans', sans-serif;
  --shadow:      0 4px 24px rgba(0,0,0,0.4);
  --transition:  0.18s ease;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.6;
}

/* ── Typography ─────────────────────────────────────────────────────────── */
h1, h2, h3, h4 { font-family: var(--font-display); font-weight: 700; }
h1 { font-size: 1.6rem; letter-spacing: -0.5px; line-height: 1.4; padding-bottom: 0.25em; overflow: visible; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
a { color: var(--accent); text-decoration: none; cursor: pointer; }

/* ── Layout ─────────────────────────────────────────────────────────────── */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}
.main-content {
  flex: 1;
  overflow-y: auto;
  padding: 0;
}
.page {
  padding: 32px 36px;
  max-width: 1100px;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  width: 200px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  flex-shrink: 0;
}
.nav-brand {
  font-family: var(--font-display);
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--accent);
  padding: 0 20px 28px;
  letter-spacing: 1px;
}
.nav-links {
  list-style: none;
  flex: 1;
}
.nav-links li a {
  display: block;
  padding: 11px 20px;
  color: var(--text-muted);
  font-size: 0.9rem;
  font-weight: 500;
  transition: color var(--transition), background var(--transition);
  border-left: 3px solid transparent;
}
.nav-links li a:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav-links li.active a {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(110,231,183,0.07);
}
.nav-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.nav-user { font-size: 0.78rem; color: var(--text-muted); font-family: var(--font-mono); }

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
  flex-wrap: wrap;
  gap: 12px;
}
.header-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-family: var(--font-body);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: #0a1a14;
  border-color: var(--accent);
}
.btn-primary:hover:not(:disabled) { background: #9df0cc; }
.btn-secondary {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent-dim);
}
.btn-secondary:hover { background: rgba(110,231,183,0.08); }
.btn-ghost {
  background: transparent;
  color: var(--accent);
  border-color: var(--border);
  padding: 5px 10px;
  font-size: 0.8rem;
  font-weight: 500;
}
.btn-ghost:hover { color: var(--text); border-color: var(--accent); background: var(--bg-input); }
.btn-ghost.accent { color: var(--accent); }
.btn-ghost.danger { color: var(--danger); }
.btn-ghost.danger:hover { background: var(--danger-dim); }
.btn.sm, .btn-ghost.sm { padding: 4px 8px; font-size: 0.78rem; }
.full-width { width: 100%; justify-content: center; }

/* ── Inputs ──────────────────────────────────────────────────────────────── */
input, textarea, select {
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.875rem;
  padding: 8px 12px;
  transition: border-color var(--transition);
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
select option { background: var(--bg-card); }
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-group label { font-size: 0.8rem; color: var(--text-muted); font-weight: 600; letter-spacing: 0.5px; text-transform: uppercase; }
.form-inline { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.form-inline input { flex: 1; min-width: 140px; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
}
.data-table td {
  padding: 11px 14px;
  border-bottom: 1px solid rgba(42,48,69,0.5);
  vertical-align: middle;
}
.data-table tr:hover td { background: rgba(255,255,255,0.02); }
.data-table .inactive-row td { opacity: 0.5; }
.data-table .actions { display: flex; gap: 6px; }
.client-id { font-family: var(--font-mono); font-size: 0.85rem; color: var(--accent); }

/* ── Status badges ───────────────────────────────────────────────────────── */
.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}
.status-badge.active  { background: rgba(110,231,183,0.12); color: var(--accent); }
.status-badge.inactive { background: rgba(120,120,140,0.12); color: var(--text-muted); }
.range-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.72rem;
  background: rgba(96,165,250,0.1);
  color: #60a5fa;
  font-family: var(--font-mono);
}

/* ── Error banner ────────────────────────────────────────────────────────── */
.error-banner {
  background: var(--danger-dim);
  border: 1px solid var(--danger);
  border-radius: var(--radius);
  color: var(--danger);
  padding: 10px 16px;
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
}
.close-btn { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 1.2rem; }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner-wrap { display: flex; justify-content: center; padding: 40px; }
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
  font-size: 0.95rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
}

/* ── Login ───────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 44px 40px;
  width: 380px;
  box-shadow: var(--shadow);
}
.login-logo {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 1px;
  margin-bottom: 8px;
}
.login-sub { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 32px; }
.login-error {
  background: var(--danger-dim);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 0.85rem;
  margin-bottom: 16px;
}
.login-card .form-group { margin-bottom: 20px; }
.login-card input { width: 100%; }
.login-context {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}
.btn-link {
  background: none;
  border: none;
  padding: 0;
  color: var(--primary);
  font-size: inherit;
  cursor: pointer;
  text-decoration: underline;
}
.login-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.login-divider::before,
.login-divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}
.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-secondary:hover { background: var(--bg-hover, var(--border)); }
.btn-secondary:disabled { opacity: 0.6; cursor: not-allowed; }

/* ── Data Entry ──────────────────────────────────────────────────────────── */
.entry-layout { max-width: 680px; }
.bulk-entry {
  background: var(--bg-card);
  border: 1px solid var(--accent-dim);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 20px;
}
.bulk-label { font-size: 0.78rem; color: var(--accent); font-weight: 600; display: block; margin-bottom: 8px; }
.bulk-input { width: 100%; font-family: var(--font-mono); font-size: 1rem; letter-spacing: 3px; }
.questions-list { margin-bottom: 20px; }
.question-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid rgba(42,48,69,0.4);
}
.q-num { color: var(--text-muted); font-family: var(--font-mono); font-size: 0.8rem; width: 24px; flex-shrink: 0; }
.q-text { flex: 1; font-size: 0.9rem; }
.answer-input { width: 80px; text-align: center; font-family: var(--font-mono); flex-shrink: 0; }

/* ── Analytics ───────────────────────────────────────────────────────────── */
.analytics-controls { display: flex; gap: 12px; margin-bottom: 28px; align-items: center; flex-wrap: wrap; }
.analytics-controls select { min-width: 220px; }
.chart-svg { display: block; overflow: visible; }
.drill-down { }
.drill-down h3 { margin-bottom: 16px; color: var(--text-muted); font-size: 0.9rem; text-transform: uppercase; letter-spacing: 0.8px; }
.deltas-panel { margin-top: 28px; }
.deltas-panel h3 { margin-bottom: 12px; }
.delta {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 700;
}
.delta.up   { background: rgba(110,231,183,0.12); color: var(--up-color); }
.delta.down { background: rgba(248,113,113,0.12); color: var(--down-color); }
.delta.flat { color: var(--text-muted); }

/* ── Assessment cards ────────────────────────────────────────────────────── */
.assessments-list { display: flex; flex-direction: column; gap: 16px; }
.assessment-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color var(--transition);
}
.assessment-card:hover { border-color: rgba(110,231,183,0.25); }
.assessment-card.inactive { opacity: 0.6; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  gap: 12px;
}
.card-title { display: flex; align-items: center; gap: 12px; flex: 1; }
.card-title h3 { font-size: 1rem; }
.card-actions { display: flex; gap: 6px; }
.card-body { padding: 0 20px 20px; border-top: 1px solid var(--border); padding-top: 16px; }
.card-meta { margin-bottom: 16px; }
.card-meta p { color: var(--text-muted); font-size: 0.875rem; margin-bottom: 8px; }
.new-assessment-form {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 28px;
}
.new-assessment-form h3 { margin-bottom: 14px; font-size: 0.9rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.6px; }

/* ── Question editor ─────────────────────────────────────────────────────── */
.question-editor { margin-top: 8px; }
.question-editor h4 { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 10px; }
.question-list { list-style: decimal; padding-left: 20px; margin-bottom: 14px; }
.q-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0;
  border-bottom: 1px solid rgba(42,48,69,0.4);
}
.q-item .q-text { flex: 1; font-size: 0.875rem; }

/* ── Scrollbars ─────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Section header ─────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}
.submissions-section { margin-top: 28px; }

/* ── Horizontal scroll wrappers ─────────────────────────────────────────── */
.table-scroll-x {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.chart-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-bottom: 20px;
}

/* ── Mobile top bar ─────────────────────────────────────────────────────── */
.mobile-topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  align-items: center;
  justify-content: space-between;
  z-index: 160;
}
.mobile-topbar .nav-brand { padding: 0; font-size: 1.2rem; letter-spacing: 0; }

/* ── Hamburger button ────────────────────────────────────────────────────── */
.hamburger {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius);
  transition: background var(--transition);
}
.hamburger:hover { background: rgba(255,255,255,0.08); }

/* ── Nav overlay (visible behind open drawer) ────────────────────────────── */
.nav-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 150;
  cursor: pointer;
}
.nav-overlay.nav-open { display: block; }

/* ── Responsive: tablet + mobile (≤ 1023 px) ────────────────────────────── */
@media (max-width: 1023px) {
  /* Sidebar becomes a slide-in drawer */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
  }
  .sidebar.nav-open {
    transform: translateX(0);
    box-shadow: 4px 0 32px rgba(0,0,0,0.5);
  }
  /* Show mobile top bar */
  .mobile-topbar { display: flex; }
  /* Let app layout grow naturally; body handles scrolling */
  .app-layout { height: auto; min-height: 100vh; overflow: visible; }
  .main-content { overflow-y: visible; padding-top: 56px; }
  /* Slightly reduced page padding */
  .page { padding: 24px 20px; }
}

/* ── Responsive: mobile only (≤ 639 px) ─────────────────────────────────── */
@media (max-width: 639px) {
  h1 { font-size: 1.3rem; }
  .page { padding: 16px 14px; }
  /* Login card: full-bleed with margin */
  .login-card { width: calc(100vw - 32px); padding: 28px 20px; }
  /* Stack section-header actions below heading */
  .section-header { flex-direction: column; align-items: flex-start; }
  /* Analytics controls stacked */
  .analytics-controls { flex-direction: column; align-items: stretch; }
  .analytics-controls select { width: 100%; }
  /* Slightly more compact table cells */
  .data-table td { padding: 9px 10px; }
  .data-table th { padding: 8px 10px; }
  /* Form inputs full-width on mobile */
  .form-inline { flex-direction: column; }
  .form-inline input { min-width: 0; width: 100%; }
  /* Tighter answer input */
  .answer-input { width: 64px; }
  /* Page header actions wrap to a second line */
  .header-actions { flex-wrap: wrap; }
}
