/* =====================================================================================
   Imagegen component library. Use ONLY these classes and the tokens in tokens.css.
   Load order: tokens.css, base.css, components.css, then a page stylesheet.

   BUTTONS
   .btn                      Button (default look = secondary). Works on <button> and <a>.
     .primary                Terracotta fill, one per view.   .secondary  Outlined (explicit).
     .ghost                  No border until hover.            .danger     Destructive (red fill).
     .danger.ghost / .danger.secondary   Quieter destructive.
     .sm / .lg               Sizes (default 40 px; .sm 32 px, desktop only; touch devices keep 44 px).
     .icon-only              Square button holding just an icon (give it aria-label).
     .block                  Full width.
     .loading                Shows a spinner, ignores clicks. Also set disabled or aria-busy.
   .btn-group                Row of joined buttons.

   FORM CONTROLS
   .input                    Text/number/password/date input.  [aria-invalid="true"] = error ring. .sm
   .textarea                 Multi-line input (resizes vertically).
   .select                   Wrap-free styled <select>.
   .check                    <label class="check"><input type="checkbox|radio"><span class="check-box"></span><span class="check-text">Label</span></label>
   .switch                   <label class="switch"><input type="checkbox"><span class="switch-track"></span><span class="switch-text">Label</span></label>
   .range                    <input type="range" class="range"> (style the value readout yourself with .mono)
   .range-row                Slider + readout on one line: <div class="range-row"><input class="range"><output class="range-value">4.0</output></div>
   .input-group              Input with a button/addon attached: <div class="input-group"><input class="input"><button class="btn">…</button></div>
   .field                    Form row. Children: .field-label, .field-control, .field-hint, .field-error (role=alert)
     .inline                 Label left, control right (collapses on phones).
     .required               On .field-label: adds a quiet asterisk.
   .field-row                Responsive grid holding several .field side by side (.cols-2, .cols-3).
   .form                     Vertical stack of fields with standard spacing.
   .form-actions             Right-aligned button row at the bottom of a form.
   .form-error               Inline form-level error text (aria-live="polite").

   NAVIGATION
   .tabs                     role=tablist row with a hairline under it. Children .tab (aria-selected="true" = active). Scrolls sideways on phones.
   .segmented                Joined toggle group. Children: button.seg (aria-pressed="true" = on) or .seg-label wrapping radio. .sm
   .pagination               Row for Prev/Next buttons and a count.

   DISPLAY
   .badge                    Small label. .neutral .accent .success .warning .danger .info. .outline  (.dot adds a status dot)
   .pill                     Larger rounded status chip with optional leading .dot (same colour modifiers as .badge).
   .dot                      6 px status dot; modifiers .success .warning .danger .info .accent .pulse
   .card                     Surface with hairline border. Modifiers: .flush (no padding) .interactive (hover/focus, use on a/button) .raised
     .card-head / .card-body / .card-foot   Optional sections with hairline separators.
   .panel                    Hairline-only section (no fill), for page areas.
   .alert                    Inline message box. .info .success .warning .danger. Children .alert-title.
   .kv                       Key/value list: <dl class="kv"><dt>Key</dt><dd>Value</dd></dl>
   .table-wrap               Horizontal scroll wrapper for tables.
   .table                    Data table. .compact for tighter rows. .responsive turns rows into stacked cards under 40rem (each <td data-label="Name">).
     .col-actions            Cell/column that right-aligns buttons.  .num  right-aligned numeric cell.
   .empty-state              Centred empty/error placeholder: .empty-icon, .empty-title, .empty-body, .empty-actions.
   .spinner                  Rotating ring. .sm .lg
   .skeleton                 Shimmering placeholder block. Add .line (text line) / .circle. Set width/height via JS style.
   .progress                 Bar track containing .progress-bar (set style.width in %). .indeterminate animates. .thin
   .avatar                   Round initial badge.
   .divider                  Hairline with optional centred text: <div class="divider"><span>or</span></div>
   .code-block               Monospace block with copy-friendly wrapping.
   .token-display            Large monospace box for a secret shown once.
   .icon                     Applied by icon(): 1.25em square, stroke 1.5, currentColor. .icon.lg 1.5em

   OVERLAYS (built by ui.js, listed so you can restyle nothing)
   .modal-backdrop > .modal[role=dialog] (.sm .lg .xl) > .modal-head(.modal-title, .modal-close) + .modal-body + .modal-foot
   .toasts (aria-live region) > .toast (.success .error .info) > .toast-msg + .toast-close
   .menu-wrap                position:relative wrapper for a trigger + .menu
   .menu                     Popover list (role=menu). Children .menu-item (button/a; .danger), .menu-sep, .menu-label. .align-end right-aligns.
   .tooltip-host             Optional: [data-tip="text"] shows a CSS tooltip on hover/focus (title="" also fine).

   SHELL (owned by app.js)
   .topbar .brand .brand-mark .nav .nav-link(.active) .topbar-right .account-btn .view .view-loading .view-error
   .compute-slot             Wrapper for the compute pill in the top bar.

   UTILITIES (base.css): .stack(.tight .loose) .row(.tight .between .end .nowrap .start) .spacer .grid(.cols-2/3/4 .auto)
   .container(.narrow) .page .page-head .section-title .eyebrow .lead .muted .text-2 .text-3 .text-accent .text-danger
   .text-success .mono .truncate .nowrap .sr-only .hairline .prose
   ===================================================================================== */

