﻿/* ===================================
   Documents Feature - Desktop Styles
   ===================================
   Document writer desktop/editor styles for the workspace.

   Contains:
   - Document editor core (layout, header, sidebar, toolbar, editor area)
   - AI document dialog styles
   - Coming-soon badge styles
   - Workspace document overrides
   - Futuristic visual effects (Houdini animations, film grain, holo shimmer)

   Companion files (loaded separately):
   - document-mobile.css  — mobile responsive overrides

   Last visual upgrade: February 13, 2026 — Bold Futuristic Effects
   =================================== */

/* ===================================
   @property DECLARATIONS — Houdini Custom Properties
   Enables smooth animation of gradient angles, hues, and opacity
   =================================== */
@property --scan-angle {
    syntax: "<angle>";
    inherits: false;
    initial-value: 0deg;
}

@property --holo-hue {
    syntax: "<angle>";
    inherits: false;
    initial-value: 0deg;
}

@property --glow-intensity {
    syntax: "<number>";
    inherits: false;
    initial-value: 0;
}

@property --breath-pos {
    syntax: "<percentage>";
    inherits: false;
    initial-value: 0%;
}

/* ===================================
   FUTURISTIC KEYFRAMES
   =================================== */

/* Scanning light — traces along borders */
@keyframes scanLight {
    0%   { --scan-angle: 0deg; }
    100% { --scan-angle: 360deg; }
}

/* Holographic color shift — iridescent accent cycling */
@keyframes holoShift {
    0%   { --holo-hue: 0deg; }
    100% { --holo-hue: 360deg; }
}

/* Ambient breathing — slow gradient drift */
@keyframes ambientBreath {
    0%, 100% {
        --breath-pos: 20%;
        opacity: 1;
    }
    33% {
        --breath-pos: 60%;
        opacity: 0.85;
    }
    66% {
        --breath-pos: 40%;
        opacity: 0.92;
    }
}

/* Focus aura — pulsing glow when editor is active */
@keyframes focusAura {
    0%, 100% {
        box-shadow:
            inset 0 0 40px rgba(0, 242, 254, 0.015),
            0 0 0 1px rgba(0, 242, 254, 0.06),
            0 0 20px rgba(0, 242, 254, 0.02);
    }
    50% {
        box-shadow:
            inset 0 0 60px rgba(0, 242, 254, 0.025),
            0 0 0 1px rgba(0, 242, 254, 0.1),
            0 0 40px rgba(0, 242, 254, 0.04);
    }
}

/* Save ripple — expanding sonar ring */
@keyframes saveRipple {
    0% {
        transform: scale(1);
        opacity: 0.6;
        box-shadow: 0 0 0 0 currentColor;
    }
    70% {
        transform: scale(1);
        opacity: 0;
        box-shadow: 0 0 0 8px currentColor;
    }
    100% {
        transform: scale(1);
        opacity: 0;
        box-shadow: 0 0 0 8px currentColor;
    }
}

/* Staggered document list entrance */
@keyframes docSlideIn {
    0% {
        opacity: 0;
        transform: translateX(-12px);
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}

/* Toolbar button magnetic hover */
@keyframes toolbarGlow {
    0%, 100% { box-shadow: 0 0 0 0 rgba(0, 242, 254, 0); }
    50% { box-shadow: 0 0 12px rgba(0, 242, 254, 0.12); }
}

/* Floating ambient orb drift */
@keyframes orbDrift1 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(60px, -40px) scale(1.1); }
    50% { transform: translate(-30px, 50px) scale(0.95); }
    75% { transform: translate(40px, 20px) scale(1.05); }
}

@keyframes orbDrift2 {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(-50px, 30px) scale(1.08); }
    50% { transform: translate(40px, -60px) scale(0.92); }
    75% { transform: translate(-20px, -30px) scale(1.04); }
}

/* Flowing gradient text */
@keyframes gradientFlow {
    0% { background-position: 0% 50%; }
    50% { background-position: 100% 50%; }
    100% { background-position: 0% 50%; }
}

/* Animated gradient border rotation */
@keyframes borderFlow {
    0% { background-position: 0% 50%; }
    100% { background-position: 300% 50%; }
}

/* Corner accent breathing */
@keyframes cornerPulse {
    0%, 100% { opacity: 0.4; }
    50% { opacity: 0.8; }
}

/* Shimmer sweep across surface */
@keyframes shimmerSweep {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* Storage bar ambient glow */
@keyframes storageGlow {
    0%, 100% { box-shadow: 0 0 8px rgba(0, 242, 254, 0.3); }
    50% { box-shadow: 0 0 16px rgba(0, 242, 254, 0.5), 0 0 4px rgba(118, 75, 162, 0.3); }
}

/* Preview scan line */
@keyframes scanLineMove {
    0% { top: 0%; opacity: 0; }
    5% { opacity: 0.6; }
    95% { opacity: 0.6; }
    100% { top: 100%; opacity: 0; }
}

/* ===================================
   ACCESSIBILITY — FOCUS-VISIBLE RINGS
   ===================================
   Interactive elements that were missing keyboard focus indicators. WCAG 2.4.7
   Focus Visible (AA) requires a visible focus indicator on every focusable
   control; without it, keyboard users get stranded in the UI with no idea
   where they are. :focus-visible (not :focus) so mouse clicks don't show
   the ring. */
#documents-view .document-item:focus-visible,
#documents-view .suggestion-item:focus-visible,
#documents-view .mode-toggle-btn:focus-visible,
#documents-view .sources-panel-summary:focus-visible,
#documents-view .doc-source-pill:focus-visible,
#documents-view .ai-chat-send-btn:focus-visible,
#ai-document-dialog .modal-close:focus-visible,
#ai-document-dialog .btn:focus-visible,
.r-skip-link:focus-visible {
    /* WCAG 1.4.11 requires ≥3:1 contrast for UI focus indicators.
       Opaque cyan on #0a0e27 = ~6.1:1 (passes); the previous 0.6 alpha
       fell to ~2.5:1 (fails). The outer glow is retained as a secondary
       cue but the outline does the contrast work. */
    outline: 2px solid #00f2fe;
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(0, 242, 254, 0.18);
}

/* ===================================
   PART 1: MAIN DOCUMENT WRITER STYLES
   =================================== */

/* Document Writer - Quantum Theme Styling */
/* References design-system.css for unified values */
:root {
    --doc-bg-primary: var(--color-bg-primary, #0a0e27);
    --doc-bg-secondary: var(--color-bg-secondary, #151a35);
    --doc-bg-tertiary: var(--color-bg-tertiary, #1e2540);
    --doc-accent-cyan: var(--color-accent-cyan, #00f2fe);
    --doc-accent-purple: var(--color-accent-purple, #764ba2);
    --doc-accent-pink: var(--color-accent-pink, #f72585);
    --doc-accent-gold: var(--color-accent-gold, #ffd60a);
    --doc-gradient-primary: var(--gradient-primary, linear-gradient(135deg, #764ba2 0%, #667eea 50%, #00f2fe 100%));
    --doc-gradient-secondary: linear-gradient(135deg, #f72585 0%, #b5179e 100%);
    --doc-gradient-tertiary: linear-gradient(135deg, #4cc9f0 0%, #4361ee 100%);
    --doc-gradient-glow: linear-gradient(135deg, rgba(118, 75, 162, 0.1) 0%, rgba(0, 242, 254, 0.08) 100%);
    --doc-text-primary: var(--color-text-primary, #ffffff);
    --doc-text-secondary: var(--color-text-secondary, rgba(255, 255, 255, 0.87));
    --doc-text-muted: var(--color-text-muted, rgba(255, 255, 255, 0.6));
    --doc-border: var(--color-border, rgba(255, 255, 255, 0.10));
    --doc-border-glow: var(--color-border-glow, rgba(255, 255, 255, 0.14));
    --doc-shadow: var(--shadow-soft, 0 4px 20px rgba(0, 0, 0, 0.25), 0 1px 3px rgba(0, 0, 0, 0.15));
    --doc-shadow-lg: var(--shadow-strong, 0 8px 40px rgba(0, 0, 0, 0.3), 0 2px 6px rgba(0, 0, 0, 0.2));
    --doc-glow: 0 0 20px rgba(0, 242, 254, 0.06);
    --doc-glow-purple: 0 0 20px rgba(118, 75, 162, 0.06);
    /* Save indicator state colors */
    --doc-save-ok: #10b981;
    --doc-save-active: #fbbf24;
    --doc-save-unsaved: #f59e0b;
    --doc-save-error: #ef4444;
    /* Semantic UI colors */
    --doc-success-text: #6ee7b7;
    --doc-danger-text: #f87171;
    --doc-danger-hover: #ef4444;
    /* Animation tokens */
    --doc-anim-scan: 6s;
    --doc-anim-holo: 12s;
    --doc-anim-breath: 20s;
    --doc-anim-ease: cubic-bezier(0.4, 0, 0.2, 1);
    /* Landing page cohesion tokens */
    --doc-gradient-button: linear-gradient(90deg, #7b68ee 0%, #00d4ff 100%);
    --doc-gradient-button-hover: linear-gradient(90deg, #8b7aff 0%, #00e0ff 100%);
    --doc-gradient-card: linear-gradient(135deg, rgba(26, 31, 58, 0.8), rgba(16, 21, 46, 0.92));
    --doc-glass-border: rgba(255, 255, 255, 0.08);
    --doc-glass-border-hover: rgba(0, 242, 254, 0.3);
}

/* Mode Toggle Buttons */
/* Top Mode Toggle Container - Centered Below Header */
.top-mode-toggle-container {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 0.5rem 0 0.25rem 0;
    background: transparent;
}

.mode-toggle-wrapper {
    display: flex;
    gap: 0.375rem;
    padding: 0.375rem;
    background: rgba(15, 20, 45, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 1rem;
    box-shadow:
        0 4px 16px rgba(0, 0, 0, 0.2),
        0 1px 3px rgba(0, 0, 0, 0.12),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
}

.mode-toggle-btn {
    padding: 0.625rem 1.75rem;
    border: 1px solid transparent;
    border-radius: 0.75rem;
    background: transparent;
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    position: relative;
    overflow: hidden;
}

.mode-toggle-btn:hover {
    background: rgba(0, 242, 254, 0.06);
    color: rgba(255, 255, 255, 0.85);
    border-color: rgba(0, 242, 254, 0.12);
}

.mode-toggle-btn.active {
    background: linear-gradient(135deg, rgba(0, 242, 254, 0.08) 0%, rgba(118, 75, 162, 0.12) 100%);
    color: white;
    border-color: rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
}

.mode-toggle-btn i {
    font-size: 1rem;
    opacity: 0.8;
}

.mode-toggle-btn.active i {
    opacity: 1;
}

/* Documents View Container
   NOTE: position/z-index managed by workspace.css and visibility-system.css.
   This file only handles the visual styling (background, flex layout).
   Do NOT add position:fixed or hardcoded z-index here. */
.documents-view {
    position: relative;
    width: 100%;
    min-height: calc(100vh - var(--doc-content-offset, 120px));
    background: var(--doc-bg-primary);
    background-image: 
        radial-gradient(circle at var(--breath-pos, 20%) 30%, rgba(118, 75, 162, 0.06) 0%, transparent 50%),
        radial-gradient(circle at calc(100% - var(--breath-pos, 20%)) 70%, rgba(0, 242, 254, 0.05) 0%, transparent 50%),
        radial-gradient(circle at 40% 80%, rgba(247, 37, 133, 0.04) 0%, transparent 50%);
    z-index: var(--z-documents-view, 400);
    display: flex;
    flex-direction: column;
    overflow: visible;
    animation: ambientBreath var(--doc-anim-breath) ease-in-out infinite;
    will-change: --breath-pos;
}

/* Film grain texture overlay — adds tactile depth to glass */
.documents-view::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0.018;
    pointer-events: none;
    z-index: var(--z-overlay, 800);
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
    mix-blend-mode: overlay;
}

/* Animation removed - now using consolidated pulse-background-subtle from design-system.css */

/* Document Writer Container */
.document-writer-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: transparent;
    color: var(--doc-text-primary);
    position: relative;
}

/* Floating ambient orbs — atmospheric depth */
.document-writer-container::before,
.document-writer-container::after {
    content: '';
    position: absolute;
    border-radius: 50%;
    pointer-events: none;
    filter: blur(80px);
    z-index: 0;
}

.document-writer-container::before {
    width: 300px;
    height: 300px;
    top: 10%;
    right: -5%;
    background: radial-gradient(circle, rgba(0, 242, 254, 0.08) 0%, transparent 70%);
    animation: orbDrift1 25s ease-in-out infinite;
    will-change: transform;
}

.document-writer-container::after {
    width: 250px;
    height: 250px;
    bottom: 15%;
    left: -3%;
    background: radial-gradient(circle, rgba(118, 75, 162, 0.1) 0%, transparent 70%);
    animation: orbDrift2 30s ease-in-out infinite;
    will-change: transform;
}

/* Document Header — Premium Glass */
.document-header {
    display: flex;
    flex-direction: column;
    /* Top padding matches the floating-nav's `top: 16px` so the buttons
       sit level-at-top with the centred Home + Documents pill rather
       than being pushed down beneath it. The pill's width (~190px) is
       narrower than the header-top row's centre gap, so it floats over
       the empty middle of the row without overlapping the left/right
       action buttons. */
    padding: 1rem 2.5rem 1rem;
    background: linear-gradient(180deg, rgba(10, 14, 39, 0.88) 0%, rgba(15, 20, 45, 0.85) 100%);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border-bottom: 1px solid var(--doc-glass-border);
    box-shadow:
        0 4px 30px rgba(0, 0, 0, 0.3),
        0 1px 0 rgba(255, 255, 255, 0.04) inset;
    z-index: var(--z-sticky, 150);
    gap: 0.75rem;
    width: 100%;
    box-sizing: border-box;
    position: relative;
}

/* Scanning accent line at bottom of header — animated light trace */
.document-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        transparent calc(50% + 30% * cos(var(--scan-angle)) - 15%),
        rgba(0, 242, 254, 0.35) calc(50% + 30% * cos(var(--scan-angle))),
        rgba(118, 75, 162, 0.25) calc(50% + 30% * cos(var(--scan-angle)) + 5%),
        transparent calc(50% + 30% * cos(var(--scan-angle)) + 15%),
        transparent 100%
    );
    z-index: 1;
    animation: scanLight var(--doc-anim-scan) linear infinite;
    will-change: --scan-angle;
}

.document-header-left,
.document-header-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex-wrap: nowrap;
}

.document-header-left {
    flex: 1;
    min-width: 0;
    justify-content: flex-start;
}

.document-header-right {
    flex-shrink: 0;
    justify-content: flex-end;
}

/* Top row: Action buttons */
.document-header-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

/* Bottom row: Title and status */
.document-header-bottom {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding-top: 0.25rem;
}

.doc-btn {
    padding: 0.6rem 1.25rem;
    border: none;
    border-radius: 0.75rem;
    font-weight: 600;
    font-size: 0.875rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, color 0.2s ease, opacity 0.2s ease;
    white-space: nowrap;
    flex-shrink: 0;
    position: relative;
    letter-spacing: 0.2px;
}

.doc-btn-primary {
    background: var(--doc-gradient-button);
    color: #ffffff;
    border: 1px solid rgba(123, 104, 238, 0.3);
    font-weight: 700;
    box-shadow:
        0 2px 10px rgba(0, 212, 255, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    overflow: hidden;
}

/* Diagonal shine sweep on primary button hover */
.doc-btn-primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.15) 50%, transparent 60%);
    transition: left 0.5s ease;
    pointer-events: none;
    z-index: 1;
}

.doc-btn-primary:hover::before {
    left: 100%;
}

.doc-btn-primary:hover {
    background: var(--doc-gradient-button-hover);
    border-color: rgba(0, 212, 255, 0.4);
    box-shadow:
        0 4px 16px rgba(0, 212, 255, 0.3),
        0 0 20px rgba(123, 104, 238, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.doc-btn-secondary {
    background: rgba(255, 255, 255, 0.04);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    color: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.doc-btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(0, 242, 254, 0.2);
    color: #ffffff;
    box-shadow:
        0 2px 8px rgba(0, 0, 0, 0.15),
        0 0 12px rgba(0, 242, 254, 0.06);
}

.doc-btn-success {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.2) 0%, rgba(5, 150, 105, 0.25) 100%);
    color: var(--doc-success-text);
    border: 1px solid rgba(16, 185, 129, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.doc-btn-success:hover {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.25) 0%, rgba(5, 150, 105, 0.3) 100%);
    border-color: rgba(16, 185, 129, 0.4);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    color: rgba(110, 231, 183, 0.9);
}

.doc-btn-warning {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.15) 0%, rgba(239, 68, 68, 0.1) 100%);
    border: 1px solid rgba(245, 158, 11, 0.4);
    color: var(--color-warning, #f59e0b);
}

.doc-btn-warning:hover {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.18) 0%, rgba(239, 68, 68, 0.12) 100%);
    border-color: rgba(245, 158, 11, 0.35);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.doc-btn-coming-soon {
    opacity: 0.7;
    cursor: not-allowed;
    position: relative;
    overflow: visible;
}

.doc-btn-coming-soon:hover {
    transform: none;
    box-shadow: none;
}

.document-title-input {
    background: transparent;
    border: none;
    color: var(--doc-text-primary);
    font-size: 1.75rem;
    font-weight: 700;
    padding: 0.4rem 0;
    border-bottom: 2px solid rgba(255, 255, 255, 0.06);
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    flex: 1;
    letter-spacing: -0.5px;
    min-width: 0;
    position: relative;
}

.document-title-input:focus {
    outline: none;
    border-bottom-color: rgba(0, 242, 254, 0.25);
    border-image: linear-gradient(var(--scan-angle, 90deg), rgba(0, 242, 254, 0.4), rgba(118, 75, 162, 0.3), rgba(0, 242, 254, 0.4)) 1;
    animation: scanLight 4s linear infinite;
    color: #ffffff;
}

.document-title-input::placeholder {
    color: var(--doc-text-muted);
    opacity: 0.35;
    font-style: italic;
}

.document-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--doc-text-muted);
    /* Bumped from 0.7rem (11.2px) to the design system's xs scale
       (12-13px) so ambient status text clears the legibility floor. */
    font-size: var(--font-size-xs);
    white-space: nowrap;
    margin-left: auto;
    padding: 0.3rem 0.85rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 2rem;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    letter-spacing: 0.3px;
    font-weight: 500;
}

.document-status i {
    color: rgba(255, 255, 255, 0.45);
    font-size: 0.72rem;
}

/* Document Main Area */
.document-main {
    display: flex;
    flex: 1;
    overflow: hidden;
    max-width: 100%;
}

/* ===================================
   DOCUMENT SIDEBAR — PREMIUM GLASS DESIGN
   =================================== */

.document-sidebar {
    width: 280px;
    background: var(--doc-gradient-card);
    border-right: 1px solid var(--doc-glass-border);
    padding: 0;
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
    transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 242, 254, 0.2) transparent;
    display: flex;
    flex-direction: column;
}

/* Hide close button on desktop */
.sidebar-close-btn {
    display: none;
}

/* Gradient accent line at top of sidebar — landing page card style */
.document-sidebar::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--doc-accent-cyan), var(--doc-accent-purple));
    pointer-events: none;
    z-index: 2;
    opacity: 0.7;
}

/* Holographic accent line at the right edge — iridescent color shift */
.document-sidebar::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 1px;
    height: 100%;
    background: linear-gradient(
        180deg,
        transparent 0%,
        hsla(calc(180 + var(--holo-hue, 0deg)), 80%, 60%, 0.4) 20%,
        hsla(calc(270 + var(--holo-hue, 0deg)), 60%, 55%, 0.5) 50%,
        hsla(calc(330 + var(--holo-hue, 0deg)), 70%, 55%, 0.3) 80%,
        transparent 100%
    );
    z-index: 1;
    animation: holoShift var(--doc-anim-holo) linear infinite;
    will-change: --holo-hue;
}

