/* ============================================================================
 * tc-ui.css — Taleclip shared UI primitives (UI revamp Phase 2, WP-A)
 *
 * Token-driven building blocks for the SPA shell (index.html) and standalone
 * templates. Every class is `tc-` prefixed (BEM: .tc-block__elem--mod).
 * Colours come from themes.css tokens (--tc-*); only the fixed brand accents
 * (--tc-violet/-blue/-cyan/-rose/-amber, --tc-tile-*) are used directly.
 * Reference: docs/ui/design_system.md · demo: docs/ui/tc-ui-kitchen-sink.html
 * JS helpers (toast / confirm / dialog / drawer / empty / skeleton / tabs):
 * /static/js/tc-ui.js  (window.TcUI)
 *
 * Text colour convention: components set a private `--_tc-fg` and use
 * `color: var(--_tc-fg)`. That lets section 17 re-assert the colour against
 * the legacy light-mode `!important` blankets without per-variant rules.
 *
 * Sections
 *   1 Typography      2 Buttons        3 Form controls   4 Tabs
 *   5 Cards           6 Badges/chips   7 Status dots     8 Tables
 *   9 Scrim/drawer/dialog              10 Empty states   11 Skeletons
 *  12 Toasts          13 Page shell (no SPA sidebar)     14 Layout utils
 *  15 Keyframes       16 Reduced motion                  17 Legacy guards
 * ========================================================================== */

/* ---------------------------------------------------------------------------
 * 1. Typography
 * ------------------------------------------------------------------------- */
.tc-h1, .tc-h2, .tc-h3, .tc-h4 {
    --_tc-fg: var(--tc-text);
    margin: 0;
    color: var(--_tc-fg);
    font-weight: 700;
    line-height: var(--tc-lh-tight);
    letter-spacing: -0.015em;
}
.tc-h1 { font-size: clamp(1.75rem, 1.2rem + 2vw, var(--tc-fs-3xl)); letter-spacing: -0.025em; }
.tc-h2 { font-size: var(--tc-fs-2xl); }
.tc-h3 { font-size: var(--tc-fs-xl); }
.tc-h4 { font-size: var(--tc-fs-lg); font-weight: 650; }

.tc-eyebrow {
    --_tc-fg: var(--tc-link);
    display: inline-block;
    color: var(--_tc-fg);
    font-size: var(--tc-fs-xs);
    font-weight: 700;
    letter-spacing: var(--tc-tracking-eyebrow);
    text-transform: uppercase;
    line-height: 1.4;
}
.tc-lead {
    --_tc-fg: var(--tc-text-muted);
    margin: 0;
    color: var(--_tc-fg);
    font-size: var(--tc-fs-lg);
    line-height: 1.55;
    max-width: 68ch;
}
.tc-muted { --_tc-fg: var(--tc-text-muted); color: var(--_tc-fg); }
.tc-soft  { --_tc-fg: var(--tc-text-soft);  color: var(--_tc-fg); }
.tc-mono  { font-family: var(--tc-font-mono); font-variant-numeric: tabular-nums; }

.tc-kbd {
    --_tc-fg: var(--tc-text-muted);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.5em;
    height: 1.5em;
    padding: 0 0.4em;
    border: 1px solid var(--tc-border-strong);
    border-bottom-width: 2px;
    border-radius: 6px;
    background: var(--tc-bg-muted);
    color: var(--_tc-fg);
    font: 600 0.72rem/1 var(--tc-font-mono);
    white-space: nowrap;
}

.tc-link {
    --_tc-fg: var(--tc-link);
    color: var(--_tc-fg);
    text-decoration: underline;
    text-decoration-color: color-mix(in srgb, currentColor 40%, transparent);
    text-underline-offset: 3px;
    border-radius: 4px;
    cursor: pointer;
}
.tc-link:hover { text-decoration-color: currentColor; }
.tc-link:focus-visible { outline: none; box-shadow: var(--tc-focus-ring); }

/* ---------------------------------------------------------------------------
 * 2. Buttons
 *    .tc-btn [--primary|--secondary|--ghost|--outline|--accent|--danger|--success]
 *            [--sm|--lg] [--icon] [--block]  + .is-loading, [disabled]
 * ------------------------------------------------------------------------- */