/* ---------- Icons ---------- */
.icon { width: 1.25em; height: 1.25em; flex: none; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; vertical-align: -0.2em; }
.icon.lg { width: 1.5em; height: 1.5em; }
.icon.xl { width: 2.25em; height: 2.25em; }

/* ---------- Buttons ---------- */
.btn {
  --btn-bg: var(--surface-2);
  --btn-bg-hover: var(--surface-3);
  --btn-fg: var(--text);
  --btn-border: var(--line-strong);
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
  min-height: var(--touch); min-width: var(--touch);
  padding: 0 var(--space-4);
  background: var(--btn-bg); color: var(--btn-fg);
  border: 1px solid var(--btn-border); border-radius: var(--radius);
  font-size: var(--text-base); font-weight: 500; line-height: 1; white-space: nowrap;
  text-decoration: none; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), transform var(--dur-fast) var(--ease);
}
.btn:hover { background: var(--btn-bg-hover); color: var(--btn-fg); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.btn.secondary { --btn-bg: transparent; --btn-bg-hover: var(--surface-2); }
.btn.primary { --btn-bg: var(--accent-strong); --btn-bg-hover: var(--accent-hover); --btn-fg: var(--text-on-accent); --btn-border: var(--accent-strong); font-weight: 600; }
.btn.primary:active { background: var(--accent-active); }
.btn.ghost { --btn-bg: transparent; --btn-bg-hover: var(--surface-2); --btn-border: transparent; --btn-fg: var(--text-2); }
.btn.ghost:hover { --btn-fg: var(--text); }
.btn.danger { --btn-bg: var(--danger-strong); --btn-bg-hover: var(--danger-hover); --btn-fg: #fff; --btn-border: var(--danger-strong); }
.btn.danger.ghost { --btn-bg: transparent; --btn-bg-hover: var(--danger-soft); --btn-fg: var(--danger); --btn-border: transparent; }
.btn.danger.secondary { --btn-bg: transparent; --btn-bg-hover: var(--danger-soft); --btn-fg: var(--danger); --btn-border: var(--danger-strong); }
.btn.lg { min-height: var(--control-h-lg); padding: 0 var(--space-5); font-size: var(--text-md); }
.btn.sm { min-height: var(--touch); padding: 0 var(--space-3); font-size: var(--text-sm); }
@media (hover: hover) and (pointer: fine) { .btn.sm { min-height: var(--control-h-sm); min-width: var(--control-h-sm); } }
.btn.icon-only { padding: 0; width: var(--touch); }
@media (hover: hover) and (pointer: fine) { .btn.icon-only.sm { width: var(--control-h-sm); } }
.btn.block { display: flex; width: 100%; }
.btn.loading { color: transparent !important; pointer-events: none; }
.btn.loading > * { visibility: hidden; }
.btn.loading::after { content: ""; position: absolute; width: 1.1em; height: 1.1em; border: 2px solid var(--text-on-accent); border-right-color: transparent; border-radius: 50%; animation: ig-spin 0.7s linear infinite; }
.btn.secondary.loading::after, .btn.ghost.loading::after, .btn:not(.primary):not(.danger).loading::after { border-color: var(--text); border-right-color: transparent; }
.btn-group { display: inline-flex; }
.btn-group > .btn { border-radius: 0; margin-left: -1px; }
.btn-group > .btn:first-child { border-radius: var(--radius) 0 0 var(--radius); margin-left: 0; }
.btn-group > .btn:last-child { border-radius: 0 var(--radius) var(--radius) 0; }

/* ---------- Inputs ---------- */
.input, .textarea, .select {
  display: block; width: 100%;
  min-height: var(--touch);
  padding: 0 var(--space-3);
  background: var(--bg-raised); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  font-size: var(--text-base); line-height: 1.4;
  transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}
.input.sm, .select.sm { min-height: var(--touch); font-size: var(--text-sm); }
@media (hover: hover) and (pointer: fine) { .input.sm, .select.sm { min-height: var(--control-h-sm); } .input, .select, .btn { min-height: var(--control-h); } .btn.lg { min-height: var(--control-h-lg); } }
.textarea { padding: var(--space-3); min-height: 6rem; resize: vertical; line-height: var(--leading-snug); }
.input::placeholder, .textarea::placeholder { color: var(--text-3); opacity: 1; }
.input:hover, .textarea:hover, .select:hover { border-color: var(--text-3); }
.input:focus, .textarea:focus, .select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.input:focus-visible, .textarea:focus-visible, .select:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.input[aria-invalid="true"], .textarea[aria-invalid="true"], .select[aria-invalid="true"] { border-color: var(--danger); }
.input:disabled, .textarea:disabled, .select:disabled { opacity: 0.5; background: var(--surface); }
.input[readonly] { color: var(--text-2); }
.input[type="number"] { font-variant-numeric: tabular-nums; }
.select {
  appearance: none; -webkit-appearance: none; padding-right: 2.25rem; cursor: pointer;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-2) 50%), linear-gradient(135deg, var(--text-2) 50%, transparent 50%);
  background-position: calc(100% - 1.15rem) 52%, calc(100% - 0.85rem) 52%;
  background-size: 0.3rem 0.3rem, 0.3rem 0.3rem; background-repeat: no-repeat;
}
.select option { background: var(--surface); color: var(--text); }
.input-group { display: flex; }
.input-group > .input { border-top-right-radius: 0; border-bottom-right-radius: 0; flex: 1 1 auto; min-width: 0; }
.input-group > .btn { border-top-left-radius: 0; border-bottom-left-radius: 0; margin-left: -1px; }

