/* ============================================================
   U.S. Policy Capital Tracker — 정부 돈 → 수주·금융지원 맵
   ============================================================ */

/* ---------- design tokens ---------- */
:root {
  color-scheme: light;

  --paper: #f3f5f9;
  --paper-2: #e9edf4;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --ink: #101821;
  --ink-2: #3a4756;
  --muted: #6c7a89;
  --faint: #93a0ad;
  --line: #e3e8ef;
  --line-2: #cdd6e0;

  --fund: #33589f;
  --fund-ink: #27467f;
  --fund-soft: #ebf1fb;
  --award: #99700f;
  --award-ink: #7d5b0c;
  --award-soft: #fbf3de;
  --rev: #11796a;
  --rev-ink: #0d6154;
  --rev-soft: #e2f4ef;
  --danger: #b13d3d;
  --danger-soft: #fdf1f1;
  --danger-line: #f0d2d2;

  --grad-fund: linear-gradient(135deg, #3d68bd 0%, #6d97e4 100%);
  --grad-award: linear-gradient(135deg, #b8871a 0%, #dcb254 100%);
  --grad-rev: linear-gradient(135deg, #14806f 0%, #4bb39c 100%);
  --grad-ink: linear-gradient(135deg, #1a2634 0%, #33475e 100%);
  --hero-wash:
    radial-gradient(1100px 460px at 12% -10%, rgba(77, 122, 205, .16), transparent 62%),
    radial-gradient(820px 420px at 92% 0%, rgba(196, 152, 46, .14), transparent 60%),
    radial-gradient(700px 400px at 60% 100%, rgba(28, 138, 118, .10), transparent 62%);

  --sh-1: 0 1px 2px rgba(16, 28, 44, .05), 0 1px 3px rgba(16, 28, 44, .04);
  --sh-2: 0 2px 6px rgba(16, 28, 44, .05), 0 10px 28px rgba(16, 28, 44, .07);
  --sh-3: 0 18px 50px rgba(16, 28, 44, .14);
  --ring: 0 0 0 3px rgba(51, 88, 159, .16);

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
  --r-xl: 24px;

  --mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: 'Pretendard', 'Noto Sans KR', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;

  --topbar-h: 62px;
}

[data-theme='dark'] {
  color-scheme: dark;

  --paper: #0c1117;
  --paper-2: #131b24;
  --panel: #151d27;
  --panel-2: #1a232e;
  --ink: #e7edf4;
  --ink-2: #b6c3d1;
  --muted: #8b9aab;
  --faint: #6d7d8e;
  --line: #26313d;
  --line-2: #35424f;

  --fund: #7ba4ec;
  --fund-ink: #a6c3f5;
  --fund-soft: #172436;
  --award: #dcb254;
  --award-ink: #ecc978;
  --award-soft: #2a2416;
  --rev: #4bc3a9;
  --rev-ink: #74d6c0;
  --rev-soft: #12291f;
  --danger: #e88b8b;
  --danger-soft: #2a1a1a;
  --danger-line: #43292a;

  --hero-wash:
    radial-gradient(1100px 460px at 12% -10%, rgba(77, 122, 205, .20), transparent 62%),
    radial-gradient(820px 420px at 92% 0%, rgba(196, 152, 46, .13), transparent 60%),
    radial-gradient(700px 400px at 60% 100%, rgba(28, 168, 143, .12), transparent 62%);

  --sh-1: 0 1px 2px rgba(0, 0, 0, .4);
  --sh-2: 0 2px 6px rgba(0, 0, 0, .35), 0 12px 30px rgba(0, 0, 0, .3);
  --sh-3: 0 20px 55px rgba(0, 0, 0, .5);
  --ring: 0 0 0 3px rgba(123, 164, 236, .25);
}

/* ---------- base ---------- */
* { box-sizing: border-box; }

html { background: var(--paper); scroll-behavior: smooth; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: none; border: 0; }
a { color: inherit; }
h1, h2, h3, h4 { margin: 0; letter-spacing: -.03em; line-height: 1.25; }
p { margin: 0; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--fund); outline-offset: 2px; }

.shell { width: min(1280px, calc(100% - 40px)); margin: 0 auto; }
.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap;
}
.num { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* inline icons never stretch to fill their flex line */
svg { flex: 0 0 auto; }
.btn svg { width: 14px; height: 14px; }
.source-link svg { width: 12px; height: 12px; }
.badge-direct svg, .match-yes svg { width: 10px; height: 10px; }
.status-line svg { width: 15px; height: 15px; vertical-align: -3px; }

/* custom scrollbars */
.scroll-thin { scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.scroll-thin::-webkit-scrollbar { width: 9px; height: 9px; }
.scroll-thin::-webkit-scrollbar-track { background: transparent; }
.scroll-thin::-webkit-scrollbar-thumb { border: 3px solid transparent; border-radius: 999px; background: var(--line-2); background-clip: content-box; }
.scroll-thin::-webkit-scrollbar-thumb:hover { background: var(--faint); background-clip: content-box; }

/* ---------- topbar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 40;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
}
.topbar-in { min-height: var(--topbar-h); display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; text-decoration: none; }
.brand-mark {
  display: grid; place-items: center; flex: 0 0 auto;
  width: 34px; height: 34px; border-radius: 11px;
  background: var(--grad-ink); color: #fff; box-shadow: var(--sh-1);
}
.brand-mark svg { width: 18px; height: 18px; }
.brand-txt { display: grid; gap: 1px; min-width: 0; }
.brand-kicker {
  color: var(--fund); font-family: var(--mono);
  font-size: 9.5px; font-weight: 600; letter-spacing: .14em;
}
.brand strong { overflow: hidden; font-size: 16.5px; letter-spacing: -.035em; text-overflow: ellipsis; white-space: nowrap; }
.brand-short { display: none; }
.topbar-actions { display: flex; flex: 0 0 auto; align-items: center; gap: 7px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 37px; padding: 8px 14px;
  border: 1px solid var(--line-2); border-radius: 999px;
  background: var(--panel); color: var(--ink-2);
  font-size: 12.5px; font-weight: 700; white-space: nowrap; text-decoration: none;
  transition: border-color .18s, background .18s, color .18s, transform .18s, box-shadow .18s;
}
.btn:hover { border-color: var(--fund); color: var(--fund-ink); transform: translateY(-1px); box-shadow: var(--sh-1); }
.btn:active { transform: translateY(0); }
.btn.primary { border-color: transparent; background: var(--grad-fund); color: #fff; box-shadow: var(--sh-1); }
.btn.primary:hover { color: #fff; filter: brightness(1.06); }
.btn.solid { border-color: transparent; background: var(--grad-ink); color: #fff; }
.btn.solid:hover { color: #fff; filter: brightness(1.15); }
.btn.icon { width: 37px; padding: 0; }
.btn.icon svg { width: 16px; height: 16px; }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn .btn-spin { width: 13px; height: 13px; border: 2px solid rgba(255, 255, 255, .38); border-top-color: #fff; border-radius: 50%; animation: spin .7s linear infinite; }

.icon-sun { display: none; }
[data-theme='dark'] .icon-sun { display: block; }
[data-theme='dark'] .icon-moon { display: none; }

/* ---------- route rail ---------- */
.route-rail { display: none; }

/* ---------- hero ---------- */
.hero { position: relative; overflow: hidden; border-bottom: 1px solid var(--line); }
.hero::before { position: absolute; inset: 0; content: ''; background: var(--hero-wash); pointer-events: none; }
.hero-in { position: relative; padding: 46px 0 34px; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 7px;
  color: var(--fund); font-family: var(--mono);
  font-size: 10px; font-weight: 600; letter-spacing: .13em;
}
.eyebrow::before { width: 16px; height: 1px; background: currentColor; content: ''; }
.hero h1 {
  max-width: 22ch; margin: 12px 0 12px;
  font-size: clamp(30px, 4.6vw, 50px); font-weight: 800;
  letter-spacing: -.052em; line-height: 1.12; word-break: keep-all;
}
.hero h1 .hl {
  background: linear-gradient(180deg, transparent 62%, color-mix(in srgb, var(--award) 32%, transparent) 62%);
  padding: 0 2px;
}
.lead { max-width: 62ch; color: var(--ink-2); font-size: 15.5px; word-break: keep-all; }

.flowrail {
  display: grid; grid-template-columns: 1fr auto 1fr auto 1fr;
  align-items: stretch; gap: 0; margin: 30px 0 0; padding: 0; list-style: none;
}
.fr {
  display: grid; gap: 3px; padding: 15px 17px;
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--panel) 78%, transparent);
  backdrop-filter: blur(6px); box-shadow: var(--sh-1);
}
.fr-n { font-family: var(--mono); font-size: 10px; font-weight: 600; letter-spacing: .1em; }
.fr b { font-size: 14.5px; letter-spacing: -.03em; }
.fr em { color: var(--muted); font-size: 11.5px; font-style: normal; word-break: keep-all; }
.fr.is-fund { border-left: 3px solid var(--fund); } .fr.is-fund .fr-n { color: var(--fund); }
.fr.is-award { border-left: 3px solid var(--award); } .fr.is-award .fr-n { color: var(--award); }
.fr.is-rev { border-left: 3px solid var(--rev); } .fr.is-rev .fr-n { color: var(--rev); }
.fr-arrow { display: grid; place-items: center; width: 42px; color: var(--faint); }
.fr-arrow svg { width: 20px; height: 20px; }

.method-note {
  display: flex; gap: 11px; align-items: flex-start;
  max-width: 640px; margin: 22px 0 0; padding: 13px 16px;
  border: 1px solid color-mix(in srgb, var(--award) 28%, var(--line));
  border-radius: var(--r-md); background: var(--award-soft);
  color: var(--award-ink); font-size: 12.5px; line-height: 1.65; word-break: keep-all;
}
.method-note svg { flex: 0 0 auto; width: 17px; height: 17px; margin-top: 2px; }

/* ---------- controls ---------- */
.controls {
  position: sticky; top: var(--topbar-h); z-index: 30;
  margin: 22px 0 0; padding: 15px 18px;
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: color-mix(in srgb, var(--panel) 88%, transparent);
  backdrop-filter: saturate(160%) blur(14px);
  -webkit-backdrop-filter: saturate(160%) blur(14px);
  box-shadow: var(--sh-2);
}
.control-row { display: flex; align-items: center; gap: 14px; }
.control-row + .control-row { margin-top: 12px; }
.control-label {
  flex: 0 0 auto; color: var(--faint); font-family: var(--mono);
  font-size: 10px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase;
}

.segmented {
  display: inline-flex; gap: 4px; padding: 4px;
  border: 1px solid var(--line); border-radius: 999px; background: var(--paper-2);
}
.segmented button {
  padding: 7px 17px; border-radius: 999px;
  color: var(--muted); font-size: 12.5px; font-weight: 700; white-space: nowrap;
  transition: background .2s, color .2s, box-shadow .2s;
}
.segmented button:hover { color: var(--ink); }
.segmented button.active { background: var(--panel); box-shadow: var(--sh-1); }
.segmented button.active[data-layer='contracts'] { color: var(--fund-ink); }
.segmented button.active[data-layer='financial'] { color: var(--award-ink); }

.chip-scroll { position: relative; min-width: 0; flex: 1; }
.chip-row {
  display: flex; gap: 7px; overflow-x: auto; padding: 2px 20px 3px 2px;
  scrollbar-width: none; scroll-snap-type: x proximity;
}
.chip-row::-webkit-scrollbar { display: none; }
.chip-scroll::after {
  position: absolute; top: 0; right: 0; bottom: 0; width: 28px; content: '';
  background: linear-gradient(to right, transparent, var(--panel) 82%);
  pointer-events: none;
}
.chip {
  flex: 0 0 auto; padding: 7px 13px; scroll-snap-align: start;
  border: 1px solid var(--line-2); border-radius: 999px;
  background: var(--panel); color: var(--ink-2);
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  transition: border-color .18s, background .18s, color .18s, transform .18s;
}
.chip:hover { border-color: var(--fund); color: var(--fund-ink); transform: translateY(-1px); }
.chip.active { border-color: transparent; background: var(--grad-ink); color: #fff; }

.search-row { display: grid; grid-template-columns: minmax(240px, 1fr) 150px 150px auto; gap: 8px; margin-top: 13px; }
.field { position: relative; min-width: 0; }
.field > svg { position: absolute; top: 50%; left: 12px; width: 15px; height: 15px; color: var(--faint); transform: translateY(-50%); pointer-events: none; }
.search-row input, .search-row select {
  width: 100%; min-height: 42px; padding: 9px 12px;
  border: 1px solid var(--line-2); border-radius: var(--r-md);
  background: var(--panel); font-size: 13.5px; outline: none;
  transition: border-color .18s, box-shadow .18s;
}
.search-row input { padding-left: 35px; }
.search-row select { appearance: none; padding-right: 30px; background-image: none; cursor: pointer; }
.field.select::after {
  position: absolute; top: 50%; right: 13px; width: 7px; height: 7px; content: '';
  border-right: 1.6px solid var(--faint); border-bottom: 1.6px solid var(--faint);
  transform: translateY(-70%) rotate(45deg); pointer-events: none;
}
.search-row input:focus, .search-row select:focus { border-color: var(--fund); box-shadow: var(--ring); }
.search-row input::placeholder { color: var(--faint); }

.preset-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 11px; }
.preset-row > span { color: var(--faint); font-family: var(--mono); font-size: 10px; letter-spacing: .08em; }
.preset {
  padding: 4px 10px; border: 1px dashed var(--line-2); border-radius: 999px;
  color: var(--muted); font-family: var(--mono); font-size: 10.5px; font-weight: 600;
  transition: border-color .18s, color .18s, background .18s;
}
.preset:hover { border-style: solid; border-color: var(--rev); background: var(--rev-soft); color: var(--rev-ink); }

/* ---------- loading / skeleton ---------- */
.status-wrap { padding: 34px 0 10px; }
.status-line {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  color: var(--muted); font-family: var(--mono); font-size: 12px; text-align: center;
}
.spinner {
  display: inline-block; width: 15px; height: 15px; flex: 0 0 auto;
  border: 2px solid var(--line-2); border-top-color: var(--fund);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 12px; margin-top: 26px; }
.skeleton-grid.wide { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
.sk {
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: var(--panel); overflow: hidden;
}
.sk-bar {
  height: 11px; margin: 14px 16px; border-radius: 999px;
  background: linear-gradient(90deg, var(--paper-2) 25%, var(--line) 37%, var(--paper-2) 63%);
  background-size: 400% 100%; animation: shimmer 1.35s ease infinite;
}
.sk-bar.tall { height: 26px; }
.sk-bar.w60 { width: 60%; } .sk-bar.w40 { width: 40%; } .sk-bar.w80 { width: 80%; }
.sk.block { min-height: 210px; }
@keyframes shimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- reveal ---------- */
.reveal { animation: rise .5s cubic-bezier(.2, .7, .3, 1) both; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- summary banner ---------- */
.summary-banner {
  position: relative; overflow: hidden;
  margin-top: 26px; padding: 24px 26px;
  border-radius: var(--r-xl); background: var(--grad-ink); color: #fff;
  box-shadow: var(--sh-2);
}
.summary-banner::after {
  position: absolute; top: -40%; right: -6%; width: 340px; height: 340px; content: '';
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 255, 255, .09), transparent 65%);
  pointer-events: none;
}
.summary-banner .eyebrow { color: #9fbde6; }
.summary-banner .eyebrow::before { background: currentColor; }
.summary-banner h2 { margin: 9px 0 8px; font-size: clamp(20px, 2.5vw, 27px); font-weight: 800; letter-spacing: -.045em; }
.summary-sentence { max-width: 76ch; color: #cdd8e4; font-size: 13.5px; word-break: keep-all; }
.summary-sentence b { color: #fff; font-weight: 700; }
.summary-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 15px; }
.meta-pill {
  padding: 5px 11px; border-radius: 999px;
  background: rgba(255, 255, 255, .1); color: #dce5ee;
  font-family: var(--mono); font-size: 10.5px; font-weight: 500;
}

/* ---------- KPI ---------- */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(215px, 1fr)); gap: 12px; margin-top: 14px; }
.kpi {
  position: relative; overflow: hidden;
  padding: 17px 18px 16px; border: 1px solid var(--line);
  border-radius: var(--r-lg); background: var(--panel); box-shadow: var(--sh-1);
  transition: transform .2s, box-shadow .2s;
}
.kpi:hover { transform: translateY(-2px); box-shadow: var(--sh-2); }
.kpi::before { position: absolute; inset: 0 0 auto 0; height: 3px; content: ''; background: var(--grad-fund); }
.kpi.is-award::before { background: var(--grad-award); }
.kpi.is-rev::before { background: var(--grad-rev); }
.kpi.is-ink::before { background: var(--grad-ink); }
.kpi-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 11.5px; font-weight: 600; }
.kpi-value { margin-top: 7px; font-family: var(--mono); font-size: 25px; font-weight: 600; letter-spacing: -.045em; line-height: 1.1; }
.kpi-sub { margin-top: 6px; color: var(--faint); font-size: 11px; word-break: keep-all; }

/* ---------- sections ---------- */
.step-section { margin-top: 46px; }
.section-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 22px; margin-bottom: 16px; }
.section-head-main { display: flex; align-items: center; gap: 13px; min-width: 0; }
.step-badge {
  display: grid; place-items: center; flex: 0 0 auto;
  width: 38px; height: 38px; border-radius: 13px;
  color: #fff; font-family: var(--mono); font-size: 12px; font-weight: 600;
  box-shadow: var(--sh-1);
}
.step-badge.is-fund { background: var(--grad-fund); }
.step-badge.is-award { background: var(--grad-award); }
.step-badge.is-rev { background: var(--grad-rev); }
.section-head h2 { font-size: clamp(18px, 2.2vw, 23px); font-weight: 800; }
.section-head .kicker { color: var(--faint); font-family: var(--mono); font-size: 10px; font-weight: 600; letter-spacing: .12em; }
.section-note { max-width: 46ch; color: var(--muted); font-size: 12px; text-align: right; word-break: keep-all; }

