/* ============================================================
   MASTER UI — COMPONENTS
   ------------------------------------------------------------
   Universal class names. Pair with tokens.css.
   Convention:
     .{component}                     base
     .{component}-{variant}           variant   (.btn-primary)
     .{component}-{size}              size      (.btn-sm)
     .{component}__{part}             part      (.card__header)
     [data-state="open"|"active"]     state
   ============================================================ */

/* ============================================================
   1. UTILITIES (atomic helpers)
   ============================================================ */
.u-row    { display: flex; align-items: center; gap: var(--space-2); }
.u-col    { display: flex; flex-direction: column; gap: var(--space-2); }
.u-grow   { flex: 1 1 auto; }
.u-mono   { font-family: var(--font-mono); }
.u-muted  { color: var(--fg-muted); }
.u-subtle { color: var(--fg-subtle); }
.u-caps   { text-transform: uppercase; letter-spacing: var(--tracking-caps); font-size: var(--text-xs); font-weight: var(--weight-medium); }
.u-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.u-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; }

/* ============================================================
   2. TYPOGRAPHY
   ============================================================ */
.h1, .h2, .h3, .h4, .h5, .h6 {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  line-height: var(--leading-tight);
  color: var(--fg);
}
.h1 { font-size: var(--text-4xl); }
.h2 { font-size: var(--text-3xl); }
.h3 { font-size: var(--text-2xl); }
.h4 { font-size: var(--text-xl); }
.h5 { font-size: var(--text-lg); }
.h6 { font-size: var(--text-md); font-weight: var(--weight-medium); }

.text-display {
  font-size: var(--text-6xl);
  font-weight: var(--weight-semibold);
  letter-spacing: -0.03em;
  line-height: 1.05;
}

.text-lead { font-size: var(--text-lg); color: var(--fg-muted); line-height: var(--leading-relaxed); }
.text-eyebrow { font-family: var(--font-mono); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: var(--tracking-caps); color: var(--fg-muted); }

a { color: var(--primary); text-decoration: none; transition: color var(--duration-fast) var(--ease-out); }
a:hover { color: var(--primary-hover); }

/* ============================================================
   2b. ICON  —  Phosphor icons (phosphoricons.com)
   ------------------------------------------------------------
   Phosphor Icons (https://phosphoricons.com) — 9,000+ icons, six weights.
   Workflow: copy an icon's SVG from the site (or @phosphor-icons assets),
   paste it, add class="icon". The class sizes it (20px default) and forces
   currentColor over the SVG's fill, so a pasted icon inherits the
   surrounding text color with zero cleanup. Phosphor draws on a 256-grid
   (viewBox="0 0 256 256") and paints with fill — no stroke to manage.

   Sizes:  .icon (20, default)  ·  .icon-sm (16)  ·  .icon-lg (24)
   Weight: regular is canonical. Pull from another weight's folder
           (bold / fill / duotone) deliberately — keep one per project.
   ============================================================ */
.icon {
  width: var(--icon-size);
  height: var(--icon-size);
  flex-shrink: 0;
  display: inline-block;
  vertical-align: middle;
  color: inherit;
}
/* recolor to text color — CSS beats the SVG's presentation attrs,
   so even an unedited pasted icon inherits currentColor */
.icon [fill]:not([fill="none"]),
.icon[fill]:not([fill="none"])     { fill: currentColor; }
.icon [stroke]:not([stroke="none"]),
.icon[stroke]:not([stroke="none"]) { stroke: currentColor; }

.icon-sm { width: var(--icon-sm); height: var(--icon-sm); }
.icon-lg { width: var(--icon-lg); height: var(--icon-lg); }

/* ============================================================
   3. BUTTON
   ============================================================ */
