/* ============================================================================
   KIT · BASE + PRIMITIVES — reset, typography, layout utilities, and every
   design-system component class. Borderless; all fills derive from the tokens.
   Vendor this (with tokens.css) into any project; it knows nothing about an app.
   ========================================================================= */

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

body {
  margin: 0;
  font-family: var(--font);
  font-size: var(--text-base);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background var(--transition), color var(--transition);
}

h1, h2, h3 { line-height: 1.2; margin: 0 0 var(--space-3); letter-spacing: var(--tracking-tight); }
h1 { font-size: var(--text-2xl); font-weight: var(--weight-bold); }
h2 { font-size: var(--text-xl); font-weight: var(--weight-semibold); }
h3 { font-size: var(--text-lg); font-weight: var(--weight-semibold); }
p  { margin: 0 0 var(--space-3); color: var(--text-muted); }
p:last-child { margin-bottom: 0; }
a  { color: var(--accent-text); }
code { font-family: var(--font-mono); font-size: 0.85em;
       background: color-mix(in srgb, var(--text) 8%, transparent);
       padding: 0.15em 0.45em; border-radius: var(--radius-1); }

.container { max-width: 780px; margin: 0 auto; padding: var(--space-8) var(--space-5); }
.stack > * + * { margin-top: var(--space-4); }
.row { display: flex; gap: var(--space-3); flex-wrap: wrap; align-items: center; }
.grid { display: grid; gap: var(--space-3); grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.muted { color: var(--text-muted); }

/* Page header */
.page-header { display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); }

/* Sections: separated by whitespace alone — no rule, no box. */
.section { margin-top: var(--space-8); }
.section__title { font-size: var(--text-base); font-weight: var(--weight-semibold);
                  letter-spacing: var(--tracking-tight); color: var(--text); margin: 0 0 var(--space-4); }
.section__body > * + * { margin-top: var(--space-4); }

/* Divider — a faded rule for an EXPLICIT separation (whitespace stays the default).
   Borderless in spirit: it tapers to transparent at both ends, suggesting separation
   rather than drawing a hard boxy line. Neutral by design — a divider is structure, so
   it derives from --text / --text-muted and never follows the accent. Pure CSS; the
   line color-mixes off --text, so it adapts to dark mode with the rest of the tokens.

   Owns NO outer margin — like every other kit component, spacing comes from the
   surrounding layout (.stack, .section, a flex gap). That lets it sit correctly both as
   a standalone section break and as a list-item separator (e.g. between feed posts).

   Built from two half-rules (the centre is where they meet): each ramps to full
   strength quickly and then HOLDS solid, tapering off only over the outer ~35% out to
   the page edge — so the line reads as a long rule with soft ends. The base form is a
   continuous line; the `--ornament` modifier opens a gap for a centred ◆ "fleuron". */
.divider { display: flex; align-items: center; border: none; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; }
.divider::before { background: linear-gradient(to right, transparent, color-mix(in srgb, var(--text) 16%, transparent) 35%); }
.divider::after  { background: linear-gradient(to left,  transparent, color-mix(in srgb, var(--text) 16%, transparent) 35%); }
/* Ornamented: open a gap between the half-rules and drop a muted ◆ into it. */
.divider--ornament { gap: var(--space-3); }
.divider__mark { flex: none; color: var(--text-muted); font-size: 0.7rem; line-height: 1; }

/* ============================================================================
   COMPONENTS — all borderless; fills come from --field / --accent.
   ========================================================================= */

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  font-family: inherit; font-size: var(--text-base); font-weight: var(--weight-medium);
  border: none; border-radius: var(--radius-2);
  color: var(--text); background: var(--field); text-decoration: none;
  cursor: pointer; user-select: none;
  transition: background var(--transition), box-shadow var(--transition), transform var(--transition), opacity var(--transition);
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn--primary   { background: var(--accent); color: var(--on-accent); --spinner-color: var(--on-accent); }
.btn--primary:hover:not(:disabled)   { background: var(--accent-hover); }
/* secondary uses --field, so it auto-recesses inside cards */
.btn--secondary:hover:not(:disabled) { background: color-mix(in srgb, var(--field) 92%, var(--text)); }
.btn--ghost     { background: transparent; }
.btn--ghost:hover:not(:disabled)     { background: var(--hover-tint); }
.btn--sm   { padding: var(--space-1) var(--space-3); font-size: var(--text-sm); }
.btn--icon { padding: var(--space-2); border-radius: var(--radius-full); width: 2.25rem; height: 2.25rem; }
/* Icon buttons hold a glyph, not text — size the SVG here so a bare viewBox-only
   icon (no width/height attrs) renders at all, the way .nav-item/.post__action do. */
