/*
 * TAP design system, v1. Served by tap-launcher:
 *
 *   <link rel="stylesheet" href="https://launcher.app.tlanfer.de/tap/v1/tap.css">
 *
 * Docs: https://gitea.tlanfer.de/tlan/tap-docs/src/branch/main/design.md
 * Preview: https://launcher.app.tlanfer.de/tap/v1/
 *
 * v1 only gets non-breaking changes. Renaming or removing a token or class
 * means v2.
 *
 * Contents
 *   1. Fonts           5. Forms            9. State and feedback
 *   2. Tokens          6. Tables          10. Frame: top bar, rail, layouts
 *   3. Base elements   7. Panels and grid 11. Utilities
 *   4. Buttons         8. Type roles
 */

/* ---------------------------------------------------------------- 1. Fonts */

@font-face {
  font-family: "Urbanist";
  src: url("fonts/urbanist-latin-wght.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/ibm-plex-mono-latin-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "IBM Plex Mono";
  src: url("fonts/ibm-plex-mono-latin-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

/* --------------------------------------------------------------- 2. Tokens */

/* Dark is the default. Light comes from the OS or from data-theme="light",
   which tap.js sets from the shared theme cookie. */
:root {
  color-scheme: dark;

  --tap-bg: #1B1B19;          /* page background */
  --tap-surface: #252523;     /* panels */
  --tap-raised: #31312E;      /* things inside panels: inputs, cards, secondary buttons */
  --tap-hover: #3B3B37;
  --tap-line: #393935;        /* hairlines inside panels only */
  --tap-fg: #F1F0EA;
  --tap-muted: #A3A196;
  --tap-faint: #75736A;

  --tap-accent: #D2E85A;      /* solid fills only: primary, selected, one feature panel */
  --tap-on-accent: #1B1B19;   /* text and icons on the accent */
  --tap-accent-text: #D2E85A; /* links, focus rings, accent-coloured text */

  --tap-good: #7FCB92;
  --tap-warn: #E9B44C;
  --tap-bad: #EF7462;
  --tap-info: #8FB3F0;

  --tap-data-1: #D2E85A;
  --tap-data-2: #E8935A;
  --tap-data-3: #8FB3F0;
  --tap-data-4: #E58FA6;
  --tap-hatch: rgba(255, 255, 255, .13);

  --tap-shadow: 0 16px 48px rgba(0, 0, 0, .45), 0 2px 6px rgba(0, 0, 0, .25);
  --tap-backdrop: rgba(0, 0, 0, .6);

  --tap-app-color: #6B6A62;   /* set to the app's launcher color */

  --tap-font: "Urbanist", "Segoe UI", system-ui, -apple-system, sans-serif;
  --tap-mono: "IBM Plex Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;

  --tap-r-panel: 22px;
  --tap-r-item: 14px;
  --tap-r-input: 12px;
  --tap-r-pill: 999px;

  --tap-gap: 14px;            /* between panels */
  --tap-pad: 24px;            /* inside panels */
  --tap-page-width: 1080px;   /* simple layout */
  --tap-wide-width: 1440px;   /* rail layout */
  --tap-gutter: 16px;         /* minimum space at the screen edges */

  --tap-ease: 120ms ease-out;

  /* The switcher reads these. */
  --tap-switcher-size: 40px;
  --tap-switcher-bg: var(--tap-raised);
  --tap-switcher-radius: 50%;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --tap-bg: #ECECE6;
    --tap-surface: #FFFFFF;
    --tap-raised: #F1F0EA;
    --tap-hover: #E6E5DE;
    --tap-line: #E2E0D7;
    --tap-fg: #1B1B19;
    --tap-muted: #65645C;
    --tap-faint: #9A988E;
    --tap-accent-text: #4F6B00;
    --tap-good: #2E8448;
    --tap-warn: #9A6200;
    --tap-bad: #C2412F;
    --tap-info: #2F62B5;
    --tap-data-1: #B9D334;
    --tap-data-2: #DD7A3C;
    --tap-data-3: #5C8BDB;
    --tap-data-4: #D46A88;
    --tap-hatch: rgba(0, 0, 0, .12);
    --tap-shadow: 0 16px 48px rgba(40, 40, 20, .16), 0 2px 6px rgba(40, 40, 20, .08);
    --tap-backdrop: rgba(30, 30, 20, .35);
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --tap-bg: #ECECE6;
  --tap-surface: #FFFFFF;
  --tap-raised: #F1F0EA;
  --tap-hover: #E6E5DE;
  --tap-line: #E2E0D7;
  --tap-fg: #1B1B19;
  --tap-muted: #65645C;
  --tap-faint: #9A988E;
  --tap-accent-text: #4F6B00;
  --tap-good: #2E8448;
  --tap-warn: #9A6200;
  --tap-bad: #C2412F;
  --tap-info: #2F62B5;
  --tap-data-1: #B9D334;
  --tap-data-2: #DD7A3C;
  --tap-data-3: #5C8BDB;
  --tap-data-4: #D46A88;
  --tap-hatch: rgba(0, 0, 0, .12);
  --tap-shadow: 0 16px 48px rgba(40, 40, 20, .16), 0 2px 6px rgba(40, 40, 20, .08);
  --tap-backdrop: rgba(30, 30, 20, .35);
}

/* ------------------------------------------------------- 3. Base elements */

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

html {
  background: var(--tap-bg);
  scrollbar-gutter: stable;   /* content never shifts when a scrollbar appears */
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--tap-bg);
  color: var(--tap-fg);
  font: 400 15px/1.5 var(--tap-font);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; text-wrap: balance; }
h1 { font-size: clamp(28px, 4vw, 40px); line-height: 1.1; letter-spacing: -.02em; }
h2 { font-size: 19px; line-height: 1.25; letter-spacing: -.01em; }
h3 { font-size: 16px; line-height: 1.3; }
h4 { font-size: 15px; line-height: 1.3; }
p { margin: 0 0 .75em; }
p:last-child { margin-bottom: 0; }
ul, ol { margin: 0 0 .75em; padding-left: 1.3em; }
small { font-size: 13px; }
strong, b { font-weight: 600; }

a { color: var(--tap-accent-text); text-underline-offset: 3px; text-decoration-thickness: 1px; }
a:hover { text-decoration-thickness: 2px; }

code, kbd, samp, pre { font-family: var(--tap-mono); font-size: 13px; }
:not(pre) > code { padding: 1px 6px; border-radius: 6px; background: var(--tap-raised); }
kbd { padding: 1px 6px; border-radius: 6px; background: var(--tap-raised); box-shadow: inset 0 -1px 0 var(--tap-line); }
pre { margin: 0 0 .75em; padding: 14px 16px; border-radius: var(--tap-r-item); background: var(--tap-raised); overflow-x: auto; line-height: 1.55; }

hr { border: 0; border-top: 1px solid var(--tap-line); margin: 18px 0; }
img, svg, video { max-width: 100%; }
::selection { background: var(--tap-accent); color: var(--tap-on-accent); }
:focus-visible { outline: 2px solid var(--tap-accent-text); outline-offset: 2px; }
[hidden] { display: none !important; }

/* Lucide icons (or any line icon) at TAP weight. Paste the SVG and add
   class="icon"; Lucide's own class "lucide" works too. */
svg.icon, svg.lucide {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75;
  stroke-linecap: round; stroke-linejoin: round;
  vertical-align: -4px;
}

dialog {
  padding: var(--tap-pad);
  border: 0;
  border-radius: var(--tap-r-panel);
  background: var(--tap-surface);
  color: var(--tap-fg);
  box-shadow: var(--tap-shadow);
  width: min(520px, calc(100vw - 2 * var(--tap-gutter)));
}
dialog::backdrop { background: var(--tap-backdrop); }

progress {
  appearance: none;
  width: 100%; height: 10px;
  border: 0; border-radius: var(--tap-r-pill);
  background: var(--tap-raised);
  overflow: hidden;
  vertical-align: middle;
}
progress::-webkit-progress-bar { background: var(--tap-raised); }
progress::-webkit-progress-value { background: var(--tap-accent); border-radius: var(--tap-r-pill); }
progress::-moz-progress-bar { background: var(--tap-accent); border-radius: var(--tap-r-pill); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

/* ------------------------------------------------------------- 4. Buttons */

/* Every button is a secondary pill by default. Add .primary for the one main
   action of a view, .ghost for quiet ones, .danger for destructive ones.
   .button makes a link look like a button. */
button, .button, input[type="submit"], input[type="button"], input[type="reset"] {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 18px;
  border: 0; border-radius: var(--tap-r-pill);
  background: var(--tap-raised); color: var(--tap-fg);
  font: 500 14px/1 var(--tap-font);
  white-space: nowrap; text-decoration: none;
  cursor: pointer;
  transition: background var(--tap-ease), color var(--tap-ease), box-shadow var(--tap-ease);
}
button:hover, .button:hover, input[type="submit"]:hover, input[type="button"]:hover, input[type="reset"]:hover {
  background: var(--tap-hover); text-decoration: none;
}
button svg.icon, .button svg.icon, button svg.lucide, .button svg.lucide { width: 18px; height: 18px; vertical-align: 0; }

.primary, button.primary, .button.primary, input[type="submit"].primary {
  background: var(--tap-accent); color: var(--tap-on-accent); font-weight: 600;
}
.primary:hover, button.primary:hover, .button.primary:hover {
  background: color-mix(in srgb, var(--tap-accent) 86%, #fff);
}
.ghost, button.ghost, .button.ghost { background: transparent; }
.ghost:hover, button.ghost:hover, .button.ghost:hover { background: var(--tap-raised); }
.danger, button.danger, .button.danger {
  background: transparent; color: var(--tap-bad);
  box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--tap-bad) 45%, transparent);
}
.danger:hover, button.danger:hover, .button.danger:hover { background: color-mix(in srgb, var(--tap-bad) 12%, transparent); }
button.sm, .button.sm { height: 32px; padding: 0 12px; font-size: 13px; }

/* Round, icon-only. Always give it an aria-label (and a title for a tooltip). */
button.icon-button, .button.icon-button { width: 40px; padding: 0; border-radius: 50%; flex: none; }
button.icon-button.sm, .button.icon-button.sm { width: 32px; height: 32px; }
button.icon-button.sm svg, .button.icon-button.sm svg { width: 16px; height: 16px; }

button:disabled, .button[aria-disabled="true"], input:disabled, select:disabled, textarea:disabled {
  opacity: .45; cursor: not-allowed; pointer-events: none;
}

/* Segmented control: a row of buttons, one pressed. */
.seg { display: inline-flex; padding: 4px; gap: 2px; border-radius: var(--tap-r-pill); background: var(--tap-raised); max-width: 100%; overflow-x: auto; }
.seg > button, .seg > a {
  height: 32px; padding: 0 14px; border-radius: var(--tap-r-pill);
  background: transparent; color: var(--tap-muted); font-weight: 500; font-size: 14px;
}
.seg > a { display: inline-flex; align-items: center; text-decoration: none; }
.seg > button:hover, .seg > a:hover { background: transparent; color: var(--tap-fg); }
.seg > [aria-pressed="true"], .seg > [aria-current], .seg > [aria-selected="true"] {
  background: var(--tap-accent); color: var(--tap-on-accent); font-weight: 600;
}
.seg > [aria-pressed="true"]:hover, .seg > [aria-current]:hover, .seg > [aria-selected="true"]:hover { background: var(--tap-accent); color: var(--tap-on-accent); }

/* --------------------------------------------------------------- 5. Forms */

label { font-size: 13px; font-weight: 500; color: var(--tap-muted); }

input:not([type]), input[type="text"], input[type="search"], input[type="email"], input[type="password"],
input[type="number"], input[type="url"], input[type="tel"], input[type="date"], input[type="datetime-local"],
input[type="time"], input[type="month"], input[type="week"], select, textarea {
  width: 100%; min-width: 0; height: 42px; padding: 0 14px;
  border: 1px solid transparent; border-radius: var(--tap-r-input);
  background: var(--tap-raised); color: var(--tap-fg);
  font: 400 15px/1.4 var(--tap-font); font-variant-numeric: tabular-nums;
  outline: none;
  transition: background var(--tap-ease), border-color var(--tap-ease);
}
textarea { height: auto; min-height: 96px; padding: 10px 14px; resize: vertical; line-height: 1.5; }
select {
  appearance: none; padding-right: 38px; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--tap-muted) 50%), linear-gradient(-45deg, transparent 50%, var(--tap-muted) 50%);
  background-size: 5px 5px; background-repeat: no-repeat;
  background-position: right 20px center, right 15px center;
}
input::placeholder, textarea::placeholder { color: var(--tap-faint); }
input:hover, select:hover, textarea:hover { background-color: var(--tap-hover); }
input:focus, select:focus, textarea:focus { border-color: var(--tap-accent-text); background-color: var(--tap-surface); }
[aria-invalid="true"] { border-color: var(--tap-bad) !important; }