/* 데스크톱에서는 늘 펼쳐진 일반 섹션처럼, 좁은 화면에서만 접히는 헤더 */
.collapsible > summary { display: block; cursor: default; list-style: none; }
.collapsible > summary::-webkit-details-marker { display: none; }
.collapse-hint, .collapse-chevron { display: none; }

/* ---------- budget ---------- */
.budget-total {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px; margin-bottom: 12px; padding: 16px 18px;
  border: 1px solid var(--line); border-radius: var(--r-lg);
  background: linear-gradient(135deg, var(--fund-soft), color-mix(in srgb, var(--fund-soft) 30%, var(--panel)));
}
.budget-total div { display: grid; gap: 3px; min-width: 0; }
.budget-total span { color: var(--muted); font-size: 11px; font-weight: 600; }
.budget-total strong { font-family: var(--mono); font-size: 17px; letter-spacing: -.03em; }

.budget-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(268px, 1fr)); gap: 12px; }
.budget-card {
  display: flex; flex-direction: column;
  padding: 18px; border: 1px solid var(--line);
  border-radius: var(--r-lg); background: var(--panel); box-shadow: var(--sh-1);
  transition: transform .2s, box-shadow .2s, border-color .2s;
}
.budget-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--fund) 35%, var(--line)); box-shadow: var(--sh-2); }
.budget-card h3 { font-size: 15px; letter-spacing: -.03em; word-break: keep-all; }
.budget-fy { margin-top: 3px; color: var(--faint); font-family: var(--mono); font-size: 10px; }

