/* ==========================================================================
   eBoat base components — shared by the PR site and the finance site.
   Ported from the pep-purchasing prototype, plus the pieces the finance app
   needs (drawer, skeleton, bars, tabs, badges, switches, inline edits).
   Load order: tokens.css -> base.css -> page css.

   Sizes come from the type scale in tokens.css (--fs-*), never from a literal
   px value: a stray hardcoded size is how this UI drifted down to 10.5px
   fine print in the first place.
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: var(--fs-base);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; text-wrap: balance; font-weight: 600; letter-spacing: -.01em; }
h1 { font-size: var(--fs-xl); }
h2 { font-size: var(--fs-md); }
h3 { font-size: var(--fs-base); }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-text); }
img, svg { max-width: 100%; }
hr { border: 0; border-top: 1px solid var(--rule-soft); margin: 14px 0; }

:focus-visible { outline: 2px solid var(--accent-text); outline-offset: 2px; border-radius: 3px; }

/* el(..., { hidden: true }) has to actually hide, whatever display the class sets */
[hidden] { display: none !important; }

/* ---------------------------------------------------------------- type ---- */
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.eyebrow {
  font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .1em;
  text-transform: uppercase; color: var(--ink-3);
}
.lede { max-width: 62ch; color: var(--ink-2); margin-top: 6px; }
.muted { color: var(--ink-3); }
.small { font-size: var(--fs-xs); }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* --------------------------------------------------------------- chrome ---- */
.topbar {
  position: sticky; top: 0; z-index: var(--z-topbar);
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 11px 20px; background: var(--surface);
  border-bottom: 1px solid var(--rule);
}
.brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
/* The bolt mark is 97x128, so fix the height and let the width follow the ratio. */
.brand .brandmark { height: 28px; width: auto; flex: none; }
.brand b { font-size: var(--fs-md); font-weight: 700; letter-spacing: -.015em; display: block; line-height: 1.15; }
.brand span { display: block; font-size: var(--fs-xs); color: var(--ink-3); letter-spacing: .04em; }

.wrap { max-width: 1360px; margin: 0 auto; padding-inline: 20px; padding-block: 22px 64px; }
.wrap-narrow { max-width: 800px; }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { margin-left: auto; }

/* -------------------------------------------------------------- buttons ---- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; justify-content: center;
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink);
  padding: 8px 15px; border-radius: var(--radius); font-size: var(--fs-sm); font-weight: 600;
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { border-color: var(--ink-3); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { filter: brightness(1.08); border-color: var(--accent); }
.btn-sm { padding: 5px 11px; font-size: var(--fs-xs); border-radius: 5px; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn-quiet:hover { background: var(--surface-2); border-color: transparent; }
.btn-danger { color: var(--bad); border-color: var(--rule); }
.btn-danger:hover { border-color: var(--bad); }

/* --------------------------------------------------------------- panels ---- */
.panel {
  background: var(--surface); border: 1px solid var(--rule-soft);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.panel + .panel { margin-top: 16px; }
/* Inside a grid the container's own `gap` already does the spacing, and this
   margin would push every panel but the first down by 16px — which is what made
   the dashboard's "Needs a decision" and "Ready to order" cards sit at different
   heights (the second lost 16px of its stretched row height to the margin). */
.grid > .panel + .panel { margin-top: 0; }
.panel-hd {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 13px 18px; border-bottom: 1px solid var(--rule-soft);
  background: var(--sunk); border-radius: var(--radius) var(--radius) 0 0;
}
.panel-hd h2 { font-size: var(--fs-md); }
.panel-bd { padding: 18px; }
.panel-ft { padding: 13px 18px; border-top: 1px solid var(--rule-soft); display: flex; gap: 8px; flex-wrap: wrap; }

.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 680px) { .g2, .g3 { grid-template-columns: 1fr; } }

/* ---------------------------------------------------------------- forms ---- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; }
.field > label { font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: var(--fs-xs); color: var(--ink-3); }
.hint.bad { color: var(--bad); font-weight: 600; }
.req { color: var(--accent-text); font-weight: 700; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=url], input[type=search], select, textarea {
  width: 100%; padding: 9px 11px; background: var(--sunk);
  border: 1px solid var(--rule); border-radius: 5px;
}
textarea { resize: vertical; min-height: 60px; }
input:focus, select:focus, textarea:focus { background: var(--surface); border-color: var(--accent-text); outline: none; }
.invalid { border-color: var(--bad) !important; background: var(--bad-soft) !important; }

/* A filter row that actually fills its panel: the status chips get their own
   line, then the search box and the category select share one grid row instead
   of stacking into a narrow right-aligned column (which is what `.toolbar` with
   margin-left:auto did to full-width inputs). */
