/* Grant Tracker design system
   Plain CSS, no build step. Tokens on :root, dark mode via [data-theme] or OS preference. */

:root {
  color-scheme: light;
  --page: #f3f3ef;
  --surface: #fcfcfb;
  --surface-2: #f6f6f3;
  --surface-3: #ecebe6;
  --sidebar: #fcfcfb;
  --ink: #141413;
  --ink-2: #52514e;
  --ink-3: #6f6e69;
  --border: rgba(11, 11, 11, 0.10);
  --border-strong: rgba(11, 11, 11, 0.18);
  --grid: #e1e0d9;
  --accent: #1c5cab;
  --accent-hover: #184f95;
  --accent-soft: #e4eefb;
  --accent-ink: #184f95;
  --focus: #2a78d6;
  --good: #0a7d0a;
  --good-soft: #e3f3e3;
  --warn: #9a6500;
  --warn-soft: #fdf1d6;
  --bad: #c03232;
  --bad-soft: #fbe7e7;
  --shadow-sm: 0 1px 2px rgba(15, 15, 10, 0.06);
  --shadow: 0 1px 3px rgba(15, 15, 10, 0.08), 0 4px 16px rgba(15, 15, 10, 0.06);
  --shadow-lg: 0 12px 40px rgba(15, 15, 10, 0.18);
  --radius: 10px;
  --radius-sm: 6px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sidebar-w: 236px;

  /* Categorical chart series (validated reference palette, fixed order) */
  --series-1: #2a78d6; --series-2: #eb6834; --series-3: #1baf7a; --series-4: #eda100;
  --series-5: #e87ba4; --series-6: #008300; --series-7: #4a3aa7; --series-8: #e34948;
  --series-muted: #c3c2b7;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --page: #0d0d0d;
  --surface: #1a1a19;
  --surface-2: #222220;
  --surface-3: #2c2c2a;
  --sidebar: #141413;
  --ink: #f4f4f1;
  --ink-2: #c3c2b7;
  --ink-3: #9d9b93;
  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);
  --grid: #2c2c2a;
  --accent: #3987e5;
  --accent-hover: #5598e7;
  --accent-soft: #17283d;
  --accent-ink: #86b6ef;
  --focus: #5598e7;
  --good: #3cc23c;
  --good-soft: #15291a;
  --warn: #f2b632;
  --warn-soft: #2e2510;
  --bad: #ef6b6b;
  --bad-soft: #3a1919;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
  --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
  --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
  --series-muted: #4a4a46;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --surface-2: #222220;
    --surface-3: #2c2c2a;
    --sidebar: #141413;
    --ink: #f4f4f1;
    --ink-2: #c3c2b7;
    --ink-3: #9d9b93;
    --border: rgba(255, 255, 255, 0.10);
    --border-strong: rgba(255, 255, 255, 0.18);
    --grid: #2c2c2a;
    --accent: #3987e5;
    --accent-hover: #5598e7;
    --accent-soft: #17283d;
    --accent-ink: #86b6ef;
    --focus: #5598e7;
    --good: #3cc23c;
    --good-soft: #15291a;
    --warn: #f2b632;
    --warn-soft: #2e2510;
    --bad: #ef6b6b;
    --bad-soft: #3a1919;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.6);
    --series-1: #3987e5; --series-2: #d95926; --series-3: #199e70; --series-4: #c98500;
    --series-5: #d55181; --series-6: #008300; --series-7: #9085e9; --series-8: #e66767;
    --series-muted: #4a4a46;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--page);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-ink); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { margin: 0; line-height: 1.25; font-weight: 600; }