.meter { margin-top: 15px; }
.meter-track {
  position: relative; height: 9px; overflow: hidden;
  border-radius: 999px; background: var(--paper-2);
}
.meter-fill { position: absolute; inset: 0 auto 0 0; border-radius: 999px; transition: width .7s cubic-bezier(.2, .8, .3, 1); }
.meter-fill.obligated { background: var(--grad-fund); opacity: .42; }
.meter-fill.outlayed { background: var(--grad-fund); }
.meter-legend { display: flex; flex-wrap: wrap; gap: 5px 14px; margin-top: 9px; }
.meter-legend span { display: inline-flex; align-items: center; gap: 5px; color: var(--muted); font-size: 11px; }
.meter-legend i { width: 8px; height: 8px; border-radius: 3px; background: var(--fund); }
.meter-legend i.soft { opacity: .42; }
.meter-legend b { color: var(--ink); font-family: var(--mono); font-size: 11.5px; }

.budget-metrics { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line); }
.budget-metrics div { min-width: 0; }
.budget-metrics span { display: block; overflow: hidden; color: var(--faint); font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.budget-metrics strong { display: block; margin-top: 2px; overflow: hidden; font-family: var(--mono); font-size: 13px; letter-spacing: -.03em; text-overflow: ellipsis; white-space: nowrap; }
.source-link {
  display: inline-flex; align-self: flex-start; align-items: center; gap: 5px; margin-top: auto; padding-top: 15px;
  color: var(--fund); font-family: var(--mono); font-size: 10.5px; font-weight: 600; text-decoration: none;
}
.source-link:hover { text-decoration: underline; }

/* ---------- award workspace ---------- */
.workspace { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); gap: 16px; align-items: start; }

