/* ============================================
   RESET & BASE
============================================ */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #eff6ff;
    --accent: #7c3aed;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #d97706;
    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface2: #f8fafc;
    --border: #e2e8f0;
    --border2: #cbd5e1;
    --text: #0f172a;
    --text2: #475569;
    --text3: #94a3b8;
    --header-h: 56px;
    --sidebar-w: 280px;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1), 0 4px 6px rgba(0,0,0,0.05);
    --transition: all 0.2s ease;
}

/* Dark Theme */
[data-theme="dark"] {
    --primary: #3b82f6;
    --primary-dark: #2563eb;
    --primary-light: #1e293b;
    --accent: #8b5cf6;
    --bg: #0f172a;
    --surface: #1e293b;
    --surface2: #1a2332;
    --border: #334155;
    --border2: #475569;
    --text: #e2e8f0;
    --text2: #94a3b8;
    --text3: #64748b;
    --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.25), 0 2px 4px rgba(0,0,0,0.15);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.3), 0 4px 6px rgba(0,0,0,0.2);
}

[data-theme="dark"] .paper-preview {
    box-shadow: 0 4px 24px rgba(0,0,0,0.5);
}

[data-theme="dark"] .markdown-textarea {
    background: var(--surface);
    color: var(--text);
}

[data-theme="dark"] .drop-message {
    background: rgba(30,41,59,0.97);
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    overflow: hidden;
}

/* ============================================
   HEADER
============================================ */
.header {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-shadow: var(--shadow);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 20px;
    font-weight: 700;
    color: var(--text);
}

.logo-icon {
    font-size: 24px;
}

.logo-accent {
    color: var(--primary);
}

.tagline {
    color: var(--text3);
    font-size: 12px;
    border-left: 1px solid var(--border);
    padding-left: 16px;
}

.header-right {
    display: flex;
    gap: 8px;
}

/* ============================================
   BUTTONS
============================================ */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 7px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition);
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-outline {
    background: transparent;
    color: var(--primary);
    border: 1px solid var(--primary);
    padding: 6px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: var(--transition);
}
.btn-outline:hover {
    background: var(--primary-light);
}

.btn-small {
    background: var(--surface2);
    color: var(--text2);
    border: 1px solid var(--border);
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    transition: var(--transition);
    white-space: nowrap;
}
.btn-small:hover {
    background: var(--border);
    color: var(--text);
}
.btn-small.active-toggle {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.upload-btn {
    background: var(--surface2);
    color: var(--text2);
    border: 1px solid var(--border);
    padding: 5px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 12px;
    transition: var(--transition);
    white-space: nowrap;
    display: inline-block;
}
.upload-btn:hover {
    background: var(--border);
    color: var(--text);
}

/* ============================================
   MAIN LAYOUT
============================================ */
.main-layout {
    display: grid;
    grid-template-columns: 1fr 1fr var(--sidebar-w);
    height: calc(100vh - var(--header-h));
    margin-top: var(--header-h);
    overflow: hidden;
}

/* ============================================
   PANEL COMMONS
============================================ */
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    min-height: 42px;
}

.panel-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.panel-actions {
    display: flex;
    gap: 6px;
    align-items: center;
}

/* ============================================
   EDITOR PANEL
============================================ */
.editor-panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--surface);
    overflow: hidden;
}

