/**
 * PA-Agent Dashboard - Apple HIG Design System
 * Inspired by Apple Human Interface Guidelines
 * Frosted glass, layered surfaces, SF Pro typography
 */

/* ========== CSS VARIABLES & THEME (Light Mode) ========== */
:root {
    /* ---- Apple System Colors ---- */
    --system-blue: #007AFF;
    --system-blue-dark: #0051D5;
    --system-blue-light: #409CFF;
    --system-green: #34C759;
    --system-green-dark: #248A3D;
    --system-red: #FF3B30;
    --system-red-dark: #D70015;
    --system-orange: #FF9500;
    --system-orange-dark: #C93400;
    --system-yellow: #FFCC00;
    --system-purple: #AF52DE;
    --system-purple-dark: #8944AB;
    --system-teal: #5AC8FA;
    --system-teal-dark: #0071A4;
    --system-indigo: #5856D6;
    --system-indigo-dark: #3634A3;
    --system-pink: #FF2D55;
    --system-mint: #00C7BE;

    /* ---- Apple Gray Scale ---- */
    --gray-1: #8E8E93;
    --gray-2: #AEAEB2;
    --gray-3: #C7C7CC;
    --gray-4: #D1D1D6;
    --gray-5: #E5E5EA;
    --gray-6: #F2F2F7;

    /* ---- Brand (maps to system-blue) ---- */
    --brand-primary: var(--system-blue);
    --brand-primary-dark: var(--system-blue-dark);
    --brand-primary-light: var(--system-blue-light);
    --brand-accent: var(--system-indigo);
    --brand-accent-light: #7B79E0;

    /* ---- Background Colors - Light Mode ---- */
    --bg-primary: #F2F2F7;           /* systemGroupedBackground */
    --bg-secondary: #FFFFFF;          /* secondarySystemGroupedBackground (card surface) */
    --bg-tertiary: #F2F2F7;          /* tertiarySystemGroupedBackground */
    --bg-elevated: #FFFFFF;           /* elevated surface */
    --bg-grouped: #F2F2F7;           /* grouped table background */

    /* ---- Text Colors - Light Mode ---- */
    --text-primary: #000000;          /* label */
    --text-secondary: #3C3C43;        /* secondaryLabel with opacity */
    --text-secondary-alpha: rgba(60, 60, 67, 0.6);
    --text-tertiary: #3C3C43;         /* tertiaryLabel with opacity */
    --text-tertiary-alpha: rgba(60, 60, 67, 0.3);
    --text-quaternary: rgba(60, 60, 67, 0.18);
    --text-inverse: #FFFFFF;
    --text-link: var(--system-blue);

    /* ---- Separator Colors ---- */
    --separator: rgba(60, 60, 67, 0.12);      /* separator */
    --separator-opaque: #C6C6C8;               /* opaqueSeparator */

    /* ---- Fill Colors ---- */
    --fill-primary: rgba(120, 120, 128, 0.2);
    --fill-secondary: rgba(120, 120, 128, 0.16);
    --fill-tertiary: rgba(120, 120, 128, 0.12);
    --fill-quaternary: rgba(120, 120, 128, 0.08);

    /* ---- Border Colors (minimal - prefer fills/separators) ---- */
    --border-primary: var(--separator);
    --border-secondary: var(--separator);
    --border-focus: var(--system-blue);

    /* ---- Semantic Colors ---- */
    --success: var(--system-green);
    --success-bg: rgba(52, 199, 89, 0.12);
    --success-border: rgba(52, 199, 89, 0.24);

    --warning: var(--system-orange);
    --warning-bg: rgba(255, 149, 0, 0.12);
    --warning-border: rgba(255, 149, 0, 0.24);

    --danger: var(--system-red);
    --danger-bg: rgba(255, 59, 48, 0.12);
    --danger-border: rgba(255, 59, 48, 0.24);

    --info: var(--system-blue);
    --info-bg: rgba(0, 122, 255, 0.12);
    --info-border: rgba(0, 122, 255, 0.24);

    /* ---- Shadows (Apple-subtle) ---- */
    --shadow-sm: 0 0 1px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 0 1px rgba(0, 0, 0, 0.06), 0 4px 16px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 0 2px rgba(0, 0, 0, 0.08), 0 8px 32px rgba(0, 0, 0, 0.08);
    --shadow-xl: 0 0 2px rgba(0, 0, 0, 0.1), 0 16px 48px rgba(0, 0, 0, 0.12);

    /* ---- Transitions (Apple spring-like curves) ---- */
    --apple-ease: cubic-bezier(0.25, 0.1, 0.25, 1);
    --apple-ease-in: cubic-bezier(0.42, 0, 1, 1);
    --apple-ease-out: cubic-bezier(0, 0, 0.58, 1);
    --apple-ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
    --transition-fast: 200ms var(--apple-ease);
    --transition-base: 280ms var(--apple-ease);
    --transition-slow: 350ms var(--apple-ease);
    --transition-spring: 500ms var(--apple-ease-spring);

    /* ---- Border Radius ---- */
    --radius-sm: 8px;
    --radius-md: 10px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-2xl: 20px;
    --radius-full: 9999px;

    /* ---- 8-Point Spacing Grid ---- */
    --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;

    /* ---- Typography ---- */
    --font-sans: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'SF Pro Text', system-ui, sans-serif;
    --font-mono: 'SF Mono', ui-monospace, Menlo, Monaco, Consolas, monospace;
    --font-rounded: 'SF Pro Rounded', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;

    /* Apple HIG Type Scale */
    --text-caption2: 11px;
    --text-caption1: 12px;
    --text-footnote: 13px;
    --text-subheadline: 15px;
    --text-body: 17px;
    --text-title3: 20px;
    --text-title2: 22px;
    --text-title1: 28px;
    --text-large-title: 34px;

    /* Mapped aliases for backward compat */
    --text-xs: var(--text-caption1);
    --text-sm: var(--text-footnote);
    --text-base: var(--text-subheadline);
    --text-lg: var(--text-body);
    --text-xl: var(--text-title3);
    --text-2xl: var(--text-title2);
    --text-3xl: var(--text-title1);
    --text-4xl: var(--text-large-title);

    /* Font Weights */
    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;

    /* ---- Z-index Scale ---- */
    --z-base: 0;
    --z-dropdown: 1000;
    --z-sticky: 1020;
    --z-fixed: 1030;
    --z-nav-bar: 1035;
    --z-modal-backdrop: 1040;
    --z-modal: 1050;
    --z-popover: 1060;
    --z-tooltip: 1070;
    --z-toast: 1080;
    --z-chat-fab: 1031;
    --z-chat-panel: 1045;

    /* ---- Frosted Glass ---- */
    --glass-bg: rgba(255, 255, 255, 0.72);
    --glass-bg-thick: rgba(255, 255, 255, 0.85);
    --glass-blur: blur(20px) saturate(180%);
    --glass-border: rgba(0, 0, 0, 0.06);

    /* ---- Layout ---- */
    --content-max-width: 1200px;
    --sidebar-width: 260px;
    --nav-height: 52px;
    --tab-bar-height: 50px;
}

