/* ============================================
   NOTEBOOKGEN — PREMIUM STYLESHEET v2.0
   Page-accurate sizing, multi-page, pro features
   ============================================ */

/* Inter font loaded via <link> in index.html — no duplicate @import needed */

/* ═══════════════════════════════════════════════
   SEO & Accessibility: Skip Navigation
   ═══════════════════════════════════════════════ */
.skip-nav {
    position: absolute;
    top: -100%;
    left: 50%;
    transform: translateX(-50%);
    padding: 0.75rem 1.5rem;
    background: var(--accent, #4a8cff);
    color: #fff;
    font-family: 'Inter', system-ui, sans-serif;
    font-size: 0.875rem;
    font-weight: 600;
    border-radius: 0 0 8px 8px;
    z-index: 100000;
    text-decoration: none;
    transition: top 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}
.skip-nav:focus {
    top: 0;
    outline: 2px solid #fff;
    outline-offset: 2px;
}

:root {
    /* UI Palette — Ultra-Premium Dark Futuristic Theme */
    --sidebar-bg: rgba(6, 9, 20, 0.96);
    --sidebar-glass: rgba(10, 17, 32, 0.75);
    --sidebar-border: rgba(99, 102, 241, 0.22);
    --sidebar-hover: rgba(99, 102, 241, 0.15);
    --sidebar-text: #f8fafc;
    --sidebar-text-muted: #94a3b8;
    --sidebar-width: 410px;

    --accent: #6366f1;
    --accent-light: #818cf8;
    --accent-glow: rgba(99, 102, 241, 0.35);
    --accent-hover: #4f46e5;
    --accent-neon: #06b6d4;
    --success: #10b981;
    --danger: #f43f5e;
    --warning: #f59e0b;
    --info: #0ea5e9;

    /* Futuristic Gradients */
    --accent-grad: linear-gradient(135deg, var(--accent), #8b5cf6);
    --neon-grad: linear-gradient(135deg, var(--accent) 0%, #a855f7 50%, var(--accent-neon) 100%);
    --glass-grad: linear-gradient(135deg, rgba(255, 255, 255, 0.05), rgba(255, 255, 255, 0.01));

    --preview-bg: #090d16; /* Sleek high-contrast dark space for paper preview */

    /* Paper Settings (A4 default) */
    --paper-bg: #fefdfb;
    --paper-width: 210mm;
    --paper-height: 297mm;
    --paper-shadow: 0 20px 50px rgba(0, 0, 0, 0.45), 0 5px 15px rgba(0, 0, 0, 0.2);
    --ruled-line-color: #c2ddf0;
    --margin-line-color: #ef9090;

    /* Margins */
    --paper-margin-top: 40px;
    --paper-margin-right: 50px;
    --paper-margin-bottom: 40px;
    --paper-margin-left: 90px;

    /* Transitions */
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 0.45s cubic-bezier(0.4, 0, 0.2, 1);

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 24px;
}

/* ======================== CROP MODAL STYLES ======================== */
.modal-content.crop-modal-content {
    max-width: 1100px;
    width: 95%;
    max-height: 95vh;
    background: #fff;
    color: #333;
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.crop-header-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

#crop-zoom-indicator {
    font-size: 12px;
    color: #666;
    min-width: 50px;
    text-align: right;
}

.crop-toolbar {
    display: flex;
    gap: 12px;
    padding: 12px;
    border-bottom: 1px solid #eee;
    flex-wrap: wrap;
    align-items: center;
    background: #fafafa;
}

.crop-tool-group {
    display: flex;
    gap: 6px;
    align-items: center;
    padding-right: 12px;
    border-right: 1px solid #ddd;
}

.crop-tool-group:last-child {
    border-right: none;
}

.crop-tool-group label {
    font-size: 12px;
    color: #666;
    font-weight: 500;
}

.scale-group {
    margin-left: auto;
}

.crop-toolbar .toolbar-select {
    min-width: 140px;
    height: 32px;
    font-size: 13px;
}

#modal-image-size-slider {
    width: 120px;
    cursor: pointer;
}

#modal-image-size-val {
    font-size: 13px;
    font-weight: 700;
    color: #1a73e8;
    min-width: 45px;
}

#modal-image-container {
    position: relative;
    overflow: auto;
    background: #e8e8e8;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 600px;
    touch-action: none;
    flex: 1;
    background-image: 
        linear-gradient(45deg, #ddd 25%, transparent 25%), 
        linear-gradient(-45deg, #ddd 25%, transparent 25%), 
        linear-gradient(45deg, transparent 75%, #ddd 75%), 
        linear-gradient(-45deg, transparent 75%, #ddd 75%);
    background-size: 20px 20px;
    background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
    padding: 20px;
}

#crop-canvas-wrapper {
    position: relative;
    cursor: crosshair;
    transform-origin: top center;
    transition: transform 0.1s ease-out;
    margin: 0 auto;
    display: block;
    width: fit-content;
    height: fit-content;
}

#crop-main-canvas {
    max-width: none !important;
    max-height: none !important;
    display: block;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    background: white;
}

#crop-grid-canvas {
    position: absolute;
    top: 0;
    left: 0;
    pointer-events: none;
}

#crop-selection-box {
    position: absolute;
    border: 2px solid #1a73e8;
    background: rgba(26, 115, 232, 0.1);
    display: none;
    pointer-events: none;
    z-index: 10;
}

.crop-sel-handle {
    position: absolute;
    width: 12px;
    height: 12px;
    background: #1a73e8;
    border: 2px solid #fff;
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.crop-sel-handle::after {
    content: '';
    position: absolute;
    top: -12px;
    left: -12px;
    right: -12px;
    bottom: -12px;
    cursor: inherit;
}

.crop-sel-handle[data-pos="tl"] { top: -6px; left: -6px; cursor: nwse-resize; }
.crop-sel-handle[data-pos="tr"] { top: -6px; right: -6px; cursor: nesw-resize; }
.crop-sel-handle[data-pos="bl"] { bottom: -6px; left: -6px; cursor: nesw-resize; }
.crop-sel-handle[data-pos="br"] { bottom: -6px; right: -6px; cursor: nwse-resize; }
.crop-sel-handle[data-pos="t"] { top: -6px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.crop-sel-handle[data-pos="b"] { bottom: -6px; left: 50%; transform: translateX(-50%); cursor: ns-resize; }
.crop-sel-handle[data-pos="l"] { left: -6px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }
.crop-sel-handle[data-pos="r"] { right: -6px; top: 50%; transform: translateY(-50%); cursor: ew-resize; }

#crop-drag-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
    color: #1a73e8;
    font-size: 12px;
    font-weight: 600;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
    white-space: nowrap;
}

#crop-keyboard-hint {
    font-size: 11px;
    color: #888;
    width: 100%;
    text-align: center;
    margin: 8px 0;
    padding: 0 10px;
}

#crop-keyboard-hint kbd {
    background: #f0f0f0;
    padding: 1px 6px;
    border-radius: 3px;
    border: 1px solid #ddd;
    margin: 0 2px;
}

.crop-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding: 15px;
    border-top: 1px solid #eee;
}

/* RESPONSIVE CROP MODAL */
@media (max-width: 768px) {
    .crop-modal-content {
        max-height: 90vh !important;
    }
    #modal-image-container {
        min-height: 200px !important;
        max-height: 50vh !important;
    }
    .crop-toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 15px;
    }
    
    .crop-tool-group {
        flex-direction: column;
        align-items: flex-start;
        border-right: none;
        border-bottom: 1px solid #eee;
        padding: 8px 0;
        gap: 8px;
    }
    
    .crop-tool-group:last-child {
        border-bottom: none;
    }
    
    .crop-toolbar .toolbar-select {
        width: 100%;
    }
    
    .scale-group {
        margin-left: 0;
        flex-direction: row;
        justify-content: space-between;
    }
    
    #modal-image-size-slider {
        flex: 1;
        margin: 0 10px;
    }
    
    .crop-header-actions {
        gap: 4px;
        overflow-x: auto;
        padding-bottom: 4px;
    }
    
    .icon-btn {
        padding: 2px;
    }
}
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--preview-bg);
    color: var(--sidebar-text);
    min-height: 100vh;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-text-size-adjust: 100%;
    -moz-text-size-adjust: 100%;
    text-size-adjust: 100%;
}

/* ======================== SCROLLBAR ======================== */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: rgba(6, 9, 20, 0.3);
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.2), rgba(6, 182, 212, 0.2));
    border-radius: 9999px;
    border: 1px solid transparent;
    background-clip: padding-box;
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.5), rgba(6, 182, 212, 0.5));
    border: 1px solid transparent;
    background-clip: padding-box;
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.4);
}

/* ======================== APP LAYOUT ======================== */
.app-container {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ======================== SIDEBAR ======================== */
.controls-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--sidebar-bg);
    backdrop-filter: blur(30px);
    -webkit-backdrop-filter: blur(30px);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    z-index: 1001; /* Higher than preview topbar */
    transition: transform var(--transition-slow);
}
/* No width animation to prevent jumping layout on mobile toggle */

.controls-sidebar.collapsed {
    width: 0;
    min-width: 0;
    transform: translateX(-100%);
    overflow: hidden;
}

.sidebar-overlay {
    display: none;
}

/* Sidebar Header */
.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.1rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    flex-shrink: 0;
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.06) 0%, transparent 100%);
    position: relative;
}

.sidebar-header::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 1.25rem;
    right: 1.25rem;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(99, 102, 241, 0.3), transparent);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 11px;
}

.logo-icon {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 14px var(--accent-glow);
    animation: logoPulse 4s ease infinite;
}

@keyframes logoPulse {

    0%,
    100% {
        box-shadow: 0 4px 14px var(--accent-glow);
    }

    50% {
        box-shadow: 0 4px 22px rgba(99, 102, 241, 0.5);
    }
}

.logo-icon .material-icons-round {
    font-size: 20px;
    color: white;
}

.sidebar-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: #f8fafc;
    line-height: 1.2;
}

.sidebar-header h1 .highlight {
    background: linear-gradient(135deg, var(--accent-light), #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    font-size: 0.65rem;
    color: var(--sidebar-text-muted);
    font-weight: 400;
    letter-spacing: 0.3px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* PRO Badge */
.pro-badge {
    font-size: 0.6rem;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 20px;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: white;
    letter-spacing: 1px;
    text-transform: uppercase;
    cursor: default;
    animation: proBadgeShine 3s ease infinite;
    box-shadow: 0 2px 10px rgba(245, 158, 11, 0.4);
}

@keyframes proBadgeShine {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.85;
        box-shadow: 0 2px 16px rgba(245, 158, 11, 0.6);
    }
}

.pro-feature-tag {
    font-size: 0.55rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 12px;
    background: linear-gradient(135deg, #f59e0b, #ef4444);
    color: white;
    letter-spacing: 0.8px;
    margin-left: auto;
    margin-right: 8px;
}

.sidebar-toggle {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--sidebar-text-muted);
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.sidebar-toggle:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.45);
    color: white;
    box-shadow: 0 0 12px rgba(99, 102, 241, 0.2);
}

/* Autosave Badge */
.autosave-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 1.25rem;
    font-size: 0.68rem;
    color: var(--success);
    opacity: 0;
    transition: opacity var(--transition-normal);
    flex-shrink: 0;
}

.autosave-badge.visible {
    opacity: 1;
}

.autosave-badge .material-icons-round {
    font-size: 13px;
}

/* Sidebar Form */
.sidebar-form {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 0 0 0.5rem 0;
    overflow-y: auto;
}

