:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --surface-2: #f3f3f0;
  --ink: #0b0b0b;
  --ink-2: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --accent: #2a78d6;
  --accent-ink: #1c5cab;
  --accent-wash: #e8f1fc;
  --s1: #2a78d6;  /* examiner / allowed */
  --s2: #eb6834;  /* art unit / abandoned */
  --s3: #1baf7a;  /* tech center / pending */
  --good: #006300;
  --bad: #b42d2d;
  --warn-bg: #fff6e0;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.04);
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
    --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
    --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
    --accent: #3987e5; --accent-ink: #86b6ef; --accent-wash: #16263a;
    --s1: #3987e5; --s2: #d95926; --s3: #199e70;
    --good: #0ca30c; --bad: #e66767; --warn-bg: #2e2612;
    --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d; --surface: #1a1a19; --surface-2: #232321;
  --ink: #ffffff; --ink-2: #c3c2b7; --muted: #898781;
  --grid: #2c2c2a; --axis: #383835; --border: rgba(255, 255, 255, 0.10);
  --accent: #3987e5; --accent-ink: #86b6ef; --accent-wash: #16263a;
  --s1: #3987e5; --s2: #d95926; --s3: #199e70;
  --good: #0ca30c; --bad: #e66767; --warn-bg: #2e2612;
  --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--page); color: var(--ink);
  font: 15px/1.5 var(--font);
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 650; }
h1 { font-size: clamp(26px, 4vw, 36px); letter-spacing: -0.01em; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
p { margin: 0 0 0.75em; }
.wrap { max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.muted { color: var(--muted); }
.ink2 { color: var(--ink-2); }
.num { font-variant-numeric: tabular-nums; }
.hidden { display: none !important; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner { display: flex; align-items: center; gap: 16px; height: 60px; }
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); white-space: nowrap; }
.brand:hover { text-decoration: none; }
.brand svg { width: 28px; height: 28px; flex: none; }
.brand svg rect { fill: var(--accent); }
.brand svg path { stroke: #fff; stroke-width: 3; stroke-linecap: round; fill: none; }
.brand span { font-size: 15px; color: var(--ink-2); }
.brand b { color: var(--ink); }
.topbar .search { flex: 1; max-width: 440px; margin-left: auto; }
.icon-btn {
  flex: none; width: 36px; height: 36px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink-2); cursor: pointer; display: grid; place-items: center;
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linejoin: round; }
.icon-btn:hover { color: var(--ink); background: var(--surface-2); }
body.home .topbar .search { visibility: hidden; }

/* search combobox */
.search { position: relative; }
.search input {
  width: 100%; height: 40px; padding: 0 12px 0 38px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink);
  font: inherit; outline: none;
}
.search input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-wash); }
.search .glyph { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px;
  stroke: var(--muted); fill: none; stroke-width: 2; pointer-events: none; }
.search.lg input { height: 56px; font-size: 18px; padding-left: 48px; border-radius: 14px; box-shadow: var(--shadow); }
.search.lg .glyph { left: 17px; width: 20px; height: 20px; }
.results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 30;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.14); padding: 6px; margin: 0; list-style: none;
  max-height: min(420px, 70vh); overflow-y: auto;
}
.results li {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer;
}
.results li[aria-selected="true"], .results li:hover { background: var(--accent-wash); }
.results .r-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.results .r-meta { color: var(--muted); font-size: 13px; white-space: nowrap; }
.results .r-empty { color: var(--muted); cursor: default; }
.tag {
  display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px;
  font-size: 12px; font-weight: 600; background: var(--surface-2); color: var(--ink-2); white-space: nowrap;
}
.tag.on { background: var(--accent-wash); color: var(--accent-ink); }
.tag.off { color: var(--muted); }

/* home */
.hero { padding: 72px 0 40px; text-align: center; }
.hero h1 { font-size: clamp(30px, 5vw, 46px); margin-bottom: 12px; }
.hero p.lead { color: var(--ink-2); font-size: 18px; max-width: 640px; margin: 0 auto 28px; }
.hero .search { max-width: 640px; margin: 0 auto; text-align: left; }
.hero .hint { margin-top: 12px; color: var(--muted); font-size: 14px; }
.home-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin: 32px 0; }
.tc-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.tc-card { display: block; color: var(--ink); }
.tc-card:hover { text-decoration: none; border-color: var(--accent); }
.tc-card .tc-num { font-size: 22px; font-weight: 650; }

/* report header */
.crumbs { margin: 24px 0 8px; font-size: 14px; color: var(--muted); }
.crumbs a { color: var(--ink-2); }
.report-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 8px; }
.report-head .chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.report-head .actions { display: flex; gap: 8px; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--ink); font: inherit; font-size: 14px; cursor: pointer;
}
.btn:hover { background: var(--surface-2); text-decoration: none; }
.summary { font-size: 17px; color: var(--ink-2); max-width: 820px; margin: 12px 0 24px; }
.summary b { color: var(--ink); }
.notice { background: var(--warn-bg); border-radius: 10px; padding: 10px 14px; margin: 12px 0; font-size: 14px; }

