/* ============================================================================
 * 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.
 * ========================================================================== */

/* ── Fonts: the same files ajenta.com.au ships (palette v2, 3 Nov 2026). Sora for
 *    headings and the wordmark, DM Sans for everything else; both variable fonts.
 *    Served from /fonts/, so the CSP needs nothing extra. ── */
@font-face { font-family: 'Sora'; src: url('/fonts/sora.woff2') format('woff2'); font-weight: 700 800; font-style: normal; font-display: swap; }
@font-face { font-family: 'DM Sans'; src: url('/fonts/dm-sans.woff2') format('woff2'); font-weight: 400 700; font-style: normal; font-display: swap; }

:root {
    --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%23b9bec7' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5'/%3E%3C/svg%3E");
    /* ── Shared colour palette (Phase 8D) — single source of truth for BOTH
     *    the user dashboard and the admin dashboard: ajenta.com.au's palette
     *    (owner, 27 Sep), ink and lime. dashboard.css redeclares these identically for back-compat;
     *    admin.html aliases its local names (--bg-page, --bg-card…) to these. ── */
    --bg-primary: #020d2f;
    --bg-secondary: #142342;
    --bg-tertiary: #071432;
    --bg-hover: #1a2b4d;
    --bg-input: #0a1736;
    --bg-elevated: #1a2b4d;
    --bg-deep: #0a1736;
    --bg-overlay: #020d2f;
    --border-primary: #22314f;
    --border-secondary: #2c3a56;
    --border-subtle: #1b2946;
    --border-form: #2c3a56;
    --text-primary: #ffffff;
    --text-secondary: #e8ecf3;
    --text-tertiary: #d2d7e2;
    --text-muted: #b9bec7;
    --text-faint: #9199a7;
    --text-dim: #6a7589;
    --cta: #c8ff43;
    --cta-hover: #b4eb2e;
    --on-cta: #020d2f;
    --accent: #2f2bb6;
    --accent-hover: #3d39d1;
    --accent-deep: #5b5ae0;
    --on-accent: #ffffff;
    --accent-bg: rgba(47, 43, 182, 0.45);
    --accent-bg-light: rgba(47, 43, 182, 0.22);
    --accent-text: #c8ff43;
    --accent-text-light: #d6ff70;
    --accent-text-pale: #eeffb8;
    --accent-text-white: #c8ff43;
    --secondary: #5b5ae0;
    --secondary-hover: #7a79ea;
    --on-secondary: #ffffff;
    --pink: #ffd2e1;
    --on-pink: #020d2f;
    --bubble-customer: #2c3a56;
    --bubble-ai: #ffd2e1;
    --on-bubble-ai: #020d2f;
    --voice-text: #ffd2e1;
    --live-dot: #c8ff43;
    --wordmark-dot: #c8ff43;
    --accent-gradient: linear-gradient(135deg, #2f2bb6 0%, #231f9a 100%);
    --accent-glow: 0 8px 22px rgba(0, 0, 0, 0.35);
    --shadow-card: 0 1px 2px rgba(0,0,0,0.35), 0 16px 40px rgba(0,0,0,0.35);
    --info-bg: #0f1f4a;
    --info-border: #2f2bb6;
    --info-text: #c7c6ff;
    --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: 'DM Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-display: 'Sora', 'DM Sans', -apple-system, BlinkMacSystemFont, 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(91, 90, 224, 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: 6px;    /* fade-and-rise travel distance (small: owner, 5 Nov 2026) */

    /* ── 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: #142342;
    --skeleton-sheen: #1a2b4d;

    /* ── 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: 40px;               /* buttons / inputs default height */
    --control-h-sm: 32px;
    --control-pad-x: 14px;           /* ONE horizontal padding for every field and button */
    --control-pad-y: 10px;
    --control-radius: var(--radius-lg);
    --control-pad-x: var(--space-4);
}

[data-theme="light"] {
    --select-chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12' fill='none' stroke='%2349556e' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M2.5 4.5 6 8l3.5-3.5'/%3E%3C/svg%3E");
    --bg-primary: #f8fafd;
    --bg-secondary: #ffffff;
    --bg-tertiary: #ffffff;
    --bg-hover: #f0f2f5;
    --bg-input: #ffffff;
    --bg-elevated: #f0f2f5;
    --bg-deep: #f0f2f5;
    --bg-overlay: #ffffff;
    --border-primary: #d2d7e2;
    --border-secondary: #b9bec7;
    --border-subtle: #e4e8ef;
    --border-form: #b9bec7;
    --text-primary: #020d2f;
    --text-secondary: #142342;
    --text-tertiary: #2c3a56;
    --text-muted: #49556e;
    --text-faint: #6a7589;
    --text-dim: #9199a7;
    --cta: #2f2bb6;
    --cta-hover: #231f9a;
    --on-cta: #ffffff;
    --accent: #2f2bb6;
    --accent-hover: #231f9a;
    --accent-deep: #231f9a;
    --on-accent: #ffffff;
    --accent-bg: #e9e9f8;
    --accent-bg-light: #f3f3fb;
    --accent-text: #2f2bb6;
    --accent-text-light: #231f9a;
    --accent-text-pale: #1a1780;
    --accent-text-white: #2f2bb6;
    --secondary: #2f2bb6;
    --secondary-hover: #231f9a;
    --on-secondary: #ffffff;
    --pink: #ffd2e1;
    --on-pink: #020d2f;
    --bubble-customer: #f0f2f5;
    --bubble-ai: #ffd2e1;
    --on-bubble-ai: #020d2f;
    --voice-text: #2f2bb6;
    --live-dot: #c8ff43;
    --wordmark-dot: #c8ff43;
    --accent-gradient: linear-gradient(135deg, #2f2bb6 0%, #231f9a 100%);
    --accent-glow: 0 6px 18px rgba(47, 43, 182, 0.22);
    --shadow-card: 0 4px 16px rgba(2,13,47,0.06), 0 1px 3px rgba(2,13,47,0.05);
    --info-bg: #ececfb;
    --info-border: #2f2bb6;
    --info-text: #231f9a;
    --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(47, 43, 182, 0.30);
    --skeleton-base: #e4e8ef;
    --skeleton-sheen: #f3f5f9;
    --state-hover-overlay: rgba(15, 23, 42, 0.04);      /* darken on hover (light) */
    --state-active-overlay: rgba(15, 23, 42, 0.08);
}

/* ── Form controls, the same everywhere (owner, 27 Sep): one chevron on
 *    single-choice selects, inset like the field's text; toggles in the accent. ── */
select:not([multiple]):not([size]) {
    -webkit-appearance: none; -moz-appearance: none; appearance: none;
    background-image: var(--select-chevron) !important;
    background-repeat: no-repeat !important;
    background-position: right 14px center !important;
    background-size: 12px 12px !important;
    padding-right: 38px !important;
}
input[type="checkbox"], input[type="radio"], input[type="range"] { accent-color: var(--accent-deep); }
/* Tick boxes and radios aren't text boxes (owner, 30 Sep), on every page:
   clicking one only ticks it. No field glow or square around it, and tapping
   its label highlights nothing; the keyboard gets a slim ring. */
input[type="checkbox"], input[type="radio"] { box-shadow: none; -webkit-tap-highlight-color: transparent; }
input[type="checkbox"]:focus, input[type="radio"]:focus { outline: none; box-shadow: none; }
input[type="checkbox"]:focus-visible, input[type="radio"]:focus-visible { outline: 2px solid var(--accent-deep); outline-offset: 2px; box-shadow: none; }
label:has(input[type="checkbox"]), label:has(input[type="radio"]) { -webkit-tap-highlight-color: transparent; user-select: none; }

/* ── The ajenta. wordmark: ajenta.com.au's mark, Sora 800 with a lime full stop
 *    on both themes (the mockups). ── */
.wordmark { font-family: var(--font-display); font-weight: 800; letter-spacing: -0.03em; color: var(--text-primary); line-height: 1; white-space: nowrap; }
.wordmark-dot { color: var(--wordmark-dot); }

/* ============================================================================
 * 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-deep); color: var(--accent-text); }

/* ============================================================================
 * 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; }

/* The one page action is the CTA colour: lime on navy, indigo on light (palette v2). */
.ui-btn--primary { background: var(--cta); color: var(--on-cta); box-shadow: var(--accent-glow); }
.ui-btn--primary:hover { transform: translateY(-1px); background: var(--cta-hover); }
/* Secondary buttons are outlines that turn indigo on hover: one loud button per section (design
   review, 2 Nov 2026) */
.ui-btn--secondary { background: transparent; color: var(--text-primary); border-color: var(--border-secondary); }
.ui-btn--secondary:hover { background: transparent; color: var(--accent-text); border-color: var(--secondary); }
.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-deep); 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); color: var(--on-accent); 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-text); 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; }
}