/* ======================== SIDEBAR SECTIONS ======================== */
.sidebar-section {
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.section-toggle {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 0.8rem 1.25rem;
    background: none;
    border: none;
    color: var(--sidebar-text);
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
}

.section-toggle:hover {
    background: var(--sidebar-hover);
    padding-left: 1.4rem;
}

.section-icon {
    font-size: 17px;
    color: var(--accent-light);
    filter: drop-shadow(0 0 6px var(--accent-glow));
    transition: all var(--transition-fast);
}

.section-toggle:hover .section-icon {
    filter: drop-shadow(0 0 10px rgba(129, 140, 248, 0.8));
    color: white;
}

.section-toggle .chevron {
    margin-left: auto;
    font-size: 18px;
    color: var(--sidebar-text-muted);
    transition: transform var(--transition-normal), color var(--transition-fast);
    transform: rotate(-90deg);
}

.section-toggle:hover .chevron {
    color: var(--accent-light);
}

.section-content {
    max-height: 0;
    overflow: hidden;
    transition: max-height var(--transition-slow), padding var(--transition-slow);
    padding: 0 1.25rem;
}

.section-content.open {
    max-height: 3000px;
    padding: 0 1.25rem 1rem;
}

.sidebar-section:has(.section-content.open) .chevron {
    transform: rotate(0deg);
}

/* ======================== FORM STYLES ======================== */
.form-group {
    margin-bottom: 0.85rem;
    display: flex;
    flex-direction: column;
}

.form-row {
    display: flex;
    gap: 10px;
}

.form-row .form-group {
    flex: 1;
}

.row-group {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.mini-select {
    padding: 2px 25px 2px 8px !important;
    font-size: 0.75rem !important;
    min-width: 80px;
    height: 28px !important;
    background: rgba(45, 55, 80, 0.4) !important;
    border-radius: var(--radius-sm) !important;
}

.expert-row-controls {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.mini-range {
    width: 100% !important;
    height: 15px !important;
    margin: 5px 0 !important;
    background: rgba(45, 55, 80, 0.4) !important;
    border: none !important;
    cursor: pointer;
}

.mini-number {
    width: 100% !important;
    height: 30px !important;
    padding: 2px 8px !important;
    font-size: 0.8rem !important;
    background: rgba(45, 55, 80, 0.4) !important;
    text-align: center;
}

.expert-controls {
    display: flex;
    gap: 8px;
    background: rgba(10, 15, 30, 0.3);
    padding: 8px;
    border-radius: var(--radius-md);
    border: 1px solid var(--sidebar-border);
}

.expert-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.expert-label {
    font-size: 0.6rem;
    font-weight: 700;
    color: var(--sidebar-text-muted);
    text-transform: uppercase;
}

.expert-item input[type="color"] {
    width: 100%;
    height: 24px;
    padding: 0;
    border: 1px solid var(--sidebar-border);
    border-radius: 3px;
    cursor: pointer;
    background: none;
}

.form-group label {
    font-size: 0.7rem;
    font-weight: 500;
    margin-bottom: 5px;
    color: var(--sidebar-text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input[type="text"],
input[type="number"],
select {
    width: 100%;
    padding: 0.6rem 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-md);
    background: rgba(20, 30, 50, 0.45);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    color: var(--sidebar-text);
    transition: all var(--transition-normal);
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0,0,0,0.05);
}

input[type="text"]:focus,
input[type="number"]:focus,
select:focus {
    outline: none;
    border-color: rgba(99, 102, 241, 0.6);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.25), 0 0 0 2px var(--accent-glow);
    background: rgba(20, 30, 50, 0.65);
}

input[type="text"]::placeholder {
    color: rgba(136, 153, 179, 0.35);
    font-size: 0.78rem;
}

input[type="number"] {
    width: 100%;
    text-align: center;
    -moz-appearance: textfield;
    appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

select {
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%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;
    padding-right: 32px;
}

/* Range Slider */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 6px;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 9999px;
    outline: none;
    margin-bottom: 4px;
    padding: 0;
    border: 1px solid rgba(255, 255, 255, 0.03);
    cursor: pointer;
    transition: all var(--transition-normal);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 9999px;
    background: linear-gradient(135deg, var(--accent-light), var(--accent-neon));
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease, background 0.2s ease;
    box-shadow: 0 0 12px var(--accent-glow), inset 0 1px 1px rgba(255,255,255,0.4);
    border: none;
}

input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.3);
    background: linear-gradient(135deg, #fff, var(--accent-light));
    box-shadow: 0 0 18px rgba(6, 182, 212, 0.8), inset 0 1px 1px rgba(255,255,255,0.8);
}

input[type="range"]::-webkit-slider-thumb:active {
    transform: scale(1.1);
    background: #fff;
    box-shadow: 0 0 25px #fff;
}

input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 9999px;
    background: linear-gradient(135deg, var(--accent-light), var(--accent-neon));
    cursor: pointer;
    border: none;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease, background 0.2s ease;
    box-shadow: 0 0 12px var(--accent-glow);
}

input[type="range"]::-moz-range-thumb:hover {
    transform: scale(1.3);
    background: linear-gradient(135deg, #fff, var(--accent-light));
    box-shadow: 0 0 18px rgba(6, 182, 212, 0.8);
}

#font-size-val,
#line-spacing-val,
#letter-spacing-val,
#word-spacing-val {
    font-size: 0.68rem;
    color: var(--sidebar-text-muted);
    align-self: flex-end;
    font-variant-numeric: tabular-nums;
}

.range-labels {
    display: flex;
    justify-content: space-between;
    font-size: 0.62rem;
    color: var(--sidebar-text-muted);
    margin-top: 2px;
}

/* Margin Controls */
.margin-controls {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 6px;
}

.margin-input {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 3px;
}

.margin-input span {
    font-size: 0.62rem;
    color: var(--sidebar-text-muted);
    text-transform: uppercase;
    font-weight: 600;
}

.margin-input input {
    width: 100%;
    padding: 4px;
    font-size: 0.75rem;
}

#margin-scope {
    flex: 1;
    padding: 6px 12px;
    border-radius: 12px;
    background: rgba(20, 30, 50, 0.45);
    border: 1px solid var(--sidebar-border);
    color: var(--sidebar-text);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

#target-page-select {
    display: none;
    width: 105px;
    padding: 6px 12px;
    border-radius: 12px;
    background: rgba(20, 30, 50, 0.45);
    border: 1px solid var(--sidebar-border);
    color: var(--sidebar-text);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition-fast);
}

/* Orientation Buttons */
.orientation-buttons {
    display: flex;
    gap: 6px;
}

.orient-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0.45rem 0.6rem;
    background: rgba(20, 30, 50, 0.8);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-sm);
    color: var(--sidebar-text-muted);
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.orient-btn:hover {
    border-color: var(--accent);
    color: var(--sidebar-text);
}

.orient-btn.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    box-shadow: 0 2px 10px var(--accent-glow);
}

.orient-btn .material-icons-round {
    font-size: 16px;
}

/* Color Options */
.color-options {
    display: flex;
    gap: 7px;
    flex-wrap: wrap;
    align-items: center;
}

.color-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    position: relative;
}

.color-btn:hover {
    transform: translateY(-2px) scale(1.1);
}

.color-btn.active {
    border: 2px solid white;
    outline: 2px solid var(--accent-light);
    transform: scale(1.12);
}

.color-btn-custom {
    background: linear-gradient(135deg, #ff6b6b, #ffd93d, #6bcb77, #4d96ff) !important;
    display: flex;
    align-items: center;
    justify-content: center;
}

.hidden-color-picker {
    width: 0;
    height: 0;
    opacity: 0;
    position: absolute;
    pointer-events: none;
}

.hex-input-wrapper {
    display: flex;
    align-items: center;
    background: rgba(10, 15, 30, 0.4);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-sm);
    padding: 0 8px;
    height: 32px;
    margin-left: 4px;
}

.hex-input-wrapper span {
    font-size: 0.8rem;
    color: var(--sidebar-text-muted);
    margin-right: 2px;
}

.hex-input-wrapper input {
    width: 65px !important;
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    font-family: 'Inter', monospace;
    font-size: 0.75rem;
    color: var(--sidebar-text) !important;
    text-transform: uppercase;
}

.hex-input-wrapper input:focus {
    outline: none;
}

/* Checkbox */
.checkbox-group {
    margin-bottom: 0.4rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 9px;
    cursor: pointer;
    font-size: 0.78rem !important;
    color: var(--sidebar-text) !important;
    text-transform: none !important;
    letter-spacing: 0 !important;
    user-select: none;
    padding: 2px 0;
}

.checkbox-label input[type="checkbox"] {
    display: none;
}

.checkmark {
    width: 17px;
    height: 17px;
    border: 1.5px solid var(--sidebar-border);
    border-radius: 5px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
    background: rgba(13, 20, 38, 0.5);
}

.checkbox-label:hover .checkmark {
    border-color: rgba(99, 102, 241, 0.6);
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.25);
    transform: translateY(-1px);
}

.checkbox-label:active .checkmark {
    transform: scale(0.9);
}

.checkbox-label input[type="checkbox"]:checked+.checkmark {
    background: var(--neon-grad);
    border-color: var(--accent);
    box-shadow: 0 0 12px rgba(6, 182, 212, 0.4);
}

.checkbox-label input[type="checkbox"]:checked+.checkmark::after {
    content: '✓';
    color: white;
    font-size: 11px;
    font-weight: 800;
    animation: checkmark-pop 0.22s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes checkmark-pop {
    0% { transform: scale(0.4); opacity: 0; }
    100% { transform: scale(1); opacity: 1; }
}

/* ======================== TEMPLATE GRID ======================== */
.template-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
}

.template-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 12px 6px;
    background: rgba(255, 255, 255, 0.01);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: var(--radius-md);
    color: var(--sidebar-text-muted);
    font-family: 'Inter', sans-serif;
    font-size: 0.68rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1), background-color 0.25s, border-color 0.25s, color 0.25s, box-shadow 0.25s;
}

.template-card:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.5);
    color: white;
    transform: translateY(-4px) scale(1.03);
    box-shadow: 0 10px 22px rgba(99, 102, 241, 0.3), 0 0 10px rgba(6, 182, 212, 0.2);
}

.template-card:active {
    transform: translateY(-1px) scale(0.97);
    box-shadow: 0 4px 10px rgba(99, 102, 241, 0.15);
}

.template-card .material-icons-round {
    font-size: 22px;
    color: var(--accent-light);
    transition: color 0.25s, transform 0.25s, filter 0.25s;
    filter: drop-shadow(0 2px 8px var(--accent-glow));
}

.template-card:hover .material-icons-round {
    color: white;
    transform: scale(1.1);
    filter: drop-shadow(0 2px 12px rgba(255, 255, 255, 0.7)) drop-shadow(0 0 8px rgba(6, 182, 212, 0.5));
}

/* ======================== EDITOR TOOLBAR ======================== */
.editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 10px 12px;
    background: rgba(8, 12, 24, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    position: sticky;
    top: -10px; /* Slight offset for sidebar scrolling */
    z-index: 100;
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    align-items: center;
}

/* Font Preview Styles */
#font-family option[value="'Kalam', cursive"] { font-family: 'Kalam', cursive; }
#font-family option[value="'Caveat', cursive"] { font-family: 'Caveat', cursive; }
#font-family option[value="'Indie Flower', cursive"] { font-family: 'Indie Flower', cursive; }
#font-family option[value="'Shadows Into Light', cursive"] { font-family: 'Shadows Into Light', cursive; }
#font-family option[value="'Dancing Script', cursive"] { font-family: 'Dancing Script', cursive; }
#font-family option[value="'Permanent Marker', cursive"] { font-family: 'Permanent Marker', cursive; }
#font-family option[value="'Patrick Hand', cursive"] { font-family: 'Patrick Hand', cursive; }
#font-family option[value="'Covered By Your Grace', cursive"] { font-family: 'Covered By Your Grace', cursive; }
#font-family option[value="'Reenie Beanie', cursive"] { font-family: 'Reenie Beanie', cursive; }
#font-family option[value="'Homemade Apple', cursive"] { font-family: 'Homemade Apple', cursive; }
#font-family option[value="'Satisfy', cursive"] { font-family: 'Satisfy', cursive; }
#font-family option[value="'Architects Daughter', cursive"] { font-family: 'Architects Daughter', cursive; }
#font-family option[value="'Tillana', cursive"] { font-family: 'Tillana', cursive; }
#font-family option[value="'Yatra One', cursive"] { font-family: 'Yatra One', cursive; }

