/* ============================================================================
 * tokens.css — Alana design tokens (WS7.2)
 *
 * Single source of truth for the design system: colour, spacing, type scale,
 * radius, shadow, motion timing. Included BEFORE dashboard.css so dashboard.css
 * (and any inline styles refactored to use tokens) can consume them.
 *
 * IMPORTANT: This file is ADDITIVE. dashboard.css already defines a rich set of
 * --bg-*, --text-*, --accent-* theme variables in its own :root / [data-theme]
 * blocks. We do NOT redefine those here (to avoid cascade fights). We add a
 * NEW, namespaced layer of primitives (spacing/type/radius/shadow/motion) plus
 * a few semantic aliases. Everything degrades gracefully via var() fallbacks.
 * ========================================================================== */

:root {
    /* ── Shared colour palette (Phase 8D) — single source of truth for BOTH
     *    the user dashboard and the admin dashboard. Refreshed layered blue-slate
     *    dark theme. dashboard.css redeclares these identically for back-compat;
     *    admin.html aliases its local names (--bg-page, --bg-card…) to these. ── */
    --bg-primary: #0b0e14;
    --bg-secondary: #151a23;
    --bg-tertiary: #11151d;
    --bg-hover: #1c222e;
    --bg-input: #0e1218;
    --bg-elevated: #1b2230;
    --bg-deep: #0e1420;
    --bg-overlay: #0b1120;
    --border-primary: #242c3a;
    --border-secondary: #374151;
    --border-subtle: #1a2130;
    --border-form: #38414f;
    --text-primary: #f3f4f6;
    --text-secondary: #e5e7eb;
    --text-tertiary: #d1d5db;
    --text-muted: #94a3b8;
    --text-faint: #6b7280;
    --text-dim: #4b5563;
    --cta: #059669;
    --cta-hover: #047857;
    --accent: #6366f1;
    --accent-hover: #5558e3;
    --accent-deep: #4f46e5;
    --accent-bg: #312e81;
    --accent-bg-light: #1e1b4b;
    --accent-text: #a5b4fc;
    --accent-text-light: #c4b5fd;
    --accent-text-pale: #e0e7ff;
    --accent-text-white: #818cf8;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --accent-glow: 0 6px 20px rgba(99, 102, 241, 0.35);
    --shadow-card: 0 6px 24px rgba(0,0,0,0.42), 0 1px 0 rgba(255,255,255,0.03) inset;
    --info-bg: #1c2a3f;
    --info-border: #1e40af;
    --info-text: #93c5fd;
    --toast-success-bg: #1e3a2f;
    --toast-success-border: #065f46;
    --toast-success-text: #6ee7b7;
    --toast-error-bg: #2d1515;
    --toast-error-border: #7f1d1d;
    --toast-error-text: #fca5a5;
    --color-scheme: dark;

    /* ── Spacing scale (4px base) ─────────────────────────────────────── */
    --space-0: 0;
    --space-1: 4px;
    --space-2: 8px;
    --space-3: 12px;
    --space-4: 16px;
    --space-5: 20px;
    --space-6: 24px;
    --space-8: 32px;
    --space-10: 40px;
    --space-12: 48px;
    --space-16: 64px;

    /* ── Type scale ───────────────────────────────────────────────────── */
    --font-sans: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --fs-2xs: 10px;
    --fs-xs: 11px;
    --fs-sm: 12px;
    --fs-base: 13px;
    --fs-md: 14px;
    --fs-lg: 16px;
    --fs-xl: 18px;
    --fs-2xl: 22px;
    --fs-3xl: 28px;
    --fs-4xl: 36px;
    --fw-regular: 400;
    --fw-medium: 500;
    --fw-semibold: 600;
    --fw-bold: 700;
    --fw-extrabold: 800;
    --lh-tight: 1.2;
    --lh-normal: 1.5;
    --lh-relaxed: 1.7;

    /* ── Radius scale ─────────────────────────────────────────────────── */
    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 10px;
    --radius-xl: 12px;
    --radius-2xl: 16px;
    --radius-pill: 999px;
    --radius-full: 50%;

    /* ── Shadow scale ─────────────────────────────────────────────────── */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.20);
    --shadow-md: 0 4px 14px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 8px 28px rgba(0, 0, 0, 0.32);
    --shadow-focus: 0 0 0 3px rgba(99, 102, 241, 0.45);

    /* ── Motion timing (WS7.1 — fast & tasteful 150–300ms) ───────────── */
    --motion-fast: 150ms;
    --motion-base: 220ms;
    --motion-slow: 300ms;
    --motion-ease: cubic-bezier(0.22, 1, 0.36, 1);    /* gentle ease-out */
    --motion-ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
    --motion-rise: 14px;   /* fade-and-rise travel distance */

    /* ── Semantic status colours (theme-agnostic, AA on dark/light) ──── */
    --status-success: #22c55e;
    --status-success-text: #34d399;
    --status-info: #3b82f6;
    --status-info-text: #60a5fa;
    --status-warn: #f59e0b;
    --status-warn-text: #fbbf24;
    --status-danger: #ef4444;
    --status-danger-text: #f87171;

    /* ── Skeleton loading shimmer ─────────────────────────────────────── */
    --skeleton-base: #1b2230;
    --skeleton-sheen: #222c3d;

    /* ── Elevation aliases (Phase 8D) ─────────────────────────────────── */
    --elevation-1: var(--shadow-sm);
    --elevation-2: var(--shadow-md);
    --elevation-3: var(--shadow-lg);

    /* ── Interaction state overlays (Phase 8D) ────────────────────────── */
    --state-hover-overlay: rgba(255, 255, 255, 0.04);   /* lighten on hover (dark) */
    --state-active-overlay: rgba(0, 0, 0, 0.22);        /* press feedback */
    --state-disabled-opacity: 0.5;
    --border-strong: var(--border-secondary);

    /* ── Canonical control geometry ───────────────────────────────────── */
    --control-h: 38px;               /* buttons / inputs default height */
    --control-h-sm: 30px;
    --control-radius: var(--radius-lg);
    --control-pad-x: var(--space-4);
}

