/* Artuis Portal: shared page frame and base components.

   Loaded by partials/shell.php before theme.css. Navy (below) is the default
   palette; theme.css redefines the same tokens per theme (html[data-theme]).
   Write colors through these variables: a literal color in a page's <style>
   is wrong in at least one theme. A color with alpha is
   color-mix(in oklch, var(--token) 20%, transparent).

   Three layers of tokens:
   - the design tokens (--surface, --text-2, --accent, --success-weak, ...),
     which theme.css redefines per theme;
   - the scales (--fs-*, --space-*, --radius-*), the same in every theme;
   - the older names pages already use (--panel, --muted, --blue, --green, ...),
     defined here once as aliases of the design tokens, so they follow the
     theme without being redefined.

   Contrast (WCAG AA, checked for every theme): --text-3 on --surface and
   --surface-2 >= 4.5:1; --on-accent on --btn-bg >= 4.5:1; --accent on --surface
   and on --accent-weak >= 4.5:1; status text on its -weak tint >= 4.5:1;
   --border-input >= 3:1 against --surface and --surface-2.
   --accent is for text, links, rings and outlines; solid fills that carry text
   (primary buttons, a "today" badge) use --btn-bg with --on-accent.

   Radius: tokens only. Inside a rounded container, an element near its edge
   takes the container's radius minus the container's padding (min 4px):
   --radius-inner is that for the 4px-padded popovers and menus.

   A page's own <style> comes after this file, so it can still override any
   rule here. */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/assets/fonts/inter-var-latin.woff2") format("woff2");
}

/* Scroll-driven edge fades (.table-wrap, .scroll-fade-x) */
@property --pf-fade-l { syntax: "<length>"; inherits: false; initial-value: 0px; }
@property --pf-fade-r { syntax: "<length>"; inherits: false; initial-value: 0px; }