.toolbar-group {
    display: flex;
    flex-wrap: wrap; /* Allow individual groups to wrap buttons internally */
    gap: 1px;
    align-items: center;
}

/* Enhanced Table Tools Group */
.toolbar-group.table-tools {
    background: rgba(99, 102, 241, 0.08); /* Subtle indigo highlight */
    border-radius: var(--radius-sm);
    padding: 3px;
    border: 1px solid rgba(99, 102, 241, 0.2);
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin: 2px 0;
    transition: all 0.3s ease;
}

.table-tools .toolbar-group {
    background: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    padding: 1px;
}

.table-tools .toolbar-btn {
    width: 26px; /* Slightly more compact for table tools */
    height: 26px;
}

.table-tools .toolbar-divider {
    height: 18px;
    opacity: 0.5;
}

/* ======================== TEXT COLOR PICKER ======================== */
.text-color-wrapper {
    position: relative;
    display: inline-flex;
}

.text-color-wrapper .toolbar-btn {
    position: relative;
    overflow: visible;
}

.text-color-indicator {
    position: absolute;
    bottom: 1px;
    left: 50%;
    transform: translateX(-50%);
    width: 14px;
    height: 3px;
    border-radius: 2px;
    background: currentColor;
    transition: background 0.15s ease;
    pointer-events: none;
}

.text-color-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    left: 50%;
    transform: translateX(-50%);
    width: 230px;
    background: rgba(15, 20, 40, 0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: var(--radius-md);
    padding: 12px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
    z-index: 1000;
    animation: tcDropIn 0.15s ease;
}

.text-color-dropdown.open {
    display: block;
}

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

.text-color-label {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--sidebar-text-muted);
    margin-bottom: 8px;
}

.text-color-presets {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 5px;
    margin-bottom: 10px;
}

.tc-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: all 0.12s ease;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.3);
}

.tc-swatch:hover {
    transform: scale(1.2);
    border-color: rgba(255, 255, 255, 0.5);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
}

.tc-swatch.active {
    border-color: #fff;
    outline: 2px solid var(--accent-light);
    transform: scale(1.15);
}

.text-color-custom-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding-top: 8px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.tc-native-picker {
    width: 30px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--sidebar-border);
    border-radius: 4px;
    cursor: pointer;
    background: none;
    flex-shrink: 0;
}

.tc-hex-input-wrapper {
    display: flex;
    align-items: center;
    background: rgba(10, 15, 30, 0.5);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-sm);
    padding: 0 6px;
    height: 28px;
    flex: 1;
}

.tc-hex-input-wrapper span {
    font-size: 0.75rem;
    color: var(--sidebar-text-muted);
    margin-right: 2px;
}

.tc-hex-input-wrapper input {
    width: 100% !important;
    border: none !important;
    background: transparent !important;
    padding: 0 !important;
    font-family: 'Inter', monospace;
    font-size: 0.72rem;
    color: var(--sidebar-text) !important;
    text-transform: uppercase;
}

.tc-remove-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.25);
    border-radius: var(--radius-sm);
    color: #ef4444;
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.tc-remove-btn:hover {
    background: rgba(239, 68, 68, 0.3);
    color: #fff;
}

/* ======================== INLINE FONT SIZE CONTROL ======================== */
.inline-font-size-wrapper {
    display: flex;
    align-items: center;
    gap: 0;
    background: rgba(20, 30, 50, 0.7);
    border: 1px solid var(--sidebar-border);
    border-radius: 8px;
    overflow: visible;
    position: relative;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.inline-font-size-wrapper:hover {
    border-color: rgba(99, 102, 241, 0.35);
}

.inline-font-size-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.font-size-step-btn {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--sidebar-text-muted);
    cursor: pointer;
    transition: all 0.15s ease;
    flex-shrink: 0;
    padding: 0;
}

.font-size-step-btn:hover {
    color: white;
    background: rgba(99, 102, 241, 0.25);
}

.font-size-step-btn:active {
    transform: scale(0.88);
}

.font-size-step-btn .material-icons-round {
    font-size: 15px;
}

#font-size-decrease {
    border-radius: 7px 0 0 7px;
}

#font-size-increase {
    border-radius: 0 7px 7px 0;
}

.font-size-display-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
    cursor: pointer;
}

.font-size-display {
    width: 28px;
    height: 26px;
    border: none;
    background: transparent;
    color: var(--sidebar-text);
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    font-weight: 600;
    text-align: center;
    padding: 0 0 0 2px;
    cursor: pointer;
    -moz-appearance: textfield;
    outline: none;
    font-variant-numeric: tabular-nums;
}

.font-size-display::-webkit-inner-spin-button,
.font-size-display::-webkit-outer-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.font-size-display:focus {
    background: rgba(99, 102, 241, 0.1);
    cursor: text;
}

.font-size-unit {
    font-size: 0.58rem;
    color: var(--sidebar-text-muted);
    font-weight: 500;
    padding-right: 0;
    pointer-events: none;
    user-select: none;
    opacity: 0.6;
}

.font-size-chevron {
    width: 18px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--sidebar-text-muted);
    cursor: pointer;
    padding: 0;
    margin-right: 1px;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.font-size-chevron .material-icons-round {
    font-size: 14px;
    transition: transform 0.2s ease;
}

.font-size-chevron:hover {
    color: white;
}

.font-size-chevron.open .material-icons-round {
    transform: rotate(180deg);
}

/* Font Size Dropdown */
.font-size-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    width: 210px;
    background: rgba(15, 20, 40, 0.97);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(99, 102, 241, 0.25);
    border-radius: var(--radius-md);
    padding: 10px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.05) inset;
    z-index: 1000;
    animation: fsDropIn 0.15s ease;
}

.font-size-dropdown.open {
    display: block;
}

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

.font-size-dropdown-label {
    font-size: 0.6rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--sidebar-text-muted);
    margin-bottom: 8px;
}

.font-size-presets {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 4px;
    margin-bottom: 8px;
}

.fs-preset {
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(20, 30, 50, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 6px;
    color: var(--sidebar-text-muted);
    font-family: 'Inter', sans-serif;
    font-size: 0.72rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.12s ease;
    font-variant-numeric: tabular-nums;
}

.fs-preset:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: rgba(99, 102, 241, 0.3);
    color: white;
    transform: scale(1.04);
}

.fs-preset.active {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
    font-weight: 700;
    box-shadow: 0 2px 8px var(--accent-glow);
}

.font-size-reset-row {
    padding-top: 6px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    display: flex;
    justify-content: center;
}

.fs-reset-btn {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 4px 12px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.2);
    border-radius: 6px;
    color: rgba(239, 144, 144, 0.9);
    font-family: 'Inter', sans-serif;
    font-size: 0.65rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s ease;
}

.fs-reset-btn:hover {
    background: rgba(239, 68, 68, 0.25);
    color: #fff;
    border-color: rgba(239, 68, 68, 0.4);
}

.toolbar-divider {
    width: 1px;
    height: 22px;
    background: var(--sidebar-border);
    margin: 0 3px;
}

.toolbar-btn {
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.02);
    border: none;
    border-radius: var(--radius-sm);
    color: var(--sidebar-text-muted);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.toolbar-btn:hover {
    background: rgba(99, 102, 241, 0.15);
    color: white;
}

.toolbar-btn.active {
    background: linear-gradient(135deg, var(--accent), #8b5cf6);
    color: white;
    box-shadow: 0 0 10px var(--accent-glow);
}

.toolbar-btn.dictating-active {
    background: rgba(244, 63, 94, 0.15);
    color: var(--danger);
    animation: pulseDictate 1.5s infinite;
}

@keyframes pulseDictate {
    0% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(244, 63, 94, 0.4);
    }

    50% {
        transform: scale(1.05);
        box-shadow: 0 0 0 6px rgba(244, 63, 94, 0);
    }

    100% {
        transform: scale(1);
        box-shadow: 0 0 0 0 rgba(244, 63, 94, 0);
    }
}

.toolbar-btn .material-icons-round {
    font-size: 16px;
}

.toolbar-select {
    height: 28px;
    padding: 0 22px 0 7px;
    font-size: 0.72rem;
    background: rgba(20, 30, 50, 0.8);
    border: 1px solid var(--sidebar-border);
    color: var(--sidebar-text);
    border-radius: var(--radius-sm);
    cursor: pointer;
    min-width: 85px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 5px center;
    -webkit-appearance: none;
    appearance: none;
}

/* ======================== RICH TEXT EDITOR ======================== */
.rich-editor {
    min-height: 180px;
    max-height: 320px;
    overflow-y: auto;
    padding: 0.75rem;
    background: rgba(20, 30, 50, 0.6);
    border: 1px solid var(--sidebar-border);
    border-top: none;
    border-radius: 0 0 var(--radius-md) var(--radius-md);
    font-family: 'Inter', sans-serif;
    font-size: 0.84rem;
    color: var(--sidebar-text);
    line-height: 1.7;
    outline: none;
    transition: all var(--transition-fast);
    word-break: break-word;
}

.rich-editor:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent-glow);
    background: rgba(20, 30, 50, 0.9);
}

.rich-editor.drag-over {
    border: 1px dashed var(--accent) !important;
    background: rgba(67, 97, 238, 0.1) !important;
    box-shadow: 0 0 15px rgba(67, 97, 238, 0.2) !important;
}


.rich-editor:empty::before {
    content: attr(data-placeholder);
    color: rgba(136, 153, 179, 0.35);
    pointer-events: none;
}

.rich-editor h1,
.rich-editor h2,
.rich-editor h3 {
    color: var(--sidebar-text);
    margin: 0.5em 0 0.3em;
}

.rich-editor ul,
.rich-editor ol {
    padding-left: 1.5em;
    margin: 0.3em 0;
}

.rich-editor hr {
    border: none;
    border-top: 1px solid var(--sidebar-border);
    margin: 0.5em 0;
}

.rich-editor img {
    max-width: 100%;
    max-height: 120px;
    border-radius: 2px;
    margin: 8px auto;
    display: block;
    box-shadow: none !important; /* EXPERT: Force-kill any legacy digital shadows */
    border: 1px solid rgba(0,0,0,0.05); /* Very subtle realistic edge */
}


/* Editor Stats */
.editor-stats {
    display: flex;
    gap: 8px;
    padding: 5px 10px;
    font-size: 0.65rem;
    color: var(--sidebar-text-muted);
    flex-shrink: 0;
}

.stats-divider {
    color: rgba(136, 153, 179, 0.25);
}

/* ======================== ACTIONS ======================== */
.actions {
    padding: 0.75rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
    margin-top: auto;
    border-top: 1px solid var(--sidebar-border);
}

.action-row {
    display: flex;
    gap: 6px;
}

.action-row .secondary-btn {
    flex: 1;
}

.primary-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--neon-grad);
    background-size: 200% 200%;
    animation: gradient-flow 6s ease infinite;
    color: white;
    border: none;
    padding: 0.72rem;
    border-radius: var(--radius-md);
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease, filter 0.2s ease;
    box-shadow: 0 4px 14px rgba(6, 182, 212, 0.3);
}

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

.primary-btn:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 0 10px 25px rgba(6, 182, 212, 0.5), 0 0 12px rgba(99, 102, 241, 0.4);
    filter: brightness(1.1);
}

.primary-btn:active {
    transform: translateY(-0.5px) scale(0.97);
    box-shadow: 0 4px 12px rgba(6, 182, 212, 0.3);
}

.primary-btn .material-icons-round {
    font-size: 17px;
}