.btn--icon svg { width: 1.15rem; height: 1.15rem; }

/* Cards */
.card {
  background: var(--surface); border-radius: var(--radius-3);
  padding: var(--space-5); box-shadow: var(--shadow-1);
  transition: box-shadow var(--transition), transform var(--transition);
}
.card--hover:hover { box-shadow: var(--shadow-3); transform: translateY(-3px); }
.card__title { font-weight: var(--weight-semibold); margin-bottom: var(--space-3); }

/* Form controls — one shared look, all on --field, no borders. */
.field { display: flex; flex-direction: column; gap: var(--space-2); }
.label { font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--text); }
.input, .textarea, .select {
  width: 100%; padding: var(--space-2) var(--space-3);
  font-family: inherit; font-size: var(--text-base); line-height: 1.5;
  color: var(--text); background: var(--field);
  border: none; border-radius: var(--radius-2);
  transition: box-shadow var(--transition);
}
.input:focus, .textarea:focus, .select:focus {
  outline: none; box-shadow: 0 0 0 2px var(--accent), 0 0 0 5px var(--accent-soft);
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); }
/* Square off the resizer corner only: a rounded corner clips the native
   ::-webkit-resizer hit-zone. Flattening this one corner gives the grip a real
   square to live in; the other three keep --radius-2. */
.textarea { resize: vertical; min-height: 5rem; border-bottom-right-radius: 0; }

/* On a card, the recessed field gets a soft inset "well" (light only — the token
   is `none` in dark, where fields elevate instead). Focus still wins with the
   accent ring (higher specificity than the resting rule). */
.card .input, .card .textarea, .card .select, .card .select-trigger { box-shadow: var(--field-inset); }
.card :is(.input, .textarea, .select):focus {
  box-shadow: 0 0 0 2px var(--accent), 0 0 0 5px var(--accent-soft);
}

/* Native select ignores our padding (menulist appearance) and renders taller.
   Strip it, match the inputs exactly, and draw our own chevron. */
.select {
  appearance: none; -webkit-appearance: none; -moz-appearance: none;
  padding-right: var(--space-7); cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='1.9' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4.5 8.75 12 15l7.5-6.25'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-3) center;
}
.hint { font-size: var(--text-sm); color: var(--text-muted); }

/* Invalid state — keyed off the standard aria-invalid attribute, so the field
   marks ITSELF invalid (for screen readers) and the look follows for free; no
   extra class to keep in sync. A danger inset ring replaces the resting fill;
   focus keeps the ring and adds the soft halo. Uses the FIXED --danger token —
   an error is sentiment, never the brand accent. Placed after the .card rules
   above so it wins on a card too (equal specificity, later in source). */
.input[aria-invalid="true"], .textarea[aria-invalid="true"],
.select[aria-invalid="true"], .select-trigger[aria-invalid="true"] {
  box-shadow: inset 0 0 0 1.5px var(--danger);
}
.input[aria-invalid="true"]:focus, .textarea[aria-invalid="true"]:focus,
.select[aria-invalid="true"]:focus, .select-trigger[aria-invalid="true"]:focus {
  box-shadow: inset 0 0 0 1.5px var(--danger), 0 0 0 3px var(--danger-soft);
}
/* Inline error message — the danger-toned partner to .hint. */
.field__error {
  display: flex; align-items: center; gap: var(--space-1);
  font-size: var(--text-sm); font-weight: var(--weight-medium); color: var(--danger);
}

/* Custom select (styled listbox) — trigger looks like an .input */
.select-menu { position: relative; }
.select-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-2);
  text-align: left; cursor: pointer;
}
.select-trigger.is-placeholder > span:first-child { color: var(--text-muted); }
.select-trigger__chevron { display: inline-flex; color: var(--text-muted); transition: transform var(--transition); }
.dropdown__menu--full { width: 100%; min-width: 0; max-height: 14rem; overflow-y: auto; }
.dropdown__item--active { color: var(--accent-text); font-weight: var(--weight-medium); }

/* Checkbox / radio — custom-drawn (not native accent-color) so the check/dot
   use --on-accent, matching button-text contrast: white on indigo, black on
   amber. The real <input> is visually hidden but still focusable; the adjacent
   .check__mark span is the indicator. Unchecked sits on neutral --control. */