:root {
  /* surfaces */
  --bg: #0c1427;
  --surface: #111c33;
  --surface-2: #16223c;
  --surface-3: #1c2a4c;
  --overlay: rgba(3, 6, 14, .62);
  /* borders: translucent, so one pair works on every surface level and tint.
     Form fields use the solid --border-input (3:1, a field's edge must show). */
  --border: color-mix(in oklch, var(--text) 10%, transparent);
  --border-strong: color-mix(in oklch, var(--text) 17%, transparent);
  --border-input: #5a6e99;
  /* 1px light edge on top of raised surfaces (popovers, dialogs) in dark themes */
  --highlight: color-mix(in oklch, var(--text) 7%, transparent);
  /* text */
  --text: #e8edf6;
  --text-2: #a9b4c9;
  --text-3: #8794b0;
  /* brand + semantic */
  --accent: #5894ff;
  --accent-hover: #7aa9ff;
  --accent-weak: color-mix(in oklch, var(--accent) 14%, transparent);
  --btn-bg: #3270e0;
  --btn-bg-hover: #2361cf;
  --on-accent: #ffffff;
  --accent-text: var(--on-accent);
  --success: #34d399;
  --success-weak: color-mix(in oklch, var(--success) 13%, transparent);
  --warning: #fbbf24;
  --warning-weak: color-mix(in oklch, var(--warning) 13%, transparent);
  --danger: #f87171;
  --danger-weak: color-mix(in oklch, var(--danger) 13%, transparent);
  --violet: #a78bfa;
  --violet-weak: color-mix(in oklch, var(--violet) 14%, transparent);
  --neutral-weak: rgba(148, 163, 184, .12);
  /* text on a solid status fill (.btn.danger:hover, .btn.success:hover) */
  --on-danger: var(--bg);
  --on-success: var(--bg);
  /* categorical chart series (Portal.chart.series) */
  --chart-1: #5b9cff;
  --chart-2: #f5b83d;
  --chart-3: #2ec4b6;
  --chart-4: #f2708a;
  --chart-5: #a78bfa;
  --chart-6: #8fd14f;
  --chart-7: #f08a4b;
  --chart-8: #7dd3fc;
  /* shape */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 14px;
  --radius-inner: calc(var(--radius) - 4px);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-lg: 0 24px 64px rgba(0, 0, 0, .5);
  /* type scale */
  --font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-xs: 11px;     /* key caps, avatar initials */
  --fs-sm: 12px;     /* table headers, captions, chips, hints */
  --fs-md: 13px;     /* controls, tables, menus, secondary text */
  --fs-base: 14px;   /* body */
  --fs-lg: 16px;     /* section, drawer and dialog titles */
  --fs-xl: 22px;     /* page title */
  /* spacing scale (4px grid) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --pf-topbar-h: 68px;

  /* older names, kept as aliases (pages still use them) */
  --bg2: var(--surface-2);
  --panel: var(--surface);
  --panel-2: var(--surface);
  --card: var(--surface);
  --hover: var(--surface-2);
  --input-bg: var(--surface);
  --th-bg: var(--surface);
  --row-hover: var(--surface-2);
  --btn-secondary: var(--surface);
  --btn-secondary-hover: var(--surface-2);
  --chip: var(--surface-3);
  --muted: var(--text-2);
  --link: var(--accent);
  --blue: var(--accent);
  --blue-2: var(--accent-hover);
  --blue2: var(--accent-hover);
  --green: var(--success);
  --red: var(--danger);
  --amber: var(--warning);
  --purple: var(--violet);
  --shadow: var(--shadow-lg);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
/* `hidden` must win over component display rules (.btn is inline-flex) */
[hidden] { display: none !important; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: var(--fs-base)/1.5 var(--font);
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.25; letter-spacing: -.01em; }
.svg-icon { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
/* a visible keyboard ring on anything focusable (components may restyle it) */
:where(a, button, summary, [tabindex], [role="button"]):focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* "Skip to content": first stop for keyboard users, hidden until focused */
.pf-skip {
  position: absolute; left: var(--space-3); top: calc(-1 * var(--space-8) - var(--space-4)); z-index: 100;
  padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm);
  background: var(--btn-bg); color: var(--on-accent); font-size: var(--fs-md); font-weight: 600;
}
.pf-skip:focus { top: var(--space-3); text-decoration: none; }
.pf-main:focus { outline: none; }

/* ---------- Frame: top bar ---------- */

.pf-topbar {
  position: sticky; top: 0; z-index: 40; height: var(--pf-topbar-h);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
/* the bar spans the window on every page, so it never shifts between pages of
   different widths (narrow Settings, the Home launcher, wide boards) */
.pf-topbar-in {
  height: 100%; padding: 0 var(--space-6);
  display: flex; align-items: center; gap: var(--space-3);
}

.pf-logo { display: flex; align-items: center; flex: none; height: 32px; padding-right: var(--space-4); margin-right: var(--space-1); border-right: 1px solid var(--border); }
.pf-logo img { display: block; width: auto; height: 32px; }

.pf-crumbs { display: flex; align-items: center; gap: 6px; min-width: 0; flex: 1 1 auto; overflow: hidden; color: var(--text-3); font-size: var(--fs-md); }
.pf-crumbs a, .pf-crumbs .sep { white-space: nowrap; flex: none; }
.pf-crumbs a { color: var(--text-2); }
.pf-crumbs a:hover { color: var(--text); }
.pf-crumbs .sep { opacity: .6; }
.pf-crumbs .here { min-width: 0; color: var(--text); font-weight: 550; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pf-crumb-switch {
  display: inline-flex; align-items: center; gap: var(--space-1); height: 30px; padding: 0 6px 0 var(--space-2); margin-left: -2px;
  border-radius: var(--radius-sm); border: 1px solid transparent; background: none; font: inherit; font-size: var(--fs-md); cursor: pointer;
}
.pf-crumb-switch:hover { background: var(--surface-2); border-color: var(--border); }
.pf-crumb-switch .svg-icon { width: 14px; height: 14px; color: var(--text-3); }
/* a section's sibling pages, inline from 1024px (the menu above stands in below that) */
.pf-tabs-inline { display: none; align-items: center; gap: 2px; min-width: 0; }
.pf-crumbs .pf-tabs-inline a {
  display: inline-flex; align-items: center; height: 30px; padding: 0 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; white-space: nowrap;
}
.pf-crumbs .pf-tabs-inline a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.pf-crumbs .pf-tabs-inline a[aria-current="page"] { background: var(--surface-2); color: var(--text); font-weight: 600; box-shadow: inset 0 0 0 1px var(--border); }
@media (min-width: 1024px) {
  .pf-crumbs.has-tabs .pf-tabs-inline { display: inline-flex; }
  .pf-crumbs.has-tabs .pf-crumb-switch { display: none; }
}
@media (min-width: 1024px) and (max-width: 1279px) {
  /* room for the tabs: Search shows as its icon */
  .pf-has-tabs .pf-search { min-width: 0; padding: 0 9px; margin-right: 0; }
  .pf-has-tabs .pf-search .lbl, .pf-has-tabs .pf-search .kbd { display: none; }
}

.pf-top-right { margin-left: auto; display: flex; align-items: center; gap: 6px; flex: none; }
.pf-search {
  display: flex; align-items: center; gap: var(--space-2); height: 36px; padding: 0 var(--space-2) 0 10px; min-width: 220px; margin-right: var(--space-1);
  border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-3); font: inherit; font-size: var(--fs-md); cursor: pointer;
}
.pf-search:hover { border-color: var(--border-strong); color: var(--text-2); }
.pf-search .kbd { margin-left: auto; }
.pf-icon-btn {
  position: relative; display: inline-grid; place-items: center; width: 36px; height: 36px; padding: 0;
  border-radius: var(--radius-sm); border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer;
}
.pf-icon-btn:hover { background: var(--surface-2); color: var(--text); }
.pf-icon-btn .dot { position: absolute; top: 7px; right: 8px; width: 7px; height: 7px; border-radius: 50%; background: var(--danger); }
.pf-icon-btn .dot.warn { background: var(--warning); }
.pf-user {
  display: flex; align-items: center; gap: var(--space-2); padding: 3px var(--space-2) 3px 3px; border-radius: 99px;
  border: 1px solid var(--border); background: none; color: inherit; font: inherit; cursor: pointer;
}
.pf-user:hover { border-color: var(--border-strong); }
.pf-user .who { font-size: var(--fs-md); font-weight: 550; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf-user > .svg-icon { width: 14px; height: 14px; color: var(--text-3); }
.pf-avatar {
  width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  font-size: var(--fs-xs); font-weight: 650; color: var(--on-accent); background: var(--av, var(--btn-bg));
}
.kbd {
  display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 5px;
  border-radius: var(--radius-xs); border: 1px solid var(--border-strong); border-bottom-width: 2px;
  font: 500 var(--fs-xs)/1 var(--font); color: var(--text-3); background: var(--surface);
}

/* top-bar theme button: shows the current theme's icon and steps to the next.
   The frame prints one icon per theme (PF_THEME_ICONS in shell.php) and the
   rule that shows each under its html[data-theme]; Navy's is here. (theme.css
   styles the older bordered .theme-toggle that the customer pages use) */
.pf-theme .svg-icon { display: none; }
html:not([data-theme]) .pf-theme .icon-navy { display: block; }

/* ---------- Frame: page column + page heading ---------- */

/* widths are of the content; the 24px side padding comes on top */
.pf-page { margin: 0 auto; padding: var(--space-6) var(--space-6) var(--space-8); max-width: calc(1200px + 48px); }
.pf-page.pf-w-narrow { max-width: calc(960px + 48px); }
.pf-page.pf-w-wide { max-width: calc(1400px + 48px); }
.pf-page.pf-w-full { max-width: none; }

.pf-header { display: flex; align-items: flex-start; gap: var(--space-3) var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-4); }
.pf-titles { min-width: 0; }
.pf-title-row { display: flex; align-items: center; gap: var(--space-2); min-width: 0; }
.pf-title { margin: 0; font-size: var(--fs-xl); font-weight: 650; overflow-wrap: anywhere; }
.pf-title-btn {
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  width: 30px; height: 30px; padding: 0; border-radius: var(--radius-sm); border: 1px solid transparent;
  background: transparent; color: var(--text-3); font-size: var(--fs-lg); line-height: 1; cursor: pointer;
}
.pf-title-btn:hover { color: var(--text); background: var(--surface-2); border-color: var(--border); }
.pf-subtitle { margin: var(--space-1) 0 0; font-size: var(--fs-md); color: var(--text-2); }
.pf-actions { margin-left: auto; display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

@media (max-width: 860px) {
  .pf-topbar-in { padding: 0 var(--space-3); gap: var(--space-2); }
  .pf-logo { padding-right: 10px; }
  .pf-logo img { height: 26px; }
  .pf-crumbs a, .pf-crumbs .sep { display: none; }   /* phone: just the current page */
  .pf-search { min-width: 0; padding: 0 9px; margin-right: 0; }
  .pf-search .lbl, .pf-search .kbd, .pf-user .who { display: none; }
  .pf-page { padding: var(--space-4) var(--space-4) var(--space-6); }
}
@media (max-width: 520px) {
  .pf-actions { margin-left: 0; width: 100%; }
}

/* ---------- Popover menu, command palette ---------- */

.pf-pop {
  position: absolute; z-index: 80; min-width: 200px; max-width: calc(100vw - 16px); padding: var(--space-1); border-radius: var(--radius);
  background: var(--surface-2); border: 1px solid var(--border-strong); box-shadow: inset 0 1px 0 var(--highlight), var(--shadow-lg);
}
.pf-pop:focus { outline: none; }
.pf-pop .opt {
  display: flex; align-items: center; gap: var(--space-2); width: 100%; padding: 7px 9px; border: 0; border-radius: var(--radius-inner);
  background: none; color: var(--text); font: inherit; font-size: var(--fs-md); text-align: left; cursor: pointer; text-decoration: none;
}
.pf-pop .opt:hover { background: var(--surface-3); outline: none; text-decoration: none; }
/* keyboard focus must be obvious: tint plus an inset ring */
.pf-pop .opt:focus-visible { background: var(--accent-weak); outline: 2px solid var(--accent); outline-offset: -2px; text-decoration: none; }
.pf-pop .opt[aria-current="page"] { font-weight: 600; }
.pf-pop .opt .check { margin-left: auto; color: var(--accent); display: inline-flex; }
.pf-pop .opt.danger { color: var(--danger); }
.pf-pop .opt .svg-icon { color: var(--text-3); }
.pf-pop .opt.danger .svg-icon { color: inherit; }
.pf-pop .head { padding: var(--space-2) 9px 6px; font-size: var(--fs-md); }
.pf-pop .head b { display: block; font-weight: 600; }
.pf-pop .head span { color: var(--text-3); font-size: var(--fs-sm); overflow-wrap: anywhere; }
.pf-pop .note { padding: 7px 9px; font-size: var(--fs-sm); color: var(--text-3); }
.pf-pop .alerts { list-style: none; margin: 0; padding: 0; }
.pf-pop .alert { display: flex; gap: var(--space-2); padding: var(--space-2) 9px; font-size: var(--fs-md); }
.pf-pop .alert .svg-icon { margin-top: 2px; color: var(--warning); }
.pf-pop .alert.error .svg-icon { color: var(--danger); }
.pf-pop .alert small { display: block; color: var(--text-3); font-size: var(--fs-sm); }
.pf-pop hr { border: 0; border-top: 1px solid var(--border); margin: var(--space-1) 0; }

/* Search palette: a modal <dialog class="pf-cmdk-back"> covering the viewport */
dialog.pf-cmdk-back {
  position: fixed; inset: 0; width: 100%; height: 100%; max-width: none; max-height: none; margin: 0;
  padding: 12vh var(--space-4) var(--space-4); border: 0; background: transparent; color: var(--text); overflow: auto;
}
dialog.pf-cmdk-back[open] { display: flex; align-items: flex-start; justify-content: center; }
dialog.pf-cmdk-back::backdrop { background: var(--overlay); }
.pf-cmdk {
  width: min(620px, calc(100vw - 32px)); background: var(--surface-2); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); box-shadow: inset 0 1px 0 var(--highlight), var(--shadow-lg); overflow: hidden;
}
.pf-cmdk-input { display: flex; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--border); color: var(--text-3); }
.pf-cmdk-input input[type="text"] { flex: 1; height: 50px; min-height: 0; padding: 0; border: 0; border-radius: 0; background: transparent; color: var(--text); font-size: var(--fs-lg); outline: none; }
.pf-cmdk-input input[type="text"]:focus { box-shadow: none; }
.pf-cmdk-list { max-height: 380px; overflow-y: auto; padding: 6px; }
.pf-cmdk-group { padding: var(--space-2) 10px var(--space-1); font-size: var(--fs-sm); font-weight: 600; color: var(--text-3); }
.pf-cmdk-item { display: flex; align-items: center; gap: 10px; padding: var(--space-2) 10px; border-radius: calc(var(--radius-lg) - 6px); cursor: pointer; color: var(--text); }
.pf-cmdk-item .svg-icon { color: var(--text-3); }
.pf-cmdk-item .hint { margin-left: auto; font-size: var(--fs-sm); color: var(--text-3); }
.pf-cmdk-item.active { background: var(--accent-weak); color: var(--accent); box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--accent) 45%, transparent); }
.pf-cmdk-item.active .svg-icon, .pf-cmdk-item.active .hint { color: var(--accent); }
.pf-cmdk-empty { padding: 28px var(--space-4); text-align: center; color: var(--text-2); }
.pf-cmdk-foot { display: flex; gap: 14px; padding: var(--space-2) 14px; border-top: 1px solid var(--border); font-size: var(--fs-sm); color: var(--text-3); }

