/**
 * TWC Core Design Tokens
 * TheWorkCompany Ecosystem — Shared Visual Language
 *
 * EVERY app and widget imports this file FIRST.
 * Partners override tokens via CSS custom properties or THEME_* config vars.
 * Canonical copy: _shared/design/twc_core.css. Site copies are byte-identical
 * (_shared/tools/design_lint.py checks them); products never redefine --twc-*
 * here or elsewhere except as aliases to their own --<project>-* tokens (ADR-DS04).
 *
 * Design principles (constitution §13):
 *   - Light theme by default. Warm off-white background. Near-black text.
 *   - Pastel-neutral palette. Mild accent pastels for CTAs and status only.
 *   - No gradients. Flat color only. No drop shadows on text.
 *   - Big fonts, not bold fonts. Hierarchy comes from SIZE, never WEIGHT.
 *     Body and headings share weight 400. Emphasis caps at 500. Never 600+.
 *   - Generous whitespace. Generous line-height (1.65 body, 1.2 heading).
 *   - Mobile-first, fluid responsive. Base styles target mobile.
 *   - Flat single-weight line icons (Lucide / Phosphor / Heroicons outline).
 */

/* ══════════════════════════════════════════════
   1. DESIGN TOKENS
   ══════════════════════════════════════════════ */

:root {
    /* ── Color: Base ── */
    --twc-bg:              #FAFAF8;
    --twc-surface:         #FFFFFF;
    --twc-surface-hover:   #F5F5F0;
    --twc-border:          #E8E6E1;
    --twc-divider:         #F0EEEA;

    /* ── Color: Text ── */
    --twc-text:            #1A1A1A;
    --twc-text-secondary:  #6B6B6B;
    --twc-text-muted:      #5A5A5A; /* 6.7:1 on --twc-bg (was #9B9B9B, 2.7:1) */
    --twc-text-inverse:    #FFFFFF;
    --twc-overlay:         rgba(0,0,0,0.3);

    /* ── Color: Accent Pastels ── */
    --twc-accent:          #5B8DEF;
    --twc-accent-hover:    #4A7DE0;
    --twc-accent-light:    #EBF1FD;
    --twc-success:         #6BC67E;
    --twc-success-light:   #EDF8F0;
    --twc-warning:         #E8C356;
    --twc-warning-light:   #FDF8E8;
    --twc-error:           #E07070;
    --twc-error-light:     #FDEDED;
    --twc-success-text:    #2D7A3F;
    --twc-warning-text:    #8A6D1B;
    --twc-error-text:      #A63D3D;
    --twc-highlight:       #C4B0F5;
    --twc-highlight-light: #F3EFFD;

    /* ── Focus ── */
    --twc-focus:           var(--twc-accent);
    --twc-focus-ring:      0 0 0 2px var(--twc-bg), 0 0 0 4px var(--twc-focus);

    /* ── Typography ── */
    /* Hierarchy comes from SIZE, not WEIGHT.
       Body and headings both use weight 400. Emphasis tops out at 500.
       --twc-font-weight-bold is an alias for 500 (do NOT exceed 500). */
    --twc-font:            "Inter", "Inter Fallback", system-ui, -apple-system, "Segoe UI", sans-serif;
    --twc-font-mono:       "JetBrains Mono", ui-monospace, "SF Mono", Menlo, monospace;
    --twc-font-display:    var(--twc-font);  /* logo fallback + display use: the one approved family */
    --twc-font-weight:        400;   /* body, headings, default */
    --twc-font-weight-medium: 500;   /* UI emphasis: buttons, labels, card titles */
    --twc-font-weight-bold:   500;   /* alias — kept for back-compat. Do not exceed 500. */

    /* ── Type Scale (fluid) ── bigger than typical defaults — "big fonts" by design */
    --twc-text-xs:    0.875rem; /* 13-14px — labels only */
    --twc-text-sm:    1rem;     /* 15-16px — supporting */
    --twc-text-base:  1.125rem;   /* 17-19px — body */
    --twc-text-lg:    1.5rem;     /* 20-24px — card titles */
    --twc-text-xl:    clamp(2rem, 1.75rem + 1vw, 2.5rem);           /* 24-32px — section heading */
    --twc-text-2xl:   clamp(2rem, 1.75rem + 1vw, 2.5rem);       /* 32-46px — page title */
    --twc-text-3xl:   clamp(2.75rem, 2.4rem + 1.4vw, 3.75rem);           /* 40-64px — hero headline */
    --twc-line-height:       1.55;   /* body — generous, breathable */
    --twc-line-height-tight: 1.2;    /* headings — large size carries it */

    /* ── Spacing Scale ── */
    --twc-space-1:  0.25rem;
    --twc-space-2:  0.5rem;
    --twc-space-3:  0.75rem;
    --twc-space-4:  1rem;
    --twc-space-6:  1.5rem;
    --twc-space-8:  2rem;
    --twc-space-12: 3rem;
    --twc-space-16: 4rem;
    --twc-space-24: 6rem;

    /* ── Layout ── */
    --twc-content-width:  1200px;
    --twc-narrow-width:   720px;
    --twc-header-height:  64px;
    --twc-sidebar-width:  260px;
    --twc-radius:         8px;
    --twc-radius-sm:      4px;
    --twc-radius-lg:      16px;
    --twc-radius-full:    9999px;

    /* ── Transitions ── */
    --twc-transition:      150ms ease;
    --twc-transition-slow: 300ms ease;

    /* ── Shadows (minimal) ── */
    --twc-shadow-sm:   0 1px 2px rgba(0,0,0,0.04);
    --twc-shadow:      0 1px 4px rgba(0,0,0,0.06);
    --twc-shadow-lg:   0 4px 12px rgba(0,0,0,0.08);

    /* ── Logo sizing ── */
    --twc-logo-sm:  32px;
    --twc-logo-md:  48px;
    --twc-logo-lg:  72px;
    --twc-logo-xl:  120px;
}


