/* The dashboard's styles: one file, no build step. Light and dark follow the device. */
:root {
  color-scheme: light dark;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --border-strong: #cdd3dc;
  --text: #18202b;
  --muted: #5f6b7a;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #e8efff;
  --accent-text: #1e48b8;
  --ok: #15803d;
  --ok-soft: #e7f6ec;
  --bad: #c2333a;
  --bad-soft: #fdecec;
  --info-soft: #eef3fb;
  --grade-ink: #ffffff;
  --grade-aplus: #0f7a45;
  --grade-a: #2f9e44;
  --grade-b: #b7860b;
  --grade-c: #dd6b20;
  --grade-d: #c2333a;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --radius: 12px;
  --radius-sm: 8px;
  --sidebar: 248px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1319;
    --surface: #151b23;
    --surface-2: #1b232d;
    --border: #253040;
    --border-strong: #334155;
    --text: #e5e9ef;
    --muted: #97a3b4;
    --accent: #5b8def;
    --accent-hover: #7aa3f5;
    --accent-soft: #1a2742;
    --accent-text: #a9c2ff;
    --ok: #4ade80;
    --ok-soft: #10291a;
    --bad: #f87171;
    --bad-soft: #351719;
    --info-soft: #172131;
    --grade-ink: #0e1319;
    --grade-aplus: #22c55e;
    --grade-a: #4ade80;
    --grade-b: #facc15;
    --grade-c: #fb923c;
    --grade-d: #f87171;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--font); font-size: 15px; line-height: 1.5; color: var(--text); background: var(--bg); }
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.6rem; line-height: 1.25; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; margin-bottom: 12px; }
h3 { font-size: 0.95rem; margin: 18px 0 6px; }
.icon { width: 20px; height: 20px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-sm { width: 16px; height: 16px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }
.break { overflow-wrap: anywhere; }

/* Shell: sidebar + main */
.shell { display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.sidebar { position: sticky; top: 0; height: 100vh; height: 100dvh; display: flex; flex-direction: column; gap: 8px; padding: 16px 12px; background: var(--surface); border-right: 1px solid var(--border); overflow-y: auto; }
.sidebar-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 8px 12px; }
.brand { display: inline-flex; align-items: center; gap: 10px; color: var(--text); font-weight: 650; font-size: 1.05rem; letter-spacing: -0.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-flex; width: 30px; height: 30px; }
.brand-mark svg { width: 100%; height: 100%; }
.brand-bg { fill: var(--accent); }
.brand-lines { fill: none; stroke: #ffffff; stroke-width: 2.6; stroke-linecap: round; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 12px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--muted); font: inherit; font-weight: 550; text-align: left; cursor: pointer; }
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item.is-active { background: var(--accent-soft); color: var(--accent-text); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 4px; padding-top: 12px; border-top: 1px solid var(--border); }
.sidebar-foot form { margin: 0; }
.who { display: flex; align-items: center; gap: 10px; padding: 8px 12px; font-weight: 550; }
.avatar { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--surface-2); color: var(--muted); font-size: 0.8rem; font-weight: 700; }
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { display: none; }
.content { width: 100%; max-width: 1080px; margin: 0 auto; padding: 32px 32px 64px; }
.icon-button { display: inline-grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: var(--radius-sm); background: none; color: var(--muted); cursor: pointer; }
.icon-button:hover { background: var(--surface-2); color: var(--text); }
.nav-close, .backdrop { display: none; }

/* Page parts */
.page-head { margin-bottom: 24px; }
.page-head-row { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.eyebrow { margin-bottom: 4px; color: var(--muted); font-size: 0.85rem; font-weight: 550; }
.lead { max-width: 62ch; margin-top: 8px; color: var(--muted); }
.section { margin-top: 32px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.back { display: inline-flex; align-items: center; gap: 6px; margin-bottom: 16px; color: var(--muted); font-size: 0.9rem; font-weight: 550; }
.back .icon { width: 16px; height: 16px; }
.empty { padding: 16px 0; color: var(--muted); }

/* Buttons, fields, alerts */
.button { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 8px 16px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; font-weight: 600; cursor: pointer; }
.button:hover { background: var(--surface-2); text-decoration: none; }
.button .icon { width: 18px; height: 18px; }
.button-primary { border-color: var(--accent); background: var(--accent); color: #ffffff; }
.button-primary:hover { border-color: var(--accent-hover); background: var(--accent-hover); }
.button-ghost { border-color: transparent; background: none; color: var(--muted); }
.button-ghost:hover { background: var(--bad-soft); color: var(--bad); }
.button-block { width: 100%; }
.button:disabled { opacity: 0.65; cursor: progress; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.9rem; font-weight: 550; }
.field input, .search { width: 100%; min-height: 42px; padding: 9px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--surface); color: var(--text); font: inherit; font-weight: 400; }
a:focus-visible, .button:focus-visible, .icon-button:focus-visible, .nav-item:focus-visible, .field input:focus, .search:focus, .dropzone:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.alert { display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px; border-radius: var(--radius-sm); font-size: 0.92rem; }
.alert-error { background: var(--bad-soft); color: var(--bad); }
.alert-info { background: var(--info-soft); }
.alert .icon { width: 18px; height: 18px; margin-top: 2px; color: var(--accent-text); }

/* Login and error pages */
.auth { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 16px; padding: 28px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow); }
.auth-card h1 { font-size: 1.35rem; }

/* Home tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.tile { display: flex; align-items: center; gap: 14px; padding: 18px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text); transition: border-color 0.15s, transform 0.15s; }
.tile:hover { border-color: var(--accent); text-decoration: none; transform: translateY(-1px); }
.tile-icon { display: grid; place-items: center; flex: none; width: 44px; height: 44px; border-radius: 10px; background: var(--accent-soft); color: var(--accent-text); }
.tile-icon .icon { width: 22px; height: 22px; }
.tile-body { display: flex; flex: 1; flex-direction: column; gap: 2px; min-width: 0; }
.tile-title { font-weight: 650; }
.tile-text { color: var(--muted); font-size: 0.9rem; }
.tile-arrow { color: var(--muted); }

/* P6: upload and history */
.upload { display: flex; flex-direction: column; gap: 16px; padding: 20px; }
.dropzone { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 28px 16px; border: 1.5px dashed var(--border-strong); border-radius: var(--radius); background: var(--surface-2); text-align: center; cursor: pointer; }
.dropzone:hover { border-color: var(--accent); }
.dropzone-icon { width: 28px; height: 28px; color: var(--accent-text); }
.dropzone-title { font-weight: 650; overflow-wrap: anywhere; }
.dropzone-hint { max-width: 52ch; color: var(--muted); font-size: 0.88rem; }
.form-actions { display: flex; justify-content: flex-end; }
.history { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.history-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px 6px 6px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.history-item form { margin: 0; }
.history-link { display: flex; flex: 1; align-items: center; gap: 12px; min-width: 0; padding: 6px; border-radius: var(--radius-sm); color: var(--text); }
.history-link:hover { background: var(--surface-2); text-decoration: none; }
.history-body { display: flex; flex-direction: column; min-width: 0; }
.history-title { overflow: hidden; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.history-meta { color: var(--muted); font-size: 0.85rem; }

/* Grades */
.grade { display: inline-grid; place-items: center; flex: none; border-radius: 10px; color: var(--grade-ink); font-weight: 800; letter-spacing: -0.02em; }
.grade-sm { width: 40px; height: 40px; font-size: 1rem; }
.grade-lg { width: 88px; height: 88px; border-radius: 18px; font-size: 2.4rem; }
.grade-Aplus { background: var(--grade-aplus); }
.grade-A { background: var(--grade-a); }
.grade-B { background: var(--grade-b); }
.grade-C { background: var(--grade-c); }
.grade-D { background: var(--grade-d); }

/* P6: result */
.head-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.head-actions form { margin: 0; }
.summary { display: grid; grid-template-columns: minmax(260px, 1fr) 2fr; gap: 16px; }
.grade-card { display: flex; align-items: center; gap: 20px; padding: 20px; }
.grade-label { color: var(--muted); font-size: 0.85rem; font-weight: 550; }
.grade-score { margin: 2px 0 10px; font-size: 1.05rem; }
.meter { display: grid; grid-template-columns: repeat(13, 1fr); gap: 3px; width: 100%; max-width: 220px; }
.meter-cell { height: 8px; border-radius: 2px; background: var(--border-strong); }
.meter-cell.is-met { background: var(--ok); }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 20px; margin: 0; padding: 16px 20px; }
.facts dt { color: var(--muted); font-size: 0.8rem; font-weight: 550; }
.facts dd { margin: 2px 0 0; font-weight: 600; overflow-wrap: anywhere; }
.notes { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.checks { overflow: hidden; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.check { display: grid; grid-template-columns: minmax(0, 1fr) 100px 120px 120px; align-items: center; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); }
.check-head { padding-top: 10px; padding-bottom: 10px; border-top: 0; background: var(--surface-2); color: var(--muted); font-size: 0.78rem; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; }
.check-group { padding: 10px 16px 6px; border-top: 1px solid var(--border); background: var(--surface-2); color: var(--muted); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; }
.check-name { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.check-detail { color: var(--muted); font-size: 0.86rem; }
.check-link { display: inline-flex; align-items: center; gap: 4px; width: fit-content; margin-top: 2px; font-size: 0.86rem; font-weight: 600; }
.check-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.check-target { color: var(--muted); }
.check .label { display: none; }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 3px 10px; border-radius: 999px; font-size: 0.82rem; font-weight: 650; white-space: nowrap; }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-bad { background: var(--bad-soft); color: var(--bad); }
.explain summary { padding: 16px 20px; font-weight: 650; cursor: pointer; }
.explain[open] summary { border-bottom: 1px solid var(--border); }
.explain-body { padding: 4px 20px 20px; }
.meanings { display: grid; gap: 12px; margin: 16px 0 0; }
.meanings dt { font-weight: 650; }
.meanings dd { margin: 2px 0 0; color: var(--muted); }
.explain-body ul { margin: 0; padding-left: 18px; color: var(--muted); }
.explain-body > .muted { margin-top: 16px; }

/* Lists */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.toolbar .search { max-width: 320px; }
.table-wrap { max-height: 75vh; overflow: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table th { position: sticky; top: 0; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2); color: var(--muted); font-weight: 650; text-align: left; white-space: nowrap; }
.table td { padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface-2); }

/* Phones and narrow windows: the sidebar becomes a drawer */
@media (max-width: 899px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: fixed; inset: 0 auto 0 0; z-index: 40; width: min(86vw, 300px); transform: translateX(-100%); transition: transform 0.2s ease; }
  .nav-open .sidebar { transform: none; box-shadow: 0 10px 40px rgb(0 0 0 / 25%); }
  .nav-close { display: inline-grid; }
  .backdrop { display: block; position: fixed; inset: 0; z-index: 30; background: rgb(15 20 25 / 45%); }
  .topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 8px; min-height: 56px; padding: env(safe-area-inset-top) 8px 0; border-bottom: 1px solid var(--border); background: var(--bg); }
  .topbar-title { overflow: hidden; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
  .content { padding: 20px 16px 48px; }
  h1 { font-size: 1.35rem; }
  .summary { grid-template-columns: minmax(0, 1fr); }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .check-head { display: none; }
  .check { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 12px; }
  .check-name { grid-column: 1 / -1; }
  .check .label { display: block; color: var(--muted); font-size: 0.72rem; font-weight: 650; letter-spacing: 0.04em; text-transform: uppercase; }
  .grade-lg { width: 72px; height: 72px; font-size: 2rem; }
  .page-head-row { align-items: flex-start; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar, .tile { transition: none; }
}