.filterbar { display: grid; gap: 11px; padding: 13px 18px; }
.filterbar-controls {
  display: grid; gap: 10px; align-items: center;
  grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
}
.filterbar-toggles { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
@media (max-width: 720px) { .filterbar-controls { grid-template-columns: 1fr; } }

/* table cells you can type straight into (spent / plan / funding editors) */
.inline-edit {
  width: 100%; padding: 5px 7px; background: transparent;
  border: 1px solid transparent; border-radius: 4px;
}
.inline-edit:hover:not(:disabled) { background: var(--sunk); border-color: var(--rule-soft); }
.inline-edit:focus { background: var(--surface); border-color: var(--accent-text); outline: none; }
.inline-edit:disabled { opacity: .7; cursor: not-allowed; }

/* checkbox rendered as a toggle: <label class="switch"><input type=checkbox><span class="track"></span>Label</label> */
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: var(--fs-sm); }
.switch input { position: absolute; opacity: 0; width: 20px; height: 20px; margin: 0; cursor: pointer; }
.switch .track {
  width: 34px; height: 20px; flex: none; border-radius: 100px;
  background: var(--surface-2); border: 1px solid var(--rule); position: relative;
}
.switch .track::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px;
  border-radius: 50%; background: var(--surface); box-shadow: var(--shadow);
}
.switch input:checked + .track { background: var(--accent); border-color: var(--accent); }
.switch input:checked + .track::after { transform: translateX(14px); background: var(--accent-ink); }
.switch input:disabled + .track { opacity: .45; }
.switch input:focus-visible + .track { outline: 2px solid var(--accent-text); outline-offset: 2px; }
@media (prefers-reduced-motion: no-preference) {
  .switch .track, .switch .track::after { transition: background .15s ease, transform .15s ease; }
}

/* line items (PR request form — kept here because the finance manual-entry
   dialog reuses the same block) */
.lineitem {
  border: 1px solid var(--rule-soft); border-radius: var(--radius);
  padding: 14px 14px 14px 46px; position: relative; background: var(--sunk);
}
.lineitem + .lineitem { margin-top: 12px; }
.lineitem .idx {
  position: absolute; left: 0; top: 0; bottom: 0; width: 34px;
  display: flex; align-items: flex-start; justify-content: center; padding-top: 16px;
  border-right: 1px solid var(--rule-soft); background: var(--surface-2);
  border-radius: var(--radius) 0 0 var(--radius);
  font-family: var(--font-mono); font-size: var(--fs-xs); font-weight: 600; color: var(--ink-3);
}
.lineitem .drop { position: absolute; right: 8px; top: 8px; }
.ext {
  margin-top: 12px; padding-top: 10px; border-top: 1px dashed var(--rule);
  display: flex; justify-content: space-between; align-items: baseline; gap: 12px;
  font-size: var(--fs-xs); color: var(--ink-3);
}
.ext b { font-size: var(--fs-md); color: var(--ink); font-weight: 600; }