.check { display: inline-flex; align-items: center; gap: var(--space-2); cursor: pointer; }
.check input { position: absolute; opacity: 0; width: 0; height: 0; }
.check__mark {
  position: relative; overflow: hidden;
  flex: none; width: 1.15rem; height: 1.15rem; background: var(--control);
  display: grid; place-items: center;
  transition: box-shadow var(--transition);
}
.check__mark--box   { border-radius: var(--radius-1); }
.check__mark--radio { border-radius: var(--radius-full); }
/* Radio fills instantly (the dot animates); the checkbox fill wipes (below). */
.check input:checked + .check__mark--radio { background: var(--accent); }
.check input:focus-visible + .check__mark  { box-shadow: 0 0 0 3px var(--accent-soft); }

/* Checkbox fill: an accent layer revealed with clip-path (crisp, no sub-pixel
   sliver that transform: scaleX leaves behind). Unchecked it's clipped from the
   right; on check the right clip recedes (fill grows left→right); on uncheck the
   right clip closes back in, so the fill drains right→left — the exact reverse. */
.check__mark--box::before {
  content: ""; position: absolute; inset: 0; z-index: 0;
  background: var(--accent);
  clip-path: inset(0 100% 0 0);
  transition: clip-path var(--transition);
}
.check input:checked + .check__mark--box::before { clip-path: inset(0 0 0 0); }

/* Checkmark glyph — a rotated border inked with --on-accent, above the fill.
   Appears just after the fill lands; on uncheck it clears immediately. */
.check__mark--box::after {
  content: ""; position: relative; z-index: 1;
  width: 0.3rem; height: 0.58rem;
  border: solid var(--on-accent); border-width: 0 0.14rem 0.14rem 0;
  transform: rotate(45deg) translateY(-1px);
  opacity: 0; transition: opacity 90ms;
}
.check input:checked + .check__mark--box::after { opacity: 1; transition: opacity var(--transition) 130ms; }

/* Radio dot — also --on-accent, scaled in when checked. */
.check__mark--radio::after {
  content: ""; width: 0.5rem; height: 0.5rem; border-radius: var(--radius-full);
  background: var(--on-accent); transform: scale(0); transition: transform var(--transition);
}
.check input:checked + .check__mark--radio::after { transform: scale(1); }

/* Toggle switch (generic) */
.switch { position: relative; display: inline-block; width: 3.25rem; height: 1.5rem; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch__track {
  position: absolute; inset: 0; cursor: pointer;
  background: var(--control); border-radius: var(--radius-full);
  /* Recessed well — a soft inset shadow reads as depth on any background
     (unlike neumorphism's outer light halo, which needs a mid-tone surface). */
  box-shadow: inset 0 1.5px 2.5px rgba(0,0,0,0.22);
}
/* Accent fill: a full-track layer that crossfades in/out under the same --transition
   as the thumb slide, so the colour change reads as synced with the knob without a
   directional edge to race ahead, lurk under the thumb, or collapse into a sliver on
   the way out. A directional wipe can't both reach the rounded end-caps AND stay
   pinned to the floating thumb (it stops 0.2rem short of each cap), so we fade the
   whole fill instead. Off = invisible (no stray accent anywhere); z-index 0 keeps it
   under the thumb. */
.switch__track::after {
  content: ""; position: absolute; inset: 0; z-index: 0;
  background: var(--accent); border-radius: inherit;
  /* Keep the recessed well visible once the accent fills the track. */
  box-shadow: inset 0 1.5px 2.5px rgba(0,0,0,0.25);
  opacity: 0;
  transition: opacity var(--transition-slow);
}
.switch input:checked + .switch__track::after { opacity: 1; }
.switch__track::before {
  content: ""; position: absolute; z-index: 1; height: 1.1rem; width: 1.1rem; left: 0.2rem; bottom: 0.2rem;
  background: #fff; border-radius: var(--radius-full);
  /* Raised, domed knob: a drop shadow lifts it off the well; the inset top
     highlight rounds it. Pairs with the track's inset shadow for the 3D read. */
  box-shadow: 0 2px 3px rgba(0,0,0,0.3), inset 0 1px 0.5px rgba(255,255,255,0.7);
  transition: transform var(--transition-slow), background var(--transition-slow);
}
/* Flip the knob to readable ink on the accent (white on indigo, black on amber)
   — same --on-accent logic as button text. Only when checked (track = accent);
   unchecked it sits on gray --control and stays white. */
.switch input:checked + .switch__track::before { transform: translateX(1.75rem); background: var(--on-accent); }

/* Theme switch variant: a real thumb carrying sun/moon icons */
.switch--theme .switch__track::before { display: none; }
.switch__thumb {
  position: absolute; z-index: 1; top: 0.2rem; left: 0.2rem; width: 1.1rem; height: 1.1rem;
  background: #fff; border-radius: var(--radius-full);
  display: grid; place-items: center; color: var(--text-muted);
  /* Same domed knob as the generic switch (drop shadow + top highlight). */
  box-shadow: 0 2px 3px rgba(0,0,0,0.3), inset 0 1px 0.5px rgba(255,255,255,0.7);
  transition: left var(--transition-slow);
}
.switch input:checked + .switch__track .switch__thumb { left: calc(100% - 1.1rem - 0.2rem); }
.switch__thumb svg { grid-area: 1 / 1; width: 0.75rem; height: 0.75rem; }
.switch__thumb .moon { display: none; }
.switch input:checked + .switch__track .switch__thumb .sun  { display: none; }
.switch input:checked + .switch__track .switch__thumb .moon { display: block; }
/* Dark mode: invert the handle — dark knob, light moon (vs light knob, dark sun). */
[data-theme="dark"] .switch--theme .switch__thumb { background: var(--surface-2); color: var(--text); }

/* Accent picker — circular swatches; active one gets a ring in its own color. */
.swatches { display: inline-flex; align-items: center; gap: var(--space-2); }
.swatch {
  width: 1.35rem; height: 1.35rem; padding: 0; border: none; border-radius: var(--radius-full);
  background: var(--swatch); cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
}
.swatch:hover { transform: scale(1.12); }
.swatch:focus-visible { outline: none; }
.swatch--active { box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--swatch); }