/* ══════════════════════════════════════════════
   1a. FONT FACES
   ══════════════════════════════════════════════ */
/* None. Inter is declared once, in type-system.css (load it before this file);
   monospace uses system fonts (ui-monospace etc.), nothing to download. */


/* ══════════════════════════════════════════════
   2. RESET & BASE
   ══════════════════════════════════════════════ */

*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 100%;
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}
@media (prefers-reduced-motion: reduce) {
    html { scroll-behavior: auto; }
}

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

img, video, svg { max-width: 100%; height: auto; display: block; }
a { color: var(--twc-accent); text-decoration: none; transition: color var(--twc-transition); }
a:hover { color: var(--twc-accent-hover); }

/* Focus: the ring is a box-shadow, so a transparent outline stays underneath for
   forced-colors mode, which drops box-shadow but repaints the outline. */
:focus-visible {
    outline: 2px solid transparent;
    outline-offset: 2px;
    box-shadow: var(--twc-focus-ring);
}
@media (forced-colors: active) {
    :focus-visible { outline: 2px solid CanvasText; }
}


/* ══════════════════════════════════════════════
   3. TYPOGRAPHY CLASSES
   ══════════════════════════════════════════════ */

.twc-hero-headline {
    font-size: var(--twc-text-3xl);
    font-weight: var(--weight-semibold, 600);
    line-height: var(--leading-display, 1.05);
    color: var(--twc-text);
    letter-spacing: var(--tracking-display, -0.02em);
}

.twc-page-title {
    font-size: var(--twc-text-2xl);
    font-weight: var(--weight-semibold, 600);
    line-height: var(--leading-title, 1.1);
    color: var(--twc-text);letter-spacing:var(--tracking-title, -0.015em);
}

.twc-section-heading {
    font-size: var(--twc-text-xl);
    font-weight: var(--weight-semibold, 600);
    line-height: var(--leading-title, 1.1);
    color: var(--twc-text);letter-spacing:var(--tracking-title, -0.015em);
}

.twc-card-title {
    font-size: var(--twc-text-lg);
    font-weight: var(--weight-medium, 500);
    line-height: var(--leading-heading, 1.2);
    color: var(--twc-text);letter-spacing:var(--tracking-heading, -0.01em);
}

.twc-body { font-size: var(--twc-text-base); }
.twc-supporting { font-size: var(--twc-text-sm); color: var(--twc-text-secondary); }
.twc-label {
    font-size: var(--font-size-caption, 0.75rem);
    font-weight: var(--weight-medium, 500);
    line-height: var(--leading-label, 1.3);
    text-transform: uppercase;
    letter-spacing: var(--tracking-caps, 0.06em);
    color: var(--twc-text-muted);
}

/* Reading width constraint for long-form text */
.twc-prose { max-width: var(--twc-narrow-width); }