/* --------------------------------------------------------------- status ---- */
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px 3px 8px; border-radius: 100px; font-size: var(--fs-xs); font-weight: 600;
  white-space: nowrap;
}
.chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex: none; }
.st-submitted { background: var(--surface-2); color: var(--ink-2); }
.st-approved  { background: var(--info-soft); color: var(--info); }
.st-ordered   { background: var(--warn-soft); color: var(--warn); }
.st-received  { background: var(--ok-soft); color: var(--ok); }
.st-denied    { background: var(--bad-soft); color: var(--bad); }
.st-cancelled { background: var(--surface-2); color: var(--ink-3); }

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 100px;
  background: var(--accent); color: var(--accent-ink);
  font-family: var(--font-mono); font-size: var(--fs-xs); font-weight: 600; line-height: 1;
}
.badge.quiet { background: var(--surface-2); color: var(--ink-2); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
/* .warn is also used for the urgency phrase ("Needed for next test day"), not just short counts.
   .badge is inline-flex with no explicit width, so a flex item's default min-width:auto let a
   long phrase shrink to its narrowest word and wrap into a cramped multi-line pill — nowrap
   keeps it one line; .tablewrap's overflow-x:auto (dataTable, components.js) absorbs any table
   this widens. */
.badge.warn { background: var(--warn-soft); color: var(--warn); white-space: nowrap; }
.badge.bad { background: var(--bad-soft); color: var(--bad); white-space: nowrap; }

/* ---------------------------------------------------------------- money ---- */
.money {
  display: grid; gap: 1px; background: var(--rule-soft);
  border: 1px solid var(--rule-soft); border-radius: var(--radius); overflow: hidden;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
}
/* Five identical white boxes made every figure read the same. The 3px cap gives
   each tile its own meaning at a glance (committed = amber, remaining = green or
   red) without turning the row into a paint chart — the numbers stay ink-coloured. */
.money > div { background: var(--surface); padding: 13px 15px; border-top: 3px solid transparent; }
.money .k { font-size: var(--fs-2xs); font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.money .v { font-size: var(--fs-xl); font-weight: 600; margin-top: 4px; letter-spacing: -.02em; }
.money .s { font-size: var(--fs-xs); color: var(--ink-3); margin-top: 2px; }
.money .lead { background: var(--shoal-soft); }
/* A "bad" money figure reads as --accent-text, not --bad: --bad is deliberately
   desaturated to a soft pink in dark mode so it stays calm on status chips —
   the exact thing that reads as "pink" instead of "red" on a big dashboard
   number. --accent-text is the app's other red, tuned for legible TEXT (5.6:1
   even in dark mode) rather than a quiet badge fill. */
.money .v.bad { color: var(--accent-text); }
.money .v.ok { color: var(--ok); }
.money .v.warn { color: var(--warn); }
.money .t-shoal { border-top-color: var(--shoal); }
.money .t-info { border-top-color: var(--info); }
.money .t-warn { border-top-color: var(--warn); }
.money .t-ok { border-top-color: var(--ok); }
/* The bar is decorative, not text, so it can afford the punchier --accent
   crimson rather than --bad's softened pink — same reasoning as .v.bad above. */
.money .t-bad { border-top-color: var(--accent); }
.money .t-accent { border-top-color: var(--accent); }

/* planned-vs-spent bar: <div class="bar"><i style="width:62%"></i></div> */
.bar { position: relative; height: 8px; border-radius: 100px; background: var(--surface-2); overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--info); border-radius: inherit; }
.bar.ok > i { background: var(--ok); }
.bar.warn > i { background: var(--warn); }
.bar.over > i, .bar.bad > i { background: var(--bad); }

/* -------------------------------------------------------------- filters ---- */
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filters button {
  border: 1px solid var(--rule); background: var(--surface); color: var(--ink-2);
  padding: 6px 12px; border-radius: 100px; font-size: var(--fs-sm); font-weight: 600; cursor: pointer;
}
.filters button:hover { border-color: var(--ink-3); }
.filters button[aria-pressed="true"] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.filters button .n { font-family: var(--font-mono); font-size: var(--fs-xs); opacity: .7; margin-left: 6px; }

.tabs { display: flex; gap: 2px; padding: 3px; background: var(--surface-2); border-radius: var(--radius); overflow-x: auto; }
.tabs button {
  border: 0; background: transparent; padding: 7px 14px; border-radius: 5px;
  font-size: var(--fs-sm); font-weight: 600; color: var(--ink-2); cursor: pointer; white-space: nowrap;
}
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
/* Without this the Spent tabs rendered as "All$6,492.42" — the counter rule below
   was scoped to .filters only, so the tab's amount had no gap at all. */
.tabs button .n { font-family: var(--font-mono); font-size: var(--fs-xs); opacity: .75; margin-left: 7px; }

/* --------------------------------------------------------------- tables ---- */
.tablewrap { overflow-x: auto; border-top: 1px solid var(--rule-soft); }
table.data { width: 100%; border-collapse: collapse; }
table.data th {
  text-align: left; font-size: var(--fs-2xs); font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--ink-2); background: var(--shoal-soft);
  padding: 9px 13px; border-bottom: 1px solid var(--rule); white-space: nowrap;
}
table.data td { padding: 10px 13px; border-bottom: 1px solid var(--rule-soft); vertical-align: top; }
table.data tbody tr:hover td { background: var(--sunk); }
table.data tr.clickable { cursor: pointer; }
table.data tr.sel td { background: var(--accent-soft); }
table.data tfoot td { font-weight: 600; background: var(--sunk); border-bottom: 0; }
.cell-r { text-align: right; white-space: nowrap; }
.cell-c { text-align: center; }
.cell-strong { font-weight: 600; }
.cell-sub { color: var(--ink-3); font-size: var(--fs-xs); }
.stripe { border-left: 3px solid transparent; }
.stripe-submitted { border-left-color: var(--ink-3); }
.stripe-approved { border-left-color: var(--info); }
.stripe-ordered { border-left-color: var(--warn); }
.stripe-received { border-left-color: var(--ok); }
.stripe-denied { border-left-color: var(--bad); }
.stripe-cancelled { border-left-color: var(--rule); }
.rowacts { display: flex; gap: 5px; flex-wrap: wrap; justify-content: flex-end; }
.linkout {
  display: inline-block; max-width: 170px; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; vertical-align: bottom; font-size: var(--fs-xs);
}

.kv { display: grid; grid-template-columns: 138px minmax(0, 1fr); gap: 7px 14px; font-size: var(--fs-base); }
.kv dt { color: var(--ink-3); font-size: var(--fs-xs); }
.kv dd { margin: 0; word-break: break-word; }