/* Range — style the track explicitly so it's visible in dark mode too
   (accent-color leaves the empty track at the UA default ≈ invisible on black). */
.range {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 1.25rem; background: transparent; cursor: pointer;
}
.range::-webkit-slider-runnable-track { height: 0.5rem; border-radius: var(--radius-full); background: var(--control); }
.range::-moz-range-track          { height: 0.5rem; border-radius: var(--radius-full); background: var(--control); }
/* Pill handle — wider than tall (elongated along the track) with fully rounded ends
   (--radius-full = a capsule: straight sides, semicircle caps). margin-top centers it
   on the track: (track − thumb)/2 = (0.375 − 0.85)/2 = -0.2375rem. */
.range::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none; margin-top: -0.2375rem;
  width: 1.5rem; height: 0.85rem; border: none; border-radius: var(--radius-full);
  background: var(--accent); box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.range::-moz-range-thumb {
  width: 1.5rem; height: 0.85rem; border: none; border-radius: var(--radius-full);
  background: var(--accent); box-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.range:focus-visible { outline: none; }
.range:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--accent-soft); }
.range:focus-visible::-moz-range-thumb     { box-shadow: 0 0 0 4px var(--accent-soft); }
/* Grab feedback: press the handle 1px into the track — same gesture as .btn:active.
   translateY (not a height change) keeps the margin-top centering above intact. */
.range:active::-webkit-slider-thumb { transform: translateY(1px); }
.range:active::-moz-range-thumb     { transform: translateY(1px); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: var(--space-1);
  padding: 0.15rem var(--space-3); font-size: 0.8125rem; font-weight: var(--weight-medium);
  line-height: 1.4; border-radius: var(--radius-full);
  background: var(--field); color: var(--text-muted);
}
.badge--accent { background: var(--accent-soft); color: var(--accent-text); }
/* Semantic badges — fixed colors, never follow the accent. */
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger); }

/* Alerts (neutral surface; accent variant for emphasis) */
.alert {
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); font-size: var(--text-sm); font-weight: var(--weight-medium);
  border-radius: var(--radius-2); background: var(--field); color: var(--text);
}
.alert--accent { background: var(--accent-soft); color: var(--accent-text); }
.alert--success { background: var(--success-soft); color: var(--success); }
.alert--warning { background: var(--warning-soft); color: var(--warning); }
.alert--danger  { background: var(--danger-soft);  color: var(--danger); }
/* Mono accent: --accent-soft is a translucent tint (→ gray), so for the
   black/white accent fill the box solidly instead. Flagged by data-mono on <html>. */
[data-mono] .alert--accent { background: var(--accent); color: var(--on-accent); }
[data-mono] .badge--accent { background: var(--accent); color: var(--on-accent); }
.alert__icon { font-weight: var(--weight-bold); }

/* Spinner — a pure-CSS loading ring. It sizes to the current font (1.1em) and
   inks with currentColor, so it adopts its context with no variants: white inside
   a primary button, --text inline, the toast/alert tone where it sits. */