.tc-btn {
    --_tc-fg: var(--tc-text);
    --_tc-bg: var(--tc-bg-elevated);
    --_tc-bg-hover: var(--tc-bg-elevated);
    --_tc-bd: var(--tc-border);
    --_tc-bd-hover: var(--tc-border-strong);
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 38px;
    padding: 0 16px;
    margin: 0;
    border: 1px solid var(--_tc-bd);
    border-radius: 10px;
    background: var(--_tc-bg);
    color: var(--_tc-fg);
    font-family: inherit;
    font-size: var(--tc-fs-sm);
    font-weight: 600;
    line-height: 1;
    text-decoration: none;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    transition: background-color 0.15s var(--tc-ease), border-color 0.15s var(--tc-ease),
                box-shadow 0.2s var(--tc-ease), transform 0.12s var(--tc-ease), color 0.15s;
}
.tc-btn:hover { background: var(--_tc-bg-hover); border-color: var(--_tc-bd-hover); }
.tc-btn:active { transform: translateY(1px); }
.tc-btn:focus-visible { outline: none; box-shadow: var(--tc-focus-ring); }
.tc-btn--primary {
    --_tc-fg: var(--tc-primary-text);
    --_tc-bg: var(--tc-primary);
    --_tc-bg-hover: var(--tc-primary-hover);
    --_tc-bd: var(--tc-primary);
    --_tc-bd-hover: var(--tc-primary-hover);
}
.tc-btn--primary:hover { box-shadow: var(--tc-glow); }
.tc-btn--secondary {
    --_tc-fg: var(--tc-secondary-text);
    --_tc-bg: var(--tc-secondary);
    --_tc-bg-hover: var(--tc-secondary-hover);
    --_tc-bd: var(--tc-secondary);
    --_tc-bd-hover: var(--tc-secondary-hover);
}
.tc-btn--ghost {
    --_tc-fg: var(--tc-text-muted);
    --_tc-bg: transparent;
    --_tc-bg-hover: var(--tc-card-hover);
    --_tc-bd: transparent;
    --_tc-bd-hover: transparent;
}
.tc-btn--ghost:hover { --_tc-fg: var(--tc-text); }
.tc-btn--outline {
    --_tc-bg: transparent;
    --_tc-bg-hover: var(--tc-card-hover);
    --_tc-bd: var(--tc-border-strong);
    --_tc-bd-hover: var(--tc-primary);
}
/* amber = accent only (e.g. "Buy credits"), never the default CTA */
.tc-btn--accent {
    --_tc-fg: #1f1400;
    --_tc-bg: var(--tc-amber);
    --_tc-bg-hover: #e6b000;
    --_tc-bd: var(--tc-amber);
    --_tc-bd-hover: #e6b000;
}
.tc-btn--danger {
    --_tc-fg: #ffffff;
    --_tc-bg: var(--tc-danger);
    --_tc-bg-hover: color-mix(in srgb, var(--tc-danger) 85%, #000);
    --_tc-bd: var(--tc-danger);
    --_tc-bd-hover: color-mix(in srgb, var(--tc-danger) 85%, #000);
}
.tc-btn--success {
    --_tc-fg: #04210f;
    --_tc-bg: var(--tc-success);
    --_tc-bg-hover: color-mix(in srgb, var(--tc-success) 88%, #000);
    --_tc-bd: var(--tc-success);
    --_tc-bd-hover: color-mix(in srgb, var(--tc-success) 88%, #000);
}
[data-theme-mode="light"] .tc-btn--success { --_tc-fg: #ffffff; }

.tc-btn--sm { min-height: 30px; padding: 0 11px; font-size: var(--tc-fs-xs); border-radius: 8px; gap: 6px; }
.tc-btn--lg { min-height: 48px; padding: 0 24px; font-size: var(--tc-fs-md); border-radius: 12px; }
.tc-btn--icon { padding: 0; width: 38px; }
.tc-btn--icon.tc-btn--sm { width: 30px; }
.tc-btn--icon.tc-btn--lg { width: 48px; }
.tc-btn--block { display: flex; width: 100%; }

.tc-btn[disabled], .tc-btn[aria-disabled="true"], .tc-btn.is-disabled {
    opacity: 0.5;
    cursor: not-allowed;
    box-shadow: none;
    transform: none;
    pointer-events: none;
}
.tc-btn.is-loading { cursor: progress; pointer-events: none; }
.tc-btn.is-loading::before {
    content: "";
    width: 14px;
    height: 14px;
    flex: none;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: tc-spin 0.7s linear infinite;
}

/* ---------------------------------------------------------------------------
 * 3. Form controls
 * ------------------------------------------------------------------------- */
/* `input.tc-input` etc. match base.css's `input[type="text"]` (0,1,1) — tc-ui.css
   loads later, so the primitive's padding/size win without !important. */
.tc-input, .tc-select, .tc-textarea,
input.tc-input, select.tc-select, textarea.tc-textarea {
    --_tc-fg: var(--tc-input-text);
    display: block;
    width: 100%;
    min-height: 38px;
    padding: 8px 12px;
    margin: 0;
    border: 1px solid var(--tc-input-border);
    border-radius: 10px;
    background: var(--tc-input-bg);
    color: var(--_tc-fg);
    font-family: inherit;
    font-size: var(--tc-fs-sm);
    line-height: 1.4;
    box-sizing: border-box;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.tc-textarea, textarea.tc-textarea { min-height: 96px; resize: vertical; }
/* >=16px on touch-size screens prevents iOS focus zoom */
@media (max-width: 640px) {
    input.tc-input, select.tc-select, textarea.tc-textarea { font-size: 16px; }
}
.tc-input::placeholder, .tc-textarea::placeholder { color: var(--tc-text-soft); opacity: 1; }
.tc-input:hover, .tc-select:hover, .tc-textarea:hover { border-color: var(--tc-border-strong); }
.tc-input:focus, .tc-select:focus, .tc-textarea:focus {
    outline: none;
    border-color: var(--tc-primary);
    box-shadow: var(--tc-focus-ring);
}
.tc-input:disabled, .tc-select:disabled, .tc-textarea:disabled { opacity: 0.55; cursor: not-allowed; }
/* themes.css forces input/select/textarea `border-color … !important`; the
   error state must win over it, hence !important here. */
.tc-input[aria-invalid="true"], .tc-select[aria-invalid="true"], .tc-textarea[aria-invalid="true"],
.tc-field.is-invalid .tc-input, .tc-field.is-invalid .tc-select, .tc-field.is-invalid .tc-textarea {
    border-color: var(--tc-danger) !important;
}
/* themes.css sets `select { background: … !important }` (shorthand), which
   would wipe the chevron image — re-assert the longhands. */
.tc-select, select.tc-select {
    appearance: none;
    -webkit-appearance: none;
    padding-right: 34px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238f84c4' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") !important;
    background-repeat: no-repeat !important;
    background-position: right 12px center !important;
    background-size: 12px 8px !important;
    cursor: pointer;
}

.tc-field { display: grid; align-content: start; gap: 6px; min-width: 0; }
.tc-field__label { --_tc-fg: var(--tc-text); color: var(--_tc-fg); font-size: var(--tc-fs-sm); font-weight: 600; }
.tc-field__hint  { --_tc-fg: var(--tc-text-soft); color: var(--_tc-fg); font-size: var(--tc-fs-xs); line-height: 1.45; }
.tc-field__error { --_tc-fg: var(--tc-danger); color: var(--_tc-fg); font-size: var(--tc-fs-xs); font-weight: 600; line-height: 1.45; }
.tc-field__error:empty { display: none; }

/* checkbox / radio:  <label class="tc-check"><input type="checkbox"> Text</label> */
.tc-check {
    --_tc-fg: var(--tc-text);
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: var(--_tc-fg);
    font-size: var(--tc-fs-sm);
    cursor: pointer;
}
.tc-check input { width: 16px; height: 16px; margin: 0; accent-color: var(--tc-primary); cursor: pointer; }
.tc-check input:focus-visible { outline: none; box-shadow: var(--tc-focus-ring); border-radius: 4px; }
.tc-check:has(input:disabled) { opacity: 0.55; cursor: not-allowed; }

/* switch: <label class="tc-switch"><input type="checkbox" role="switch">
           <span class="tc-switch__track" aria-hidden="true"></span> Label</label> */
.tc-switch {
    --_tc-fg: var(--tc-text);
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--_tc-fg);
    font-size: var(--tc-fs-sm);
    cursor: pointer;
}
.tc-switch input {
    position: absolute;
    opacity: 0;
    width: 36px;
    height: 20px;
    margin: 0;
    cursor: pointer;
}
.tc-switch__track {
    position: relative;
    flex: none;
    width: 36px;
    height: 20px;
    border-radius: 999px;
    background: var(--tc-border);
    border: 1px solid var(--tc-border-strong);
    box-sizing: border-box;
    transition: background-color 0.18s var(--tc-ease), border-color 0.18s;
}
.tc-switch__track::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.35);
    transition: transform 0.18s var(--tc-ease);
}
.tc-switch input:checked + .tc-switch__track { background: var(--tc-primary); border-color: var(--tc-primary); }
.tc-switch input:checked + .tc-switch__track::after { transform: translateX(16px); }
.tc-switch input:focus-visible + .tc-switch__track { box-shadow: var(--tc-focus-ring); }
.tc-switch input:disabled + .tc-switch__track { opacity: 0.5; }
.tc-switch:has(input:disabled) { cursor: not-allowed; }

/* input group: addon + borderless inner control share one frame */
.tc-input-group {
    display: flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 0 10px;
    border: 1px solid var(--tc-input-border);
    border-radius: 10px;
    background: var(--tc-input-bg);
    transition: border-color 0.15s, box-shadow 0.15s;
}
.tc-input-group:hover { border-color: var(--tc-border-strong); }
.tc-input-group:focus-within { border-color: var(--tc-primary); box-shadow: var(--tc-focus-ring); }
.tc-input-group > .tc-input,
.tc-input-group > input.tc-input {
    flex: 1 1 auto;
    min-width: 0;
    padding-left: 2px;
    padding-right: 2px;
    border: 0;
    background: transparent;
    box-shadow: none !important; /* frame owns the ring (themes.css forces one on input:focus) */
}
.tc-input-group__addon {
    --_tc-fg: var(--tc-text-soft);
    display: inline-flex;
    align-items: center;
    flex: none;
    color: var(--_tc-fg);
    font-size: var(--tc-fs-sm);
}
.tc-input-group--search { border-radius: 12px; }
.tc-input-group--search .tc-kbd { margin-left: auto; }

/* ---------------------------------------------------------------------------
 * 4. Tabs  — .tc-tabs[role=tablist] > .tc-tab[role=tab][aria-selected]
 *            + .tc-tabpanel[role=tabpanel]; .tc-tabs--pill variant
 * ------------------------------------------------------------------------- */
.tc-tabs {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    border-bottom: 1px solid var(--tc-border);
    overflow-x: auto;
    scrollbar-width: thin;
}
.tc-tab {
    --_tc-fg: var(--tc-text-muted);
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 14px;
    margin: 0 0 -1px;
    border: 0;
    border-bottom: 2px solid transparent;
    border-radius: 8px 8px 0 0;
    background: transparent;
    color: var(--_tc-fg);
    font-family: inherit;
    font-size: var(--tc-fs-sm);
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s, background-color 0.15s;
}
.tc-tab:hover { --_tc-fg: var(--tc-text); background: var(--tc-card-hover); }
.tc-tab[aria-selected="true"], .tc-tab.is-active {
    --_tc-fg: var(--tc-text);
    border-bottom-color: var(--tc-primary);
}
.tc-tab:focus-visible { outline: none; box-shadow: var(--tc-focus-ring); }
.tc-tab[disabled], .tc-tab[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }
.tc-tabs--pill { gap: 6px; border-bottom: 0; align-items: center; padding: 2px; }
.tc-tabs--pill .tc-tab {
    margin: 0;
    padding: 6px 14px;
    border: 1px solid var(--tc-border);
    border-radius: 999px;
    font-size: var(--tc-fs-xs);
}
/* primary-tinted rather than --tc-sidebar-active: highContrast sets that to
   pure #fff/#000, which would hide --tc-text on it */
.tc-tabs--pill .tc-tab[aria-selected="true"], .tc-tabs--pill .tc-tab.is-active {
    background: color-mix(in srgb, var(--tc-primary) 24%, transparent);
    border-color: var(--tc-border-strong);
}
.tc-tabpanel { padding-top: 16px; }
.tc-tabpanel[hidden] { display: none; }
.tc-tabpanel:focus-visible { outline: none; box-shadow: var(--tc-focus-ring); border-radius: 8px; }

/* ---------------------------------------------------------------------------
 * 5. Cards
 * ------------------------------------------------------------------------- */
.tc-card {
    --_tc-fg: var(--tc-text);
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 12px;
    min-width: 0;
    padding: 18px;
    border: 1px solid var(--tc-border);
    border-radius: 16px;
    background: var(--tc-card-bg);
    color: var(--_tc-fg);
    box-shadow: var(--tc-shadow);
    text-decoration: none;
}
.tc-card__header { display: flex; align-items: center; gap: 10px; justify-content: space-between; min-width: 0; }
.tc-card__title { margin: 0; color: var(--tc-text); font-size: var(--tc-fs-md); font-weight: 700; line-height: 1.3; }
.tc-card__body { color: var(--tc-text-muted); font-size: var(--tc-fs-sm); line-height: 1.5; min-width: 0; }
.tc-card__footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--tc-border);
}
.tc-card__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 42px;
    height: 42px;
    border-radius: 12px;
    background: var(--tc-badge-bg);
    color: var(--tc-text);
    font-size: 1.25rem;
}
.tc-card--glass {
    background: var(--tc-card-glass);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    backdrop-filter: blur(14px) saturate(140%);
}
.tc-card--interactive {
    cursor: pointer;
    transition: transform 0.18s var(--tc-ease), border-color 0.18s, box-shadow 0.2s var(--tc-ease);
}
.tc-card--interactive:hover {
    transform: translateY(-2px);
    border-color: var(--tc-border-strong);
    box-shadow: var(--tc-shadow), var(--tc-glow);
}
.tc-card--interactive:active { transform: translateY(0); }
.tc-card--interactive:focus-visible { outline: none; box-shadow: var(--tc-focus-ring); }