/* ========== DARK MODE VARIABLES ========== */
/* Support both body.dark-mode (existing JS) and data-theme="dark" */
body.dark-mode,
[data-theme="dark"] {
    /* Apple Dark System Colors (shifted for dark backgrounds) */
    --system-blue: #0A84FF;
    --system-blue-dark: #409CFF;
    --system-blue-light: #0A84FF;
    --system-green: #30D158;
    --system-green-dark: #30DB5B;
    --system-red: #FF453A;
    --system-red-dark: #FF6961;
    --system-orange: #FF9F0A;
    --system-orange-dark: #FFB340;
    --system-yellow: #FFD60A;
    --system-purple: #BF5AF2;
    --system-purple-dark: #DA8FFF;
    --system-teal: #64D2FF;
    --system-teal-dark: #70D7FF;
    --system-indigo: #5E5CE6;
    --system-indigo-dark: #7D7AFF;
    --system-pink: #FF375F;
    --system-mint: #63E6E2;

    /* Dark Gray Scale */
    --gray-1: #8E8E93;
    --gray-2: #636366;
    --gray-3: #48484A;
    --gray-4: #3A3A3C;
    --gray-5: #2C2C2E;
    --gray-6: #1C1C1E;

    /* Dark Backgrounds (OLED-friendly pure black) */
    --bg-primary: #000000;
    --bg-secondary: #1C1C1E;
    --bg-tertiary: #2C2C2E;
    --bg-elevated: #1C1C1E;
    --bg-grouped: #000000;

    /* Dark Text */
    --text-primary: #FFFFFF;
    --text-secondary: #EBEBF5;
    --text-secondary-alpha: rgba(235, 235, 245, 0.6);
    --text-tertiary: #EBEBF5;
    --text-tertiary-alpha: rgba(235, 235, 245, 0.3);
    --text-quaternary: rgba(235, 235, 245, 0.18);
    --text-inverse: #000000;
    --text-link: #0A84FF;

    /* Dark Separators */
    --separator: rgba(84, 84, 88, 0.65);
    --separator-opaque: #38383A;

    /* Dark Fills */
    --fill-primary: rgba(120, 120, 128, 0.36);
    --fill-secondary: rgba(120, 120, 128, 0.32);
    --fill-tertiary: rgba(120, 120, 128, 0.24);
    --fill-quaternary: rgba(120, 120, 128, 0.18);

    /* Dark Borders */
    --border-primary: var(--separator);
    --border-secondary: var(--separator);

    /* Dark Semantic Colors */
    --success-bg: rgba(48, 209, 88, 0.16);
    --success-border: rgba(48, 209, 88, 0.32);
    --warning-bg: rgba(255, 159, 10, 0.16);
    --warning-border: rgba(255, 159, 10, 0.32);
    --danger-bg: rgba(255, 69, 58, 0.16);
    --danger-border: rgba(255, 69, 58, 0.32);
    --info-bg: rgba(10, 132, 255, 0.16);
    --info-border: rgba(10, 132, 255, 0.32);

    /* Dark Shadows */
    --shadow-sm: 0 0 1px rgba(0, 0, 0, 0.3), 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 0 1px rgba(0, 0, 0, 0.4), 0 4px 16px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 0 2px rgba(0, 0, 0, 0.5), 0 8px 32px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 0 2px rgba(0, 0, 0, 0.6), 0 16px 48px rgba(0, 0, 0, 0.4);

    /* Dark Frosted Glass */
    --glass-bg: rgba(28, 28, 30, 0.72);
    --glass-bg-thick: rgba(28, 28, 30, 0.85);
    --glass-border: rgba(255, 255, 255, 0.08);
}

/* prefers-color-scheme fallback (when no JS class is applied) */
@media (prefers-color-scheme: dark) {
    :root:not(.light-mode-forced) body:not(.light-mode) {
        --system-blue: #0A84FF;
        --system-green: #30D158;
        --system-red: #FF453A;
        --system-orange: #FF9F0A;
        --system-yellow: #FFD60A;
        --system-purple: #BF5AF2;
        --system-teal: #64D2FF;
        --system-indigo: #5E5CE6;

        --bg-primary: #000000;
        --bg-secondary: #1C1C1E;
        --bg-tertiary: #2C2C2E;
        --bg-elevated: #1C1C1E;

        --text-primary: #FFFFFF;
        --text-secondary: #EBEBF5;
        --text-secondary-alpha: rgba(235, 235, 245, 0.6);
        --text-tertiary-alpha: rgba(235, 235, 245, 0.3);
        --text-inverse: #000000;

        --separator: rgba(84, 84, 88, 0.65);
        --fill-primary: rgba(120, 120, 128, 0.36);
        --fill-secondary: rgba(120, 120, 128, 0.32);
        --fill-tertiary: rgba(120, 120, 128, 0.24);

        --glass-bg: rgba(28, 28, 30, 0.72);
        --glass-bg-thick: rgba(28, 28, 30, 0.85);
        --glass-border: rgba(255, 255, 255, 0.08);
    }
}


/* ========== RESET & BASE STYLES ========== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-text-size-adjust: 100%;
    text-rendering: optimizeLegibility;
}

body {
    font-family: var(--font-sans);
    font-size: var(--text-body);
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.47;  /* Apple default for body text */
    letter-spacing: -0.022em;
    transition: background-color var(--transition-base), color var(--transition-base);
    min-height: 100vh;
}

::selection {
    background: rgba(0, 122, 255, 0.25);
    color: inherit;
}


/* ========== TYPOGRAPHY ========== */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-primary);
    letter-spacing: -0.022em;
}

h1 {
    font-size: var(--text-large-title);
    font-weight: var(--font-bold);
    line-height: 1.12;
    letter-spacing: 0.011em;
}

h2 {
    font-size: var(--text-title1);
    font-weight: var(--font-bold);
    line-height: 1.14;
    letter-spacing: 0.013em;
}

h3 {
    font-size: var(--text-title2);
    font-weight: var(--font-bold);
    line-height: 1.18;
    letter-spacing: 0.016em;
}

h4 {
    font-size: var(--text-title3);
    font-weight: var(--font-semibold);
    line-height: 1.2;
    letter-spacing: 0.012em;
}

h5 {
    font-size: var(--text-body);
    font-weight: var(--font-semibold);
    line-height: 1.29;
}

h6 {
    font-size: var(--text-subheadline);
    font-weight: var(--font-semibold);
    line-height: 1.33;
}

p {
    margin-bottom: var(--space-4);
    line-height: 1.47;
}

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

a:hover {
    opacity: 0.72;
}

a:active {
    opacity: 0.56;
}

small, .text-footnote {
    font-size: var(--text-footnote);
    line-height: 1.38;
    letter-spacing: -0.008em;
}

.text-caption1 {
    font-size: var(--text-caption1);
    line-height: 1.33;
    letter-spacing: 0;
}