.secondary-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    background: rgba(255, 255, 255, 0.02);
    color: var(--sidebar-text-muted);
    border: 1px solid rgba(255, 255, 255, 0.06);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    padding: 0.55rem 0.7rem;
    border-radius: var(--radius-md);
    font-family: 'Inter', sans-serif;
    font-size: 0.75rem;
    font-weight: 500;
    cursor: pointer;
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease, border 0.2s ease, color 0.2s ease;
}

.secondary-btn:hover {
    background: rgba(99, 102, 241, 0.12);
    border-color: rgba(99, 102, 241, 0.45);
    color: white;
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.15);
}

.secondary-btn:active {
    transform: translateY(-0.5px) scale(0.97);
}

.secondary-btn .material-icons-round {
    font-size: 15px;
}

.danger-btn:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.3);
}

/* ======================== PREVIEW AREA ======================== */
.preview-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--preview-bg);
    background-image:
        radial-gradient(circle at 20% 50%, rgba(99, 102, 241, 0.04) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(124, 58, 237, 0.04) 0%, transparent 50%);
    position: relative;
}

/* Preview Top Bar */
.preview-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 20px;
    background: rgba(8, 12, 24, 0.65);
    backdrop-filter: blur(18px);
    -webkit-backdrop-filter: blur(18px);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    flex-shrink: 0;
    z-index: 100;
}

.sidebar-open-btn {
    margin-right: 8px;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-sm);
    cursor: pointer;
    color: var(--sidebar-text-muted);
    transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s, border-color 0.2s, color 0.2s;
}

.icon-btn:hover {
    background: rgba(99, 102, 241, 0.15);
    border-color: rgba(99, 102, 241, 0.5);
    color: white;
    transform: scale(1.08);
}

.icon-btn:active {
    transform: scale(0.92);
}

.icon-btn .material-icons-round {
    font-size: 17px;
}

#zoom-level {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--sidebar-text-muted);
    min-width: 38px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.topbar-info {
    display: flex;
    align-items: center;
    gap: 14px;
}

.page-size-indicator {
    font-size: 0.72rem;
    color: var(--accent-light);
    font-weight: 600;
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(99, 102, 241, 0.2);
    padding: 3px 10px;
    border-radius: 20px;
}

.page-info {
    font-size: 0.72rem;
    color: var(--sidebar-text-muted);
    font-weight: 500;
}

/* Paper Scroll Container */
.paper-scroll-container {
    flex: 1;
    overflow: auto; /* Enable horizontal and vertical scrollbars for overflow */
    display: block; /* Use block layout to resolve Firefox flexbox zoom centering alignment bugs and left-overflow clipping */
    padding: 2rem 1.5rem 3rem;
}

.paper-wrapper {
    display: block;
    margin: 0 auto;
    width: fit-content; /* Sized to fit content (ruling pages) for auto margin centering */
    transition: transform var(--transition-slow);
    transform-origin: top center;
    flex-shrink: 0;
}

#pages-container {
    display: flex;
    flex-direction: column;
    gap: 24px;
}

/* ======================== PAPER ======================== */
.paper {
    width: var(--paper-width);
    height: var(--paper-height);
    background-color: var(--paper-bg);
    /* EXPERT: Natural lighting vignette combined with base background */
    background: radial-gradient(circle at 15% 15%, rgba(255,255,255,0) 0%, rgba(0,0,0,0.02) 100%), var(--paper-bg);
    
    position: relative;
    padding: var(--paper-margin-top) var(--paper-margin-right) var(--paper-margin-bottom) var(--paper-margin-left);
    box-sizing: border-box; /* CRITICAL: Ensure margins don't grow page beyond A4 */

    font-family: 'Kalam', cursive;
    color: #243f8a;
    font-size: 22px;
    line-height: var(--ruled-line-spacing, 38px);

    transition: background var(--transition-normal);
    overflow: hidden;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1), 0 1px 4px rgba(0,0,0,0.05);
    border-radius: 2px;
    z-index: 1;
}

/* Paper Base pseudo-layer — used for textures and overlays */
.paper::before {
    content: '';
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background: transparent;
}


.micro-chunk {
    display: block;
    margin: 0 !important;
    padding: 0 !important;
    line-height: inherit;
}

/* Paper Texture */
.paper-textured::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.035'/%3E%3C/svg%3E");
    pointer-events: none;
    z-index: 0;
}

/* Ruled Paper — Dynamic Spacing */
.paper-ruled {
    background-image: linear-gradient(
        transparent calc(var(--ruled-line-spacing, 38px) - 1px), 
        var(--ruled-line-color) calc(var(--ruled-line-spacing, 38px) - 1px), 
        var(--ruled-line-color) var(--ruled-line-spacing, 38px), 
        transparent var(--ruled-line-spacing, 38px)
    );
    background-size: 100% var(--ruled-line-spacing, 38px);
    background-position: 0 0;
}

/* Math Grid Paper */
.paper-math {
    background-image:
        linear-gradient(var(--ruled-line-color) 1px, transparent 1px),
        linear-gradient(90deg, var(--ruled-line-color) 1px, transparent 1px);
    background-size: 20px 20px;
}

.paper-math .margin-line {
    display: none;
}

/* Dotted Grid Paper */
.paper-dotted {
    background-image: radial-gradient(circle, var(--ruled-line-color) 1px, transparent 1px);
    background-size: 20px 20px;
}

.paper-dotted .margin-line {
    display: none;
}

/* Blank Paper */
.paper-blank {
    background-image: none;
    /* FIX: Use CSS variable so Paper Color picker works on blank pages too */
    background-color: var(--paper-bg);
}

.paper-blank .margin-line {
    display: none;
}

/* Margin Line */
.margin-line {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 70px;
    width: 2px;
    background-color: var(--margin-line-color);
    box-shadow: 3px 0 0 rgba(239, 144, 144, 0.3);
    z-index: 1;
}

/* Paper Header */
.paper-header {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 0.6rem;
    position: relative;
    z-index: 2;
    padding-bottom: 0.4rem;
    border-bottom: 1px dashed rgba(150, 150, 180, 0.3);
}

.paper-header-left,
.paper-header-right {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.paper-header-field {
    font-size: 0.85em;
    opacity: 0.9;
}

.paper-header-field .field-label {
    font-weight: 700;
    font-size: 0.8em;
}

.paper-title {
    font-size: 1.35em;
    font-weight: 700;
    text-align: center;
    margin-bottom: 0.8rem;
    text-decoration: underline;
    text-underline-offset: 4px;
    position: relative;
    z-index: 2;
    color: var(--ink-color, #243f8a); /* EXPERT: Force deep ink color */
}

.paper-content {
    display: flow-root;
    height: 100%;
    width: 100%;
    margin: 0 !important;
    padding: 4px 0 0 0 !important; /* Safety padding-top to prevent ascender clipping */
    word-break: break-word;
    position: relative;
    z-index: 2;
    overflow: visible; /* EXPERT: Set to visible so SVG filter bleed on table borders isn't clipped at the boundary! */
    mix-blend-mode: multiply; /* EXPERT: Authentic ink absorption effect */
    /* Precise Mobile Rendering */
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    font-variant-ligatures: none;
}

/* Handwriting Font Utility */
.handwriting-font {
    font-family: inherit;
    display: inline-block;
}

/* Specific resets for elements inside the paper to ensure continuous handwriting flow */
.paper-content p, 
.paper-content div, 
.paper-content h1, 
.paper-content h2, 
.paper-content h3, 
.paper-content ul, 
.paper-content ol {
    margin: 0 !important;
    padding: 0 !important;
    line-height: inherit;
    box-sizing: border-box !important; /* EXPERT: Ensures no hidden padding breaks height calculations */
    border: none !important; /* Prevents border-width from shifting heights */
}


/* Ensure placeholder text matches tone */
.placeholder-text {
    color: #b0b8c8;
    font-style: italic;
    font-size: 0.85em;
}

/* Page Number */
.page-number {
    position: absolute;
    bottom: 25px; /* expert padding */
    text-align: center;
    font-size: 0.75em;
    font-weight: 600;
    color: rgba(100, 100, 140, 0.6);
    z-index: 5;
    transition: all 0.3s ease;
}

.page-num-center {
    left: 0;
    right: 0;
    text-align: center;
}

.page-num-left {
    left: var(--paper-margin-left);
    text-align: left;
}

.page-num-right {
    right: var(--paper-margin-right);
    text-align: right;
}

/* Coffee stain */
.coffee-stain {
    position: absolute;
    border-radius: 50%;
    z-index: 3;
    pointer-events: none;
    background: radial-gradient(ellipse, transparent 50%, rgba(139, 90, 43, 0.06) 55%, rgba(139, 90, 43, 0.1) 60%, rgba(139, 90, 43, 0.04) 70%, transparent 75%);
}

/* Margin doodle */
.margin-doodle {
    position: absolute;
    left: 10px;
    z-index: 3;
    pointer-events: none;
    opacity: 0.15;
    font-size: 20px;
    transform: rotate(-10deg);
}

/* CamScanner / Scanned Document Effect */
.paper-scanned {
    filter: brightness(1.05) contrast(1.1) saturate(0.9) sepia(0.05) blur(0.2px) !important;
}

.paper-scanned::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 10;
    background: radial-gradient(circle at center, transparent 40%, rgba(0, 0, 0, 0.06) 100%);
    box-shadow: inset 0 0 120px rgba(0, 0, 0, 0.04);
}

/* Vintage Paper / Aged Effect */
.paper-vintage {
    filter: sepia(0.35) contrast(0.95) brightness(0.96) saturate(0.8);
    background-color: #f7f1e3 !important;
}

.paper-vintage::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 11;
    background-image: 
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='400' height='400'%3E%3Cfilter id='f'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.8' numOctaves='5' stitchTiles='stitch'/%3E%3CfeColorMatrix type='saturate' values='0'/%3E%3C/filter%3E%3Crect width='400' height='400' filter='url(%23f)' opacity='0.08'/%3E%3C/svg%3E"),
        radial-gradient(circle at 10% 10%, rgba(139, 69, 19, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 90% 85%, rgba(139, 69, 19, 0.05) 0%, transparent 40%);
    mix-blend-mode: multiply;
}

/* Ink Blend Effect */
#display-content,
.paper-title,
.paper-header-field {
    mix-blend-mode: multiply;
}

/* ======================== HANDWRITING ENGINE STYLES ======================== */
.hw-char {
    display: inline-block;
    transition: none;
    will-change: transform, opacity;
}

.hw-word {
    display: inline-block;
    white-space: pre;
    text-rendering: geometricPrecision;
    -webkit-font-smoothing: antialiased;
    will-change: transform, opacity;
}

.hw-word > span {
    margin: 0 -0.15px;
}

.paper-content .hw-word {
    mix-blend-mode: multiply;
}

/* Formatting in paper */
#pages-container img,
#pages-container .active-editor-img {
    outline: none !important;
}

.paper-content b,
.paper-content strong {
    font-weight: 700;
}

.paper-content i,
.paper-content em {
    font-style: italic;
}

.paper-content u {
    text-decoration: underline;
    text-underline-offset: 3px;
    text-decoration-style: wavy;
    text-decoration-color: currentColor;
}

/* EXPERT: Strikethrough logic for handwriting spans */
.paper-content s, 
.paper-content strike, 
.paper-content del { 
    text-decoration: line-through !important; 
    text-decoration-thickness: 1.5px;
    text-decoration-color: currentColor;
    color: inherit; 
}

/* Force inheritance for handwriting word/char spans as they are display:inline-block */
.paper-content s *, 
.paper-content strike *, 
.paper-content del * {
    text-decoration: line-through !important;
}

.paper-content h1,
.paper-content h2,
.paper-content h3 {
    text-decoration: underline;
    text-underline-offset: 4px;
    margin: 0.5em 0 0.3em;
}