/* creation-shortcut tiles (mockup row: Generate Video / Image / Voice / Avatar / …) */
.tc-card[class*="tc-card--tint-"] { background-color: var(--tc-card-bg); background-image: var(--_tc-tile); border-color: var(--_tc-tile-bd); }
.tc-card[class*="tc-card--tint-"] .tc-card__icon { background: var(--_tc-tile-icon); color: #ffffff; }
.tc-card--tint-violet { --_tc-tile: var(--tc-tile-violet); --_tc-tile-bd: rgba(139,53,245,0.45); --_tc-tile-icon: var(--tc-violet); }
.tc-card--tint-blue   { --_tc-tile: var(--tc-tile-blue);   --_tc-tile-bd: rgba(52,155,255,0.42); --_tc-tile-icon: #1f7ae0; }
.tc-card--tint-cyan   { --_tc-tile: var(--tc-tile-cyan);   --_tc-tile-bd: rgba(54,220,235,0.40); --_tc-tile-icon: #0e8fa0; }
.tc-card--tint-rose   { --_tc-tile: var(--tc-tile-rose);   --_tc-tile-bd: rgba(224,71,158,0.42); --_tc-tile-icon: #c2307f; }
.tc-card--tint-amber  { --_tc-tile: var(--tc-tile-amber);  --_tc-tile-bd: rgba(255,196,0,0.40);  --_tc-tile-icon: #b37800; }

.tc-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(var(--tc-card-min, 220px), 1fr));
    gap: var(--tc-gap, 16px);
}

/* ---------------------------------------------------------------------------
 * 6. Badges + chips (shared tone machinery)
 * ------------------------------------------------------------------------- */
.tc-badge, .tc-chip { --_tc-mix: #ffffff; }
[data-theme-mode="light"] .tc-badge, [data-theme-mode="light"] .tc-chip { --_tc-mix: #12081f; }
.tc-badge--success, .tc-chip--success { --_tc-tone: var(--tc-success); }
.tc-badge--warning, .tc-chip--warning { --_tc-tone: var(--tc-warning); }
.tc-badge--danger,  .tc-chip--danger  { --_tc-tone: var(--tc-danger); }
.tc-badge--info,    .tc-chip--info    { --_tc-tone: var(--tc-info); }
.tc-badge--violet,  .tc-chip--violet  { --_tc-tone: var(--tc-violet-soft); }
[data-theme-mode="light"] .tc-badge--violet, [data-theme-mode="light"] .tc-chip--violet { --_tc-tone: var(--tc-violet); }

.tc-badge {
    --_tc-fg: var(--tc-badge-text);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border: 1px solid transparent;
    border-radius: 999px;
    background: var(--tc-badge-bg);
    color: var(--_tc-fg);
    font-size: 0.7rem;
    font-weight: 700;
    line-height: 1.2;
    letter-spacing: 0.02em;
    white-space: nowrap;
    vertical-align: middle;
}
.tc-badge[class*="tc-badge--"]:not(.tc-badge--neutral),
.tc-chip[class*="tc-chip--"] {
    --_tc-fg: color-mix(in srgb, var(--_tc-tone) 62%, var(--_tc-mix));
    background: color-mix(in srgb, var(--_tc-tone) 15%, transparent);
    border-color: color-mix(in srgb, var(--_tc-tone) 34%, transparent);
}
.tc-badge--neutral {
    --_tc-fg: var(--tc-text-muted);
    background: var(--tc-bg-elevated);
    border-color: var(--tc-border);
}

/* header status pill: <span class="tc-chip"><span class="tc-dot tc-dot--ok"></span>
   <span class="tc-chip__label">Queue</span><span class="tc-chip__value">0</span></span> */
.tc-chip {
    --_tc-fg: var(--tc-text);
    display: inline-flex;
    align-items: center;
    gap: 7px;
    height: 30px;
    padding: 0 12px;
    border: 1px solid var(--tc-border);
    border-radius: 999px;
    background: var(--tc-card-glass);
    color: var(--_tc-fg);
    font-size: var(--tc-fs-xs);
    font-weight: 600;
    line-height: 1;
    white-space: nowrap;
}
.tc-chip__label { color: inherit; opacity: 0.78; }
.tc-chip__value { font-variant-numeric: tabular-nums; font-weight: 700; }
button.tc-chip, a.tc-chip { cursor: pointer; text-decoration: none; font-family: inherit; }
button.tc-chip:hover, a.tc-chip:hover { border-color: var(--tc-border-strong); }
button.tc-chip:focus-visible, a.tc-chip:focus-visible { outline: none; box-shadow: var(--tc-focus-ring); }

/* ---------------------------------------------------------------------------
 * 7. Status dot — .tc-dot [--ok|--warn|--err|--idle] [--pulse]
 * ------------------------------------------------------------------------- */
.tc-dot {
    --_tc-dot: var(--tc-text-soft);
    display: inline-block;
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--_tc-dot);
    vertical-align: middle;
}
.tc-dot--ok   { --_tc-dot: var(--tc-success); }
.tc-dot--warn { --_tc-dot: var(--tc-warning); }
.tc-dot--err  { --_tc-dot: var(--tc-danger); }
.tc-dot--idle { --_tc-dot: var(--tc-text-soft); }
.tc-dot--pulse { animation: tc-pulse 1.8s ease-out infinite; }

/* ---------------------------------------------------------------------------
 * 8. Tables
 * ------------------------------------------------------------------------- */
.tc-table-wrap {
    max-width: 100%;
    overflow: auto;
    border: 1px solid var(--tc-border);
    border-radius: 14px;
    background: var(--tc-card-bg);
    -webkit-overflow-scrolling: touch;
}
.tc-table-wrap:focus-visible { outline: none; box-shadow: var(--tc-focus-ring); }
.tc-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    color: var(--tc-text);
    font-size: var(--tc-fs-sm);
}
.tc-table th, .tc-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--tc-border);
    text-align: left;
    vertical-align: middle;
}
.tc-table thead th {
    --_tc-fg: var(--tc-text-muted);
    background: var(--tc-table-header);
    color: var(--_tc-fg);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    white-space: nowrap;
}
.tc-table td { --_tc-fg: var(--tc-text); color: var(--_tc-fg); }
.tc-table tbody tr:last-child td { border-bottom: 0; }
.tc-table tbody tr { background: transparent; transition: background-color 0.12s; }
.tc-table tbody tr:hover { background: var(--tc-table-row-hover); }
.tc-table .is-num, .tc-table td.tc-num, .tc-table th.tc-num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}
.tc-table--sticky thead th { position: sticky; top: 0; z-index: 1; }
.tc-table--dense th, .tc-table--dense td { padding: 6px 10px; }