/* ══════════════════════════════════════════════
   3a. LOGO — image with first-letter fallback
   ══════════════════════════════════════════════ */
/* Use logo_helper::app_logo_html() to render. The helper picks <img> if
   APP_LOGO is configured AND the file exists, otherwise the fallback below. */

.twc-logo,
.twc-logo-fallback {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--twc-logo-md);
    height: var(--twc-logo-md);
    border-radius: var(--twc-radius-full);
    flex-shrink: 0;
    overflow: hidden;
    line-height: 1;
}

.twc-logo img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.twc-logo-fallback {
    background: var(--twc-accent-light);
    color: var(--twc-accent);
    font-family: var(--twc-font-display);
    font-weight: var(--twc-font-weight-medium);
    font-size: calc(var(--twc-logo-md) * 0.5);
    text-transform: uppercase;
    user-select: none;
}

.twc-logo--sm,
.twc-logo--sm.twc-logo-fallback { width: var(--twc-logo-sm); height: var(--twc-logo-sm); }
.twc-logo--sm.twc-logo-fallback { font-size: calc(var(--twc-logo-sm) * 0.5); }

.twc-logo--lg,
.twc-logo--lg.twc-logo-fallback { width: var(--twc-logo-lg); height: var(--twc-logo-lg); }
.twc-logo--lg.twc-logo-fallback { font-size: calc(var(--twc-logo-lg) * 0.5); }

.twc-logo--xl,
.twc-logo--xl.twc-logo-fallback { width: var(--twc-logo-xl); height: var(--twc-logo-xl); }
.twc-logo--xl.twc-logo-fallback { font-size: calc(var(--twc-logo-xl) * 0.5); }


/* ══════════════════════════════════════════════
   4. LAYOUT PRIMITIVES
   ══════════════════════════════════════════════ */

.twc-layout {
    width: 100%;
    padding: var(--twc-space-4);
}

@media (min-width: 768px) {
    .twc-layout { padding: var(--twc-space-8); }
}

@media (min-width: 1024px) {
    .twc-layout {
        max-width: var(--twc-content-width);
        margin: 0 auto;
        padding: var(--twc-space-12);
    }
}

.twc-section {
    padding-top: var(--twc-space-12);
    padding-bottom: var(--twc-space-12);
}

@media (min-width: 768px) {
    .twc-section {
        padding-top: var(--twc-space-16);
        padding-bottom: var(--twc-space-16);
    }
}

@media (min-width: 1024px) {
    .twc-section {
        padding-top: var(--twc-space-24);
        padding-bottom: var(--twc-space-24);
    }
}

.twc-center { text-align: center; margin-left: auto; margin-right: auto; }


/* ══════════════════════════════════════════════
   5. COMPONENT CLASSES
   ══════════════════════════════════════════════ */

/* ── Card ── */
.twc-card {
    background: var(--twc-surface);
    border: 1px solid var(--twc-border);
    border-radius: var(--twc-radius);
    padding: var(--twc-space-6);
    box-shadow: var(--twc-shadow-sm);
    transition: box-shadow var(--twc-transition), border-color var(--twc-transition);
}

.twc-card:hover {
    box-shadow: var(--twc-shadow);
    border-color: var(--twc-accent-light);
}

/* ── Button: Primary ── */
.twc-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--twc-space-2);
    padding: var(--twc-space-3) var(--twc-space-6);
    font-family: var(--twc-font);
    font-size: var(--twc-text-base);
    font-weight: var(--weight-medium, 500);
    line-height: var(--leading-body, 1.55);
    color: var(--twc-text-inverse);
    background: var(--twc-accent);
    border: none;
    border-radius: var(--twc-radius);
    cursor: pointer;
    transition: background var(--twc-transition);
    min-height: 44px; /* WCAG touch target */
    min-width: 44px;
}

.twc-btn:hover { background: var(--twc-accent-hover); }

/* ── Button: Secondary ── */
.twc-btn-secondary {
    composes: twc-btn;
    color: var(--twc-text);
    background: var(--twc-surface);
    border: 1px solid var(--twc-border);
}

.twc-btn-secondary:hover {
    background: var(--twc-surface-hover);
    border-color: var(--twc-accent);
}

/* ── Button: Ghost ── */
.twc-btn-ghost {
    color: var(--twc-accent);
    background: transparent;
    border: none;
    padding: var(--twc-space-2) var(--twc-space-4);
    font-family: var(--twc-font);
    font-size: var(--twc-text-base);
    font-weight: var(--weight-medium, 500);
    cursor: pointer;
    transition: background var(--twc-transition);
    border-radius: var(--twc-radius-sm);
    min-height: 44px;
}