h1 { font-size: 22px; letter-spacing: -0.01em; }
h2 { font-size: 16px; }
h3 { font-size: 14px; }
p { margin: 0 0 0.75em; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }
code, .mono { font-family: var(--mono); font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
[x-cloak] { display: none !important; }
.icon { flex-shrink: 0; vertical-align: -3px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- App shell ---------- */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  background: var(--sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 14px 10px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 16px; color: var(--ink); font-weight: 650; font-size: 15px; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--accent); color: #fff;
}
.nav-group { margin-bottom: 14px; }
.nav-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); padding: 4px 10px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 7px;
  color: var(--ink-2); font-weight: 500;
}
.nav-link:hover { background: var(--surface-3); color: var(--ink); text-decoration: none; }
.nav-link.active { background: var(--accent-soft); color: var(--accent-ink); }
.nav-link .count { margin-left: auto; font-size: 11.5px; font-weight: 600; background: var(--surface-3); color: var(--ink-2); padding: 0 7px; border-radius: 999px; }
.nav-link .count.alert { background: var(--bad-soft); color: var(--bad); }
.sidebar-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px;
  padding: 10px 24px; background: color-mix(in srgb, var(--page) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px); border-bottom: 1px solid var(--border);
}
.topbar .menu-btn { display: none; }
.search-wrap { position: relative; flex: 1; max-width: 560px; }
.search-wrap .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search-input {
  width: 100%; padding: 8px 12px 8px 34px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface); color: var(--ink); font: inherit;
}
.search-input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent); }
.search-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg); max-height: 70vh; overflow-y: auto; padding: 6px;
}
.search-results:empty { display: none; }
.search-section { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-3); padding: 8px 10px 4px; }
.search-hit { display: block; padding: 7px 10px; border-radius: 6px; color: var(--ink); }
.search-hit:hover, .search-hit:focus { background: var(--surface-3); text-decoration: none; }
.search-hit small { display: block; color: var(--ink-3); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.content { padding: 24px; max-width: 1480px; width: 100%; }

.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-ink); font-weight: 650; font-size: 12px; flex-shrink: 0;
}
.avatar.sm { width: 22px; height: 22px; font-size: 10px; }