/* Custom scrollbar */
.document-sidebar::-webkit-scrollbar {
    width: 4px;
}

.document-sidebar::-webkit-scrollbar-track {
    background: transparent;
}

.document-sidebar::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(0, 242, 254, 0.3), rgba(118, 75, 162, 0.3));
    border-radius: 4px;
}

.document-sidebar::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, rgba(0, 242, 254, 0.5), rgba(118, 75, 162, 0.5));
}

/* --- Sidebar Title --- */
.sidebar-title {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2.5px;
    color: rgba(255, 255, 255, 0.35);
    padding: 1.5rem 1.25rem 0.5rem;
    margin: 0;
    position: relative;
    z-index: 1;
}

.sidebar-section {
    padding: 0.5rem 1rem 1rem;
    position: relative;
    z-index: 1;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.sidebar-section h4 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    margin-bottom: 0.75rem;
    color: rgba(255, 255, 255, 0.35);
}

.sidebar-section h4 i {
    color: var(--doc-accent-cyan);
    font-size: 0.75rem;
    opacity: 0.6;
}

/* --- Document Tabs — Pill Design --- */
.document-tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 0.875rem;
    padding: 3px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.06);
    position: relative;
}

.doc-tab-btn {
    flex: 1;
    padding: 0.5rem 0.75rem;
    background: transparent;
    border: none;
    border-radius: 8px;
    color: rgba(255, 255, 255, 0.45);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    position: relative;
    overflow: hidden;
    z-index: 1;
}

.doc-tab-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 8px;
    opacity: 0;
    background: linear-gradient(135deg, rgba(0, 242, 254, 0.1), rgba(118, 75, 162, 0.1));
    transition: opacity 0.3s ease;
}

.doc-tab-btn:hover {
    color: rgba(255, 255, 255, 0.8);
}

.doc-tab-btn:hover::before {
    opacity: 1;
}

.doc-tab-btn.active {
    color: #fff;
    background: linear-gradient(135deg, rgba(118, 75, 162, 0.7), rgba(0, 242, 254, 0.4));
    box-shadow:
        0 2px 12px rgba(0, 0, 0, 0.3),
        0 1px 3px rgba(0, 0, 0, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.1),
        0 0 16px rgba(0, 242, 254, 0.08);
    animation: toolbarGlow 3s ease-in-out infinite;
}

.doc-tab-btn.active::before {
    opacity: 0;
}

.doc-tab-btn i {
    font-size: 0.8rem;
    transition: transform 0.2s ease;
}

.doc-tab-btn:hover i {
    transform: scale(1.1);
}

.trash-count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 16px;
    height: 16px;
    padding: 0 5px;
    background: linear-gradient(135deg, #f72585, #b5179e);
    color: white;
    font-size: 0.6rem;
    font-weight: 700;
    border-radius: 8px;
    line-height: 1;
    box-shadow: 0 2px 8px rgba(247, 37, 133, 0.4);
}

/* Mobile hamburger badge — surfaces active-generation count when the
   docs sidebar is collapsed. Anchored to the upper-right of
   #doc-mobile-menu-btn (the only element that contains this badge).
   Hidden by default; JS toggles .is-hidden + sets textContent based on
   documentTasks.activeCount(). Yellow tint to match the in-progress
   card state. */
.active-task-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    background: linear-gradient(135deg, var(--color-warning), #fbbf24);
    color: #0a0e27;
    /* Bumped from 0.65rem (10.4px) to 0.72rem (~11.5px) so two-digit
       counts ("9+") remain legible on small viewports. */
    font-size: 0.72rem;
    font-weight: 700;
    border-radius: 9px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(251, 191, 36, 0.45);
    pointer-events: none;
}
/* Anchor: the hamburger button needs position:relative for the absolute
   badge. The existing .doc-mobile-menu-toggle rule lacks it; scoped
   here so we don't reach into the original block. */
.doc-mobile-menu-toggle {
    position: relative;
}

/* --- Search Bar — Floating Glass --- */
.document-search {
    position: relative;
    margin-bottom: 1rem;
}

.document-search i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: rgba(255, 255, 255, 0.3);
    font-size: 0.8rem;
    transition: color 0.3s ease;
    z-index: 1;
}

.document-search input {
    width: 100%;
    padding: 10px 12px 10px 36px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 10px;
    color: var(--doc-text-primary);
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    box-sizing: border-box;
}

.document-search input::placeholder {
    color: rgba(255, 255, 255, 0.25);
    font-weight: 400;
}

.document-search input:focus {
    outline: none;
    border-color: rgba(0, 242, 254, 0.35);
    background: rgba(0, 242, 254, 0.04);
    box-shadow:
        0 0 0 3px rgba(0, 242, 254, 0.06),
        0 0 15px rgba(0, 242, 254, 0.08),
        0 4px 16px rgba(0, 0, 0, 0.2);
}

.document-search:has(input:focus) i {
    color: var(--doc-accent-cyan);
}

/* --- Documents List --- */
.documents-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* --- Document Item — Glass Card with Glow --- */
.document-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 14px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--doc-glass-border);
    border-radius: 14px;
    transition:
        transform 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        background 0.3s ease,
        border-color 0.3s ease,
        box-shadow 0.3s ease;
    margin-bottom: 0;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    /* Staggered entrance animation */
    animation: docSlideIn 0.35s cubic-bezier(0.4, 0, 0.2, 1) both;
}

/* Staggered delays for cascading reveal */
.document-item:nth-child(1)  { animation-delay: 0ms; }
.document-item:nth-child(2)  { animation-delay: 40ms; }
.document-item:nth-child(3)  { animation-delay: 80ms; }
.document-item:nth-child(4)  { animation-delay: 120ms; }
.document-item:nth-child(5)  { animation-delay: 160ms; }
.document-item:nth-child(6)  { animation-delay: 200ms; }
.document-item:nth-child(7)  { animation-delay: 240ms; }
.document-item:nth-child(8)  { animation-delay: 280ms; }
.document-item:nth-child(9)  { animation-delay: 320ms; }
.document-item:nth-child(10) { animation-delay: 360ms; }
.document-item:nth-child(n+11) { animation-delay: 400ms; }

/* Decorative left accent bar on hover */
.document-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 50%;
    transform: translateY(-50%) scaleY(0);
    width: 3px;
    height: 60%;
    border-radius: 0 3px 3px 0;
    background: linear-gradient(180deg, var(--doc-accent-cyan), var(--doc-accent-purple));
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.document-item:hover {
    background: rgba(0, 242, 254, 0.05);
    border-color: rgba(0, 242, 254, 0.25);
    transform: translateX(4px);
    box-shadow:
        0 4px 20px rgba(0, 0, 0, 0.25),
        0 0 20px rgba(0, 242, 254, 0.06);
}

.document-item:hover::before {
    transform: translateY(-50%) scaleY(1);
}

/* Active / selected state */
.document-item.active {
    background: linear-gradient(135deg, rgba(0, 242, 254, 0.06) 0%, rgba(118, 75, 162, 0.04) 100%);
    border-color: rgba(0, 242, 254, 0.25);
    box-shadow:
        0 4px 20px rgba(0, 0, 0, 0.25),
        0 0 20px rgba(0, 242, 254, 0.08);
}

.document-item.active::before {
    transform: translateY(-50%) scaleY(1);
    background: var(--doc-accent-cyan);
}

/* Shimmer sweep on document item hover */
.document-item::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 60%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.04), transparent);
    pointer-events: none;
    z-index: 1;
    transition: none;
}

.document-item:hover::after {
    animation: shimmerSweep 0.8s ease forwards;
}

/* Empty state */
.document-item.empty {
    flex-direction: column;
    text-align: center;
    padding: 2.5rem 1.5rem;
    cursor: default;
    background: rgba(255, 255, 255, 0.02);
    border: 1px dashed rgba(255, 255, 255, 0.08);
}

.document-item.empty::before {
    display: none;
}

.document-item.empty:hover {
    transform: none;
    background: rgba(255, 255, 255, 0.02);
    box-shadow: none;
    border-color: rgba(255, 255, 255, 0.08);
}

.document-item.empty p {
    color: rgba(255, 255, 255, 0.35);
    font-size: 0.85rem;
    margin: 0 0 4px;
}

.document-item.empty small {
    color: rgba(255, 255, 255, 0.2);
    font-size: 0.75rem;
}

/* --- Document Info --- */
.document-info {
    flex: 1;
    min-width: 0;
    cursor: pointer;
}

.document-title {
    font-weight: 600;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 4px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: 0.2px;
    transition: color 0.2s ease;
}

.document-item:hover .document-title {
    color: #fff;
}

.document-meta {
    display: flex;
    gap: 8px;
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.35);
    font-weight: 500;
    letter-spacing: 0.3px;
}