.twc-btn-ghost:hover { background: var(--twc-accent-light); }

/* ── Input ── */
.twc-input {
    width: 100%;
    padding: var(--twc-space-3) var(--twc-space-4);
    font-family: var(--twc-font);
    font-size: var(--twc-text-base);
    color: var(--twc-text);
    background: var(--twc-surface);
    border: 1px solid var(--twc-border);
    border-radius: var(--twc-radius-sm);
    transition: border-color var(--twc-transition);
    min-height: 44px;
}

.twc-input:focus {
    outline: 2px solid transparent;
    border-color: var(--twc-accent);
    box-shadow: 0 0 0 3px var(--twc-accent-light);
}

.twc-input::placeholder { color: var(--twc-text-muted); }

/* ── Badge / Tag ── */
.twc-badge {
    display: inline-block;
    padding: var(--twc-space-1) var(--twc-space-3);
    font-size: var(--twc-text-xs);
    font-weight: var(--weight-medium, 500);
    border-radius: var(--twc-radius-full);
    line-height: var(--leading-label, 1.3);
}

.twc-badge-accent  { background: var(--twc-accent-light);    color: var(--twc-accent); }
.twc-badge-success { background: var(--twc-success-light);   color: var(--twc-success-text); }
.twc-badge-warning { background: var(--twc-warning-light);   color: var(--twc-warning-text); }
.twc-badge-error   { background: var(--twc-error-light);     color: var(--twc-error-text); }

/* ── Divider ── */
.twc-divider {
    border: none;
    border-top: 1px solid var(--twc-divider);
    margin: var(--twc-space-8) 0;
}

/* ── Skeleton loading placeholder ── */
.twc-skeleton {
    background: linear-gradient(90deg, var(--twc-divider) 25%, var(--twc-surface-hover) 50%, var(--twc-divider) 75%);
    background-size: 200% 100%;
    animation: twc-shimmer 1.5s infinite;
    border-radius: var(--twc-radius-sm);
}

@keyframes twc-shimmer {
    0%   { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}


/* ══════════════════════════════════════════════
   6. NAVIGATION CHROME — HEADER & FOOTER
   ══════════════════════════════════════════════ */

/* ── Header ── */
.twc-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--twc-header-height);
    padding: 0 var(--twc-space-4);
    background: var(--twc-surface);
    border-bottom: 1px solid var(--twc-border);
}

.twc-header-left,
.twc-header-right {
    display: flex;
    align-items: center;
    gap: var(--twc-space-2);
}

.twc-header-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: none;
    background: transparent;
    color: var(--twc-text);
    border-radius: var(--twc-radius-sm);
    cursor: pointer;
    transition: background var(--twc-transition);
    font-size: var(--font-size-sub, 1.25rem);
    position: relative;line-height:var(--leading-sub, 1.3);
}

.twc-header-icon:hover { background: var(--twc-surface-hover); }

/* Notification badge dot */
.twc-header-icon[data-badge]::after {
    content: '';
    position: absolute;
    top: 10px;
    right: 10px;
    width: 8px;
    height: 8px;
    border-radius: var(--twc-radius-full);
    background: var(--twc-error);
    border: 2px solid var(--twc-surface);
}

/* ── Dropdown (desktop) ── */
.twc-dropdown {
    position: absolute;
    top: calc(var(--twc-header-height) - var(--twc-space-2));
    min-width: 240px;
    max-height: 400px;
    overflow-y: auto;
    background: var(--twc-surface);
    border: 1px solid var(--twc-border);
    border-radius: var(--twc-radius);
    box-shadow: var(--twc-shadow-lg);
    padding: var(--twc-space-2) 0;
    display: none;
    z-index: 1001;
}

.twc-dropdown.is-open { display: block; }

.twc-dropdown-left  { left: var(--twc-space-4); }
.twc-dropdown-right { right: var(--twc-space-4); }

.twc-dropdown-item {
    display: flex;
    align-items: center;
    gap: var(--twc-space-3);
    padding: var(--twc-space-3) var(--twc-space-4);
    font-size: var(--twc-text-sm);
    color: var(--twc-text);
    text-decoration: none;
    transition: background var(--twc-transition);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: var(--twc-font);
    min-height: 44px;
}