.btn {
  --btn-h: 32px;
  --btn-px: var(--space-3);
  --btn-fs: var(--text-sm);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: var(--btn-h);
  padding: 0 var(--btn-px);
  font-family: var(--font-sans);
  font-size: var(--btn-fs);
  font-weight: var(--weight-medium);
  line-height: 1;
  letter-spacing: 0;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  position: relative;
  isolation: isolate;       /* contain the ::before surface layer */
  transition:
    background var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    color var(--duration-fast) var(--ease-out),
    box-shadow var(--duration-base) var(--ease-out),
    transform 260ms cubic-bezier(0.34, 1.8, 0.5, 1);   /* springy overshoot — bounces in AND out */
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

/* Crisp feedback — the bounce lives on a backing ::before layer (fill + border
   + shadow), NOT on the button itself, so the LABEL never moves: text + icons
   stay razor-sharp with no shimmer. The layer animates `top` (a paint
   property), never `transform`, so it's also never promoted to a GPU layer.
   Solid variants (primary/secondary/danger) get the spring — see the surface
   block below. Plain + grouped buttons keep a simple static shadow lift. */
.btn:hover:not(:disabled):not([aria-disabled="true"]):not(.btn-link):not(.btn-ghost):not(.btn-primary):not(.btn-secondary):not(.btn-danger):not(:focus-visible) {
  box-shadow: var(--shadow);
}
.btn:active:not(:disabled):not([aria-disabled="true"]):not(.btn-link):not(.btn-primary):not(.btn-secondary):not(.btn-danger):not(:focus-visible) {
  box-shadow: var(--shadow-inner);
  transition-duration: var(--duration-fast);
}

/* ---- Surface layer (solid variants) ----
   ::before carries the visible fill / stroke / elevation. The whole .btn — this
   layer, the label, and any icons — bounces together via the element's own
   `transform` (set below), so the contents stay pinned to the moving button.
   Painting the fill here lets the primary keep its inner hairline as an inset
   shadow that bounces along too. */
.btn-primary::before,
.btn-secondary::before,
.btn-danger::before {
  content: "";
  position: absolute;
  inset: -1px;                       /* cover the full visual (border) box */
  z-index: -1;                       /* sit behind the label */
  border-radius: var(--radius);
  border: 1px solid transparent;
  transition:
    background var(--duration-fast) var(--ease-out),
    border-color var(--duration-fast) var(--ease-out),
    /* elevation rides the same spring as the lift, so body + shadow stay glued */
    box-shadow 260ms cubic-bezier(0.34, 1.8, 0.5, 1);
}
/* Solid buttons bounce as a rigid unit — the whole element (body + text +
   icons) translates together, so the label is pinned to the moving button and
   moves in perfect sync (no per-glyph pixel-snapping stutter). `transform` is
   applied ONLY while hovering/pressing — no `will-change`, no permanent layer —
   so at rest there's no compositing and text stays crisp. Lift 2px on hover
   with a spring overshoot; press 2px below rest on click. */
.btn-primary:hover:not(:disabled):not([aria-disabled="true"]),
.btn-secondary:hover:not(:disabled):not([aria-disabled="true"]),
.btn-danger:hover:not(:disabled):not([aria-disabled="true"]) { transform: translateY(-2px); }
/* Keep the label color stable on hover. When a .btn is an <a>, the global
   `a:hover { color: var(--primary-hover) }` would otherwise repaint the text —
   solid buttons must hold their own foreground. */
.btn-primary:hover:not(:disabled):not([aria-disabled="true"]),
.btn-secondary:hover:not(:disabled):not([aria-disabled="true"]) { color: var(--fg); }
.btn-danger:hover:not(:disabled):not([aria-disabled="true"]) { color: #fff; }
.btn-primary:active:not(:disabled):not([aria-disabled="true"]),
.btn-secondary:active:not(:disabled):not([aria-disabled="true"]),
.btn-danger:active:not(:disabled):not([aria-disabled="true"]) {
  transform: translateY(2px);        /* presses below rest — a clear click-down */
  transition-duration: var(--duration-fast);
}
/* Segmented-control segments stay put — they must not bounce individually. */
.btn-group .btn:hover,
.btn-group .btn:active { transform: none !important; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; pointer-events: none; }
.btn .icon { width: var(--icon-size); height: var(--icon-size); flex-shrink: 0; }

/* sizes */
.btn-sm { --btn-h: 28px; --btn-px: var(--space-3); --btn-fs: var(--text-xs); }
.btn-lg { --btn-h: 40px; --btn-px: var(--space-5); --btn-fs: var(--text-base); }

/* variants */
.btn-primary {
  color: var(--fg);
  background: transparent;        /* fill is painted on the bouncing ::before */
  border: 1px solid transparent;  /* geometry only — visible stroke is on ::before */
}
/* Translucent brand fill + outer stroke, with the inner --surface hairline as
   an inset shadow so the double-stroke bounces together with the fill. */
.btn-primary::before {
  background: color-mix(in srgb, var(--primary) 16%, transparent);
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--surface), var(--shadow-sm);
}
.btn-primary:hover:not(:disabled):not([aria-disabled="true"])::before {
  background: color-mix(in srgb, var(--primary) 26%, transparent);
  border-color: var(--primary-hover);
  box-shadow: inset 0 0 0 1px var(--surface), var(--shadow);
}
.btn-primary:active:not(:disabled):not([aria-disabled="true"])::before {
  box-shadow: inset 0 0 0 1px var(--surface), var(--shadow-inner);
}

/* Focus ring sits outside the button so it stays readable */
.btn-primary:focus-visible {
  box-shadow: 0 0 0 3px var(--ring);
}

[data-theme="dark"] .btn-primary { color: var(--fg); }
[data-theme="dark"] .btn-primary::before {
  /* Slightly stronger tint so it reads on dark surfaces */
  background: color-mix(in srgb, var(--primary) 16%, transparent);
  border-color: var(--primary);
  box-shadow: inset 0 0 0 1px var(--surface), var(--shadow-sm);
}
[data-theme="dark"] .btn-primary:hover:not(:disabled):not([aria-disabled="true"])::before {
  background: color-mix(in srgb, var(--primary) 24%, transparent);
  border-color: var(--primary-hover);
}

.btn-secondary {
  color: var(--fg);
  background: transparent;        /* painted on the bouncing ::before */
  border: 1px solid transparent;
}
.btn-secondary::before { background: var(--surface); border-color: var(--border); }
.btn-secondary:hover:not(:disabled):not([aria-disabled="true"])::before {
  background: var(--surface-hover);
  border-color: var(--border-strong);
  box-shadow: var(--shadow);
}
.btn-secondary:active:not(:disabled):not([aria-disabled="true"])::before { box-shadow: var(--shadow-inner); }

.btn-ghost {
  background: transparent;
  color: var(--fg);
}
.btn-ghost:hover { background: var(--surface-hover); color: var(--fg); }
/* Active / selected (e.g. current nav item) */
.btn-ghost[aria-pressed="true"],
.btn-ghost.is-active { background: var(--surface-active); }

.btn-danger {
  color: #fff;
  background: transparent;        /* painted on the bouncing ::before */
  border: 1px solid transparent;
}
.btn-danger::before { background: var(--danger); border-color: var(--danger); }
.btn-danger:hover:not(:disabled):not([aria-disabled="true"])::before {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
  box-shadow: var(--shadow);
}
.btn-danger:active:not(:disabled):not([aria-disabled="true"])::before { box-shadow: var(--shadow-inner); }

.btn-link {
  background: transparent;
  color: var(--primary);
  border: none;
  padding: 0;
  height: auto;
}
.btn-link:hover { color: var(--primary-hover); text-decoration: underline; text-underline-offset: 3px; }

/* icon-only */
.btn-icon { padding: 0; width: var(--btn-h); }

/* button group */
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-top-left-radius: var(--radius); border-bottom-left-radius: var(--radius); }
.btn-group .btn:last-child  { border-top-right-radius: var(--radius); border-bottom-right-radius: var(--radius); }
.btn-group .btn + .btn { margin-left: -1px; }
.btn-group .btn:hover, .btn-group .btn[aria-pressed="true"] { z-index: 1; }
/* Selected segment — tonal brand fill, matching the primary button language */
.btn-group .btn[aria-pressed="true"] {
  background: color-mix(in srgb, var(--primary) 16%, transparent);
  border-color: var(--primary);
  color: var(--fg);
}
/* Segmented control keeps fills/strokes on the element (flush shared seams,
   square inner corners) and does NOT bounce per-segment — disable the surface
   layer and restore element-level fills inside a group. */
