/* Grants Management — styles matched to the Portfolio Site (light + dark).
   Colors are the same tokens the Portfolio Site uses; --fee and --fee-soft mark the fees-only panel. */
:root {
  color-scheme: light;
  --page: #f6f6f3; --surface: #ffffff; --surface-2: #f9f9f7; --surface-3: #f0efec;
  --ink: #111110; --ink-2: #52514e; --muted: #7a7873; --line: #e4e3dd; --line-strong: #c9c8c0;
  --brand: #1f3a5f; --brand-ink: #ffffff; --accent: #2a78d6; --accent-soft: #e8f1fc;
  --neg: #b42318; --good: #006300;
  --warn-bg: #fff6e0; --warn-ink: #7a4b00; --err-bg: #fdecec; --err-ink: #8f1d1d;
  --ok-bg: #e9f6ea; --ok-ink: #1e5e22; --info-bg: #eaf2fc; --info-ink: #184f95;
  --fee: #8a5a00; --fee-soft: #fff6e0;
  --shadow: 0 1px 2px rgba(17, 17, 16, .05), 0 1px 1px rgba(17, 17, 16, .03);
  --radius: 10px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", "PingFang SC", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0f0f0e; --surface: #1a1a19; --surface-2: #202020; --surface-3: #2a2a28;
    --ink: #f4f4f1; --ink-2: #c3c2b7; --muted: #9a988f; --line: #2f2f2c; --line-strong: #44443f;
    --brand: #2c4f7c; --accent: #5598e7; --accent-soft: #1b2c42; --neg: #f08a80; --good: #0ca30c;
    --warn-bg: #3a2d10; --warn-ink: #f5d38a; --err-bg: #3b1717; --err-ink: #f5b5b0;
    --ok-bg: #16301a; --ok-ink: #9fdca6; --info-bg: #15263c; --info-ink: #a9c9f2;
    --fee: #f5d38a; --fee-soft: #3a2d10; --shadow: none;
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0f0f0e; --surface: #1a1a19; --surface-2: #202020; --surface-3: #2a2a28;
  --ink: #f4f4f1; --ink-2: #c3c2b7; --muted: #9a988f; --line: #2f2f2c; --line-strong: #44443f;
  --brand: #2c4f7c; --accent: #5598e7; --accent-soft: #1b2c42; --neg: #f08a80; --good: #0ca30c;
  --warn-bg: #3a2d10; --warn-ink: #f5d38a; --err-bg: #3b1717; --err-ink: #f5b5b0;
  --ok-bg: #16301a; --ok-ink: #9fdca6; --info-bg: #15263c; --info-ink: #a9c9f2;
  --fee: #f5d38a; --fee-soft: #3a2d10; --shadow: none;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--page); color: var(--ink); font: 14px/1.45 var(--font); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h1 { font-size: 22px; font-weight: 650; }
h2 { font-size: 15px; font-weight: 650; }
h3 { font-size: 11px; font-weight: 650; margin: 16px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- shell: navy top bar, white sidebar (same as the Portfolio Site) ---------- */
.topbar { position: sticky; top: 0; z-index: 30; height: 56px; display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--brand); color: var(--brand-ink); }
.brand { display: flex; align-items: center; gap: 10px; color: var(--brand-ink); min-width: 0; }
.brand:hover { text-decoration: none; }
.brand-logo { width: 24px; height: 34px; border-radius: 4px; flex: none; object-fit: cover; box-shadow: 0 0 0 1px rgba(255,255,255,.3); }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-text small { font-size: 11px; opacity: .75; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.icon-btn { background: transparent; border: 1px solid rgba(255,255,255,.25); color: var(--brand-ink); border-radius: 8px; width: 34px; height: 34px; cursor: pointer; font-size: 15px; }
.nav-toggle { display: none; background: transparent; border: 0; color: var(--brand-ink); font-size: 20px; cursor: pointer; }
.user-menu { position: relative; }
.user-menu summary { list-style: none; display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 8px; border-radius: 8px; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu summary:hover { background: rgba(255,255,255,.1); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: rgba(255,255,255,.2); display: grid; place-items: center; font-weight: 650; font-size: 12px; }
.uname { font-size: 13px; }
.user-menu .menu { position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; min-width: 240px; box-shadow: 0 8px 24px rgba(0,0,0,.15); padding: 6px; }
.user-menu .menu a, .user-menu .menu button { display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 6px; color: var(--ink); background: none; border: 0; font: inherit; cursor: pointer; }
.user-menu .menu a:hover, .user-menu .menu button:hover { background: var(--surface-3); text-decoration: none; }
.user-menu .menu form { margin: 0; }
.menu-head { padding: 8px 10px; font-size: 12px; color: var(--muted); border-bottom: 1px solid var(--line); margin-bottom: 4px; }
.shell { display: flex; min-height: calc(100vh - 56px); }
.sidebar { width: 228px; flex: none; background: var(--surface); border-right: 1px solid var(--line); padding: 12px 10px; position: sticky; top: 56px; height: calc(100vh - 56px); overflow-y: auto; }
.sidebar a { display: block; padding: 7px 10px; border-radius: 7px; color: var(--ink-2); font-size: 13.5px; }
.sidebar a:hover { background: var(--surface-3); text-decoration: none; color: var(--ink); }
.sidebar a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-section { text-transform: uppercase; letter-spacing: .07em; font-size: 10.5px; color: var(--muted); padding: 14px 10px 4px; }
.nav-foot { font-size: 11px; color: var(--muted); padding: 18px 10px 6px; }
.content { flex: 1; min-width: 0; padding: 20px 24px 48px; }
@media (max-width: 900px) {
  .nav-toggle { display: block; }
  .sidebar { position: fixed; left: 0; top: 56px; z-index: 25; transform: translateX(-100%); transition: transform .2s ease; box-shadow: 4px 0 18px rgba(0,0,0,.12); }
  body.nav-open .sidebar { transform: none; }
  .content { padding: 16px; }
  .uname { display: none; }
  .brand-text small { display: none; }
}

/* ---------- sign-in and installer ---------- */
body.bare { min-height: 100vh; display: grid; place-items: center; background: var(--page); }
.bare-wrap { width: 100%; max-width: 380px; padding: 24px 16px; }
.bare-wrap.wide { max-width: 620px; }
.bare-card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 26px 24px; box-shadow: 0 10px 30px rgba(0,0,0,.08); }
.bare-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.bare-brand div { display: flex; flex-direction: column; }
.bare-brand small { color: var(--muted); font-size: 12px; }
.bare-title { font-size: 19px; margin-bottom: 12px; }
.bare-note { text-align: center; font-size: 11.5px; color: var(--muted); margin-top: 14px; }
.bare-card p { margin: 0 0 12px; }

/* Page header */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 16px; }
.card.fee { border-color: color-mix(in srgb, var(--fee) 45%, var(--line)); }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 10px; }
.card-head h2 { margin: 0; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.grid-tiles { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; box-shadow: var(--shadow); }
.tile .label { color: var(--ink-2); font-size: 12px; }
.tile .value { font-size: 22px; font-weight: 650; letter-spacing: -.01em; margin-top: 2px; font-variant-numeric: tabular-nums; }
.tile.fee .value { color: var(--fee); }
@media (max-width: 520px) { .grid-2 { grid-template-columns: 1fr; } }

/* Buttons and forms (Portfolio Site style) */
.btn, button.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 32px; padding: 5px 12px; border-radius: 7px; border: 1px solid var(--line-strong); background: var(--surface); color: var(--ink); font: inherit; font-size: 13px; font-weight: 550; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #172d4a; }
.btn.danger { color: var(--neg); border-color: currentColor; }
.btn.small { min-height: 26px; padding: 2px 9px; font-size: 12px; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; font-size: 12px; }
label { display: block; font-size: 12.5px; color: var(--ink-2); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=email], input[type=number], input[type=date], input[type=search], input[type=file], select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 7px; padding: 6px 8px; min-height: 32px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
input[readonly] { background: var(--surface-3); color: var(--ink-2); }
textarea { min-height: 80px; resize: vertical; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px 16px; }
.form-grid .wide { grid-column: 1 / -1; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13.5px; color: var(--ink); }
.check input { width: auto; min-height: auto; }
.form-actions { display: flex; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
.help { font-size: 12px; color: var(--muted); margin-top: 3px; }
.calc-tag { font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-left: 4px; font-weight: normal; }
.filters { display: flex; gap: 10px 12px; flex-wrap: wrap; align-items: flex-end; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin-bottom: 16px; box-shadow: var(--shadow); }
.filters > div { min-width: 160px; flex: 1; max-width: 260px; }
.filters label { font-size: 11.5px; color: var(--muted); }
.filters .grow { max-width: 360px; }

/* Tables */
.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); max-height: 72vh; }
table.data { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
table.data th, table.data td { padding: 6px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
table.data th { position: sticky; top: 0; background: var(--surface-2); font-size: 11.5px; color: var(--ink-2); font-weight: 600; z-index: 1; white-space: nowrap; }
table.data th a { color: inherit; }
table.data tbody tr:hover td { background: color-mix(in srgb, var(--accent-soft) 45%, transparent); }
table.data td.sticky, table.data th.sticky { position: sticky; left: 0; background: var(--surface); z-index: 2; }
table.data th.sticky { z-index: 3; background: var(--surface-2); }
table.data tfoot td { font-weight: 700; background: var(--surface-2); position: sticky; bottom: 0; }
table.data th.fee, table.data td.fee { background: color-mix(in srgb, var(--fee-soft) 70%, var(--surface)); }
table.kv { width: 100%; border-collapse: collapse; }
table.kv th { width: 42%; text-align: left; font-weight: 500; color: var(--muted); padding: 5px 10px 5px 0; vertical-align: top; font-size: 13px; }
table.kv td { padding: 5px 0; vertical-align: top; word-break: break-word; }
table.kv tr + tr th, table.kv tr + tr td { border-top: 1px solid var(--line); }

/* Tabs on the case page */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tabs a { padding: 9px 14px; font-size: 13px; color: var(--ink-2); border-bottom: 2px solid transparent; white-space: nowrap; font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }
.tabs a.fee { color: var(--fee); }
.tabs a.fee.active { border-bottom-color: var(--fee); }

/* Badges */
.badge { display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-3); color: var(--ink-2); white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok-ink); }
.badge.warn { background: var(--warn-bg); color: var(--warn-ink); }
.badge.bad { background: var(--err-bg); color: var(--err-ink); }
.badge.fee { background: var(--fee-soft); color: var(--fee); }
.badge.accent { background: var(--info-bg); color: var(--info-ink); }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13.5px; background: var(--ok-bg); color: var(--ok-ink); }
.flash-warn { background: var(--warn-bg); color: var(--warn-ink); }
.flash-bad { background: var(--err-bg); color: var(--err-ink); }