.twc-dropdown-item:hover { background: var(--twc-surface-hover); }

.twc-dropdown-divider {
    border: none;
    border-top: 1px solid var(--twc-divider);
    margin: var(--twc-space-2) 0;
}

/* ── Bottom Sheet (mobile dropdown replacement) ── */
.twc-bottomsheet {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 1002;
    background: var(--twc-surface);
    border-top-left-radius: var(--twc-radius-lg);
    border-top-right-radius: var(--twc-radius-lg);
    box-shadow: var(--twc-shadow-lg);
    padding: var(--twc-space-4) var(--twc-space-4) calc(var(--twc-space-4) + env(safe-area-inset-bottom, 0px));
    max-height: 70vh;
    overflow-y: auto;
}

.twc-bottomsheet.is-open { display: block; }

.twc-bottomsheet-handle {
    width: 36px;
    height: 4px;
    background: var(--twc-border);
    border-radius: var(--twc-radius-full);
    margin: 0 auto var(--twc-space-4);
}

.twc-bottomsheet-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1001;
    background: var(--twc-overlay);
}

.twc-bottomsheet-overlay.is-open { display: block; }

/* ── Footer: Desktop Left Strip ── */
.twc-footer-strip {
    position: fixed;
    top: var(--twc-header-height);
    left: 0;
    bottom: 0;
    width: 60px;
    display: none; /* hidden on mobile */
    flex-direction: column;
    align-items: center;
    gap: var(--twc-space-4);
    padding: var(--twc-space-6) var(--twc-space-2);
    background: var(--twc-surface);
    border-right: 1px solid var(--twc-border);
    z-index: 900;
}

@media (min-width: 1024px) {
    .twc-footer-strip { display: flex; }

    /* Offset main content when strip is visible */
    .twc-has-footer-strip {
        margin-left: 60px;
    }
}

.twc-footer-strip-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--twc-space-1);
    color: var(--twc-text-secondary);
    font-size: var(--twc-text-xs);
    text-decoration: none;
    padding: var(--twc-space-2);
    border-radius: var(--twc-radius-sm);
    transition: background var(--twc-transition), color var(--twc-transition);
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
}

.twc-footer-strip-icon:hover {
    background: var(--twc-surface-hover);
    color: var(--twc-text);
}

/* ── Footer: Mobile Bottom Bar ── */
.twc-footer-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(56px + env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    display: flex;
    align-items: center;
    justify-content: space-around;
    background: var(--twc-surface);
    border-top: 1px solid var(--twc-border);
    z-index: 900;
}

@media (min-width: 1024px) {
    .twc-footer-bar { display: none; }
}

.twc-footer-bar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--twc-space-1);
    color: var(--twc-text-secondary);
    font-size: var(--twc-text-xs);
    text-decoration: none;
    padding: var(--twc-space-2);
    min-width: 44px;
    min-height: 44px;
    justify-content: center;
}

.twc-footer-bar-item.is-active { color: var(--twc-accent); }

/* Body padding to prevent content hiding behind fixed chrome */
.twc-app-body {
    padding-top: var(--twc-header-height);
    padding-bottom: 56px; /* mobile footer bar */
}

@media (min-width: 1024px) {
    .twc-app-body {
        padding-bottom: 0; /* no bottom bar on desktop */
    }
}


/* ══════════════════════════════════════════════
   7. DEMO BANNER (repositioned above footer on mobile)
   ══════════════════════════════════════════════ */

.twc-demo-banner {
    position: fixed;
    bottom: 56px; /* sits above mobile footer bar */
    left: 0;
    right: 0;
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--twc-space-4);
    padding: var(--twc-space-3) var(--twc-space-4);
    background: var(--twc-highlight-light);
    border-top: 1px solid var(--twc-highlight);
    font-size: var(--twc-text-sm);
    color: var(--twc-text-secondary);
}

.twc-demo-banner a {
    font-weight: var(--twc-font-weight-medium);
    color: var(--twc-accent);
}

@media (min-width: 1024px) {
    .twc-demo-banner {
        bottom: 0; /* no footer bar on desktop */
        left: 60px; /* offset for left strip */
    }
}


/* ══════════════════════════════════════════════
   7. UTILITY CLASSES
   ══════════════════════════════════════════════ */

.twc-sr-only {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

.twc-truncate {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.twc-noindex { /* Reminder: also add <meta name="robots" content="noindex"> in HTML */ }