.btn-group .btn-primary::before,
.btn-group .btn-secondary::before,
.btn-group .btn-danger::before { display: none; }
.btn-group .btn-secondary { background: var(--surface); border-color: var(--border); }
.btn-group .btn-secondary:hover { background: var(--surface-hover); border-color: var(--border-strong); }

/* ============================================================
   3b. SPLASH BUTTON  ·  .btn-splash
   ------------------------------------------------------------
   For marketing pages, splash screens, and launch pages.
   At rest: bare text — no border, no background.
   On hover: a 4-pointed shining-star appears at the top-left
   corner (fading cross + 1px circle ring) and a gradient bar
   materialises beneath the label.
   Use .btn-splash--on-dark when placing on dark surfaces.
   ============================================================ */
.btn-splash {
  /* 4-point shining star (cross arms + 1px ring) drawn as an SVG vector
     mask over currentColor. Arms are SOLID 1px, fade only at the tips, and
     are pixel-aligned (integer rows + crispEdges) so they render as a true
     1px line rather than a 2px anti-aliased straddle. Star is centred on
     11.5 so the cross and ring stay concentric on the pixel grid. */
  --splash-star: url("data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%2024%2024'%3E%3Cdefs%3E%3ClinearGradient%20id='h'%20x1='0'%20x2='1'%20y1='0'%20y2='0'%3E%3Cstop%20offset='0'%20stop-color='%23fff'%20stop-opacity='0'/%3E%3Cstop%20offset='.22'%20stop-color='%23fff'/%3E%3Cstop%20offset='.78'%20stop-color='%23fff'/%3E%3Cstop%20offset='1'%20stop-color='%23fff'%20stop-opacity='0'/%3E%3C/linearGradient%3E%3ClinearGradient%20id='v'%20x1='0'%20x2='0'%20y1='0'%20y2='1'%3E%3Cstop%20offset='0'%20stop-color='%23fff'%20stop-opacity='0'/%3E%3Cstop%20offset='.22'%20stop-color='%23fff'/%3E%3Cstop%20offset='.78'%20stop-color='%23fff'/%3E%3Cstop%20offset='1'%20stop-color='%23fff'%20stop-opacity='0'/%3E%3C/linearGradient%3E%3C/defs%3E%3Crect%20x='0'%20y='11'%20width='24'%20height='1'%20fill='url(%23h)'%20shape-rendering='crispEdges'/%3E%3Crect%20x='11'%20y='0'%20width='1'%20height='24'%20fill='url(%23v)'%20shape-rendering='crispEdges'/%3E%3Ccircle%20cx='11.5'%20cy='11.5'%20r='4.5'%20fill='none'%20stroke='%23fff'%20stroke-width='1'/%3E%3C/svg%3E");
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  height: var(--btn-h, 32px);
  padding: 0 var(--btn-px, var(--space-3));
  background: none;
  border: none;
  border-radius: 0;
  font-family: var(--font-sans);
  font-size: var(--btn-fs, var(--text-sm));
  font-weight: var(--weight-medium);
  color: var(--fg);
  cursor: pointer;
  position: relative;
  isolation: isolate;
  text-decoration: none;
  -webkit-font-smoothing: antialiased;
}
.btn-splash--on-dark { color: #fff; }

/* The 4-pointed star at the top-left corner — SVG vector mask over
   currentColor. Same fading-cross + ring shape as before, but the vector
   engine keeps it crisp at every rotation angle (stacked 1px CSS gradient
   hairlines blurred badly once rotated). */
.btn-splash::before {
  content: "";
  position: absolute;
  top: 0; left: 0;
  width: 24px; height: 24px;
  background: currentColor;
  -webkit-mask: var(--splash-star) center / contain no-repeat;
  mask: var(--splash-star) center / contain no-repeat;
  transform: translate(-50%, -50%) scale(0.5);
  opacity: 0;
  transition: opacity 0.22s var(--ease-in);
}
.btn-splash:hover::before {
  animation: btn-splash-enter 0.5s var(--ease-spring) forwards;
}

/* Fading gradient bar beneath the text label */
.btn-splash::after {
  content: "";
  position: absolute;
  bottom: 3px;
  left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%,
    currentColor 25%,
    currentColor 75%,
    transparent 100%
  );
  transform-origin: center;
  transform: scaleX(0.4);
  opacity: 0;
  transition:
    opacity 0.22s var(--ease-out),
    transform 0.22s var(--ease-out);
}
.btn-splash:hover {
  color: var(--fg);
}
.btn-splash:hover::after {
  opacity: 1;
  transform: scaleX(1);
}