.list-pane { display: flex; flex-direction: column; min-width: 0; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--panel); box-shadow: var(--sh-1); }
.list-bar { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line); }
.list-bar .field { flex: 1; }
.list-bar input {
  width: 100%; min-height: 36px; padding: 7px 11px 7px 33px;
  border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--panel-2); font-size: 12.5px; outline: none;
}
.list-bar input:focus { border-color: var(--fund); box-shadow: var(--ring); }
.list-count { padding: 9px 15px 0; color: var(--faint); font-family: var(--mono); font-size: 10.5px; }
.award-list { display: grid; gap: 8px; align-content: start; max-height: 640px; overflow-y: auto; padding: 10px 12px 14px; }

.award-card {
  position: relative; width: 100%; overflow: hidden;
  padding: 13px 15px 12px; border: 1px solid var(--line);
  border-radius: var(--r-md); background: var(--panel);
  text-align: left; transition: border-color .18s, box-shadow .18s, transform .18s, background .18s;
}
.award-card::before {
  position: absolute; inset: 0 auto 0 0; width: 3px; content: '';
  background: var(--grad-award); opacity: 0; transition: opacity .18s;
}
.award-card:hover { border-color: color-mix(in srgb, var(--award) 45%, var(--line)); transform: translateX(2px); box-shadow: var(--sh-1); }
.award-card.selected { border-color: var(--award); background: color-mix(in srgb, var(--award-soft) 55%, var(--panel)); box-shadow: var(--sh-2); }
.award-card.selected::before { opacity: 1; }
.award-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tag-row { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; min-width: 0; }
.tag {
  padding: 2.5px 7px; border-radius: 5px;
  background: var(--paper-2); color: var(--muted);
  font-family: var(--mono); font-size: 9.5px; font-weight: 600; white-space: nowrap;
}
.tag.type { background: var(--award-soft); color: var(--award-ink); }
.tag.grant { background: var(--rev-soft); color: var(--rev-ink); }
.tag.loan { background: color-mix(in srgb, var(--danger-soft) 80%, var(--panel)); color: var(--danger); }
.tag.ticker { background: var(--rev-soft); color: var(--rev-ink); font-weight: 700; }
.award-date { flex: 0 0 auto; color: var(--faint); font-family: var(--mono); font-size: 9.5px; white-space: nowrap; }
.award-recipient { margin-top: 7px; font-size: 13.5px; font-weight: 700; letter-spacing: -.025em; word-break: break-word; }
.award-desc {
  display: -webkit-box; margin-top: 3px; overflow: hidden;
  color: var(--muted); font-size: 11.5px; line-height: 1.5;
  -webkit-box-orient: vertical; -webkit-line-clamp: 2;
}
.award-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.award-agency { overflow: hidden; color: var(--faint); font-size: 10.5px; text-overflow: ellipsis; white-space: nowrap; }
.award-amount { flex: 0 0 auto; font-family: var(--mono); font-size: 13px; font-weight: 600; letter-spacing: -.03em; }
.award-bar { height: 3px; margin-top: 9px; overflow: hidden; border-radius: 999px; background: var(--paper-2); }
.award-bar i { display: block; height: 100%; border-radius: 999px; background: var(--grad-award); transition: width .6s cubic-bezier(.2, .8, .3, 1); }