.document-date,
.document-size {
    white-space: nowrap;
}

/* --- Action Buttons (appear on hover) --- */
.document-actions {
    display: flex;
    gap: 4px;
    opacity: 0;
    transform: translateX(8px);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.document-item:hover .document-actions {
    opacity: 1;
    transform: translateX(0);
}

.doc-action-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 6px 8px;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.doc-action-btn:hover {
    background: rgba(0, 242, 254, 0.15);
    border-color: rgba(0, 242, 254, 0.3);
    color: var(--doc-accent-cyan);
}

.doc-action-btn i {
    font-size: 0.7rem;
}

/* --- Trash Items --- */
.document-item.trash-item {
    opacity: 0.65;
    background: rgba(247, 37, 133, 0.03);
    border-color: rgba(247, 37, 133, 0.08);
}

.document-item.trash-item::before {
    background: linear-gradient(180deg, #f72585, #b5179e);
}

.document-item.trash-item:hover {
    opacity: 1;
    background: rgba(247, 37, 133, 0.06);
    border-color: rgba(247, 37, 133, 0.2);
    box-shadow:
        0 4px 16px rgba(0, 0, 0, 0.25),
        0 1px 3px rgba(0, 0, 0, 0.15);
}

.document-item.trash-item .document-title {
    color: rgba(255, 255, 255, 0.45);
}

.document-item.trash-item:hover .document-title {
    color: rgba(255, 255, 255, 0.9);
}

/* Trash Action Buttons */
.doc-action-btn.restore-document:hover {
    background: rgba(0, 242, 254, 0.15);
    border-color: rgba(0, 242, 254, 0.35);
    color: var(--doc-accent-cyan);
    box-shadow: 0 0 12px rgba(0, 242, 254, 0.2);
}

.doc-action-btn.delete-permanent {
    color: rgba(247, 37, 133, 0.6);
}

.doc-action-btn.delete-permanent:hover {
    background: rgba(247, 37, 133, 0.15);
    border-color: rgba(247, 37, 133, 0.35);
    color: #f72585;
    box-shadow: 0 0 12px rgba(247, 37, 133, 0.2);
}

/* --- Sidebar Brand Header --- */
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 1.25rem 1.25rem 0.25rem;
    position: relative;
    z-index: 1;
}

.sidebar-brand-icon {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: linear-gradient(135deg, rgba(118, 75, 162, 0.4), rgba(0, 242, 254, 0.3));
    border: 1px solid rgba(0, 242, 254, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.9rem;
    color: var(--doc-accent-cyan);
    box-shadow:
        0 4px 16px rgba(0, 0, 0, 0.25),
        0 1px 3px rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
    position: relative;
    overflow: hidden;
}

/* Animated gradient border on brand icon */
.sidebar-brand-icon::before {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: 10px;
    background: linear-gradient(90deg,
        rgba(0, 242, 254, 0.4),
        rgba(118, 75, 162, 0.4),
        rgba(0, 242, 254, 0.4)
    );
    background-size: 300% 100%;
    animation: borderFlow 6s linear infinite;
    z-index: -1;
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask-composite: exclude;
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    padding: 1px;
}

.sidebar-brand-text {
    min-width: 0;
}

.sidebar-brand-text .sidebar-title {
    font-size: 0.9rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    text-transform: none;
    background: linear-gradient(90deg, #ffffff, var(--doc-accent-cyan), var(--doc-accent-purple), #ffffff);
    background-size: 300% 100%;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    animation: gradientFlow 8s ease infinite;
    padding: 0;
    margin: 0;
    line-height: 1.2;
}

.sidebar-doc-count {
    font-size: 0.65rem;
    font-weight: 600;
    color: rgba(0, 242, 254, 0.5);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

/* --- Sidebar Footer --- */
.sidebar-footer-info {
    margin-top: auto;
    padding: 1rem 1.25rem 1.25rem;
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
    z-index: 1;
}

.sidebar-storage {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.storage-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.65rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(255, 255, 255, 0.3);
}

.storage-label i {
    font-size: 0.6rem;
    color: rgba(0, 242, 254, 0.4);
}

.storage-bar {
    width: 100%;
    height: 3px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 3px;
    overflow: hidden;
}

.storage-bar-fill {
    height: 100%;
    border-radius: 3px;
    background: linear-gradient(90deg, var(--doc-accent-cyan), var(--doc-accent-purple));
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    animation: storageGlow 3s ease-in-out infinite;
    position: relative;
    overflow: hidden;
}

/* Shimmer highlight on storage bar */
.storage-bar-fill::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 60%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.3), transparent);
    animation: shimmerSweep 3s ease-in-out infinite;
}

.storage-text {
    /* 0.7rem ≈ 11.2px — minimum readable size on 1× displays. 0.6rem (9.6px)
     * was illegible without zooming. */
    font-size: 0.7rem;
    color: rgba(255, 255, 255, 0.25);
    font-weight: 500;
    letter-spacing: 0.3px;
}

/* Editor Area */
.document-editor-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
}

.editor-container {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    width: 100%;
    position: relative;
}

/* Animated gradient border — flowing cyan/purple accent */
.editor-container::before {
    content: '';
    position: absolute;
    inset: -1px;
    background: linear-gradient(90deg,
        transparent,
        rgba(0, 242, 254, 0.12),
        rgba(118, 75, 162, 0.12),
        rgba(0, 242, 254, 0.12),
        transparent
    );
    background-size: 300% 100%;
    animation: borderFlow 10s linear infinite;
    z-index: -1;
    pointer-events: none;
    mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    mask-composite: exclude;
    -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    padding: 1px;
}

/* Editor Toolbar — Floating Glass.
 * `position: relative` (not sticky): the toolbar's parent .editor-container has
 * `overflow: hidden`, which silently disables `position: sticky`. The toolbar
 * was staying visible by flex-column layout coincidence, not stickiness — make
 * the intent explicit. flex-shrink: 0 ensures it never collapses. */
.editor-toolbar {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0.625rem 1.25rem;
    background: linear-gradient(180deg, rgba(15, 20, 45, 0.85) 0%, rgba(21, 26, 53, 0.8) 100%);
    backdrop-filter: blur(20px) saturate(1.3);
    -webkit-backdrop-filter: blur(20px) saturate(1.3);
    border-bottom: 1px solid rgba(0, 242, 254, 0.06);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.03),
        0 2px 16px rgba(0, 0, 0, 0.25);
    gap: 0.5rem;
    flex-wrap: wrap;
    width: 100%;
    box-sizing: border-box;
    position: relative;
    flex-shrink: 0;
    z-index: var(--z-sticky, 150);
}

.toolbar-group {
    display: flex;
    gap: 2px;
    padding: 3px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 0.625rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.toolbar-group:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: rgba(0, 242, 254, 0.12);
    box-shadow: 0 0 12px rgba(0, 242, 254, 0.04), inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.toolbar-btn {
    padding: 0.5rem 0.625rem;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 0.4rem;
    color: rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    font-size: 0.875rem;
}

.toolbar-btn i {
    font-size: 0.875rem;
    color: inherit;
    transition: color 0.2s ease;
}

.toolbar-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.95);
}

.toolbar-btn:active {
    opacity: 0.8;
    transition-duration: 0.1s;
}

.toolbar-btn.active {
    background: linear-gradient(135deg, rgba(0, 242, 254, 0.08) 0%, rgba(118, 75, 162, 0.06) 100%);
    border-color: rgba(0, 242, 254, 0.18);
    color: var(--doc-accent-cyan);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
    position: relative;
}

/* Gradient accent underline on active toolbar button */
.toolbar-btn.active::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 10%;
    right: 10%;
    height: 2px;
    background: linear-gradient(90deg, var(--doc-accent-purple), var(--doc-accent-cyan));
    border-radius: 2px;
    opacity: 0.7;
}

.toolbar-btn.active i {
    color: inherit;
}

.heading-label {
    font-weight: 700;
    font-size: 0.8rem;
    letter-spacing: -0.5px;
}

.toolbar-divider {
    width: 1px;
    height: 24px;
    background: linear-gradient(180deg, transparent, rgba(255, 255, 255, 0.1), transparent);
    margin: 0 0.375rem;
}

.toolbar-spacer {
    flex: 1;
}

/* Editor Content */
.editor-content {
    flex: 1;
    display: flex;
    overflow: hidden;
    justify-content: center;
    width: 100%;
    position: relative;
    background-image:
        repeating-linear-gradient(0deg, transparent, transparent 59px, rgba(0, 242, 254, 0.015) 59px, rgba(0, 242, 254, 0.015) 60px),
        repeating-linear-gradient(90deg, transparent, transparent 59px, rgba(0, 242, 254, 0.015) 59px, rgba(0, 242, 254, 0.015) 60px);
}

/* Corner accent brackets — viewfinder frame */
.editor-content::before,
.editor-content::after {
    content: '';
    position: absolute;
    width: 24px;
    height: 24px;
    pointer-events: none;
    z-index: 2;
    animation: cornerPulse 4s ease-in-out infinite;
}

.editor-content::before {
    top: 8px;
    left: 8px;
    border-top: 2px solid rgba(0, 242, 254, 0.25);
    border-left: 2px solid rgba(0, 242, 254, 0.25);
}

.editor-content::after {
    bottom: 8px;
    right: 8px;
    border-bottom: 2px solid rgba(118, 75, 162, 0.25);
    border-right: 2px solid rgba(118, 75, 162, 0.25);
    animation-delay: -2s;
}

.markdown-editor {
    flex: 1;
    padding: 2.5rem 3.5rem;
    background: rgba(10, 14, 39, 0.4);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: none;
    color: var(--doc-text-primary);
    /* Reading typography — was monospace (JetBrains Mono), which made
       prose feel like source code. Editor is for writing, not coding;
       monospace stays on inline `code` / fenced blocks in the preview. */
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI',
                 Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 1rem;
    line-height: 1.75;
    resize: none;
    overflow-y: auto;
    /* Reading-comfortable measure (~70ch). Was 900px ≈ 112ch, well past
       the 60-75ch sweet spot. Capped at 720px on smaller viewports so
       it still fills the column on narrow editors. */
    max-width: min(720px, 72ch);
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    caret-color: var(--doc-accent-cyan);
    tab-size: 4;
    letter-spacing: 0.01em;
}

.markdown-editor::placeholder {
    color: var(--doc-text-muted);
    opacity: 0.4;
    font-style: italic;
}

/* Preview crossfade transition */
.preview-crossfade-out {
    opacity: 0 !important;
    transform: translateY(4px) !important;
    transition: opacity 0.25s ease, transform 0.25s ease !important;
}

.markdown-editor:focus {
    outline: none;
    background: rgba(10, 14, 39, 0.6);
    animation: focusAura 4s ease-in-out infinite;
    will-change: box-shadow;
}

/* Desktop focus-visible rings for keyboard navigation */
.doc-btn:focus-visible,
.toolbar-btn:focus-visible,
.doc-tab-btn:focus-visible,
.doc-action-btn:focus-visible,
.ai-panel-toggle:focus-visible,
.ai-action-btn:focus-visible {
    outline: 2px solid rgba(0, 242, 254, 0.5);
    outline-offset: 2px;
    box-shadow: 0 0 0 4px rgba(0, 242, 254, 0.08);
}

.document-title-input:focus-visible {
    outline: none;
    border-bottom-color: rgba(0, 242, 254, 0.25);
    box-shadow: 0 2px 0 0 rgba(0, 242, 254, 0.15);
}

.document-search input:focus-visible {
    outline: 2px solid var(--doc-accent-cyan);
    outline-offset: -2px;
}

.preview-pane {
    flex: 1;
    padding: 2.5rem 3.5rem;
    background: rgba(10, 14, 39, 0.35);
    overflow-y: auto;
    overflow-x: hidden;
    border-left: 1px solid rgba(255, 255, 255, 0.04);
    position: relative;
}

/* Retro scan line moving down preview pane */
.preview-pane::after {
    content: '';
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(0, 242, 254, 0.3), transparent);
    pointer-events: none;
    z-index: 2;
    animation: scanLineMove 6s linear infinite;
}

.preview-pane::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 100%;
    background: linear-gradient(
        180deg,
        transparent 0%,
        hsla(calc(180 + var(--holo-hue, 0deg)), 80%, 60%, 0.12) 30%,
        hsla(calc(260 + var(--holo-hue, 0deg)), 60%, 55%, 0.08) 70%,
        transparent 100%
    );
    pointer-events: none;
    animation: holoShift var(--doc-anim-holo) linear infinite;
    animation-delay: -6s;
    will-change: --holo-hue;
}

.preview-content {
    max-width: 900px;
    margin: 0 auto;
    color: var(--doc-text-primary);
    line-height: 1.8;
}

.preview-content h1,
.preview-content h2,
.preview-content h3 {
    color: rgba(255, 255, 255, 0.95);
    margin-top: 2rem;
    margin-bottom: 1rem;
    letter-spacing: -0.5px;
}

.preview-content h1 {
    font-size: 2.25rem;
    font-weight: 700;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding-bottom: 0.75rem;
    color: rgba(255, 255, 255, 0.95);
}

.preview-content h2 {
    font-size: 1.75rem;
    font-weight: 700;
}

.preview-content h3 {
    font-size: 1.35rem;
    font-weight: 700;
    color: rgba(255, 255, 255, 0.85);
}

.preview-content p {
    margin-bottom: 1rem;
}

.preview-content ul,
.preview-content ol {
    margin: 1rem 0;
    padding-left: 2rem;
}

.preview-content code {
    background: rgba(255, 255, 255, 0.04);
    padding: 0.15rem 0.4rem;
    border-radius: 0.3rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.85em;
    color: rgba(0, 242, 254, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.preview-content pre {
    background: rgba(10, 14, 39, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.06);
    padding: 1.25rem;
    border-radius: 0.75rem;
    overflow-x: auto;
    margin: 1.25rem 0;
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.15);
}

.preview-content pre code {
    background: transparent;
    padding: 0;
}

.preview-content blockquote {
    border-left: 3px solid;
    border-image: linear-gradient(180deg, rgba(118, 75, 162, 0.4), rgba(0, 242, 254, 0.2)) 1;
    padding-left: 1.25rem;
    margin: 1.5rem 0;
    color: var(--doc-text-secondary);
    font-style: italic;
    background: rgba(118, 75, 162, 0.03);
    padding: 1rem 1.25rem;
    border-radius: 0 0.75rem 0.75rem 0;
}

.preview-content table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.25rem 0;
    border-radius: 0.5rem;
    overflow: hidden;
}

