/* ============================================
   Operra Design System V2 — "Simple et Magique"
   ============================================
   Principles:
   - Calm design: less on screen, more in focus
   - AI invisible: intelligence embedded, not badged
   - Strategic minimalism: everything earns its place
   - 4px grid, Inter font, refined palette
   ============================================ */

/* ---- Font: Inter (Google Fonts preloaded in base.html) ---- */

/* ---- Design Tokens ---- */
:root, [data-theme="dark"] {
    /* Backgrounds — deeper, calmer */
    --bg-primary: #09090b;
    --bg-secondary: #111113;
    --bg-tertiary: #18181b;
    --bg-input: #1c1c20;
    --bg-hover: #222226;
    --bg-active: #2a2a2f;
    --bg-card: #111113;
    --bg-elevated: #18181b;
    --bg-overlay: rgba(0, 0, 0, 0.6);

    /* Text — high contrast, clear hierarchy */
    --text-primary: #fafafa;
    --text-secondary: #a1a1aa;
    --text-muted: #52525b;
    --text-inverse: #09090b;

    /* Accent — refined indigo (not aggressive red) */
    --accent-primary: #6366f1;
    --accent-primary-hover: #818cf8;
    --accent-primary-subtle: rgba(99, 102, 241, 0.12);
    --accent-secondary: #8b5cf6;

    /* Semantic */
    --accent-success: #22c55e;
    --accent-success-subtle: rgba(34, 197, 94, 0.12);
    --accent-warning: #f59e0b;
    --accent-warning-subtle: rgba(245, 158, 11, 0.12);
    --accent-danger: #ef4444;
    --accent-danger-subtle: rgba(239, 68, 68, 0.12);
    --accent-info: #3b82f6;
    --accent-info-subtle: rgba(59, 130, 246, 0.12);

    /* Keep legacy aliases working */
    --accent-color: var(--accent-primary);
    --success-color: var(--accent-success);
    --error-color: var(--accent-danger);
    --warning-color: var(--accent-warning);

    /* Borders — subtle */
    --border-color: #27272a;
    --border-light: #1e1e22;
    --border-focus: var(--accent-primary);

    /* Shadows — subtle depth */
    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3), 0 1px 2px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.2);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 8px 10px -6px rgba(0, 0, 0, 0.3);

    /* Radius — consistent */
    --radius-xs: 4px;
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Spacing — 4px 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 — Inter scale */
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', monospace;

    --text-xs: 0.75rem;     /* 12px */
    --text-sm: 0.8125rem;   /* 13px */
    --text-base: 0.875rem;  /* 14px */
    --text-md: 0.9375rem;   /* 15px */
    --text-lg: 1rem;        /* 16px */
    --text-xl: 1.125rem;    /* 18px */
    --text-2xl: 1.25rem;    /* 20px */
    --text-3xl: 1.5rem;     /* 24px */
    --text-4xl: 1.875rem;   /* 30px */

    --leading-tight: 1.25;
    --leading-normal: 1.5;
    --leading-relaxed: 1.625;

    --font-normal: 400;
    --font-medium: 500;
    --font-semibold: 600;
    --font-bold: 700;

    /* Layout */
    --sidebar-width: 260px;
    --sidebar-collapsed: 56px;
    --header-height: 48px;

    /* Transitions — feel fast */
    --transition-fast: 100ms ease;
    --transition-base: 150ms ease;
    --transition-slow: 250ms ease;
    --transition-spring: 200ms cubic-bezier(0.16, 1, 0.3, 1);
}

/* ---- Light Theme ---- */
[data-theme="light"] {
    --bg-primary: #ffffff;
    --bg-secondary: #fafafa;
    --bg-tertiary: #f4f4f5;
    --bg-input: #ffffff;
    --bg-hover: #f0f0f2;
    --bg-active: #e4e4e7;
    --bg-card: #ffffff;
    --bg-elevated: #ffffff;
    --bg-overlay: rgba(0, 0, 0, 0.4);

    --text-primary: #09090b;
    --text-secondary: #52525b;
    --text-muted: #a1a1aa;
    --text-inverse: #fafafa;

    --border-color: #e4e4e7;
    --border-light: #f0f0f2;

    --shadow-xs: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.06), 0 2px 4px -2px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
    --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
}

/* ---- Base Reset (overrides old body) ---- */
body {
    font-family: var(--font-sans) !important;
    font-size: var(--text-base) !important;
    line-height: var(--leading-normal);
    color: var(--text-primary);
    background: var(--bg-primary) !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-feature-settings: 'cv02', 'cv03', 'cv04', 'cv11';
}

