:root {
  /* surfaces */
  --bg: #eef2f7;
  --bg-grad: radial-gradient(1200px 600px at 100% -10%, #e7eefb 0%, transparent 55%),
             radial-gradient(900px 500px at -10% 0%, #eef4ff 0%, transparent 50%),
             #eef2f7;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --ink: #0f1b2d;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #e6ebf2;
  --line-strong: #d4dce8;

  /* brand */
  --accent: #1e40af;
  --accent-2: #2563eb;
  --accent-soft: #eaf1ff;
  --accent-ink: #ffffff;
  --amber: #b45309;
  --amber-soft: #fff4e3;

  /* semantic */
  --ok-bg: #dcfce7; --ok-ink: #166534;
  --warn-bg: #fef3c7; --warn-ink: #92400e;
  --hi-bg: #fee2e2; --hi-ink: #991b1b;

  /* elevation */
  --shadow-sm: 0 1px 2px rgba(15,27,45,.05), 0 1px 1px rgba(15,27,45,.04);
  --shadow: 0 2px 8px -2px rgba(15,27,45,.10), 0 4px 18px -8px rgba(15,27,45,.14);
  --shadow-lg: 0 10px 40px -8px rgba(15,27,45,.22);

  --radius: 14px;
  --radius-sm: 9px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: var(--bg-grad);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
a { color: var(--accent-2); text-decoration: none; }
a:hover { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
  border-radius: 6px;
}

/* topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(255,255,255,.82);
  backdrop-filter: saturate(160%) blur(10px);
  -webkit-backdrop-filter: saturate(160%) blur(10px);
  border-bottom: 1px solid var(--line);
  padding: 13px 24px; box-shadow: var(--shadow-sm);
  position: sticky; top: 0; z-index: 30;
}
.brand { font-size: 17px; font-weight: 700; color: var(--ink); letter-spacing: -.01em; }
.brand span { color: var(--muted); font-weight: 500; }
.topbar nav a {
  margin-left: 8px; color: var(--muted); font-weight: 500; font-size: 13px;
  padding: 7px 12px; border-radius: 8px; transition: background .15s, color .15s;
}
.topbar nav a:hover { background: var(--accent-soft); color: var(--accent); }
main { padding: 24px; max-width: 1500px; margin: 0 auto; }

/* login */
.login-page { display: grid; place-items: center; min-height: 100dvh; background: var(--bg-grad); }
.login-card {
  background: var(--panel); padding: 38px 34px; border-radius: 18px;
  box-shadow: var(--shadow-lg); width: 330px; text-align: center;
  border: 1px solid var(--line);
}
.login-card h1 { margin: 0; font-size: 27px; letter-spacing: -.02em; }
.login-card .sub { margin: 4px 0 26px; color: var(--muted); letter-spacing: .14em; text-transform: uppercase; font-size: 11px; font-weight: 600; }
.login-card input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--line-strong); border-radius: 10px;
  font-size: 15px; margin-bottom: 14px; transition: border-color .15s, box-shadow .15s;
}
.login-card input:focus { outline: none; border-color: var(--accent-2); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card button {
  width: 100%; padding: 12px; border: 0; border-radius: 10px;
  background: linear-gradient(180deg, var(--accent-2), var(--accent));
  color: var(--accent-ink); font-size: 15px; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow-sm); transition: filter .15s, transform .05s;
}
.login-card button:hover { filter: brightness(1.06); }
.login-card button:active { transform: translateY(1px); }
.login-card .error { color: var(--hi-ink); background: var(--hi-bg); padding: 9px; border-radius: 9px; margin: 0 0 16px; font-size: 13px; }

/* filters */
.filters {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 15px; margin-bottom: 18px; box-shadow: var(--shadow);
}
.filters form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filters .search { flex: 1 1 320px; min-width: 240px; }
.filters input, .filters select {
  padding: 9px 11px; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  font-size: 13px; background: #fff; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
.filters input:focus, .filters select:focus {
  outline: none; border-color: var(--accent-2); box-shadow: 0 0 0 3px var(--accent-soft);
}
.filters select { cursor: pointer; }
.filters .datelbl { font-size: 12px; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.filters .clear {
  font-size: 13px; color: var(--muted); margin-left: auto; padding: 8px 12px;
  border-radius: var(--radius-sm); transition: background .15s, color .15s;
}
.filters .clear:hover { background: var(--panel-2); color: var(--ink); }

.count { color: var(--muted); margin: 2px 4px 12px; font-size: 13px; font-weight: 500; }

/* grid table */
.grid {
  width: 100%; border-collapse: separate; border-spacing: 0; background: var(--panel);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.grid thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); background: var(--panel-2); border-bottom: 1px solid var(--line-strong);
  padding: 12px; white-space: nowrap;
}
.grid thead th a { color: var(--muted); display: inline-flex; align-items: center; gap: 3px; transition: color .15s; }
.grid thead th a:hover { color: var(--ink); }
.grid thead th.sorted { color: var(--accent); }
.grid thead th.sorted a { color: var(--accent); }
.grid tbody td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.grid tbody tr:last-child td { border-bottom: 0; }
.grid tbody tr { cursor: pointer; transition: background .12s; }
.grid tbody tr:hover { background: var(--accent-soft); }
.grid .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-weight: 600; color: var(--accent); }
.grid .small { font-size: 12px; font-weight: 400; }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid .nowrap { white-space: nowrap; }
.grid .summary { max-width: 340px; color: var(--ink); }
.grid .empty { text-align: center; color: var(--muted); padding: 48px; cursor: default; font-size: 14px; }
.ver { background: var(--line); color: var(--muted); border-radius: 5px; padding: 1px 6px; margin-left: 6px; font-size: 11px; font-weight: 600; }

/* badges */
.badge {
  display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; white-space: nowrap; line-height: 1.4;
  border: 1px solid transparent;
}
.badge.ok { background: var(--ok-bg); color: var(--ok-ink); border-color: #bbf7d0; }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); border-color: #fde68a; }
.badge.hi { background: var(--hi-bg); color: var(--hi-ink); border-color: #fecaca; margin-left: 6px; }
.badge.muted { background: var(--panel-2); color: var(--muted); border-color: var(--line-strong); }
.badge.grade { font-family: ui-monospace, monospace; min-width: 28px; justify-content: center; font-weight: 700; }
.badge.grade-a { background: #dcfce7; color: #166534; border-color: #bbf7d0; }
.badge.grade-b { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.badge.grade-c { background: #fef9c3; color: #854d0e; border-color: #fde68a; }
.badge.grade-d { background: #ffedd5; color: #9a3412; border-color: #fed7aa; }
.badge.grade-f { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.badge.grade-n { background: var(--panel-2); color: var(--muted); border-color: var(--line-strong); }

/* detail */
.detail-wrap { display: grid; grid-template-columns: 1fr 300px; gap: 24px; align-items: start; }
.report {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 34px 38px; box-shadow: var(--shadow);
}
.report-actions { display: flex; justify-content: space-between; align-items: center; padding: 16px 0 6px; border-bottom: 1px solid var(--line); margin-bottom: 10px; }
.report-actions .back { font-weight: 600; color: var(--muted); }
.report-actions .back:hover { color: var(--ink); }
.report-actions .sn-link {
  font-weight: 600; font-size: 13px; padding: 7px 13px; border-radius: var(--radius-sm);
  background: var(--accent-soft); color: var(--accent); transition: background .15s;
}
.report-actions .sn-link:hover { background: #dbe7ff; }
.sidebar {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); position: sticky; top: 80px;
}
.sidebar h3 { margin: 0 0 12px; font-family: ui-monospace, monospace; font-size: 18px; color: var(--accent); letter-spacing: -.01em; }
.sidebar h4 { margin: 20px 0 9px; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--faint); font-weight: 600; }
.meta { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; margin: 0; font-size: 13px; }
.meta dt { color: var(--muted); }
.meta dd { margin: 0; font-weight: 500; }
.versions { list-style: none; padding: 0; margin: 0; }
.versions li { margin-bottom: 5px; }
.versions a { padding: 3px 8px; border-radius: 7px; display: inline-block; transition: background .15s; }
.versions a:hover { background: var(--panel-2); }
.versions a.current { font-weight: 700; background: var(--accent-soft); color: var(--accent); }
.versions .vdate { color: var(--muted); font-size: 12px; font-weight: 400; }

/* markdown body */
.markdown-body { font-size: 14.5px; }
.markdown-body h1 { font-size: 24px; border-bottom: 2px solid var(--line); padding-bottom: 9px; letter-spacing: -.01em; }
.markdown-body h2 { font-size: 19px; margin-top: 28px; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.markdown-body h3 { font-size: 16px; margin-top: 22px; }
.markdown-body table { border-collapse: collapse; width: 100%; margin: 14px 0; font-size: 13.5px; }
.markdown-body th, .markdown-body td { border: 1px solid var(--line); padding: 8px 11px; text-align: left; vertical-align: top; }
.markdown-body th { background: var(--panel-2); font-weight: 600; }
.markdown-body tr:nth-child(even) td { background: #fbfcfe; }
.markdown-body code { background: #eef2f8; padding: 1px 6px; border-radius: 5px; font-size: 12.5px; color: #b91c1c; }
.markdown-body pre { background: #0f172a; color: #e2e8f0; padding: 15px; border-radius: 10px; overflow-x: auto; }
.markdown-body pre code { background: none; color: inherit; padding: 0; }
.markdown-body blockquote { border-left: 3px solid var(--accent-2); margin: 14px 0; padding: 6px 16px; color: var(--muted); background: var(--panel-2); border-radius: 0 8px 8px 0; }

/* Collapsible report sections (server wraps each <h2> in <details>) */
.markdown-body details.report-section { border: 1px solid var(--line); border-radius: 12px; margin: 12px 0; background: var(--panel); overflow: hidden; box-shadow: var(--shadow-sm); }
.markdown-body details.report-section > summary {
  font-size: 18px; font-weight: 700; color: var(--ink); cursor: pointer; list-style: none;
  padding: 13px 16px; background: var(--panel-2); border-bottom: 1px solid transparent;
  display: flex; align-items: center; gap: 9px; user-select: none; transition: background .15s;
}
.markdown-body details.report-section > summary::-webkit-details-marker { display: none; }
.markdown-body details.report-section > summary::before {
  content: "▶"; font-size: 11px; color: var(--accent-2); transition: transform .18s ease; flex: none;
}
.markdown-body details.report-section[open] > summary::before { transform: rotate(90deg); }
.markdown-body details.report-section[open] > summary { border-bottom-color: var(--line); }
.markdown-body details.report-section:not([open]) > summary:hover { background: #eef2f8; }
.markdown-body details.report-section > .section-body { padding: 4px 18px 16px; }
.markdown-body details.report-section > .section-body > :first-child { margin-top: 8px; }
.markdown-body details.report-section h3 { margin-top: 18px; }
.report-toolbar { display: flex; gap: 10px; margin: 10px 0 6px; }
.report-toolbar button {
  font-size: 12.5px; color: var(--muted); background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 6px 12px; cursor: pointer; font-weight: 500; transition: background .15s, color .15s, border-color .15s;
}
.report-toolbar button:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-2); }

@media (max-width: 900px) {
  .detail-wrap { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  .grid thead th { position: static; }
  main { padding: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* --- Dashboard summary bar --- */
.statbar {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin: 0 0 16px;
}
.stat {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.stat-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}
.stat-value {
  font-size: 30px;
  font-weight: 700;
  line-height: 1.1;
  color: var(--ink);
}
.stat-value small { font-size: 15px; font-weight: 600; color: var(--faint); margin-left: 3px; }
.stat-value.grade { color: var(--accent); }
.stat-sub { font-size: 12px; color: var(--faint); }
.stat-empty { border-style: dashed; background: var(--panel-2); }
.stat-empty .stat-value { color: var(--faint); }
@media (max-width: 720px) { .statbar { grid-template-columns: 1fr; } }