.preview-content table th,
.preview-content table td {
    padding: 0.75rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.preview-content table th {
    background: rgba(0, 242, 254, 0.08);
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    text-align: left;
    text-transform: uppercase;
    font-size: 0.85rem;
    letter-spacing: 0.05em;
}

/* Striped table rows */
.preview-content table tbody tr:nth-child(even) {
    background: rgba(255, 255, 255, 0.02);
}
.preview-content table tbody tr:hover {
    background: rgba(0, 242, 254, 0.05);
}

/* Table captions */
.preview-content table caption {
    caption-side: top;
    text-align: left;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.6);
    padding: 8px 0;
    font-style: italic;
}

/* ========== Document-Intelligent Styling ========== */

/* Citation superscripts */
.preview-content .citation-ref {
    font-size: 0.75em;
    line-height: 0;
    vertical-align: super;
}
.preview-content .citation-ref a {
    color: rgba(0, 242, 254, 0.8);
    text-decoration: none;
    padding: 0 1px;
    transition: color 0.2s ease;
}
.preview-content .citation-ref a:hover {
    color: #764ba2;
    text-decoration: underline;
}

/* References section */
.preview-content .references-section {
    margin-top: 48px;
    padding-top: 32px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}
.preview-content .references-section h2 {
    font-size: 1.5rem;
    margin-bottom: 20px;
}
.preview-content .ref-entry {
    font-weight: 600;
    color: rgba(0, 242, 254, 0.8);
    margin-right: 4px;
}
.preview-content .references-section p {
    padding-left: 2.5em;
    text-indent: -2.5em;
    font-size: 0.95rem;
    line-height: 1.6;
    margin-bottom: 8px;
}

/* Disclaimer section */
.preview-content .doc-disclaimer {
    margin-top: 48px;
    padding: 20px 24px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.5);
    line-height: 1.6;
}
.preview-content .doc-disclaimer h2 {
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    margin-bottom: 8px;
    color: rgba(255, 255, 255, 0.5);
}

/* Document metadata header (research reports) */
.preview-content .doc-metadata-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    background: rgba(0, 242, 254, 0.05);
    border: 1px solid rgba(0, 242, 254, 0.15);
    border-radius: 8px;
    margin-bottom: 24px;
    font-size: 0.9rem;
}
.preview-content .doc-brand {
    font-weight: 700;
    color: rgba(0, 242, 254, 1);
}
.preview-content .doc-date {
    color: rgba(255, 255, 255, 0.6);
}
.preview-content .doc-author {
    font-style: italic;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 32px;
}

/* Blog byline */
.preview-content .doc-byline {
    display: flex;
    align-items: center;
    gap: 8px;
    color: rgba(255, 255, 255, 0.6);
    font-size: 0.9rem;
    margin-bottom: 32px;
    padding-bottom: 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}
.preview-content .byline-author { font-weight: 600; }
.preview-content .byline-sep { color: rgba(255, 255, 255, 0.3); }

/* Table of Contents */
.preview-content .doc-toc {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    padding: 20px 24px;
    margin-bottom: 32px;
}
.preview-content .doc-toc h2 {
    font-size: 1.1rem;
    margin-bottom: 12px;
    margin-top: 0;
}
.preview-content .doc-toc ol {
    list-style: none;
    padding: 0;
    margin: 0;
}
.preview-content .doc-toc li {
    padding: 6px 0;
}
.preview-content .toc-link {
    color: rgba(255, 255, 255, 0.85);
    text-decoration: none;
    transition: color 0.2s;
    font-size: 0.95rem;
}
.preview-content .toc-link:hover {
    color: rgba(0, 242, 254, 1);
}

/* Document type badge */
.preview-content .doc-type-badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 16px;
}
.preview-content .doc-type-badge.research {
    background: rgba(0, 242, 254, 0.1);
    color: rgba(0, 242, 254, 1);
    border: 1px solid rgba(0, 242, 254, 0.2);
}
.preview-content .doc-type-badge.blog {
    background: rgba(118, 75, 162, 0.1);
    color: rgba(118, 75, 162, 1);
    border: 1px solid rgba(118, 75, 162, 0.2);
}
.preview-content .doc-type-badge.newsletter {
    background: rgba(255, 214, 10, 0.1);
    color: rgba(255, 214, 10, 1);
    border: 1px solid rgba(255, 214, 10, 0.2);
}

/* Editor Footer — Premium Glass */
.editor-footer {
    padding: 0.75rem 2rem;
    background: linear-gradient(180deg, rgba(21, 26, 53, 0.75) 0%, rgba(15, 20, 45, 0.85) 100%);
    backdrop-filter: blur(20px) saturate(1.3);
    -webkit-backdrop-filter: blur(20px) saturate(1.3);
    border-top: 1px solid rgba(0, 242, 254, 0.06);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.03),
        0 -2px 16px rgba(0, 0, 0, 0.2);
    width: 100%;
    box-sizing: border-box;
    position: relative;
}

/* Scanning accent line at top of footer — synced light trace */
.editor-footer::before {
    content: '';
    position: absolute;
    top: -1px;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(
        90deg,
        transparent 0%,
        transparent calc(50% + 30% * cos(var(--scan-angle)) - 15%),
        rgba(118, 75, 162, 0.2) calc(50% + 30% * cos(var(--scan-angle))),
        rgba(0, 242, 254, 0.15) calc(50% + 30% * cos(var(--scan-angle)) + 5%),
        transparent calc(50% + 30% * cos(var(--scan-angle)) + 15%),
        transparent 100%
    );
    animation: scanLight var(--doc-anim-scan) linear infinite;
    animation-delay: -3s;
    will-change: --scan-angle;
}

.editor-stats {
    display: flex;
    gap: 2rem;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.45);
    justify-content: center;
    max-width: 1600px;
    margin: 0 auto;
    font-weight: 500;
    letter-spacing: 0.2px;
}

.editor-stats span {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
    padding: 0.2rem 0.6rem;
    border-radius: 1rem;
    transition: all 0.3s ease;
}

.stat-item:hover {
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.7);
}

.stat-item i {
    color: rgba(255, 255, 255, 0.35);
    font-size: 0.7rem;
}

/* Save Indicator (footer) */
.save-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding-top: 0.35rem;
    /* Bumped from 0.7rem (11.2px) to design-system xs (12-13px). */
    font-size: var(--font-size-xs);
    color: rgba(255, 255, 255, 0.35);
    transition: all 0.3s ease;
    letter-spacing: 0.2px;
}

.save-indicator .save-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--doc-save-ok);
    flex-shrink: 0;
    transition: all 0.3s ease;
    position: relative;
}

/* Ripple ring on save dot */
.save-indicator .save-dot::after {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    border: 1px solid;
    color: inherit;
    opacity: 0;
    animation: none;
}

.save-indicator.saving .save-dot {
    background: var(--doc-save-active);
    animation: pulse-dot 1s ease-in-out infinite;
}

.save-indicator.saving .save-dot::after {
    color: var(--doc-save-active);
    animation: saveRipple 1.5s ease-out infinite;
}

.save-indicator.unsaved .save-dot {
    background: var(--doc-save-unsaved);
}

.save-indicator.error .save-dot {
    background: var(--doc-save-error);
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.6; transform: scale(1.3); }
}

/* Desktop-only visibility helper */
.desktop-only {
    display: flex;
}

.editor-stats i {
    color: rgba(255, 255, 255, 0.35);
    font-size: 0.75rem;
}

/* AI Assistant Panel — Premium Glass */
.document-ai-panel {
    width: 300px;
    background: linear-gradient(180deg, rgba(15, 20, 45, 0.92) 0%, rgba(10, 14, 39, 0.95) 100%);
    backdrop-filter: blur(24px) saturate(1.3);
    -webkit-backdrop-filter: blur(24px) saturate(1.3);
    border-left: 1px solid rgba(255, 255, 255, 0.04);
    box-shadow:
        -4px 0 16px rgba(0, 0, 0, 0.15),
        -1px 0 3px rgba(0, 0, 0, 0.1),
        inset 1px 0 0 rgba(255, 255, 255, 0.03);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

/* Holographic accent line on left edge — iridescent shift */
.document-ai-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 1px;
    height: 100%;
    background: linear-gradient(
        180deg,
        transparent 0%,
        hsla(calc(200 + var(--holo-hue, 0deg)), 70%, 55%, 0.15) 30%,
        hsla(calc(280 + var(--holo-hue, 0deg)), 60%, 50%, 0.12) 70%,
        transparent 100%
    );
    z-index: 1;
    animation: holoShift var(--doc-anim-holo) linear infinite;
    animation-delay: -4s;
    will-change: --holo-hue;
}

.document-ai-panel.collapsed {
    width: 0;
    overflow: hidden;
}

.ai-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    background: rgba(255, 255, 255, 0.02);
    border-bottom: 1px solid rgba(0, 242, 254, 0.06);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.ai-panel-title {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-weight: 700;
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--doc-text-primary);
}

.ai-panel-title i {
    color: var(--doc-accent-purple);
    font-size: 1rem;
}

.ai-panel-toggle {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.5);
    width: 30px;
    height: 30px;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    align-items: center;
    justify-content: center;
}

.ai-panel-toggle:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.1);
    color: rgba(255, 255, 255, 0.8);
}

.ai-panel-content {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem;
}

.ai-suggestions-section,
.ai-actions-section,
.ai-chat-section {
    margin-bottom: 2rem;
}

.ai-suggestions-section h4,
.ai-actions-section h4,
.ai-chat-section h4 {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--doc-text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.75px;
    margin-bottom: 0.875rem;
}

.ai-suggestions-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.suggestion-item {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 0.75rem;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.suggestion-item::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 2px;
    height: 100%;
    background: linear-gradient(180deg, rgba(0, 242, 254, 0.2), rgba(118, 75, 162, 0.15));
    opacity: 0;
    transition: opacity 0.3s ease;
}

.suggestion-item:hover::before {
    opacity: 1;
}

.suggestion-item:hover {
    background: rgba(0, 242, 254, 0.04);
    border-color: rgba(0, 242, 254, 0.12);
    transform: translateX(4px);
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.15);
}

.suggestion-item i {
    color: var(--doc-accent-cyan);
    font-size: 0.875rem;
    margin-top: 0.125rem;
}

.suggestion-item span {
    font-size: 0.875rem;
    line-height: 1.5;
}

.ai-action-btn {
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.ai-action-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(0, 242, 254, 0.05), rgba(255, 255, 255, 0.06), rgba(0, 242, 254, 0.05), transparent);
    transition: left 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-action-btn:hover::before {
    left: 100%;
}

.ai-action-btn:hover {
    background: rgba(0, 242, 254, 0.06);
    border-color: rgba(0, 242, 254, 0.15);
    color: var(--doc-accent-cyan);
    transform: translateX(4px) scale(1.01);
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.15), 0 0 16px rgba(0, 242, 254, 0.06);
}

.ai-action-btn i {
    font-size: 0.875rem;
}

.ai-chat-input-wrapper {
    display: flex;
    gap: 0.5rem;
}

.ai-chat-input {
    flex: 1;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.75rem;
    color: var(--doc-text-primary);
    font-size: 0.85rem;
    transition: all 0.3s ease;
}

.ai-chat-input:focus {
    outline: none;
    border-color: rgba(0, 242, 254, 0.15);
    box-shadow: 0 0 0 2px rgba(0, 242, 254, 0.04);
    background: rgba(255, 255, 255, 0.04);
}

.ai-chat-send-btn {
    padding: 0.75rem 1rem;
    background: linear-gradient(135deg, rgba(0, 242, 254, 0.1) 0%, rgba(118, 75, 162, 0.12) 100%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.75rem;
    color: white;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.ai-chat-send-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    border-color: rgba(0, 242, 254, 0.15);
}

/* Responsive Design */
@media (max-width: 1440px) {
    .document-title-input {
        font-size: 1.5rem;
    }
}

@media (max-width: 1200px) {
    .document-ai-panel {
        width: 280px;
    }
    
    .document-title-input {
        font-size: 1.35rem;
    }
    
    .doc-btn {
        padding: 0.6rem 1rem;
        font-size: 0.875rem;
    }
}

@media (max-width: 1024px) {
    .document-header-top {
        flex-direction: column;
        gap: 0.75rem;
    }
    
    .document-header-left,
    .document-header-right {
        width: 100%;
        justify-content: center;
    }
    
    .document-title-input {
        font-size: 1.25rem;
    }

    .document-main {
        flex-direction: column;
    }
    
    /* Sidebar tablet rules removed — handled by document-mobile.css */

    .document-sidebar::before,
    .document-sidebar::after {
        display: none;
    }

    .sidebar-brand {
        width: 100%;
        padding: 0.75rem 1rem 0.25rem;
    }

    .sidebar-footer-info {
        display: none;
    }
    
    .document-ai-panel {
        width: 100%;
        border-left: none;
        border-top: 1px solid var(--doc-border);
        max-height: 300px;
    }
}

/* Mobile overrides moved to document-mobile.css with higher specificity */

/* Scrollbar Styling (sidebar has its own scrollbar above) */
.markdown-editor::-webkit-scrollbar,
.preview-pane::-webkit-scrollbar,
.ai-panel-content::-webkit-scrollbar {
    width: 6px;
}

.markdown-editor::-webkit-scrollbar-track,
.preview-pane::-webkit-scrollbar-track,
.ai-panel-content::-webkit-scrollbar-track {
    background: rgba(10, 14, 39, 0.3);
    border-radius: 6px;
    margin: 4px;
}

.markdown-editor::-webkit-scrollbar-thumb,
.preview-pane::-webkit-scrollbar-thumb,
.ai-panel-content::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 6px;
}

.markdown-editor::-webkit-scrollbar-thumb:hover,
.preview-pane::-webkit-scrollbar-thumb:hover,
.ai-panel-content::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.18);
}

/* ===================================
   PART 2: AI DOCUMENT GENERATION DIALOG
   =================================== */

#ai-document-dialog.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-max, 10000);
    animation: fadeIn 0.3s ease;
    padding: 40px 20px;
    overflow-y: auto;
}

