/**
 * 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.
 *
 * 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:      #9B9B9B;
    --twc-text-inverse:    #FFFFFF;

    /* ── 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-highlight:       #C4B0F5;
    --twc-highlight-light: #F3EFFD;

    /* ── 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', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --twc-font-mono:       'JetBrains Mono', 'Fira Code', monospace;
    --twc-font-display:    'TaoFont', 'Inter', sans-serif;  /* logo fallback + display use */
    --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:    clamp(0.8125rem, 0.78rem + 0.2vw, 0.875rem); /* 13-14px — labels only */
    --twc-text-sm:    clamp(0.9375rem, 0.9rem + 0.25vw, 1rem);     /* 15-16px — supporting */
    --twc-text-base:  clamp(1.0625rem, 1rem + 0.3vw, 1.1875rem);   /* 17-19px — body */
    --twc-text-lg:    clamp(1.25rem, 1.15rem + 0.5vw, 1.5rem);     /* 20-24px — card titles */
    --twc-text-xl:    clamp(1.5rem, 1.3rem + 1vw, 2rem);           /* 24-32px — section heading */
    --twc-text-2xl:   clamp(2rem, 1.6rem + 1.8vw, 2.875rem);       /* 32-46px — page title */
    --twc-text-3xl:   clamp(2.5rem, 2rem + 2.5vw, 4rem);           /* 40-64px — hero headline */
    --twc-line-height:       1.65;   /* 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
   ══════════════════════════════════════════════ */
/* TaoFont — used for logo fallback (first letter when no APP_LOGO image exists)
   and any display/branding contexts. Place the file at cdn/fonts/taofont.ttf. */
@font-face {
    font-family: 'TaoFont';
    src: url('../fonts/taofont.ttf') format('truetype');
    font-weight: 400 500;
    font-style: normal;
    font-display: swap;
}

/* JetBrains Mono — used by --twc-font-mono. Two weights ship with the kit;
   browsers will pick the closest match. Without these declarations the
   token silently falls back to the system monospace. */
@font-face {
    font-family: 'JetBrains Mono';
    src: url('../fonts/JetBrainsMono-Regular.ttf') format('truetype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}
@font-face {
    font-family: 'JetBrains Mono';
    src: url('../fonts/JetBrainsMono-Medium.ttf') format('truetype');
    font-weight: 500;
    font-style: normal;
    font-display: swap;
}


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

body {
    font-family: var(--twc-font);
    font-size: var(--twc-text-base);
    font-weight: var(--twc-font-weight);
    line-height: var(--twc-line-height);
    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); }


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

.twc-hero-headline {
    font-size: var(--twc-text-3xl);
    font-weight: var(--twc-font-weight-bold);
    line-height: var(--twc-line-height-tight);
    color: var(--twc-text);
    letter-spacing: -0.02em;
}

.twc-page-title {
    font-size: var(--twc-text-2xl);
    font-weight: var(--twc-font-weight-bold);
    line-height: var(--twc-line-height-tight);
    color: var(--twc-text);
}

.twc-section-heading {
    font-size: var(--twc-text-xl);
    font-weight: var(--twc-font-weight-medium);
    line-height: var(--twc-line-height-tight);
    color: var(--twc-text);
}

.twc-card-title {
    font-size: var(--twc-text-lg);
    font-weight: var(--twc-font-weight-medium);
    line-height: var(--twc-line-height);
    color: var(--twc-text);
}

.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(--twc-text-xs);
    font-weight: var(--twc-font-weight-medium);
    line-height: var(--twc-line-height-tight);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    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(--twc-font-weight-medium);
    line-height: 1;
    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(--twc-font-weight-medium);
    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: none;
    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(--twc-font-weight-medium);
    border-radius: var(--twc-radius-full);
    line-height: var(--twc-line-height-tight);
}

.twc-badge-accent  { background: var(--twc-accent-light);    color: var(--twc-accent); }
.twc-badge-success { background: var(--twc-success-light);   color: #2D7A3F; }
.twc-badge-warning { background: var(--twc-warning-light);   color: #8A6D1B; }
.twc-badge-error   { background: var(--twc-error-light);     color: #A63D3D; }

/* ── 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: 1.25rem;
    position: relative;
}

.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: rgba(0,0,0,0.3);
}

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