/* Checkbox and radio */
.check { display: inline-flex; align-items: flex-start; gap: var(--space-3); min-height: var(--touch); padding-block: var(--space-2); cursor: pointer; position: relative; }
.check > input { position: absolute; opacity: 0; width: 1.25rem; height: 1.25rem; margin: 0; top: 0.8rem; left: 0; }
.check-box { flex: none; width: 1.25rem; height: 1.25rem; margin-top: 0.1rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm); background: var(--bg-raised); display: grid; place-items: center; transition: background-color var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease); }
.check > input[type="radio"] + .check-box { border-radius: 50%; }
.check-box::after { content: ""; width: 0.65rem; height: 0.35rem; border-left: 2px solid var(--text-on-accent); border-bottom: 2px solid var(--text-on-accent); transform: translateY(-1px) rotate(-45deg); opacity: 0; }
.check > input[type="radio"] + .check-box::after { width: 0.5rem; height: 0.5rem; border: 0; border-radius: 50%; background: var(--text-on-accent); transform: none; }
.check:hover .check-box { border-color: var(--text-3); }
.check > input:checked + .check-box { background: var(--accent-strong); border-color: var(--accent-strong); }
.check > input:checked + .check-box::after { opacity: 1; }
.check > input:focus-visible + .check-box { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.check > input:disabled + .check-box, .check > input:disabled ~ .check-text { opacity: 0.45; }
.check-text { line-height: var(--leading-snug); padding-top: 0.05rem; }

/* Switch */
.switch { display: inline-flex; align-items: center; gap: var(--space-3); min-height: var(--touch); cursor: pointer; position: relative; }
.switch > input { position: absolute; opacity: 0; width: 2.5rem; height: 1.5rem; margin: 0; left: 0; }
.switch-track { flex: none; width: 2.5rem; height: 1.5rem; border-radius: var(--radius-pill); background: var(--surface-3); border: 1px solid var(--line-strong); position: relative; transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease); }
.switch-track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 1.1rem; height: 1.1rem; border-radius: 50%; background: var(--text-2); transition: transform var(--dur) var(--ease), background-color var(--dur) var(--ease); }
.switch > input:checked + .switch-track { background: var(--accent-strong); border-color: var(--accent-strong); }
.switch > input:checked + .switch-track::after { transform: translateX(1rem); background: #fff; }
.switch > input:focus-visible + .switch-track { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.switch > input:disabled + .switch-track, .switch > input:disabled ~ .switch-text { opacity: 0.45; }

/* Range */
.range { -webkit-appearance: none; appearance: none; width: 100%; height: var(--touch); background: transparent; margin: 0; cursor: pointer; }
.range::-webkit-slider-runnable-track { height: 3px; border-radius: 2px; background: var(--line-strong); }
.range::-moz-range-track { height: 3px; border-radius: 2px; background: var(--line-strong); }
.range::-moz-range-progress { height: 3px; border-radius: 2px; background: var(--accent); }
.range::-webkit-slider-thumb { -webkit-appearance: none; width: 1.1rem; height: 1.1rem; margin-top: calc(-0.55rem + 1.5px); border-radius: 50%; background: var(--text); border: 3px solid var(--accent-strong); transition: transform var(--dur-fast) var(--ease); }
.range::-moz-range-thumb { width: 0.8rem; height: 0.8rem; border-radius: 50%; background: var(--text); border: 3px solid var(--accent-strong); }
.range:hover::-webkit-slider-thumb { transform: scale(1.12); }
.range:focus-visible { outline: 2px solid var(--focus-ring); outline-offset: 0; }
.range:disabled { opacity: 0.45; }
.range-row { display: flex; align-items: center; gap: var(--space-3); }
.range-value { min-width: 3.2rem; text-align: right; font-family: var(--font-mono); font-size: var(--text-sm); color: var(--text-2); font-variant-numeric: tabular-nums; }

/* Field rows */
.field { display: flex; flex-direction: column; gap: var(--space-2); min-width: 0; }
.field-label { font-size: var(--text-sm); font-weight: 600; color: var(--text); line-height: var(--leading-snug); }
.field-label.required::after { content: " *"; color: var(--text-3); font-weight: 400; }
.field-control { min-width: 0; }
.field-hint { font-size: var(--text-sm); color: var(--text-3); line-height: var(--leading-snug); }
.field-error { font-size: var(--text-sm); color: var(--danger); line-height: var(--leading-snug); }
.field-error:empty { display: none; }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: var(--space-4); }
.field.inline .field-label { flex: 0 0 38%; }
.field.inline .field-control { flex: 1 1 auto; }
@media (max-width: 36rem) { .field.inline { flex-direction: column; align-items: stretch; gap: var(--space-2); } .field.inline .field-label { flex: none; } }
.field-row { display: grid; gap: var(--space-4); grid-template-columns: repeat(auto-fit, minmax(min(100%, 14rem), 1fr)); }
.field-row.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field-row.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
@media (max-width: 36rem) { .field-row.cols-2, .field-row.cols-3 { grid-template-columns: minmax(0, 1fr); } }
.form { display: flex; flex-direction: column; gap: var(--space-4); }
.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: var(--space-3); flex-wrap: wrap; padding-top: var(--space-2); }
.form-error { font-size: var(--text-sm); color: var(--danger); min-height: 1.2em; line-height: var(--leading-snug); }
.form-error:empty { display: none; }
fieldset.field { border: 0; padding: 0; margin: 0; }
fieldset.field > legend { padding: 0; margin-bottom: var(--space-2); }