.text-caption2 {
    font-size: var(--text-caption2);
    line-height: 1.27;
    letter-spacing: 0.007em;
}

.text-subheadline {
    font-size: var(--text-subheadline);
    line-height: 1.33;
    letter-spacing: -0.016em;
}

.text-body {
    font-size: var(--text-body);
    line-height: 1.29;
    letter-spacing: -0.022em;
}

.text-large-title {
    font-size: var(--text-large-title);
    font-weight: var(--font-bold);
    line-height: 1.12;
    letter-spacing: 0.011em;
}


/* ========== LAYOUT ========== */
.container {
    max-width: var(--content-max-width);
    margin: 0 auto;
    padding: var(--space-10) var(--space-4);
}

.container-narrow {
    max-width: 900px;
    margin: 0 auto;
    padding: var(--space-10) var(--space-4);
}

.section {
    margin-bottom: var(--space-10);
}

.section-header {
    margin-bottom: var(--space-6);
}

.section-title {
    font-size: var(--text-title2);
    font-weight: var(--font-bold);
    color: var(--text-primary);
    margin-bottom: var(--space-1);
    letter-spacing: 0.016em;
}

.section-subtitle {
    font-size: var(--text-subheadline);
    color: var(--text-secondary-alpha);
    letter-spacing: -0.016em;
}

/* Page layout with sidebar (desktop) */
.page-layout {
    display: flex;
    min-height: 100vh;
}

.page-sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--glass-bg-thick);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-right: 0.5px solid var(--glass-border);
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: var(--z-sticky);
    overflow-y: auto;
    padding-top: var(--space-12);
}

.page-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding-top: var(--nav-height);
}


/* ========== NAVIGATION BAR (Frosted Glass) ========== */
.nav-bar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-bottom: 0.5px solid var(--glass-border);
    position: sticky;
    top: 0;
    z-index: var(--z-nav-bar);
    min-height: var(--nav-height);
    flex-wrap: wrap;
}

.nav-bar a {
    font-size: var(--text-subheadline);
    font-weight: var(--font-medium);
    color: var(--text-link);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    transition: background var(--transition-fast), opacity var(--transition-fast);
}

.nav-bar a:hover {
    background: var(--fill-tertiary);
    opacity: 1;
}

.nav-bar a.active {
    background: var(--system-blue);
    color: var(--text-inverse);
    font-weight: var(--font-semibold);
}

.nav-title {
    font-size: var(--text-body);
    font-weight: var(--font-semibold);
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
    white-space: nowrap;
}

.nav-spacer {
    flex: 1;
}


/* ========== CARDS ========== */
.card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--space-6);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition-base), transform var(--transition-base);
    /* No visible border - relies on background layering */
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-clickable {
    cursor: pointer;
}

.card-clickable:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-lg);
}

.card-clickable:active {
    transform: scale(0.98);
    box-shadow: var(--shadow-sm);
    transition: transform 100ms var(--apple-ease);
}

.card-header {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    padding-bottom: var(--space-3);
    border-bottom: 0.5px solid var(--separator);
}

.card-title {
    font-size: var(--text-body);
    font-weight: var(--font-semibold);
    flex: 1;
}

.card-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-title3);
    flex-shrink: 0;
    background: var(--fill-quaternary);
}

/* Large card variant */
.card-large {
    border-radius: var(--radius-xl);
    padding: var(--space-8);
}

/* Inset grouped card (like iOS Settings sections) */
.card-grouped {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: none;
    overflow: hidden;
    padding: 0;
}


/* ========== BUTTONS ========== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    font-family: var(--font-sans);
    font-size: var(--text-subheadline);
    font-weight: var(--font-semibold);
    line-height: 1.33;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: opacity var(--transition-fast), transform 100ms var(--apple-ease);
    text-decoration: none;
    -webkit-user-select: none;
    user-select: none;
    white-space: nowrap;
    min-height: 36px;
}

.btn:active {
    transform: scale(0.97);
}

/* Primary - Filled blue */
.btn-primary {
    background: var(--system-blue);
    color: #FFFFFF;
}

.btn-primary:hover {
    opacity: 0.85;
    color: #FFFFFF;
}

/* Secondary - Gray fill */
.btn-secondary {
    background: var(--fill-secondary);
    color: var(--text-primary);
}

.btn-secondary:hover {
    opacity: 0.85;
}

/* Destructive - Red */
.btn-danger,
.btn-destructive {
    background: var(--system-red);
    color: #FFFFFF;
}

.btn-danger:hover,
.btn-destructive:hover {
    opacity: 0.85;
    color: #FFFFFF;
}

/* Ghost / Text - Just blue text */
.btn-ghost,
.btn-text {
    background: transparent;
    color: var(--system-blue);
    padding: var(--space-2) var(--space-3);
}

.btn-ghost:hover,
.btn-text:hover {
    background: var(--fill-quaternary);
}

/* Tinted button (light blue bg, blue text) */
.btn-tinted {
    background: rgba(0, 122, 255, 0.12);
    color: var(--system-blue);
}

.btn-tinted:hover {
    background: rgba(0, 122, 255, 0.18);
}

/* Button sizes */
.btn-sm {
    font-size: var(--text-footnote);
    padding: var(--space-1) var(--space-3);
    min-height: 28px;
    border-radius: 6px;
}

.btn-lg {
    font-size: var(--text-body);
    padding: var(--space-3) var(--space-6);
    min-height: 44px;
    border-radius: var(--radius-md);
}

.btn-block {
    display: flex;
    width: 100%;
}

.btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    transform: none;
}

/* Icon-only button */
.btn-icon {
    width: 36px;
    height: 36px;
    padding: 0;
    border-radius: var(--radius-full);
    background: var(--fill-tertiary);
    color: var(--text-secondary-alpha);
    font-size: var(--text-body);
}

.btn-icon:hover {
    background: var(--fill-secondary);
    color: var(--text-primary);
}


/* ========== SEGMENTED CONTROL ========== */
.segmented-control {
    display: inline-flex;
    background: var(--fill-tertiary);
    border-radius: var(--radius-sm);
    padding: 2px;
    gap: 0;
    position: relative;
}

.segmented-control-item {
    position: relative;
    z-index: 1;
    padding: var(--space-1) var(--space-4);
    font-family: var(--font-sans);
    font-size: var(--text-footnote);
    font-weight: var(--font-medium);
    color: var(--text-primary);
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: color var(--transition-fast);
    min-height: 28px;
    white-space: nowrap;
    -webkit-user-select: none;
    user-select: none;
}

.segmented-control-item:hover {
    color: var(--text-primary);
}

.segmented-control-item.active {
    background: var(--bg-secondary);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    font-weight: var(--font-semibold);
}

body.dark-mode .segmented-control-item.active,
[data-theme="dark"] .segmented-control-item.active {
    background: var(--gray-4);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.24);
}