.spinner {
  /* Accent by default; overridable so it stays visible on accent-filled surfaces
     (e.g. a primary button sets it to --on-accent below). */
  --c: var(--spinner-color, var(--accent));
  display: inline-block; width: 1em; height: 1em; vertical-align: -0.125em;
  border-radius: var(--radius-full);
  /* A conic sweep gives the comet: bright head at the top (the 0°/360° seam),
     fading back to transparent at 25% — since the spin is clockwise, the fade trails
     BEHIND the head (counter-clockwise) and the ~90° transparent gap leads. A radial
     mask punches out the centre so only a 2px ring remains. (CSS gradients interpolate
     premultiplied, so the fade drops alpha without muddying the hue.) */
  background: conic-gradient(from 0deg, transparent 25%, var(--c));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 2px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 2px));
  animation: spin 0.9s linear infinite;
  /* Promote to its own layer so the rotation is interpolated smoothly rather than
     re-rasterised onto the pixel grid each frame — what makes a spinner wobble. */
  will-change: transform; transform: translateZ(0);
}
/* Keep the translateZ in the keyframe so the spin doesn't drop the layer hint. */
@keyframes spin { to { transform: translateZ(0) rotate(360deg); } }

/* htmx request feedback: anything tagged .htmx-indicator stays hidden until a
   request is in flight, then fades in — htmx toggles .htmx-request on the element
   making the request (or on its hx-indicator target). The kit states this contract
   explicitly so a vendored copy shows spinners without relying on htmx's own
   injected default stylesheet. The element still occupies layout (opacity, not
   display) so the button doesn't reflow when its spinner appears. */
.htmx-indicator { opacity: 0; transition: opacity var(--transition); }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { opacity: 1; }

/* Skeleton — a loading-state shimmer. Split into PAINT and GEOMETRY on purpose, which
   is what lets a skeleton be exactly the size of the thing it stands in for:

     • PAINT (`.skeleton` / `.is-loading`) is the animated fill ONLY — a neutral
       --control base (same backing as toggle tracks) with a --hover-tint band sweeping
       across. Both tokens are derived from --text, so the shimmer auto-inverts in dark
       mode with no extra rules. It sets NO width/height of its own.
     • GEOMETRY comes from context: put `.is-loading` on a real component and it keeps
       that component's own box (padding, font-size, radius, min-size), so the
       button/avatar/card skeleton is pixel-identical to its loaded self. For free-
       standing placeholders, `.skeleton-line` sizes to the surrounding font; a bare
       `.skeleton` you size yourself.

   Override --skeleton-base to re-tint on an already-tinted surface. */