/* ---------- Tabs, segmented ---------- */
.tabs { display: flex; gap: var(--space-1); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; position: relative; display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--touch); padding: 0 var(--space-4); background: transparent; border: 0; color: var(--text-2); font-weight: 500; font-size: var(--text-base); text-decoration: none; white-space: nowrap; transition: color var(--dur-fast) var(--ease); }
.tab:hover { color: var(--text); text-decoration: none; }
.tab[aria-selected="true"], .tab.active { color: var(--text); }
.tab[aria-selected="true"]::after, .tab.active::after { content: ""; position: absolute; left: var(--space-3); right: var(--space-3); bottom: -1px; height: 2px; background: var(--accent); }
.tab:focus-visible { outline-offset: -3px; }

.segmented { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--radius); background: var(--bg-raised); padding: 2px; gap: 2px; max-width: 100%; }
.seg, .seg-label { flex: 1 1 auto; display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2); min-height: calc(var(--touch) - 6px); padding: 0 var(--space-4); border: 0; background: transparent; color: var(--text-2); border-radius: calc(var(--radius) - 2px); font-weight: 500; font-size: var(--text-sm); cursor: pointer; position: relative; white-space: nowrap; transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); }
.seg:hover, .seg-label:hover { color: var(--text); }
.seg[aria-pressed="true"], .seg[aria-checked="true"], .seg.active, .seg-label:has(input:checked) { background: var(--surface-3); color: var(--text); box-shadow: inset 0 0 0 1px var(--line-strong); }
.seg-label > input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg-label:has(input:focus-visible) { outline: 2px solid var(--focus-ring); outline-offset: 1px; }
.segmented.sm .seg, .segmented.sm .seg-label { padding: 0 var(--space-3); }
@media (hover: hover) and (pointer: fine) { .segmented.sm .seg, .segmented.sm .seg-label { min-height: calc(var(--control-h-sm) - 4px); } }
.pagination { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); color: var(--text-2); font-size: var(--text-sm); }

