/* ================================================================
   CLARUS WRITER — Redesigned Stylesheet
   Design Philosophy: The interface disappears so the words appear.
   ================================================================ */

/* === Design Tokens === */
:root {
    /* Slate Scale */
    --color-white: #ffffff;
    --color-black: #000000;
    --color-slate-50: #f8fafc;
    --color-slate-100: #f1f5f9;
    --color-slate-200: #e2e8f0;
    --color-slate-300: #cbd5e1;
    --color-slate-400: #94a3b8;
    --color-slate-500: #64748b;
    --color-slate-600: #475569;
    --color-slate-700: #334155;
    --color-slate-800: #1e293b;
    --color-slate-900: #0f172a;

    /* Brand */
    --color-indigo-500: #6366f1;
    --color-indigo-600: #4f46e5;
    --color-rose-500: #f43f5e;
    --color-rose-600: #e11d48;

    /* Semantic: Light Mode */
    --bg-app: var(--color-slate-50);
    --bg-surface: var(--color-white);
    --bg-surface-hover: var(--color-slate-50);
    --bg-input: var(--color-white);
    --bg-overlay-color: 255, 255, 255;
    --bg-modal-overlay-color: 15, 23, 42;
    --bg-overlay: rgba(var(--bg-overlay-color), 0.8);
    --bg-modal-overlay: rgba(var(--bg-modal-overlay-color), 0.4);

    --text-primary: var(--color-slate-900);
    --text-secondary: var(--color-slate-500);
    --text-tertiary: var(--color-slate-400);
    --text-inverse: var(--color-white);

    --border-subtle: var(--color-slate-200);
    --border-strong: var(--color-slate-300);
    --border-focus: var(--color-indigo-500);
    --focus-ring: rgba(99, 102, 241, 0.25);

    --primary-color: var(--color-indigo-600);
    --danger-color: var(--color-rose-500);
    --ui-accent: var(--color-indigo-500);

    /* Dynamic overrides (JS sets these) */
    --bg-color: var(--bg-app);
    --text-color: var(--text-primary);

    /* Spacing */
    --space-2xs: 4px;
    --space-xs: 8px;
    --space-sm: 12px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;
    --space-2xl: 48px;

    /* Typography */
    --font-ui: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-editor: 'Lora', serif;
    --text-xs: 0.75rem;
    --text-sm: 0.8125rem;
    --text-base: 1rem;
    --text-lg: 1.125rem;
    --text-xl: 1.5rem;
    --text-2xl: 2rem;

    /* Effects */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.07), 0 2px 4px -2px rgb(0 0 0 / 0.05);
    --shadow-lg: 0 10px 25px -5px rgb(0 0 0 / 0.08), 0 8px 10px -6px rgb(0 0 0 / 0.04);
    --shadow-xl: 0 20px 50px -12px rgb(0 0 0 / 0.15);
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-full: 9999px;

    /* Motion */
    --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
    --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);
    --duration-fast: 150ms;
    --duration-base: 200ms;
    --duration-slow: 350ms;

    /* Layout */
    --header-height: 52px;
    --sidebar-width: 320px;
    --editor-width: 800px;

    /* Z-Index */
    --z-base: 0;
    --z-editor: 10;
    --z-controls: 20;
    --z-popover: 100;
    --z-dropdown: 200;
    --z-sidebar-backdrop: 290;
    --z-sidebar: 300;
    --z-overlay: 1000;
    --z-modal: 1010;
}

/* === Dark Mode === */
.dark-mode {
    --bg-app: #0c0f17;
    --bg-surface: #151922;
    --bg-surface-hover: #1c212e;
    --bg-input: #151922;
    --bg-overlay-color: 15, 23, 42;
    --bg-modal-overlay-color: 0, 0, 0;

    --text-primary: #e8ecf4;
    --text-secondary: var(--color-slate-400);
    --text-tertiary: var(--color-slate-500);
    --text-inverse: var(--color-slate-900);

    --border-subtle: #1e2536;
    --border-strong: #2a3349;
    --border-focus: var(--color-indigo-500);
    --focus-ring: rgba(129, 140, 248, 0.3);

    --primary-color: #818cf8;
    --danger-color: #fb7185;
    --ui-accent: #818cf8;

    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.4);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 10px 25px -5px rgb(0 0 0 / 0.5);
    --shadow-xl: 0 20px 50px -12px rgb(0 0 0 / 0.6);
}

/* === Reset === */
html { font-size: 16px; }
* { margin: 0; padding: 0; box-sizing: border-box; }

*:focus-visible {
    outline: 2px solid var(--border-focus);
    outline-offset: 2px;
}

body {
    font-family: var(--font-ui);
    background-color: var(--bg-color);
    color: var(--text-color);
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    transition: background-color var(--duration-base) var(--ease-in-out),
                color var(--duration-base) var(--ease-in-out);
}

/* === Header === */
.controls {
    background-color: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    height: var(--header-height);
    z-index: var(--z-controls);
    position: relative;
    transition: background-color var(--duration-base), border-color var(--duration-base);
}

.header-main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 var(--space-lg);
    gap: var(--space-md);
}

/* Logo */
#clarus-logo { height: 22px; width: auto; transition: opacity var(--duration-fast); }
#clarus-logo:hover { opacity: 0.7; }
.logo-text { fill: var(--text-primary); font-family: var(--font-editor); letter-spacing: -0.02em; transition: fill var(--duration-base); }
.logo-accent { opacity: 0.45; }