.skeleton, .is-loading {
  --skeleton-base: var(--control);
  /* The travelling glint. A translucent white lightens the grey base in BOTH themes
     (a darker tint would vanish on the dark base), so the sweep always reads. Override
     --skeleton-glint to tune it. */
  --skeleton-glint: color-mix(in srgb, #fff 42%, transparent);
  background:
    linear-gradient(90deg, transparent, var(--skeleton-glint) 50%, transparent) 0 0 / 200% 100% no-repeat,
    var(--skeleton-base);
  animation: skeleton-sweep 1.5s linear infinite;
}
/* The band enters off the left edge and travels fully across to off the right, so it
   actually crosses the element (transparent ends keep the loop seam invisible). */
@keyframes skeleton-sweep { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* A standalone skeleton block takes the default component radius. */
.skeleton { display: inline-block; border-radius: var(--radius-1); }
/* A text-line bar: inline-block, so it lives INSIDE a line of text and the surrounding
   line-height provides its vertical slot — the bar itself is thinner (0.7em) and
   centered, but the space it occupies is exactly one real text line. That's what makes
   a loaded line and its skeleton the same height: drop it in a heading, a `.muted`
   line, anything, and the slot tracks that text. Width is yours to set. */
.skeleton-line { height: 0.7em; vertical-align: middle; border-radius: var(--radius-full); }

/* `.is-loading` turns a REAL component into its own skeleton: keep the box, drop the
   ink + interactivity. It deliberately sets NO border-radius, so the element keeps its
   own (pill button, round avatar). Children stay in the layout (the box doesn't
   reflow) but go invisible, leaving just the shimmer. */
.is-loading { color: transparent !important; cursor: default; pointer-events: none; user-select: none; }
.is-loading > * { visibility: hidden; }

@media (prefers-reduced-motion: reduce) { .skeleton, .is-loading { animation: none; } }

/* Toasts — transient feedback: the SERVER-state partner to the static inline
   .alert. The region is a fixed, click-through stack mounted once per page; an
   htmx handler appends a toast into it out-of-band (see `toast_oob`), and Alpine
   auto-dismisses each after a few seconds. Tones map the same fixed semantics as
   .alert/.badge — they never track the accent. */
.toast-region {
  position: fixed; bottom: var(--space-5); right: var(--space-5); z-index: 60;
  display: flex; flex-direction: column; gap: var(--space-3);
  width: min(22rem, calc(100vw - 2 * var(--space-5)));
  pointer-events: none;  /* the region ignores the cursor; each toast re-enables it */
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: var(--space-3);
  padding: var(--space-3) var(--space-4); border-radius: var(--radius-2);
  background: var(--surface); color: var(--text); box-shadow: var(--shadow-3);
  font-size: var(--text-sm); font-weight: var(--weight-medium);
  animation: toast-in 240ms cubic-bezier(0.2, 0.9, 0.3, 1.25);
}
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
/* A toast FLOATS over arbitrary page content, so its tint must be OPAQUE (unlike
   .alert/.badge, which sit on a solid surface and can use the translucent --*-soft
   tokens). Composite the same tone percentages OVER --surface instead of over
   transparent — same hue, now solid in both themes. */
.toast--accent  { background: color-mix(in srgb, var(--accent)  12%, var(--surface)); color: var(--accent-text); }
.toast--success { background: color-mix(in srgb, var(--success) 12%, var(--surface)); color: var(--success); }
.toast--warning { background: color-mix(in srgb, var(--warning) 14%, var(--surface)); color: var(--warning); }
.toast--danger  { background: color-mix(in srgb, var(--danger)  12%, var(--surface)); color: var(--danger); }
[data-mono] .toast--accent { background: var(--accent); color: var(--on-accent); }
.toast__icon { font-weight: var(--weight-bold); }
.toast__body { flex: 1; min-width: 0; }
/* Dismiss affordance — a ghosted ✕ that inherits the toast's ink. */
.toast__close {
  flex: none; border: none; background: transparent; color: inherit; cursor: pointer;
  font: inherit; font-size: var(--text-lg); line-height: 1; padding: 0; opacity: 0.55;
  transition: opacity var(--transition);
}
.toast__close:hover { opacity: 1; }
/* Exit animation (Alpine drives the leave; entrance is the CSS keyframe above). */
.toast-leave      { transition: opacity 200ms ease, transform 200ms ease; }
.toast-leave-from { opacity: 1; }
.toast-leave-to   { opacity: 0; transform: translateX(12px); }

/* Dropdown */
.dropdown { position: relative; display: inline-block; }
.dropdown__menu {
  position: absolute; top: calc(100% + var(--space-2)); left: 0; min-width: 12rem; z-index: 20;
  background: var(--surface); border-radius: var(--radius-2);
  box-shadow: var(--shadow-3); padding: var(--space-1); list-style: none; margin: 0;
}
.dropdown__item {
  display: block; width: 100%; text-align: left; padding: var(--space-2) var(--space-3);
  border: none; background: transparent; color: var(--text); font: inherit; cursor: pointer;
  border-radius: var(--radius-1);
}
.dropdown__item:hover { background: var(--hover-tint); }

/* Modal */
.modal__backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 40;
  display: flex; align-items: center; justify-content: center; padding: var(--space-4);
}
.modal__panel {
  background: var(--surface); border-radius: var(--radius-3); box-shadow: var(--shadow-3);
  padding: var(--space-6); max-width: 28rem; width: 100%;
}
/* Animate OPEN only (no leave hooks → instant close). Backdrop fades; the panel
   pops with a slight overshoot for snap. */
.modal-fade      { transition: opacity 150ms ease; }
.modal-fade-from { opacity: 0; }
.modal-fade-to   { opacity: 1; }
.modal-pop       { transition: opacity 180ms ease, transform 180ms cubic-bezier(0.2, 0.9, 0.3, 1.25); }
.modal-pop-from  { opacity: 0; transform: scale(0.94); }
.modal-pop-to    { opacity: 1; transform: scale(1); }

/* Tabs — all tabs share a continuous baseline; an accent underline slides to
   the active one (positioned by Alpine from the active tab's box). */
.tabs { display: flex; gap: var(--space-1); position: relative; border-bottom: 2px solid var(--control); }
.tab {
  padding: var(--space-2) var(--space-4); border: none; background: transparent; cursor: pointer;
  font: inherit; font-weight: var(--weight-medium); color: var(--text-muted);
  transition: color var(--transition);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--accent-text); }
.tab__indicator {
  position: absolute; bottom: -2px; left: 0; height: 2px; width: 0;
  background: var(--accent-text); border-radius: var(--radius-full);
  transition: left var(--transition), width var(--transition);
}