/* ---------- Base components ---------- */

.wrap {
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
  border-radius: var(--radius-lg); padding: var(--space-4); margin-bottom: var(--space-4);
}
.section-title { font-size: var(--fs-lg); font-weight: 600; margin: 0 0 var(--space-2); }
.muted { color: var(--text-2); }
.faint { color: var(--text-3); }
.right { text-align: right; }
.mt { margin-top: var(--space-4); }
/* money and other signed figures (Portal.money already prints the minus sign) */
.neg { color: var(--danger); }
.pos { color: var(--success); }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 34px; padding: var(--space-2) var(--space-3); border-radius: var(--radius-sm); border: 1px solid transparent;
  background: var(--btn-bg); color: var(--on-accent); cursor: pointer;
  font: inherit; font-size: var(--fs-md); font-weight: 550; line-height: 1.2; white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}
.btn:hover { background: var(--btn-bg-hover); text-decoration: none; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); box-shadow: var(--shadow-sm); }
.btn.secondary:hover { background: var(--surface-2); }
.btn.ghost { background: transparent; border-color: var(--border); color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-2); color: var(--text); }
.btn.danger { background: var(--danger-weak); color: var(--danger); }
.btn.danger:hover { background: var(--danger); color: var(--on-danger); }
.btn.success { background: var(--success-weak); color: var(--success); }
.btn.success:hover { background: var(--success); color: var(--on-success); }
.btn.small, .btn.sm { min-height: 28px; padding: var(--space-1) var(--space-2); font-size: var(--fs-sm); }