input[type="checkbox"], input[type="radio"] {
  appearance: none; flex: none;
  width: 20px; height: 20px; margin: 0;
  display: inline-grid; place-items: center; vertical-align: -5px;
  background: var(--tap-raised); box-shadow: inset 0 0 0 1.5px var(--tap-faint);
  cursor: pointer; transition: background var(--tap-ease), box-shadow var(--tap-ease);
}
input[type="checkbox"] { border-radius: 7px; }
input[type="radio"] { border-radius: 50%; }
input[type="checkbox"]:checked, input[type="radio"]:checked { background: var(--tap-accent); box-shadow: none; }
input[type="checkbox"]:checked::after {
  content: ""; width: 10px; height: 6px;
  border: 2px solid var(--tap-on-accent); border-top: 0; border-right: 0;
  rotate: -45deg; translate: 0 -1px;
}
input[type="radio"]:checked::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--tap-on-accent); }

/* On/off switch: <input type="checkbox" class="switch"> */
input[type="checkbox"].switch { width: 40px; height: 24px; border-radius: 12px; box-shadow: none; background: var(--tap-hover); position: relative; display: inline-block; }
input[type="checkbox"].switch::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 18px; height: 18px; border: 0; border-radius: 50%;
  background: var(--tap-fg); rotate: 0deg;
  transition: translate 150ms ease-out, background var(--tap-ease);
}
input[type="checkbox"].switch:checked { background: var(--tap-accent); }
input[type="checkbox"].switch:checked::after { translate: 16px 0; background: var(--tap-on-accent); }