/* Header Document Area */
.header-doc-area {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.doc-selector-inline {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.doc-selector-inline select {
    appearance: none;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    font-weight: 500;
    padding: 6px 28px 6px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--duration-fast);
    max-width: 200px;
}

.doc-selector-inline select:hover {
    background: var(--bg-surface-hover);
    border-color: var(--border-subtle);
}

.doc-selector-inline select:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--focus-ring);
}

.doc-selector-inline .select-wrapper {
    position: relative;
}

/* Badge */
.badge {
    background: var(--border-subtle);
    color: var(--text-secondary);
    font-size: 10px;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 10px;
    transition: background-color var(--duration-base), color var(--duration-base);
}

/* Settings Toggle (always visible) */
.settings-toggle-btn {
    display: flex !important;
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    padding: 6px;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--duration-fast);
}

.settings-toggle-btn:hover {
    background: var(--bg-surface-hover);
    color: var(--text-primary);
}

.settings-toggle-btn:active {
    transform: scale(0.95);
}

/* === Sidebar === */
.settings-container {
    position: fixed;
    top: var(--header-height);
    right: 0;
    bottom: 0;
    width: var(--sidebar-width);
    background-color: var(--bg-surface);
    border-left: 1px solid var(--border-subtle);
    z-index: var(--z-sidebar);
    overflow-y: auto;
    overflow-x: hidden;

    transform: translateX(100%);
    opacity: 0;
    visibility: hidden;
    transition: transform var(--duration-slow) var(--ease-out),
                opacity var(--duration-base) var(--ease-in-out),
                visibility var(--duration-slow),
                background-color var(--duration-base),
                border-color var(--duration-base);
}

.settings-container.is-open {
    transform: translateX(0);
    opacity: 1;
    visibility: visible;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    top: var(--header-height);
    background: rgba(0, 0, 0, 0.15);
    z-index: var(--z-sidebar-backdrop);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--duration-slow) var(--ease-out), visibility var(--duration-slow);
    pointer-events: none;
}

.settings-container.is-open ~ .sidebar-backdrop {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.sidebar-inner {
    padding: var(--space-lg);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

/* Sidebar Header */
.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
    margin-bottom: var(--space-sm);
}

.sidebar-title {
    font-size: var(--text-sm);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-secondary);
}

.sidebar-close-btn {
    color: var(--text-tertiary);
}

.sidebar-close-btn:hover {
    color: var(--text-primary);
}

/* Sidebar Sections */
.sidebar-section {
    padding: var(--space-sm) 0;
}

.sidebar-section + .sidebar-section {
    border-top: 1px solid var(--border-subtle);
}

.sidebar-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-tertiary);
    margin-bottom: var(--space-xs);
    padding: 0 var(--space-xs);
}

/* Sidebar Items (buttons) */
.sidebar-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    padding: 8px var(--space-xs);
    border: none;
    background: none;
    text-align: left;
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color var(--duration-fast), color var(--duration-fast);
}

.sidebar-item:hover {
    background-color: var(--bg-surface-hover);
}

.sidebar-item svg {
    width: 16px;
    height: 16px;
    color: var(--text-secondary);
    flex-shrink: 0;
    transition: color var(--duration-fast);
}

.sidebar-item:hover svg {
    color: var(--text-primary);
}

/* Sidebar Controls (label + input) */
.sidebar-control {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px var(--space-xs);
    gap: var(--space-sm);
}

.sidebar-control label {
    font-size: var(--text-sm);
    color: var(--text-secondary);
    white-space: nowrap;
    flex-shrink: 0;
}

.sidebar-divider {
    height: 1px;
    background: var(--border-subtle);
    margin: var(--space-xs) 0;
}

/* Sync row */
.sync-row {
    flex-wrap: wrap;
}

.toggle-group {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.sync-label {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    font-style: italic;
}

.pat-input-row {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: 6px var(--space-xs);
}

/* === Shared Form Elements === */
.select-wrapper { position: relative; display: inline-block; }
.select-wrapper::after {
    content: '';
    position: absolute;
    right: 10px; top: 50%;
    transform: translateY(-50%);
    width: 7px; height: 5px;
    background-color: var(--text-tertiary);
    clip-path: polygon(100% 0%, 0 0%, 50% 100%);
    pointer-events: none;
    transition: background-color var(--duration-base);
}

select, input[type="text"], input[type="password"], input[type="number"] {
    appearance: none;
    background-color: var(--bg-input);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    border-radius: var(--radius-md);
    padding: 5px 28px 5px 10px;
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    transition: background-color var(--duration-base), border-color var(--duration-base),
                color var(--duration-base), box-shadow var(--duration-fast);
    min-width: 60px;
}

input[type="number"], input[type="text"] { padding-right: 10px; }

select:hover, input:hover { border-color: var(--text-tertiary); }
select:focus, input:focus {
    outline: none;
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--focus-ring);
}
button:disabled, select:disabled { opacity: 0.5; cursor: not-allowed; }

/* Range Slider */
input[type=range] {
    -webkit-appearance: none;
    width: 100%;
    background: transparent;
    cursor: pointer;
}
input[type=range]:focus { outline: none; }
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    height: 14px; width: 14px;
    border-radius: 50%;
    background: var(--bg-surface);
    border: 2px solid var(--primary-color);
    margin-top: -5px;
    box-shadow: var(--shadow-sm);
    transition: transform var(--duration-fast);
}
input[type=range]::-webkit-slider-thumb:hover { transform: scale(1.15); }
input[type=range]::-webkit-slider-runnable-track {
    width: 100%; height: 4px;
    background: var(--border-subtle);
    border-radius: var(--radius-full);
    transition: background-color var(--duration-base);
}