.paper-content h1 {
    font-size: 1.4em;
}

.paper-content h2 {
    font-size: 1.25em;
}

.paper-content h3 {
    font-size: 1.12em;
}

.paper-content ul,
.paper-content ol {
    padding-left: 1.5em;
    margin: 0.2em 0;
}

.paper-content hr {
    border: none;
    border-top: 2px solid currentColor;
    opacity: 0.25;
    margin: 0.5em 0;
}

.paper-content img {
    max-width: 100%;
    max-height: 800px;
    border-radius: 4px;
    margin: 15px auto;
    display: block;
    box-shadow: none !important;
}

/* Handwritten-style Tables (v4.0 — Expert Logic) */
.paper-content table {
    width: 100%;
    border-collapse: collapse; 
    margin: 12px 0; 
    font-size: 0.88em;
    position: relative;
    filter: url('#hand-drawn-filter');
    mix-blend-mode: multiply;
    border: none !important;
}

.paper-content table th,
.paper-content table td {
    border: 1.2px solid currentColor;
    padding: 8px 12px;
    text-align: left !important;
    vertical-align: top;
    position: relative;
    transition: border-color 0.2s ease;
    box-sizing: border-box;
}

/* Outer boundary overshoot - refined for perfect symmetric alignment */
.paper-content table::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    border: 0.5px solid currentColor;
    opacity: 0.1;
    pointer-events: none;
    z-index: -1;
    transform: scale(1.001); /* Minimal overshoot to prevent shift */
    transition: opacity 0.2s ease;
}

.paper-content table.no-borders::after {
    opacity: 0 !important;
}

/* Rich editor table preview */
.rich-editor table {
    width: 100%;
    border-collapse: collapse;
    margin: 6px 0;
    font-size: 0.85rem;
}

.rich-editor table th,
.rich-editor table td {
    border: 1px solid var(--sidebar-border);
    padding: 4px 8px;
    text-align: left;
    color: var(--sidebar-text);
}

/* ======================== INK SMUDGES ======================== */
.smudges-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
    z-index: 3;
    overflow: hidden;
}

.ink-smudge {
    position: absolute;
    border-radius: 50%;
    background: radial-gradient(ellipse, rgba(25, 25, 112, 0.05) 0%, transparent 70%);
    filter: blur(2px);
    pointer-events: none;
}

/* ======================== TOAST NOTIFICATIONS ======================== */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 1100; /* FIX: Must be above sidebar (1001) so toasts are always visible */
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    background: rgba(10, 15, 30, 0.95);
    backdrop-filter: blur(10px);
    color: white;
    border-radius: var(--radius-md);
    font-size: 0.82rem;
    font-family: 'Inter', sans-serif;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
    animation: toastIn 0.3s ease forwards;
    border-left: 3px solid var(--accent);
}

.toast.success {
    border-left-color: var(--success);
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.warning {
    border-left-color: var(--warning);
}

.toast .material-icons-round {
    font-size: 17px;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes toastOut {
    from {
        opacity: 1;
        transform: translateY(0) scale(1);
    }

    to {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
}

/* ======================== MOBILE ACTION BAR ======================== */
.mobile-action-bar {
    display: none;
}

/* ======================== MOBILE PERFORMANCE + LAYOUT (Merged) ======================== */
@media (max-width: 900px) {
    :root {
        /* Faster transitions on mobile */
        --transition-normal: 0.15s ease;
        --transition-slow: 0.2s ease;
    }

    /* Disable expensive GPU filters on mobile devices */
    .controls-sidebar,
    .editor-toolbar,
    .modal-content {
        backdrop-filter: none !important;
        -webkit-backdrop-filter: none !important;
        background: var(--sidebar-bg) !important;
    }

    .coffee-stain {
        /* Simpler gradient for mobile */
        background: rgba(139, 90, 43, 0.05) !important;
    }

    /* Reduce paper texture complexity */
    .paper-vintage::after {
        opacity: 0.05 !important;
    }

    /* Smoother sidebar transition */
    .controls-sidebar {
        will-change: transform;
    }

    /* FIX #17: Make draw canvas responsive on small screens */
    #draw-canvas {
        max-width: 100%;
        height: auto;
    }

    .app-container {
        flex-direction: column;
        overflow: hidden;
        position: relative;
    }

    .controls-sidebar {
        position: fixed;
        top: 60px;
        left: 0;
        height: calc(100vh - 60px);
        width: 85%;
        max-width: 350px;
        min-width: 0;
        box-shadow: 15px 0 50px rgba(0, 0, 0, 0.6);
        z-index: 1001;
    }

    .controls-sidebar.collapsed {
        transform: translateX(-100%);
        width: 0;
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        top: 60px;
        left: 0;
        right: 0;
        bottom: 0;
        background: rgba(0, 0, 0, 0.4);
        backdrop-filter: blur(4px);
        -webkit-backdrop-filter: blur(4px);
        z-index: 1000;
        opacity: 0;
        pointer-events: none;
        transition: opacity var(--transition-normal);
    }

    .controls-sidebar .sidebar-header {
        padding: 0.5rem 1.25rem;
    }

    .controls-sidebar .sidebar-header .logo-area {
        display: none;
    }

    .controls-sidebar .sidebar-header .header-actions {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .sidebar-overlay.visible {
        opacity: 1;
        pointer-events: auto;
    }

    .preview-area {
        overflow: hidden;
        flex: 1; /* Take all available space between topbar and mobile action bar */
        min-height: 0; /* FIX: Required for proper flex shrinking in column layout */
        width: 100%;
        display: flex;
        flex-direction: column;
    }

    .paper-scroll-container {
        display: block; /* ensure block layout on mobile */
        flex: 1;
        min-height: 0;
        padding: 0.75rem 0.25rem 1.5rem;
        overflow: auto; /* enable horizontal and vertical scrollbars for overflow */
        -webkit-overflow-scrolling: touch;
    }

    .paper-wrapper {
        transform-origin: top center;
    }

    .preview-topbar {
        flex-wrap: wrap;
        gap: 4px;
        padding: 6px 8px;
    }

    .zoom-controls {
        gap: 4px;
    }

    .icon-btn {
        width: 28px;
        height: 28px;
    }

    .icon-btn .material-icons-round {
        font-size: 15px;
    }

    #zoom-level {
        font-size: 0.65rem;
        min-width: 30px;
    }

    .topbar-info {
        gap: 6px;
    }

    .page-size-indicator {
        font-size: 0.62rem;
        padding: 2px 6px;
    }

    .page-info {
        font-size: 0.62rem;
    }

    .sidebar-open-btn {
        display: inline-flex !important;
    }

    /* Show mobile action bar */
    .mobile-action-bar {
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 6px;
        padding: 10px 16px;
        background: rgba(10, 15, 30, 0.95);
        backdrop-filter: blur(12px);
        border-top: 1px solid rgba(55, 70, 95, 0.5);
        flex-shrink: 0;
        z-index: 100;
    }

    .mobile-action-btn {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 3px;
        flex: 1;
        padding: 8px 12px;
        background: linear-gradient(135deg, rgba(99, 102, 241, 0.2), rgba(124, 58, 237, 0.2));
        border: 1px solid rgba(99, 102, 241, 0.3);
        border-radius: 12px;
        color: #c4c9e2;
        font-family: 'Inter', sans-serif;
        font-size: 0.65rem;
        font-weight: 600;
        cursor: pointer;
        transition: all 0.2s ease;
        letter-spacing: 0.3px;
    }

    .mobile-action-btn:active {
        transform: scale(0.95);
        background: linear-gradient(135deg, rgba(99, 102, 241, 0.4), rgba(124, 58, 237, 0.4));
        color: white;
    }

    .mobile-action-btn .material-icons-round {
        font-size: 22px;
        color: rgba(165, 180, 252, 0.9);
    }
}

@media (max-width: 500px) {
    /* JS will handle zoom dynamically */

    .form-row {
        flex-direction: column;
    }

    .template-grid {
        grid-template-columns: 1fr 1fr;
    }

    .preview-area {
        height: calc(100vh - 60px);
    }

    .controls-sidebar {
        width: 90%;
        max-width: 300px;
    }

    /* Hide non-essential topbar elements on very small screens */
    .page-size-indicator {
        display: none;
    }

    .topbar-info {
        gap: 4px;
    }

    .preview-topbar {
        padding: 4px 6px;
        gap: 3px;
    }

    .mobile-action-btn {
        padding: 6px 8px;
        font-size: 0.6rem;
    }

    .mobile-action-btn .material-icons-round {
        font-size: 20px;
    }
}

/* ======================== MODAL (DRAW) ======================== */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(3px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--transition-fast);
}

.modal.active {
    opacity: 1;
    pointer-events: auto;
}

.modal-content {
    background: rgba(20, 30, 50, 0.98);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 550px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: rgba(10, 15, 30, 0.5);
    border-bottom: 1px solid var(--sidebar-border);
}

.modal-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--sidebar-text);
}

.modal-body {
    padding: 15px 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
    align-items: center;
}

.draw-tools {
    display: flex;
    width: 100%;
    gap: 10px;
    align-items: center;
    background: rgba(10, 15, 30, 0.5);
    padding: 8px 12px;
    border-radius: var(--radius-md);
    border: 1px solid var(--sidebar-border);
}

#draw-canvas {
    background: #ffffff;
    border: 2px solid var(--sidebar-border);
    border-radius: var(--radius-sm);
    cursor: crosshair;
    touch-action: none;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 20px;
    background: rgba(10, 15, 30, 0.5);
    border-top: 1px solid var(--sidebar-border);
}

/* Custom Paper Background */
.custom-paper {
    background-size: 100% 100% !important;
    background-repeat: no-repeat !important;
    background-position: center !important;
}