/* ---------- Page header ---------- */
.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head .titles { flex: 1; min-width: 240px; }
.page-head .subtitle { color: var(--ink-2); margin-top: 4px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.crumbs { font-size: 12.5px; color: var(--ink-3); margin-bottom: 6px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.crumbs a { color: var(--ink-3); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 13px;
  border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 550; cursor: pointer; white-space: nowrap; line-height: 1.3;
  transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--surface-3); color: var(--ink); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { background: var(--bad-soft); }
.btn.primary.danger { background: #c03232; border-color: #c03232; color: #fff; }
.btn.primary.danger:hover { background: #a82828; }
.btn.sm { padding: 4px 9px; font-size: 12.5px; border-radius: 6px; }
.btn.icon-only { padding: 7px; }
.btn.sm.icon-only { padding: 4px; }
.btn[disabled] { opacity: 0.5; pointer-events: none; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-radius: 8px 0 0 8px; }
.btn-group .btn:last-child { border-radius: 0 8px 8px 0; }
.btn-group .btn + .btn { margin-left: -1px; }
.btn-group .btn.active { background: var(--accent-soft); color: var(--accent-ink); border-color: var(--border-strong); }

/* ---------- Cards & layout grids ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 14.5px; }
.card-head .actions { margin-left: auto; display: flex; gap: 6px; align-items: center; }
.card-body { padding: 16px; }
.card-body.flush { padding: 0; }
.card-foot { padding: 10px 16px; border-top: 1px solid var(--border); color: var(--ink-3); font-size: 12.5px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(300px, 1fr); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--ink-3); }
.ink-2 { color: var(--ink-2); }
.small { font-size: 12.5px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.tnum { font-variant-numeric: tabular-nums; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; }

/* ---------- Stat tiles ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow-sm); }
.stat-label { color: var(--ink-2); font-size: 12.5px; display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 26px; font-weight: 650; margin-top: 4px; letter-spacing: -0.01em; }
.stat-sub { color: var(--ink-3); font-size: 12.5px; margin-top: 2px; }
a.stat:hover { border-color: var(--border-strong); text-decoration: none; }
a.stat { color: inherit; display: block; }

/* ---------- Badges & chips ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap; line-height: 1.5;
  background: var(--surface-3); color: var(--ink-2);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
.badge.plain::before { display: none; }
/* Application statuses */
.s-idea, .s-not_pursued, .s-withdrawn { background: var(--surface-3); color: var(--ink-2); }
.s-planning { background: #ece9fb; color: #4a3aa7; }
.s-drafting { background: #e4eefb; color: #1c5cab; }
.s-routing { background: #dcf3ea; color: #0d7a52; }
.s-submitted { background: #fdf1d6; color: #8a5a00; }
.s-in_review { background: #fde6dc; color: #b2471b; }
.s-reviewed { background: #fbe0d4; color: #a03c12; }
.s-pending_award { background: #fbe4ee; color: #b0325f; }
.s-awarded { background: #dff2df; color: #0a6e0a; }
.s-not_funded { background: #fbe4e4; color: #b42a2a; }
/* Award statuses */
.a-active { background: #dff2df; color: #0a6e0a; }
.a-nce { background: #fdf1d6; color: #8a5a00; }
.a-closing { background: #fde6dc; color: #b2471b; }
.a-ended { background: var(--surface-2); color: var(--ink-2); box-shadow: inset 0 0 0 1px var(--border); }
.a-closed { background: var(--surface-3); color: var(--ink-2); }
.a-suspended, .a-terminated { background: #fbe4e4; color: #b42a2a; }
/* Opportunity statuses */
.o-watching { background: var(--surface-3); color: var(--ink-2); }
.o-planning { background: #ece9fb; color: #4a3aa7; }
.o-applying { background: #e4eefb; color: #1c5cab; }
.o-passed, .o-closed { background: var(--surface-3); color: var(--ink-3); }
/* Task statuses */
.t-todo { background: var(--surface-3); color: var(--ink-2); }
.t-in_progress { background: #e4eefb; color: #1c5cab; }
.t-waiting { background: #fdf1d6; color: #8a5a00; }
.t-done { background: #dff2df; color: #0a6e0a; }
.t-skipped { background: var(--surface-3); color: var(--ink-3); }
.p-high { background: #fbe4e4; color: #b42a2a; }
.p-medium { background: var(--surface-3); color: var(--ink-2); }
.p-low { background: var(--surface-3); color: var(--ink-3); }

:root[data-theme="dark"] .s-planning, :root[data-theme="dark"] .o-planning { background: #262046; color: #b3abf2; }
:root[data-theme="dark"] .s-drafting, :root[data-theme="dark"] .o-applying, :root[data-theme="dark"] .t-in_progress { background: #17283d; color: #86b6ef; }
:root[data-theme="dark"] .s-routing { background: #12302a; color: #5fd3a6; }
:root[data-theme="dark"] .s-submitted, :root[data-theme="dark"] .a-nce, :root[data-theme="dark"] .t-waiting { background: #2e2510; color: #f2c25a; }
:root[data-theme="dark"] .s-in_review, :root[data-theme="dark"] .a-closing { background: #33200f; color: #f09a6e; }
:root[data-theme="dark"] .s-reviewed { background: #331b10; color: #f0875c; }
:root[data-theme="dark"] .s-pending_award { background: #351826; color: #ee8fb3; }
:root[data-theme="dark"] .s-awarded, :root[data-theme="dark"] .a-active, :root[data-theme="dark"] .t-done { background: #15291a; color: #6fd46f; }
:root[data-theme="dark"] .s-not_funded, :root[data-theme="dark"] .a-suspended, :root[data-theme="dark"] .a-terminated, :root[data-theme="dark"] .p-high { background: #3a1919; color: #f08b8b; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .s-planning, :root:not([data-theme="light"]) .o-planning { background: #262046; color: #b3abf2; }
  :root:not([data-theme="light"]) .s-drafting, :root:not([data-theme="light"]) .o-applying, :root:not([data-theme="light"]) .t-in_progress { background: #17283d; color: #86b6ef; }
  :root:not([data-theme="light"]) .s-routing { background: #12302a; color: #5fd3a6; }
  :root:not([data-theme="light"]) .s-submitted, :root:not([data-theme="light"]) .a-nce, :root:not([data-theme="light"]) .t-waiting { background: #2e2510; color: #f2c25a; }
  :root:not([data-theme="light"]) .s-in_review, :root:not([data-theme="light"]) .a-closing { background: #33200f; color: #f09a6e; }
  :root:not([data-theme="light"]) .s-reviewed { background: #331b10; color: #f0875c; }
  :root:not([data-theme="light"]) .s-pending_award { background: #351826; color: #ee8fb3; }
  :root:not([data-theme="light"]) .s-awarded, :root:not([data-theme="light"]) .a-active, :root:not([data-theme="light"]) .t-done { background: #15291a; color: #6fd46f; }
  :root:not([data-theme="light"]) .s-not_funded, :root:not([data-theme="light"]) .a-suspended, :root:not([data-theme="light"]) .a-terminated, :root:not([data-theme="light"]) .p-high { background: #3a1919; color: #f08b8b; }
}

.chip { display: inline-block; padding: 1px 8px; border-radius: 6px; font-size: 12px; font-weight: 550; border: 1px solid transparent; }
.chip-blue { background: color-mix(in srgb, #2a78d6 14%, transparent); color: var(--ink); border-color: color-mix(in srgb, #2a78d6 35%, transparent); }
.chip-teal { background: color-mix(in srgb, #1baf7a 14%, transparent); color: var(--ink); border-color: color-mix(in srgb, #1baf7a 35%, transparent); }
.chip-green { background: color-mix(in srgb, #008300 13%, transparent); color: var(--ink); border-color: color-mix(in srgb, #008300 35%, transparent); }
.chip-amber { background: color-mix(in srgb, #eda100 16%, transparent); color: var(--ink); border-color: color-mix(in srgb, #eda100 40%, transparent); }
.chip-orange { background: color-mix(in srgb, #eb6834 14%, transparent); color: var(--ink); border-color: color-mix(in srgb, #eb6834 35%, transparent); }
.chip-red { background: color-mix(in srgb, #e34948 14%, transparent); color: var(--ink); border-color: color-mix(in srgb, #e34948 35%, transparent); }
.chip-pink { background: color-mix(in srgb, #e87ba4 16%, transparent); color: var(--ink); border-color: color-mix(in srgb, #e87ba4 40%, transparent); }
.chip-purple { background: color-mix(in srgb, #4a3aa7 13%, transparent); color: var(--ink); border-color: color-mix(in srgb, #4a3aa7 35%, transparent); }
.chip-gray { background: var(--surface-3); color: var(--ink-2); border-color: var(--border); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }

/* ---------- Due-date accents ---------- */
.due { display: inline-flex; align-items: center; gap: 5px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.due-overdue { color: var(--bad); font-weight: 600; }
.due-soon { color: var(--warn); font-weight: 600; }
.due-month { color: var(--ink); }
.due-later { color: var(--ink-2); }
.date-pill {
  display: inline-flex; flex-direction: column; align-items: center; justify-content: center; width: 46px; min-width: 46px;
  border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); padding: 3px 0; line-height: 1.15;
}
.date-pill .m { font-size: 10.5px; text-transform: uppercase; font-weight: 650; color: var(--ink-3); letter-spacing: 0.05em; }
.date-pill .d { font-size: 17px; font-weight: 650; }
.date-pill.due-overdue { background: var(--bad-soft); border-color: transparent; }
.date-pill.due-overdue .m, .date-pill.due-overdue .d { color: var(--bad); }
.date-pill.due-soon { background: var(--warn-soft); border-color: transparent; }
.date-pill.due-soon .m, .date-pill.due-soon .d { color: var(--warn); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; }
.table th, .table td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th {
  font-size: 12px; font-weight: 600; color: var(--ink-3); background: var(--surface-2);
  position: sticky; top: 0; z-index: 1; white-space: nowrap;
}
.table th a { color: var(--ink-3); }
.table th a.sorted { color: var(--ink); }
.table tbody tr:hover td { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table .title-cell a { color: var(--ink); font-weight: 550; }
.table .title-cell small { display: block; color: var(--ink-3); font-weight: 400; }
.table.compact th, .table.compact td { padding: 6px 10px; }
.table tfoot td { font-weight: 650; background: var(--surface-2); border-top: 1px solid var(--border-strong); }

/* ---------- Lists ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.list > li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 550; color: var(--ink); display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .meta { color: var(--ink-3); font-size: 12.5px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---------- Forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 14px 16px; }
.field { grid-column: span 6; display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field.span-12 { grid-column: span 12; } .field.span-8 { grid-column: span 8; }
.field.span-4 { grid-column: span 4; } .field.span-3 { grid-column: span 3; }
.field label, .label { font-weight: 550; font-size: 13px; color: var(--ink); }
.field .help { color: var(--ink-3); font-size: 12px; }
.field .errors, .errorlist { color: var(--bad); font-size: 12.5px; margin: 0; padding: 0; list-style: none; }
.input, .field input[type=text], .field input[type=email], .field input[type=url], .field input[type=number],
.field input[type=password], .field input[type=date], .field input[type=search], .field input[type=file],
.field select, .field textarea, select.input, textarea.input {
  width: 100%; padding: 7px 10px; border-radius: 7px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink); font: inherit; min-height: 36px;
}
.field textarea, textarea.input { min-height: 90px; resize: vertical; line-height: 1.5; }
.field select[multiple] { min-height: 110px; }
.field input:focus, .field select:focus, .field textarea:focus, .input:focus {
  outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 22%, transparent);
}
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--bad); }
.field.check { flex-direction: row; align-items: flex-start; gap: 8px; }
.field.check input { margin-top: 3px; width: 16px; height: 16px; accent-color: var(--accent); }
.field.check .help { display: block; }
.inline-check { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.inline-check input { width: 16px; height: 16px; accent-color: var(--accent); margin: 0; }
.field.autofilled input:not([type=checkbox]), .field.autofilled select, .field.autofilled textarea {
  background: color-mix(in srgb, var(--accent-soft) 70%, var(--surface)); border-color: color-mix(in srgb, var(--accent) 45%, var(--border-strong));
}
.field.autofilled > label::after { content: "auto-filled"; margin-left: 6px; font-size: 10.5px; font-weight: 600; color: var(--accent-ink); text-transform: uppercase; letter-spacing: 0.04em; }
.fieldset { border: 0; padding: 0; margin: 0 0 8px; }
.fieldset-title { grid-column: span 12; font-size: 12px; font-weight: 650; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-3); padding-top: 10px; border-top: 1px solid var(--border); margin-top: 6px; }
.fieldset-title:first-child { border-top: 0; margin-top: 0; padding-top: 0; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; padding-top: 16px; margin-top: 8px; border-top: 1px solid var(--border); }
.form-table input[type=text], .form-table input[type=number], .form-table select {
  width: 100%; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--ink); font: inherit; min-height: 32px;
}
.input-sm { padding: 4px 8px; min-height: 30px; font-size: 13px; border-radius: 6px; border: 1px solid var(--border-strong); background: var(--surface); color: var(--ink); font-family: inherit; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 14px; }
.filters .input-sm { min-width: 140px; }
.filters input[type=search] { min-width: 220px; }
.kv-row { display: grid; grid-template-columns: 1fr 2fr auto; gap: 8px; margin-bottom: 6px; }
.inline-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- Definition lists ---------- */
.dl { display: grid; grid-template-columns: minmax(130px, max-content) 1fr; gap: 8px 16px; margin: 0; }
.dl dt { color: var(--ink-3); font-size: 12.5px; padding-top: 1px; }
.dl dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.prose { overflow-wrap: anywhere; }
.prose p:last-child { margin-bottom: 0; }
.prose ul, .prose ol { padding-left: 20px; margin: 0 0 0.75em; }

/* ---------- Tabs ---------- */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--border); margin-bottom: 16px; overflow-x: auto; }
.tab {
  padding: 9px 14px; border: 0; background: none; color: var(--ink-2); font: inherit; font-weight: 550; cursor: pointer;
  border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px;
}
.tab:hover { color: var(--ink); text-decoration: none; }
.tab.active { color: var(--accent-ink); border-bottom-color: var(--accent); }
.tab .count { font-size: 11px; background: var(--surface-3); color: var(--ink-2); border-radius: 999px; padding: 0 6px; }

/* ---------- Progress ---------- */
.progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.progress.good > span { background: var(--good); }
.progress.warn > span { background: #eda100; }
.progress.bad > span { background: var(--bad); }

/* ---------- Kanban ---------- */
.board { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(250px, 1fr); gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: start; }
.column { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; max-height: calc(100vh - 210px); }
.column-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; font-weight: 600; border-bottom: 1px solid var(--border); }
.column-head .count { margin-left: auto; color: var(--ink-3); font-weight: 550; font-size: 12.5px; }
.column-body { padding: 8px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; min-height: 80px; }
.kcard {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 10px 11px; box-shadow: var(--shadow-sm);
  cursor: grab; transition: box-shadow 0.12s, border-color 0.12s;
}
.kcard:hover { border-color: var(--border-strong); box-shadow: var(--shadow); }
.kcard .k-title { font-weight: 600; color: var(--ink); display: block; margin-bottom: 4px; }
.kcard .k-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; font-size: 12px; color: var(--ink-3); align-items: center; }
.sortable-ghost { opacity: 0.4; }
.sortable-drag { box-shadow: var(--shadow-lg); }
.column.drop-hint .column-body { outline: 2px dashed var(--border-strong); outline-offset: -4px; border-radius: 8px; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 14px 26px; }
.timeline li::before { content: ""; position: absolute; left: 8px; top: 18px; bottom: 0; width: 1px; background: var(--border-strong); }
.timeline li:last-child::before { display: none; }
.timeline .dot { position: absolute; left: 0; top: 2px; width: 17px; height: 17px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-3); color: var(--ink-2); }
.timeline .dot .icon { width: 10px; height: 10px; }
.timeline .when { font-size: 12px; color: var(--ink-3); }

/* ---------- Calendar ---------- */
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-left: 1px solid var(--border); border-top: 1px solid var(--border); }
.cal-dow { font-size: 11.5px; font-weight: 600; color: var(--ink-3); padding: 6px 8px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--surface-2); text-transform: uppercase; letter-spacing: 0.04em; }
.cal-day { min-height: 116px; padding: 4px 5px 6px; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--surface); min-width: 0; }
.cal-day.other { background: var(--surface-2); }
.cal-day.other .cal-num { color: var(--ink-3); }
.cal-day.weekend { background: color-mix(in srgb, var(--surface-2) 60%, var(--surface)); }
.cal-num { font-size: 12px; font-weight: 600; padding: 2px 4px; display: inline-block; border-radius: 6px; }
.cal-day.today .cal-num { background: var(--accent); color: #fff; }
.cal-ev {
  display: block; font-size: 11.5px; line-height: 1.3; padding: 2px 6px; margin-top: 3px; border-radius: 5px;
  color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border-left: 3px solid var(--ev, var(--series-1));
  background: color-mix(in srgb, var(--ev, var(--series-1)) 12%, var(--surface));
}
.cal-ev:hover { text-decoration: none; filter: brightness(0.97); }
.ev-sponsor { --ev: var(--series-8); }
.ev-internal { --ev: var(--series-2); }
.ev-loi { --ev: var(--series-7); }
.ev-task { --ev: var(--series-1); }
.ev-report { --ev: var(--series-6); }
.ev-review { --ev: var(--series-3); }
.ev-award { --ev: var(--series-5); }
.ev-opportunity { --ev: var(--series-4); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: 12.5px; color: var(--ink-2); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; background: var(--ev); display: inline-block; }

/* ---------- Empty states ---------- */
.empty { text-align: center; padding: 34px 20px; color: var(--ink-3); }
.empty .icon { color: var(--ink-3); margin-bottom: 8px; }
.empty h3 { color: var(--ink); margin-bottom: 4px; }

/* ---------- Alerts / messages ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); margin-bottom: 14px; }
.alert { align-items: center; flex-wrap: wrap; }
.alert-progress { width: 160px; }
.alert.warn { background: var(--warn-soft); border-color: transparent; }
.alert.bad { background: var(--bad-soft); border-color: transparent; }
.alert.good { background: var(--good-soft); border-color: transparent; }
.alert.info { background: var(--accent-soft); border-color: transparent; }
.form-grid > .alert { grid-column: 1 / -1; margin-bottom: 0; }
.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 100; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.toast {
  display: flex; gap: 10px; align-items: flex-start; padding: 11px 14px; border-radius: 10px; background: var(--ink); color: var(--surface);
  box-shadow: var(--shadow-lg); font-weight: 500; animation: toast-in 0.18s ease-out;
}
.toast.error { background: var(--bad); color: #fff; }
.toast .btn { color: inherit; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Dropdown & modal ---------- */
.dropdown { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 60; min-width: 210px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
}
.menu.left { left: 0; right: auto; }
.menu a, .menu button {
  display: flex; align-items: center; gap: 9px; width: 100%; padding: 7px 10px; border-radius: 6px; color: var(--ink);
  background: none; border: 0; font: inherit; text-align: left; cursor: pointer;
}
.menu a:hover, .menu button:hover { background: var(--surface-3); text-decoration: none; }
.menu .danger { color: var(--bad); }
.menu .sep { height: 1px; background: var(--border); margin: 5px 2px; }
.menu .menu-label { font-size: 11px; color: var(--ink-3); padding: 6px 10px 2px; text-transform: uppercase; letter-spacing: 0.05em; font-weight: 600; }

.modal-backdrop { position: fixed; inset: 0; z-index: 80; background: rgba(10, 10, 8, 0.45); display: grid; place-items: start center; padding: 6vh 16px; overflow-y: auto; }
.modal { width: 100%; max-width: 640px; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }
.modal.wide { max-width: 860px; }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 16px; }
.modal-head .btn { margin-left: auto; }
.modal-body { padding: 18px; }
.modal .form-actions { padding: 14px 18px; margin: 0; }

/* ---------- Auth pages ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--page); }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .card-body { padding: 26px; }
.auth-brand { display: flex; align-items: center; gap: 10px; justify-content: center; margin-bottom: 18px; font-size: 18px; font-weight: 650; }
.auth .field { grid-column: span 12; }
.qr { background: #fff; padding: 10px; border-radius: 10px; display: inline-block; border: 1px solid var(--border); }
.qr svg { width: 180px; height: 180px; display: block; }
.codes { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px 16px; font-family: var(--mono); font-size: 15px; padding: 14px; background: var(--surface-2); border-radius: 8px; }

/* ---------- Charts ---------- */
.chart-box { position: relative; height: 280px; }
.chart-box.tall { height: 340px; }
.chart-box.short { height: 220px; }
.chart-note { color: var(--ink-3); font-size: 12px; margin-top: 8px; }
details.table-view { margin-top: 10px; }
details.table-view summary { cursor: pointer; color: var(--ink-3); font-size: 12.5px; }
details.table-view .table { margin-top: 8px; font-size: 12.5px; }

/* ---------- Effort matrix ---------- */
.effort-cell { font-variant-numeric: tabular-nums; text-align: right; }
.effort-over { color: var(--bad); font-weight: 700; }
.effort-high { color: var(--warn); font-weight: 650; }
.bar-inline { display: flex; height: 8px; border-radius: 999px; overflow: hidden; background: var(--surface-3); min-width: 120px; gap: 2px; }
.bar-inline span { display: block; height: 100%; }

/* ---------- Gantt ---------- */
.gantt { position: relative; }
.gantt-row { display: grid; grid-template-columns: 240px 1fr; align-items: center; gap: 12px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.gantt-row:last-child { border-bottom: 0; }
.gantt-label { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 550; }
.gantt-track { position: relative; height: 22px; background: var(--surface-2); border-radius: 6px; }
.gantt-bar { position: absolute; top: 3px; bottom: 3px; border-radius: 4px; background: var(--series-1); min-width: 4px; }
.gantt-bar.nce { background: repeating-linear-gradient(45deg, var(--series-4), var(--series-4) 4px, color-mix(in srgb, var(--series-4) 60%, var(--surface)) 4px, color-mix(in srgb, var(--series-4) 60%, var(--surface)) 8px); }
.gantt-bar.pending { background: color-mix(in srgb, var(--series-1) 35%, var(--surface)); border: 1px dashed var(--series-1); }
.gantt-today { position: absolute; top: -4px; bottom: -4px; width: 2px; background: var(--bad); border-radius: 2px; z-index: 2; }
.gantt-axis { display: grid; grid-template-columns: 240px 1fr; gap: 12px; font-size: 11.5px; color: var(--ink-3); }
.gantt-axis .ticks { position: relative; height: 18px; }
.gantt-axis .ticks span { position: absolute; transform: translateX(-50%); }

/* ---------- File icon ---------- */
.file-ico { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; font-size: 10px; font-weight: 700; text-transform: uppercase; background: var(--surface-3); color: var(--ink-2); flex-shrink: 0; }
.file-ico.pdf { background: #fbe4e4; color: #b42a2a; }
.file-ico.docx, .file-ico.doc { background: #e4eefb; color: #1c5cab; }
.file-ico.xlsx, .file-ico.xls, .file-ico.csv { background: #dff2df; color: #0a6e0a; }
.file-ico.pptx, .file-ico.ppt { background: #fde6dc; color: #b2471b; }
.file-ico.link { background: #ece9fb; color: #4a3aa7; }

/* ---------- Checkbox task toggle ---------- */
.check-btn {
  width: 20px; height: 20px; border-radius: 6px; border: 1.5px solid var(--border-strong); background: var(--surface);
  display: grid; place-items: center; cursor: pointer; padding: 0; color: transparent; flex-shrink: 0;
}
.check-btn:hover { border-color: var(--accent); }
.check-btn.done { background: var(--good); border-color: var(--good); color: #fff; }
.task-row .title { white-space: normal; }
.task-row { align-items: flex-start !important; }
.task-row .check-btn { margin-top: 2px; }
.task-done .title { text-decoration: line-through; color: var(--ink-3); }

/* ---------- HTMX states ---------- */
.htmx-request.htmx-indicator, .htmx-request .htmx-indicator { opacity: 1; }
.htmx-indicator { opacity: 0; transition: opacity 0.2s; }
.htmx-swapping { opacity: 0.4; transition: opacity 0.15s; }
[hx-get].htmx-request, form.htmx-request { opacity: 0.75; }

/* ---------- Responsive ---------- */
@media (max-width: 1180px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 270px; z-index: 90; transform: translateX(-100%);
    transition: transform 0.2s ease; box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: none; }
  .sidebar-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 85; }
  .topbar { padding: 10px 16px; }
  .topbar .menu-btn { display: inline-flex; }
  .content { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .field, .field.span-4, .field.span-3, .field.span-8 { grid-column: span 12; }
  .gantt-row, .gantt-axis { grid-template-columns: 120px 1fr; }
  .cal-day { min-height: 80px; }
  .cal-ev { font-size: 10.5px; padding: 1px 4px; }
  .topbar .hide-sm { display: none; }
}
@media (max-width: 560px) {
  .alert-progress { width: 100%; }
  .grid-4 { grid-template-columns: minmax(0, 1fr); }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-value { font-size: 21px; }
  .dl { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  .dl dd { margin-bottom: 8px; }
}

/* ---------- Print (Other Support, reports) ---------- */
@media print {
  .sidebar, .topbar, .no-print, .toasts { display: none !important; }
  .app { display: block; }
  body { background: #fff; color: #000; font-size: 11pt; }
  .content { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; }
  .table th { background: #eee; position: static; }
  a { color: #000; }
}