.slider-with-value {
    flex: 1;
    max-width: 140px;
}

/* Icon Buttons */
.icon-btn {
    background: transparent;
    border: 1px solid transparent;
    color: var(--text-secondary);
    padding: 6px;
    border-radius: var(--radius-md);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color var(--duration-base), background-color var(--duration-base);
}
.icon-btn:hover {
    background-color: var(--bg-surface-hover);
    color: var(--text-primary);
}
.icon-btn:active { transform: translateY(1px); }

/* Toggle Switch */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 34px; height: 18px;
    flex-shrink: 0;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: var(--border-strong);
    border-radius: 18px;
    transition: background-color var(--duration-base);
}
.slider:before {
    position: absolute;
    content: "";
    height: 12px; width: 12px;
    left: 3px; bottom: 3px;
    background-color: var(--color-white);
    border-radius: 50%;
    transition: transform var(--duration-base);
    box-shadow: var(--shadow-sm);
}
input:checked + .slider { background-color: var(--primary-color); }
input:checked + .slider:before { transform: translateX(16px); }

/* Clean Input */
.clean-input {
    border: none;
    background: transparent;
    width: 100%;
    font-size: var(--text-xs);
    color: var(--text-primary);
    padding: 4px 0;
}
.clean-input:focus {
    box-shadow: none;
    border-bottom: 1px solid var(--primary-color);
    border-radius: 0;
    outline: none;
}
.clean-input::placeholder {
    color: var(--text-tertiary);
}

/* Theme Icons */
.icon-state { position: relative; width: 16px; height: 16px; flex-shrink: 0; }
.icon-moon, .icon-sun {
    position: absolute; top: 0; left: 0;
    transition: transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.4s ease, color var(--duration-base);
    color: var(--text-primary);
}
.dark-mode .icon-sun { transform: rotate(90deg) scale(0.5); opacity: 0; }
.dark-mode .icon-moon { transform: rotate(0) scale(1); opacity: 1; }
body:not(.dark-mode) .icon-moon { transform: rotate(-90deg) scale(0.5); opacity: 0; }
body:not(.dark-mode) .icon-sun { transform: rotate(0) scale(1); opacity: 1; }

/* Custom Theme Popover (inside sidebar) */
#custom-theme-popover {
    padding: var(--space-sm) var(--space-xs);
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}
#custom-theme-popover.hidden { display: none; }

.color-picker-grid {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.color-setting {
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.color-setting label {
    font-size: var(--text-xs);
    color: var(--text-secondary);
}

input[type="color"] {
    -webkit-appearance: none;
    border: 2px solid var(--border-subtle);
    padding: 0;
    width: 26px; height: 26px;
    border-radius: 50%;
    cursor: pointer;
    overflow: hidden;
    transition: transform var(--duration-fast), border-color var(--duration-fast);
}
input[type="color"]:hover { transform: scale(1.1); border-color: var(--text-secondary); }
input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: none; border-radius: 50%; }

.popover-actions { display: flex; gap: var(--space-xs); margin-top: var(--space-2xs); }
.btn-xs {
    padding: 5px 12px; font-size: var(--text-xs); font-weight: 500;
    border-radius: var(--radius-sm); border: 1px solid var(--border-subtle);
    cursor: pointer; flex: 1; transition: all var(--duration-fast);
    font-family: var(--font-ui);
}
.btn-xs:hover { transform: translateY(-1px); }
.btn-xs.primary { background-color: var(--primary-color); color: var(--color-white); border-color: var(--primary-color); }
.btn-xs.secondary { background: transparent; color: var(--text-primary); }
.btn-xs.secondary:hover { background-color: var(--bg-surface-hover); }

/* === Dropdown Menu (doc actions) === */
.dropdown-container { position: relative; }

.dropdown-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background-color: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: var(--space-2xs);
    box-shadow: var(--shadow-lg);
    z-index: var(--z-dropdown);
    min-width: 200px;
    display: flex;
    flex-direction: column;
    gap: 1px;

    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
    transform-origin: top right;
    transition: opacity var(--duration-fast) var(--ease-out),
                transform var(--duration-fast) var(--ease-out),
                background-color var(--duration-base),
                border-color var(--duration-base);
}

.dropdown-menu.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-6px) scale(0.97);
}

.menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    width: 100%;
    padding: 8px var(--space-sm);
    border: none;
    background: none;
    text-align: left;
    color: var(--text-primary);
    font-family: var(--font-ui);
    font-size: var(--text-sm);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: background-color var(--duration-fast), color var(--duration-fast);
}

.menu-item:hover { background-color: var(--bg-surface-hover); }
.menu-item svg { width: 16px; height: 16px; color: var(--text-secondary); transition: color var(--duration-fast); flex-shrink: 0; }
.menu-item:hover svg { color: var(--text-primary); }

.menu-item.danger-action { color: var(--danger-color); }
.menu-item.danger-action svg { color: var(--danger-color); }
.menu-item.danger-action:hover { background-color: var(--bg-surface-hover); }

.menu-divider { height: 1px; background-color: var(--border-subtle); margin: 2px 0; transition: background-color var(--duration-base); }