[data-theme="light"] {
    /* Shared light palette (Phase 8D) — mirrors dashboard.css light theme. */
    --bg-primary: #eef2f8;
    --bg-secondary: #ffffff;
    --bg-tertiary: #f7f9fc;
    --bg-hover: #e6ebf2;
    --bg-input: #ffffff;
    --bg-elevated: #f4f7fb;
    --bg-deep: #eef2f8;
    --bg-overlay: #e0e7ff;
    --border-primary: #dfe6ef;
    --border-secondary: #cbd5e1;
    --border-subtle: #e6ebf2;
    --border-form: #cbd5e1;
    --text-primary: #1a1a2e;
    --text-secondary: #1e293b;
    --text-tertiary: #334155;
    --text-muted: #64748b;
    --text-faint: #94a3b8;
    --text-dim: #94a3b8;
    --accent-bg: #e0e7ff;
    --accent-bg-light: #eef2ff;
    --accent-text: #4338ca;
    --accent-text-light: #4f46e5;
    --accent-text-pale: #312e81;
    --accent-text-white: #4f46e5;
    --accent-glow: 0 6px 18px rgba(99, 102, 241, 0.22);
    --shadow-card: 0 4px 16px rgba(15,23,42,0.08), 0 1px 3px rgba(15,23,42,0.05);
    --info-bg: #eff6ff;
    --info-border: #60a5fa;
    --info-text: #1d4ed8;
    --toast-success-bg: #ecfdf5;
    --toast-success-border: #10b981;
    --toast-success-text: #065f46;
    --toast-error-bg: #fef2f2;
    --toast-error-border: #ef4444;
    --toast-error-text: #991b1b;
    --color-scheme: light;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 2px 8px rgba(15, 23, 42, 0.08), 0 1px 3px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 10px 30px rgba(15, 23, 42, 0.10);
    --shadow-focus: 0 0 0 3px rgba(99, 102, 241, 0.30);
    --skeleton-base: #e7ecf3;
    --skeleton-sheen: #f3f6fa;
    --state-hover-overlay: rgba(15, 23, 42, 0.04);      /* darken on hover (light) */
    --state-active-overlay: rgba(15, 23, 42, 0.08);
}

/* ============================================================================
 * Shared component primitives consumed across landing + dashboard (WS7.4)
 * ========================================================================== */