/* a <button> that reads as an inline text link (row actions, "Show more") */
.link-btn {
  display: inline; padding: 0; margin: 0; border: 0; background: none; color: var(--accent);
  font: inherit; text-align: inherit; cursor: pointer; border-radius: 2px;
}
.link-btn:hover { text-decoration: underline; }
.link-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.link-btn.danger { color: var(--danger); }
.link-btn:disabled { color: var(--text-3); cursor: default; text-decoration: none; }

label { display: block; color: var(--text-2); font-size: var(--fs-sm); font-weight: 550; margin-bottom: 6px; }
input[type="text"], input[type="date"], input[type="month"], input[type="number"],
input[type="email"], input[type="password"], input[type="search"], input[type="time"],
input[type="datetime-local"], input[type="url"], select, textarea {
  width: 100%; background: var(--surface); color: var(--text);
  border: 1px solid var(--border-input); border-radius: var(--radius-sm);
  padding: 7px 10px; outline: none; font: inherit; font-size: var(--fs-md);
}
/* inputs at the select's height (body line-height would make them 4px taller) */
input[type="text"], input[type="date"], input[type="month"], input[type="number"],
input[type="email"], input[type="password"], input[type="search"], input[type="time"],
input[type="datetime-local"], input[type="url"] { line-height: normal; }
input::placeholder, textarea::placeholder { color: var(--text-3); }
input:hover, select:hover, textarea:hover { border-color: var(--text-3); }
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
textarea { min-height: 96px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }

.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.toolbar > div { min-width: 180px; }
.grid { display: grid; gap: var(--space-3); }
.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
@media (max-width: 720px) {
  .cols-2, .cols-3, .cols-4, .cols-5 { grid-template-columns: minmax(0, 1fr); }
  .toolbar > div { min-width: 0; flex: 1 1 100%; }
}

table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-md); }
/* figures line up in columns everywhere; .num also right-aligns them */
th, td { padding: 10px var(--space-3); border-bottom: 1px solid var(--border); text-align: left; font-variant-numeric: tabular-nums; }
th {
  color: var(--text-3); font-size: var(--fs-sm); font-weight: 600; white-space: nowrap;
  background: var(--surface); position: sticky; top: 0; z-index: 1;
}
tr:hover td { background: var(--surface-2); }
.table-wrap { max-height: 520px; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }

.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 1px var(--space-2); border-radius: 999px;
  background: var(--neutral-weak); border: 1px solid transparent; color: var(--text-2); font-size: var(--fs-sm); font-weight: 550;
}
.link { color: var(--accent); cursor: pointer; }

/* ---------- Shared building blocks for the redesigned pages ----------
   (card / kpi / pill / avatar / table styles stay in each page's <style>:
   older pages use those class names for other things) */

.num { font-variant-numeric: tabular-nums; text-align: right; }
.mono { font-family: var(--mono); font-size: var(--fs-sm); }
.icon-btn {
  position: relative; display: inline-grid; place-items: center; width: 32px; height: 32px; padding: 0; flex: none;
  border-radius: var(--radius-sm); border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.icon-btn.bordered { border-color: var(--border); }
.icon-btn.sm { width: 26px; height: 26px; }

/* Filter chips: a value is set by clicking the chip (Portal.popover), cleared with its x.
   The x is a 24px target, whether a <span class="x"> or a <button class="x">. */
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 10px; border-radius: 99px;
  border: 1px dashed var(--border-strong); background: transparent; color: var(--text-2); font: inherit; font-size: var(--fs-md); cursor: pointer; white-space: nowrap;
}
.chip-btn:hover { color: var(--text); border-color: var(--text-3); }
.chip-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.chip-btn.on { border-style: solid; border-color: transparent; background: var(--accent-weak); color: var(--accent); font-weight: 550; }
.chip-btn .x {
  display: inline-grid; place-items: center; width: 24px; height: 24px; margin: -3px -7px -3px -3px; padding: 0;
  border: 0; border-radius: 50%; background: none; color: inherit; font: inherit; opacity: .7; cursor: pointer;
}
.chip-btn .x:hover { opacity: 1; background: color-mix(in oklch, currentColor 14%, transparent); }
.chip-btn .x:focus-visible { opacity: 1; outline: 2px solid var(--accent); outline-offset: 0; }
.chip-btn .svg-icon { width: 14px; height: 14px; }

.segmented { display: inline-flex; padding: 3px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border); }
.segmented button {
  display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border: 0; border-radius: calc(var(--radius-sm) - 3px);
  background: transparent; color: var(--text-2); font: inherit; font-size: var(--fs-sm); font-weight: 550; cursor: pointer;
}
.segmented button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.meter { height: 6px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.meter > span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }

.section-label { font-size: var(--fs-sm); font-weight: 600; letter-spacing: .05em; text-transform: uppercase; color: var(--text-3); margin: 22px 0 10px; }
.dl { display: grid; grid-template-columns: 130px minmax(0, 1fr); gap: 10px 14px; font-size: var(--fs-md); margin: 0; }
.dl dt { color: var(--text-3); }
.dl dd { margin: 0; min-width: 0; }
.cell-main { font-weight: 550; }
.cell-sub { font-size: var(--fs-sm); color: var(--text-3); }

/* Horizontal scroll with faded edges: an edge fades only while there is more
   to scroll that way (scroll-driven; browsers without it show no fade). */