/* ---------- detail pane ---------- */
.detail-pane { position: sticky; top: calc(var(--topbar-h) + 14px); min-width: 0; }
.detail-card { overflow: hidden; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--panel); box-shadow: var(--sh-2); }
.detail-head { padding: 18px 20px 16px; background: linear-gradient(160deg, var(--award-soft), transparent 80%); border-bottom: 1px solid var(--line); }
.detail-head .tag-row { margin-bottom: 9px; }
.detail-head h3 { font-size: 18px; font-weight: 800; letter-spacing: -.035em; word-break: break-word; }
.detail-head p { margin-top: 7px; color: var(--muted); font-size: 12px; word-break: keep-all; }

.stage-list { padding: 6px 20px 4px; }
.stage {
  position: relative; display: grid; grid-template-columns: 30px 1fr; gap: 13px;
  padding: 16px 0 16px;
}
.stage + .stage::before {
  position: absolute; top: -8px; left: 14.5px; width: 1px; height: 16px; content: '';
  background: repeating-linear-gradient(to bottom, var(--line-2) 0 3px, transparent 3px 6px);
}
.stage-icon {
  display: grid; place-items: center; width: 30px; height: 30px;
  border-radius: 10px; color: #fff; font-family: var(--mono); font-size: 10.5px; font-weight: 600;
}
.stage-icon.is-fund { background: var(--grad-fund); }
.stage-icon.is-award { background: var(--grad-award); }
.stage-icon.is-rev { background: var(--grad-rev); }
.stage-body { min-width: 0; }
.stage-kicker { font-family: var(--mono); font-size: 9.5px; font-weight: 600; letter-spacing: .1em; }
.stage-kicker.is-fund { color: var(--fund); }
.stage-kicker.is-award { color: var(--award); }
.stage-kicker.is-rev { color: var(--rev); }
.stage-body h4 { margin-top: 4px; font-size: 14.5px; font-weight: 700; word-break: break-word; }
.stage-body > p { margin-top: 5px; color: var(--muted); font-size: 11.5px; word-break: keep-all; }
.stage-figure { margin-top: 11px; }
.stage-figure span { display: block; color: var(--faint); font-size: 10.5px; }
.stage-figure strong { display: block; margin-top: 1px; font-family: var(--mono); font-size: 22px; font-weight: 600; letter-spacing: -.045em; }
.stage-figure small { display: block; margin-top: 2px; color: var(--faint); font-size: 10.5px; }
.kv { display: grid; gap: 6px; margin-top: 12px; }
.kv div { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.kv span { color: var(--muted); font-size: 11.5px; }
.kv b { flex: 0 0 auto; font-family: var(--mono); font-size: 12px; font-weight: 600; text-align: right; }
.badge-direct {
  display: inline-flex; align-items: center; gap: 5px; margin-top: 8px;
  padding: 3px 9px; border-radius: 999px;
  background: var(--rev-soft); color: var(--rev-ink);
  font-family: var(--mono); font-size: 9.5px; font-weight: 700;
}

/* scale comparison */
.scale-block { margin: 4px 20px 16px; padding: 15px 16px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--panel-2); }
.scale-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; color: var(--ink-2); font-size: 12px; font-weight: 700; }
.scale-rows { display: grid; gap: 11px; margin-top: 12px; }
.scale-row { display: grid; gap: 5px; }
.scale-row .lbl { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; color: var(--muted); font-size: 11px; }
.scale-row .lbl b { color: var(--ink); font-family: var(--mono); font-size: 11.5px; }
.scale-track { height: 8px; overflow: hidden; border-radius: 999px; background: var(--paper-2); }
.scale-track i { display: block; height: 100%; border-radius: 999px; transition: width .7s cubic-bezier(.2, .8, .3, 1); }
.scale-track i.is-award { background: var(--grad-award); }
.scale-track i.is-outlay { background: var(--grad-fund); }
.scale-track i.is-rev { background: var(--grad-rev); }
.scale-foot { margin-top: 11px; color: var(--faint); font-size: 10.5px; line-height: 1.55; word-break: keep-all; }