/* Table — a data table is the one place whitespace alone fails for scanning, so
   it earns the kit's sanctioned hairline (the same faded --rule the divider uses,
   NOT a boxy border): a subtle --rule between body rows for vertical tracking, a
   stronger --rule-strong anchoring the header. No zebra. A hover row tint stays
   on top. Numeric columns (.table__num) right-align with tabular figures so digits
   line up. Rows get rounded ends on hover via the first/last td. .table-wrap scrolls
   horizontally when the columns' min-content exceeds the container (narrow
   viewports) — tables don't shrink below content, so without this the table bleeds
   past its card. data_table() emits the wrapper. */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.table th { text-align: left; padding: var(--space-2) var(--space-3); color: var(--text-muted); font-weight: var(--weight-medium);
            border-bottom: 1px solid var(--rule-strong); }
.table td { padding: var(--space-3); }
/* Faded hairline between body rows (not after the last) — the scannability win. */
.table tbody tr:not(:last-child) td { border-bottom: 1px solid var(--rule); }
.table tbody tr:hover td { background: var(--hover-tint); }
.table td:first-child { border-radius: var(--radius-1) 0 0 var(--radius-1); }
.table td:last-child  { border-radius: 0 var(--radius-1) var(--radius-1) 0; }
.table__num { text-align: right; font-variant-numeric: tabular-nums; }

/* Date picker — a calendar popover. The trigger reuses .input/.select-trigger
   (same look as the custom select); the panel reuses the floating-surface tokens
   (--surface + --shadow-3) shared by the dropdown/modal/hovercard. The selected
   day is an accent chip inked with --on-accent — the same button-text contrast
   logic (white on indigo, black on amber). Calendar math lives in Alpine's
   datepicker() factory; this only paints the grid. */
.datepicker { position: relative; }
.datepicker__panel {
  position: absolute; top: calc(100% + var(--space-2)); left: 0; z-index: 30;
  width: max-content; background: var(--surface); border-radius: var(--radius-2);
  box-shadow: var(--shadow-3); padding: var(--space-3);
}
.datepicker__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-2); }
.datepicker__label { font-weight: var(--weight-semibold); font-size: var(--text-sm); }
/* Compact icon nav buttons (the kit .btn--icon is sized for touch; the calendar
   wants tighter month arrows). */
.datepicker__nav { width: 1.9rem; height: 1.9rem; }
.datepicker__nav svg { width: 16px; height: 16px; }
.datepicker__grid { display: grid; grid-template-columns: repeat(7, 2rem); gap: 2px; }
.datepicker__dow { margin-bottom: var(--space-1); }
.datepicker__dowcell { display: grid; place-items: center; height: 1.4rem; font-size: 0.7rem; font-weight: var(--weight-medium); color: var(--text-muted); }
.datepicker__day {
  height: 2rem; width: 2rem; padding: 0; border: none; border-radius: var(--radius-1);
  background: transparent; color: var(--text); font: inherit; font-size: var(--text-sm);
  cursor: pointer; transition: background var(--transition);
}
.datepicker__day:hover:not(:disabled) { background: var(--hover-tint); }
.datepicker__day:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--accent-soft); }
.datepicker__day--blank { visibility: hidden; cursor: default; }
/* Today: an accent ring (an outline, not a fill) so it reads even when unselected. */
.datepicker__day--today { box-shadow: inset 0 0 0 1.5px var(--accent); color: var(--accent-text); font-weight: var(--weight-semibold); }
/* Selected: the accent chip wins over the today ring. */
.datepicker__day--sel, .datepicker__day--sel:hover { background: var(--accent); color: var(--on-accent); box-shadow: none; font-weight: var(--weight-semibold); }

/* Alpine cloak */
[x-cloak] { display: none !important; }

/* Page shells — width wrappers for app-like pages. */
/* Wide shell for app-like pages (the showcase keeps its narrow .container) */
.shell { max-width: 1180px; margin: 0 auto; padding: var(--space-6) var(--space-5); }
.shell--narrow { max-width: 740px; }

/* Card header row (pairs with .card / .card__title). */
.card__head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.card__head .card__title { margin: 0; }
.card__head a { text-decoration: none; }

/* Avatar — a circular initial/icon chip. */
.avatar {
  flex: none; width: 2rem; height: 2rem; border-radius: var(--radius-full);
  display: grid; place-items: center; font-size: var(--text-xs); font-weight: var(--weight-semibold);
  background: var(--accent-soft); color: var(--accent-text);
}
[data-mono] .avatar { background: var(--accent); color: var(--on-accent); }
.avatar--lg { width: 2.5rem; height: 2.5rem; font-size: 0.85rem; }
/* The feed avatar doubles as a hovercard trigger — strip button chrome, hint it. */
.avatar--trigger { border: none; cursor: pointer; padding: 0; transition: box-shadow var(--transition); }
.avatar--trigger:hover { box-shadow: 0 0 0 3px var(--accent-soft); }
.avatar--trigger:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.avatar--sm { width: 1.5rem; height: 1.5rem; font-size: 0.7rem; }