/* === Editor Area === */
main {
    flex-grow: 1;
    display: flex;
    justify-content: center;
    padding: var(--space-xl) var(--space-md);
    overflow-x: hidden;
    z-index: var(--z-editor);
    transition: opacity var(--duration-base);
}

#editor-container {
    position: relative;
    width: 100%;
    max-width: var(--editor-width);
    transition: max-width var(--duration-base) var(--ease-in-out);
    display: flex;
    gap: var(--space-lg);
}

#editor, #preview-pane {
    width: 100%;
    min-height: 70vh;
    padding: 48px 40px;
    font-size: var(--font-size, 18px);
    line-height: 1.85;
    color: var(--text-color);
    background-color: var(--editor-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    outline: none;
    transition: background-color var(--duration-base), box-shadow var(--duration-base), color var(--duration-base);
}

#editor:focus {
    box-shadow: var(--shadow-md);
}

[contenteditable]:empty::before {
    content: 'Start writing...';
    color: var(--text-tertiary);
    cursor: text;
    font-style: italic;
}

/* Preview Pane */
#preview-pane { display: none; border-left: 1px solid var(--border-subtle); overflow-y: auto; background: var(--bg-surface); }
main.preview-active #preview-pane { display: block; animation: fadeIn var(--duration-base) var(--ease-out); }
main.preview-active #editor-container { max-width: 1600px; }
main.preview-active #editor { width: 50%; }
main.preview-active #preview-pane { width: 50%; padding: 36px; }

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

#preview-pane h1, #preview-pane h2 { border-bottom: 1px solid var(--border-subtle); padding-bottom: 0.3em; margin-top: 1.5em; color: var(--text-primary); }
#preview-pane p, #preview-pane li { color: var(--text-primary); }
#preview-pane code { background: var(--border-subtle); color: var(--text-primary); padding: 2px 6px; border-radius: 4px; font-size: 0.9em; font-family: 'Roboto Mono', monospace; }
#preview-pane blockquote { border-left: 4px solid var(--primary-color); margin: 1em 0; padding-left: 16px; color: var(--text-secondary); font-style: italic; }

/* === Lookup Popover === */
#lookup-popover {
    position: absolute;
    z-index: var(--z-popover);
    transform: translate(-50%, -120%) scale(1);
    opacity: 1;
    transition: opacity var(--duration-fast), transform var(--duration-fast);
}
#lookup-popover.hidden { opacity: 0; transform: translate(-50%, -110%) scale(0.95); pointer-events: none; }

#lookup-btn {
    background-color: var(--bg-surface);
    color: var(--primary-color);
    padding: 6px 14px;
    border-radius: var(--radius-full);
    border: 1px solid var(--border-subtle);
    box-shadow: var(--shadow-md);
    gap: 6px;
    font-size: var(--text-xs);
    font-weight: 600;
    transition: all var(--duration-fast);
}
#lookup-btn:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
}

/* === Footer === */
.stats {
    background-color: var(--bg-surface);
    border-top: 1px solid var(--border-subtle);
    padding: var(--space-xs) var(--space-xl);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: var(--text-xs);
    color: var(--text-secondary);
    transition: background-color var(--duration-base), border-color var(--duration-base);
    z-index: var(--z-controls);
    position: relative;
}

.stat-container {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.stat-group {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.primary-stats {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 3px;
}

.stat-label {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
}

.stat-value {
    font-weight: 500;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.stat-sep {
    color: var(--text-tertiary);
    font-size: 10px;
}

/* Expand button */
.expand-stats-btn {
    background: none;
    border: none;
    color: var(--text-tertiary);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    transition: all var(--duration-fast);
    margin-left: var(--space-2xs);
}
.expand-stats-btn:hover {
    color: var(--text-primary);
    background: var(--bg-surface-hover);
}

.stats.expanded .expand-stats-btn svg {
    transform: rotate(180deg);
}

/* Expanded stats — hidden by default */
.expanded-stats {
    display: none;
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding-top: var(--space-xs);
    animation: fadeIn var(--duration-fast) var(--ease-out);
}

.stats.expanded .expanded-stats {
    display: flex;
}

/* Goal stats */
.goal-stats {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    margin-left: var(--space-sm);
    padding-left: var(--space-sm);
    border-left: 1px solid var(--border-subtle);
}

#goal-input {
    width: 48px; padding: 2px 0; height: auto;
    border: none; border-bottom: 1px solid var(--border-subtle);
    border-radius: 0; background: transparent;
    text-align: center; font-weight: 500;
    color: var(--text-primary);
    font-size: var(--text-xs);
}
#goal-input:focus { border-bottom-color: var(--primary-color); box-shadow: none; }

#goal-progress-container { width: 80px; height: 4px; background: var(--border-subtle); border-radius: var(--radius-full); overflow: hidden; }
#goal-progress-bar { height: 100%; background: var(--primary-color); width: 0; transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1); }

.status-area { font-style: italic; opacity: 0.7; color: var(--text-secondary); font-size: var(--text-xs); }

/* Save Status */
@keyframes savePulse { 0% { opacity: 0.5; } 50% { opacity: 1; } 100% { opacity: 0.5; } }
#save-status.saving { animation: savePulse 1.5s infinite; color: var(--ui-accent); }

/* === Modals === */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-color: var(--bg-modal-overlay);
    backdrop-filter: blur(6px);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: var(--z-overlay);
    opacity: 1;
    visibility: visible;
    transition: opacity var(--duration-base), background-color var(--duration-base);
}
.modal-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }

.modal {
    background-color: var(--bg-surface);
    padding: var(--space-xl);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    width: 90%;
    max-width: 460px;
    transform: scale(1) translateY(0);
    transition: transform var(--duration-base) cubic-bezier(0.175, 0.885, 0.32, 1.275), background-color var(--duration-base);
    display: flex;
    flex-direction: column;
    max-height: 85vh;
    border: 1px solid var(--border-subtle);
    z-index: var(--z-modal);
    overflow-y: auto;
}
.modal-overlay.hidden .modal { transform: scale(0.95) translateY(8px); }

.modal.modal-large { max-width: 640px; height: 80vh; }

.modal h2 { margin-bottom: var(--space-md); font-size: var(--text-lg); color: var(--text-primary); font-weight: 600; }
.modal p { color: var(--text-secondary); margin-bottom: var(--space-lg); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-lg); }
.modal-header h2 { margin: 0; }

.modal-input {
    width: 100%;
    padding: var(--space-sm);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: var(--text-base);
    margin-bottom: var(--space-lg);
    transition: border-color var(--duration-fast), background-color var(--duration-base);
}
.modal-input:focus { border-color: var(--border-focus); outline: none; box-shadow: 0 0 0 2px var(--focus-ring); }

.modal-buttons { display: flex; justify-content: flex-end; gap: var(--space-sm); margin-top: auto; }
.modal-btn-primary, .modal-btn-secondary, .modal-btn-danger {
    padding: 8px 18px;
    border-radius: var(--radius-md);
    font-weight: 500;
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--duration-fast);
    font-size: var(--text-sm);
    font-family: var(--font-ui);
}
.modal-btn-primary.small { padding: 5px 12px; font-size: var(--text-xs); }

.modal-btn-primary { background: var(--primary-color); color: var(--color-white); }
.modal-btn-primary:hover { filter: brightness(1.1); box-shadow: 0 4px 6px rgba(0,0,0,0.1); transform: translateY(-1px); }

.modal-btn-secondary { background: transparent; color: var(--text-primary); border-color: var(--border-subtle); }
.modal-btn-secondary:hover { background: var(--bg-surface-hover); border-color: var(--text-secondary); }

.modal-btn-danger { background: var(--danger-color); color: var(--color-white); }
.modal-btn-danger:hover { background: var(--color-rose-600); box-shadow: 0 4px 6px rgba(225, 29, 72, 0.2); }

/* Dictionary */
#dictionary-word { font-family: var(--font-editor); font-size: var(--text-2xl); color: var(--primary-color); margin-bottom: var(--space-sm); }
#dictionary-results h3 { font-size: var(--text-sm); text-transform: uppercase; color: var(--text-secondary); margin-top: var(--space-md); border-bottom: 1px solid var(--border-subtle); padding-bottom: 4px; }
#dictionary-results ul { list-style: none; padding: 0; margin-top: var(--space-sm); }
#dictionary-results li { margin-bottom: var(--space-md); padding-left: var(--space-md); border-left: 3px solid var(--border-subtle); line-height: 1.6; color: var(--text-primary); }
#dictionary-results strong { color: var(--text-primary); font-weight: 600; }
#dictionary-results em { display: block; margin-top: 4px; color: var(--text-tertiary); font-size: 0.9em; font-style: italic; }
#snapshots-list, #dictionary-results { overflow-y: auto; padding-right: 8px; margin-bottom: var(--space-md); }

/* Snapshots */
.snapshot-item {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    padding: var(--space-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
    transition: border-color 0.2s, box-shadow 0.2s, background-color var(--duration-base);
}
.snapshot-item:hover { border-color: var(--primary-color); box-shadow: var(--shadow-sm); }
.snapshot-item-info { display: flex; flex-direction: column; gap: 4px; }
.snapshot-item-info .name { font-weight: 600; color: var(--text-primary); font-size: var(--text-base); }
.snapshot-item-info .details { font-size: var(--text-xs); color: var(--text-tertiary); }
.snapshot-item-actions { display: flex; gap: 8px; }

/* === Focus Mode === */
body.focus-mode .controls,
body.focus-mode .stats,
body.focus-mode .sidebar-backdrop {
    display: none;
}

body.focus-mode .settings-container {
    display: none;
}

body.focus-mode main {
    padding: 0;
    height: 100vh;
}
body.focus-mode #editor-container {
    max-width: var(--editor-width) !important;
    margin: 0 auto;
    height: 100%;
}
body.focus-mode #editor {
    min-height: 100vh;
    border-radius: 0;
    box-shadow: none;
    padding-top: 15vh;
    border: none;
    background: transparent;
    background-color: var(--bg-app);
}

/* === Typewriter Mode === */
body.typewriter-mode #editor {
    padding-top: 45vh;
    padding-bottom: 45vh;
}
body.typewriter-mode #editor-container {
    scroll-behavior: smooth;
}
body.typewriter-mode .typewriter-line {
    background-color: rgba(99, 102, 241, 0.06);
    border-radius: var(--radius-sm);
    margin: 0 -8px;
    padding: 0 8px;
}

/* === Search & Replace === */
#search-overlay {
    position: fixed;
    top: calc(var(--header-height) + var(--space-md));
    right: var(--space-lg);
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: var(--space-md);
    z-index: var(--z-modal);
    min-width: 300px;
    max-width: 380px;
    font-family: var(--font-ui);
}
#search-overlay.hidden { display: none; }

.search-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-sm);
}
.search-header h3 { font-size: var(--text-sm); font-weight: 600; color: var(--text-primary); margin: 0; }