/* ---------------------------------------------------------------------------
 * 9. Scrim, drawer, dialog (CSS only — behaviour in tc-ui.js)
 *    open state: [data-open] or .is-open
 * ------------------------------------------------------------------------- */
.tc-scrim {
    position: fixed;
    inset: 0;
    z-index: calc(var(--tc-z-drawer) - 1);
    background: rgba(6, 3, 18, 0.62);
    -webkit-backdrop-filter: blur(2px);
    backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 0.2s var(--tc-ease);
}
[data-theme-mode="light"] .tc-scrim { background: rgba(36, 22, 74, 0.32); }
.tc-scrim--modal { z-index: calc(var(--tc-z-modal) - 1); }
.tc-scrim[data-open], .tc-scrim.is-open { opacity: 1; }

.tc-drawer, .tc-dialog {
    --_tc-fg: var(--tc-text);
    position: fixed;
    display: flex;
    flex-direction: column;
    background: var(--tc-modal-bg);
    color: var(--_tc-fg);
    box-shadow: var(--tc-shadow);
    visibility: hidden;
    box-sizing: border-box;
}
.tc-drawer {
    top: var(--tc-vv-top, 0px);
    bottom: auto;
    height: var(--tc-vvh, 100%);
    right: 0;
    z-index: var(--tc-z-drawer);
    width: var(--tc-drawer-width, min(420px, 92vw));
    border-left: 1px solid var(--tc-modal-border);
    transform: translateX(100%);
    transition: transform 0.24s var(--tc-ease), visibility 0s linear 0.24s;
}
.tc-drawer--left {
    right: auto;
    left: 0;
    border-left: 0;
    border-right: 1px solid var(--tc-modal-border);
    transform: translateX(-100%);
}
.tc-drawer[data-open], .tc-drawer.is-open {
    visibility: visible;
    transform: none;
    transition: transform 0.24s var(--tc-ease), visibility 0s;
}

