:root {
  --bg: #0f172a;
  --bg-soft: #111c33;
  --card: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #1d4ed8;
  --brand-dark: #1e40af;
  --brand-soft: #eff4ff;
  --ok: #047857;
  --warn-bg: #fffbeb;
  --warn-ink: #92400e;
  --warn-line: #fcd34d;
  --err-bg: #fef2f2;
  --err-ink: #991b1b;
  --err-line: #fecaca;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--ink);
  background: #f1f5f9;
  line-height: 1.5;
}

.wrap { max-width: 1080px; margin: 0 auto; padding: 0 20px; }

.site-header {
  background: linear-gradient(135deg, var(--bg) 0%, var(--bg-soft) 100%);
  color: #fff;
  padding: 26px 0;
}
.site-header h1 { margin: 0; font-size: 1.55rem; letter-spacing: -0.01em; }
.tagline { margin: 4px 0 0; color: #94a3b8; font-size: 0.9rem; }

main.wrap { padding-top: 22px; padding-bottom: 48px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 18px 20px;
  margin-bottom: 18px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.grid { display: grid; gap: 16px; }
.top-grid { grid-template-columns: 1.4fr 1fr; }
@media (max-width: 620px) { .top-grid { grid-template-columns: 1fr; } }

.field { display: flex; flex-direction: column; }
.field > label { font-weight: 600; font-size: 0.85rem; margin-bottom: 6px; }
.req { color: #dc2626; }
.muted { color: var(--muted); font-weight: 400; }

input[type="text"], select {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 0.95rem;
  background: #fff;
  color: var(--ink);
}
input:focus, select:focus { outline: 2px solid rgba(29, 78, 216, 0.25); border-color: var(--brand); }

.year-range { display: flex; align-items: center; gap: 10px; }
.year-range select { flex: 1; }
.dash { color: var(--muted); font-size: 0.85rem; }

.hint { color: var(--muted); font-size: 0.78rem; margin-top: 5px; min-height: 1em; }

/* ratios multi-select */
.ratios-block { margin-top: 18px; }
.ratios-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.ratios-head label { font-weight: 600; font-size: 0.85rem; }
.ratio-actions { display: flex; gap: 12px; }
.link-btn { background: none; border: none; color: var(--brand); font-size: 0.82rem; cursor: pointer; padding: 0; }
.link-btn:hover { text-decoration: underline; }

.checkbox-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 6px 14px;
}
.ratio-check {
  display: flex; align-items: center; gap: 8px;
  font-size: 0.88rem; padding: 6px 8px; border-radius: 7px; cursor: pointer;
}
.ratio-check:hover { background: var(--brand-soft); }
.ratio-check input { width: 15px; height: 15px; accent-color: var(--brand); }

.actions { display: flex; align-items: center; gap: 14px; margin-top: 18px; flex-wrap: wrap; }
.inline-check { display: flex; align-items: center; gap: 6px; font-size: 0.85rem; color: var(--muted); }

button.primary {
  background: var(--brand); color: #fff; border: none; border-radius: 8px;
  padding: 11px 22px; font-size: 0.95rem; font-weight: 600; cursor: pointer;
}
button.primary:hover { background: var(--brand-dark); }
button.primary:disabled { opacity: 0.6; cursor: not-allowed; }

.status { color: var(--muted); font-size: 0.85rem; }
.spinner { width: 18px; height: 18px; border: 3px solid #cbd5e1; border-top-color: var(--brand); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }

/* matrix */
.matrix-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.matrix-head h3 { margin: 0; font-size: 1.05rem; }
.matrix-scroll { overflow-x: auto; border: 1px solid var(--line); border-radius: 10px; }
table.matrix { border-collapse: collapse; width: 100%; font-size: 0.88rem; }
table.matrix th, table.matrix td { padding: 9px 12px; text-align: right; white-space: nowrap; border-bottom: 1px solid #f1f5f9; }
table.matrix thead th { background: #f8fafc; position: sticky; top: 0; }
table.matrix th.corner, table.matrix th.rname { text-align: left; position: sticky; left: 0; background: #fff; z-index: 1; }
table.matrix thead th.corner { background: #f8fafc; z-index: 2; }
table.matrix th.yr { text-align: right; }
.yr .fye { display: block; font-weight: 700; color: var(--ink); }
.yr .fy { display: block; font-weight: 400; font-size: 0.72rem; color: var(--muted); }
a.fy-link { color: var(--brand); text-decoration: none; }
a.fy-link:hover { text-decoration: underline; }
a.ratios-link { display: block; font-size: 0.7rem; font-weight: 400; margin-top: 2px; color: var(--ok); }
th.rname { font-weight: 600; }
th.rname .unit { color: var(--muted); font-weight: 400; margin-left: 4px; }
td.val { font-variant-numeric: tabular-nums; cursor: pointer; }
td.val:hover { background: var(--brand-soft); }
td.val:focus { outline: 2px solid rgba(29,78,216,.35); }
td.na { color: #cbd5e1; }
.warnflag { color: #b45309; cursor: help; }
.bad { color: #b91c1c; font-weight: 400; font-size: 0.8rem; }
.click-hint { margin: 10px 2px 0; }

/* detail panel (reused by single result) */
.detail-card .result-head, .result-head {
  display: flex; justify-content: space-between; align-items: baseline;
  flex-wrap: wrap; gap: 8px; border-bottom: 1px solid var(--line);
  padding-bottom: 12px; margin-bottom: 12px;
}
.result-title { font-size: 1.1rem; font-weight: 700; margin: 0; }
.result-sub { color: var(--muted); font-size: 0.85rem; }
.result-value { font-size: 1.7rem; font-weight: 800; color: var(--brand-dark); }
table.audit { width: 100%; border-collapse: collapse; margin-top: 4px; }
table.audit th, table.audit td { text-align: left; padding: 7px 8px; font-size: 0.88rem; border-bottom: 1px solid #f1f5f9; vertical-align: top; }
table.audit th { color: var(--muted); font-weight: 600; width: 44%; }
.mono { font-variant-numeric: tabular-nums; font-family: "SF Mono", ui-monospace, Menlo, Consolas, monospace; }

.warnings { margin-top: 14px; background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink); border-radius: 8px; padding: 10px 12px; font-size: 0.85rem; }
.warnings ul { margin: 6px 0 0; padding-left: 18px; }

.error-card { background: var(--err-bg); border-color: var(--err-line); color: var(--err-ink); }
.error-card h3 { margin: 0 0 6px; font-size: 1rem; }
.error-card .code { font-family: ui-monospace, monospace; font-size: 0.8rem; opacity: 0.8; }

.notice-card { background: #f8fafc; }
.notice-card h3 { margin: 0 0 8px; font-size: 0.95rem; }
.notice-card p { margin: 0; color: var(--muted); font-size: 0.85rem; }

.site-footer { padding: 20px 0 40px; color: var(--muted); font-size: 0.8rem; }
.site-footer code { background: #e2e8f0; padding: 1px 5px; border-radius: 4px; }

/* pinning */
td.val { position: relative; }
td.val .pinbtn {
  border: none; background: none; cursor: pointer; font-size: 0.8rem;
  opacity: 0; margin-left: 6px; padding: 0 2px; vertical-align: middle; line-height: 1;
}
td.val:hover .pinbtn { opacity: 0.4; }
td.val .pinbtn:hover { opacity: 1; }
td.val.pinned { background: #fef9c3; }
td.val.pinned .pinbtn { opacity: 1; }

.pinned-card { border-color: #fcd34d; background: #fffdf5; }
.pinned-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.pinned-head h3 { margin: 0; font-size: 1.05rem; }
table.matrix td.l, table.matrix th.l { text-align: left; }
.pinval { cursor: pointer; }
.pinval:hover { background: var(--brand-soft); }

.detail-actions { margin-top: 14px; }
.pin-action {
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 14px; font-size: 0.85rem; cursor: pointer; color: var(--brand-dark); font-weight: 600;
}
.pin-action:hover { background: var(--brand-soft); }
.pin-action.active { background: #fef9c3; border-color: #fcd34d; color: #92400e; }