.search-close-btn {
    background: none; border: none; cursor: pointer;
    padding: var(--space-2xs); color: var(--text-secondary); border-radius: var(--radius-sm);
}
.search-close-btn:hover { background: var(--bg-surface-hover); color: var(--text-primary); }

.search-inputs { display: flex; flex-direction: column; gap: var(--space-xs); }
.search-input-group { display: flex; gap: var(--space-xs); }
.search-input-group input {
    flex: 1; padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--border-subtle); border-radius: var(--radius-sm);
    font-size: var(--text-sm); background: var(--bg-input); color: var(--text-primary);
}
.search-input-group input:focus { outline: none; border-color: var(--primary-color); box-shadow: 0 0 0 3px var(--focus-ring); }

.search-actions { display: flex; gap: var(--space-xs); margin-top: var(--space-sm); flex-wrap: wrap; }
.search-btn {
    padding: var(--space-xs) var(--space-sm);
    border: 1px solid var(--border-subtle); border-radius: var(--radius-sm);
    background: var(--bg-surface); color: var(--text-primary);
    font-size: var(--text-xs); font-weight: 500; cursor: pointer;
    transition: all var(--duration-fast); font-family: var(--font-ui);
}
.search-btn:hover { background: var(--bg-surface-hover); border-color: var(--border-strong); }
.search-btn.primary { background: var(--primary-color); color: white; border-color: var(--primary-color); }
.search-btn.primary:hover { opacity: 0.9; }

.search-results { margin-top: var(--space-sm); font-size: var(--text-xs); color: var(--text-secondary); }
.search-options { display: flex; gap: var(--space-md); margin-top: var(--space-xs); }
.search-option { display: flex; align-items: center; gap: var(--space-2xs); font-size: var(--text-xs); color: var(--text-secondary); }
.search-option input[type="checkbox"] { width: 14px; height: 14px; cursor: pointer; }

.search-highlight { background-color: rgba(251, 191, 36, 0.4); border-radius: 2px; }
.search-highlight.current { background-color: rgba(251, 191, 36, 0.8); outline: 2px solid var(--primary-color); }

/* === Markdown Toolbar === */
#markdown-toolbar {
    position: sticky;
    top: 0;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border-subtle);
    padding: var(--space-xs) var(--space-sm);
    display: flex;
    gap: var(--space-2xs);
    flex-wrap: wrap;
    z-index: var(--z-controls);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
}
#markdown-toolbar.hidden { display: none; }

.toolbar-btn {
    padding: var(--space-2xs) var(--space-xs);
    background: none; border: 1px solid transparent;
    border-radius: var(--radius-sm); cursor: pointer;
    color: var(--text-secondary); font-size: var(--text-sm);
    font-family: var(--font-ui);
    display: flex; align-items: center; justify-content: center;
    min-width: 28px; height: 28px;
    transition: all var(--duration-fast);
}
.toolbar-btn:hover { background: var(--bg-surface-hover); color: var(--text-primary); border-color: var(--border-subtle); }
.toolbar-btn:active { background: var(--border-subtle); }
.toolbar-btn svg { width: 16px; height: 16px; }
.toolbar-divider { width: 1px; height: 20px; background: var(--border-subtle); margin: 0 var(--space-2xs); align-self: center; }

/* === Word Frequency === */
.word-frequency-list { max-height: 300px; overflow-y: auto; }
.word-frequency-item { display: flex; justify-content: space-between; align-items: center; padding: var(--space-xs) 0; border-bottom: 1px solid var(--border-subtle); }
.word-frequency-item:last-child { border-bottom: none; }
.word-frequency-word { font-weight: 500; color: var(--text-primary); }
.word-frequency-count { background: var(--bg-surface-hover); padding: var(--space-2xs) var(--space-xs); border-radius: var(--radius-full); font-size: var(--text-xs); color: var(--text-secondary); }

/* === Writing Stats History === */
.stats-history-chart { width: 100%; height: 200px; background: var(--bg-surface-hover); border-radius: var(--radius-md); padding: var(--space-md); margin-bottom: var(--space-md); }
.stats-history-list { max-height: 200px; overflow-y: auto; }
.stats-history-item { display: flex; justify-content: space-between; padding: var(--space-xs) 0; border-bottom: 1px solid var(--border-subtle); font-size: var(--text-sm); }

/* === TTS === */
.tts-controls {
    display: flex; align-items: center; gap: var(--space-sm);
    padding: var(--space-sm); background: var(--bg-surface-hover);
    border-radius: var(--radius-md); margin-bottom: var(--space-md);
}
.tts-btn {
    padding: var(--space-xs) var(--space-md);
    background: var(--primary-color); color: white;
    border: none; border-radius: var(--radius-sm);
    cursor: pointer; font-size: var(--text-sm); font-weight: 500;
    display: flex; align-items: center; gap: var(--space-xs);
    font-family: var(--font-ui);
}
.tts-btn:hover { opacity: 0.9; }
.tts-btn:disabled { opacity: 0.5; cursor: not-allowed; }
.tts-btn.tts-stop { background: var(--danger-color); }
.tts-speed { display: flex; align-items: center; gap: var(--space-xs); font-size: var(--text-sm); color: var(--text-secondary); }
.tts-speed input[type="range"] { width: 80px; }
.tts-progress-text { font-size: var(--text-sm); color: var(--text-secondary); }