/* Pop-in entrance — simple scale + fade; rests at rotate(0) where the
   1px cross is pixel-aligned and razor-sharp. */
@keyframes btn-splash-enter {
  from { opacity: 0; transform: translate(-50%,-50%) scale(0.4); }
  to   { opacity: 1; transform: translate(-50%,-50%) scale(1);   }
}

/* Pop-out — triggered by .is-leaving added via JS on mouseleave */
.btn-splash.is-leaving::before {
  animation: btn-splash-leave 0.28s var(--ease-spring) forwards !important;
}
@keyframes btn-splash-leave {
  from { opacity: 1; transform: translate(-50%,-50%) scale(1);   }
  to   { opacity: 0; transform: translate(-50%,-50%) scale(0.4); }
}

.btn-splash:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 3px;
  border-radius: var(--radius-sm);
}
.btn-splash:disabled,
.btn-splash[aria-disabled="true"] { opacity: 0.4; pointer-events: none; }

/* ============================================================
   4. FORM INPUTS
   ============================================================ */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.label { font-size: var(--text-xs); font-weight: var(--weight-medium); color: var(--fg); }
.label .required { color: var(--danger); margin-left: 2px; }
.hint  { font-size: var(--text-xs); color: var(--fg-muted); }
.error { font-size: var(--text-xs); color: var(--danger); }

.input,
.textarea,
.select {
  height: 32px;
  padding: 0 var(--space-3);
  font-family: var(--font-sans);
  font-size: var(--text-sm);
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: border-color var(--duration-fast) var(--ease-out),
              box-shadow var(--duration-fast) var(--ease-out),
              background var(--duration-fast) var(--ease-out);
  width: 100%;
}
.input::placeholder, .textarea::placeholder { color: var(--fg-subtle); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--border-strong); }
.input:focus, .textarea:focus, .select:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--ring);
}
.input:disabled, .textarea:disabled, .select:disabled {
  background: var(--bg-muted);
  color: var(--fg-subtle);
  cursor: not-allowed;
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"], .select[aria-invalid="true"] {
  border-color: var(--danger);
}
.input[aria-invalid="true"]:focus,
.textarea[aria-invalid="true"]:focus,
.select[aria-invalid="true"]:focus { box-shadow: 0 0 0 3px var(--ring-danger); }

/* error message — animates in when shown by forms.js */
.error[data-error] {
  margin: 0;
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: max-height var(--duration-base) var(--ease-out),
              opacity var(--duration-fast) var(--ease-out);
}
.error[data-error].is-shown {
  max-height: 3em;
  opacity: 1;
}