.caution {
  display: flex; gap: 9px; margin: 0 20px 16px; padding: 12px 14px;
  border-left: 3px solid var(--award); border-radius: 0 var(--r-sm) var(--r-sm) 0;
  background: var(--award-soft); color: var(--award-ink);
  font-size: 11.5px; line-height: 1.6; word-break: keep-all;
}
.caution svg { flex: 0 0 auto; width: 15px; height: 15px; margin-top: 2px; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 20px 20px; }
.detail-actions .btn { min-height: 34px; font-size: 11.5px; }

.empty {
  display: grid; gap: 8px; place-items: center;
  padding: 46px 22px; border: 1px dashed var(--line-2);
  border-radius: var(--r-lg); color: var(--muted); font-size: 12.5px; text-align: center;
}
.empty svg { width: 26px; height: 26px; color: var(--faint); }
.empty b { color: var(--ink); font-size: 13.5px; }

/* ---------- recipient table ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--panel); box-shadow: var(--sh-1); }
table { width: 100%; min-width: 760px; border-collapse: collapse; }
th, td { padding: 13px 16px; border-bottom: 1px solid var(--line); font-size: 12.5px; text-align: right; white-space: nowrap; }
thead th {
  position: sticky; top: 0; z-index: 1;
  background: var(--panel-2); color: var(--muted);
  font-family: var(--mono); font-size: 10px; font-weight: 600; letter-spacing: .04em;
}
th.sortable { cursor: pointer; user-select: none; transition: color .18s; }
th.sortable:hover { color: var(--ink); }
th .arrow { display: inline-block; margin-left: 4px; opacity: .35; }
th.sorted .arrow { opacity: 1; }
th:first-child, td:first-child { text-align: left; white-space: normal; }
tbody tr { transition: background .15s; }
tbody tr:hover { background: var(--panel-2); }
tbody tr:last-child td { border-bottom: none; }
.cell-name { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; font-weight: 600; }
.cell-bar { position: relative; }
.cell-bar i {
  position: absolute; right: 16px; bottom: 6px; height: 3px;
  border-radius: 999px; background: var(--grad-award); opacity: .6;
}
.cell-bar.outlay i { background: var(--grad-fund); }
.match-yes { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px; border-radius: 999px; background: var(--rev-soft); color: var(--rev-ink); font-family: var(--mono); font-size: 10px; font-weight: 700; }
.match-no { color: var(--faint); font-size: 11px; }
.row-link { color: inherit; font: inherit; text-align: left; text-decoration: none; border-bottom: 1px dotted var(--line-2); }
.row-link:hover { color: var(--fund-ink); border-bottom-color: var(--fund); }

/* ---------- glossary / notices / footer ---------- */
.glossary { margin-top: 34px; border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--panel); overflow: hidden; }
.glossary > summary {
  display: flex; align-items: center; gap: 9px; padding: 15px 18px;
  font-size: 13.5px; font-weight: 700; cursor: pointer; list-style: none;
}
.glossary > summary::-webkit-details-marker { display: none; }
.glossary > summary::after {
  margin-left: auto; width: 8px; height: 8px; content: '';
  border-right: 1.7px solid var(--faint); border-bottom: 1.7px solid var(--faint);
  transform: rotate(45deg) translateY(-2px); transition: transform .22s;
}
.glossary[open] > summary::after { transform: rotate(225deg) translateY(-2px); }
.glossary > summary svg { width: 16px; height: 16px; color: var(--fund); }
.glossary-body { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 12px; padding: 0 18px 18px; }
.gloss-item { padding: 13px 15px; border: 1px solid var(--line); border-radius: var(--r-md); background: var(--panel-2); }
.gloss-item dt { font-size: 12.5px; font-weight: 700; }
.gloss-item dd { margin: 5px 0 0; color: var(--muted); font-size: 11.5px; line-height: 1.6; word-break: keep-all; }