/* ======================== PRINT ======================== */
@media print {

    .no-print,
    .preview-topbar,
    .toast-container,
    .controls-sidebar,
    .mobile-action-bar {
        display: none !important;
    }

    html,
    body {
        background: #ffffff !important;
        background-color: #ffffff !important;
        background-image: none !important;
        margin: 0;
        padding: 0;
        overflow: visible !important;
        color-scheme: light !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .app-container {
        height: auto !important;
        overflow: visible !important;
        display: block !important;
        padding: 0 !important;
        background: transparent !important;
        background-image: none !important;
    }

    .preview-area {
        height: auto !important;
        overflow: visible !important;
        display: block !important;
        padding: 0 !important;
        background: transparent !important;
        background-image: none !important;
    }

    .paper-scroll-container {
        padding: 0 !important;
        overflow: visible !important;
        display: block !important;
        background: transparent !important;
        background-image: none !important;
    }

    .paper-wrapper {
        filter: none !important;
        box-shadow: none !important;
        margin: 0 !important;
        transform: none !important;
        background: transparent !important;
        zoom: 1 !important;
    }

    #pages-container {
        display: block !important;
        gap: 0 !important;
        background: transparent !important;
    }

    .paper {
        margin: 0 !important;
        box-shadow: none !important;
        border: none !important;
        border-radius: 0 !important;
        width: var(--paper-width) !important;
        height: var(--paper-height) !important;
        page-break-after: always !important;
        break-after: page !important;
        page-break-inside: avoid !important;
        background-color: #ffffff !important;
        filter: none !important;
        -webkit-filter: none !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        
        /* FIX: Removed !important so JS per-page inline padding values take precedence */
        padding: var(--paper-margin-top) var(--paper-margin-right) var(--paper-margin-bottom) var(--paper-margin-left);
    }

    .paper-content,
    .paper-content *,
    .paper-title,
    .paper-header-field,
    #display-content {
        mix-blend-mode: normal !important;
    }

    .paper-content table {
        filter: url('#hand-drawn-filter') !important;
        -webkit-filter: url('#hand-drawn-filter') !important;
        mix-blend-mode: normal !important;
        border-collapse: collapse !important;
        box-sizing: border-box !important;
    }

    .paper-content table th,
    .paper-content table td {
        border: 1.5px solid currentColor !important;
        padding: 8px 12px !important;
        text-align: left !important;
        vertical-align: top !important;
        box-sizing: border-box !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    .paper-content table::after {
        content: '' !important;
        position: absolute !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        border: 0.5px solid currentColor !important;
        opacity: 0.1 !important;
        pointer-events: none !important;
        z-index: -1 !important;
        transform: scale(1.001) !important;
    }

    .paper-content img {
        max-width: 100% !important;
        max-height: none !important;
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
        filter: url('#hand-drawn-filter') !important;
        -webkit-filter: url('#hand-drawn-filter') !important;
        mix-blend-mode: normal !important;
    }

    .inner-container {
        visibility: visible !important;
        opacity: 1 !important;
        display: block !important;
        overflow: visible !important; /* EXPERT: Prevents cutting off handwritten tails (j,y,g) at the container edge */
    }

    /* FIX #19: Preserve CamScanner effect in print (without blur which doesn't print well) */
    .paper.paper-scanned {
        filter: brightness(1.05) contrast(1.1) saturate(0.9) sepia(0.05) !important;
        -webkit-filter: brightness(1.05) contrast(1.1) saturate(0.9) sepia(0.05) !important;
    }

    /* FIX #19: Preserve Vintage Paper effect in print (vignette overlay preserved by not resetting it) */
    .paper.paper-vintage {
        filter: sepia(0.35) contrast(0.95) brightness(0.96) saturate(0.8) !important;
        -webkit-filter: sepia(0.35) contrast(0.95) brightness(0.96) saturate(0.8) !important;
    }

    /* Rules for specific paper types during print */
    .paper-ruled {
        /* Standard fallback, but allow JS inline styles to win */
        background-image: linear-gradient(transparent 37px, var(--ruled-line-color) 37px, var(--ruled-line-color) 38px, transparent 38px);
        background-size: 100% 38px;
        background-position: 0 0;
    }

    .paper-blank {
        background-color: #ffffff !important;
        background-image: none !important;
    }

    .paper-textured::before {
        display: none !important;
    }

    .paper-content {
        background: transparent !important;
    }

    .paper-content>div {
        background: transparent !important;
    }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    @page {
        margin: 0;
        size: A4 portrait;
    }
}

/* ======================== TABLE ADVANCED TOOLS ======================== */
.table-grid-chooser {
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    gap: 4px;
    margin-bottom: 20px;
    justify-content: center;
}

.grid-square {
    width: 22px;
    height: 22px;
    border: 1px solid var(--sidebar-border);
    border-radius: 3px;
    cursor: pointer;
    background: rgba(10, 15, 30, 0.3);
    transition: all 0.1s ease;
}

.grid-square.active {
    background: var(--accent);
    border-color: var(--accent-light);
    box-shadow: 0 0 10px var(--accent-glow);
}

.table-size-inputs {
    padding-top: 10px;
    border-top: 1px solid var(--sidebar-border);
}

.input-with-btns {
    display: flex;
    align-items: center;
    gap: 5px;
    background: rgba(10, 15, 30, 0.4);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-sm);
    padding: 2px;
}

.input-with-btns input {
    width: 40px !important;
    border: none !important;
    background: transparent !important;
    text-align: center;
    padding: 0 !important;
    margin: 0 !important;
}

.small-btn {
    background: var(--accent);
    color: white;
    border: none;
    width: 24px;
    height: 24px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-weight: bold;
    font-size: 16px;
}

.small-btn:hover {
    background: var(--accent-light);
}

/* Selective border hiding logic - SURGICAL control using triple-reset to win over neighbors */
.paper-content table th.no-border-top, .paper-content table td.no-border-top { border-top: 0px hidden transparent !important; }
.paper-content table th.no-border-bottom, .paper-content table td.no-border-bottom { border-bottom: 0px hidden transparent !important; }
.paper-content table th.no-border-left, .paper-content table td.no-border-left { border-left: 0px hidden transparent !important; }
.paper-content table th.no-border-right, .paper-content table td.no-border-right { border-right: 0px hidden transparent !important; }

.paper-content table.no-borders th,
.paper-content table.no-borders td {
    border: 0px hidden transparent !important;
}

/* EXPERT: Disable SVG displacement filter when borders are hidden to prevent "phantom line" artifacts */
.paper-content table.no-borders {
    filter: none !important;
}

/* Faint guides in the editor when borders are off */
.rich-editor table.no-borders th,
.rich-editor table.no-borders td {
    border: 1px dashed rgba(136, 153, 179, 0.15) !important;
}

.rich-editor table th.no-border-top, .rich-editor table td.no-border-top { border-top: 1px dashed rgba(136, 153, 179, 0.15) !important; }
.rich-editor table th.no-border-bottom, .rich-editor table td.no-border-bottom { border-bottom: 1px dashed rgba(136, 153, 179, 0.15) !important; }
.rich-editor table th.no-border-left, .rich-editor table td.no-border-left { border-left: 1px dashed rgba(136, 153, 179, 0.15) !important; }
.rich-editor table th.no-border-right, .rich-editor table td.no-border-right { border-right: 1px dashed rgba(136, 153, 179, 0.15) !important; }

/* Seamless Table Splitting (Human-like) */
.paper-content table.table-split-bottom {
    margin-bottom: 0 !important; /* Authentic assignment look without gaps */
}

.paper-content table.table-split-top,
.paper-content table.table-continuation {
    margin-top: 0 !important; /* Authentic assignment look without gaps */
}

/* Hide table outer shadow if the user hid the outer framing */
.paper-content table.hide-outer-frame::after {
    opacity: 0 !important;
}

/* Prevent outer borders from appearing spontaneously at table splits if outer frame is hidden */
.paper-content table.hide-outer-frame.table-split-top tr:first-child th,
.paper-content table.hide-outer-frame.table-split-top tr:first-child td {
    border-top: 0px hidden transparent !important;
}

.paper-content table.hide-outer-frame.table-split-bottom tr:last-child th,
.paper-content table.hide-outer-frame.table-split-bottom tr:last-child td {
    border-bottom: 0px hidden transparent !important;
}

/* Visual cue for split - optional wavy line or just open */
.table-split-indicator {
    font-size: 0.7em;
    font-style: italic;
    opacity: 0.6;
    text-align: right;
    margin-top: -8px;
    margin-bottom: 8px;
}

/* Split within a row */
.row-split-bottom td, .row-split-bottom th {
    border-bottom-style: dashed !important;
    border-bottom-width: 1px !important;
    opacity: 0.8;
}

.row-split-top td, .row-split-top th {
    border-top-style: dashed !important;
    border-top-width: 1px !important;
    opacity: 0.8;
}

/* ======================== FULLSCREEN ======================== */
.preview-area:fullscreen {
    background: var(--preview-bg);
}

.preview-area:-webkit-full-screen {
    background: var(--preview-bg);
}
/* ======================== PROCESSING OVERLAY ======================== */
.processing-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(10, 15, 30, 0.85);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.processing-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.processing-content {
    text-align: center;
    color: white;
}

.processing-content h3 {
    font-size: 1.4rem;
    margin: 20px 0 8px;
    font-weight: 600;
}

.processing-content p {
    color: var(--sidebar-text-muted);
    font-size: 0.9rem;
}

.loader-ripple {
    display: inline-block;
    position: relative;
    width: 80px;
    height: 80px;
}
.loader-ripple div {
    position: absolute;
    border: 4px solid var(--accent);
    opacity: 1;
    border-radius: 50%;
    animation: loader-ripple 1s cubic-bezier(0, 0.2, 0.8, 1) infinite;
}
.loader-ripple div:nth-child(2) {
    animation-delay: -0.5s;
}
@keyframes loader-ripple {
    0% { top: 36px; left: 36px; width: 0; height: 0; opacity: 0; }
    5% { top: 36px; left: 36px; width: 0; height: 0; opacity: 1; }
    100% { top: 0px; left: 0px; width: 72px; height: 72px; opacity: 0; }
}

/* ======================== SNAPSHOT MANAGER ======================== */
.section-desc {
    font-size: 0.7rem;
    color: var(--sidebar-text-muted);
    margin-bottom: 12px;
    line-height: 1.4;
}

.action-btn {
    padding: 0.65rem 1rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: 'Inter', sans-serif;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--transition-fast);
    color: white;
}

.snapshot-btn {
    width: 100%;
    margin-bottom: 16px;
    background: linear-gradient(135deg, var(--accent), #4f46e5) !important;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 700 !important;
    letter-spacing: 0.5px;
    box-shadow: 0 4px 12px var(--accent-glow);
}

.snapshot-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px var(--accent-glow);
    filter: brightness(1.1);
}

.snapshot-list-container {
    background: rgba(10, 15, 30, 0.3);
    border: 1px solid var(--sidebar-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.snapshot-header {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(45, 55, 80, 0.4);
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--sidebar-text-muted);
    border-bottom: 1px solid var(--sidebar-border);
}

.snapshot-list {
    max-height: 240px;
    overflow-y: auto;
}

.empty-state {
    padding: 20px;
    text-align: center;
    font-size: 0.72rem;
    color: var(--sidebar-text-muted);
    font-style: italic;
}

.snapshot-item {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(55, 70, 95, 0.2);
    display: flex;
    flex-direction: column;
    gap: 8px;
    transition: background var(--transition-fast);
    animation: slideInSnapshot 0.3s ease-out;
}

@keyframes slideInSnapshot {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}

.snapshot-item:last-child {
    border-bottom: none;
}

.snapshot-item:hover {
    background: rgba(99, 102, 241, 0.08);
}

.snapshot-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.snapshot-time {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--sidebar-text);
}

.snapshot-date {
    font-size: 0.62rem;
    color: var(--sidebar-text-muted);
}

.snapshot-actions {
    display: flex;
    gap: 6px;
}

.snapshot-action-btn {
    flex: 1;
    height: 28px;
    border-radius: 4px;
    border: 1px solid var(--sidebar-border);
    background: rgba(20, 30, 50, 0.5);
    color: var(--sidebar-text);
    font-size: 0.68rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all var(--transition-fast);
}

.snapshot-action-btn:hover {
    background: var(--sidebar-hover);
    border-color: var(--accent-light);
}

.restore-btn:hover {
    background: var(--success) !important;
    border-color: var(--success) !important;
    color: white !important;
}

.delete-btn:hover {
    background: var(--danger) !important;
    border-color: var(--danger) !important;
    color: white !important;
}

.snapshot-action-btn .material-icons-round {
    font-size: 14px;
}

/* Expert Paste Optimizer Styles */
.rich-editor img, .paper-content img {
    max-width: 100%;
    height: auto !important;
    display: block;
    margin: 15px auto;
    border-radius: 4px;
    transition: transform 0.2s ease;
}

.rich-editor table, .paper-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
}

/* Ensure pasted content respects handwriting font */
.rich-editor * {
    font-family: inherit !important;
}

.rich-editor .micro-chunk {
    display: inline;
}

/* Expert Realism: Handwritten Bullets & Lists */
.paper-content ul {
    list-style: none !important;
    padding-left: 1.5rem !important;
}

.paper-content ul li {
    position: relative;
    margin-bottom: 0.3em;
}

.paper-content ul li::before {
    content: '•';
    position: absolute;
    left: -1rem;
    font-weight: 900;
    font-size: 1.4em;
    line-height: 0.8;
    color: inherit;
    opacity: 0.85;
    transform: rotate(12deg) scale(0.9);
}

.paper-content ol {
    padding-left: 1.5rem !important;
}

.paper-content ol li {
    padding-left: 0.2rem;
    margin-bottom: 0.3em;
}

/* Expert Realism: Heading Accents */
.paper-content h1, .paper-content h2, .paper-content h3 {
    font-weight: 800 !important;
    color: inherit; /* Inherit active ink color instead of sidebar-text */
    letter-spacing: -0.5px;
    margin-top: 0.8em !important;
    margin-bottom: 0.4em !important;
    filter: drop-shadow(0.5px 0.5px 0px currentColor); /* Simulates thicker ink/marker */
}