#ai-document-dialog .modal-container {
    background: linear-gradient(135deg, rgba(15, 20, 45, 0.95) 0%, rgba(10, 14, 39, 0.98) 100%);
    border-radius: 20px;
    border: 1px solid rgba(0, 242, 254, 0.15);
    box-shadow:
        0 25px 80px rgba(0, 0, 0, 0.5),
        0 0 40px rgba(0, 242, 254, 0.06),
        inset 0 0 0 1px rgba(255, 255, 255, 0.04);
    max-width: 700px;
    width: 100%;
    /* vh fallback, then svh (small viewport height) override for iOS Safari.
     * `100vh` on iOS doesn't account for the bottom browser chrome, which
     * was clipping the modal footer. `svh` reports the visible viewport. */
    max-height: calc(100vh - 80px);
    max-height: calc(100svh - 80px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: premiumModalIn 0.45s cubic-bezier(0.16, 1, 0.3, 1) forwards;
    margin: auto;
    position: relative;
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
}

/* Exit animation class applied by JS */
#ai-document-dialog .modal-container.modal-exiting {
    animation: premiumModalOut 0.25s ease-in forwards;
    pointer-events: none;
}

#ai-document-dialog .modal-header {
    padding: 24px 28px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: linear-gradient(135deg, rgba(21, 26, 53, 0.8) 0%, rgba(15, 20, 45, 0.85) 100%);
    flex-shrink: 0;
    min-height: 70px;
    position: relative;
}

#ai-document-dialog .modal-header::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, rgba(0, 242, 254, 0.3), rgba(118, 75, 162, 0.2), rgba(240, 147, 251, 0.15), transparent);
    animation: docShimmer 4s ease-in-out infinite;
}

/* Renamed from shimmer to avoid collision with chat.css shimmer (bg-position based) */
@keyframes docShimmer {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

#ai-document-dialog .modal-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    display: flex;
    align-items: center;
    gap: 12px;
    text-transform: none;
}

#ai-document-dialog .modal-header h2 i {
    color: rgba(0, 242, 254, 0.7);
    font-size: 24px;
    filter: drop-shadow(0 0 8px rgba(0, 242, 254, 0.4));
}

#ai-document-dialog .modal-close {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: var(--doc-danger-text);
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 18px;
}

#ai-document-dialog .modal-close:hover {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.4);
    color: #ef4444;
    transform: rotate(90deg) scale(1.1);
}

#ai-document-dialog .modal-body {
    padding: 28px;
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.1) transparent;
    background: rgba(10, 14, 39, 0.4);
}

#ai-document-dialog .modal-body::-webkit-scrollbar {
    width: 6px;
}

#ai-document-dialog .modal-body::-webkit-scrollbar-track {
    background: rgba(10, 14, 39, 0.3);
    border-radius: 4px;
}

#ai-document-dialog .modal-body::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

#ai-document-dialog .modal-body::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.18);
}

#ai-document-dialog .form-group {
    margin-bottom: 24px;
}

#ai-document-dialog .form-group label {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.87);
    font-size: 14px;
    text-transform: none;
    letter-spacing: normal;
}

#ai-document-dialog .form-group label i {
    color: rgba(0, 242, 254, 0.5);
    font-size: 18px;
}

#ai-document-dialog .form-control {
    width: 100%;
    padding: 14px 16px;
    background: rgba(10, 14, 39, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 12px;
    color: rgba(255, 255, 255, 0.9);
    font-size: 15px;
    transition: all 0.3s ease;
    font-family: inherit;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.1);
}

#ai-document-dialog .form-control:hover {
    border-color: rgba(255, 255, 255, 0.12);
    background: rgba(10, 14, 39, 0.7);
}

#ai-document-dialog .form-control:focus {
    outline: none;
    border-color: rgba(0, 242, 254, 0.3);
    box-shadow:
        0 0 0 3px rgba(0, 242, 254, 0.08),
        0 0 20px rgba(0, 242, 254, 0.05),
        inset 0 1px 3px rgba(0, 0, 0, 0.1);
    background: rgba(10, 14, 39, 0.8);
}

#ai-document-dialog .form-control::placeholder {
    color: rgba(255, 255, 255, 0.3);
    opacity: 0.7;
}

#ai-document-dialog select.form-control {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2300f2fe' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 20px;
    padding-right: 40px;
}

#ai-document-dialog textarea.form-control {
    resize: vertical;
    min-height: 120px;
    line-height: 1.6;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
}

#ai-document-dialog .form-hint {
    display: block;
    margin-top: 8px;
    font-size: 12px;
    color: rgba(255, 255, 255, 0.38);
    font-style: italic;
}

#ai-document-dialog .form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

#ai-document-dialog .form-col {
    margin-bottom: 0;
}

#ai-document-dialog .checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    margin-right: 20px;
    margin-bottom: 8px;
    cursor: pointer;
    color: rgba(255, 255, 255, 0.87);
    font-size: 14px;
    transition: color 0.2s ease;
    text-transform: none;
}

#ai-document-dialog .checkbox-label:hover {
    color: rgba(0, 242, 254, 0.7);
}

#ai-document-dialog .checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--doc-accent-cyan);
    border-radius: 4px;
}

/* In-dialog status panel CSS removed 2026-05-12 along with the
   corresponding markup and JS. Generation progress now surfaces
   via yellow/green/red cards in the documents sidebar (see
   .document-item.is-generating / .is-completed / .is-failed)
   so the dialog can close immediately on submit. */

#ai-document-dialog .modal-footer {
    padding: 20px 28px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    background: linear-gradient(135deg, rgba(21, 26, 53, 0.8) 0%, rgba(15, 20, 45, 0.85) 100%);
    flex-shrink: 0;
}

#ai-document-dialog .btn {
    padding: 12px 24px;
    border-radius: 0.625rem;
    font-weight: 600;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s ease;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    text-transform: none;
    letter-spacing: normal;
}

#ai-document-dialog .btn-secondary {
    background: rgba(255, 255, 255, 0.04);
    color: rgba(255, 255, 255, 0.7);
    border: 1px solid rgba(255, 255, 255, 0.08);
}

#ai-document-dialog .btn-secondary:hover {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.9);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

#ai-document-dialog .btn-primary {
    /* Opaque CTA gradient — was rgba(...0.2) translucent and read as a
       muted secondary, indistinguishable from the actual secondary
       button next to it. The primary action in the dialog needs visual
       weight; this gradient matches the header "Generate Document" CTA
       so users see the same affordance in both surfaces. */
    background: linear-gradient(135deg, #7b68ee 0%, #00d4ff 100%);
    color: white;
    border: 1px solid rgba(0, 212, 255, 0.6);
    box-shadow: 0 4px 20px rgba(0, 212, 255, 0.25), 0 2px 6px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
}

#ai-document-dialog .btn-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, #8c7bf0 0%, #1ce0ff 100%);
    transform: translateY(-2px);
    box-shadow: 0 8px 28px rgba(0, 212, 255, 0.40), 0 4px 12px rgba(0, 0, 0, 0.35);
    border-color: rgba(0, 212, 255, 0.85);
}

#ai-document-dialog .btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

#ai-document-dialog .btn-primary:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

#ai-document-dialog .btn i {
    font-size: 16px;
}

/* @keyframes fadeIn and spin defined in design-system.css */

@keyframes premiumModalIn {
    from {
        transform: translateY(30px) scale(0.95);
        opacity: 0;
    }
    to {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

@keyframes premiumModalOut {
    from {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
    to {
        transform: translateY(-15px) scale(0.97);
        opacity: 0;
    }
}

/* ===================================
   PART 3: COMING SOON COMPONENTS
   =================================== */

html body .nav-item-coming-soon {
    position: relative;
    opacity: 0.7;
    cursor: not-allowed;
    pointer-events: none;
}

.nav-item-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-coming-soon-badge {
    position: absolute;
    top: 8px;
    right: 12px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.6) 0%, rgba(118, 75, 162, 0.6) 100%);
    color: white;
    font-size: 8px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    z-index: var(--z-dropdown, 100);
}

.nav-item-tooltip {
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    margin-left: 15px;
    background: linear-gradient(135deg, rgba(21, 26, 53, 0.98) 0%, rgba(30, 37, 64, 0.98) 100%);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.75rem;
    padding: 1rem 1.25rem;
    min-width: 280px;
    max-width: 320px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
    z-index: var(--z-tooltip, 1250);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    pointer-events: none;
}

.nav-item-coming-soon:hover .nav-item-tooltip {
    opacity: 1;
    visibility: visible;
    margin-left: 20px;
}

.nav-item-tooltip strong {
    display: block;
    color: rgba(0, 242, 254, 0.7);
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 0.5rem;
    letter-spacing: 0.3px;
}

.nav-item-tooltip p {
    color: rgba(255, 255, 255, 0.85);
    font-size: 13px;
    line-height: 1.6;
    margin: 0;
}

.nav-item-tooltip::before {
    content: '';
    position: absolute;
    left: -8px;
    top: 50%;
    transform: translateY(-50%);
    width: 0;
    height: 0;
    border-top: 8px solid transparent;
    border-bottom: 8px solid transparent;
    border-right: 8px solid rgba(255, 255, 255, 0.08);
}

.coming-soon-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: linear-gradient(135deg, rgba(102, 126, 234, 0.6) 0%, rgba(118, 75, 162, 0.6) 100%);
    color: white;
    font-size: 10px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    z-index: var(--z-dropdown, 100);
}

/* (pulse-glow @keyframes removed — defined but unreferenced) */

html body .document-ai-panel-coming-soon {
    display: flex;
    width: 300px;
    min-width: 300px;
    flex-shrink: 0;
    background: var(--doc-gradient-card);
    border-left: 1px solid var(--doc-glass-border);
    border-radius: 0;
    backdrop-filter: blur(24px) saturate(1.3);
    -webkit-backdrop-filter: blur(24px) saturate(1.3);
    box-shadow:
        -4px 0 16px rgba(0, 0, 0, 0.15),
        -1px 0 3px rgba(0, 0, 0, 0.1),
        inset 1px 0 0 rgba(255, 255, 255, 0.03);
    overflow: hidden;
    position: relative;
}

.coming-soon-badge-top {
    position: absolute;
    top: 16px;
    right: 16px;
    background: linear-gradient(135deg, rgba(118, 75, 162, 0.3) 0%, rgba(0, 242, 254, 0.2) 100%);
    color: rgba(255, 255, 255, 0.85);
    font-size: 9px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 2rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    border: 1px solid rgba(0, 242, 254, 0.15);
    box-shadow: 0 2px 12px rgba(0, 242, 254, 0.1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: var(--z-dropdown, 100);
    display: inline-block;
}

.document-ai-panel-coming-soon::before {
    z-index: var(--z-base, 1);
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: 
        radial-gradient(ellipse at 30% 20%, rgba(0, 242, 254, 0.04) 0%, transparent 50%),
        radial-gradient(ellipse at 70% 80%, rgba(118, 75, 162, 0.05) 0%, transparent 50%);
    pointer-events: none;
    animation: backgroundShift 20s ease-in-out infinite;
}

@keyframes backgroundShift {
    0%, 100% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }
    50% {
        opacity: 0.8;
        transform: translate(-10px, 10px) scale(1.05);
    }
}

.coming-soon-container {
    width: 100%;
    padding: 3rem 2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    z-index: var(--z-base, 1);
}

.coming-soon-content {
    text-align: center;
    max-width: 400px;
}

.coming-soon-icon {
    font-size: 4rem;
    background: linear-gradient(135deg, rgba(0, 242, 254, 0.7) 0%, rgba(118, 75, 162, 0.6) 50%, rgba(247, 37, 133, 0.5) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 1.5rem;
    animation: float 4s ease-in-out infinite;
}

/* (iconGlow @keyframes removed — defined with both stops as no-op `filter: none` and unreferenced) */

/* @keyframes float — local fallback so this animation works even when
 * shared-crypto.css is not loaded (e.g. user role that doesn't include
 * crypto features, or load-order drift). If shared-crypto.css IS loaded
 * its definition supersedes this one harmlessly. */
@keyframes float {
    0%, 100% { transform: translateY(0); }
    50%      { transform: translateY(-10px); }
}

.coming-soon-title {
    font-size: 1.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #ffffff 0%, var(--doc-accent-cyan) 50%, var(--doc-accent-purple) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 0.75rem;
    letter-spacing: -0.3px;
}

.coming-soon-description {
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.45);
    line-height: 1.65;
    margin-bottom: 1.75rem;
}

.coming-soon-features {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 2rem;
}

.feature-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(0, 242, 254, 0.06);
    border-radius: 0.75rem;
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.feature-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(0, 242, 254, 0.06), rgba(255, 255, 255, 0.06), rgba(0, 242, 254, 0.06), transparent);
    transition: left 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

.feature-item:hover::before {
    left: 100%;
}

.feature-item:hover {
    background: rgba(0, 242, 254, 0.04);
    border-color: rgba(0, 242, 254, 0.15);
    transform: translateX(6px) scale(1.01);
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.15), 0 0 20px rgba(0, 242, 254, 0.06);
}

.feature-item i {
    color: rgba(0, 242, 254, 0.45);
    font-size: 1rem;
}

.coming-soon-badge-large {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.5rem;
    background: linear-gradient(135deg, rgba(118, 75, 162, 0.25) 0%, rgba(0, 242, 254, 0.15) 100%);
    color: rgba(255, 255, 255, 0.85);
    font-size: 0.85rem;
    font-weight: 700;
    border-radius: 2rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    border: 1px solid rgba(0, 242, 254, 0.15);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

/* (pulse-badge @keyframes removed — defined but unreferenced) */

.coming-soon-badge-large i {
    animation: rocket 1.5s ease-in-out infinite;
}

@keyframes rocket {
    0%, 100% {
        transform: translateY(0px) rotate(-45deg);
    }
    50% {
        transform: translateY(-5px) rotate(-45deg);
    }
}

/* ===================================
   PART 4: WORKSPACE DOCUMENTS VIEW OVERRIDES
   =================================== */

#documents-view,
#documents-view.documents-view {
    position: relative;
    top: auto;
    left: auto;
    right: auto;
    bottom: auto;
    width: 100%;
    height: auto;
    min-height: calc(100vh - 120px);
}

/* Visibility: #documents-view.is-hidden defined in workspace/workspace.css */

#documents-view .document-writer-container {
    height: 100%;
    width: 100%;
    display: flex;
    flex-direction: column;
}