.drop-zone {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.drop-zone.drag-over {
    background: var(--primary-light);
}

.drop-message {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 10;
    background: rgba(239,246,255,0.97);
}

.drop-zone.drag-over .drop-message {
    opacity: 1;
}

.drop-icon {
    font-size: 48px;
}

.drop-message p {
    color: var(--text2);
    font-size: 14px;
    text-align: center;
}

.drop-sub {
    font-size: 12px !important;
    color: var(--text3) !important;
}

.markdown-textarea {
    width: 100%;
    height: 100%;
    border: none;
    outline: none;
    resize: none;
    font-family: 'Courier New', monospace;
    font-size: 13px;
    line-height: 1.6;
    padding: 16px;
    color: var(--text);
    background: var(--surface);
    tab-size: 2;
}

.markdown-textarea::placeholder {
    color: var(--text3);
}

/* ── Cursor & Selection Visibility ── */
/* Custom cursor for Markdown Input panel */
.markdown-textarea {
    caret-color: #2563eb;
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20'%3E%3Ccircle cx='10' cy='10' r='4' fill='none' stroke='%232563eb' stroke-width='2'/%3E%3Cline x1='10' y1='0' x2='10' y2='6' stroke='%232563eb' stroke-width='1.5'/%3E%3Cline x1='10' y1='14' x2='10' y2='20' stroke='%232563eb' stroke-width='1.5'/%3E%3Cline x1='0' y1='10' x2='6' y2='10' stroke='%232563eb' stroke-width='1.5'/%3E%3Cline x1='14' y1='10' x2='20' y2='10' stroke='%232563eb' stroke-width='1.5'/%3E%3C/svg%3E") 10 10, text;
}
.markdown-textarea:focus {
    box-shadow: inset 4px 0 0 0 var(--primary);
    outline: none;
}
.markdown-textarea::selection {
    background: rgba(37, 99, 235, 0.35);
    color: inherit;
}
.markdown-textarea::-moz-selection {
    background: rgba(37, 99, 235, 0.35);
    color: inherit;
}

/* Custom cursor for Live Preview panel */
.preview-wrapper {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20'%3E%3Ccircle cx='10' cy='10' r='4' fill='none' stroke='%237c3aed' stroke-width='2'/%3E%3Cline x1='10' y1='0' x2='10' y2='6' stroke='%237c3aed' stroke-width='1.5'/%3E%3Cline x1='10' y1='14' x2='10' y2='20' stroke='%237c3aed' stroke-width='1.5'/%3E%3Cline x1='0' y1='10' x2='6' y2='10' stroke='%237c3aed' stroke-width='1.5'/%3E%3Cline x1='14' y1='10' x2='20' y2='10' stroke='%237c3aed' stroke-width='1.5'/%3E%3C/svg%3E") 10 10, text;
}
.preview-wrapper:focus-within,
.preview-wrapper:focus {
    box-shadow: inset 4px 0 0 0 var(--accent);
}
.preview-content ::selection {
    background: rgba(124, 58, 237, 0.35);
    color: inherit;
}
.preview-content ::-moz-selection {
    background: rgba(124, 58, 237, 0.35);
    color: inherit;
}

/* Dark theme cursor & selection adjustments */
[data-theme="dark"] .markdown-textarea {
    caret-color: #60a5fa;
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20'%3E%3Ccircle cx='10' cy='10' r='4' fill='none' stroke='%2360a5fa' stroke-width='2'/%3E%3Cline x1='10' y1='0' x2='10' y2='6' stroke='%2360a5fa' stroke-width='1.5'/%3E%3Cline x1='10' y1='14' x2='10' y2='20' stroke='%2360a5fa' stroke-width='1.5'/%3E%3Cline x1='0' y1='10' x2='6' y2='10' stroke='%2360a5fa' stroke-width='1.5'/%3E%3Cline x1='14' y1='10' x2='20' y2='10' stroke='%2360a5fa' stroke-width='1.5'/%3E%3C/svg%3E") 10 10, text;
}
[data-theme="dark"] .markdown-textarea:focus {
    box-shadow: inset 4px 0 0 0 #3b82f6;
}
[data-theme="dark"] .markdown-textarea::selection {
    background: rgba(59, 130, 246, 0.45);
}
[data-theme="dark"] .markdown-textarea::-moz-selection {
    background: rgba(59, 130, 246, 0.45);
}
[data-theme="dark"] .preview-wrapper {
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20'%3E%3Ccircle cx='10' cy='10' r='4' fill='none' stroke='%23a78bfa' stroke-width='2'/%3E%3Cline x1='10' y1='0' x2='10' y2='6' stroke='%23a78bfa' stroke-width='1.5'/%3E%3Cline x1='10' y1='14' x2='10' y2='20' stroke='%23a78bfa' stroke-width='1.5'/%3E%3Cline x1='0' y1='10' x2='6' y2='10' stroke='%23a78bfa' stroke-width='1.5'/%3E%3Cline x1='14' y1='10' x2='20' y2='10' stroke='%23a78bfa' stroke-width='1.5'/%3E%3C/svg%3E") 10 10, text;
}
[data-theme="dark"] .preview-wrapper:focus-within,
[data-theme="dark"] .preview-wrapper:focus {
    box-shadow: inset 4px 0 0 0 #8b5cf6;
}
[data-theme="dark"] .preview-content ::selection {
    background: rgba(139, 92, 246, 0.45);
}
[data-theme="dark"] .preview-content ::-moz-selection {
    background: rgba(139, 92, 246, 0.45);
}

/* Source-line highlight flash when syncing */
.preview-content [data-source-line].sync-highlight {
    background: rgba(37, 99, 235, 0.12);
    border-radius: 3px;
    transition: background 0.6s ease;
}
[data-theme="dark"] .preview-content [data-source-line].sync-highlight {
    background: rgba(59, 130, 246, 0.15);
}

/* Mirrored selection highlight (persistent until deselected) */
.sync-selection {
    background: rgba(250, 204, 21, 0.45);
    border-radius: 2px;
    box-shadow: 0 0 0 1px rgba(250, 204, 21, 0.6);
    transition: background 0.2s ease;
}
[data-theme="dark"] .sync-selection {
    background: rgba(96, 165, 250, 0.3);
    box-shadow: 0 0 0 1px rgba(96, 165, 250, 0.4);
}

.editor-footer {
    display: flex;
    gap: 16px;
    padding: 6px 14px;
    border-top: 1px solid var(--border);
    background: var(--surface2);
    font-size: 11px;
    color: var(--text3);
}

/* ============================================
   PREVIEW PANEL
============================================ */
.preview-panel {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg);
    overflow: hidden;
}