.paper-content h1 { font-size: 1.45em !important; border-bottom: 1.5px solid rgba(0,0,0,0.1); display: inline-block; padding-bottom: 2px; }
.paper-content h2 { font-size: 1.25em !important; }
.paper-content h3 { font-size: 1.15em !important; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }

/* Expert Realism: Math/Formula protection */
.handwriting-formula {
    display: inline-block;
    white-space: nowrap;
    font-style: italic;
    padding: 0 4px;
    background: rgba(0,0,0,0.02);
    border-radius: 3px;
}

/* Ultimate Expert Realism: Optical Scanner Noise Overlay */
.paper-scanned::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: 20;
    pointer-events: none;
    opacity: 0.04;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
}

/* Ensure ultra-crisp text on high-res displays */
.hw-char, .hw-word {
    -webkit-backface-visibility: hidden;
    backface-visibility: hidden;
}

/* Asset Jump Buffer: Prevents images/tables from getting too close to bottom edge */
.inner-container img, .inner-container table {
    break-inside: avoid;
    page-break-inside: avoid;
}

/* ═══════════════════════════════════════════════════════════
   Sidebar Footer — AdSense & Legal Links
   ═══════════════════════════════════════════════════════════ */
.sidebar-footer {
    padding: 1.5rem 1.25rem 2rem;
    border-top: 1px solid var(--sidebar-border);
    margin-top: auto;
    background: rgba(8, 12, 24, 0.4);
    text-align: center;
    flex-shrink: 0;
}
.sidebar-footer-links {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px 12px;
    margin-bottom: 0.75rem;
}
.sidebar-footer-links a {
    color: var(--sidebar-text-muted);
    font-size: 0.75rem;
    text-decoration: none;
    transition: color var(--transition-fast), transform var(--transition-fast);
    font-weight: 500;
}
.sidebar-footer-links a:hover {
    color: #4a8cff;
}
.sidebar-footer-copyright {
    font-size: 0.7rem;
    color: rgba(136, 153, 179, 0.4);
    margin: 0;
}

/* ═══════════════════════════════════════════════════════════
   Site Footer — AdSense Cross-Links
   ═══════════════════════════════════════════════════════════ */
.site-footer {
    background: linear-gradient(180deg, rgba(10, 15, 30, 0.0) 0%, rgba(10, 15, 30, 0.98) 15%, #060a14 100%);
    border-top: 1px solid rgba(74, 140, 255, 0.12);
    padding: 3rem 1.5rem 1.5rem;
    margin-top: 2rem;
    font-family: 'Inter', system-ui, sans-serif;
    color: #8899b3;
}
.footer-inner {
    max-width: 1100px;
    margin: 0 auto;
}
.footer-grid {
    display: grid;
    grid-template-columns: 1.5fr 1fr 1fr 1.2fr;
    gap: 2rem;
    margin-bottom: 2rem;
}
.footer-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 0.75rem;
}
.footer-logo .material-icons-round {
    font-size: 28px;
    color: #4a8cff;
}
.footer-brand {
    font-size: 1.25rem;
    font-weight: 700;
    color: #e2e8f0;
    letter-spacing: -0.02em;
}
.footer-brand .highlight {
    color: #4af5c7;
}
.footer-about-text {
    font-size: 0.82rem;
    line-height: 1.65;
    color: #7a8ba6;
    margin: 0;
}
.footer-heading {
    font-size: 0.85rem;
    font-weight: 700;
    color: #c8d6e5;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin: 0 0 0.85rem;
}
.footer-links {
    list-style: none;
    margin: 0;
    padding: 0;
}
.footer-links li {
    margin-bottom: 0.5rem;
}
.footer-links a {
    color: #7a8ba6;
    text-decoration: none;
    font-size: 0.82rem;
    transition: color 0.2s ease, padding-left 0.2s ease;
    display: inline-flex;
    align-items: center;
}
.footer-links a:hover {
    color: #4a8cff;
    padding-left: 4px;
}
.footer-bottom {
    border-top: 1px solid rgba(55, 70, 95, 0.35);
    padding-top: 1.25rem;
    text-align: center;
}
.footer-bottom p {
    font-size: 0.78rem;
    color: #5a6b80;
    margin: 0;
}
@media (max-width: 768px) {
    .footer-grid {
        grid-template-columns: 1fr 1fr;
        gap: 1.5rem;
    }
}
@media (max-width: 480px) {
    .footer-grid {
        grid-template-columns: 1fr;
        gap: 1.25rem;
    }
    .site-footer {
        padding: 2rem 1rem 1rem;
    }
}

/* ==========================================================================
   LIGHT MODE STYLING & COMPONENT OVERRIDES
   ========================================================================== */
body.light-theme {
    /* UI Palette — Ultra-Premium Light Glassmorphic Theme */
    --sidebar-bg: #ffffff;
    --sidebar-glass: #f8fafc;
    --sidebar-border: rgba(99, 102, 241, 0.16);
    --sidebar-hover: rgba(99, 102, 241, 0.05);
    --sidebar-text: #0f172a;
    --sidebar-text-muted: #64748b;
    --preview-bg: #f1f5f9;
    --accent: #4f46e5;
    --accent-light: #6366f1;
    --accent-glow: rgba(79, 70, 229, 0.12);
    --accent-hover: #4338ca;
    
    background: var(--preview-bg);
    color: var(--sidebar-text);
}

/* Custom component overrides for Light Mode to fix hardcoded dark backgrounds */
body.light-theme .orient-btn {
    background: rgba(15, 23, 42, 0.05) !important;
    border-color: rgba(99, 102, 241, 0.16) !important;
    color: var(--sidebar-text-muted) !important;
}

body.light-theme .orient-btn:hover {
    background: rgba(99, 102, 241, 0.08) !important;
    border-color: var(--accent) !important;
    color: var(--sidebar-text) !important;
}

body.light-theme .orient-btn.active {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    color: #ffffff !important;
    box-shadow: 0 2px 10px var(--accent-glow) !important;
}

body.light-theme .inline-font-size-wrapper {
    background: rgba(15, 23, 42, 0.05) !important;
    border-color: rgba(99, 102, 241, 0.16) !important;
}

body.light-theme .fs-preset {
    background: rgba(15, 23, 42, 0.05) !important;
    border-color: rgba(99, 102, 241, 0.1) !important;
    color: var(--sidebar-text-muted) !important;
}

body.light-theme .fs-preset:hover {
    background: rgba(99, 102, 241, 0.08) !important;
    border-color: rgba(99, 102, 241, 0.25) !important;
    color: var(--accent) !important;
}

body.light-theme .fs-preset.active {
    background: var(--accent) !important;
    border-color: var(--accent) !important;
    color: #ffffff !important;
}

body.light-theme .toolbar-select {
    background-color: rgba(15, 23, 42, 0.05) !important;
    border-color: rgba(99, 102, 241, 0.16) !important;
    color: var(--sidebar-text) !important;
}

body.light-theme .modal-content {
    background: #ffffff !important;
    border-color: rgba(99, 102, 241, 0.2) !important;
    box-shadow: 0 10px 40px rgba(15, 23, 42, 0.15) !important;
}

body.light-theme .modal-header,
body.light-theme .modal-footer,
body.light-theme .draw-tools {
    background: #f8fafc !important;
    border-color: rgba(99, 102, 241, 0.16) !important;
}

body.light-theme .snapshot-action-btn {
    background: rgba(15, 23, 42, 0.05) !important;
    border-color: rgba(99, 102, 241, 0.16) !important;
    color: var(--sidebar-text) !important;
}

body.light-theme .snapshot-action-btn:hover {
    background: rgba(99, 102, 241, 0.08) !important;
    border-color: var(--accent-light) !important;
    color: var(--accent) !important;
}

body.light-theme #margin-scope,
body.light-theme #target-page-select {
    background: rgba(255, 255, 255, 0.8) !important;
    border: 1px solid rgba(99, 102, 241, 0.16) !important;
    color: #0f172a !important;
}

body.light-theme .mini-select {
    background: rgba(255, 255, 255, 0.8) !important;
    border: 1px solid rgba(99, 102, 241, 0.16) !important;
    color: #0f172a !important;
}

body.light-theme .snapshot-list-container {
    background: rgba(255, 255, 255, 0.6) !important;
    border: 1px solid rgba(99, 102, 241, 0.16) !important;
}

body.light-theme .snapshot-header {
    background: #f8fafc !important;
    border-bottom: 1px solid rgba(99, 102, 241, 0.16) !important;
    color: var(--sidebar-text-muted) !important;
}

body.light-theme .snapshot-item {
    border-bottom: 1px solid rgba(99, 102, 241, 0.1) !important;
}

body.light-theme .snapshot-item:hover {
    background: rgba(99, 102, 241, 0.05) !important;
}



/* Force Solid Backgrounds in Light Mode (fixes cloudy grey shadow leakage) */
body.light-theme .controls-sidebar,
body.light-theme .sidebar-footer {
    background: #ffffff !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
}

body.light-theme .editor-toolbar {
    background: #f8fafc !important;
    border-color: rgba(99, 102, 241, 0.16) !important;
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

body.light-theme .rich-editor {
    background: #ffffff !important;
    border-color: rgba(99, 102, 241, 0.16) !important;
    color: #0f172a !important;
}

body.light-theme .rich-editor:focus {
    background: #ffffff !important;
    border-color: var(--accent) !important;
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.15), 0 0 0 2px rgba(99, 102, 241, 0.15) !important;
}

/* Scrollbar override for Light Mode */
body.light-theme ::-webkit-scrollbar-track {
    background: rgba(226, 232, 240, 0.5);
}
body.light-theme ::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.25), rgba(6, 182, 212, 0.25));
}
body.light-theme ::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, rgba(99, 102, 241, 0.5), rgba(6, 182, 212, 0.5));
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.25);
}

/* Input Fields overrides in Light Mode */
body.light-theme input[type="text"],
body.light-theme input[type="number"],
body.light-theme select {
    background: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(15, 23, 42, 0.12);
    color: #0f172a;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.05);
}
body.light-theme input[type="text"]:focus,
body.light-theme input[type="number"]:focus,
body.light-theme select:focus {
    background: #ffffff;
    border-color: var(--accent);
    box-shadow: 0 0 15px rgba(99, 102, 241, 0.15), 0 0 0 2px rgba(99, 102, 241, 0.15);
}
body.light-theme input[type="text"]::placeholder {
    color: rgba(15, 23, 42, 0.4);
}