.tc-dialog {
    left: 50%;
    z-index: var(--tc-z-modal);
    width: min(520px, calc(100vw - 32px));
    top: calc(var(--tc-vv-top, 0px) + (var(--tc-vvh, 100dvh) / 2));
    max-height: calc(var(--tc-vvh, 100dvh) - 48px);
    border: 1px solid var(--tc-modal-border);
    border-radius: 18px;
    opacity: 0;
    transform: translate(-50%, -47%) scale(0.98);
    transition: opacity 0.18s var(--tc-ease), transform 0.2s var(--tc-ease), visibility 0s linear 0.2s;
}
.tc-dialog--sm { width: min(400px, calc(100vw - 32px)); }
.tc-dialog--lg { width: min(760px, calc(100vw - 32px)); }
.tc-dialog--xl { width: min(1040px, calc(100vw - 32px)); }
.tc-dialog[data-open], .tc-dialog.is-open {
    visibility: visible;
    opacity: 1;
    transform: translate(-50%, -50%);
    transition: opacity 0.18s var(--tc-ease), transform 0.2s var(--tc-ease), visibility 0s;
}
.tc-dialog:focus-visible, .tc-drawer:focus-visible { outline: none; }

.tc-dialog__header, .tc-drawer__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--tc-modal-border);
}
.tc-dialog__title, .tc-drawer__title { margin: 0; color: var(--tc-text); font-size: var(--tc-fs-lg); font-weight: 700; }
.tc-dialog__body, .tc-drawer__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
    padding: 18px 20px;
    color: var(--tc-text-muted);
    font-size: var(--tc-fs-sm);
    line-height: 1.55;
}
.tc-dialog__footer, .tc-drawer__footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
    padding: 14px 20px;
    border-top: 1px solid var(--tc-modal-border);
}
/* set by TcUI while an overlay is open */
html.tc-scroll-lock, html.tc-scroll-lock body { overflow: hidden; }

