/* ---------------------------------------------------------------------------
   Resource Planning – design tokens
--------------------------------------------------------------------------- */
:root {
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --bg: #f3f5f9;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --border: #e4e9f0;
  --border-strong: #cfd7e3;
  --text: #0f172a;
  --text-2: #3f4b5f;
  --muted: #6b7789;
  --accent: #3b6cf6;
  --accent-hover: #2f5ae0;
  --accent-soft: #e9efff;
  --accent-text: #2450c9;
  --ok: #15803d;      --ok-soft: #dcfce7;
  --warn: #b45309;    --warn-soft: #fef3c7;
  --bad: #b91c1c;     --bad-soft: #fee2e2;
  --row-hover: #f5f8ff;
  --sidebar-bg: #0f172a;
  --sidebar-text: #9aa8bf;
  --sidebar-hover: rgba(255, 255, 255, .06);
  --sidebar-active: rgba(91, 140, 255, .22);
  --toast-bg: #0f172a; --toast-text: #f8fafc;
  --viz-plan: #2a78d6; --viz-actual: #eb6834; --viz-grid: #e4e9f0; --viz-axis: #cfd7e3;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04), 0 1px 3px rgba(15, 23, 42, .06);
  --shadow: 0 10px 30px rgba(15, 23, 42, .12);
  --radius: 14px;
  --radius-sm: 9px;
  --focus: 0 0 0 3px rgba(59, 108, 246, .22);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1120;
    --surface: #121a2c;
    --surface-2: #182236;
    --border: #253049;
    --border-strong: #34405c;
    --text: #e6ebf4;
    --text-2: #c3ccdb;
    --muted: #8d99af;
    --accent: #5b8cff;
    --accent-hover: #6f9bff;
    --accent-soft: #1b2a4f;
    --accent-text: #a5bdff;
    --ok: #4ade80;      --ok-soft: #11301f;
    --warn: #fbbf24;    --warn-soft: #3a2b0a;
    --bad: #f87171;     --bad-soft: #401717;
    --row-hover: #16203a;
    --sidebar-bg: #070c19;
    --sidebar-text: #8d99af;
    --toast-bg: #e6ebf4; --toast-text: #0b1120;
    --viz-plan: #3987e5; --viz-actual: #d95926; --viz-grid: #253049; --viz-axis: #34405c;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow: 0 10px 30px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

/* ---------------------------------------------------------------------------
   Base
--------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0; min-height: 100vh; font-family: var(--font); font-size: 14px; line-height: 1.45;
  color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased;
  display: grid; grid-template-columns: 240px minmax(0, 1fr);
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 6px; }
h2 { font-size: 16px; font-weight: 650; letter-spacing: -.01em; margin: 26px 0 6px; }
h3 { font-size: 13px; font-weight: 600; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
h1 + p.help { font-size: 14px; margin-bottom: 22px; }
p.help { color: var(--muted); font-size: 13px; margin: 0 0 14px; max-width: 1100px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
code { background: var(--surface-2); border: 1px solid var(--border); padding: 1px 6px; border-radius: 6px; font-size: 12px; }

/* ---------------------------------------------------------------------------
   Sidebar
--------------------------------------------------------------------------- */
.sidebar {
  background: var(--sidebar-bg); color: var(--sidebar-text); position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; padding: 20px 12px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 6px 22px; color: #fff; }
.brand .logo {
  width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, #5b8cff, #8b5cf6); color: #fff; font-weight: 800; font-size: 14px; letter-spacing: -.02em;
  box-shadow: 0 6px 16px rgba(91, 140, 255, .35);
}
.brand-name { font-weight: 700; font-size: 14.5px; line-height: 1.2; white-space: nowrap; }
.brand-sub { font-size: 11.5px; color: var(--sidebar-text); }
.nav-group { font-size: 10.5px; letter-spacing: .1em; text-transform: uppercase; color: #64748b; padding: 16px 12px 6px; font-weight: 600; }
.sidebar a {
  display: flex; align-items: center; gap: 10px; color: var(--sidebar-text); padding: 9px 12px; margin: 1px 0;
  border-radius: 9px; font-weight: 500; transition: background .15s, color .15s;
}
.sidebar a:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.sidebar a.active { background: var(--sidebar-active); color: #fff; }
.sidebar a.active svg { color: #8fb0ff; }
.sidebar svg { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; opacity: .9; }
.sidebar-footer { margin-top: auto; padding: 18px 12px 4px; font-size: 11.5px; color: #64748b; }

/* Mobile top bar */
.topbar { display: none; align-items: center; gap: 12px; padding: 12px 16px; background: var(--sidebar-bg); color: #fff; position: sticky; top: 0; z-index: 15; }
.topbar button { background: transparent; border: 1px solid rgba(255,255,255,.2); color: #fff; height: 34px; width: 38px; padding: 0; border-radius: 8px; font-size: 18px; }
.topbar .brand-name { font-size: 15px; }
.scrim { display: none; position: fixed; inset: 0; background: rgba(15, 23, 42, .5); z-index: 19; }

/* ---------------------------------------------------------------------------
   Content and cards
--------------------------------------------------------------------------- */
.content { padding: 28px 32px 60px; max-width: 1700px; min-width: 0; }
.panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 20px; box-shadow: var(--shadow-sm);
}
.panel > h2:first-child { margin-top: 0; }
.panel.table-wrap { padding: 0; overflow: hidden; }
.panel.table-wrap > table { border: none; }
.panel .table-wrap { border: 1px solid var(--border); border-radius: var(--radius-sm); }
.table-wrap { overflow-x: auto; }
.empty { color: var(--muted); padding: 28px 16px; text-align: center; font-size: 13.5px; }
.panel.empty { padding: 36px 20px; }

.toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 16px; }
.toolbar label { color: var(--muted); font-size: 13px; display: inline-flex; align-items: center; gap: 8px; }
.row { display: flex; flex-wrap: wrap; gap: 12px 14px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.field label label { text-transform: none; letter-spacing: 0; font-weight: 500; font-size: 13px; color: var(--text-2); display: inline-flex; align-items: center; gap: 6px; margin-right: 12px; }
.field > span { display: inline-flex; flex-wrap: wrap; align-items: center; min-height: 36px; }
.legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 12px; color: var(--muted); margin: 0 0 10px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend span::before { content: ""; width: 12px; height: 12px; border-radius: 4px; }
.legend .l-ok::before { background: var(--ok-soft); border: 1px solid var(--ok); }
.legend .l-under::before { background: var(--warn-soft); border: 1px solid var(--warn); }
.legend .l-over::before { background: var(--bad-soft); border: 1px solid var(--bad); }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.kpi { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 14px 20px; box-shadow: var(--shadow-sm); }
.kpi::before { content: ""; position: absolute; left: 0; top: 14px; bottom: 14px; width: 4px; border-radius: 4px; background: linear-gradient(180deg, var(--accent), #8b5cf6); }
.kpi .label { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi .value { font-size: 24px; font-weight: 700; letter-spacing: -.02em; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* Tabs */
.tabs { display: inline-flex; flex-wrap: wrap; gap: 3px; padding: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; margin-bottom: 18px; }
.tabs button { height: 32px; padding: 0 13px; border: none; background: transparent; color: var(--text-2); font-weight: 500; border-radius: 8px; }
.tabs button:hover { color: var(--accent-text); background: var(--surface); }
.tabs button.active { background: var(--surface); color: var(--accent-text); font-weight: 600; box-shadow: var(--shadow-sm); }
.panel[hidden] { display: none; }
.tabs.card-tabs { margin-bottom: 14px; }
.emp-card { padding: 4px 0 6px; }
.emp-card table { font-size: 12.5px; border: 1px solid var(--border); border-radius: 8px; margin: 6px 0; width: auto; }
.emp-card th { position: static; }
tr.detail > td { background: var(--surface-2); }

/* ---------------------------------------------------------------------------
   Controls
--------------------------------------------------------------------------- */
input, select, button, textarea { font: inherit; color: var(--text); }
input, select, textarea {
  height: 36px; padding: 0 11px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); transition: border-color .15s, box-shadow .15s; min-width: 0;
}
input::placeholder { color: var(--muted); opacity: .75; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--focus); }
input[type=number] { width: 96px; text-align: right; font-variant-numeric: tabular-nums; }
input[type=date], input[type=month] { width: 160px; }
input.wide { width: 240px; }
input[type=checkbox] { height: 16px; width: 16px; padding: 0; accent-color: var(--accent); vertical-align: -2px; }
input[type=file] { height: auto; padding: 6px 8px; font-size: 13px; }
input:disabled { background: var(--surface-2); color: var(--muted); }
select { padding-right: 30px; appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b7789' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }
button {
  height: 36px; padding: 0 14px; border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, transform .05s, box-shadow .15s;
}
button:hover { border-color: var(--accent); color: var(--accent-text); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: none; box-shadow: var(--focus); }
button:disabled { opacity: .5; cursor: default; transform: none; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 4px 12px rgba(59, 108, 246, .25); }
button.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
button.danger { color: var(--bad); border-color: transparent; background: transparent; }
button.danger:hover { background: var(--bad-soft); border-color: transparent; color: var(--bad); }
button.small { height: 28px; padding: 0 9px; font-size: 12px; }
a > button { pointer-events: auto; }
a:has(> button):hover { text-decoration: none; }
.dl-links { display: inline-flex; flex-wrap: wrap; gap: 8px; }

/* ---------------------------------------------------------------------------
   Tables
--------------------------------------------------------------------------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); font-size: 13.5px; }
th, td { padding: 7px 8px; text-align: left; vertical-align: middle; white-space: nowrap; border-bottom: 1px solid var(--border); }
th {
  font-size: 10.5px; font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--muted);
  background: var(--surface-2); position: sticky; top: 0; z-index: 1;
}
thead tr + tr th { top: 31px; }
th.group-head { text-align: center; border-bottom: 1px solid var(--border-strong); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover > td:not([class*="cell-"]) { background: var(--row-hover); }
tr.total td { font-weight: 600; background: var(--surface-2); }
tr.group td { font-weight: 600; background: var(--accent-soft); color: var(--accent-text); }
tr.group td .muted { color: var(--accent-text); opacity: .75; }
tr.sub td:first-child { padding-left: 28px; }
tr.muted td { color: var(--muted); }
td input, td select { height: 30px; padding: 0 8px; font-size: 13px; }
td select { min-width: 110px; padding-right: 24px; background-position: right 7px center; }
td input[type=number] { width: 68px; }
td input[type=date] { width: 148px; }
td input.wide { width: 200px; }
.inline-edit input, .inline-edit select { width: 100%; min-width: 90px; }
.c-note { color: var(--muted); }
table:not([data-nosort]) thead th { cursor: pointer; user-select: none; }
table:not([data-nosort]) thead th:hover { color: var(--accent-text); }
th.sort-asc::after { content: " \25B2"; font-size: 8px; color: var(--accent); }
th.sort-desc::after { content: " \25BC"; font-size: 8px; color: var(--accent); }

/* Heat cells */
.cell-ok { background: var(--ok-soft); color: var(--ok); }
.cell-over { background: var(--bad-soft); color: var(--bad); font-weight: 600; }
.cell-under { background: var(--warn-soft); color: var(--warn); }
.cell-none { color: var(--muted); }
td.cell-ok, td.cell-over, td.cell-under { box-shadow: inset 3px 0 0 currentColor; }
span.cell-over, span.cell-under, b.cell-over { padding: 1px 6px; border-radius: 5px; }

/* Badges and bars */
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; letter-spacing: .01em; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.overloaded { background: var(--bad-soft); color: var(--bad); }
.badge.underloaded { background: var(--warn-soft); color: var(--warn); }
.badge.unplanned, .badge.idle { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.bar { position: relative; height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; min-width: 110px; }
.bar > span { display: block; height: 100%; background: var(--ok); border-radius: 999px; }
.bar > span.over { background: var(--bad); }
.bar > span.under { background: var(--warn); }

/* Import results */
.import-result { margin-top: 12px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; }
.import-result ul { margin: 6px 0 0; padding-left: 20px; }
.import-result li.err { color: var(--bad); }

/* Toast */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 50; background: var(--toast-bg); color: var(--toast-text);
  padding: 11px 16px 11px 14px; border-radius: 10px; box-shadow: var(--shadow); font-weight: 500; font-size: 13.5px;
  display: flex; align-items: center; gap: 10px; animation: toast-in .18s ease-out;
}
.toast::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ok); flex: none; }
.toast.error { background: var(--bad); color: #fff; }
.toast.error::before { background: #fff; }
.toast[hidden] { display: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------------------
   Responsive
--------------------------------------------------------------------------- */
@media (max-width: 960px) {
  body { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 264px; transform: translateX(-100%); transition: transform .2s ease; z-index: 20; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .scrim.open { display: block; }
  .topbar { display: flex; }
  .content { padding: 18px 16px 40px; }
  h1 { font-size: 21px; }
  .panel { padding: 16px; }
}

/* Approvals */
.nav-badge { margin-left: auto; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; display: inline-grid; place-items: center; }
.nav-badge[hidden] { display: none; }
td.pending-cell input { border-color: var(--warn); box-shadow: inset 0 0 0 1px var(--warn); }
.pending-note { font-size: 11px; color: var(--warn); font-weight: 600; margin-top: 2px; white-space: nowrap; }

/* Login and user box */
.login-wrap { min-height: calc(100vh - 120px); display: grid; place-items: center; }
.login-panel { width: 100%; max-width: 400px; padding: 28px; }
.login-panel .field { margin-top: 0; }
.login-panel input { width: 100%; }
.user-box { display: flex; align-items: center; gap: 10px; padding: 10px 8px; border-top: 1px solid rgba(255,255,255,.08); }
.user-avatar { width: 30px; height: 30px; border-radius: 50%; background: linear-gradient(135deg, #5b8cff, #8b5cf6); color: #fff; display: grid; place-items: center; font-size: 10px; flex: none; }
.user-text { min-width: 0; flex: 1; }
.user-name { color: #fff; font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--sidebar-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-box button { background: transparent; border: 1px solid rgba(255,255,255,.15); color: #cbd5e1; height: 30px; width: 32px; padding: 0; border-radius: 8px; }
.user-box button:hover { border-color: #fff; color: #fff; }
input:disabled, select:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; opacity: .8; }
.sidebar a[hidden], .nav-group[hidden], .user-box[hidden] { display: none; }

/* Charts */
.viz-box { position: relative; width: 100%; }
.viz { display: block; width: 100%; height: auto; font-family: var(--font); }
.viz-grid { stroke: var(--viz-grid); stroke-width: 1; }
.viz-axis { stroke: var(--viz-axis); stroke-width: 1; }
.viz-tick { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.viz-bar { transition: opacity .12s; }
.viz-plan { fill: var(--viz-plan); }
.viz-actual { fill: var(--viz-actual); }
.viz-swatch.viz-plan, .viz-key.viz-plan { background: var(--viz-plan); }
.viz-swatch.viz-actual, .viz-key.viz-actual { background: var(--viz-actual); }
.viz-hit { fill: transparent; cursor: default; outline: none; }
.viz-hit.active, .viz-hit:focus-visible { fill: rgba(127, 127, 127, .08); }
.viz-legend { display: flex; flex-wrap: wrap; gap: 18px; font-size: 12.5px; color: var(--text-2); margin: 0 0 8px; }
.viz-legend span { display: inline-flex; align-items: center; gap: 7px; }
.viz-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; }
.viz-tip { position: absolute; pointer-events: none; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: var(--shadow); padding: 8px 10px; font-size: 12.5px; z-index: 5; min-width: 150px; }
.viz-tip-head { font-weight: 600; margin-bottom: 4px; }
.viz-tip-row { display: flex; align-items: center; gap: 7px; padding: 1px 0; }
.viz-tip-row b { font-variant-numeric: tabular-nums; }
.viz-tip-delta { color: var(--muted); border-top: 1px solid var(--border); margin-top: 4px; padding-top: 4px; }
.viz-key { display: inline-block; width: 10px; height: 3px; border-radius: 2px; }
div.viz-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.viz-card { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px 14px 6px; background: var(--surface); }
.viz-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; margin-bottom: 6px; font-weight: 600; }
.viz-card-head a { color: var(--text); }
.unknown-box { margin-top: 12px; padding: 12px 14px; border: 1px solid var(--warn); border-radius: var(--radius-sm); background: var(--warn-soft); }
.unknown-box table { background: transparent; }
.unknown-box th, .unknown-box td { background: transparent; }
.badge.type-project { background: var(--accent-soft); color: var(--accent-text); }
.badge.type-account { background: var(--ok-soft); color: var(--ok); }
.badge.type-admin { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.filter-bar { padding: 14px 18px; }
td.notes { white-space: normal; min-width: 220px; }
/* vertical column headers (program names) */
th.vh { height: 150px; vertical-align: bottom; text-align: center; padding: 8px 3px; width: 64px; max-width: 64px; }
table.matrix td { padding: 6px 3px; }
table.matrix td:first-child, table.matrix th:first-child { padding-left: 10px; padding-right: 10px; }
table.matrix td input[type=number] { width: 58px; padding: 0 4px; }
table.matrix td .pending-note, table.matrix td .small { white-space: normal; line-height: 1.2; }
th.vh > span { writing-mode: vertical-rl; transform: rotate(180deg); display: inline-block; max-height: 134px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-transform: none; letter-spacing: 0; font-size: 13px; font-weight: 600; line-height: 1.2; }
th.vh.sort-asc::after, th.vh.sort-desc::after { display: block; }