/* ========== Quality flags warning banner (Phase 4) ========== */
/* Appears above the editor/preview when the writer service returned
   document.quality_flags (citations_unavailable, sections_unavailable,
   research_unavailable). Gives users a clear amber signal that the
   document shipped with known limitations. */

.quality-warning-banner {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    margin: 0 0 12px 0;
    background: linear-gradient(
        135deg,
        rgba(251, 191, 36, 0.08),
        rgba(251, 191, 36, 0.03)
    );
    border: 1px solid rgba(251, 191, 36, 0.3);
    border-left: 3px solid rgba(251, 191, 36, 0.8);
    border-radius: 0.5rem;
    color: rgba(254, 243, 199, 0.95);
    font-size: 0.9rem;
    line-height: 1.5;
}
.quality-warning-banner.is-hidden {
    display: none;
}
.quality-warning-banner .qfb-icon {
    flex-shrink: 0;
    color: rgba(251, 191, 36, 0.9);
    font-size: 1.1rem;
    padding-top: 2px;
}
.quality-warning-banner .qfb-body {
    flex: 1;
    min-width: 0;
}
.quality-warning-banner .qfb-title {
    font-weight: 600;
    color: rgba(254, 243, 199, 1);
    margin-bottom: 6px;
}
.quality-warning-banner .qfb-list {
    margin: 0;
    padding-left: 18px;
    list-style: disc;
}
.quality-warning-banner .qfb-list li {
    margin: 2px 0;
}
.quality-warning-banner .qfb-flag {
    background: rgba(251, 191, 36, 0.12);
    color: rgba(254, 243, 199, 1);
    padding: 1px 6px;
    border-radius: 0.25rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8em;
    border: 1px solid rgba(251, 191, 36, 0.25);
}
.quality-warning-banner .qfb-dismiss {
    flex-shrink: 0;
    background: transparent;
    border: none;
    color: rgba(254, 243, 199, 0.6);
    font-size: 1.4rem;
    line-height: 1;
    cursor: pointer;
    /* WCAG 2.5.5 Target Size: ≥44×44px touch target. The previous
     * `padding: 0 4px` produced ~22×22px which is below the AA minimum
     * for touch / fat-finger interaction. Padding inflates the hit area;
     * negative margin keeps the visual position unchanged. */
    padding: 12px;
    min-width: 44px;
    min-height: 44px;
    margin: -12px;
    transition: color 0.15s ease;
}
.quality-warning-banner .qfb-dismiss:hover {
    color: rgba(254, 243, 199, 1);
}

/* ========== Structured sources panel (Phase 4) ========== */
/* Collapsible <details> panel below the editor/preview that lists
   every source returned by the writer's sources array. Native
   <details> means it can't overlap content (the previous sources
   pills panel was removed for exactly that reason). */

.sources-panel {
    margin: 16px 0 24px 0;
    background: linear-gradient(
        135deg,
        rgba(118, 75, 162, 0.04),
        rgba(0, 242, 254, 0.03)
    );
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 0.75rem;
    overflow: hidden;
    color: var(--doc-text-primary);
}
.sources-panel.is-hidden {
    display: none;
}
.sources-panel-summary {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    cursor: pointer;
    user-select: none;
    list-style: none;
    font-size: 0.95rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    transition: background 0.15s ease;
}
.sources-panel-summary::-webkit-details-marker {
    display: none;
}
.sources-panel-summary:hover {
    background: rgba(255, 255, 255, 0.03);
}
.sources-panel-icon {
    color: rgba(0, 242, 254, 0.8);
    font-size: 0.9rem;
}
.sources-panel-label {
    flex: 0 0 auto;
}
.sources-panel-count {
    flex: 0 0 auto;
    background: rgba(0, 242, 254, 0.12);
    color: rgba(0, 242, 254, 0.95);
    border: 1px solid rgba(0, 242, 254, 0.25);
    padding: 1px 8px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
}
.sources-panel-chevron {
    margin-left: auto;
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.75rem;
    transition: transform 0.2s ease;
}
.sources-panel[open] .sources-panel-chevron {
    transform: rotate(180deg);
}
/* When the panel is open, cap height + scroll. A research doc can return
 * 20+ sources; without this the list pushes everything below it off-screen
 * and the user can't see the editor footer / stats. */
.sources-panel[open] {
    max-height: 400px;
    overflow-y: auto;
}
.sources-panel-list {
    list-style: decimal;
    margin: 0;
    padding: 0 16px 16px 42px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    padding-top: 14px;
}
.sources-panel-item {
    margin: 10px 0;
    padding: 6px 0;
    color: rgba(255, 255, 255, 0.85);
}
.sources-panel-item::marker {
    color: rgba(0, 242, 254, 0.7);
    font-weight: 700;
    font-family: 'JetBrains Mono', monospace;
}
.sources-panel-link {
    color: rgba(0, 242, 254, 0.9);
    text-decoration: none;
    font-weight: 500;
    line-height: 1.4;
    display: inline-block;
    transition: color 0.15s ease;
}
.sources-panel-link:hover {
    color: rgba(118, 75, 162, 1);
    text-decoration: underline;
}
.sources-panel-meta {
    margin-top: 4px;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.45);
}
.sources-panel-meta-author {
    font-weight: 600;
    color: rgba(255, 255, 255, 0.6);
}
.sources-panel-meta-section {
    font-style: italic;
    color: rgba(0, 242, 254, 0.6);
}

/* ========== Export buttons compact styling (Phase 4) ========== */
/* The Copy MD / Copy HTML / Print buttons sit in the header alongside
   Preview and Save. The header row is flex-wrap: nowrap, so with the
   full "Copy MD" / "Copy HTML" / "Print" labels the row overflows and
   overlaps neighbouring buttons on normal-width screens. Drop the
   visible labels entirely (tooltips on the <button title="..."> still
   give users affordance on hover) and tighten padding so each button
   becomes an icon chip rather than a wide pill. */

#copy-markdown-btn .btn-label,
#copy-html-btn .btn-label,
#print-document-btn .btn-label {
    display: none;
}
#copy-markdown-btn,
#copy-html-btn,
#print-document-btn {
    padding: 0.6rem 0.75rem;
}

/* ========== Print stylesheet (Phase 4) ========== */
/* Strip every UI chrome element when the user prints the page so
   they get a clean, readable document on paper. The JS print handler
   ensures the preview pane is populated and visible before calling
   window.print(); this stylesheet then hides everything except the
   preview content and converts the dark theme to a high-contrast
   light theme suitable for ink. */

/* `@page` MUST sit at the top level of the stylesheet. Safari \u226415
   silently ignores `@page` rules nested inside `@media print { \u2026 }`,
   which strips the controlled page margins and lets the browser default
   (varies by user setting) take over. Hoisting it outside `@media print`
   guarantees consistent margins across browsers. */
@page {
    margin: 1.5cm 1.8cm;
}