/* ---------- Badges, pills, dots ---------- */
.badge { --b-fg: var(--text-2); --b-bg: var(--surface-2); --b-line: var(--line-strong); display: inline-flex; align-items: center; gap: var(--space-1); padding: 0.1rem 0.5rem; min-height: 1.35rem; font-size: var(--text-xs); font-weight: 600; letter-spacing: 0.02em; line-height: 1.3; color: var(--b-fg); background: var(--b-bg); border: 1px solid transparent; border-radius: var(--radius-sm); white-space: nowrap; }
.badge.outline { background: transparent; border-color: var(--b-line); }
.badge.accent, .pill.accent { --b-fg: var(--accent); --b-bg: var(--accent-soft); --b-line: var(--accent-line); }
.badge.success, .pill.success { --b-fg: var(--success); --b-bg: var(--success-soft); --b-line: var(--success); }
.badge.warning, .pill.warning { --b-fg: var(--warning); --b-bg: var(--warning-soft); --b-line: var(--warning); }
.badge.danger, .pill.danger { --b-fg: var(--danger); --b-bg: var(--danger-soft); --b-line: var(--danger); }
.badge.info, .pill.info { --b-fg: var(--info); --b-bg: var(--info-soft); --b-line: var(--info); }
.pill { --b-fg: var(--text-2); --b-bg: var(--surface-2); --b-line: var(--line-strong); display: inline-flex; align-items: center; gap: var(--space-2); min-height: 1.9rem; padding: 0 var(--space-3); font-size: var(--text-sm); font-weight: 500; color: var(--b-fg); background: var(--b-bg); border: 1px solid var(--b-line); border-radius: var(--radius-pill); white-space: nowrap; }
.dot { flex: none; width: 0.4rem; height: 0.4rem; border-radius: 50%; background: var(--text-3); display: inline-block; }
.dot.success { background: var(--success); } .dot.warning { background: var(--warning); } .dot.danger { background: var(--danger); } .dot.info { background: var(--info); } .dot.accent { background: var(--accent); }
.dot.pulse { animation: ig-pulse 1.6s ease-in-out infinite; }