/* ── Accessible focus ring: visible keyboard focus everywhere ─────────── */
:where(a, button, input, select, textarea, [tabindex], .nav-item, .conv-filter-btn,
       .work-tab, .channel-toggle, .adr-btn):focus-visible {
    outline: none;
    box-shadow: var(--shadow-focus);
    border-radius: var(--radius-sm);
}
/* Don't show the ring on mouse click, only keyboard (focus-visible handles it) */

/* ── Loading skeletons ────────────────────────────────────────────────── */
.skeleton {
    position: relative;
    overflow: hidden;
    background: var(--skeleton-base);
    border-radius: var(--radius-sm);
}
.skeleton::after {
    content: '';
    position: absolute;
    inset: 0;
    transform: translateX(-100%);
    background: linear-gradient(90deg,
        transparent 0%,
        var(--skeleton-sheen) 50%,
        transparent 100%);
    animation: skeleton-shimmer 1.3s infinite;
}
.skeleton-line { height: 12px; margin: 6px 0; border-radius: var(--radius-xs); }
.skeleton-line.sk-lg { height: 28px; }
.skeleton-line.sk-sm { height: 9px; }
.skeleton-text-60 { width: 60%; }
.skeleton-text-40 { width: 40%; }
.skeleton-text-80 { width: 80%; }

@keyframes skeleton-shimmer {
    100% { transform: translateX(100%); }
}

/* ── Empty / error state blocks (shared) ──────────────────────────────── */
.state-block {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    text-align: center;
    padding: var(--space-8) var(--space-4);
    color: var(--text-faint);
}
.state-block .state-icon { font-size: 28px; opacity: 0.85; line-height: 1; }
.state-block .state-title { font-size: var(--fs-md); font-weight: var(--fw-semibold); color: var(--text-secondary); }
.state-block .state-desc { font-size: var(--fs-base); color: var(--text-faint); max-width: 320px; line-height: var(--lh-normal); }
.state-block.state-error .state-title { color: var(--status-danger-text); }
.state-block .state-retry {
    margin-top: var(--space-2);
    background: var(--bg-elevated);
    border: 1px solid var(--border-secondary);
    color: var(--text-secondary);
    padding: var(--space-2) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--fs-base);
    cursor: pointer;
    transition: border-color var(--motion-fast) var(--motion-ease), color var(--motion-fast) var(--motion-ease);
}
.state-block .state-retry:hover { border-color: var(--accent); color: var(--accent); }

/* ============================================================================
 * Animation primitives (WS7.1) — used by anim.js. CSS-only fallback so that
 * even before JS runs, content is visible (no FOUC / hidden-content risk).
 * anim.js adds [data-anim] hooks; these classes are applied/cleared by it.
 * ========================================================================== */

/* Element queued for entrance animation (set by anim.js BEFORE animating).
 * Guarded so it ONLY hides when JS is present AND motion is allowed. */
@media (prefers-reduced-motion: no-preference) {
    .js-anim [data-anim-pending] {
        opacity: 0;
        transform: translateY(var(--motion-rise));
    }
}

/* ============================================================================
 * Canonical component primitives (Phase 8D refresh)
 *
 * ADDITIVE + namespaced (.ui-*) so existing dashboard/admin classes are never
 * clobbered. These are the ONE canonical style per component; shared components
 * are migrated onto them in Phase 2. Every value is token-driven so both themes
 * and reduced-motion are covered automatically.
 * ========================================================================== */

/* Buttons ------------------------------------------------------------------ */
.ui-btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--space-2);
    height: var(--control-h); padding: 0 var(--space-5);
    font-family: var(--font-sans); font-size: var(--fs-md); font-weight: var(--fw-semibold);
    line-height: 1; border-radius: var(--control-radius); border: 1px solid transparent;
    cursor: pointer; white-space: nowrap; user-select: none;
    transition: transform var(--motion-fast) var(--motion-ease),
                box-shadow var(--motion-fast) var(--motion-ease),
                background var(--motion-fast) var(--motion-ease),
                border-color var(--motion-fast) var(--motion-ease),
                filter var(--motion-fast) var(--motion-ease);
}
.ui-btn:active { transform: translateY(1px); }
.ui-btn:disabled, .ui-btn[disabled] { opacity: var(--state-disabled-opacity); cursor: not-allowed; transform: none; }

