/* ============================================
   VoiceBoard — Apple iOS Design System v3
   Precision-crafted to match Apple HIG
   ============================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
    /* ── Organization Brand Colors (overridden per-org via inline styles) ── */
    --color-primary: #007AFF;
    --color-primary-hover: color-mix(in srgb, var(--color-primary) 82%, black);
    --color-primary-light: color-mix(in srgb, var(--color-primary) 12%, transparent);
    --color-primary-glass: color-mix(in srgb, var(--color-primary) 6%, transparent);

    --color-secondary: #5AC8FA;
    --color-secondary-hover: color-mix(in srgb, var(--color-secondary) 82%, black);
    --color-secondary-light: color-mix(in srgb, var(--color-secondary) 12%, transparent);
    --color-secondary-glass: color-mix(in srgb, var(--color-secondary) 6%, transparent);

    --color-accent: #BF5AF2;
    --color-accent-hover: color-mix(in srgb, var(--color-accent) 82%, black);
    --color-accent-light: color-mix(in srgb, var(--color-accent) 12%, transparent);
    --color-accent-glass: color-mix(in srgb, var(--color-accent) 6%, transparent);

    /* ── Brand Composites ── */
    --brand-stripe: linear-gradient(180deg, var(--color-primary), var(--color-secondary) 50%, var(--color-accent));
    --brand-stripe-h: linear-gradient(90deg, var(--color-primary), var(--color-secondary) 50%, var(--color-accent));
    --brand-glow: 0 0 24px -4px color-mix(in srgb, var(--color-primary) 30%, transparent);
    --brand-glow-accent: 0 0 20px -4px color-mix(in srgb, var(--color-accent) 25%, transparent);

    /* ── iOS 18 System Colors ── */
    --color-success: #34C759;
    --color-success-light: rgba(52, 199, 89, 0.12);
    --color-danger: #FF3B30;
    --color-danger-light: rgba(255, 59, 48, 0.12);
    --color-warning: #FF9500;
    --color-warning-light: rgba(255, 149, 0, 0.12);
    --color-info: #5AC8FA;
    --color-purple: #AF52DE;
    --color-pink: #FF2D55;
    --color-teal: #5AC8FA;
    --color-indigo: #5856D6;
    --color-orange: #FF9500;
    --color-mint: #00C7BE;
    --color-cyan: #32ADE6;

    /* ── Semantic Colors — Light Mode (iOS 18) ── */
    --color-background: #F2F2F7;
    --color-surface: #FFFFFF;
    --color-surface-elevated: #FFFFFF;
    --color-secondary-bg: #F2F2F7;
    --color-tertiary-bg: #E5E5EA;
    --color-text-primary: #000000;
    --color-text-secondary: #6C6C70;
    --color-text-tertiary: #AEAEB2;
    --color-text-quaternary: #C7C7CC;
    --color-border: rgba(60, 60, 67, 0.12);
    --color-border-strong: rgba(60, 60, 67, 0.20);
    --color-separator: rgba(60, 60, 67, 0.08);
    --color-fill: rgba(120, 120, 128, 0.12);
    --color-fill-secondary: rgba(120, 120, 128, 0.08);
    --color-fill-tertiary: rgba(120, 120, 128, 0.04);

    /* ── Sidebar ── */
    --sidebar-bg: #F7F7FA;
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 76px;

    /* ── Spacing (iOS 8pt grid) ── */
    --spacing-2xs: 2px;
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;
    --spacing-2xl: 48px;
    --spacing-3xl: 64px;

    /* ── Typography — SF Pro (Inter as web fallback) ── */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', 'Segoe UI', system-ui, sans-serif;
    --font-size-2xs: 11px;
    --font-size-xs: 12px;
    --font-size-sm: 13px;
    --font-size-base: 15px;
    --font-size-lg: 17px;
    --font-size-xl: 20px;
    --font-size-2xl: 24px;
    --font-size-3xl: 28px;
    --font-size-4xl: 34px;
    --font-weight-light: 300;
    --font-weight-regular: 400;
    --font-weight-medium: 500;
    --font-weight-semibold: 600;
    --font-weight-bold: 700;
    --font-weight-heavy: 800;

    /* ── iOS Shadows (subtle, layered) ── */
    --shadow-xs: 0 0.5px 1px rgba(0, 0, 0, 0.04);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06), 0 1px 3px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.10), 0 4px 12px rgba(0, 0, 0, 0.06);
    --shadow-float: 0 20px 60px rgba(0, 0, 0, 0.12), 0 8px 20px rgba(0, 0, 0, 0.08);

    /* ── iOS Border Radius ── */
    --radius-xs: 4px;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --radius-2xl: 24px;
    --radius-3xl: 32px;
    --radius-full: 9999px;
    --radius-continuous: 14px; /* iOS continuous corners */

    /* ── Transitions — iOS Spring Physics ── */
    --transition-fast: 0.2s cubic-bezier(0.25, 0.1, 0.25, 1);
    --transition-base: 0.3s cubic-bezier(0.25, 0.1, 0.25, 1);
    --transition-slow: 0.45s cubic-bezier(0.25, 0.1, 0.25, 1);
    --transition-spring: 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    --transition-ios: 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-bounce: 0.6s cubic-bezier(0.68, -0.55, 0.27, 1.55);

    /* ── iOS Vibrancy & Glass ── */
    --glass-bg: rgba(255, 255, 255, 0.75);
    --glass-bg-thick: rgba(255, 255, 255, 0.85);
    --glass-bg-thin: rgba(255, 255, 255, 0.45);
    --glass-border: rgba(255, 255, 255, 0.4);
    --glass-blur: 24px;
    --glass-blur-heavy: 40px;

    /* ── iOS Touch Targets ── */
    --touch-target-min: 44px;
}