.empty { padding: 44px 20px; text-align: center; color: var(--ink-3); }
.empty h3 { color: var(--ink); margin-bottom: 6px; font-size: var(--fs-md); }
.empty p { max-width: 46ch; margin: 0 auto; }
.empty .btn { margin-top: 14px; }

/* -------------------------------------------------------------- notices ---- */
.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 15px; border-radius: var(--radius); font-size: var(--fs-base);
  background: var(--info-soft); color: var(--info); border: 1px solid transparent;
}
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.notice b { color: inherit; }
.notice + .notice { margin-top: 10px; }

/* ------------------------------------------------------- modal / drawer ---- */
.scrim {
  position: fixed; inset: 0; background: rgba(9, 18, 25, .55); z-index: var(--z-scrim);
  display: flex; align-items: flex-start; justify-content: center; padding: 24px 16px; overflow: auto;
}
.modal {
  background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lift);
  width: min(680px, 100%); border: 1px solid var(--rule);
}
.modal.sm { width: min(460px, 100%); }
.modal.md { width: min(680px, 100%); }
.modal.lg { width: min(980px, 100%); }
.modal-hd { display: flex; align-items: center; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--rule-soft); }
.modal-hd h2 { font-size: var(--fs-md); margin-right: auto; }
.modal-bd { padding: 18px; display: grid; gap: 14px; }
.modal-ft { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--rule-soft); flex-wrap: wrap; }

/* the drawer reuses .scrim but pins its panel to the right edge */
.scrim-drawer { padding: 0; align-items: stretch; justify-content: flex-end; overflow: hidden; z-index: var(--z-drawer); }
.drawer {
  display: flex; flex-direction: column; width: min(var(--drawer-w), 100%);
  background: var(--surface); border-left: 1px solid var(--rule);
  box-shadow: var(--shadow-lift); max-height: 100%;
}
.drawer-hd { display: flex; align-items: center; gap: 12px; padding: 15px 18px; border-bottom: 1px solid var(--rule-soft); }
.drawer-hd h2 { font-size: var(--fs-md); margin-right: auto; }
.drawer-bd { padding: 18px; overflow: auto; flex: 1; display: grid; gap: 14px; align-content: start; }
.drawer-ft { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--rule-soft); flex-wrap: wrap; }
@media (max-width: 640px) {
  .drawer { width: 100%; border-left: 0; }
}
@media (prefers-reduced-motion: no-preference) {
  .modal { animation: rise .16s ease-out; }
  .drawer { animation: slidein .18s ease-out; }
  @keyframes rise { from { opacity: 0; transform: translateY(10px); } }
  @keyframes slidein { from { transform: translateX(24px); opacity: .4; } }
}

/* --------------------------------------------------- toast / busy / load ---- */
.toasts {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  z-index: var(--z-toast); display: flex; flex-direction: column; gap: 8px;
  align-items: center; pointer-events: none; max-width: calc(100vw - 32px);
}
.toast {
  pointer-events: auto; cursor: pointer;
  background: var(--ink); color: var(--paper); padding: 11px 19px; border-radius: 100px;
  font-size: var(--fs-sm); font-weight: 600; box-shadow: 0 12px 30px -12px rgba(0, 0, 0, .6);
  border: 1px solid transparent; text-align: center;
}
.toast.ok { background: var(--ok-soft); color: var(--ok); border-color: currentColor; }
.toast.bad { background: var(--bad-soft); color: var(--bad); border-color: currentColor; }
@media (prefers-reduced-motion: no-preference) {
  .toast { animation: pop .18s ease-out; }
  @keyframes pop { from { opacity: 0; transform: translateY(8px); } }
}

.spin {
  width: 13px; height: 13px; border: 2px solid currentColor; border-right-color: transparent;
  border-radius: 50%; display: inline-block; flex: none;
}
@media (prefers-reduced-motion: no-preference) { .spin { animation: sp .7s linear infinite; } }
@keyframes sp { to { transform: rotate(360deg); } }

/* shimmer placeholder; static block when the viewer asked for less motion */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--sunk) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  border-radius: 5px; min-height: 12px;
}
.skeleton + .skeleton { margin-top: 10px; }
.skeleton.line { height: 12px; }
.skeleton.block { height: 96px; }
@media (prefers-reduced-motion: no-preference) {
  .skeleton { animation: shimmer 1.4s ease infinite; }
  @keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
}

/* ------------------------------------------------------ app shell layout ---- */
/* Sidebar on wide screens, stacked (with a horizontal nav strip) below 900px. */
.applayout { display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; }
@media (min-width: 900px) {
  .applayout { grid-template-columns: var(--sidebar-w) minmax(0, 1fr); }
}
.sidebar { min-width: 0; }
.content { min-width: 0; }