/* ========== BADGES & PILLS ========== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: 2px var(--space-2);
    font-size: var(--text-caption2);
    font-weight: var(--font-medium);
    border-radius: var(--radius-full);
    line-height: 1.27;
    letter-spacing: 0;
    white-space: nowrap;
}

.badge-success {
    background: var(--success-bg);
    color: var(--system-green);
}

.badge-warning {
    background: var(--warning-bg);
    color: var(--system-orange);
}

.badge-danger {
    background: var(--danger-bg);
    color: var(--system-red);
}

.badge-info {
    background: var(--info-bg);
    color: var(--system-blue);
}

.badge-neutral {
    background: var(--fill-tertiary);
    color: var(--text-secondary-alpha);
}

.badge-purple {
    background: rgba(175, 82, 222, 0.12);
    color: var(--system-purple);
}

/* Numeric badge (notification count) */
.badge-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: var(--radius-full);
    background: var(--system-red);
    color: #FFFFFF;
    font-size: var(--text-caption2);
    font-weight: var(--font-bold);
    line-height: 1;
}

/* Dot indicator */
.badge-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    display: inline-block;
    flex-shrink: 0;
}

.badge-dot-success { background: var(--system-green); }
.badge-dot-warning { background: var(--system-orange); }
.badge-dot-danger { background: var(--system-red); }
.badge-dot-info { background: var(--system-blue); }
.badge-dot-neutral { background: var(--gray-2); }


/* ========== STATS & METRICS ========== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--space-4);
    margin-bottom: var(--space-8);
}

.stat-card {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.stat-icon {
    font-size: var(--text-title2);
    margin-bottom: var(--space-3);
    opacity: 0.8;
}

.stat-value {
    font-size: var(--text-large-title);
    font-weight: var(--font-bold);
    line-height: 1;
    margin-bottom: var(--space-1);
    letter-spacing: -0.02em;
}

.stat-label {
    font-size: var(--text-footnote);
    font-weight: var(--font-medium);
    color: var(--text-secondary-alpha);
    letter-spacing: -0.008em;
}

.stat-change {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: var(--text-caption1);
    font-weight: var(--font-semibold);
    margin-top: var(--space-2);
}

.stat-change-positive { color: var(--system-green); }
.stat-change-negative { color: var(--system-red); }


/* ========== THEME TOGGLE ========== */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    background: var(--fill-tertiary);
    color: var(--text-primary);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-full);
    cursor: pointer;
    font-size: var(--text-footnote);
    font-weight: var(--font-medium);
    border: none;
    transition: background var(--transition-fast), opacity var(--transition-fast);
    -webkit-user-select: none;
    user-select: none;
}

.theme-toggle:hover {
    background: var(--fill-secondary);
}

.theme-toggle:active {
    opacity: 0.72;
}


/* ========== TABLES & LISTS (iOS Inset Grouped Style) ========== */
.table-container {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.table {
    width: 100%;
    border-collapse: collapse;
}

.table th {
    background: transparent;
    padding: var(--space-2) var(--space-4);
    text-align: left;
    font-size: var(--text-caption1);
    font-weight: var(--font-semibold);
    color: var(--text-secondary-alpha);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    border-bottom: 0.5px solid var(--separator);
}

.table td {
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-subheadline);
    border-bottom: 0.5px solid var(--separator);
}

/* Left-inset separator (like iOS Settings) */
.table.table-inset td {
    border-bottom: none;
    position: relative;
}

.table.table-inset td::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: var(--space-4);
    right: 0;
    height: 0.5px;
    background: var(--separator);
}

.table.table-inset tr:last-child td::after {
    display: none;
}

.table tbody tr {
    transition: background var(--transition-fast);
}

.table tbody tr:hover {
    background: var(--fill-quaternary);
}

.table tbody tr:active {
    background: var(--fill-tertiary);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

/* List Container (iOS Settings style) */
.list-container {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-sm);
}

.list-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    min-height: 44px;  /* Apple minimum touch target */
    position: relative;
    transition: background 60ms var(--apple-ease);
}

/* Left-inset separator */
.list-item::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: var(--space-4);
    right: 0;
    height: 0.5px;
    background: var(--separator);
}

.list-item:last-child::after {
    display: none;
}

.list-item:hover {
    background: var(--fill-quaternary);
}

.list-item:active {
    background: var(--fill-tertiary);
}

.list-item-clickable {
    cursor: pointer;
}

/* Disclosure indicator (chevron) */
.list-item-disclosure::before {
    content: '';
    position: absolute;
    right: var(--space-4);
    top: 50%;
    transform: translateY(-50%) rotate(45deg);
    width: 8px;
    height: 8px;
    border-top: 2px solid var(--gray-3);
    border-right: 2px solid var(--gray-3);
}

/* List section header */
.list-section-header {
    font-size: var(--text-footnote);
    font-weight: var(--font-normal);
    color: var(--text-secondary-alpha);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    padding: var(--space-6) var(--space-4) var(--space-2);
}

.list-section-header:first-child {
    padding-top: var(--space-8);
}

/* List section footer/caption */
.list-section-footer {
    font-size: var(--text-footnote);
    color: var(--text-secondary-alpha);
    padding: var(--space-2) var(--space-4) var(--space-4);
    line-height: 1.38;
}


/* ========== FORM INPUTS ========== */
.form-label {
    display: block;
    font-size: var(--text-subheadline);
    font-weight: var(--font-normal);
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.form-input,
.form-textarea,
.form-select {
    width: 100%;
    padding: var(--space-2) var(--space-3);
    font-family: var(--font-sans);
    font-size: var(--text-body);
    color: var(--text-primary);
    background: var(--fill-quaternary);
    border: none;
    border-radius: var(--radius-md);
    outline: none;
    min-height: 36px;
    transition: background var(--transition-fast), box-shadow var(--transition-fast);
    -webkit-appearance: none;
    appearance: none;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    background: var(--bg-secondary);
    box-shadow: 0 0 0 3.5px rgba(0, 122, 255, 0.3);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--text-tertiary-alpha);
}

.form-textarea {
    resize: vertical;
    min-height: 80px;
    line-height: 1.47;
}

.form-select {
    padding-right: var(--space-8);
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath d='M2.5 4.5L6 8L9.5 4.5' fill='none' stroke='%238E8E93' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    cursor: pointer;
}

/* Inline form (label and input side by side, like iOS Settings) */
.form-row-inline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);
    padding: var(--space-3) var(--space-4);
    min-height: 44px;
}

.form-row-inline .form-label {
    margin-bottom: 0;
    flex-shrink: 0;
}

.form-row-inline .form-input,
.form-row-inline .form-select {
    width: auto;
    min-width: 120px;
    text-align: right;
}

/* Form group */
.form-group {
    margin-bottom: var(--space-4);
}

.form-help {
    font-size: var(--text-footnote);
    color: var(--text-secondary-alpha);
    margin-top: var(--space-1);
}

.form-error {
    font-size: var(--text-footnote);
    color: var(--system-red);
    margin-top: var(--space-1);
}