/* password strength meter */
.strength { display: flex; align-items: center; gap: var(--space-2); }
.strength__bars {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  flex: 1;
}
.strength__bars i {
  height: 4px;
  border-radius: var(--radius-full);
  background: var(--bg-muted);
  transition: background var(--duration-base) var(--ease-out);
}
/* fill N bars based on score, colored weak→strong */
.strength__bars[data-score="1"] i:nth-child(-n+1),
.strength__bars[data-score="2"] i:nth-child(-n+2),
.strength__bars[data-score="3"] i:nth-child(-n+3) { background: var(--strength-color, var(--fg-subtle)); }
.strength__bars[data-score="1"] { --strength-color: var(--danger); }
.strength__bars[data-score="2"] { --strength-color: var(--warning); }
.strength__bars[data-score="3"] { --strength-color: var(--success); }
.strength__label {
  font-size: var(--text-2xs);
  color: var(--fg-muted);
  min-width: 5ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.textarea {
  height: auto;
  min-height: 80px;
  padding: var(--space-2) var(--space-3);
  line-height: var(--leading-snug);
  resize: vertical;
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23a1a1aa' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'></polyline></svg>");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
  padding-right: var(--space-8);
}

/* sizes */
.input-sm, .select-sm { height: 28px; font-size: var(--text-xs); padding-left: var(--space-2); padding-right: var(--space-2); }
.input-lg, .select-lg { height: 40px; font-size: var(--text-base); }

/* input with prefix/suffix wrapper */
.input-group {
  display: flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
}
.input-group:focus-within { border-color: var(--border-focus); box-shadow: 0 0 0 3px var(--ring); }
.input-group .input { border: none; box-shadow: none; }
.input-group .input:focus { box-shadow: none; }
.input-group__addon {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0 var(--space-3);
  background: var(--bg-subtle);
  color: var(--fg-muted);
  font-size: var(--text-xs);
  border-right: 1px solid var(--border);
}
.input-group__addon:last-child { border-right: none; border-left: 1px solid var(--border); }

/* custom dropdown — styled trigger + popover menu */
.dropdown { position: relative; display: block; }
.dropdown__trigger {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; height: 32px;
  padding: 0 var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  font-family: inherit;
  color: var(--fg);
  cursor: pointer;
  gap: var(--space-2);
  text-align: left;
  transition: border-color var(--duration-fast) var(--ease-out);
}
.dropdown__trigger:hover { border-color: var(--border-strong); }
.dropdown__trigger:focus-visible {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--ring);
}
.dropdown__value { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dropdown__caret { flex-shrink: 0; color: var(--fg-muted); transition: transform var(--duration-fast) var(--ease-out); }
.dropdown.is-open .dropdown__caret { transform: rotate(180deg); }
.dropdown__menu {
  position: absolute;
  top: calc(100% + var(--space-1));
  left: 0; right: 0;
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transform: translateY(-4px);
  transition:
    opacity var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out),
    visibility 0s var(--duration-fast);
}
.dropdown.is-open .dropdown__menu {
  opacity: 1; visibility: visible; transform: translateY(0);
  transition:
    opacity var(--duration-fast) var(--ease-out),
    transform var(--duration-fast) var(--ease-out),
    visibility 0s 0s;
}
.dropdown__option { user-select: none; }
.dropdown__option[aria-selected="true"] { color: var(--primary-fg); background: var(--primary-subtle); }

/* dropdown inside overflow-scroll contexts (e.g. modals) —
   menu switches to fixed positioning; JS anchors via getBoundingClientRect */
.dropdown--fixed .dropdown__menu { position: fixed; }

/* checkbox + radio */
.checkbox,
.radio {
  appearance: none;
  width: 16px; height: 16px;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  cursor: pointer;
  display: inline-grid;
  place-content: center;
  transition: background var(--duration-fast), border-color var(--duration-fast);
  flex-shrink: 0;
}
.checkbox { border-radius: var(--radius); }
.radio    { border-radius: var(--radius-full); }
.checkbox:hover, .radio:hover { border-color: var(--fg-muted); }
.checkbox:checked, .radio:checked {
  background: var(--primary);
  border-color: var(--primary);
}
.checkbox:checked::after {
  content: ""; width: 9px; height: 9px;
  background: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'></polyline></svg>") center/contain no-repeat;
}
.radio:checked::after {
  content: ""; width: 6px; height: 6px; border-radius: var(--radius-full); background: #fff;
}
.checkbox:focus-visible, .radio:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

.check-row { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; font-size: var(--text-sm); }

/* switch */
.switch {
  appearance: none;
  position: relative;
  width: 32px; height: 18px;
  background: var(--border-strong);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: background var(--duration-base);
  flex-shrink: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  border-radius: var(--radius-full);
  background: #fff;
  box-shadow: var(--shadow);
  transition: transform var(--duration-base) var(--ease-spring);
}
.switch:checked { background: var(--primary); }
.switch:checked::after { transform: translateX(14px); }
.switch:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

/* ============================================================
   5. CARD / SURFACE
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card__header,
.card__footer {
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-3);
}
.card__footer { border-bottom: none; border-top: 1px solid var(--border); background: var(--bg-subtle); }
.card__body { padding: var(--space-5); }
.card__title { font-size: var(--text-base); font-weight: var(--weight-semibold); margin: 0; }
.card__subtitle { font-size: var(--text-xs); color: var(--fg-muted); margin-top: 2px; }

/* glass surface */
.glass {
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius);
}

/* stat tile */
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-4) var(--space-5);
  display: flex; flex-direction: column; gap: var(--space-1);
}
.stat__label { font-size: var(--text-xs); color: var(--fg-muted); font-weight: var(--weight-medium); }
.stat__value { font-size: var(--text-2xl); font-weight: var(--weight-semibold); letter-spacing: var(--tracking-tight); font-variant-numeric: tabular-nums; }
.stat__delta { font-size: var(--text-xs); font-family: var(--font-mono); }
.stat__delta--up   { color: var(--success); }
.stat__delta--down { color: var(--danger); }