/* Range Slider overrides in Light Mode */
body.light-theme input[type="range"] {
    background: rgba(15, 23, 42, 0.08);
    border: 1px solid rgba(15, 23, 42, 0.03);
}
body.light-theme input[type="range"]::-webkit-slider-thumb {
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    box-shadow: 0 0 8px rgba(79, 70, 229, 0.3), inset 0 1px 1px rgba(255,255,255,0.5);
}
body.light-theme input[type="range"]::-webkit-slider-thumb:hover {
    background: linear-gradient(135deg, #ffffff, var(--accent-light));
    box-shadow: 0 0 12px rgba(79, 70, 229, 0.5);
}
body.light-theme input[type="range"]::-moz-range-thumb {
    background: linear-gradient(135deg, var(--accent-light), var(--accent));
    box-shadow: 0 0 8px rgba(79, 70, 229, 0.3);
}
body.light-theme input[type="range"]::-moz-range-thumb:hover {
    background: linear-gradient(135deg, #ffffff, var(--accent-light));
    box-shadow: 0 0 12px rgba(79, 70, 229, 0.5);
}

/* Checkboxes overrides in Light Mode */
body.light-theme .checkmark {
    background: rgba(255, 255, 255, 0.9);
    border-color: rgba(15, 23, 42, 0.18);
}
body.light-theme .checkbox-label:hover .checkmark {
    border-color: var(--accent);
    box-shadow: 0 0 8px rgba(99, 102, 241, 0.15);
}
body.light-theme .checkbox-label input[type="checkbox"]:checked + .checkmark {
    background: var(--accent-grad);
    border-color: var(--accent);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.3);
}

/* Secondary Buttons overrides in Light Mode */
body.light-theme .secondary-btn {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(15, 23, 42, 0.12);
    color: #475569;
}
body.light-theme .secondary-btn:hover {
    background: rgba(99, 102, 241, 0.08);
    border-color: var(--accent-light);
    color: var(--accent);
}

/* Editor Toolbar overrides in Light Mode */
body.light-theme .editor-toolbar {
    background: rgba(241, 245, 249, 0.9);
    border-color: rgba(15, 23, 42, 0.08);
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
body.light-theme .toolbar-btn {
    background: rgba(255, 255, 255, 0.6);
    color: #475569;
    border: 1px solid rgba(15, 23, 42, 0.06);
}
body.light-theme .toolbar-btn:hover {
    background: rgba(99, 102, 241, 0.08);
    color: var(--accent);
    border-color: rgba(99, 102, 241, 0.25);
}
body.light-theme .toolbar-btn.active {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

/* Template Card overrides in Light Mode */
body.light-theme .template-card {
    background: rgba(255, 255, 255, 0.6);
    border-color: rgba(15, 23, 42, 0.08);
}
body.light-theme .template-card:hover {
    background: rgba(99, 102, 241, 0.08);
    border-color: rgba(99, 102, 241, 0.3);
    color: var(--accent);
}
body.light-theme .template-card:hover .material-icons-round {
    color: var(--accent);
}

/* Extra Details & Contrast Tweaks */
body.light-theme .sidebar-section {
    border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}
body.light-theme .sidebar-header {
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.95), rgba(248, 250, 252, 0.95));
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
}
body.light-theme .sidebar-header h1 {
    color: #0f172a;
}
body.light-theme .expert-controls {
    background: rgba(255, 255, 255, 0.5);
    border-color: rgba(15, 23, 42, 0.08);
}
body.light-theme .section-toggle {
    color: #334155;
}
body.light-theme .section-toggle:hover {
    background: rgba(99, 102, 241, 0.06);
    color: var(--accent);
}
body.light-theme .preview-topbar {
    background: rgba(255, 255, 255, 0.75);
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.05), inset 0 1px 0 rgba(255, 255, 255, 0.8);
}
body.light-theme .icon-btn {
    background: rgba(255, 255, 255, 0.7);
    border-color: rgba(15, 23, 42, 0.12);
}
body.light-theme .icon-btn:hover {
    background: rgba(99, 102, 241, 0.08);
    border-color: var(--accent-light);
    color: var(--accent);
}
body.light-theme #zoom-level,
body.light-theme .page-size-indicator,
body.light-theme .page-info {
    color: #475569;
}
body.light-theme .mobile-action-bar {
    background: rgba(255, 255, 255, 0.97);
    border-top: 1px solid rgba(15, 23, 42, 0.12);
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.05);
}
body.light-theme .mobile-action-btn {
    background: rgba(99, 102, 241, 0.06);
    border: 1px solid rgba(99, 102, 241, 0.15);
    color: #334155;
}
body.light-theme .mobile-action-btn:hover {
    background: rgba(99, 102, 241, 0.12);
    border-color: rgba(99, 102, 241, 0.3);
    color: var(--accent);
}
body.light-theme .mobile-action-btn:active {
    background: rgba(99, 102, 241, 0.18);
    color: var(--accent);
}
body.light-theme .mobile-action-btn .material-icons-round {
    color: var(--accent-light);
}

/* ======================== GLOBAL APP HEADER & RESPONSIVENESS ======================== */
.app-header {
    height: 60px;
    background: var(--sidebar-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--sidebar-border);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    position: relative;
    z-index: 1002;
    flex-shrink: 0;
}

body.light-theme .app-header {
    background: #ffffff;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 2px 10px rgba(0,0,0,0.03);
}

.app-header .header-inner {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.app-header .header-logo {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.app-header .header-logo .material-icons-round {
    font-size: 28px;
    color: var(--accent);
    filter: drop-shadow(0 0 8px var(--accent-glow));
}

.app-header .header-logo-text {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--sidebar-text);
    letter-spacing: -0.5px;
}

.app-header .header-logo-text .hl {
    background: linear-gradient(135deg, var(--accent-light), #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.app-header .desktop-nav {
    display: flex;
    align-items: center;
}

.app-header .nav-links {
    display: flex;
    gap: 0.25rem;
    list-style: none;
}

.app-header .nav-links a {
    display: block;
    padding: 0.4rem 0.8rem;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--sidebar-text-muted);
    text-decoration: none;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.app-header .nav-links a:hover {
    color: var(--sidebar-text);
    background: var(--sidebar-hover);
}

.app-header .nav-links a.active {
    color: white !important;
    background: var(--accent-grad);
    box-shadow: 0 2px 8px var(--accent-glow);
}

/* Language Switcher Styling */
.lang-select-wrapper {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: var(--sidebar-hover);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.08);
    margin-left: 0.5rem;
}

.lang-select-wrapper .lang-icon {
    font-size: 16px;
    color: var(--sidebar-text-muted);
}

.lang-select {
    background: transparent;
    border: none;
    color: var(--sidebar-text);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    outline: none;
}

.lang-select option {
    background: #1e2538;
    color: var(--sidebar-text);
}

.mobile-nav-menu .lang-select-wrapper {
    margin: 1rem 1.5rem;
    justify-content: center;
    background: rgba(255, 255, 255, 0.05);
}

/* Mobile Menu Toggle */
.mobile-menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--sidebar-text-muted);
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.mobile-menu-toggle:hover {
    color: var(--sidebar-text);
    background: var(--sidebar-hover);
}

/* Mobile Nav Menu Overlay */
.mobile-nav-menu {
    display: none;
    position: fixed;
    top: 60px;
    left: 0;
    right: 0;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--sidebar-border);
    padding: 1rem;
    z-index: 1001;
    flex-direction: column;
    gap: 8px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.25);
}

body.light-theme .mobile-nav-menu {
    background: #ffffff;
    border-bottom: 1px solid rgba(15, 23, 42, 0.08);
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.08);
}

.mobile-nav-menu a {
    display: block;
    padding: 0.75rem 1rem;
    color: var(--sidebar-text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.mobile-nav-menu a:hover {
    color: var(--sidebar-text);
    background: var(--sidebar-hover);
}

.mobile-nav-menu a.active {
    color: white !important;
    background: var(--accent-grad);
}

/* Layout Adaptation */
.app-container {
    height: calc(100vh - 60px) !important;
}

/* Responsive adjustments for header */
@media (max-width: 900px) {
    .app-header {
        padding: 0 1rem;
    }
    .app-header .desktop-nav {
        display: none;
    }
    .mobile-menu-toggle {
        display: flex;
    }
    .mobile-nav-menu.open {
        display: flex;
    }
}

/* Draft Mode Toggle Active Styling */
#draft-mode-toggle.active {
    background: rgba(234, 179, 8, 0.2);
    border-color: rgba(234, 179, 8, 0.6);
    color: #eab308;
    box-shadow: 0 0 8px rgba(234, 179, 8, 0.3);
}

#draft-mode-toggle.active:hover {
    background: rgba(234, 179, 8, 0.3);
    border-color: rgba(234, 179, 8, 0.8);
    color: #f59e0b;
    transform: scale(1.08);
}

body.light-theme #draft-mode-toggle.active {
    background: rgba(217, 119, 6, 0.15);
    border-color: rgba(217, 119, 6, 0.4);
    color: #d97706;
}

body.light-theme #draft-mode-toggle.active:hover {
    background: rgba(217, 119, 6, 0.25);
    border-color: rgba(217, 119, 6, 0.6);
    color: #b45309;
    transform: scale(1.08);
}

/* ═══════════════════════════════════════════════════════════
   FAQ Section Styles
   ═══════════════════════════════════════════════════════════ */
.faq-section {
    padding: 5rem 1.5rem 3rem;
    font-family: 'Inter', system-ui, sans-serif;
    background: linear-gradient(180deg, rgba(10, 15, 30, 0.0) 0%, rgba(6, 10, 20, 0.4) 100%);
    border-top: 1px solid rgba(74, 140, 255, 0.08);
}

.faq-inner {
    max-width: 850px;
    margin: 0 auto;
}

.faq-section-title {
    font-size: 2.25rem;
    font-weight: 800;
    text-align: center;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, #ffffff 30%, #a5b4fc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.03em;
}

.faq-section-subtitle {
    font-size: 1rem;
    text-align: center;
    color: #7a8ba6;
    margin-bottom: 3rem;
    line-height: 1.5;
}

.faq-accordion {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.faq-item {
    background: rgba(15, 23, 42, 0.4);
    border: 1px solid rgba(74, 140, 255, 0.1);
    border-radius: 12px;
    overflow: hidden;
    transition: border-color 0.25s ease, box-shadow 0.25s ease, background-color 0.25s ease;
}

.faq-item:hover {
    border-color: rgba(74, 140, 255, 0.25);
    background: rgba(15, 23, 42, 0.6);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.faq-item.active {
    border-color: rgba(74, 140, 255, 0.4);
    background: rgba(15, 23, 42, 0.75);
    box-shadow: 0 4px 25px rgba(74, 140, 255, 0.05);
}

.faq-question-btn {
    width: 100%;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem 1.5rem;
    background: none;
    border: none;
    color: #e2e8f0;
    font-size: 1.05rem;
    font-weight: 600;
    text-align: left;
    cursor: pointer;
    transition: color 0.25s ease;
}

.faq-question-btn:focus-visible {
    outline: 2px solid #4a8cff;
    outline-offset: -2px;
}

.faq-item:hover .faq-question-btn {
    color: #ffffff;
}

.faq-item.active .faq-question-btn {
    color: #4a8cff;
}

.faq-icon {
    font-size: 24px;
    color: #7a8ba6;
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1), color 0.25s ease;
}

.faq-item.active .faq-icon {
    transform: rotate(180deg);
    color: #4a8cff;
}

.faq-answer {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s cubic-bezier(0.4, 0, 0.2, 1), opacity 0.3s ease;
    opacity: 0;
}

.faq-answer-content {
    padding: 0 1.5rem 1.5rem;
}

.faq-answer p {
    margin: 0;
    color: #8899b3;
    font-size: 0.95rem;
    line-height: 1.6;
}

/* Light Theme Overrides */
body.light-theme .faq-section {
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    border-top: 1px solid rgba(99, 102, 241, 0.12);
}

body.light-theme .faq-section-title {
    background: linear-gradient(135deg, #0f172a 30%, #4338ca 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

body.light-theme .faq-section-subtitle {
    color: #64748b;
}

body.light-theme .faq-item {
    background: #ffffff;
    border: 1px solid rgba(99, 102, 241, 0.12);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
}

body.light-theme .faq-item:hover {
    border-color: rgba(99, 102, 241, 0.3);
    background: #ffffff;
    box-shadow: 0 6px 16px rgba(99, 102, 241, 0.08);
}

body.light-theme .faq-item.active {
    border-color: rgba(99, 102, 241, 0.4);
    background: #ffffff;
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.1);
}

body.light-theme .faq-question-btn {
    color: #334155;
}

body.light-theme .faq-item:hover .faq-question-btn {
    color: #0f172a;
}

body.light-theme .faq-item.active .faq-question-btn {
    color: #4f46e5;
}

body.light-theme .faq-icon {
    color: #64748b;
}

body.light-theme .faq-item.active .faq-icon {
    color: #4f46e5;
}

body.light-theme .faq-answer p {
    color: #475569;
}