/* ========== TOGGLE SWITCH (iOS Style) ========== */
.toggle-switch {
    position: relative;
    width: 51px;
    height: 31px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--fill-secondary);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: background 200ms var(--apple-ease);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    height: 27px;
    width: 27px;
    left: 2px;
    bottom: 2px;
    background: #FFFFFF;
    border-radius: var(--radius-full);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15), 0 0 1px rgba(0, 0, 0, 0.1);
    transition: transform 200ms var(--apple-ease-spring);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--system-green);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

.toggle-switch input:focus-visible + .toggle-slider {
    box-shadow: 0 0 0 3.5px rgba(0, 122, 255, 0.3);
}

/* Small toggle variant */
.toggle-switch-sm {
    width: 39px;
    height: 24px;
}

.toggle-switch-sm .toggle-slider::before {
    height: 20px;
    width: 20px;
}

.toggle-switch-sm input:checked + .toggle-slider::before {
    transform: translateX(15px);
}


/* ========== GRID LAYOUTS ========== */
.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-4);
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-4);
}

.grid-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-4);
}

@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .grid-2, .grid-3, .grid-4 {
        grid-template-columns: 1fr;
    }
}


/* ========== EMPTY STATES ========== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: var(--space-16) var(--space-6);
    color: var(--text-secondary-alpha);
}

.empty-state-icon {
    font-size: 56px;
    margin-bottom: var(--space-4);
    opacity: 0.4;
}

.empty-state-title {
    font-size: var(--text-title3);
    font-weight: var(--font-semibold);
    color: var(--text-primary);
    margin-bottom: var(--space-2);
}

.empty-state-message {
    font-size: var(--text-subheadline);
    color: var(--text-secondary-alpha);
    max-width: 320px;
    line-height: 1.47;
}

.empty-state-action {
    margin-top: var(--space-6);
}


/* ========== LOADING SKELETONS ========== */
.loading-skeleton {
    background: linear-gradient(
        90deg,
        var(--fill-quaternary) 0%,
        var(--fill-tertiary) 40%,
        var(--fill-quaternary) 80%
    );
    background-size: 300% 100%;
    animation: skeleton-shimmer 1.8s ease-in-out infinite;
    border-radius: var(--radius-sm);
}

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

.skeleton-text {
    height: 14px;
    margin-bottom: var(--space-2);
    border-radius: 4px;
}

.skeleton-text:last-child {
    width: 60%;
}

.skeleton-heading {
    height: 22px;
    width: 50%;
    margin-bottom: var(--space-3);
    border-radius: 4px;
}

.skeleton-avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
}

.skeleton-card {
    height: 120px;
    border-radius: var(--radius-lg);
}


/* ========== TOAST NOTIFICATIONS ========== */
.toast-container {
    position: fixed;
    top: calc(var(--nav-height) + var(--space-4));
    left: 50%;
    transform: translateX(-50%);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-2);
    pointer-events: none;
    width: 100%;
    max-width: 400px;
    padding: 0 var(--space-4);
}

.toast {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    background: var(--glass-bg-thick);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    color: var(--text-primary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    font-size: var(--text-subheadline);
    font-weight: var(--font-medium);
    pointer-events: auto;
    animation: toast-slide-down 350ms var(--apple-ease-spring);
    max-width: 100%;
}

.toast.toast-success {
    color: var(--system-green);
}

.toast.toast-success::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--system-green);
    flex-shrink: 0;
}

.toast.toast-error {
    color: var(--system-red);
}

.toast.toast-error::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--system-red);
    flex-shrink: 0;
}

.toast.toast-info::before {
    content: '';
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    background: var(--system-blue);
    flex-shrink: 0;
}