/* ---------- Cards, panels, alerts ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: var(--space-5); min-width: 0; }
.card.flush { padding: 0; overflow: hidden; }
.card.raised { box-shadow: var(--shadow-2); background: var(--surface-2); }
.card.interactive { display: block; color: inherit; text-decoration: none; cursor: pointer; transition: border-color var(--dur-fast) var(--ease), background-color var(--dur-fast) var(--ease); }
.card.interactive:hover { border-color: var(--line-strong); background: var(--surface-2); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--line); }
.card-head h2, .card-head h3 { font-size: var(--text-lg); margin: 0; }
.card-body { padding: var(--space-5); }
.card-foot { padding: var(--space-3) var(--space-5); border-top: 1px solid var(--line); display: flex; gap: var(--space-3); justify-content: flex-end; align-items: center; }
.panel { border-top: 1px solid var(--line); padding-block: var(--space-5); }
.alert { --a-c: var(--info); --a-bg: var(--info-soft); display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-3) var(--space-4); border: 1px solid var(--a-c); border-left-width: 3px; border-radius: var(--radius); background: var(--a-bg); font-size: var(--text-sm); line-height: var(--leading-snug); color: var(--text); }
.alert > .icon { color: var(--a-c); margin-top: 0.05rem; }
.alert.success { --a-c: var(--success); --a-bg: var(--success-soft); }
.alert.warning { --a-c: var(--warning); --a-bg: var(--warning-soft); }
.alert.danger { --a-c: var(--danger); --a-bg: var(--danger-soft); }
.alert-title { font-weight: 600; display: block; }
.kv { display: grid; grid-template-columns: minmax(7rem, max-content) 1fr; gap: var(--space-2) var(--space-5); }
.kv dt { color: var(--text-3); font-size: var(--text-sm); }
.kv dd { margin: 0; min-width: 0; }
@media (max-width: 30rem) { .kv { grid-template-columns: 1fr; gap: 0; } .kv dd { margin-bottom: var(--space-3); } }
.avatar { width: 2rem; height: 2rem; border-radius: 50%; display: inline-grid; place-items: center; background: var(--surface-3); border: 1px solid var(--line-strong); color: var(--text); font-size: var(--text-sm); font-weight: 600; text-transform: uppercase; flex: none; }
.divider { display: flex; align-items: center; gap: var(--space-3); color: var(--text-3); font-size: var(--text-sm); }
.divider::before, .divider::after { content: ""; flex: 1; border-top: 1px solid var(--line); }
.code-block { font-family: var(--font-mono); font-size: var(--text-sm); background: var(--bg-raised); border: 1px solid var(--line); border-radius: var(--radius); padding: var(--space-3) var(--space-4); overflow: auto; white-space: pre-wrap; word-break: break-word; }
.token-display { font-family: var(--font-mono); font-size: var(--text-md); letter-spacing: 0.04em; background: var(--bg); border: 1px dashed var(--accent-line); border-radius: var(--radius); padding: var(--space-4); text-align: center; user-select: all; word-break: break-all; }

/* ---------- Tables ---------- */
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; border: 1px solid var(--line); border-radius: var(--radius-lg); }
.table { width: 100%; font-size: var(--text-sm); }
.table th { text-align: left; font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: var(--tracking-caps); color: var(--text-3); padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line-strong); white-space: nowrap; background: var(--bg-raised); }
.table td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover td { background: var(--surface); }
.table.compact td, .table.compact th { padding-block: var(--space-2); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .col-actions { text-align: right; white-space: nowrap; }
.table .col-actions .btn + .btn { margin-left: var(--space-1); }
@media (max-width: 40rem) {
  .table.responsive, .table.responsive tbody, .table.responsive tr, .table.responsive td { display: block; width: 100%; }
  .table.responsive thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .table.responsive tr { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--line); }
  .table.responsive tbody tr:last-child { border-bottom: 0; }
  .table.responsive td { display: flex; justify-content: space-between; align-items: center; gap: var(--space-4); border: 0; padding: var(--space-1) 0; text-align: right; }
  .table.responsive td::before { content: attr(data-label); flex: none; color: var(--text-3); font-size: var(--text-xs); font-weight: 600; text-transform: uppercase; letter-spacing: var(--tracking-caps); text-align: left; }
  .table.responsive td:not([data-label])::before { content: none; }
  .table.responsive td.col-actions { justify-content: flex-end; padding-top: var(--space-2); }
  .table.responsive tbody tr:hover td { background: transparent; }
}

/* ---------- Empty state, spinner, skeleton, progress ---------- */
.empty-state { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--space-3); padding: var(--space-8) var(--space-5); color: var(--text-2); max-width: 32rem; margin-inline: auto; }
.empty-icon { color: var(--text-3); }
.empty-title { font-family: var(--font-display); font-size: var(--text-xl); color: var(--text); font-weight: 500; line-height: var(--leading-tight); }
.empty-body { color: var(--text-2); }
.empty-actions { margin-top: var(--space-2); display: flex; gap: var(--space-3); flex-wrap: wrap; justify-content: center; }
.spinner { display: inline-block; width: 1.25rem; height: 1.25rem; border: 2px solid var(--line-strong); border-top-color: var(--accent); border-radius: 50%; animation: ig-spin 0.8s linear infinite; flex: none; }
.spinner.sm { width: 0.9rem; height: 0.9rem; }
.spinner.lg { width: 2rem; height: 2rem; border-width: 3px; }
.skeleton { display: block; background: linear-gradient(90deg, var(--surface) 0%, var(--surface-2) 50%, var(--surface) 100%); background-size: 200% 100%; animation: ig-shimmer 1.4s linear infinite; border-radius: var(--radius); min-height: 1rem; }
.skeleton.line { height: 0.9rem; margin-block: 0.35rem; }
.skeleton.circle { border-radius: 50%; }
.progress { height: 4px; background: var(--surface-3); border-radius: var(--radius-pill); overflow: hidden; position: relative; }
.progress.thin { height: 2px; }
.progress-bar { height: 100%; width: 0; background: var(--accent); border-radius: inherit; transition: width var(--dur) var(--ease); }
.progress.indeterminate .progress-bar { width: 35%; animation: ig-indeterminate 1.3s var(--ease) infinite; }