.preview-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    justify-content: center;
}

.paper-preview {
    background: white;
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 700px;
    min-height: 297mm;
    position: relative;
    transition: var(--transition);
}

.preview-content {
    width: 100%;
    height: 100%;
}

.empty-preview {
    color: var(--text3);
    font-size: 14px;
    text-align: center;
    padding: 40px 20px;
    font-style: italic;
}

/* ============================================
   CONTROLS PANEL
============================================ */
.controls-panel {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    overflow: hidden;
}

.controls-body {
    flex: 1;
    overflow-y: auto;
    padding: 0;
}

.controls-body::-webkit-scrollbar {
    width: 4px;
}
.controls-body::-webkit-scrollbar-track {
    background: var(--surface2);
}
.controls-body::-webkit-scrollbar-thumb {
    background: var(--border2);
    border-radius: 2px;
}

/* ============================================
   SECTION BLOCKS
============================================ */
.section-block {
    border-bottom: 1px solid var(--border);
    padding: 12px 14px;
}

.section-title {
    font-size: 11px;
    font-weight: 700;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 10px;
}

/* ============================================
   CONTROL ROWS
============================================ */
.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
    gap: 8px;
}

.control-row:last-child {
    margin-bottom: 0;
}

.control-label {
    font-size: 12px;
    color: var(--text2);
    white-space: nowrap;
    flex-shrink: 0;
    min-width: 90px;
}

.control-select {
    flex: 1;
    padding: 5px 8px;
    border: 1px solid var(--border2);
    border-radius: var(--radius-sm);
    font-size: 12px;
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    outline: none;
    transition: var(--transition);
}

.control-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}

/* ============================================
   COLOR INPUT
============================================ */
.color-input-wrap {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    justify-content: flex-end;
}

.color-picker {
    width: 32px;
    height: 26px;
    border: 1px solid var(--border2);
    border-radius: var(--radius-sm);
    cursor: pointer;
    padding: 2px;
    background: var(--surface);
}

.color-hex {
    font-size: 11px;
    color: var(--text3);
    font-family: monospace;
    min-width: 52px;
}

/* ============================================
   NUMBER INPUT
============================================ */
.number-input-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    justify-content: flex-end;
}

.num-btn {
    width: 26px;
    height: 26px;
    border: 1px solid var(--border2);
    border-radius: var(--radius-sm);
    background: var(--surface2);
    color: var(--text);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
    line-height: 1;
}