/* === Writing Prompts === */
.writing-prompt-card {
    background: linear-gradient(135deg, var(--primary-color), var(--color-indigo-500));
    color: white; padding: var(--space-xl);
    border-radius: var(--radius-lg); margin-bottom: var(--space-md);
    text-align: center;
}
.writing-prompt-card p { font-size: var(--text-lg); font-style: italic; line-height: 1.6; margin: 0; color: white; }
.prompt-actions { display: flex; gap: var(--space-sm); justify-content: center; margin-top: var(--space-md); }
.prompt-btn {
    padding: var(--space-xs) var(--space-md);
    background: rgba(255, 255, 255, 0.2); color: white;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-sm); cursor: pointer;
    font-size: var(--text-sm); font-family: var(--font-ui);
}
.prompt-btn:hover { background: rgba(255, 255, 255, 0.3); }

/* === Grammar === */
.grammar-error { background-color: rgba(239, 68, 68, 0.12); border-bottom: 2px wavy var(--danger-color); cursor: pointer; position: relative; }
.grammar-warning { background-color: rgba(251, 191, 36, 0.12); border-bottom: 2px wavy #f59e0b; cursor: pointer; }
.grammar-tooltip {
    position: absolute; bottom: 100%; left: 0;
    background: var(--bg-surface); border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md); padding: var(--space-sm);
    box-shadow: var(--shadow-lg); max-width: 300px; z-index: var(--z-popover); font-size: var(--text-sm);
}
.grammar-tooltip-message { color: var(--text-primary); margin-bottom: var(--space-xs); }
.grammar-tooltip-suggestions { display: flex; gap: var(--space-xs); flex-wrap: wrap; }
.grammar-suggestion {
    background: var(--bg-surface-hover); padding: var(--space-2xs) var(--space-xs);
    border-radius: var(--radius-sm); font-size: var(--text-xs); cursor: pointer; color: var(--primary-color);
}
.grammar-suggestion:hover { background: var(--primary-color); color: white; }

/* === Drag & Drop === */
#editor.drag-over {
    background-color: rgba(99, 102, 241, 0.04);
    border: 2px dashed var(--primary-color) !important;
}
#editor.drag-over::after {
    content: 'Drop file to import';
    position: absolute; top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    background: var(--primary-color); color: white;
    padding: var(--space-md) var(--space-xl);
    border-radius: var(--radius-md);
    font-family: var(--font-ui); font-size: var(--text-base); font-weight: 600;
    pointer-events: none; z-index: 100;
}

/* === Scrollbars === */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-subtle); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* === Sidebar Hint === */
.sidebar-hint {
    font-size: var(--text-xs);
    color: var(--text-tertiary);
    font-style: italic;
    padding: 2px var(--space-xs);
    line-height: 1.4;
    margin: 0;
}

.sidebar-sub-label {
    font-size: var(--text-xs);
    font-weight: 600;
    color: var(--text-tertiary);
    padding: 4px var(--space-xs) 2px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* === Floating AI Toolbar === */
#ai-toolbar {
    position: absolute;
    z-index: var(--z-popover);
    display: flex;
    gap: 2px;
    background: var(--bg-surface);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    padding: 3px;
    box-shadow: var(--shadow-lg);
    transform: translateX(-50%);
    transition: opacity var(--duration-fast), transform var(--duration-fast);
}
#ai-toolbar.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateX(-50%) translateY(4px);
}

.ai-action-btn {
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 500;
    font-family: var(--font-ui);
    border: none;
    background: none;
    color: var(--text-secondary);
    border-radius: var(--radius-full);
    cursor: pointer;
    white-space: nowrap;
    transition: all var(--duration-fast);
}
.ai-action-btn:hover {
    background: var(--primary-color);
    color: var(--color-white);
}

/* === AI Response Modal === */
.ai-response-area {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-md);
    background: var(--bg-surface-hover);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-subtle);
    margin-bottom: var(--space-md);
    font-family: var(--font-editor);
    font-size: var(--text-sm);
    line-height: 1.7;
    color: var(--text-primary);
    white-space: pre-wrap;
    min-height: 120px;
}
.ai-response-area .ai-cursor {
    display: inline-block;
    width: 2px;
    height: 1em;
    background: var(--primary-color);
    animation: aiCursorBlink 0.8s infinite;
    vertical-align: text-bottom;
    margin-left: 1px;
}
@keyframes aiCursorBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0; }
}

/* === Zen Mode === */
body.zen-mode .controls,
body.zen-mode .stats,
body.zen-mode .sidebar-backdrop,
body.zen-mode .settings-container,
body.zen-mode #lookup-popover {
    display: none !important;
}

body.zen-mode {
    background: linear-gradient(135deg, #0c0f17 0%, #1a1a2e 30%, #16213e 60%, #0f3460 100%);
    background-size: 400% 400%;
    animation: zenGradient 20s ease infinite;
}

@keyframes zenGradient {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

body.zen-mode main {
    padding: 0;
    height: 100vh;
}

body.zen-mode #editor-container {
    max-width: var(--editor-width) !important;
    margin: 0 auto;
    height: 100%;
}

body.zen-mode #editor {
    min-height: 100vh;
    border-radius: 0;
    box-shadow: none;
    padding-top: 15vh;
    border: none;
    background: transparent;
    color: #e8ecf4;
}

body.zen-mode [contenteditable]:empty::before {
    color: rgba(232, 236, 244, 0.3);
}