@keyframes toast-slide-down {
    from {
        opacity: 0;
        transform: translateY(-16px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes toast-out {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    to {
        opacity: 0;
        transform: translateY(-16px) scale(0.95);
    }
}


/* ========== MODALS (Sheet Style) ========== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: var(--z-modal-backdrop);
    display: none;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal-overlay.open {
    display: flex;
    animation: modal-backdrop-in 200ms var(--apple-ease);
}

@keyframes modal-backdrop-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-container {
    background: var(--bg-secondary);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 440px;
    max-height: 85vh;
    overflow-y: auto;
    z-index: var(--z-modal);
    animation: modal-sheet-in 350ms var(--apple-ease-spring);
}

@keyframes modal-sheet-in {
    from {
        opacity: 0;
        transform: scale(0.96) translateY(20px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-4) var(--space-5);
    border-bottom: 0.5px solid var(--separator);
}

.modal-header h3 {
    font-size: var(--text-body);
    font-weight: var(--font-semibold);
}

.modal-close {
    background: var(--fill-tertiary);
    border: none;
    width: 30px;
    height: 30px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-subheadline);
    color: var(--text-secondary-alpha);
    cursor: pointer;
    transition: background var(--transition-fast);
    line-height: 1;
}

.modal-close:hover {
    background: var(--fill-secondary);
    color: var(--text-primary);
}

.modal-body {
    padding: var(--space-5);
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-3);
    padding: var(--space-4) var(--space-5);
    border-top: 0.5px solid var(--separator);
}

/* Mobile: slide-up sheet */
@media (max-width: 768px) {
    .modal-overlay {
        align-items: flex-end;
    }

    .modal-container {
        max-width: 100%;
        max-height: 90vh;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        animation: modal-sheet-up 350ms var(--apple-ease-spring);
    }

    @keyframes modal-sheet-up {
        from {
            opacity: 0;
            transform: translateY(100%);
        }
        to {
            opacity: 1;
            transform: translateY(0);
        }
    }

    /* Sheet drag handle */
    .modal-header::before {
        content: '';
        position: absolute;
        top: var(--space-2);
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 5px;
        background: var(--fill-secondary);
        border-radius: var(--radius-full);
    }

    .modal-header {
        position: relative;
        padding-top: var(--space-6);
    }
}


/* ========== GLOBAL SEARCH ========== */
.nav-search-wrapper {
    position: relative;
    margin-left: auto;
}

.nav-search-input {
    width: 200px;
    padding: var(--space-2) var(--space-3);
    padding-left: 32px;
    font-family: var(--font-sans);
    font-size: var(--text-footnote);
    background: var(--fill-tertiary);
    color: var(--text-primary);
    border: none;
    border-radius: var(--radius-sm);
    outline: none;
    transition: width var(--transition-base), background var(--transition-fast), box-shadow var(--transition-fast);
}

.nav-search-input::placeholder {
    color: var(--text-tertiary-alpha);
}

.nav-search-input:focus {
    width: 260px;
    background: var(--bg-secondary);
    box-shadow: 0 0 0 3.5px rgba(0, 122, 255, 0.3);
}

.nav-search-icon {
    position: absolute;
    left: 10px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--gray-1);
    font-size: 14px;
    pointer-events: none;
    line-height: 1;
}

.search-dropdown {
    position: absolute;
    top: calc(100% + var(--space-2));
    left: 0;
    width: 380px;
    max-height: 480px;
    overflow-y: auto;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    z-index: var(--z-dropdown);
    display: none;
    animation: dropdown-in 200ms var(--apple-ease);
}

.search-dropdown.open {
    display: block;
}

@keyframes dropdown-in {
    from {
        opacity: 0;
        transform: translateY(-4px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.search-group-title {
    font-size: var(--text-caption1);
    font-weight: var(--font-semibold);
    color: var(--text-secondary-alpha);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    padding: var(--space-3) var(--space-4) var(--space-1);
}

.search-result-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-4);
    cursor: pointer;
    transition: background 60ms var(--apple-ease);
    text-decoration: none;
    color: var(--text-primary);
    min-height: 36px;
}

.search-result-item:hover {
    background: var(--fill-quaternary);
}

.search-result-item:active {
    background: var(--fill-tertiary);
}

.search-result-title {
    flex: 1;
    font-size: var(--text-subheadline);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.search-result-badge {
    font-size: var(--text-caption2);
    font-weight: var(--font-medium);
    padding: 2px var(--space-2);
    border-radius: var(--radius-full);
    background: var(--fill-tertiary);
    color: var(--text-secondary-alpha);
    flex-shrink: 0;
}

.search-no-results {
    padding: var(--space-8) var(--space-4);
    text-align: center;
    color: var(--text-tertiary-alpha);
    font-size: var(--text-subheadline);
}


/* ========== SYNC STATUS INDICATORS ========== */
.sync-status-bar {
    display: inline-flex;
    align-items: center;
    gap: var(--space-4);
    margin-left: var(--space-4);
}

.sync-indicator {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    cursor: pointer;
    font-size: var(--text-caption1);
    color: var(--text-secondary-alpha);
    font-weight: var(--font-medium);
}

.sync-dot {
    width: 8px;
    height: 8px;
    border-radius: var(--radius-full);
    flex-shrink: 0;
}

.sync-dot.success { background: var(--system-green); }
.sync-dot.idle_listening { background: var(--system-green); }
.sync-dot.syncing { background: var(--system-orange); animation: sync-pulse 1.2s ease-in-out infinite; }
.sync-dot.error { background: var(--system-red); }
.sync-dot.idle { background: var(--gray-2); }

@keyframes sync-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.sync-popover {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    width: 260px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    z-index: var(--z-popover);
    padding: var(--space-3) var(--space-4);
    font-size: var(--text-caption1);
    color: var(--text-primary);
    line-height: 1.6;
    animation: popover-in 200ms var(--apple-ease);
}

.sync-popover.open {
    display: block;
}

@keyframes popover-in {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(-4px) scale(0.96);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0) scale(1);
    }
}

.sync-popover-row {
    display: flex;
    justify-content: space-between;
    padding: 2px 0;
}

.sync-popover-label {
    color: var(--text-secondary-alpha);
}

.sync-popover-value {
    font-weight: var(--font-semibold);
}

.sync-popover-error {
    margin-top: var(--space-2);
    padding: var(--space-2);
    background: var(--danger-bg);
    color: var(--system-red);
    border-radius: var(--radius-sm);
    font-size: var(--text-caption2);
    word-break: break-word;
}


/* ========== QUICK CAPTURE FAB ========== */
.quick-capture-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 50px;
    height: 50px;
    border-radius: var(--radius-full);
    background: var(--system-blue);
    color: #FFFFFF;
    border: none;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0, 122, 255, 0.32), var(--shadow-md);
    z-index: var(--z-fixed);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 200ms var(--apple-ease-spring), box-shadow var(--transition-fast);
}

.quick-capture-fab:hover {
    transform: scale(1.06);
    box-shadow: 0 6px 24px rgba(0, 122, 255, 0.4), var(--shadow-lg);
}

.quick-capture-fab:active {
    transform: scale(0.94);
    box-shadow: 0 2px 8px rgba(0, 122, 255, 0.2), var(--shadow-sm);
}

.quick-capture-modal .modal-container {
    max-width: 400px;
}


/* ========== PROGRESS BAR ========== */
.progress-bar {
    height: 4px;
    background: var(--fill-tertiary);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--system-blue);
    border-radius: var(--radius-full);
    transition: width 500ms var(--apple-ease);
}

.progress-bar-success .progress-bar-fill { background: var(--system-green); }
.progress-bar-warning .progress-bar-fill { background: var(--system-orange); }
.progress-bar-danger .progress-bar-fill { background: var(--system-red); }

/* Indeterminate progress */
.progress-bar-indeterminate .progress-bar-fill {
    width: 30% !important;
    animation: progress-indeterminate 1.5s var(--apple-ease) infinite;
}

@keyframes progress-indeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}


/* ========== ACTIVITY INDICATOR (Spinner) ========== */
.activity-indicator {
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--fill-tertiary);
    border-top-color: var(--text-secondary-alpha);
    border-radius: var(--radius-full);
    animation: spin 0.8s linear infinite;
}

.activity-indicator-sm {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

.activity-indicator-lg {
    width: 32px;
    height: 32px;
    border-width: 3px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}


/* ========== DIVIDER ========== */
.divider {
    height: 0.5px;
    background: var(--separator);
    margin: var(--space-4) 0;
}

.divider-inset {
    margin-left: var(--space-4);
}


/* ========== ALERT / BANNER ========== */
.alert {
    display: flex;
    align-items: flex-start;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-lg);
    font-size: var(--text-subheadline);
    line-height: 1.47;
}

.alert-info {
    background: var(--info-bg);
    color: var(--system-blue);
}

.alert-success {
    background: var(--success-bg);
    color: var(--system-green);
}

.alert-warning {
    background: var(--warning-bg);
    color: var(--system-orange);
}

.alert-danger {
    background: var(--danger-bg);
    color: var(--system-red);
}


/* ========== AVATAR ========== */
.avatar {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-full);
    object-fit: cover;
    flex-shrink: 0;
}

.avatar-sm { width: 28px; height: 28px; }
.avatar-lg { width: 56px; height: 56px; }
.avatar-xl { width: 80px; height: 80px; }

.avatar-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--fill-secondary);
    color: var(--text-secondary-alpha);
    font-weight: var(--font-semibold);
    font-size: var(--text-body);
}


/* ========== CHIP / TAG ========== */
.chip {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-1) var(--space-3);
    background: var(--fill-tertiary);
    color: var(--text-primary);
    border-radius: var(--radius-full);
    font-size: var(--text-footnote);
    font-weight: var(--font-medium);
    cursor: default;
}

.chip-interactive {
    cursor: pointer;
    transition: background var(--transition-fast);
}

.chip-interactive:hover {
    background: var(--fill-secondary);
}

.chip-selected {
    background: var(--system-blue);
    color: #FFFFFF;
}


/* ========== TOOLBAR ========== */
.toolbar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    background: var(--glass-bg);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border-bottom: 0.5px solid var(--glass-border);
}


/* ========== UTILITIES ========== */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-left { text-align: left; }

.font-medium { font-weight: var(--font-medium); }
.font-semibold { font-weight: var(--font-semibold); }
.font-bold { font-weight: var(--font-bold); }

