/* ── Design Tokens ─────────────────────────────────────────────────────── */
:root {
  --primary:    #2563eb;
  --primary-2:  #7c3aed;
  --primary-3:  #0891b2;
  --good:       #16a34a;
  --bad:        #dc2626;
  --warn:       #f59e0b;
  --neutral:    #64748b;

  --surface:    rgba(255, 255, 255, 0.82);
  --radius:     18px;
  --radius-sm:  10px;
  --radius-xs:  6px;

  --app-bg-0:   #f6f7ff;
  --text-primary: #1e293b;
  --text-muted:   #64748b;
  --text-light:   #94a3b8;
  --border:       rgba(148, 163, 184, 0.28);

  --shadow-card: 0 4px 24px rgba(37,99,235,.08), 0 1px 4px rgba(0,0,0,.04);
  --shadow-lg:   0 8px 48px rgba(37,99,235,.14), 0 2px 8px rgba(0,0,0,.07);
}

/* ── Base ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background-color: var(--app-bg-0);
  background-image:
    radial-gradient(ellipse 80% 50% at  10% -10%, rgba(124, 58,237,.09) 0%, transparent 60%),
    radial-gradient(ellipse 60% 40% at  90%  20%, rgba(  8,145,178,.07) 0%, transparent 55%),
    radial-gradient(ellipse 50% 60% at  50% 100%, rgba( 22,163, 74,.05) 0%, transparent 60%);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ── Navigation ────────────────────────────────────────────────────────── */