.scroll-fade-x { overflow-x: auto; }
@supports (animation-timeline: scroll()) {
  .table-wrap, .scroll-fade-x {
    -webkit-mask-image: linear-gradient(to right, transparent, #000 var(--pf-fade-l), #000 calc(100% - var(--pf-fade-r)), transparent);
    mask-image: linear-gradient(to right, transparent, #000 var(--pf-fade-l), #000 calc(100% - var(--pf-fade-r)), transparent);
    animation: pf-fade-x linear both; animation-timeline: scroll(self inline);
  }
}
@keyframes pf-fade-x {
  0% { --pf-fade-l: 0px; --pf-fade-r: 28px; }
  6% { --pf-fade-l: 28px; }
  94% { --pf-fade-r: 28px; }
  100% { --pf-fade-l: 28px; --pf-fade-r: 0px; }
}

/* Drawer: Portal.drawer({title, sub, head, body, foot}) slides in from the right */
.drawer-back { position: fixed; inset: 0; background: var(--overlay); z-index: 70; opacity: 0; pointer-events: none; transition: opacity .18s; }
.drawer-back.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 71; width: min(560px, 100vw);
  background: var(--surface-2); border-left: 1px solid var(--border-strong); box-shadow: inset 1px 0 0 var(--highlight), var(--shadow-lg);
  transform: translateX(100%); transition: transform .22s cubic-bezier(.2, .8, .2, 1);
  display: flex; flex-direction: column; visibility: hidden;
}
.drawer.open { transform: none; visibility: visible; }
.drawer.wide { width: min(720px, 100vw); }
.drawer-head { display: flex; align-items: flex-start; gap: 10px; padding: var(--space-4) 18px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { margin: 0; font-size: var(--fs-lg); font-weight: 650; overflow-wrap: anywhere; }
.drawer-head .sub { margin-top: var(--space-1); font-size: var(--fs-md); color: var(--text-2); }
.drawer-head .right { margin-left: auto; display: flex; gap: var(--space-1); flex: none; }
.drawer-body { padding: 18px; overflow-y: auto; flex: 1; }
.drawer-foot { padding: var(--space-3) 18px; border-top: 1px solid var(--border); display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: flex-end; align-items: center; }
/* inside a drawer or modal (on --surface-2): table headers and row hovers one step up */
:is(.drawer, .pf-modal) th { background: var(--surface-2); }
:is(.drawer, .pf-modal) tr:hover td { background: var(--surface-3); }
:is(.drawer, .pf-modal, .pf-dialog) .btn.secondary { background: var(--surface-2); }
:is(.drawer, .pf-modal, .pf-dialog) .btn.secondary:hover, :is(.drawer, .pf-modal, .pf-dialog) .btn.ghost:hover,
:is(.drawer, .pf-modal) .icon-btn:hover { background: var(--surface-3); }
@media (max-width: 520px) {
  .dl { grid-template-columns: minmax(0, 1fr); gap: 2px 0; }
  .dl dd { margin-bottom: 10px; }
}

/* Modal: <dialog class="pf-modal"> opened with Portal.modal.open(el) */
.pf-modal {
  width: min(560px, calc(100vw - 32px)); max-width: min(560px, calc(100vw - 32px));
  max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px);
  padding: 0; border: 1px solid var(--border-strong); border-radius: var(--radius-lg);
  background: var(--surface-2); color: var(--text); box-shadow: inset 0 1px 0 var(--highlight), var(--shadow-lg);
}
.pf-modal[open] { display: flex; flex-direction: column; }
.pf-modal.wide { width: min(760px, calc(100vw - 32px)); max-width: min(760px, calc(100vw - 32px)); }
.pf-modal::backdrop { background: var(--overlay); }
.pf-modal-head { display: flex; align-items: flex-start; gap: 10px; padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--border); }
.pf-modal-head h2 { margin: 0; font-size: var(--fs-lg); font-weight: 650; overflow-wrap: anywhere; }
.pf-modal-head .sub { margin-top: var(--space-1); font-size: var(--fs-md); color: var(--text-2); }
.pf-modal-head > :last-child:not(:first-child) { margin-left: auto; flex: none; }
.pf-modal-body { padding: var(--space-5); overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.pf-modal-foot { display: flex; flex-wrap: wrap; gap: var(--space-2); justify-content: flex-end; align-items: center; padding: var(--space-3) var(--space-5); border-top: 1px solid var(--border); }

/* ---------- Loading skeletons ----------
   Portal.skeleton.* builds them; portal.js also fills empty tables while a page
   loads and turns any "Loading…" placeholder a page writes into one. */
.sk {
  display: block; height: 12px; border-radius: 6px; max-width: 100%;
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 45%, var(--surface-2) 90%);
  background-size: 300% 100%; animation: pf-sk 1.4s ease-in-out infinite;
}
.sk.round { border-radius: 50%; }
.sk.pill { border-radius: 99px; }
@keyframes pf-sk { from { background-position: 100% 0; } to { background-position: -100% 0; } }
.sk-lines { display: flex; flex-direction: column; gap: 10px; padding: 6px 0; }
tr.sk-row td { padding-top: 13px; padding-bottom: 13px; }
tr.sk-row:hover td { background: transparent; }
.sk-cards { display: grid; gap: 10px; }
.sk-card { display: flex; flex-direction: column; gap: 9px; padding: var(--space-3) 14px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
/* a cards skeleton in a grid container: each card is a grid item */
[data-skeleton="cards"] > .sk-auto, [data-skeleton="cards"] > .sk-auto > .sk-cards { display: contents; }
/* First load of a page (html.pf-booting, until its first requests finish):
   charts and KPI figures show a shimmer instead of an empty canvas or a 0. */
html.pf-booting .pf-main :has(> canvas) { position: relative; }
html.pf-booting .pf-main canvas { visibility: hidden; }
html.pf-booting .pf-main :has(> canvas)::after {
  content: ""; position: absolute; inset: 6px; border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 45%, var(--surface-2) 90%);
  background-size: 300% 100%; animation: pf-sk 1.4s ease-in-out infinite;
}
html.pf-booting .pf-main .kpi .value:not(:has(.sk)) {
  color: transparent; width: 60%; border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 0%, var(--surface-3) 45%, var(--surface-2) 90%);
  background-size: 300% 100%; animation: pf-sk 1.4s ease-in-out infinite;
}

/* ---------- Busy buttons (portal.js marks the clicked button while its request runs) ---------- */
.is-busy { pointer-events: none; cursor: progress; opacity: .8; }
.is-busy::after {
  content: ""; display: inline-block; width: 12px; height: 12px; margin-left: 6px; flex: none; vertical-align: -2px;
  border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%;
  opacity: 0; animation: pf-spin .7s linear infinite, pf-show 0s .25s forwards;   /* only if it takes a moment */
}
.icon-btn.is-busy::after, .pf-icon-btn.is-busy::after { position: absolute; margin: 0; }
/* On a .btn the spinner (and the check after a save) sits in the middle and the
   label fades, so the button keeps its width. --pf-btn-fg is the variant's ink. */
.btn { --pf-btn-fg: var(--on-accent); }
.btn.secondary, .btn.ghost { --pf-btn-fg: var(--text); }
.btn.danger { --pf-btn-fg: var(--danger); }
.btn.success { --pf-btn-fg: var(--success); }
.btn.is-busy, .btn.is-done { position: relative; }
.btn.is-busy { animation: pf-ink-out 0s .25s forwards; }
.btn.is-busy::after {
  position: absolute; left: 50%; top: 50%; width: 14px; height: 14px; margin: -7px 0 0 -7px;
  border-color: var(--pf-btn-fg); border-right-color: transparent;
}
.btn.is-done { color: transparent !important; transition: none; }
.btn.is-done::after {
  content: ""; position: absolute; left: 50%; top: 50%; width: 16px; height: 16px; margin: -8px 0 0 -8px;
  background: var(--pf-btn-fg);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E") center / contain no-repeat;
  animation: pf-pop .24s cubic-bezier(.2, .9, .3, 1.35);
}
@keyframes pf-ink-out { to { color: transparent; } }
@keyframes pf-pop { from { transform: scale(.4); opacity: 0; } }
.icon-btn.is-busy > .svg-icon, .pf-icon-btn.is-busy > .svg-icon { animation: pf-hide 0s .25s forwards; }
@keyframes pf-spin { to { transform: rotate(360deg); } }
@keyframes pf-show { to { opacity: .9; } }
@keyframes pf-hide { to { opacity: 0; } }
@keyframes pf-pulse { 0%, 100% { opacity: .25; } 50% { opacity: .9; } }