.hidden { display: none !important; }
.visible { display: block; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-row { flex-direction: row; }
.flex-1 { flex: 1; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }

.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
.gap-6 { gap: var(--space-6); }

.m-0 { margin: 0; }
.mt-2 { margin-top: var(--space-2); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mt-8 { margin-top: var(--space-8); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }
.mb-8 { margin-bottom: var(--space-8); }

.p-0 { padding: 0; }
.p-2 { padding: var(--space-2); }
.p-4 { padding: var(--space-4); }
.p-6 { padding: var(--space-6); }

.rounded-sm { border-radius: var(--radius-sm); }
.rounded-md { border-radius: var(--radius-md); }
.rounded-lg { border-radius: var(--radius-lg); }
.rounded-xl { border-radius: var(--radius-xl); }
.rounded-full { border-radius: var(--radius-full); }

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

.text-secondary { color: var(--text-secondary-alpha); }
.text-tertiary { color: var(--text-tertiary-alpha); }
.text-link { color: var(--text-link); }
.text-success { color: var(--system-green); }
.text-warning { color: var(--system-orange); }
.text-danger { color: var(--system-red); }

.bg-grouped { background: var(--bg-grouped); }
.bg-surface { background: var(--bg-secondary); }
.bg-elevated { background: var(--bg-elevated); }

.shadow-sm { box-shadow: var(--shadow-sm); }
.shadow-md { box-shadow: var(--shadow-md); }
.shadow-lg { box-shadow: var(--shadow-lg); }

/* Screen reader only */
.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;
}

/* Focus visible ring (accessibility) */
:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3.5px rgba(0, 122, 255, 0.35);
    border-radius: var(--radius-sm);
}


/* ========== RESPONSIVE BREAKPOINTS ========== */

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) {
    .page-sidebar {
        display: none;
    }

    .page-content {
        margin-left: 0;
    }

    .container, .container-narrow {
        padding: var(--space-8) var(--space-4);
    }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
    :root {
        --nav-height: 44px;
    }

    .container, .container-narrow {
        padding: var(--space-6) var(--space-4);
    }

    .section {
        margin-bottom: var(--space-6);
    }

    .section-title {
        font-size: var(--text-title3);
    }

    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-3);
    }

    .nav-bar {
        gap: var(--space-1);
        padding: var(--space-1) var(--space-3);
    }

    .nav-bar a {
        font-size: var(--text-footnote);
        padding: var(--space-1) var(--space-2);
    }

    /* Bottom tab bar on mobile */
    .nav-bar.nav-bottom {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        top: auto;
        background: var(--glass-bg-thick);
        backdrop-filter: var(--glass-blur);
        -webkit-backdrop-filter: var(--glass-blur);
        border-top: 0.5px solid var(--glass-border);
        border-bottom: none;
        justify-content: space-around;
        padding-bottom: env(safe-area-inset-bottom);
        z-index: var(--z-nav-bar);
        min-height: var(--tab-bar-height);
    }

    .nav-bar.nav-bottom a {
        flex-direction: column;
        gap: 2px;
        font-size: var(--text-caption2);
        padding: var(--space-1) var(--space-2);
    }

    /* Card adjustments */
    .card {
        border-radius: var(--radius-md);
        padding: var(--space-4);
    }

    .card-header {
        margin-bottom: var(--space-3);
        padding-bottom: var(--space-2);
    }

    /* Toast on mobile */
    .toast-container {
        top: auto;
        bottom: calc(var(--tab-bar-height) + var(--space-4) + env(safe-area-inset-bottom));
    }

    /* FAB position above tab bar */
    .quick-capture-fab {
        bottom: calc(var(--tab-bar-height) + var(--space-4) + env(safe-area-inset-bottom));
    }

    /* Search full-width on mobile */
    .nav-search-input {
        width: 100%;
    }

    .nav-search-input:focus {
        width: 100%;
    }

    .search-dropdown {
        width: calc(100vw - var(--space-8));
        left: auto;
        right: 0;
    }
}

/* Small mobile (< 390px) */
@media (max-width: 390px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }

    .stat-value {
        font-size: var(--text-title1);
    }
}