.bar { height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }
.status-list { display: grid; gap: 8px; }
.status-list .row { display: grid; grid-template-columns: minmax(0, 1fr) 46px; gap: 4px 10px; align-items: center; }
.status-list .row .bar { grid-column: 1 / -1; }

/* Checklist matrix */
.cl td.v { text-align: center; white-space: nowrap; }
.cl .v-ok { color: var(--ok-ink); font-weight: 600; }
.cl .v-na { color: var(--muted); }
.cl .v-pending { color: var(--warn-ink); font-weight: 600; }
.cl .v-other { color: var(--err-ink); }
.cl select { padding: 2px 4px; min-width: 70px; font-size: 12px; }
.cl tr.heading td { background: var(--surface-2); font-weight: 700; }
.zh { color: var(--muted); font-size: 12px; }

/* Spreadsheet copy */
.sheet td { white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
.sheet th.rown, .sheet td.rown { color: var(--muted); background: var(--surface-2); text-align: right; position: sticky; left: 0; }

.secret { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; letter-spacing: .08em; background: var(--surface-2); padding: 8px 10px; border-radius: 8px; word-break: break-all; }
.reveal { font-size: 11px; margin-left: 6px; }
.changelog h2 { margin-top: 18px; }
.changelog ul { margin: 6px 0 0 18px; padding: 0; }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.diff-old { color: var(--err-ink); text-decoration: line-through; }
.diff-new { color: var(--ok-ink); }

/* Printable IRS sheet */
.print-only { display: none; }
@media print {
  .topbar, .sidebar, .no-print, .flash { display: none !important; }
  .shell { display: block; }
  .content { padding: 0; }
  .card { box-shadow: none; border: 0; padding: 0; }
  body { background: #fff; color: #000; font-size: 12px; }
  .print-only { display: block; }
}
.irs table { border-collapse: collapse; width: 100%; }
.irs td, .irs th { border: 1px solid var(--line); padding: 5px 8px; }
.irs th { text-align: left; width: 34%; background: var(--surface-2); }

/* Case page: details on the left, fees panel on the right */
.case-layout.with-fees { display: grid; grid-template-columns: minmax(0, 1fr) 400px; gap: 16px; align-items: start; }
.fee-panel { position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; }
.fee-panel table.kv th { width: 55%; }
.fee-panel .table-wrap table.data th, .fee-panel .table-wrap table.data td { padding: 5px 6px; font-size: 12px; }
@media (max-width: 1200px) { .case-layout.with-fees { grid-template-columns: 1fr; } .fee-panel { position: static; max-height: none; } }
.page-head .actions form { margin: 0; }
.page-head h1 { margin-bottom: 2px; }
.cl button.cell { background: none; border: 1px solid transparent; border-radius: 6px; padding: 2px 6px; min-width: 44px; font: inherit; cursor: pointer; color: inherit; }
.cl button.cell:hover { border-color: var(--line); background: var(--surface); }
.cl button.cell.v-ok { color: var(--ok-ink); font-weight: 600; }
.cl button.cell.v-na { color: var(--muted); }
.cl button.cell.v-pending { color: var(--warn-ink); font-weight: 600; }
.cl button.cell.v-other { color: var(--err-ink); }
.tabs { flex-wrap: wrap; }
.tile .badge { white-space: normal; }