/* Hovercard — a pointer-triggered popover. The wrapper is the hover zone; the
   panel is an absolutely-positioned child (so it stays inside that zone) with a
   transparent top bridge spanning the gap to the trigger. The surface reuses the
   same tokens as the modal/dropdown's floating panels: --surface + --shadow-3. */
.hovercard { position: relative; display: inline-flex; }
.hovercard__panel {
  position: absolute; top: 100%; left: 0; z-index: 50;
  padding-top: var(--space-2);          /* transparent bridge — keeps hover alive */
  width: max-content; max-width: 16rem;
  /* Capture the contextual on-card fill before the surface re-points --field for
     its own children. --field elevates off the card (a lighter grey in dark mode),
     so the popover reads as a raised plane rather than a same-colour blur. */
  --pop-surface: var(--field);
}
.hovercard__surface {
  display: flex; flex-direction: column; gap: var(--space-3);
  background: var(--pop-surface); border-radius: var(--radius-3);
  box-shadow: var(--shadow-3); padding: var(--space-4);
  /* Re-base fills for the popover's own children (e.g. the secondary button),
     same trick as `.card { --field: var(--bg) }` — so they contrast with the
     popover surface instead of melting into it. */
  --field: var(--surface);
}
.hovercard__head { display: flex; align-items: center; gap: var(--space-3); }
.hovercard__head .feed__body { flex: 1; min-width: 0; }
.hovercard__stats { display: flex; gap: var(--space-5); }
.hovercard__stats > div { display: flex; flex-direction: column; line-height: 1.2; }
.hovercard__stat-val { font-weight: var(--weight-semibold); font-size: var(--text-lg); }
.hovercard__stat-key { font-size: var(--text-xs); color: var(--text-muted); }

/* Tooltip — a lightweight text label, the pure-CSS partner to the rich (Alpine)
   hovercard: for naming icon-only affordances (.btn--icon) and the like. No JS
   driver — :hover + :focus-within do the work. The trigger carries its own
   accessible name (e.g. aria-label); the bubble is aria-hidden, so it's purely
   visual reinforcement for sighted pointer/keyboard users — no id-wiring to keep
   in sync. Inverted surface (--text fill / --bg ink) reads unmistakably as a
   tooltip and auto-flips per theme, the one place the kit inverts on purpose. */
.tooltip { position: relative; display: inline-flex; }
.tooltip__bubble {
  position: absolute; left: 50%; bottom: 100%; z-index: 60;
  margin-bottom: var(--space-2);          /* gap to the trigger (the caret spans it) */
  transform: translate(-50%, 4px);        /* settles up into place on show */
  width: max-content; max-width: 16rem;
  padding: var(--space-1) var(--space-2);
  background: var(--text); color: var(--bg);
  border-radius: var(--radius-1); box-shadow: var(--shadow-3);
  font-size: var(--text-xs); font-weight: var(--weight-medium); line-height: 1.3;
  opacity: 0; pointer-events: none;
  transition: opacity var(--transition), transform var(--transition);
}
/* Caret — a square rotated 45°, same fill as the bubble, straddling its bottom
   edge so it points down at the trigger. */
.tooltip__bubble::after {
  content: ""; position: absolute; top: 100%; left: 50%;
  width: 0.5rem; height: 0.5rem; margin: -0.25rem 0 0 -0.25rem;
  background: var(--text); transform: rotate(45deg);
}
/* Show on pointer hover OR keyboard focus within the wrapper. A short enter delay
   keeps the bubble from flashing on transient pass-throughs; it hides instantly. */
.tooltip:hover .tooltip__bubble,
.tooltip:focus-within .tooltip__bubble {
  opacity: 1; transform: translate(-50%, 0); transition-delay: 350ms;
}
/* Below placement — flip under the trigger (e.g. icons in the top nav), caret up. */
.tooltip--bottom .tooltip__bubble {
  bottom: auto; top: 100%; margin: var(--space-2) 0 0; transform: translate(-50%, -4px);
}
.tooltip--bottom .tooltip__bubble::after { top: auto; bottom: 100%; margin: 0 0 -0.25rem -0.25rem; }
.tooltip--bottom:hover .tooltip__bubble,
.tooltip--bottom:focus-within .tooltip__bubble { transform: translate(-50%, 0); }