@media print {
    /* Kill the dark background \u2014 printers and reader apps expect
       white paper. */
    html, body {
        background: white !important;
        color: #000 !important;
    }

    /* Apply print-color-adjust to the entire preview pane container too,
       not just .preview-content. The legacy direct-print path (Ctrl+P
       without opening the modal) prints #preview-pane directly; without
       this rule Chrome strips the pane's background and any pseudo-element
       tinting before sending to the printer/PDF engine. */
    #preview-pane {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    /* Hide every chrome element: sidebars, nav, header buttons,
       toolbars, footers, banners, the coming-soon smart editor
       panel, the sources-panel chevron, and the editor textarea
       itself (we print the preview instead). */
    #doc-writer-sidebar,
    .document-header,
    .mobile-save-indicator,
    .mobile-overflow-btn,
    .editor-toolbar,
    .editor-footer,
    .editor-sidebar,
    .smart-editor-panel,
    .doc-mobile-menu-toggle,
    #quality-flags-banner,
    .markdown-editor,
    .sources-panel-summary .sources-panel-chevron,
    .workspace-sidebar,
    .workspace-navbar,
    .workspace-header {
        display: none !important;
    }

    /* Force the preview pane visible even when the editor was the
       active view \u2014 the JS handler toggles this at runtime, but
       the stylesheet is the safety net. */
    #preview-pane,
    #preview-pane.is-hidden {
        display: block !important;
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        height: auto !important;
        overflow: visible !important;
        padding: 0 !important;
        background: white !important;
    }

    /* Preview content: light theme but PRESERVES the preview's premium feel
       (typography scale, generous line-height, brand cyan as accent). This
       block was previously aggressive about stripping styling for "print-
       safety"; the result was a black-and-white doc that bore no resemblance
       to the on-screen preview the user just authored. We can keep brand
       identity AND be ink-friendly — modern colour laser/inkjet handles
       light cyan tints just fine, and screen colour intent is to be
       *suggested* in print, not surgically removed.

       `print-color-adjust: exact` (and the legacy -webkit- prefix) asks the
       browser to honour background colours instead of stripping them as
       a "save ink" optimisation. Critical for the metadata header pill. */
    .preview-content,
    .preview-content * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
    .preview-content {
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        color: #1a1a1a !important;
        background: white !important;
        /* 12pt + 1.75 line-height matches the preview's 18px/1.8 ratio at
           A4/Letter widths — readable, with breathing room. */
        font-size: 12pt !important;
        line-height: 1.75 !important;
    }
    .preview-content h1,
    .preview-content h2,
    .preview-content h3,
    .preview-content h4 {
        color: #0a0e27 !important; /* match preview's near-black */
        page-break-after: avoid;
        letter-spacing: -0.3px;
        margin-top: 1.4em;
        margin-bottom: 0.5em;
    }
    .preview-content h1 {
        font-size: 24pt !important;
        font-weight: 700 !important;
        border-bottom: 1px solid #0a0e27 !important;
        padding-bottom: 0.4em;
    }
    .preview-content h2 {
        font-size: 17pt !important;
        font-weight: 700 !important;
        border-bottom: 1px solid #888 !important;
        padding-bottom: 0.3em;
    }
    .preview-content h3 {
        font-size: 13pt !important;
        font-weight: 700 !important;
    }
    .preview-content p,
    .preview-content li {
        color: #222 !important;
    }
    .preview-content strong { color: #0a0e27 !important; font-weight: 700 !important; }
    .preview-content a {
        /* Darker cyan = readable as text in ink, still on-brand */
        color: #006978 !important;
        text-decoration: underline !important;
    }
    .preview-content code {
        background: #f4f4f4 !important;
        color: #c7254e !important;
        border: 1px solid #ddd !important;
        padding: 0.1em 0.35em;
        border-radius: 3px;
        font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace !important;
        font-size: 0.9em !important;
    }
    .preview-content pre {
        background: #f9f9f9 !important;
        border: 1px solid #ddd !important;
        color: #111 !important;
        page-break-inside: avoid;
        padding: 1em;
        border-radius: 6px;
    }
    .preview-content blockquote {
        /* Cyan accent bar on the left mirrors the preview's gradient border */
        border-left: 3px solid #00838f !important;
        background: #f6fbfc !important;
        color: #333 !important;
        font-style: italic;
        padding: 0.5em 1em;
        margin: 1em 0;
    }
    .preview-content table {
        border-collapse: collapse !important;
        page-break-inside: avoid;
        margin: 1em 0;
    }
    .preview-content table th,
    .preview-content table td {
        border: 1px solid #666 !important;
        color: #111 !important;
        padding: 0.5em 0.75em;
    }
    .preview-content table th {
        background: #e0f4f7 !important; /* light cyan, mirrors preview's th tint */
        color: #0a0e27 !important;
        font-weight: 600 !important;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        font-size: 0.85em;
    }

    /* Document metadata pill — the "Mirror Markets · May 12, 2026" header.
       Previously stripped to plain text on white; restored to match the
       preview's branded pill (light cyan tint + cyan border + cyan brand
       text). Critical for premium-doc feel — the user spends effort on the
       on-screen preview and expects the print to reflect it. */
    .preview-content .doc-metadata-header {
        display: flex !important;
        align-items: center;
        gap: 12px;
        padding: 10px 16px !important;
        background: #ecfafd !important;
        border: 1px solid #b8e5ed !important;
        border-radius: 6px !important;
        margin-bottom: 18px !important;
        font-size: 0.92em;
        page-break-inside: avoid;
    }
    .preview-content .doc-brand {
        font-weight: 700 !important;
        color: #006978 !important; /* print-safe brand cyan */
    }
    .preview-content .doc-date {
        color: #555 !important;
    }
    .preview-content .doc-author {
        font-style: italic;
        color: #555 !important;
        margin-bottom: 24px;
    }
    .preview-content .doc-byline {
        display: flex !important;
        align-items: center;
        gap: 6px;
        color: #555 !important;
        font-size: 0.92em;
        margin-bottom: 24px;
        padding-bottom: 16px;
        border-bottom: 1px solid #ddd !important;
    }
    .preview-content .byline-author { font-weight: 600 !important; color: #1a1a1a !important; }
    .preview-content .references-section,
    .preview-content .doc-disclaimer {
        border-top: 1px solid #aaa !important;
        margin-top: 1.5em;
        padding-top: 1em;
    }
    .preview-content .doc-disclaimer {
        font-size: 0.85em;
        color: #666 !important;
    }

    /* Sources panel: always expanded, visible, light-themed. */
    .sources-panel {
        background: white !important;
        border: 1px solid #888 !important;
        color: #111 !important;
        page-break-inside: avoid;
    }
    .sources-panel[open],
    .sources-panel {
        /* force open so collapsed state doesn't hide sources */
        padding-bottom: 8px !important;
    }
    .sources-panel-list {
        display: block !important;
        border-top: 1px solid #888 !important;
        color: #111 !important;
    }
    .sources-panel-link {
        color: #0645ad !important;
    }
    .sources-panel-summary {
        color: #000 !important;
    }
    .sources-panel-count {
        background: #e8e8e8 !important;
        color: #000 !important;
        border-color: #888 !important;
    }

    /* Images: never overflow the page, never split mid-image. */
    .preview-content img {
        max-width: 100% !important;
        height: auto !important;
        display: block !important;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* Code blocks: wrap on the print path (the on-screen `overflow-x: auto`
       scrollbar doesn't exist on paper). */
    .preview-content pre {
        white-space: pre-wrap !important;
        word-break: break-word !important;
        overflow-wrap: anywhere !important;
        overflow-x: visible !important;
    }

    /* Tables: full width on paper so they don't render at content width
       and look misaligned next to wider paragraphs. */
    .preview-content table {
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Typographic widows/orphans control: no single lonely line at the
       top or bottom of a page. */
    .preview-content p,
    .preview-content li {
        orphans: 3;
        widows: 3;
    }

    /* Modern break-after property \u2014 supplements the legacy page-break-after
       declarations above for browsers that prefer the unprefixed spec. */
    .preview-content h1,
    .preview-content h2,
    .preview-content h3,
    .preview-content h4 {
        break-after: avoid;
    }

    /* ---- Print preview modal scoping ----
       When the print-preview modal is open, the user has explicitly
       opted into the curated paper canvas. Hide every workspace
       chrome element AND the modal's own controls, leaving only the
       `.print-preview-paper` content visible. The existing chrome-
       hiding rules above still apply for the legacy direct Ctrl+P
       path. */
    body.is-print-preview-active .workspace-sidebar,
    body.is-print-preview-active .workspace-navbar,
    body.is-print-preview-active .workspace-header,
    body.is-print-preview-active .ambient-background,
    body.is-print-preview-active .floating-nav,
    body.is-print-preview-active #ai-document-dialog,
    body.is-print-preview-active .toast-container,
    body.is-print-preview-active #documents-view {
        display: none !important;
    }
    body.is-print-preview-active .print-preview-modal {
        position: static !important;
        background: white !important;
        display: block !important;
        padding: 0 !important;
        margin: 0 !important;
        height: auto !important;
        overflow: visible !important;
    }
    body.is-print-preview-active .print-preview-modal .print-preview-header,
    body.is-print-preview-active .print-preview-modal .print-preview-actions {
        display: none !important;
    }
    body.is-print-preview-active .print-preview-modal .print-preview-body {
        position: static !important;
        background: white !important;
        padding: 0 !important;
        margin: 0 !important;
        height: auto !important;
        overflow: visible !important;
    }
    body.is-print-preview-active .print-preview-modal .print-preview-paper {
        position: static !important;
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 0 !important;
        background: white !important;
        box-shadow: none !important;
        border: none !important;
        border-radius: 0 !important;
        min-height: 0 !important;
    }
}

/* ============================================================================
   Active task cards (yellow / green / red states)
   ============================================================================
   Rendered above the saved-docs list in #recent-documents-list. State is
   conveyed through both an accent border-left and an icon so colour alone
   isn't the only cue (WCAG 1.4.1).
   - is-generating  = yellow  = AI generation in progress
   - is-completed   = green   = saved to DB, awaiting user to open it
   - is-failed      = red     = task failed; user can dismiss / regenerate
   ============================================================================ */
.active-task-cards {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.active-task-cards.is-empty {
    /* Don't reserve list space when no tasks are running. */
    display: none;
}

.document-item.is-generating,
.document-item.is-completed,
.document-item.is-failed {
    border-left-width: 3px;
    border-left-style: solid;
    /* The colour-coded left border replaces the default cyan accent
       bar (.document-item::before scaleY(0) \u2192 scaleY(1) on hover). */
    transition: background 0.25s ease, border-color 0.25s ease, transform 0.25s ease;
}

/* Suppress the default cyan accent bar \u2014 the coloured left border
   IS the state indicator and a second cyan stripe on hover would
   muddle the visual signal. */
.document-item.is-generating::before,
.document-item.is-completed::before,
.document-item.is-failed::before {
    display: none;
}

/* Per-state colour + glow.
   Solid colours sourced from design-system tokens (--color-warning /
   --color-success / --color-error). The rgba() background tints keep
   their literal channels so the soft glass-tinting effect doesn't
   depend on a CSS-variable-aware colour function. */
.document-item.is-generating {
    border-left-color: var(--color-warning);
    background: rgba(245, 158, 11, 0.07);
}
.document-item.is-generating:hover {
    background: rgba(245, 158, 11, 0.11);
    border-color: rgba(245, 158, 11, 0.4);
    border-left-color: var(--color-warning);
    box-shadow: 0 4px 18px rgba(245, 158, 11, 0.10);
}
.document-item.is-generating:focus-visible {
    outline: 2px solid var(--color-warning);
    outline-offset: 2px;
}

.document-item.is-completed {
    border-left-color: var(--color-success);
    background: rgba(16, 185, 129, 0.07);
    cursor: pointer;
}
.document-item.is-completed:hover {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.45);
    border-left-color: var(--color-success);
    box-shadow: 0 4px 22px rgba(16, 185, 129, 0.18);
}
.document-item.is-completed:focus-visible {
    outline: 2px solid var(--color-success);
    outline-offset: 2px;
}

.document-item.is-failed {
    border-left-color: var(--color-error);
    background: rgba(239, 68, 68, 0.06);
}
.document-item.is-failed:hover {
    background: rgba(239, 68, 68, 0.10);
    border-color: rgba(239, 68, 68, 0.40);
    border-left-color: var(--color-error);
    box-shadow: 0 4px 18px rgba(239, 68, 68, 0.12);
}
.document-item.is-failed:focus-visible {
    outline: 2px solid var(--color-error);
    outline-offset: 2px;
}

/* Dismiss-X focus ring on red/green cards. */
.doc-task-dismiss:focus-visible {
    outline: 2px solid var(--color-error);
    outline-offset: 2px;
    background: rgba(239, 68, 68, 0.15);
}

/* State icons */
.doc-task-icon {
    margin-right: 8px;
    font-size: 0.95rem;
    vertical-align: -1px;
}
.document-item.is-generating .doc-task-icon { color: var(--color-warning); }
.document-item.is-completed .doc-task-icon  { color: var(--color-success); }
.document-item.is-failed .doc-task-icon     { color: var(--color-error); }

.task-topic {
    font-weight: 500;
}
.task-stage,
.task-ready,
.task-error {
    font-size: 0.78rem;
    /* 0.85 alpha for AA contrast against the tinted card backgrounds.
       At 0.7 the small text fell into WCAG borderline (~4.8:1). */
    color: rgba(224, 230, 237, 0.85);
}
.task-error {
    color: rgba(254, 202, 202, 0.95);
}
/* Live 10-minute countdown on the yellow (generating) card. margin-left:auto
   pushes it to the right edge of the .document-meta row — and since the
   generating card has no .document-actions, that edge is the card's right
   edge, so the timer sits bottom-right. Tabular figures keep it from
   shifting width as the digits change. */
.task-countdown {
    margin-left: auto;
    font-size: 0.78rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.5px;
    color: var(--doc-accent-cyan, #00f2fe);
    white-space: nowrap;
}
/* Past 0:00 the generation is wrapping up — cool the countdown to a muted
   tone so it stops reading as "time pressure". */
.document-item.is-generating.is-finalizing .task-countdown {
    color: rgba(224, 230, 237, 0.6);
}
/* Inline "Generation started" panel that briefly replaces the AI dialog
   body before the modal closes — gives the user a prominent confirmation
   instead of just a corner toast. */
.ai-dialog-success-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 36px 32px 24px;
    min-height: 220px;
    animation: aiDialogSuccessIn 240ms cubic-bezier(0.4, 0, 0.2, 1);
}
.ai-dialog-success-state.is-hidden {
    display: none !important;
}
.ai-dialog-success-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at 30% 30%,
        rgba(16, 185, 129, 0.35) 0%,
        rgba(16, 185, 129, 0.12) 60%,
        rgba(16, 185, 129, 0) 100%);
    box-shadow:
        0 0 0 4px rgba(16, 185, 129, 0.15),
        0 8px 28px rgba(16, 185, 129, 0.25);
    color: var(--color-success);
    font-size: 1.6rem;
    margin-bottom: 16px;
    animation: aiDialogSuccessIcon 360ms cubic-bezier(0.34, 1.56, 0.64, 1);
}
.ai-dialog-success-title {
    margin: 0 0 8px;
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--doc-text-primary, #e0e6ed);
    letter-spacing: -0.01em;
}
.ai-dialog-success-body {
    margin: 0;
    font-size: 0.92rem;
    line-height: 1.55;
    color: rgba(224, 230, 237, 0.7);
    max-width: 420px;
}
@keyframes aiDialogSuccessIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}
@keyframes aiDialogSuccessIcon {
    0%   { transform: scale(0.4); opacity: 0; }
    60%  { transform: scale(1.15); opacity: 1; }
    100% { transform: scale(1); }
}
@media (prefers-reduced-motion: reduce) {
    .ai-dialog-success-state,
    .ai-dialog-success-icon {
        animation: none !important;
    }
}

/* ── Generating / Ready / Failed dialog panel variants ────────────────────
   All three render into the shared .ai-dialog-success-state container. The
   generating panel adds explore links + a live countdown; the failed panel
   recolors the icon. */

/* Generating icon: swap the green success gradient for the brand button
   gradient so a spinner reads as "in progress", not "done". */
.ai-dialog-generating-icon {
    background: radial-gradient(circle at 30% 30%,
        rgba(123, 104, 238, 0.38) 0%,
        rgba(0, 212, 255, 0.14) 60%,
        rgba(0, 212, 255, 0) 100%);
    box-shadow:
        0 0 0 4px rgba(123, 104, 238, 0.15),
        0 8px 28px rgba(0, 212, 255, 0.22);
    color: var(--doc-accent-cyan, #00f2fe);
}

/* Failed icon: danger tint. */
.ai-dialog-failed-icon {
    background: radial-gradient(circle at 30% 30%,
        rgba(239, 68, 68, 0.35) 0%,
        rgba(239, 68, 68, 0.12) 60%,
        rgba(239, 68, 68, 0) 100%);
    box-shadow:
        0 0 0 4px rgba(239, 68, 68, 0.15),
        0 8px 28px rgba(239, 68, 68, 0.25);
    color: var(--doc-danger-text, #f87171);
}

/* "Explore other services" links shown while the document generates. */
.ai-dialog-explore-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin: 18px 0 4px;
}
.ai-dialog-explore-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 10px 18px;
    border-radius: 999px;
    border: 1px solid var(--doc-glass-border, rgba(255, 255, 255, 0.08));
    background: rgba(255, 255, 255, 0.04);
    color: var(--doc-text-secondary, rgba(255, 255, 255, 0.87));
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}
.ai-dialog-explore-link i {
    color: var(--doc-accent-cyan, #00f2fe);
    font-size: 0.95rem;
}
.ai-dialog-explore-link:hover {
    background: rgba(123, 104, 238, 0.16);
    border-color: rgba(123, 104, 238, 0.45);
    color: #fff;
    transform: translateY(-1px);
}
.ai-dialog-explore-link:focus-visible {
    outline: 2px solid var(--doc-accent-cyan, #00f2fe);
    outline-offset: 2px;
}

/* Big live countdown beneath the explore links. */
.ai-dialog-countdown {
    margin-top: 18px;
    font-size: 2.1rem;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.5px;
    line-height: 1;
    color: var(--doc-text-primary, #fff);
}
.ai-dialog-countdown-caption {
    margin: 6px 0 0;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--doc-text-muted, rgba(255, 255, 255, 0.6));
}

/* Terminal-state action row (Open document / Try again / Close). */
.ai-dialog-ready-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
}

/* Reduced motion: kill the spinner on the generating icon (numbers still
   tick — that's text content, not animation). */
@media (prefers-reduced-motion: reduce) {
    .ai-dialog-generating-icon .fa-spin {
        animation: none !important;
    }
}

/* The dismiss X on red/green cards reuses the .doc-action-btn shape
   but with a tinted hover so the affordance reads as destructive. */
.doc-task-dismiss:hover {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
}

/* Respect reduced-motion: stop the spinner animation on yellow cards. */
@media (prefers-reduced-motion: reduce) {
    .document-item.is-generating .doc-task-icon.fa-spin {
        animation: none !important;
    }
    .document-item.is-generating,
    .document-item.is-completed,
    .document-item.is-failed {
        transition: none !important;
    }
}

/* ============================================================================
   Print preview modal
   ============================================================================
   Full-screen overlay that previews the document on a paper-style canvas
   before printing. Triggered by the Print button; closed via Esc, the
   close X, or backdrop click. The actual printing happens via
   window.print() while body.is-print-preview-active is set \u2014 the @media
   print rules above scope output to .print-preview-paper.
   ============================================================================ */
.print-preview-modal {
    position: fixed;
    inset: 0;
    z-index: 10050;
    display: flex;
    flex-direction: column;
    background: rgba(6, 9, 24, 0.86);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    animation: ppmFadeIn 0.18s ease-out;
}
.print-preview-modal[aria-hidden="true"] {
    display: none;
}

@keyframes ppmFadeIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.print-preview-header {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    /* `max()` with the safe-area inset keeps Close/Print clear of the iPhone
       notch / Dynamic Island. Falls back to 14px on devices without insets. */
    padding: max(14px, env(safe-area-inset-top, 0px)) max(22px, env(safe-area-inset-right, 0px)) 14px max(22px, env(safe-area-inset-left, 0px));
    background: rgba(20, 26, 48, 0.92);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.print-preview-header h2 {
    margin: 0;
    color: #e0e6ed;
    font-size: 1rem;
    font-weight: 600;
    letter-spacing: -0.2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60%;
}
.print-preview-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}
/* Keep Print + Close from shrinking when the document title is long;
   the h2 already truncates with ellipsis via overflow:hidden. */
.print-preview-actions > button {
    flex-shrink: 0;
}

.print-preview-body {
    flex: 1 1 auto;
    overflow: auto;
    padding: 32px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.print-preview-paper {
    width: 100%;
    max-width: 820px;
    min-height: calc(11in - 64px);
    background: white;
    color: #1a1a1a;
    padding: 64px 72px;
    box-shadow:
        0 4px 24px rgba(0, 0, 0, 0.45),
        0 0 0 1px rgba(255, 255, 255, 0.04);
    border-radius: 4px;
    /* Faint horizontal page-break indicators every ~11in so the user
       gets a sense of where pages will split. The line sits 3px above
       the implied page edge so it doesn't visually collide with the
       paper's bottom border on a single-page document. */
    background-image: repeating-linear-gradient(
        to bottom,
        transparent 0,
        transparent calc(11in - 4px),
        rgba(0, 0, 0, 0.08) calc(11in - 4px),
        rgba(0, 0, 0, 0.08) calc(11in - 3px),
        transparent calc(11in - 3px),
        transparent 11in
    );
}

/* The paper's .preview-content reuses the existing on-screen preview
   styling so the user sees what they're about to print, exactly. */
.print-preview-paper .preview-content {
    color: #1a1a1a;
    font-size: 12pt;
    line-height: 1.75;
}
.print-preview-paper .preview-content h1,
.print-preview-paper .preview-content h2,
.print-preview-paper .preview-content h3,
.print-preview-paper .preview-content h4 {
    color: #0a0e27;
    letter-spacing: -0.3px;
}
.print-preview-paper .preview-content h1 {
    font-size: 24pt;
    border-bottom: 1px solid #0a0e27;
    padding-bottom: 0.4em;
    margin-top: 0;
}
.print-preview-paper .preview-content h2 {
    font-size: 17pt;
    border-bottom: 1px solid #888;
    padding-bottom: 0.3em;
}
.print-preview-paper .preview-content h3 {
    font-size: 13pt;
}
.print-preview-paper .preview-content a {
    color: #006978;
    text-decoration: underline;
}
.print-preview-paper .preview-content code {
    background: #f4f4f4;
    color: #c7254e;
    border: 1px solid #ddd;
    padding: 0.1em 0.35em;
    border-radius: 3px;
    font-family: 'JetBrains Mono', 'SF Mono', Consolas, monospace;
    font-size: 0.9em;
}
.print-preview-paper .preview-content pre {
    background: #f9f9f9;
    border: 1px solid #ddd;
    color: #111;
    padding: 1em;
    border-radius: 6px;
    /* Wrap long code lines so they don't overflow the ~676px content
       width of the paper canvas. Preserves whitespace within the line. */
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: anywhere;
}
.print-preview-paper .preview-content blockquote {
    border-left: 3px solid #00838f;
    background: #f6fbfc;
    color: #333;
    font-style: italic;
    padding: 0.5em 1em;
    margin: 1em 0;
}
.print-preview-paper .preview-content table {
    border-collapse: collapse;
    margin: 1em 0;
}
.print-preview-paper .preview-content table th,
.print-preview-paper .preview-content table td {
    border: 1px solid #666;
    color: #111;
    padding: 0.5em 0.75em;
}
.print-preview-paper .preview-content table th {
    background: #e0f4f7;
    color: #0a0e27;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-size: 0.85em;
}

/* Small-screen + reduced-motion fall-backs */
@media (max-width: 720px) {
    .print-preview-body { padding: 14px; }
    .print-preview-paper { padding: 24px 18px; min-height: 0; }
    .print-preview-header h2 { font-size: 0.92rem; max-width: 50%; }
}
@media (prefers-reduced-motion: reduce) {
    .print-preview-modal { animation: none; }
}

/* Visually-hidden utility for off-screen text that screen readers
   should still announce. Used by #task-announce (the polite live
   region for generation state transitions) and any future a11y
   announcements. Standard pattern; no other .sr-only exists at
   workspace scope. */
.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;
}

#documents-view .document-header {
    flex-shrink: 0;
}