/* ── Dark Mode — iOS 18 ── */
[data-theme="dark"] {
    --color-background: #000000;
    --color-surface: #1C1C1E;
    --color-surface-elevated: #2C2C2E;
    --color-secondary-bg: #1C1C1E;
    --color-tertiary-bg: #2C2C2E;
    --color-text-primary: #FFFFFF;
    --color-text-secondary: #98989D;
    --color-text-tertiary: #636366;
    --color-text-quaternary: #48484A;
    --color-border: rgba(255, 255, 255, 0.10);
    --color-border-strong: rgba(255, 255, 255, 0.18);
    --color-separator: rgba(255, 255, 255, 0.06);
    --color-fill: rgba(120, 120, 128, 0.24);
    --color-fill-secondary: rgba(120, 120, 128, 0.16);
    --color-fill-tertiary: rgba(120, 120, 128, 0.08);

    --sidebar-bg: #111113;

    --shadow-xs: 0 0.5px 1px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.10);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.35), 0 1px 2px rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.10);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.30), 0 1px 3px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.10);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.40), 0 2px 6px rgba(0, 0, 0, 0.30), inset 0 1px 0 rgba(255, 255, 255, 0.10);
    --shadow-xl: 0 16px 48px rgba(0, 0, 0, 0.50), 0 4px 12px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.10);
    --shadow-float: 0 20px 60px rgba(0, 0, 0, 0.55), 0 8px 20px rgba(0, 0, 0, 0.40), inset 0 1px 0 rgba(255, 255, 255, 0.10);

    --glass-bg: rgba(28, 28, 30, 0.60);
    --glass-bg-thick: rgba(28, 28, 30, 0.75);
    --glass-bg-thin: rgba(28, 28, 30, 0.35);
    --glass-border: rgba(255, 255, 255, 0.15);
}

/* ── Global Reset ── */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background-color: var(--color-background);
    background-image: var(--app-bg-image, none);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    color: var(--color-text-primary);
    line-height: 1.47;
    font-size: var(--font-size-base);
    overflow-x: hidden;
}

.app-layout {
    min-height: 100vh;
    min-height: 100dvh;
    background-color: var(--color-background);
    background-image: var(--app-bg-image, none);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    position: relative;
    z-index: 0;
}

/* Premium ambient glow — subtle in iOS style */
.app-layout::before {
    content: '';
    position: fixed;
    top: -30vh;
    right: -15vw;
    width: 50vw;
    height: 50vh;
    background: radial-gradient(circle, var(--color-primary-glass) 0%, transparent 65%);
    z-index: -1;
    pointer-events: none;
    opacity: 0.4;
}

.app-layout::after {
    content: '';
    position: fixed;
    bottom: -15vh;
    left: 5vw;
    width: 40vw;
    height: 40vh;
    background: radial-gradient(circle, var(--color-accent-glass) 0%, transparent 65%);
    z-index: -1;
    pointer-events: none;
    opacity: 0.3;
}

a {
    color: var(--color-primary);
    text-decoration: none;
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--color-primary-hover);
}

/* ── iOS-style Scrollbar ── */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--color-text-quaternary);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-tertiary);
}

/* Firefox scrollbar */
* {
    scrollbar-width: thin;
    scrollbar-color: var(--color-text-quaternary) transparent;
}

/* ── Selection uses high-contrast colors ── */
::selection {
    background: #007AFF;
    color: #ffffff;
}

/* Chat bubbles text selection (black box with white text for yellow/colored bubbles) */
.cd-bubble::selection,
.ai-chat-bubble::selection,
.message-bubble::selection,
.full-chat-bubble::selection,
.user-bubble::selection,
.user-bubble-full::selection {
    background: #000000 !important;
    color: #ffffff !important;
}

/* ── Focus visible for accessibility ── */
:focus-visible {
    outline: 3px solid var(--color-primary);
    outline-offset: 2px;
    border-radius: var(--radius-sm);
}

/* Invert black logo text to white in dark mode, preserve other colors */
[data-theme="dark"] .sidebar-logo img,
[data-theme="dark"] .theme-aware-logo {
    filter: invert(1) hue-rotate(180deg) contrast(1.2) brightness(1.2);
    mix-blend-mode: normal !important;
}

/* ── Reduced Motion ── */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* ── iOS Safe Area Support ── */
@supports (padding: env(safe-area-inset-bottom)) {
    body {
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }
}