/* ---------------------------------------------------------------------------
 * 10. Empty state
 * ------------------------------------------------------------------------- */
.tc-empty {
    --_tc-fg: var(--tc-text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 40px 24px;
    border: 1px dashed var(--tc-border-strong);
    border-radius: 16px;
    color: var(--_tc-fg);
    text-align: center;
}
.tc-empty__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: var(--tc-badge-bg);
    color: var(--tc-text);
    font-size: 1.5rem;
}
.tc-empty__title { margin: 4px 0 0; color: var(--tc-text); font-size: var(--tc-fs-md); font-weight: 700; }
.tc-empty__body { margin: 0; max-width: 46ch; font-size: var(--tc-fs-sm); line-height: 1.5; }
.tc-empty__action { margin-top: 6px; display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }

/* ---------------------------------------------------------------------------
 * 11. Skeletons
 * ------------------------------------------------------------------------- */
.tc-skeleton {
    --_tc-shine: rgba(255, 255, 255, 0.07);
    position: relative;
    display: block;
    overflow: hidden;
    border-radius: 8px;
    background: color-mix(in srgb, var(--tc-text) 10%, transparent);
}
[data-theme-mode="light"] .tc-skeleton { --_tc-shine: rgba(255, 255, 255, 0.75); background: color-mix(in srgb, var(--tc-text) 8%, transparent); }
.tc-skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg, transparent, var(--_tc-shine), transparent);
    animation: tc-shimmer 1.4s ease-in-out infinite;
}
.tc-skeleton--text   { height: 0.8em; width: 100%; margin: 0.45em 0; border-radius: 6px; }
.tc-skeleton--text:last-child:not(:only-child) { width: 70%; }
.tc-skeleton--title  { height: 1.35em; width: 55%; margin: 0.3em 0 0.6em; }
.tc-skeleton--thumb  { width: 100%; aspect-ratio: 16 / 9; border-radius: 12px; }
.tc-skeleton--circle { width: 40px; height: 40px; border-radius: 50%; }

/* ---------------------------------------------------------------------------
 * 12. Toasts
 * ------------------------------------------------------------------------- */