/* ============================================================
   6. BADGE / CHIP / TAG
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  height: 20px;
  padding: 0 var(--space-2);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  letter-spacing: var(--tracking-wide);
  text-transform: uppercase;
  border-radius: var(--radius);
  background: var(--bg-muted);
  color: var(--fg-muted);
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-success { background: var(--success-subtle); color: var(--success-fg); }
.badge-warning { background: var(--warning-subtle); color: var(--warning-fg); }
.badge-danger  { background: var(--danger-subtle);  color: var(--danger-fg); }
.badge-info    { background: var(--info-subtle);    color: var(--info-fg); }
.badge-accent  { background: var(--primary-subtle);  color: var(--primary-fg); }
.badge-outline { background: transparent; border-color: var(--border); color: var(--fg-muted); }

.badge .dot { width: 6px; height: 6px; border-radius: var(--radius-full); background: currentColor; }

/* chip — larger, removable */
.chip {
  display: inline-flex; align-items: center; gap: var(--space-2);
  height: 26px;
  padding: 0 var(--space-3);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  background: var(--bg-muted);
  color: var(--fg);
  border-radius: var(--radius-full);
  border: 1px solid var(--border);
}
.chip__close { cursor: pointer; opacity: 0.6; line-height: 1; }
.chip__close:hover { opacity: 1; }

/* tag — square, mono, technical */
.tag {
  display: inline-flex; align-items: center;
  height: 20px;
  padding: 0 var(--space-2);
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  background: var(--bg-muted);
  color: var(--fg-muted);
  border-radius: var(--radius);
}

/* ============================================================
   7. AVATAR
   ============================================================ */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: var(--radius-full);
  background: var(--bg-muted);
  color: var(--fg);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  overflow: hidden;
  flex-shrink: 0;
  border: 1px solid var(--border);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar-xs { width: 20px; height: 20px; font-size: 9px; }
.avatar-sm { width: 24px; height: 24px; font-size: 10px; }
.avatar-lg { width: 40px; height: 40px; font-size: var(--text-sm); }
.avatar-xl { width: 56px; height: 56px; font-size: var(--text-md); }

.avatar-group { display: inline-flex; }
.avatar-group .avatar + .avatar { margin-left: -8px; }
.avatar-group .avatar { box-shadow: 0 0 0 2px var(--bg); }

/* user row */
.user {
  display: inline-flex; align-items: center; gap: var(--space-2);
}
.user__name { font-size: var(--text-sm); font-weight: var(--weight-medium); }
.user__meta { font-size: var(--text-xs); color: var(--fg-muted); }

/* ============================================================
   8. TABLE
   ============================================================ */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}
.table th,
.table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-variant-numeric: tabular-nums;
  vertical-align: middle;
}
.table thead th {
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  color: var(--fg-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 1;
  white-space: nowrap;
}
.table tbody tr { transition: background var(--duration-fast); }
.table tbody tr:hover { background: var(--surface-hover); }
.table tbody tr:hover td { border-bottom-color: transparent; }
.table tbody tr:has(+ tr:hover) td { border-bottom-color: transparent; }
.table tbody tr:last-child td { border-bottom: none; }
.table .num { text-align: right; font-family: var(--font-mono); }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* ============================================================
   9. NAVIGATION
   ============================================================ */
/* top bar */
.topbar {
  height: var(--topbar-h);
  display: flex; align-items: center;
  padding: 0 var(--space-5);
  gap: var(--space-4);
  background: var(--glass);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: var(--z-sticky);
}
.topbar__brand { display: flex; align-items: center; gap: var(--space-2); font-weight: var(--weight-semibold); font-size: var(--text-base); }

/* side nav */
.sidenav {
  width: var(--sidebar-w);
  height: 100%;
  background: var(--bg-subtle);
  border-right: 1px solid var(--border);
  padding: var(--space-3);
  display: flex; flex-direction: column; gap: var(--space-1);
}
.sidenav__section { margin-top: var(--space-4); font-size: var(--text-2xs); color: var(--fg-subtle); text-transform: uppercase; letter-spacing: var(--tracking-caps); padding: 0 var(--space-2) var(--space-2); }
.sidenav__item {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  color: var(--fg-muted);
  cursor: pointer;
  transition: background var(--duration-fast), color var(--duration-fast);
  text-decoration: none;
}
.sidenav__item:hover { background: var(--surface-hover); color: var(--fg); }
.sidenav__item[aria-current="page"],
.sidenav__item.is-active {
  background: var(--primary-subtle) !important;
  color: var(--primary) !important;
  font-weight: var(--weight-semibold);
  box-shadow: none;
  transition: none;
}
.sidenav__item .icon { width: var(--icon-sm); height: var(--icon-sm); flex-shrink: 0; opacity: 0.7; }

/* tabs */
.tabs {
  position: relative;
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
}
.tab {
  position: relative;
  padding: var(--space-2) var(--space-3);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--fg-muted);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: color var(--duration-fast);
}
.tab:hover { color: var(--fg); }
/* sliding selected-tab underbar */
.tabs__bar {
  position: absolute;
  bottom: 0;
  height: 2px;
  background: var(--fg);
  border-radius: var(--radius-full);
  pointer-events: none;
  transition:
    transform var(--hover-slide-duration) var(--hover-slide-ease),
    width    var(--hover-slide-duration) var(--hover-slide-ease);
  will-change: transform, width;
}
/* hover ghost bar — primary color, fades in/out */
.tabs__hover-bar {
  position: absolute;
  bottom: 0;
  height: 2px;
  background: var(--primary);
  border-radius: var(--radius-full);
  pointer-events: none;
  opacity: 0;
  transition:
    transform var(--hover-slide-duration) var(--hover-slide-ease),
    width    var(--hover-slide-duration) var(--hover-slide-ease),
    opacity  var(--duration-fast) var(--ease-out);
  will-change: transform, width, opacity;
}
/* static selected-tab underline (no-JS fallback) */
.tab[aria-selected="true"]::after,
.tab.is-active::after {
  content: "";
  position: absolute;
  left: var(--space-3); right: var(--space-3); bottom: -1px; height: 2px;
  background: var(--fg);
  border-radius: var(--radius-full);
}
/* hide it when JS replaces it with the sliding bar */
.js-motion .tab[aria-selected="true"]::after,
.js-motion .tab.is-active::after { display: none; }