.num-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.num-input {
    width: 52px;
    height: 26px;
    border: 1px solid var(--border2);
    border-radius: var(--radius-sm);
    text-align: center;
    font-size: 12px;
    color: var(--text);
    background: var(--surface);
    outline: none;
    transition: var(--transition);
}

.num-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}

/* Remove number input arrows */
.num-input::-webkit-inner-spin-button,
.num-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.num-input { -moz-appearance: textfield; }

/* ============================================
   FONT SIZE TABLE
============================================ */
.font-size-table,
.font-size-fixed {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-top: 8px;
    overflow: hidden;
}

.fst-header {
    background: var(--border);
    padding: 5px 10px;
    font-size: 10px;
    font-weight: 700;
    color: var(--text2);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.fst-row {
    display: flex;
    align-items: center;
    padding: 4px 10px;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}

.fst-row:last-child { border-bottom: none; }

.fst-label {
    font-size: 11px;
    color: var(--text2);
    min-width: 36px;
    font-weight: 600;
}

.fst-value {
    flex: 1;
    font-size: 12px;
    font-weight: 700;
    color: var(--primary);
    font-family: monospace;
}

.fst-unit {
    font-size: 10px;
    color: var(--text3);
}

.fst-row-fixed {
    display: flex;
    align-items: center;
    padding: 4px 10px;
    border-bottom: 1px solid var(--border);
    gap: 8px;
}
.fst-row-fixed:last-child { border-bottom: none; }

.fst-input {
    flex: 1;
    height: 24px;
    border: 1px solid var(--border2);
    border-radius: 3px;
    text-align: center;
    font-size: 12px;
    color: var(--text);
    background: var(--surface);
    outline: none;
}
.fst-input:focus { border-color: var(--primary); }
.fst-input::-webkit-inner-spin-button,
.fst-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.fst-input { -moz-appearance: textfield; }

/* ============================================
   RADIO GROUP
============================================ */
.radio-group {
    display: flex;
    gap: 12px;
    flex: 1;
    justify-content: flex-end;
}

.radio-label {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--text2);
    cursor: pointer;
}

.radio-label input[type="radio"] {
    accent-color: var(--primary);
    cursor: pointer;
}

/* ============================================
   MARGINS
============================================ */
.margins-block {
    margin-top: 8px;
}

.margins-label {
    font-size: 11px;
    color: var(--text3);
    margin-bottom: 6px;
}

.margins-grid {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 4px;
    align-items: center;
    justify-items: center;
}

.margin-input-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.margin-label {
    font-size: 10px;
    color: var(--text3);
}

.margin-input {
    width: 52px;
    height: 26px;
    border: 1px solid var(--border2);
    border-radius: var(--radius-sm);
    text-align: center;
    font-size: 12px;
    color: var(--text);
    background: var(--surface);
    outline: none;
    transition: var(--transition);
}

.margin-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}

.margin-input::-webkit-inner-spin-button,
.margin-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.margin-input { -moz-appearance: textfield; }

.margin-center-icon {
    font-size: 24px;
    opacity: 0.3;
}

/* ============================================
   TOGGLE SWITCH
============================================ */
.zero-space-toggle {
    align-items: center;
}

.toggle-switch {
    position: relative;
    width: 38px;
    height: 20px;
    display: inline-block;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--border2);
    border-radius: 20px;
    cursor: pointer;
    transition: var(--transition);
}

.toggle-slider::before {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    left: 3px;
    top: 3px;
    background: white;
    border-radius: 50%;
    transition: var(--transition);
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.toggle-switch input:checked + .toggle-slider {
    background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(18px);
}

/* ============================================
   FORMAT BUTTONS
============================================ */
.format-buttons {
    display: flex;
    gap: 6px;
}

.format-btn {
    flex: 1;
    padding: 8px 4px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface2);
    color: var(--text2);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    text-align: center;
    transition: var(--transition);
}

.format-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--primary-light);
}

.format-btn.active {
    border-color: var(--primary);
    background: var(--primary);
    color: white;
}

/* ============================================
   DOWNLOAD / PRINT
============================================ */
.download-section {
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    position: sticky;
    bottom: 0;
    background: var(--surface);
    border-top: 2px solid var(--border);
}