#zen-controls {
    position: fixed;
    bottom: var(--space-lg);
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-full);
    padding: var(--space-xs) var(--space-md);
    z-index: var(--z-overlay);
    transition: opacity var(--duration-base);
}
#zen-controls.hidden { display: none; }

.zen-ctrl-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-full);
    display: flex;
    align-items: center;
    transition: all var(--duration-fast);
}
.zen-ctrl-btn:hover {
    color: white;
    background: rgba(255, 255, 255, 0.15);
}

#zen-volume {
    width: 80px;
    accent-color: var(--primary-color);
}

/* === Writing Streaks & Heatmap === */
.streaks-stats {
    display: flex;
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
}

.streak-stat-card {
    flex: 1;
    min-width: 100px;
    background: var(--bg-surface-hover);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    text-align: center;
    border: 1px solid var(--border-subtle);
}

.streak-stat-value {
    font-size: var(--text-xl);
    font-weight: 600;
    color: var(--primary-color);
    display: block;
}

.streak-stat-label {
    font-size: var(--text-xs);
    color: var(--text-secondary);
    margin-top: 2px;
}

.heatmap-container {
    overflow-x: auto;
    padding-bottom: var(--space-sm);
    margin-bottom: var(--space-md);
}

.heatmap-container svg {
    display: block;
    margin: 0 auto;
}

.heatmap-cell {
    rx: 2;
    ry: 2;
    transition: opacity var(--duration-fast);
}

.heatmap-cell:hover {
    stroke: var(--text-primary);
    stroke-width: 1;
}

/* === Keyboard Shortcuts === */
.shortcuts-list {
    overflow-y: auto;
    max-height: 60vh;
}

.shortcuts-group {
    margin-bottom: var(--space-lg);
}

.shortcuts-group-title {
    font-size: var(--text-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-tertiary);
    margin-bottom: var(--space-xs);
    padding-bottom: var(--space-2xs);
    border-bottom: 1px solid var(--border-subtle);
}

.shortcut-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
}

.shortcut-keys {
    display: flex;
    gap: 4px;
}

.shortcut-key {
    background: var(--bg-surface-hover);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-sm);
    padding: 2px 8px;
    font-size: 11px;
    font-family: var(--font-ui);
    font-weight: 500;
    color: var(--text-primary);
    min-width: 24px;
    text-align: center;
}

.shortcut-desc {
    font-size: var(--text-sm);
    color: var(--text-secondary);
}

/* === Document Templates === */
.templates-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: var(--space-sm);
    overflow-y: auto;
    max-height: 60vh;
    padding-bottom: var(--space-md);
}

.template-card {
    background: var(--bg-surface-hover);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-md);
    cursor: pointer;
    transition: all var(--duration-fast);
    text-align: center;
}

.template-card:hover {
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.template-icon {
    font-size: 28px;
    margin-bottom: var(--space-xs);
    display: block;
}

.template-name {
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--text-primary);
    margin-bottom: 4px;
}

.template-desc {
    font-size: 11px;
    color: var(--text-tertiary);
    line-height: 1.3;
}

/* === Session Word Count === */
.session-stat .session-words-value {
    color: var(--primary-color);
    font-weight: 600;
}

/* === Print === */
@media print {
    .controls, .stats, #lookup-popover, .dropdown-menu, .settings-container, .sidebar-backdrop { display: none !important; }
    body, main { height: auto; padding: 0; overflow: visible; background: white; color: black; }
    #editor-container { max-width: 100%; width: 100%; }
    #editor { box-shadow: none; border: none; padding: 0; width: 100%; }
    #preview-pane { display: none; }
}

/* === Mobile Responsive === */
@media (max-width: 768px) {
    .header-main {
        padding: 0 var(--space-md);
    }

    .doc-selector-inline select {
        max-width: 140px;
    }

    /* Sidebar: full width on mobile */
    .settings-container {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--border-subtle);
    }

    /* Editor */
    main {
        padding: var(--space-md) var(--space-xs);
    }

    #editor {
        padding: var(--space-lg);
        border-radius: var(--radius-sm);
    }

    /* Dropdown becomes bottom sheet on mobile */
    .dropdown-menu {
        position: fixed;
        top: auto; bottom: 0; left: 0; right: 0;
        width: 100%;
        border-radius: var(--radius-xl) var(--radius-xl) 0 0;
        border: 1px solid var(--border-subtle);
        box-shadow: 0 -4px 20px rgba(0,0,0,0.1);
        transform: translateY(100%);
        opacity: 1;
        display: flex;
        z-index: var(--z-sidebar);
        max-height: 60vh;
        overflow-y: auto;
        padding: var(--space-md);
    }
    .dropdown-menu.hidden {
        transform: translateY(100%);
        visibility: hidden;
    }
    .dropdown-menu:not(.hidden) {
        transform: translateY(0);
        visibility: visible;
    }

    .dropdown-container { position: static; }

    /* Footer */
    .stats {
        flex-direction: column;
        gap: var(--space-xs);
        padding: var(--space-xs) var(--space-md);
        align-items: flex-start;
    }

    .goal-stats {
        border-left: none;
        padding-left: 0;
        margin-left: 0;
    }

    /* AI toolbar: horizontal scroll on mobile */
    #ai-toolbar {
        max-width: calc(100vw - 32px);
        overflow-x: auto;
    }

    .templates-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    }

    .streaks-stats {
        flex-direction: column;
    }
}

/* Small screens */
@media (max-width: 480px) {
    #clarus-logo { height: 18px; }
    .header-doc-area { gap: 2px; }
}