.ui-btn--primary { background: var(--accent-gradient, var(--accent)); color: #fff; box-shadow: var(--accent-glow); }
.ui-btn--primary:hover { transform: translateY(-1px); filter: brightness(1.06); }
.ui-btn--secondary { background: var(--bg-elevated); color: var(--text-secondary); border-color: var(--border-secondary); }
.ui-btn--secondary:hover { border-color: var(--accent); color: var(--text-primary); background: var(--bg-hover); }
.ui-btn--danger { background: var(--status-danger); color: #fff; }
.ui-btn--danger:hover { transform: translateY(-1px); filter: brightness(1.08); }
.ui-btn--ghost { background: transparent; color: var(--text-muted); }
.ui-btn--ghost:hover { background: var(--state-hover-overlay); color: var(--text-primary); }
.ui-btn--sm { height: var(--control-h-sm); padding: 0 var(--space-3); font-size: var(--fs-sm); }

/* Inputs / selects / textareas -------------------------------------------- */
.ui-input, .ui-select, .ui-textarea {
    width: 100%; min-height: var(--control-h); padding: var(--space-2) var(--space-3);
    font-family: var(--font-sans); font-size: var(--fs-md); color: var(--text-primary);
    background: var(--bg-input); border: 1px solid var(--border-form);
    border-radius: var(--control-radius);
    transition: border-color var(--motion-fast) var(--motion-ease),
                box-shadow var(--motion-fast) var(--motion-ease);
}
.ui-textarea { min-height: 88px; resize: vertical; line-height: var(--lh-normal); }
.ui-input::placeholder, .ui-textarea::placeholder { color: var(--text-faint); }
.ui-input:focus, .ui-select:focus, .ui-textarea:focus {
    outline: none; border-color: var(--accent); box-shadow: var(--shadow-focus);
}

/* Cards / panels ----------------------------------------------------------- */
.ui-card {
    background: var(--bg-secondary); border: 1px solid var(--border-primary);
    border-radius: var(--radius-xl); padding: var(--space-6); box-shadow: var(--elevation-1);
    transition: transform var(--motion-fast) var(--motion-ease),
                box-shadow var(--motion-base) var(--motion-ease),
                border-color var(--motion-fast) var(--motion-ease);
}
.ui-card--interactive:hover { transform: translateY(-2px); box-shadow: var(--shadow-card); border-color: var(--border-secondary); }

/* Badges ------------------------------------------------------------------- */
.ui-badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 2px var(--space-2); font-size: var(--fs-2xs); font-weight: var(--fw-bold);
    letter-spacing: 0.03em; text-transform: uppercase; border-radius: var(--radius-pill);
    background: var(--accent-bg); color: var(--accent-text); border: 1px solid transparent;
}
.ui-badge--success { background: var(--toast-success-bg); color: var(--toast-success-text); }
.ui-badge--danger  { background: var(--toast-error-bg); color: var(--toast-error-text); }
.ui-badge--info    { background: var(--info-bg); color: var(--info-text); }

/* Tabs --------------------------------------------------------------------- */
.ui-tab {
    padding: var(--space-2) var(--space-4); font-size: var(--fs-md); font-weight: var(--fw-semibold);
    color: var(--text-muted); background: transparent; border: none;
    border-bottom: 2px solid transparent; cursor: pointer;
    transition: color var(--motion-fast) var(--motion-ease), border-color var(--motion-fast) var(--motion-ease);
}
.ui-tab:hover { color: var(--text-primary); }
.ui-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Tables ------------------------------------------------------------------- */
.ui-table { width: 100%; border-collapse: collapse; font-size: var(--fs-base); }
.ui-table th {
    text-align: left; padding: var(--space-3) var(--space-4); font-size: var(--fs-sm);
    font-weight: var(--fw-semibold); color: var(--text-muted); text-transform: uppercase;
    letter-spacing: 0.03em; border-bottom: 1px solid var(--border-primary);
}
.ui-table td { padding: var(--space-3) var(--space-4); border-bottom: 1px solid var(--border-subtle); color: var(--text-secondary); }
.ui-table tbody tr { transition: background var(--motion-fast) var(--motion-ease); }
.ui-table tbody tr:hover { background: var(--state-hover-overlay); }

/* Reduced motion: neutralise everything non-essential. */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.001ms !important;
        scroll-behavior: auto !important;
    }
    .skeleton::after { animation: none; }
    [data-anim-pending] { opacity: 1 !important; transform: none !important; }
}