.app-nav {
  position: sticky; top: 0; z-index: 200;
  background: rgba(37, 99, 235, 0.96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(255,255,255,.12);
  box-shadow: 0 2px 20px rgba(37,99,235,.28);
}

.app-nav__inner {
  max-width: 1400px; margin: 0 auto;
  padding: 0 24px;
  display: flex; align-items: center; height: 58px;
  gap: 4px;
}

.app-nav__brand {
  font-weight: 800; font-size: 1rem;
  letter-spacing: -.025em;
  color: #fff; text-decoration: none;
  margin-right: 16px;
  display: flex; flex-direction: column; line-height: 1.1;
  flex-shrink: 0;
}
.app-nav__brand small {
  font-size: .68rem; font-weight: 400;
  opacity: .65; letter-spacing: .02em;
}

.app-navlink {
  color: rgba(255,255,255,.78);
  text-decoration: none;
  font-size: .85rem; font-weight: 500;
  padding: 7px 14px;
  border-radius: 8px;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.app-navlink:hover { background: rgba(255,255,255,.16); color: #fff; }
.app-navlink--active {
  background: linear-gradient(135deg, rgba(255,255,255,.25), rgba(255,255,255,.12));
  color: #fff; font-weight: 700;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.22);
}

.app-nav__spacer { flex: 1; }

/* ── Main ──────────────────────────────────────────────────────────────── */
.app-main {
  max-width: 1400px;
  margin: 0 auto;
  padding: 36px 24px 72px;
}

/* ── Page Header ───────────────────────────────────────────────────────── */
.app-page-header { margin-bottom: 28px; }
.app-page-header h1 {
  font-size: 1.85rem; font-weight: 800;
  letter-spacing: -.03em; line-height: 1.15;
}
.app-page-header p {
  color: var(--text-muted); margin-top: 6px;
  font-size: .9rem;
}

/* ── Cards ─────────────────────────────────────────────────────────────── */
.app-card {
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  padding: 24px;
  overflow: hidden;
}
.app-card--sm { padding: 18px 20px; }

.app-card__title {
  font-size: .72rem; font-weight: 700;
  letter-spacing: .09em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 16px;
}

/* ── KPI Cards ─────────────────────────────────────────────────────────── */
.app-kpi {
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  padding: 20px 22px 22px;
  position: relative; overflow: hidden;
  transition: box-shadow .2s, transform .2s;
}
.app-kpi:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }

.app-kpi::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg,
    var(--kpi-c1, var(--primary)),
    var(--kpi-c2, var(--primary-2)));
}
.app-kpi--blue    { --kpi-c1: #2563eb; --kpi-c2: #3b82f6; }
.app-kpi--violet  { --kpi-c1: #7c3aed; --kpi-c2: #a78bfa; }
.app-kpi--green   { --kpi-c1: #16a34a; --kpi-c2: #34d399; }
.app-kpi--amber   { --kpi-c1: #d97706; --kpi-c2: #f59e0b; }
.app-kpi--cyan    { --kpi-c1: #0891b2; --kpi-c2: #22d3ee; }
.app-kpi--rose    { --kpi-c1: #e11d48; --kpi-c2: #fb7185; }

.app-kpi__label {
  font-size: .7rem; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 8px;
}
.app-kpi__value {
  font-size: 2.5rem; font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.035em; color: var(--text-primary); line-height: 1;
}
.app-kpi__sub {
  font-size: .76rem; color: var(--text-muted); margin-top: 6px;
}

/* ── Grids ─────────────────────────────────────────────────────────────── */
.app-grid-2 { display: grid; grid-template-columns: repeat(2,1fr); gap: 20px; }
.app-grid-3 { display: grid; grid-template-columns: repeat(3,1fr); gap: 20px; }
.app-grid-4 { display: grid; grid-template-columns: repeat(4,1fr); gap: 20px; }
.app-grid-5 { display: grid; grid-template-columns: repeat(5,1fr); gap: 16px; }

@media (max-width: 1100px) {
  .app-grid-4, .app-grid-5 { grid-template-columns: repeat(2,1fr); }
  .app-grid-3               { grid-template-columns: repeat(2,1fr); }
}
@media (max-width: 640px) {
  .app-grid-2, .app-grid-3, .app-grid-4, .app-grid-5 { grid-template-columns: 1fr; }
  .app-main { padding: 20px 14px 48px; }
}

/* ── Table ─────────────────────────────────────────────────────────────── */
.app-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.app-table th {
  text-align: left; padding: 10px 16px;
  font-size: .7rem; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.app-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.app-table tr:last-child td { border-bottom: none; }
.app-table tr:hover td { background: rgba(37,99,235,.025); }

/* ── Badges ────────────────────────────────────────────────────────────── */
.app-badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: .7rem; font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase;
  white-space: nowrap;
}
.app-badge--blue   { background: rgba(37,99,235,.1);   color: #1d4ed8; }
.app-badge--violet { background: rgba(124,58,237,.1);  color: #6d28d9; }
.app-badge--green  { background: rgba(22,163,74,.1);   color: #15803d; }
.app-badge--amber  { background: rgba(245,158,11,.1);  color: #b45309; }
.app-badge--red    { background: rgba(220,38,38,.1);   color: #b91c1c; }
.app-badge--cyan   { background: rgba(8,145,178,.1);   color: #0e7490; }
.app-badge--slate  { background: rgba(100,116,139,.1); color: #475569; }

/* ── Buttons ───────────────────────────────────────────────────────────── */
.app-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 20px; border-radius: var(--radius-sm);
  font-size: .875rem; font-weight: 600; cursor: pointer;
  border: none; text-decoration: none;
  transition: opacity .15s, box-shadow .15s, transform .1s;
}
.app-btn:hover { opacity: .88; box-shadow: 0 4px 14px rgba(0,0,0,.1); transform: translateY(-1px); }
.app-btn--primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; }
.app-btn--ghost   { background: rgba(37,99,235,.08); color: var(--primary); }
.app-btn--sm      { padding: 5px 13px; font-size: .8rem; }

/* ── Form Controls ─────────────────────────────────────────────────────── */
.app-select, .app-input {
  padding: 8px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: rgba(255,255,255,.92);
  color: var(--text-primary); font-size: .875rem;
  font-family: inherit; outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.app-select:focus, .app-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}
.app-label {
  display: block; font-size: .72rem; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 5px;
}

/* ── Filter Bar ────────────────────────────────────────────────────────── */
.filter-bar {
  background: var(--surface);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  padding: 18px 22px;
  display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end;
  margin-bottom: 24px;
}
.filter-bar__group { display: flex; flex-direction: column; }

/* ── Comment Cards ─────────────────────────────────────────────────────── */
.comment-card {
  background: var(--surface);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-card);
  padding: 20px 22px;
  transition: box-shadow .2s, transform .2s;
}
.comment-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-1px); }

.comment-card__body {
  color: var(--text-primary);
  font-size: .9rem; line-height: 1.7;
  margin-bottom: 14px;
}
.comment-card__meta {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
}
.comment-card__id {
  font-size: .7rem; color: var(--text-light);
  font-family: 'SF Mono', 'Fira Code', monospace;
}

/* ── Progress Bar ──────────────────────────────────────────────────────── */
.app-progress {
  height: 8px; background: rgba(148,163,184,.2);
  border-radius: 99px; overflow: hidden;
  margin-top: 8px;
}
.app-progress__bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--primary-2));
  border-radius: 99px;
  transition: width .6s ease;
}
.app-progress--sm { height: 5px; }

/* ── Pagination ────────────────────────────────────────────────────────── */
.app-pagination {
  display: flex; align-items: center; gap: 6px;
  justify-content: center; margin-top: 32px; flex-wrap: wrap;
}
.app-pagination a,
.app-pagination span {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 38px; height: 38px; padding: 0 10px;
  border-radius: 9px; font-size: .875rem; font-weight: 500;
  text-decoration: none;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  transition: all .15s;
}
.app-pagination a:hover { background: rgba(37,99,235,.08); border-color: var(--primary); color: var(--primary); }
.app-pagination .current { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 700; }
.app-pagination .ellipsis { border: none; background: transparent; color: var(--text-muted); }
.app-pagination .disabled { opacity: .35; pointer-events: none; }

/* ── Heatmap ───────────────────────────────────────────────────────────── */
.heatmap-wrap { overflow-x: auto; }
.heatmap-table {
  width: 100%; border-collapse: collapse; font-size: .8rem;
  min-width: 480px;
}
.heatmap-table th {
  padding: 9px 12px;
  font-size: .68rem; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase;
  color: var(--text-muted); text-align: center;
  border-bottom: 2px solid var(--border);
}
.heatmap-table th:first-child { text-align: left; min-width: 130px; }
.heatmap-table td {
  padding: 8px 10px; text-align: center;
  font-variant-numeric: tabular-nums;
  border-bottom: 1px solid var(--border);
}
.heatmap-table td:first-child { text-align: left; font-weight: 600; }
.heatmap-table tr:last-child td { border-bottom: none; }
.heatmap-table td.cell-val {
  position: relative; cursor: default;
}
.cell-n   { font-weight: 700; font-size: .82rem; }
.cell-pct { font-size: .68rem; color: var(--text-muted); }

/* ── Crosstab section header ───────────────────────────────────────────── */
.ct-section {
  margin-bottom: 32px;
}
.ct-section + .ct-section { border-top: 1px solid var(--border); padding-top: 32px; }

/* ── Methodology ───────────────────────────────────────────────────────── */
.pipeline-step {
  display: flex; gap: 16px; align-items: flex-start;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.pipeline-step:last-child { border-bottom: none; }
.pipeline-step__num {
  width: 28px; height: 28px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  color: #fff; font-size: .75rem; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; margin-top: 2px;
}
.pipeline-step__name { font-weight: 700; font-size: .9rem; }
.pipeline-step__desc { font-size: .82rem; color: var(--text-muted); margin-top: 2px; }

/* ── Code block ────────────────────────────────────────────────────────── */
.code-block {
  background: #0f172a; color: #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 16px 20px;
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: .8rem; line-height: 1.7;
  overflow-x: auto; white-space: pre-wrap; word-break: break-all;
}

/* ── Live coding banner ────────────────────────────────────────────────── */
.coding-banner {
  display: flex; align-items: center; gap: 14px;
  background: rgba(37,99,235,.06);
  border: 1px solid rgba(37,99,235,.18);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  margin-bottom: 24px;
}
.coding-banner--done {
  background: rgba(22,163,74,.06);
  border-color: rgba(22,163,74,.2);
}
.coding-banner__dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--primary); flex-shrink: 0;
  animation: pulse-dot 1.6s ease-in-out infinite;
}
.coding-banner--done .coding-banner__dot {
  background: var(--good); animation: none;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .5; transform: scale(.7); }
}

/* ── Raw LLM ───────────────────────────────────────────────────────────── */
.rawllm-sample {
  display: flex; flex-direction: column; gap: 8px;
}
.rawllm-sample__item {
  display: flex; gap: 10px; align-items: center;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: all .15s; text-decoration: none; color: inherit;
}
.rawllm-sample__item:hover { border-color: var(--primary); background: rgba(37,99,235,.05); }

/* ── Chart container ───────────────────────────────────────────────────── */
.chart-wrap {
  position: relative;
  height: 220px;
  width: 100%;
}
.chart-wrap--tall { height: 280px; }
.chart-wrap--doughnut { height: 200px; }

/* ── Divider ───────────────────────────────────────────────────────────── */
.divider { border: none; border-top: 1px solid var(--border); margin: 24px 0; }

/* ── Section label ─────────────────────────────────────────────────────── */
.section-label {
  font-size: .72rem; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase;
  color: var(--text-muted); margin-bottom: 12px;
  display: block;
}

/* ── Loading bar ───────────────────────────────────────────────────────── */
#loading-bar {
  position: fixed; top: 0; left: 0; height: 3px;
  background: linear-gradient(90deg, var(--primary), var(--primary-2), var(--primary-3));
  z-index: 9999; width: 0;
  transition: width .3s ease, opacity .4s ease;
  box-shadow: 0 0 10px rgba(37,99,235,.45);
  pointer-events: none;
}

/* ── Utilities ─────────────────────────────────────────────────────────── */
.flex            { display: flex; }
.flex-col        { display: flex; flex-direction: column; }
.flex-wrap       { flex-wrap: wrap; }
.items-center    { align-items: center; }
.items-start     { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-end     { justify-content: flex-end; }
.gap-2           { gap: 8px; }
.gap-3           { gap: 12px; }
.gap-4           { gap: 16px; }
.gap-5           { gap: 20px; }
.gap-6           { gap: 24px; }
.mt-1            { margin-top: 4px; }
.mt-2            { margin-top: 8px; }
.mt-3            { margin-top: 12px; }
.mt-4            { margin-top: 16px; }
.mt-6            { margin-top: 24px; }
.mt-8            { margin-top: 32px; }
.mb-2            { margin-bottom: 8px; }
.mb-4            { margin-bottom: 16px; }
.mb-6            { margin-bottom: 24px; }
.text-muted      { color: var(--text-muted); }
.text-light      { color: var(--text-light); }
.text-sm         { font-size: .875rem; }
.text-xs         { font-size: .75rem; }
.text-2xl        { font-size: 1.5rem; }
.font-bold       { font-weight: 700; }
.font-semibold   { font-weight: 600; }
.text-right      { text-align: right; }
.text-center     { text-align: center; }
.truncate        { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.w-full          { width: 100%; }
.tabular-nums    { font-variant-numeric: tabular-nums; }
.uppercase       { text-transform: uppercase; }