/* ---- Smooth transitions on interactive elements ---- */
a, button, input, select, textarea, .nav-btn, .mp-card, .sub-tab {
    transition: all var(--transition-base);
}

/* ---- Focus ring — accessible, beautiful ---- */
:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: 2px;
}

/* ---- Scrollbar — minimal ---- */
::-webkit-scrollbar {
    width: 4px;
    height: 4px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--radius-full);
}
::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ---- Selection ---- */
::selection {
    background: var(--accent-primary-subtle);
    color: var(--text-primary);
}

/* V2 Component Overrides are in design-components.css */

/* ============================================
   Command Palette (Cmd+K) — "Magic Search"
   ============================================ */
.cmd-palette-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(4px);
    z-index: 9999;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding-top: 20vh;
}
.cmd-palette-overlay.active {
    display: flex;
    animation: cmdFadeIn var(--transition-fast) ease-out;
}

.cmd-palette {
    width: 560px;
    max-width: 90vw;
    background: var(--bg-elevated);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    overflow: hidden;
    animation: cmdSlideIn var(--transition-spring);
}

.cmd-palette-input-wrap {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-3) var(--space-4);
    border-bottom: 1px solid var(--border-color);
}
.cmd-palette-input-wrap .cmd-icon {
    color: var(--text-muted);
    font-size: var(--text-lg);
    flex-shrink: 0;
}
.cmd-palette-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-sans);
    font-size: var(--text-md);
    outline: none;
    padding: var(--space-2) 0;
}
.cmd-palette-input::placeholder {
    color: var(--text-muted);
}
.cmd-palette-hint {
    font-size: var(--text-xs);
    color: var(--text-muted);
    background: var(--bg-hover);
    padding: 2px 6px;
    border-radius: var(--radius-xs);
    flex-shrink: 0;
}

.cmd-palette-results {
    max-height: 360px;
    overflow-y: auto;
    padding: var(--space-2);
}
.cmd-palette-group {
    padding: var(--space-2) var(--space-3);
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.cmd-palette-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--text-secondary);
    font-size: var(--text-sm);
}
.cmd-palette-item:hover,
.cmd-palette-item.active {
    background: var(--accent-primary-subtle);
    color: var(--text-primary);
}
.cmd-palette-item .cmd-item-icon {
    width: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: var(--text-sm);
    flex-shrink: 0;
}
.cmd-palette-item.active .cmd-item-icon {
    color: var(--accent-primary);
}
.cmd-palette-item .cmd-item-label {
    flex: 1;
}
.cmd-palette-item .cmd-item-shortcut {
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-family: var(--font-mono);
}

.cmd-palette-footer {
    padding: var(--space-2) var(--space-4);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: var(--space-4);
    font-size: var(--text-xs);
    color: var(--text-muted);
}
.cmd-palette-footer kbd {
    background: var(--bg-hover);
    padding: 1px 5px;
    border-radius: var(--radius-xs);
    font-family: var(--font-mono);
    font-size: 10px;
    border: 1px solid var(--border-color);
}

/* ---- Animations ---- */
@keyframes cmdFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes cmdSlideIn {
    from { opacity: 0; transform: translateY(-8px) scale(0.98); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ============================================
   Sidebar V2 — Collapsible Sections
   ============================================ */
.sidebar-section {
    border-bottom: 1px solid var(--border-light);
}
.sidebar-section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-2) var(--space-4);
    cursor: pointer;
    user-select: none;
}
.sidebar-section-header:hover {
    background: var(--bg-hover);
}
.sidebar-section-title {
    font-size: var(--text-xs);
    font-weight: var(--font-semibold);
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.sidebar-section-chevron {
    font-size: 10px;
    color: var(--text-muted);
    transition: transform var(--transition-base);
}
.sidebar-section.collapsed .sidebar-section-chevron {
    transform: rotate(-90deg);
}
.sidebar-section-items {
    overflow: hidden;
    transition: max-height var(--transition-slow), opacity var(--transition-base);
    max-height: 500px;
    opacity: 1;
}
.sidebar-section.collapsed .sidebar-section-items {
    max-height: 0;
    opacity: 0;
}

/* Nav button V2 overrides moved to design-components.css */

/* ============================================
   Cmd+K Trigger Button (sidebar header)
   ============================================ */
.cmd-k-trigger {
    display: inline-flex;
    align-items: center;
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 2px 8px;
    cursor: pointer;
    transition: all var(--transition-fast);
}
.cmd-k-trigger:hover {
    background: var(--bg-active);
    border-color: var(--accent-primary);
}
.cmd-k-trigger kbd {
    font-family: var(--font-sans);
    font-size: var(--text-xs);
    color: var(--text-muted);
    line-height: 1.6;
}