.callout { margin-top: 24px; padding: 15px 17px; border-radius: var(--r-md); font-size: 12.5px; line-height: 1.65; word-break: keep-all; }
.callout strong { display: block; margin-bottom: 5px; font-size: 12.5px; }
.callout ul { margin: 6px 0 0; padding-left: 18px; }
.callout li + li { margin-top: 3px; }
.notices { border: 1px solid color-mix(in srgb, var(--fund) 26%, var(--line)); background: var(--fund-soft); color: var(--fund-ink); }
.errors { border: 1px solid var(--danger-line); background: var(--danger-soft); color: var(--danger); }

.page-footer {
  margin: 42px 0 0; padding: 22px 0 60px; border-top: 1px solid var(--line);
  color: var(--faint); font-size: 11px; line-height: 1.8; word-break: keep-all;
}
.page-footer a { color: var(--fund); text-decoration: none; }
.page-footer a:hover { text-decoration: underline; }

/* ---------- toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; z-index: 60;
  padding: 11px 20px; border-radius: 999px;
  background: var(--grad-ink); color: #fff;
  font-size: 12.5px; font-weight: 600; box-shadow: var(--sh-3);
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- back to top ---------- */
.to-top {
  position: fixed; right: 22px; bottom: 22px; z-index: 35;
  display: grid; place-items: center; width: 42px; height: 42px;
  border: 1px solid var(--line-2); border-radius: 50%;
  background: var(--panel); color: var(--ink-2); box-shadow: var(--sh-2);
  opacity: 0; transform: translateY(10px); pointer-events: none;
  transition: opacity .25s, transform .25s, border-color .2s, color .2s;
}
.to-top.show { opacity: 1; transform: none; pointer-events: auto; }
.to-top:hover { border-color: var(--fund); color: var(--fund); }
.to-top svg { width: 17px; height: 17px; }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .workspace { grid-template-columns: 1fr; }
  .detail-pane { position: static; }
  .award-list { max-height: 440px; }
  .skeleton-grid.wide { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .flowrail { grid-template-columns: 1fr; gap: 0; }
  .fr-arrow { width: 100%; height: 26px; }
  .fr-arrow svg { transform: rotate(90deg); }
  .section-head { align-items: flex-start; flex-direction: column; gap: 9px; }
  .section-note { max-width: none; text-align: left; }
  .search-row { grid-template-columns: 1fr 1fr; }
  .search-row .field.q { grid-column: 1 / -1; }
  .search-row .btn { grid-column: 1 / -1; }
}