/* stat tiles */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile, .card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.tile { padding: 14px 16px; }
.tile .label { font-size: 13px; color: var(--ink-2); }
.tile .value { font-size: 30px; font-weight: 650; line-height: 1.15; margin: 4px 0 2px; }
.tile .value small { font-size: 15px; font-weight: 500; color: var(--ink-2); }
.tile .sub { font-size: 13px; color: var(--muted); }
.delta { font-weight: 600; }
.delta.up { color: var(--good); }
.delta.down { color: var(--bad); }
.tile.hero-tile .value { font-size: 48px; }

/* cards & grid */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.span-12 { grid-column: span 12; } .span-8 { grid-column: span 8; } .span-7 { grid-column: span 7; }
.span-6 { grid-column: span 6; } .span-5 { grid-column: span 5; } .span-4 { grid-column: span 4; }
@media (max-width: 900px) { .grid > * { grid-column: span 12; } }
.card { padding: 18px 20px; min-width: 0; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 12px; }
.card-head p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex: none; }
.seg button {
  border: 0; background: transparent; color: var(--ink-2); font: inherit; font-size: 13px; padding: 4px 10px; cursor: pointer;
}
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); font-weight: 600; }
.chart { width: 100%; height: 320px; }
.chart.tall { height: 460px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 14px; height: 3px; border-radius: 2px; vertical-align: middle; margin-right: 6px; }
.legend i.sq { width: 10px; height: 10px; border-radius: 3px; }
.insight { border-left: 3px solid var(--accent); padding: 4px 0 4px 12px; margin: 12px 0 0; color: var(--ink-2); font-size: 14px; }

/* meter */
.meter { position: relative; height: 10px; border-radius: 99px; background: var(--accent-wash); margin: 10px 0 6px; }
.meter .fill { position: absolute; inset: 0 auto 0 0; border-radius: 99px; background: var(--accent); }
.meter .mark { position: absolute; top: -4px; width: 2px; height: 18px; background: var(--ink-2); border-radius: 1px; }
.meter-scale { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); }

/* tables */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--grid); vertical-align: middle; }
th { font-size: 12px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; white-space: nowrap; }
td.r, th.r { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:last-child td { border-bottom: 0; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--ink); }
th[aria-sort="ascending"]::after { content: " ▲"; }
th[aria-sort="descending"]::after { content: " ▼"; }
.bar-cell { width: 34%; min-width: 120px; }
.hbar { position: relative; height: 8px; background: var(--surface-2); border-radius: 99px; }
.hbar .fill { position: absolute; inset: 0 auto 0 0; background: var(--s1); border-radius: 99px; }
.hbar .tick { position: absolute; top: -3px; width: 2px; height: 14px; border-radius: 1px; }
.hbar .tick.au { background: var(--s2); }
.hbar .tick.tc { background: var(--s3); }
td .small { font-size: 12px; color: var(--muted); }
input.cost {
  width: 90px; height: 30px; padding: 0 8px; border-radius: 6px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); font: inherit; text-align: right; font-variant-numeric: tabular-nums;
}
tfoot td { font-weight: 650; border-top: 1px solid var(--axis); border-bottom: 0; }

details.method { margin: 8px 0 32px; }
details.method summary { cursor: pointer; font-weight: 600; padding: 8px 0; }
details.method dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; font-size: 14px; color: var(--ink-2); }
details.method dt { font-weight: 600; color: var(--ink); }
@media (max-width: 640px) { details.method dl { grid-template-columns: 1fr; } }

.footer { border-top: 1px solid var(--border); margin-top: 40px; padding: 24px 0 40px; color: var(--muted); font-size: 13px; }
.footer b { color: var(--ink-2); }

.skeleton { height: 120px; border-radius: var(--radius); background: linear-gradient(90deg, var(--surface-2), var(--surface), var(--surface-2)); background-size: 200% 100%; animation: sh 1.2s infinite; margin: 24px 0; }
@keyframes sh { to { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton { animation: none; } }

@media (max-width: 640px) {
  .brand span { display: none; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .tile { padding: 12px; }
  .card-head { flex-wrap: wrap; }
  .bar-cell { display: none; }
  th, td { padding: 7px 6px; }
  .report-head .actions { width: 100%; }
  .topbar-inner { gap: 10px; }
  .tile .value { font-size: 26px; }
  .tile.hero-tile .value { font-size: 40px; }
  .card { padding: 16px; }
  .chart { height: 280px; }
  .chart.tall { height: 420px; }
}

@media print {
  @page { margin: 14mm; }
  body { background: #fff; font-size: 12px; }
  .topbar, .report-head .actions, .seg, .footer a[href^="mailto"] { display: none !important; }
  .card, .tile { box-shadow: none; break-inside: avoid; }
  .grid { display: block; }
  .grid > * { margin-bottom: 12px; }
  details.method { display: block; }
  details.method > * { display: block; }
}