.download-btn {
    width: 100%;
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    letter-spacing: 0.02em;
    box-shadow: 0 2px 8px rgba(37,99,235,0.4);
}

.download-btn:hover {
    background: var(--primary-dark);
    box-shadow: 0 4px 12px rgba(37,99,235,0.5);
    transform: translateY(-1px);
}

.download-btn:active {
    transform: translateY(0);
}

.print-btn {
    width: 100%;
    padding: 9px;
    background: var(--surface2);
    color: var(--text2);
    border: 1px solid var(--border2);
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.print-btn:hover {
    background: var(--border);
    color: var(--text);
}

/* ============================================
   PROGRESS OVERLAY
============================================ */
.progress-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.progress-box {
    background: var(--surface);
    border-radius: var(--radius);
    padding: 32px 40px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    min-width: 240px;
}

.progress-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.progress-text {
    font-size: 14px;
    color: var(--text2);
    margin-bottom: 12px;
}

.progress-bar-wrap {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    width: 0%;
    transition: width 0.3s ease;
}

/* ============================================
   TOAST
============================================ */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: #1e293b;
    color: white;
    padding: 10px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 2000;
    transition: transform 0.3s ease;
    white-space: nowrap;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }

/* ============================================
   PREVIEW CONTENT STYLES
   (Applied to the paper preview element)
============================================ */
.preview-content h1,
.preview-content h2,
.preview-content h3,
.preview-content h4,
.preview-content h5,
.preview-content h6 {
    font-weight: 700;
    line-height: 1.2;
}

.preview-content p {
    margin: 0;
}

.preview-content ul,
.preview-content ol {
    padding-left: 1.5em;
}

.preview-content li {
    margin: 0;
}

.preview-content pre {
    background: #f4f4f4;
    overflow-x: auto;
}

.preview-content code {
    font-family: 'Courier New', monospace;
}

.preview-content blockquote {
    border-left: 3px solid #ccc;
    padding-left: 12px;
    color: #555;
}

.preview-content table {
    border-collapse: collapse;
    width: 100%;
}

.preview-content th,
.preview-content td {
    border: 1px solid #ddd;
    padding: 4px 8px;
    text-align: left;
}

.preview-content th {
    background: #f4f4f4;
    font-weight: 700;
}

.preview-content hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 4px 0;
}

.preview-content img {
    max-width: 100%;
}

/* ============================================
   SCROLLBARS
============================================ */
.preview-wrapper::-webkit-scrollbar { width: 6px; }
.preview-wrapper::-webkit-scrollbar-track { background: var(--bg); }
.preview-wrapper::-webkit-scrollbar-thumb {
    background: var(--border2);
    border-radius: 3px;
}

/* ============================================
   PRINT STYLES
============================================ */
@media print {
    body > *:not(#printFrame) { display: none !important; }
}

/* ============================================
   RESPONSIVE
============================================ */
@media (max-width: 1100px) {
    .main-layout {
        grid-template-columns: 1fr var(--sidebar-w);
    }
    .preview-panel {
        display: none;
    }
}

@media (max-width: 720px) {
    .main-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 1fr auto;
    }
    .controls-panel {
        display: none;
    }
}

/* ============================================
   THEME TOGGLE BUTTON
============================================ */
.btn-theme {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: var(--surface2);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}
.btn-theme:hover {
    border-color: var(--primary);
    background: var(--primary-light);
    transform: rotate(20deg);
}
.theme-icon {
    transition: transform 0.4s ease;
}
.btn-theme:hover .theme-icon {
    transform: scale(1.15);
}

/* ============================================
   MARKDOWN TOOLBAR
============================================ */
.md-toolbar {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 4px 8px;
    background: var(--surface2);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    min-height: 34px;
}

.tb-btn {
    height: 26px;
    min-width: 28px;
    padding: 0 6px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text2);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}
.tb-btn:hover {
    background: var(--primary-light);
    color: var(--primary);
    border-color: var(--primary);
}
.tb-btn:active {
    transform: scale(0.93);
}

.tb-sep {
    width: 1px;
    height: 18px;
    background: var(--border2);
    margin: 0 4px;
    flex-shrink: 0;
}