/* breadcrumb */
.breadcrumb { display: flex; align-items: center; gap: var(--space-2); font-size: var(--text-xs); color: var(--fg-muted); }
.breadcrumb a { color: var(--fg-muted); }
.breadcrumb a:hover { color: var(--fg); }
.breadcrumb__sep { color: var(--fg-subtle); }
.breadcrumb [aria-current="page"] { color: var(--fg); }

/* ============================================================
   10. MODAL / DIALOG
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: var(--overlay);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: grid; place-items: center;
  z-index: var(--z-modal);
  animation: fade-in var(--duration-base) var(--ease-out);
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(100%, 480px);
  max-height: 90vh;
  display: flex; flex-direction: column;
  animation: pop-in var(--duration-base) var(--ease-spring);
}
.modal__header {
  padding: var(--space-5) var(--space-5) var(--space-3);
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3);
}
.modal__title { font-size: var(--text-lg); font-weight: var(--weight-semibold); margin: 0; }
.modal__close { width: 28px; height: 28px; border: none; background: transparent; border-radius: var(--radius); cursor: pointer; color: var(--fg-muted); display: grid; place-items: center; }
.modal__close:hover { background: var(--surface-hover); color: var(--fg); }
.modal__body { padding: 0 var(--space-5) var(--space-5); overflow-y: auto; color: var(--fg-muted); font-size: var(--text-sm); line-height: var(--leading-relaxed); }
.modal__footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: var(--space-2); }

/* Modal — fullscreen sheet on mobile */
@media (max-width: 520px) {
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal {
    width: 100%;
    border-radius: var(--radius) var(--radius) 0 0;
    max-height: 92dvh;
    animation: slide-up var(--duration-base) var(--ease-out);
  }
  @keyframes slide-up {
    from { transform: translateY(20px); opacity: 0; }
    to   { transform: translateY(0);    opacity: 1; }
  }
}

/* ============================================================
   11. TOAST / ALERT
   ============================================================ */
.toast {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: var(--text-sm);
  min-width: 280px; max-width: 420px;
}
.toast__title { font-weight: var(--weight-medium); }
.toast__desc  { color: var(--fg-muted); margin-top: 2px; font-size: var(--text-xs); }
.toast__icon  { width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px; }

/* live toast stack (created by forms.js) */
.toast-region {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  pointer-events: none;
}
.toast-region .toast {
  pointer-events: auto;
  cursor: pointer;
  transition: opacity var(--duration-base) var(--ease-out),
              transform var(--duration-base) var(--ease-spring);
}
.toast--enter { opacity: 0; transform: translateY(8px) scale(0.98); }
.toast--leave { opacity: 0; transform: translateX(12px); }
@media (max-width: 520px) {
  .toast-region { left: var(--space-4); right: var(--space-4); bottom: var(--space-4); }
  .toast-region .toast { min-width: 0; width: 100%; }
}

.alert {
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  font-size: var(--text-sm);
  border: 1px solid;
}
.alert-info    { background: var(--info-subtle);    border-color: transparent; color: var(--info-fg); }
.alert-success { background: var(--success-subtle); border-color: transparent; color: var(--success-fg); }
.alert-warning { background: var(--warning-subtle); border-color: transparent; color: var(--warning-fg); }
.alert-danger  { background: var(--danger-subtle);  border-color: transparent; color: var(--danger-fg); }

/* ============================================================
   12. TOOLTIP / POPOVER
   ============================================================ */
.tooltip {
  position: absolute;
  bottom: calc(100% + var(--space-2));
  left: 50%;
  transform: translateX(-50%);
  padding: var(--space-1) var(--space-2);
  background: var(--fg);
  color: var(--bg);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  white-space: nowrap;
  pointer-events: none;
  z-index: 200;
  opacity: 0;
  visibility: hidden;
  transition:
    opacity var(--duration-fast) var(--ease-out),
    visibility 0s var(--duration-fast);
}
.tooltip-wrap {
  position: relative;
  display: inline-flex;
}
.tooltip-wrap:hover .tooltip,
.tooltip-wrap:focus-within .tooltip {
  opacity: 1;
  visibility: visible;
  transition:
    opacity var(--duration-fast) var(--ease-out),
    visibility 0s 0s;
}
.popover {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: var(--space-2);
  min-width: 180px;
  font-size: var(--text-sm);
}
.popover__item {
  display: flex; align-items: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-2);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--fg);
}
.popover__item:hover { background: var(--surface-hover); }
.popover__sep { height: 1px; background: var(--border); margin: var(--space-1) 0; }