/* ========== PRINT STYLES ========== */
@media print {
    /* Hide interactive elements */
    .nav-bar,
    .nav-bar.nav-bottom,
    .theme-toggle,
    .btn,
    button,
    .quick-capture-fab,
    .toast-container,
    .modal-overlay,
    .page-sidebar,
    .sync-status-bar,
    .segmented-control,
    .toggle-switch,
    .nav-search-wrapper {
        display: none !important;
    }

    /* Reset to print-friendly */
    body {
        background: #FFFFFF;
        color: #000000;
        font-size: 12pt;
    }

    .page-content {
        margin-left: 0;
    }

    .container, .container-narrow {
        max-width: 100%;
        padding: 0;
    }

    .card {
        box-shadow: none;
        border: 0.5pt solid #D1D1D6;
        page-break-inside: avoid;
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .table-container {
        box-shadow: none;
        border: 0.5pt solid #D1D1D6;
    }

    a {
        color: #000000;
        text-decoration: underline;
    }

    a[href]::after {
        content: " (" attr(href) ")";
        font-size: 9pt;
        color: #666666;
    }

    .badge {
        border: 0.5pt solid currentColor;
    }
}


/* ========== ANIMATIONS ========== */
/* Fade in */
.fade-in {
    animation: fade-in 350ms var(--apple-ease);
}

@keyframes fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Slide up (for sheets, drawers) */
.slide-up {
    animation: slide-up 350ms var(--apple-ease-spring);
}

@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateY(24px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Scale in (for popovers, tooltips) */
.scale-in {
    animation: scale-in 200ms var(--apple-ease);
}

@keyframes scale-in {
    from {
        opacity: 0;
        transform: scale(0.95);
    }
    to {
        opacity: 1;
        transform: scale(1);
    }
}

/* Content transition (page content swaps) */
.content-appear {
    animation: content-appear 300ms var(--apple-ease);
}

@keyframes content-appear {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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


/* ========== Command Palette ========== */

/* Keyboard Shortcut Badges — reusable across the app */
.kbd-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    font-family: var(--font-sans);
    font-size: var(--text-caption1);
    font-weight: var(--font-medium);
    color: var(--text-secondary-alpha);
    background: var(--fill-quaternary);
    border: 0.5px solid var(--separator);
    border-radius: 5px;
    line-height: 1;
    white-space: nowrap;
    user-select: none;
    -webkit-user-select: none;
}

.kbd-badge-sm {
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    font-size: var(--text-caption2);
    border-radius: 4px;
}

.kbd-badge-group {
    display: inline-flex;
    align-items: center;
    gap: 3px;
}

/* Skeleton — additional utility shapes */
.skeleton-badge {
    display: inline-block;
    width: 60px;
    height: 20px;
    border-radius: var(--radius-full);
}

.skeleton-button {
    display: inline-block;
    width: 80px;
    height: 36px;
    border-radius: var(--radius-sm);
}

.skeleton-chip {
    display: inline-block;
    width: 90px;
    height: 26px;
    border-radius: var(--radius-full);
}

.skeleton-stat {
    width: 100%;
    height: 80px;
    border-radius: var(--radius-lg);
}

.skeleton-row {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    min-height: 44px;
}

.skeleton-row .skeleton-avatar {
    flex-shrink: 0;
}

.skeleton-row .skeleton-text {
    flex: 1;
}

/* Skeleton pulse variant (gentler alternative to shimmer) */
.skeleton-pulse {
    animation: skeleton-pulse-anim 1.5s ease-in-out infinite;
    background: var(--fill-quaternary);
    border-radius: var(--radius-sm);
}

@keyframes skeleton-pulse-anim {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* ============================================================
   ENHANCED COMPONENTS (Phase 0 — Dashboard Redesign)
   ============================================================ */

/* --- Enhanced Stat Card --- */
.stat-card-enhanced {
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: flex-start;
    gap: var(--space-4);
    transition: box-shadow var(--transition-base), transform var(--transition-base);
}
.stat-card-enhanced:hover {
    box-shadow: var(--shadow-md);
}
.stat-card-enhanced::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    border-radius: var(--radius-lg) 0 0 var(--radius-lg);
    background: var(--_accent, var(--system-blue));
}
.stat-card-enhanced .stat-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    flex-shrink: 0;
    background: var(--_accent-bg, var(--info-bg));
}
.stat-card-enhanced .stat-value {
    font-size: var(--text-title2);
    font-weight: var(--font-bold);
    color: var(--text-primary);
    line-height: 1.1;
    font-feature-settings: 'tnum' 1;
}
.stat-card-enhanced .stat-label {
    font-size: var(--text-footnote);
    color: var(--text-secondary-alpha);
    margin-top: var(--space-1);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.stat-card-enhanced .stat-detail {
    font-size: var(--text-caption1);
    color: var(--text-tertiary-alpha);
    margin-top: var(--space-1);
}
.stats-grid {
    display: grid;
    gap: var(--space-4);
    margin-bottom: var(--space-6);
}
.stats-grid-3 { grid-template-columns: repeat(3, 1fr); }
.stats-grid-4 { grid-template-columns: repeat(4, 1fr); }

/* --- Enhanced Empty State --- */
.empty-state-illustration {
    width: 120px;
    height: 120px;
    margin-bottom: var(--space-5);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-2xl);
    background: var(--fill-quaternary);
}
.empty-state-illustration-inner {
    font-size: 48px;
    line-height: 1;
}
.empty-state-tip {
    font-size: var(--text-footnote);
    color: var(--text-tertiary-alpha);
    margin-top: var(--space-4);
    max-width: 280px;
    line-height: 1.47;
    text-align: center;
}
.empty-state-actions {
    display: flex;
    gap: var(--space-3);
    margin-top: var(--space-6);
    flex-wrap: wrap;
    justify-content: center;
}

/* --- Enhanced Filter Pill --- */
.filter-pill-enhanced {
    display: inline-flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-4);
    border: none;
    border-radius: var(--radius-full);
    background: var(--fill-quaternary);
    cursor: pointer;
    font-family: var(--font-sans);
    font-size: var(--text-footnote);
    font-weight: var(--font-medium);
    color: var(--text-primary);
    transition: all var(--transition-fast);
    white-space: nowrap;
}
.filter-pill-enhanced:hover {
    background: var(--fill-tertiary);
    box-shadow: var(--shadow-sm);
}
.filter-pill-enhanced.active {
    background: var(--system-blue);
    color: #FFFFFF;
}
.filter-pill-icon {
    font-size: var(--text-subheadline);
    line-height: 1;
}
.filter-pill-count {
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: var(--radius-full);
    background: rgba(0, 0, 0, 0.08);
    font-size: var(--text-caption2);
    font-weight: var(--font-bold);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}
.filter-pill-enhanced.active .filter-pill-count {
    background: rgba(255, 255, 255, 0.25);
    color: #FFFFFF;
}
.filter-pills-row {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
    margin-bottom: var(--space-5);
}

/* --- Workflow Steps --- */
.workflow-steps {
    display: flex;
    align-items: center;
    gap: var(--space-1);
    padding: var(--space-4) var(--space-5);
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: var(--space-6);
    overflow-x: auto;
}
.workflow-step {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    font-size: var(--text-footnote);
    font-weight: var(--font-medium);
    color: var(--text-secondary-alpha);
    white-space: nowrap;
    flex-shrink: 0;
}
.workflow-step.active {
    color: var(--system-blue);
    background: var(--info-bg);
    font-weight: var(--font-semibold);
}
.workflow-step.completed {
    color: var(--system-green-dark);
}
.workflow-step-number {
    width: 24px;
    height: 24px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: var(--text-caption1);
    font-weight: var(--font-bold);
    background: var(--fill-tertiary);
    color: var(--text-secondary-alpha);
    flex-shrink: 0;
}
.workflow-step.active .workflow-step-number {
    background: var(--system-blue);
    color: #FFFFFF;
}
.workflow-step.completed .workflow-step-number {
    background: var(--system-green);
    color: #FFFFFF;
}
.workflow-connector {
    width: 24px;
    height: 2px;
    background: var(--fill-tertiary);
    flex-shrink: 0;
}
.workflow-connector.completed {
    background: var(--system-green);
}

/* --- Workload Bar --- */
.workload-bar {
    display: flex;
    height: 6px;
    border-radius: var(--radius-full);
    overflow: hidden;
    background: var(--fill-tertiary);
}
.workload-bar-segment {
    height: 100%;
    transition: width 500ms var(--apple-ease, ease);
}

/* --- Alert Banner --- */
.alert-banner {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-footnote);
    font-weight: var(--font-medium);
    margin-bottom: var(--space-4);
}
.alert-banner-warning {
    background: var(--warning-bg);
    color: var(--system-orange-dark);
    border: 1px solid var(--warning-border);
}
.alert-banner-danger {
    background: var(--danger-bg);
    color: var(--system-red);
    border: 1px solid var(--danger-border);
}
.alert-banner-success {
    background: var(--success-bg);
    color: var(--system-green-dark);
    border: 1px solid var(--success-border);
}

/* --- Responsive: Enhanced Components --- */
@media (max-width: 768px) {
    .stats-grid-3 { grid-template-columns: 1fr; }
    .stats-grid-4 { grid-template-columns: repeat(2, 1fr); }
    .stat-card-enhanced {
        padding: var(--space-4);
    }
    .stat-card-enhanced .stat-icon {
        width: 36px;
        height: 36px;
        font-size: 18px;
    }
    .workflow-steps {
        padding: var(--space-3) var(--space-4);
    }
    .empty-state-illustration {
        width: 88px;
        height: 88px;
    }
    .empty-state-illustration-inner {
        font-size: 36px;
    }
    .filter-pills-row {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }
}