/* ---------- Empty and failed states ---------- */
td.pf-empty-cell { padding: 28px var(--space-4); text-align: center; color: var(--text-2); font-size: var(--fs-md); }
td:has(> .pf-empty) { padding: 0; }
tr:hover > td:has(> .pf-empty) { background: transparent; }
tr:hover > td.pf-empty-cell { background: transparent; }
.pf-failed { color: var(--text-2); }
.pf-empty { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 28px var(--space-4); text-align: center; color: var(--text-2); font-size: var(--fs-md); }
.pf-empty > .svg-icon { width: 26px; height: 26px; color: var(--text-3); margin-bottom: var(--space-1); }
.pf-empty b { color: var(--text); font-size: var(--fs-base); font-weight: 600; }
.pf-empty .btn { margin-top: var(--space-2); }

/* Toasts: Portal.toast() stacks them in .pf-toasts, two live regions made on page load
   (polite for confirmations, role="alert" for errors). Errors stay until dismissed. */
.pf-toasts { position: fixed; right: var(--space-5); bottom: var(--space-5); z-index: 1000; display: flex; flex-direction: column; gap: var(--space-2); align-items: flex-end; pointer-events: none; }
.pf-toast-region { display: flex; flex-direction: column; gap: var(--space-2); align-items: flex-end; }
.pf-toast {
  display: flex; align-items: center; gap: 10px; min-width: 240px; max-width: min(420px, calc(100vw - 32px));
  background: var(--surface-3); border: 1px solid var(--border-strong); color: var(--text);
  padding: 10px 6px 10px var(--space-3); border-radius: var(--radius); box-shadow: inset 0 1px 0 var(--highlight), var(--shadow-lg); font-size: var(--fs-md);
  animation: pf-toast-in .18s ease; pointer-events: auto;
}
.pf-toast .svg-icon { color: var(--success); }
.pf-toast.error { border-color: color-mix(in oklch, var(--danger) 55%, transparent); }
.pf-toast.error .svg-icon { color: var(--danger); }
.pf-toast-msg { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.pf-toast .btn { margin-left: auto; }
.pf-toast-x {
  display: inline-grid; place-items: center; flex: none; width: 28px; height: 28px; margin-left: auto; padding: 0;
  border: 0; border-radius: var(--radius-sm); background: none; color: var(--text-3); cursor: pointer;
}
.pf-toast .btn + .pf-toast-x { margin-left: 0; }
.pf-toast-x:hover { color: var(--text); background: color-mix(in oklch, var(--text) 8%, transparent); }
.pf-toast-x .svg-icon, .pf-toast.error .pf-toast-x .svg-icon { color: inherit; width: 14px; height: 14px; }
@keyframes pf-toast-in { from { transform: translateY(8px); opacity: 0; } }
.pf-toast.out { opacity: 0; transform: translateX(12px); transition: opacity .16s ease, transform .16s ease; pointer-events: none; }
@media (max-width: 520px) { .pf-toasts { right: var(--space-4); left: var(--space-4); bottom: var(--space-4); align-items: stretch; } .pf-toast { min-width: 0; max-width: none; } }

/* Confirm dialog: Portal.confirm() */
.pf-dialog { border: 1px solid var(--border-strong); border-radius: var(--radius-lg); padding: var(--space-5); width: min(440px, calc(100vw - 32px));
  background: var(--surface-2); color: var(--text); box-shadow: inset 0 1px 0 var(--highlight), var(--shadow-lg); }
.pf-dialog::backdrop { background: var(--overlay); }
.pf-dialog h2 { margin: 0 0 var(--space-2); font-size: var(--fs-lg); }
.pf-dialog p { margin: 0 0 var(--space-4); color: var(--text-2); white-space: pre-line; }
.pf-dialog .pf-dialog-actions { display: flex; justify-content: flex-end; gap: var(--space-2); }

/* Expired session: reauth.js shows this instead of navigating away */
.pf-reauth {
  position: fixed; top: var(--space-3); left: 50%; transform: translateX(-50%); z-index: 1001;
  display: flex; align-items: center; gap: var(--space-3); width: max-content; max-width: calc(100vw - 32px);
  padding: var(--space-2) var(--space-2) var(--space-2) var(--space-4); border-radius: var(--radius);
  background: var(--surface-3); border: 1px solid color-mix(in oklch, var(--warning) 60%, transparent); color: var(--text);
  box-shadow: inset 0 1px 0 var(--highlight), var(--shadow-lg); font-size: var(--fs-md);
}
.pf-reauth-msg { min-width: 0; }
.pf-reauth-x {
  display: inline-grid; place-items: center; width: 28px; height: 28px; padding: 0; border: 0; border-radius: var(--radius-sm);
  background: none; color: var(--text-3); font-size: var(--fs-lg); line-height: 1; cursor: pointer;
}
.pf-reauth-x:hover { color: var(--text); background: color-mix(in oklch, var(--text) 8%, transparent); }
@media (max-width: 520px) { .pf-reauth { flex-wrap: wrap; left: var(--space-4); right: var(--space-4); transform: none; width: auto; } }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* ---------- Page transitions ----------
   Moving between pages cross-fades the content (the new page rises 6px) while
   the top bar stays put. Browsers without cross-document view transitions
   just navigate. shell.php also prefetches a staff page when its link is hovered. */
@view-transition { navigation: auto; }
.pf-topbar { view-transition-name: pf-topbar; }
::view-transition-group(pf-topbar) { animation: none; }
::view-transition-old(pf-topbar) { display: none; }
::view-transition-new(pf-topbar) { animation: none; }
::view-transition-old(root) { animation: pf-vt-out .12s ease both; }
::view-transition-new(root) { animation: pf-vt-in .2s cubic-bezier(.2, .8, .2, 1) both; }
@keyframes pf-vt-out { to { opacity: 0; } }
@keyframes pf-vt-in { from { opacity: 0; transform: translateY(6px); } }

/* Progress: a thin bar along the top while a request or a page takes over 300 ms (portal.js) */
.pf-progress {
  position: fixed; top: 0; left: 0; width: 100%; height: 2px; z-index: 1003; pointer-events: none;
  background: var(--accent); box-shadow: 0 0 8px color-mix(in oklch, var(--accent) 60%, transparent);
  transform-origin: 0 50%; transform: scaleX(0); opacity: 0;
}
.pf-progress.on { opacity: 1; transform: scaleX(.9); transition: transform 10s cubic-bezier(.08, .7, .2, 1), opacity .12s; }
.pf-progress.done { opacity: 0; transform: scaleX(1); transition: transform .2s ease, opacity .25s ease .2s; }

/* Pop-ups: modals, the confirm dialog and the Search palette fade and scale in
   and out; menus grow from their button (portal.js sets transform-origin). */
dialog.pf-modal, dialog.pf-dialog, dialog.pf-cmdk-back {
  opacity: 0;
  transition: opacity .16s ease, transform .16s ease, overlay .16s ease allow-discrete, display .16s ease allow-discrete;
}
dialog.pf-modal, dialog.pf-dialog { transform: translateY(6px) scale(.98); }
dialog.pf-modal[open], dialog.pf-dialog[open], dialog.pf-cmdk-back[open] { opacity: 1; transform: none; }
dialog.pf-cmdk-back .pf-cmdk { transition: transform .16s ease; }
dialog.pf-cmdk-back:not([open]) .pf-cmdk { transform: translateY(-6px) scale(.98); }
:is(dialog.pf-modal, dialog.pf-dialog, dialog.pf-cmdk-back)::backdrop {
  opacity: 0; transition: opacity .16s ease, overlay .16s ease allow-discrete, display .16s ease allow-discrete;
}
:is(dialog.pf-modal, dialog.pf-dialog, dialog.pf-cmdk-back)[open]::backdrop { opacity: 1; }
@starting-style {
  dialog.pf-modal[open], dialog.pf-dialog[open] { opacity: 0; transform: translateY(6px) scale(.98); }
  dialog.pf-cmdk-back[open] { opacity: 0; }
  dialog.pf-cmdk-back[open] .pf-cmdk { transform: translateY(-6px) scale(.98); }
  :is(dialog.pf-modal, dialog.pf-dialog, dialog.pf-cmdk-back)[open]::backdrop { opacity: 0; }
}
.pf-pop { animation: pf-pop-in .14s cubic-bezier(.2, .8, .2, 1); }
@keyframes pf-pop-in { from { opacity: 0; transform: scale(.96); } }

/* Totals: <tfoot class="pf-total"> (or tr.pf-total) under a money or hours table;
   inside a .table-wrap it stays in view at the bottom while the rows scroll. */
:is(tfoot.pf-total, tr.pf-total) td, :is(tfoot.pf-total, tr.pf-total) th {
  font-weight: 600; color: var(--text); background: var(--surface);
  border-top: 1px solid var(--border-strong); border-bottom: 0;
}
:is(tfoot.pf-total, tr.pf-total):hover td, tfoot.pf-total tr:hover td { background: var(--surface); }
.table-wrap tfoot.pf-total td, .table-wrap tfoot.pf-total th { position: sticky; bottom: 0; z-index: 1; }
:is(.drawer, .pf-modal) :is(tfoot.pf-total, tr.pf-total) td { background: var(--surface-2); }

/* Relative times: Portal.timeAgo(); the title holds the exact time */
time.pf-ago { white-space: nowrap; text-decoration: underline dotted transparent; text-underline-offset: 3px; transition: text-decoration-color .12s; }
time.pf-ago:hover { text-decoration-color: var(--text-3); }

/* ---------- Reduced motion ----------
   Movement goes; state changes stay instant. A busy spinner becomes a slow
   pulse (it still says "working"), skeletons hold still. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
  .sk, html.pf-booting .pf-main :has(> canvas)::after, html.pf-booting .pf-main .kpi .value:not(:has(.sk)) { animation: none !important; }
  .is-busy::after { border-right-color: currentColor; animation: pf-pulse 2s ease-in-out .25s infinite both !important; }
  .table-wrap, .scroll-fade-x { animation-duration: auto !important; }
  .btn.is-done::after { animation: none !important; }
}
@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
}