/* ============================================================
   13. LOADING — SKELETON + SPINNER
   ============================================================ */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-muted) 0%,
    var(--surface-hover) 50%,
    var(--bg-muted) 100%
  );
  background-size: 200% 100%;
  border-radius: var(--radius);
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
.skeleton-text { height: 0.9em; border-radius: var(--radius); }
.skeleton-circle { border-radius: var(--radius-full); }

.spinner {
  width: 16px; height: 16px;
  border: 2px solid;
  border-color: color-mix(in srgb, currentColor 20%, transparent);
  border-top-color: currentColor;
  border-radius: var(--radius-full);
  animation: spin 0.7s linear infinite;
  display: inline-block;
  flex-shrink: 0;
}
.spinner-sm { width: 12px; height: 12px; border-width: 1.5px; }
.spinner-lg { width: 24px; height: 24px; border-width: 2.5px; }

.progress {
  width: 100%; height: 6px;
  background: var(--bg-muted);
  border-radius: var(--radius-full);
  overflow: hidden;
}
.progress__bar {
  height: 100%;
  background: var(--primary);
  border-radius: var(--radius-full);
  transition: width var(--duration-slow) var(--ease-out);
}

/* ============================================================
   14. CODE / KBD
   ============================================================ */
code, .code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  padding: 2px 6px;
  background: var(--bg-muted);
  color: var(--fg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
pre {
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  background: var(--bg-subtle);
  color: var(--fg);
  padding: var(--space-4);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow-x: auto;
  line-height: var(--leading-snug);
  margin: 0;
}
pre code { background: transparent; padding: 0; border: none; font-size: inherit; }

kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px;
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: var(--text-2xs);
  font-weight: var(--weight-medium);
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--radius);
  color: var(--fg-muted);
}

/* ============================================================
   15. DIVIDER / SEPARATOR
   ============================================================ */
.divider {
  height: 1px;
  background: var(--border);
  border: none;
  margin: var(--space-4) 0;
}
.divider-vertical { width: 1px; height: 100%; background: var(--border); }

/* ============================================================
   16. EMPTY STATE
   ============================================================ */
.empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-3);
  padding: var(--space-12) var(--space-6);
  text-align: center;
  color: var(--fg-muted);
}
.empty__icon { width: 40px; height: 40px; opacity: 0.4; }
.empty__title { font-size: var(--text-base); font-weight: var(--weight-medium); color: var(--fg); }
.empty__desc { font-size: var(--text-sm); max-width: 320px; }

/* ============================================================
   17. ANIMATIONS
   ============================================================ */
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes pop-in {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
@keyframes slide-in-bottom {
  from { opacity: 0; transform: translateY(12px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================================
   17. SLIDING HOVER INDICATOR (motion.js)
   A single highlight per group, animates between siblings instead
   of fading in/out. See motion.js for which groups auto-attach.
   ============================================================ */
.hover-indicator {
  position: absolute;
  top: 0;
  left: 0;
  width: 0;
  height: 0;
  background: var(--bg-muted);
  border-radius: var(--radius);
  pointer-events: none;
  opacity: 0;
  transform: translate(0, 0);
  transition:
    transform var(--hover-slide-duration) var(--hover-slide-ease),
    width    var(--hover-slide-duration) var(--hover-slide-ease),
    height   var(--hover-slide-duration) var(--hover-slide-ease),
    border-radius var(--hover-slide-duration) var(--hover-slide-ease),
    opacity  var(--duration-fast) var(--ease-out);
  will-change: transform, width, height;
  z-index: 0;
}

/* Items must paint above the indicator. We only do this when JS is
   live so the layout/feedback is unchanged for no-JS users. */
.js-motion .sidenav__item,
.js-motion .popover__item,
.js-motion .tab { position: relative; z-index: 1; }
.js-motion .table td,
.js-motion .table th,
.js-motion .token-table td,
.js-motion .token-table th { position: relative; z-index: 1; }

/* Disable native :hover backgrounds where the indicator takes over,
   so we don't get a double highlight. */
.js-motion .sidenav__item:hover,
.js-motion .popover__item:hover,
.js-motion .table tbody tr:hover,
.js-motion .token-table tbody tr:hover,
.js-motion .token-table tr:hover { background: transparent; }
.js-motion .table tbody tr:hover td,
.js-motion .table tbody tr:has(+ tr:hover) td { border-bottom-color: var(--border); }

/* Active sidenav item — primary tint wins over the motion indicator */
.js-motion .sidenav__item[aria-current="page"],
.js-motion .sidenav__item.is-active {
  background: var(--primary-subtle) !important;
  color: var(--primary) !important;
  transition: none;
}

/* Sidenav hover indicator uses a primary tint */
.sidenav .hover-indicator { background: var(--primary-subtle); }

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