/* A label wrapping a checkbox, radio or switch puts it in a row. */
label:has(> input[type="checkbox"], > input[type="radio"]) {
  display: inline-flex; align-items: center; gap: 10px;
  font-size: 14px; color: var(--tap-fg); cursor: pointer;
}

/* .field: label, control, then an optional .hint or .error. */
.field { display: grid; gap: 6px; min-width: 0; align-content: start; }
.hint { font-size: 12.5px; color: var(--tap-faint); }
.error { font-size: 12.5px; color: var(--tap-bad); }
.fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 18px; }
.fields > .full { grid-column: 1 / -1; }

/* Unit inside an input: <div class="affix"><input><span>km</span></div> */
.affix { position: relative; }
.affix > input { padding-right: 44px; }
.affix > span { position: absolute; right: 14px; top: 50%; translate: 0 -50%; color: var(--tap-muted); font-size: 14px; pointer-events: none; }

/* Pill search box. Wrap the input and a search icon in a label or form. */
.search {
  display: flex; align-items: center; gap: 10px;
  height: 40px; padding: 0 16px; margin: 0;
  border-radius: var(--tap-r-pill); background: var(--tap-raised); color: var(--tap-muted);
  min-width: 0; transition: background var(--tap-ease);
}
.search:hover { background: var(--tap-hover); }
.search:focus-within { background: var(--tap-surface); box-shadow: inset 0 0 0 1px var(--tap-accent-text); }
.search input { height: 100%; padding: 0; border: 0 !important; background: transparent !important; font-size: 14px; }
.search svg { width: 18px; height: 18px; }