/* ---------- Modal ---------- */
.modal-backdrop { position: fixed; inset: 0; z-index: var(--z-modal); background: var(--overlay); display: grid; place-items: center; padding: var(--space-4); overflow-y: auto; animation: ig-fade var(--dur) var(--ease); }
.modal { width: 100%; max-width: 32rem; max-height: calc(100dvh - 2rem); display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-3); animation: ig-rise var(--dur) var(--ease); }
.modal.sm { max-width: 26rem; } .modal.lg { max-width: 44rem; } .modal.xl { max-width: 64rem; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); padding: var(--space-4) var(--space-5); border-bottom: 1px solid var(--line); }
.modal-title { font-family: var(--font-display); font-size: var(--text-lg); font-weight: 500; line-height: var(--leading-tight); padding-top: 0.55rem; }
.modal-close { margin: -0.15rem -0.5rem 0 0; }
.modal-body { padding: var(--space-5); overflow-y: auto; flex: 1 1 auto; min-height: 0; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--space-3); flex-wrap: wrap; padding: var(--space-4) var(--space-5); border-top: 1px solid var(--line); }
@media (max-width: 36rem) { .modal-foot > .btn { flex: 1 1 auto; } }

/* ---------- Toast ---------- */
.toasts { position: fixed; z-index: var(--z-toast); right: var(--space-4); bottom: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); width: min(24rem, calc(100vw - 2rem)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: flex-start; gap: var(--space-3); padding: var(--space-3) var(--space-3) var(--space-3) var(--space-4); background: var(--surface-2); border: 1px solid var(--line-strong); border-left: 3px solid var(--info); border-radius: var(--radius); box-shadow: var(--shadow-2); font-size: var(--text-sm); line-height: var(--leading-snug); animation: ig-rise var(--dur) var(--ease); }
.toast.success { border-left-color: var(--success); } .toast.error { border-left-color: var(--danger); }
.toast-icon { margin-top: 0.1rem; color: var(--info); } .toast.success .toast-icon { color: var(--success); } .toast.error .toast-icon { color: var(--danger); }
.toast-msg { flex: 1 1 auto; min-width: 0; padding-top: 0.1rem; }
.toast-close { margin: -0.4rem -0.2rem -0.4rem 0; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity var(--dur) var(--ease), transform var(--dur) var(--ease); }
@media (max-width: 36rem) { .toasts { left: var(--space-3); right: var(--space-3); bottom: var(--space-3); width: auto; } }

/* ---------- Menu / popover ---------- */
.menu-wrap { position: relative; display: inline-block; }
.menu { position: absolute; z-index: var(--z-menu); top: calc(100% + 6px); left: 0; min-width: 12rem; max-width: min(20rem, calc(100vw - 1.5rem)); padding: var(--space-1); background: var(--surface-2); border: 1px solid var(--line-strong); border-radius: var(--radius-lg); box-shadow: var(--shadow-2); animation: ig-rise var(--dur-fast) var(--ease); }
.menu.align-end { left: auto; right: 0; }
.menu-item { display: flex; align-items: center; gap: var(--space-3); width: 100%; min-height: var(--touch); padding: 0 var(--space-3); background: transparent; border: 0; border-radius: var(--radius); color: var(--text); font-size: var(--text-base); text-align: left; text-decoration: none; cursor: pointer; }
.menu-item:hover, .menu-item:focus-visible { background: var(--surface-3); color: var(--text); text-decoration: none; outline: none; }
.menu-item:focus-visible { box-shadow: inset 0 0 0 2px var(--focus-ring); }
.menu-item.danger { color: var(--danger); }
.menu-item .icon { color: var(--text-2); }
.menu-sep { height: 1px; background: var(--line); margin: var(--space-1) 0; border: 0; }
.menu-label { padding: var(--space-2) var(--space-3); font-size: var(--text-xs); color: var(--text-3); line-height: var(--leading-snug); }
.menu-label strong { display: block; color: var(--text); font-size: var(--text-base); font-weight: 600; }