@media (max-width: 720px) {
  :root { --topbar-h: 56px; }
  .shell { width: min(100% - 26px, 720px); }
  .brand strong { font-size: 14.5px; }
  .brand-kicker, .brand-long { display: none; }
  .brand-short { display: inline; }
  .hide-sm { display: none; }
  .route-rail { display: block; border-bottom: 1px solid var(--line); background: var(--panel); }
  .route-rail-in { display: flex; gap: 7px; overflow-x: auto; padding: 8px 0; scrollbar-width: none; }
  .route-rail-in::-webkit-scrollbar { display: none; }
  .route-rail a { flex: 0 0 auto; padding: 6px 10px; border: 1px solid var(--line-2); border-radius: 999px; background: var(--panel); color: var(--ink-2); font-size: 11.5px; font-weight: 700; text-decoration: none; white-space: nowrap; }
  .route-rail a:hover { border-color: var(--fund); color: var(--fund-ink); }
  .hero-in { padding: 30px 0 24px; }
  .lead { font-size: 14px; }
  .controls { position: static; padding: 13px; }
  .control-row { align-items: flex-start; flex-direction: column; gap: 8px; }
  .control-row > .chip-scroll, .control-row > .segmented { width: 100%; }
  .segmented button { flex: 1; padding: 8px 10px; }
  .summary-banner { padding: 20px; border-radius: var(--r-lg); }
  .kpi-value { font-size: 22px; }
  .step-section { margin-top: 34px; }
  .budget-metrics { grid-template-columns: repeat(3, 1fr); gap: 6px; }

  .collapsible > summary { cursor: pointer; -webkit-tap-highlight-color: transparent; }
  .collapsible > summary:focus-visible { outline: 2px solid var(--fund); outline-offset: 3px; border-radius: var(--r-md); }
  .collapsible > summary .section-head-main { width: 100%; }
  .collapsible:not([open]) > summary .section-head { margin-bottom: 0; }
  .collapsible:not([open]) > summary .section-note { display: none; }
  .collapse-hint {
    display: inline-block; margin-left: auto; flex: 0 0 auto;
    color: var(--faint); font-family: var(--mono); font-size: 10.5px; white-space: nowrap;
  }
  .collapse-chevron {
    display: block; width: 8px; height: 8px; margin-left: 12px; flex: 0 0 auto;
    border-right: 1.8px solid var(--faint); border-bottom: 1.8px solid var(--faint);
    transform: rotate(45deg) translateY(-2px); transition: transform .22s;
  }
  .collapsible[open] > summary .collapse-chevron { transform: rotate(225deg) translateY(-2px); }

  .stage-list, .scale-block, .caution, .detail-actions { margin-left: 0; margin-right: 0; }
  .stage-list { padding: 4px 16px; }
  .scale-block { margin: 4px 16px 14px; }
  .caution { margin: 0 16px 14px; }
  .detail-actions { padding: 0 16px 16px; }
  .detail-head { padding: 16px; }
  .to-top { right: 14px; bottom: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}