/* -------------------------------------------------------------- 6. Tables */

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th {
  text-align: left; font-size: 12.5px; font-weight: 500; color: var(--tap-muted);
  padding: 0 12px 10px 0; white-space: nowrap; vertical-align: bottom;
}
td { padding: 12px 12px 12px 0; border-top: 1px solid var(--tap-line); vertical-align: middle; }
th:last-child, td:last-child { padding-right: 0; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr.link { cursor: pointer; }
tbody tr.link:hover td { background: color-mix(in srgb, var(--tap-raised) 55%, transparent); }
/* Wrap wide tables so they scroll inside their panel, not the page. */
.table-wrap { overflow-x: auto; margin-inline: calc(-1 * var(--tap-pad)); padding-inline: var(--tap-pad); }

/* ---------------------------------------------------- 7. Panels and grid */

/* Panels are told apart by tone. No border, no shadow. */
.panel {
  background: var(--tap-surface); border-radius: var(--tap-r-panel);
  padding: var(--tap-pad); min-width: 0;
  display: flex; flex-direction: column; gap: 18px;
}
.panel > :is(.seg, button, .button, .chip, .status):not(.dropzone),
.stack > :is(.seg, button, .button, .chip, .status):not(.dropzone) { align-self: flex-start; justify-self: start; }
.panel-head { display: flex; align-items: center; gap: 12px; min-height: 32px; flex-wrap: wrap; }
.panel-head > :last-child:not(:first-child) { margin-left: auto; display: flex; gap: 6px; align-items: center; }
/* At most one per screen: the thing that matters most right now. */
.panel.feature { background: var(--tap-accent); color: var(--tap-on-accent); }
.panel.feature :is(.label, .eyebrow, .muted, label) { color: color-mix(in srgb, var(--tap-on-accent) 68%, transparent); }
.panel.feature :is(button, .button):not(.primary) { background: color-mix(in srgb, var(--tap-on-accent) 10%, transparent); color: var(--tap-on-accent); }
.panel.feature a { color: inherit; }

/* Items inside a panel: cards in a list, tiles. */
.item { background: var(--tap-raised); border-radius: var(--tap-r-item); padding: 14px 16px; min-width: 0; }
a.item, button.item { display: block; height: auto; text-align: left; color: inherit; text-decoration: none; font: inherit; transition: background var(--tap-ease); }
a.item:hover, button.item:hover { background: var(--tap-hover); }

/* 12-column grid. Give panels different spans to show what matters most. */
/* Panels in a row share their height; .grid.top lets each keep its own. */
.grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--tap-gap); }
.grid.top { align-items: start; }
.span-3 { grid-column: span 3; } .span-4 { grid-column: span 4; } .span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; } .span-7 { grid-column: span 7; } .span-8 { grid-column: span 8; }
.span-9 { grid-column: span 9; } .span-12 { grid-column: 1 / -1; }
@media (max-width: 1000px) {
  .span-3, .span-4, .span-5 { grid-column: span 6; }
  .span-7, .span-8, .span-9 { grid-column: 1 / -1; }
}
@media (max-width: 720px) {
  .grid > [class*="span-"] { grid-column: 1 / -1; }
  .fields { grid-template-columns: minmax(0, 1fr); }
}