.tc-toast-region {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: var(--tc-z-toast);
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    width: min(380px, calc(100vw - 32px));
    pointer-events: none;
}
.tc-toast {
    --_tc-fg: var(--tc-text);
    --_tc-tone: var(--tc-info);
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: start;
    gap: 10px;
    padding: 12px 12px 12px 14px;
    border: 1px solid var(--tc-modal-border);
    border-left: 4px solid var(--_tc-tone);
    border-radius: 14px;
    background: var(--tc-modal-bg);
    color: var(--_tc-fg);
    box-shadow: var(--tc-shadow);
    pointer-events: auto;
    animation: tc-toast-in 0.22s var(--tc-ease);
}
.tc-toast--success { --_tc-tone: var(--tc-success); }
.tc-toast--warning { --_tc-tone: var(--tc-warning); }
.tc-toast--danger  { --_tc-tone: var(--tc-danger); }
.tc-toast--info    { --_tc-tone: var(--tc-info); }
.tc-toast.is-leaving { animation: tc-toast-out 0.18s var(--tc-ease) forwards; }
.tc-toast__icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: color-mix(in srgb, var(--_tc-tone) 22%, transparent);
    color: var(--_tc-tone);
    font-size: 0.8rem;
    font-weight: 800;
    line-height: 1;
}
.tc-toast__content { min-width: 0; }
.tc-toast__title { margin: 1px 0 2px; color: var(--tc-text); font-size: var(--tc-fs-sm); font-weight: 700; }
.tc-toast__message { margin: 0; color: var(--tc-text-muted); font-size: var(--tc-fs-sm); line-height: 1.45; overflow-wrap: anywhere; }
.tc-toast__actions { display: flex; gap: 8px; margin-top: 8px; }
.tc-toast__close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    margin: -2px -2px 0 0;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--tc-text-soft);
    font-size: 1.05rem;
    line-height: 1;
    cursor: pointer;
}
.tc-toast__close:hover { background: var(--tc-card-hover); color: var(--tc-text); }
.tc-toast__close:focus-visible { outline: none; box-shadow: var(--tc-focus-ring); }

/* ---------------------------------------------------------------------------
 * 13. Page shell for templates WITHOUT the SPA sidebar
 * ------------------------------------------------------------------------- */
.tc-page {
    --_tc-fg: var(--tc-text);
    width: 100%;
    max-width: var(--tc-page-max, 1200px);
    margin: 0 auto;
    padding: clamp(16px, 3vw, 32px);
    box-sizing: border-box;
    color: var(--_tc-fg);
    font-family: var(--tc-font-sans);
}
.tc-page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px 24px;
    margin-bottom: 24px;
}
.tc-page-header__text { display: flex; flex-direction: column; gap: 6px; min-width: 0; flex: 1 1 320px; }
.tc-page-header__eyebrow {
    color: var(--tc-link);
    font-size: var(--tc-fs-xs);
    font-weight: 700;
    letter-spacing: var(--tc-tracking-eyebrow);
    text-transform: uppercase;
}
.tc-page-header__title {
    margin: 0;
    color: var(--tc-text);
    font-size: clamp(1.5rem, 1.1rem + 1.4vw, var(--tc-fs-2xl));
    font-weight: 700;
    line-height: var(--tc-lh-tight);
    letter-spacing: -0.02em;
}
.tc-page-header__subtitle { margin: 0; color: var(--tc-text-muted); font-size: var(--tc-fs-md); line-height: 1.5; max-width: 70ch; }
.tc-page-header__actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }

.tc-topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    gap: 16px;
    min-height: 60px;
    padding: 8px clamp(12px, 3vw, 28px);
    box-sizing: border-box;
    border-bottom: 1px solid var(--tc-border);
    background: var(--tc-header-bg);
    -webkit-backdrop-filter: blur(14px) saturate(140%);
    backdrop-filter: blur(14px) saturate(140%);
    font-family: var(--tc-font-sans);
}
.tc-topbar__brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    flex: none;
    color: var(--tc-text);
    font-size: var(--tc-fs-lg);
    font-weight: 800;
    letter-spacing: -0.01em;
    text-decoration: none;
    border-radius: 8px;
}
.tc-topbar__brand:focus-visible { outline: none; box-shadow: var(--tc-focus-ring); }
.tc-topbar__nav { display: flex; align-items: center; gap: 4px; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.tc-topbar__spacer { flex: 1 1 auto; }
.tc-topbar__actions { display: flex; align-items: center; gap: 8px; flex: none; }

.tc-nav-link {
    --_tc-fg: var(--tc-text-muted);
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 12px;
    border-radius: 10px;
    color: var(--_tc-fg);
    font-size: var(--tc-fs-sm);
    font-weight: 600;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 0.15s, color 0.15s;
}
.tc-nav-link:hover { --_tc-fg: var(--tc-text); background: var(--tc-card-hover); }
.tc-nav-link[aria-current="page"], .tc-nav-link.is-active { --_tc-fg: var(--tc-text); background: color-mix(in srgb, var(--tc-primary) 24%, transparent); }
.tc-nav-link:focus-visible { outline: none; box-shadow: var(--tc-focus-ring); }

.tc-panel {
    --_tc-fg: var(--tc-text);
    padding: 20px;
    border: 1px solid var(--tc-border);
    border-radius: 16px;
    background: var(--tc-card-bg);
    color: var(--_tc-fg);
    font-size: var(--tc-fs-sm);
}
.tc-panel__header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.tc-panel__title { margin: 0; color: var(--tc-text); font-size: var(--tc-fs-lg); font-weight: 700; }

/* ---------------------------------------------------------------------------
 * 14. Layout utilities (only what the primitives need)
 * ------------------------------------------------------------------------- */
.tc-stack { display: flex; flex-direction: column; gap: var(--tc-gap, 12px); }
.tc-row   { display: flex; flex-wrap: wrap; align-items: center; gap: var(--tc-gap, 12px); }
.tc-grid  { display: grid; gap: var(--tc-gap, 16px); grid-template-columns: repeat(auto-fill, minmax(var(--tc-grid-min, 240px), 1fr)); }
.tc-sr-only {
    position: absolute !important;
    width: 1px; height: 1px;
    padding: 0; margin: -1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
    border: 0;
}

/* ---------------------------------------------------------------------------
 * 15. Keyframes
 * ------------------------------------------------------------------------- */
@keyframes tc-spin { to { transform: rotate(360deg); } }
@keyframes tc-shimmer { to { transform: translateX(100%); } }
@keyframes tc-pulse {
    0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--_tc-dot) 55%, transparent); }
    70%  { box-shadow: 0 0 0 7px transparent; }
    100% { box-shadow: 0 0 0 0 transparent; }
}
@keyframes tc-toast-in  { from { opacity: 0; transform: translateY(8px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes tc-toast-out { to { opacity: 0; transform: translateX(16px); } }

/* ---------------------------------------------------------------------------
 * 16. Reduced motion
 * ------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .tc-btn, .tc-card--interactive, .tc-tab, .tc-switch__track, .tc-switch__track::after,
    .tc-drawer, .tc-dialog, .tc-scrim, .tc-nav-link, .tc-input, .tc-select, .tc-textarea {
        transition: none !important;
    }
    .tc-card--interactive:hover, .tc-btn:active { transform: none; }
    .tc-skeleton::after, .tc-dot--pulse, .tc-toast, .tc-toast.is-leaving { animation: none !important; }
    .tc-btn.is-loading::before { animation-duration: 2.4s; }
}

/* ---------------------------------------------------------------------------
 * 17. Legacy guards
 *     light-mode-overrides.css forces `color: … !important` on EVERY element
 *     inside .page-section / .admin-page in light mode (and a button rule with
 *     specificity ~(0,7,1)). That would paint white-on-violet CTAs dark. These
 *     guards re-assert each primitive's own --_tc-fg. `#tc-ui-guard` never
 *     exists in the DOM — inside :is() it only lifts specificity to ID level so
 *     the guard beats those long attribute chains. Descendants inherit; the
 *     element rule comes second so a nested primitive keeps its own colour.
 * ------------------------------------------------------------------------- */
[data-theme="light"] :is(.tc-btn, .tc-badge, .tc-chip, .tc-eyebrow, .tc-link, .tc-muted, .tc-soft,
    .tc-kbd, .tc-tab, .tc-nav-link, .tc-toast, .tc-empty, .tc-field__label, .tc-field__hint,
    .tc-field__error, .tc-input-group__addon, .tc-table th, .tc-table td, .tc-h1, .tc-h2, .tc-h3,
    .tc-h4, .tc-lead, .tc-check, .tc-switch, #tc-ui-guard) * {
    color: inherit !important;
}
[data-theme="light"] :is(.tc-btn, .tc-badge, .tc-chip, .tc-eyebrow, .tc-link, .tc-muted, .tc-soft,
    .tc-kbd, .tc-tab, .tc-nav-link, .tc-toast, .tc-empty, .tc-field__label, .tc-field__hint,
    .tc-field__error, .tc-input-group__addon, .tc-table th, .tc-table td, .tc-h1, .tc-h2, .tc-h3,
    .tc-h4, .tc-lead, .tc-check, .tc-switch, #tc-ui-guard) {
    color: var(--_tc-fg) !important;
}
/* toast/empty/dialog sub-parts have their own tones */
[data-theme="light"] :is(.tc-toast__title, .tc-empty__title, .tc-card__title, .tc-dialog__title,
    .tc-drawer__title, .tc-panel__title, .tc-page-header__title, #tc-ui-guard) { color: var(--tc-text) !important; }
[data-theme="light"] :is(.tc-toast__message, .tc-card__body, .tc-page-header__subtitle, #tc-ui-guard) { color: var(--tc-text-muted) !important; }
[data-theme="light"] :is(.tc-toast__icon, #tc-ui-guard) { color: var(--_tc-tone) !important; }
[data-theme="light"] :is(.tc-card[class*="tc-card--tint-"] .tc-card__icon, #tc-ui-guard) { color: #ffffff !important; }
/* light-mode-overrides section 4 forces input surfaces; keep the error border */
[data-theme="light"] :is(.tc-input, .tc-select, .tc-textarea, #tc-ui-guard)[aria-invalid="true"] { border-color: var(--tc-danger) !important; }
[data-theme="light"] :is(.tc-input-group > .tc-input, #tc-ui-guard) { border: 0 !important; background: transparent !important; }