#documents-view .document-main {
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

body.documents-mode #documents-view {
    display: flex;
}

/* Hide workspace help hint in documents mode to prevent overlap */
body.documents-mode .workspace-help-hint {
    display: none;
}

/* ===================================
   RESPONSIVE ADJUSTMENTS (Mobile)
   =================================== */

@media screen and (max-width: 767px) {
    .coming-soon-container {
        padding: 2rem 1.5rem;
    }
    
    .coming-soon-icon {
        font-size: 3rem;
        margin-bottom: 1rem;
    }
    
    .coming-soon-title {
        font-size: 1.5rem;
        margin-bottom: 0.75rem;
    }
    
    .coming-soon-description {
        font-size: 0.9rem;
        margin-bottom: 1.5rem;
    }
    
    .coming-soon-features {
        gap: 0.5rem;
        margin-bottom: 1.5rem;
    }
    
    .feature-item {
        padding: 0.5rem 0.75rem;
        font-size: 0.85rem;
    }
    
    .coming-soon-badge-large {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
    
    .coming-soon-badge {
        font-size: 9px;
        padding: 2px 6px;
    }

    #ai-document-dialog.modal-overlay {
        padding: 20px 15px;
    }

    #ai-document-dialog .modal-container {
        max-width: 100%;
        width: 100%;
        max-height: calc(100vh - 40px);
        max-height: calc(100svh - 40px);
    }

    #ai-document-dialog .modal-header {
        padding: 20px;
    }

    #ai-document-dialog .modal-header h2 {
        font-size: 18px;
    }

    #ai-document-dialog .modal-body {
        padding: 20px;
    }

    #ai-document-dialog .form-row {
        grid-template-columns: 1fr;
        gap: 0;
    }

    #ai-document-dialog .modal-footer {
        padding: 16px 20px;
        flex-direction: column;
        gap: 10px;
    }

    #ai-document-dialog .btn {
        width: 100%;
        justify-content: center;
    }
}

@media (max-width: 480px) {
    #ai-document-dialog.modal-overlay {
        padding: 10px;
    }
    
    #ai-document-dialog .modal-container {
        max-height: calc(100vh - 20px);
        max-height: calc(100svh - 20px);
    }

    #ai-document-dialog .modal-header {
        padding: 16px;
    }

    #ai-document-dialog .modal-body {
        padding: 16px;
    }

    #ai-document-dialog .modal-footer {
        padding: 12px 16px;
    }
}

@media screen and (min-width: 768px) {
    .document-ai-panel-coming-soon {
        min-height: 500px;
    }
}

/* ========================================
   18. REDUCED-MOTION & ACCESSIBILITY GUARDS
   ======================================== */

@media (prefers-reduced-motion: reduce) {
    /* Disable all ambient / looping animations */
    .documents-view,
    .document-header::after,
    .editor-footer::before,
    .document-sidebar::after,
    .document-ai-panel::before,
    .preview-pane::before,
    .markdown-editor:focus,
    .doc-tab-btn.active,
    .save-indicator.saving .save-dot::after,
    .save-indicator.saving .save-dot,
    .sidebar-brand-icon,
    .storage-bar-fill,
    .document-title-input:focus,
    .document-writer-container::before,
    .document-writer-container::after,
    .editor-container::before,
    .editor-content::before,
    .editor-content::after,
    .preview-pane::after,
    .storage-bar-fill::after,
    .sidebar-brand-icon::before,
    .sidebar-brand-text .sidebar-title,
    .document-item::after {
        animation: none !important;
    }

    /* Remove grain overlay */
    .documents-view::before {
        display: none !important;
    }

    /* Keep hover transforms but make them instant */
    .doc-btn,
    .doc-btn-primary,
    .doc-btn-secondary,
    .doc-btn-success,
    .toolbar-btn,
    .document-item,
    .feature-item,
    .ai-action-btn,
    .sidebar-brand-icon,
    .storage-bar-fill,
    .doc-tab-btn,
    .document-search input,
    .doc-action-btn {
        transition-duration: 0.01ms !important;
    }

    /* Disable staggered entrance */
    .document-item {
        animation: none !important;
        opacity: 1 !important;
    }

    /* Disable new onboarding animations */
    .ai-coach-mark,
    .coach-mark-fade-out {
        animation: none !important;
    }

    .empty-state-card,
    .doc-btn-ai {
        transition-duration: 0.01ms !important;
    }

    /* (in-dialog progress-bar reduced-motion override removed 2026-05-12;
       generation no longer renders progress inside the dialog. Task-card
       reduced-motion rules live alongside the cards themselves.) */
}



/* ========================================
   AI WRITE BUTTON
   ======================================== */
.doc-btn-ai {
    background: linear-gradient(135deg, rgba(123, 104, 238, 0.25) 0%, rgba(0, 212, 255, 0.2) 100%);
    color: #ffffff;
    border: 1px solid rgba(123, 104, 238, 0.35);
    font-weight: 700;
    box-shadow:
        0 2px 10px rgba(123, 104, 238, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    overflow: hidden;
    position: relative;
}

.doc-btn-ai::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(105deg, transparent 40%, rgba(255, 255, 255, 0.12) 50%, transparent 60%);
    transition: left 0.5s ease;
    pointer-events: none;
    z-index: 1;
}

.doc-btn-ai:hover::before {
    left: 100%;
}

.doc-btn-ai:hover {
    background: linear-gradient(135deg, rgba(123, 104, 238, 0.4) 0%, rgba(0, 212, 255, 0.3) 100%);
    border-color: rgba(123, 104, 238, 0.5);
    box-shadow:
        0 4px 16px rgba(123, 104, 238, 0.25),
        0 0 20px rgba(0, 212, 255, 0.1),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

/* Allow coach mark tooltip to overflow the button */
.doc-btn-ai.has-coach-mark {
    overflow: visible;
}

.doc-btn-ai.has-coach-mark::before {
    display: none;
}

/* ========================================
   EMPTY STATE WELCOME
   ======================================== */
.document-empty-state {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
}

.empty-state-content {
    text-align: center;
    max-width: 640px;
}

.empty-state-icon {
    font-size: 3rem;
    color: rgba(0, 242, 254, 0.2);
    margin-bottom: 1.25rem;
}

.empty-state-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: #ffffff;
    margin: 0 0 0.5rem;
    letter-spacing: -0.01em;
}

.empty-state-subtitle {
    font-size: 0.95rem;
    color: rgba(255, 255, 255, 0.5);
    margin: 0 0 2rem;
}

.empty-state-cards {
    display: flex;
    gap: 1.25rem;
    justify-content: center;
    flex-wrap: wrap;
}

.empty-state-card {
    flex: 1;
    min-width: 220px;
    max-width: 280px;
    padding: 1.75rem 1.5rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 1rem;
    cursor: pointer;
    text-align: center;
    transition: background 0.25s ease, border-color 0.25s ease, box-shadow 0.25s ease, transform 0.25s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    color: inherit;
    font-family: inherit;
    font-size: inherit;
}

.empty-state-card:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(0, 242, 254, 0.2);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.2), 0 0 30px rgba(0, 242, 254, 0.06);
    transform: translateY(-2px);
}

.empty-state-card:focus-visible {
    outline: 2px solid rgba(0, 242, 254, 0.6);
    outline-offset: 2px;
    border-color: rgba(0, 242, 254, 0.3);
}

/* Tactile press feedback — without :active the cards feel unresponsive
 * to the click that just hover-lifted them. */
.empty-state-card:active {
    transform: translateY(0);
    box-shadow: none;
    transition-duration: 0.08s;
}

.empty-card-icon {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.35rem;
}

.empty-card-icon-ai {
    background: linear-gradient(135deg, rgba(123, 104, 238, 0.2) 0%, rgba(0, 212, 255, 0.15) 100%);
    color: rgba(123, 104, 238, 0.9);
    border: 1px solid rgba(123, 104, 238, 0.2);
}

.empty-card-icon-blank {
    background: rgba(0, 242, 254, 0.08);
    color: rgba(0, 242, 254, 0.7);
    border: 1px solid rgba(0, 242, 254, 0.15);
}

.empty-card-title {
    font-size: 1.05rem;
    font-weight: 700;
    color: #ffffff;
    margin: 0;
}

.empty-card-desc {
    font-size: 0.82rem;
    color: rgba(255, 255, 255, 0.45);
    line-height: 1.5;
    margin: 0;
}

.empty-card-cta {
    font-size: 0.8rem;
    font-weight: 600;
    color: rgba(0, 242, 254, 0.7);
    margin-top: auto;
    display: flex;
    align-items: center;
    gap: 0.35rem;
    transition: color 0.2s ease;
}

.empty-state-card:hover .empty-card-cta {
    color: rgba(0, 242, 254, 1);
}

/* ========================================
   AI COACH MARK TOOLTIP
   ======================================== */
.ai-coach-mark {
    position: absolute;
    top: calc(100% + 10px);
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(135deg, rgba(123, 104, 238, 0.9) 0%, rgba(88, 70, 200, 0.95) 100%);
    color: #ffffff;
    padding: 0.5rem 0.85rem;
    border-radius: 0.6rem;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3), 0 0 20px rgba(123, 104, 238, 0.2);
    z-index: 1000;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    animation: coachMarkEntry 0.4s ease-out;
    pointer-events: auto;
}

.ai-coach-mark::before {
    content: '';
    position: absolute;
    top: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid rgba(123, 104, 238, 0.9);
}

.coach-mark-text i {
    margin-right: 0.3rem;
}

.coach-mark-close {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 1rem;
    cursor: pointer;
    padding: 0 0 0 0.25rem;
    line-height: 1;
}

.coach-mark-close:hover {
    color: #ffffff;
}

.coach-mark-fade-out {
    animation: coachMarkExit 0.3s ease-in forwards;
}

@keyframes coachMarkEntry {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes coachMarkExit {
    from {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
    to {
        opacity: 0;
        transform: translateX(-50%) translateY(6px);
    }
}

@media (max-width: 520px) {
    .empty-state-cards {
        flex-direction: column;
        align-items: center;
    }
    .empty-state-card {
        max-width: 100%;
        min-width: 0;
    }
    .ai-coach-mark {
        font-size: 0.72rem;
        padding: 0.4rem 0.7rem;
    }
}
/* ========================================
   DOCUMENT SOURCE PILLS
   ======================================== */

.document-sources-panel {
    padding: 16px 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(0, 0, 0, 0.15);
    flex-shrink: 0;
    max-height: 120px;
    overflow-y: auto;
}

.document-sources-panel .sources-header {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: rgba(255, 255, 255, 0.6);
    margin-bottom: 12px;
}

.document-sources-panel .sources-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.doc-source-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(10px);
    cursor: pointer;
}

.doc-source-pill.orange {
    background: rgba(255, 152, 0, 0.12);
    border: 1px solid rgba(255, 152, 0, 0.3);
    color: #ffab40;
}

.doc-source-pill.blue {
    background: rgba(33, 150, 243, 0.12);
    border: 1px solid rgba(33, 150, 243, 0.3);
    color: #42a5f5;
}

.doc-source-pill.green {
    background: rgba(76, 175, 80, 0.12);
    border: 1px solid rgba(76, 175, 80, 0.3);
    color: #66bb6a;
}

.doc-source-pill:hover {
    transform: translateY(-2px) scale(1.05);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
    filter: brightness(1.2);
}

.doc-source-pill i {
    font-size: 0.75rem;
    opacity: 0.8;
}

/* ========================================
   MOBILE STYLES
   ========================================
   All mobile-specific styles are in document-mobile.css
   which loads AFTER this file with higher specificity.
   DO NOT add mobile overrides here — they create
   z-index conflicts and value duplication.
   ======================================== */