/* ---------------------------------------------------------- 8. Type roles */

.display { font-size: clamp(28px, 4vw, 40px); font-weight: 600; line-height: 1.1; letter-spacing: -.02em; }
.stat { font-size: clamp(34px, 4vw, 44px); font-weight: 600; line-height: 1; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat small, .stat .unit { font-size: .45em; font-weight: 500; letter-spacing: 0; color: var(--tap-muted); }
.panel.feature .stat .unit, .panel.feature .stat small { color: inherit; opacity: .6; }
.title { font-size: 19px; font-weight: 600; line-height: 1.25; letter-spacing: -.01em; }
.label { font-size: 13px; font-weight: 500; color: var(--tap-muted); }
.eyebrow { font-size: 13px; font-weight: 500; color: var(--tap-muted); margin: 0 0 4px; }
.muted { color: var(--tap-muted); }
.mono { font-family: var(--tap-mono); font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.prose { max-width: 65ch; }

/* ------------------------------------------------- 9. State and feedback */

.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px; border-radius: var(--tap-r-pill);
  background: var(--tap-raised); color: var(--tap-muted);
  font-size: 13px; font-weight: 500; white-space: nowrap;
}
.status {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 10px; border-radius: var(--tap-r-pill);
  font-size: 12.5px; font-weight: 600; white-space: nowrap;
  color: var(--tap-muted); background: var(--tap-raised);
}
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status.good { color: var(--tap-good); background: color-mix(in srgb, var(--tap-good) 14%, transparent); }
.status.warn { color: var(--tap-warn); background: color-mix(in srgb, var(--tap-warn) 14%, transparent); }
.status.bad  { color: var(--tap-bad);  background: color-mix(in srgb, var(--tap-bad) 14%, transparent); }

.delta { display: inline-flex; align-items: center; gap: 2px; font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; }
.delta.up { color: var(--tap-good); }
.delta.down { color: var(--tap-bad); }

.callout {
  display: flex; gap: 12px; padding: 14px 16px; border-radius: var(--tap-r-item);
  background: color-mix(in srgb, var(--tap-info) 12%, transparent); font-size: 14px;
}
.callout > svg { color: var(--tap-info); flex: none; margin-top: 1px; vertical-align: 0; }
.callout.warn { background: color-mix(in srgb, var(--tap-warn) 13%, transparent); }
.callout.warn > svg { color: var(--tap-warn); }
.callout.bad { background: color-mix(in srgb, var(--tap-bad) 13%, transparent); }
.callout.bad > svg { color: var(--tap-bad); }

/* Dashed box for "add something" and file drops. */
.dropzone {
  display: flex; align-items: center; justify-content: center; gap: 12px; flex-wrap: wrap;
  min-height: 48px; padding: 16px;
  border: 1.5px dashed var(--tap-line); border-radius: var(--tap-r-item);
  background: transparent; color: var(--tap-muted); font-size: 14px; font-weight: 500;
  transition: border-color var(--tap-ease), color var(--tap-ease);
}
button.dropzone { height: auto; width: 100%; border-radius: var(--tap-r-item); }
button.dropzone:hover, .dropzone.over { background: transparent; border-color: var(--tap-faint); color: var(--tap-fg); }

.empty { display: grid; justify-items: start; gap: 8px; padding: 8px 0; }
.empty > .title { font-size: 16px; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex: none;
  display: inline-grid; place-items: center; overflow: hidden;
  background: var(--tap-raised); color: var(--tap-fg);
  font-size: 13px; font-weight: 600;
}
.avatar.sm { width: 24px; height: 24px; font-size: 10.5px; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }

/* Stacked bar for parts of a whole. Children set width and background. */
.bar { display: flex; gap: 3px; height: 10px; border-radius: var(--tap-r-pill); overflow: hidden; background: var(--tap-raised); }
.bar > * { display: block; height: 100%; border-radius: var(--tap-r-pill); background: var(--tap-accent); }

/* Hatching marks the inactive or the rest: other bars, remaining capacity. */
.hatch { background-image: repeating-linear-gradient(135deg, var(--tap-hatch) 0 2px, transparent 2px 7px); }

.legend { display: grid; gap: 10px; margin: 0; padding: 0; list-style: none; }
.legend > * { display: flex; align-items: center; gap: 10px; font-size: 14px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend .num { margin-left: auto; color: var(--tap-muted); }

/* Popover menu, e.g. <div popover class="menu">. Shadows are for floating things only. */
.menu {
  margin: 0; padding: 6px; min-width: 220px;
  border: 0; border-radius: var(--tap-r-item);
  background: var(--tap-surface); color: var(--tap-fg);
  box-shadow: var(--tap-shadow);
}
.menu > a, .menu > button {
  display: flex; align-items: center; gap: 10px; width: 100%; height: 38px; padding: 0 12px;
  border-radius: 10px; background: transparent; color: var(--tap-fg);
  font-size: 14px; font-weight: 500; text-decoration: none; justify-content: flex-start;
}
.menu > a:hover, .menu > button:hover { background: var(--tap-raised); }
.menu > hr { margin: 6px 4px; }
.menu > .menu-head { padding: 8px 12px 10px; display: grid; gap: 2px; }

/* ---------------------------------------- 10. Frame: top bar, rail, layouts */

/*
 * Simple layout (single-screen apps):
 *   <body class="tap-simple">
 *     <header class="tap-topbar">…</header>
 *     <main class="tap-main">…</main>
 *
 * Rail layout (apps with sections):
 *   <body class="tap-rail-layout">
 *     <header class="tap-topbar">…</header>
 *     <nav class="tap-rail">…</nav>
 *     <main class="tap-main">…</main>
 */
body.tap-simple, body.tap-rail-layout {
  padding-left: max(var(--tap-gutter), env(safe-area-inset-left, 0px));
  padding-right: max(var(--tap-gutter), env(safe-area-inset-right, 0px));
  padding-bottom: 48px;
}
body.tap-simple > .tap-topbar, body.tap-simple > .tap-main { width: 100%; max-width: var(--tap-page-width); margin-inline: auto; }
/* Narrow content for forms and lists; stays left-aligned under the app name. */
body.tap-simple > .tap-main.narrow > * { max-width: 720px; width: 100%; }

body.tap-rail-layout {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr);
  grid-template-areas: "top top" "rail main";
  grid-template-rows: auto 1fr;
  column-gap: var(--tap-gap);
  max-width: calc(var(--tap-wide-width) + 2 * var(--tap-gutter));
  margin-inline: auto;
}
body.tap-rail-layout > .tap-topbar { grid-area: top; }
body.tap-rail-layout > .tap-rail { grid-area: rail; }
body.tap-rail-layout > .tap-main { grid-area: main; }

.tap-main { display: grid; gap: var(--tap-gap); align-content: start; min-width: 0; }

/* Top bar: identity, optional app-wide search, up to two app-wide icon
   buttons, the switcher, the account. Never page actions. */
.tap-topbar {
  display: flex; align-items: center; gap: 12px 16px;
  min-height: 72px; padding-block: 14px;
}
.tap-brand {
  display: inline-flex; align-items: center; gap: 12px; flex: none;
  color: var(--tap-fg); text-decoration: none;
  font-size: 17px; font-weight: 600; letter-spacing: -.01em;
}
.tap-brand:hover { text-decoration: none; }
.tap-mark {
  width: 32px; height: 32px; border-radius: 10px; flex: none; overflow: hidden;
  display: inline-grid; place-items: center;
  background: var(--tap-app-color); color: #fff;
  font-size: 12.5px; font-weight: 600; letter-spacing: -.01em;
}
.tap-mark img, .tap-mark svg { width: 100%; height: 100%; }
.tap-topbar .search { flex: 0 1 360px; margin-left: 8px; }
.tap-topbar-end { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.tap-topbar-end > button:not(.primary) { width: 40px; padding: 0; border-radius: 50%; }

/* Page heading: eyebrow, h1, page actions on the right. */
.tap-pagehead { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 16px 24px; padding: 4px 0 8px; }
.tap-pagehead > :last-child:not(:first-child) { margin-left: auto; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }

/* Rail: icon links to the app's sections. Label each with aria-label and title. */
.tap-rail {
  position: sticky; top: 16px; align-self: start;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 0; border-radius: var(--tap-r-panel); background: var(--tap-surface);
}
.tap-rail a {
  width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center;
  color: var(--tap-muted); transition: background var(--tap-ease), color var(--tap-ease);
}
.tap-rail a:hover { background: var(--tap-raised); color: var(--tap-fg); }
.tap-rail a[aria-current] { background: var(--tap-accent); color: var(--tap-on-accent); }
.tap-rail hr { width: 24px; margin: 4px 0; }

/* <tap-account> from tap.js */
tap-account { display: inline-flex; }
tap-account > button.avatar { padding: 0; height: 36px; width: 36px; border-radius: 50%; background: var(--tap-raised); font-size: 13px; font-weight: 600; }
tap-account > button.avatar:hover { background: var(--tap-hover); }
tap-account .menu { position: fixed; inset: auto; }
tap-account .seg { width: 100%; }
tap-account .seg > button { flex: 1; }

@media (max-width: 720px) {
  :root { --tap-pad: 18px; }
  .tap-topbar { min-height: 60px; padding-block: 10px; gap: 10px; }
  .tap-topbar .search { display: none; }
  body.tap-rail-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "top" "rail" "main"; row-gap: var(--tap-gap); }
  .tap-rail { position: static; flex-direction: row; padding: 6px; overflow-x: auto; justify-content: flex-start; }
  .tap-rail hr { display: none; }
}

/* ---------------------------------------------------------- 11. Utilities */

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.stack { display: grid; gap: var(--tap-gap); align-content: start; min-width: 0; }
.push { margin-left: auto; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