/* ============================================
   FIND & REPLACE BAR
============================================ */
.find-replace-bar {
    background: var(--surface2);
    border-bottom: 2px solid var(--primary);
    padding: 6px 10px;
    animation: frSlideDown 0.2s ease;
}

@keyframes frSlideDown {
    from { opacity: 0; transform: translateY(-10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.fr-row {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}
.fr-row:last-child { margin-bottom: 0; }

.fr-input {
    flex: 1;
    height: 28px;
    border: 1px solid var(--border2);
    border-radius: var(--radius-sm);
    padding: 0 8px;
    font-size: 12px;
    background: var(--surface);
    color: var(--text);
    outline: none;
    transition: var(--transition);
}
.fr-input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}

.fr-btn {
    height: 28px;
    padding: 0 8px;
    border: 1px solid var(--border2);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text2);
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    transition: var(--transition);
    white-space: nowrap;
}
.fr-btn:hover {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.fr-replace-btn {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 700;
}

.fr-count {
    font-size: 11px;
    color: var(--text3);
    min-width: 32px;
    text-align: center;
    font-family: monospace;
}

.fr-case-label {
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 11px;
    color: var(--text3);
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    transition: var(--transition);
    user-select: none;
}
.fr-case-label:hover {
    background: var(--border);
}
.fr-case-label input {
    width: 12px; height: 12px;
    accent-color: var(--primary);
}

.fr-close {
    width: 24px;
    height: 24px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text3);
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}
.fr-close:hover {
    background: var(--danger);
    color: white;
}

/* ============================================
   WORD GOAL & READING TIME
============================================ */
.footer-sep {
    color: var(--border2);
    margin: 0 2px;
}

.word-goal-wrap {
    display: flex;
    align-items: center;
    gap: 4px;
}

.word-goal-label {
    display: flex;
    align-items: center;
    gap: 3px;
    cursor: pointer;
    font-size: 11px;
}

.word-goal-input {
    width: 54px;
    height: 18px;
    border: 1px solid var(--border2);
    border-radius: 3px;
    font-size: 10px;
    text-align: center;
    background: var(--surface);
    color: var(--text);
    outline: none;
    padding: 0 2px;
}
.word-goal-input:focus {
    border-color: var(--primary);
}
.word-goal-input::-webkit-inner-spin-button,
.word-goal-input::-webkit-outer-spin-button { -webkit-appearance: none; }
.word-goal-input { -moz-appearance: textfield; }

.word-goal-bar-wrap {
    width: 48px;
    height: 6px;
    background: var(--border);
    border-radius: 3px;
    overflow: hidden;
}
.word-goal-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 3px;
    width: 0%;
    transition: width 0.3s ease, background 0.3s ease;
}
.word-goal-bar.complete {
    background: var(--success);
}

.word-goal-pct {
    font-size: 10px;
    color: var(--text3);
    min-width: 28px;
    font-family: monospace;
}

/* ============================================
   TOOL BUTTONS (TOC, Clear Saved)
============================================ */
.tool-btn {
    flex: 1;
    text-align: center;
    padding: 6px 8px !important;
    font-size: 11px !important;
}
.tool-btn:hover {
    background: var(--primary-light) !important;
    color: var(--primary) !important;
    border-color: var(--primary) !important;
}

/* ============================================
   SYNC SCROLL BUTTON
============================================ */
.sync-scroll-btn {
    position: relative;
    overflow: hidden;
}
.sync-scroll-btn.active-toggle {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}
.sync-scroll-btn:not(.active-toggle) {
    background: var(--surface2);
    color: var(--text3);
    border-color: var(--border);
}
.sync-scroll-btn:not(.active-toggle):hover {
    color: var(--primary);
    border-color: var(--primary);
    background: var(--primary-light);
}
.sync-scroll-btn::after {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
    transform: translateX(-100%);
    transition: none;
}
.sync-scroll-btn.active-toggle:hover::after {
    transform: translateX(100%);
    transition: transform 0.5s ease;
}

/* ============================================
   THEME TRANSITION
============================================ */
html[data-theme] * {
    transition: background-color 0.3s ease, color 0.2s ease, border-color 0.3s ease;
}