[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after { content: attr(data-tip); position: absolute; z-index: var(--z-menu); left: 50%; top: calc(100% + 6px); transform: translateX(-50%); width: max-content; max-width: 16rem; padding: var(--space-1) var(--space-2); background: var(--surface-3); border: 1px solid var(--line-strong); border-radius: var(--radius-sm); color: var(--text); font-size: var(--text-xs); font-weight: 400; line-height: var(--leading-snug); text-align: left; white-space: normal; pointer-events: none; }

/* ---------- Shell ---------- */
.topbar { position: sticky; top: 0; z-index: var(--z-topbar); height: var(--topbar-h); display: flex; align-items: center; gap: var(--space-4); padding-inline: var(--space-5); background: var(--bg); border-bottom: 1px solid var(--line); }
.brand { display: inline-flex; align-items: baseline; gap: var(--space-2); color: var(--text); text-decoration: none; font-family: var(--font-display); font-size: 1.5rem; font-weight: 500; letter-spacing: 0.01em; line-height: 1; min-height: var(--touch); align-items: center; }
.brand:hover { color: var(--text); text-decoration: none; }
.brand-mark { display: inline-block; width: 0.5rem; height: 0.5rem; background: var(--accent-strong); transform: rotate(45deg); margin-right: 0.15rem; flex: none; }
.nav { display: flex; align-items: center; gap: var(--space-1); margin-left: var(--space-3); }
.nav-link { display: inline-flex; align-items: center; min-height: var(--touch); padding: 0 var(--space-3); color: var(--text-2); text-decoration: none; font-weight: 500; border-radius: var(--radius); position: relative; }
.nav-link:hover { color: var(--text); text-decoration: none; background: var(--surface); }
.nav-link.active { color: var(--text); }
.nav-link.active::after { content: ""; position: absolute; left: var(--space-3); right: var(--space-3); bottom: 0.2rem; height: 2px; background: var(--accent); }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.compute-slot { display: flex; align-items: center; min-width: 0; }
.account-btn { display: inline-flex; align-items: center; gap: var(--space-2); min-height: var(--touch); padding: 0 var(--space-2) 0 var(--space-1); background: transparent; border: 1px solid transparent; border-radius: var(--radius-pill); color: var(--text); }
.account-btn:hover { background: var(--surface); border-color: var(--line); }
.account-name { max-width: 9rem; font-size: var(--text-sm); font-weight: 500; }
.view { min-height: calc(100dvh - var(--topbar-h)); outline: none; }
body.bare .view { min-height: 100dvh; }
.topbar[hidden] { display: none; }
.view-loading { display: grid; place-items: center; min-height: 50vh; }
.view-error { padding-block: var(--space-7); }
.nav-toggle { display: none; }
@media (max-width: 48rem) {
  .topbar { padding-inline: var(--space-3); gap: var(--space-2); }
  .nav-toggle { display: inline-flex; }
  .nav { position: absolute; top: var(--topbar-h); left: 0; right: 0; flex-direction: column; align-items: stretch; margin: 0; padding: var(--space-2) var(--space-3); background: var(--bg); border-bottom: 1px solid var(--line); box-shadow: var(--shadow-2); }
  .nav { display: none; }
  .nav.open { display: flex; }
  .nav-link { padding: 0 var(--space-3); }
  .nav-link.active::after { left: 0; right: auto; width: 2px; top: 0.5rem; bottom: 0.5rem; height: auto; }
  .account-name { display: none; }
  .brand { font-size: 1.35rem; }
}

/* ---------- Keyframes ---------- */
@keyframes ig-spin { to { transform: rotate(360deg); } }
@keyframes ig-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }
@keyframes ig-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ig-rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes ig-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
@keyframes ig-indeterminate { 0% { transform: translateX(-100%); } 100% { transform: translateX(300%); } }
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
  .spinner, .btn.loading::after { animation-duration: 2s !important; }
}

/* Touch: segmented options meet the 44 px target on phones and touch screens */
@media (pointer: coarse), (max-width: 48rem) {
  .seg, .seg-label { min-height: var(--touch); }
}
