/* ========================================
   QP Editor – styles.css
   Premium Dark UI + A4 Print Preview
   ======================================== */

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #f9fafb;
    --surface: #ffffff;
    --surface2: #f3f4f6;
    --border: #e5e7eb;
    --accent: #2563eb;
    --accent2: #60a5fa;
    --green: #10b981;
    --text: #1f2937;
    --text-muted: #6b7280;
    --danger: #ef4444;
    --editor-w: 480px;
    --radius: 10px;
    --font: 'Inter', sans-serif;
}

html,
body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
}

/* ── APP LAYOUT ── */
.app-wrapper {
    display: flex;
    height: calc(100vh - 38px);
    overflow: hidden;
}

/* ── EDITOR PANEL ── */
.editor-panel {
    width: var(--editor-w);
    min-width: var(--editor-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    transition: width 0.3s ease, min-width 0.3s ease;
    position: relative;
    z-index: 10;
}

.editor-panel.collapsed {
    width: 56px;
    min-width: 56px;
}

.editor-panel.collapsed .editor-scroll,
.editor-panel.collapsed .editor-header h1,
.editor-panel.collapsed .editor-header p {
    display: none;
}

.editor-header {
    padding: 20px 16px;
    background: #ffffff;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 12px;
}

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

.logo-icon {
    width: 28px;
    height: 28px;
    color: var(--accent);
    stroke-width: 1.5;
}

.logo h1 {
    font-family: 'Outfit', sans-serif;
    font-size: 1.2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    background-clip: text;
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.logo p {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ── LUCIDE ICONS ── */
[data-lucide] {
    width: 16px;
    height: 16px;
    display: inline-block;
    vertical-align: middle;
    stroke: currentColor;
    fill: none;
    stroke-width: 1.5;
    line-height: 1;
}

.btn-head-icon [data-lucide],
.draw-tool-btn [data-lucide],
.open-draw-btn [data-lucide],
.btn-icon [data-lucide],
.qn-move-btn [data-lucide],
.add-block-btn [data-lucide],
.btn-preview [data-lucide],
.btn-download [data-lucide],
.apply-all-font-btn [data-lucide],
.btn-theme-toggle [data-lucide],
.btn-download-top [data-lucide] {
    width: 14px;
    height: 14px;
    margin-right: 3px;
    stroke-width: 1.5;
}

.remove-q-btn [data-lucide],
.remove-block-btn [data-lucide],
.btn-close-modal [data-lucide] {
    width: 14px;
    height: 14px;
    stroke-width: 1.5;
}

.modal-header h2 [data-lucide] {
    width: 20px;
    height: 20px;
    margin-right: 6px;
    vertical-align: middle;
}

.block-tag [data-lucide] {
    width: 13px;
    height: 13px;
    margin-right: 3px;
    stroke-width: 1.5;
    vertical-align: middle;
}

/* ── TOGGLE BUTTON ── */
.toggle-btn {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 28px;
    height: 28px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.toggle-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

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

.btn-head-icon {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    height: 28px;
    padding: 0 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.72rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-head-icon:hover {
    background: var(--surface);
    color: var(--accent);
    border-color: var(--accent);
}

/* Scrollable editor body */
.editor-scroll {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.editor-scroll::-webkit-scrollbar {
    width: 5px;
}

.editor-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.editor-scroll::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* ── SECTION ── */
.editor-section {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
}

.section-title {
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    display: inline-block;
    flex-shrink: 0;
}

/* ── FIELDS ── */
.field-group {
    margin-bottom: 10px;
}

.field-group:last-child {
    margin-bottom: 0;
}

.field-group label {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
    margin-bottom: 4px;
    font-weight: 500;
}

.field-group input,
.field-group textarea,
.field-group select {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text);
    font-family: var(--font);
    font-size: 0.82rem;
    padding: 8px 10px;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
    resize: vertical;
}

.field-group input:focus,
.field-group textarea:focus,
.field-group select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(108, 99, 255, 0.15);
}

.field-group textarea {
    min-height: 64px;
}

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

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

/* ── PARTS ── */
.part-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    margin-top: 12px;
    position: relative;
}

.part-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 10px;
}

.part-card-title {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--accent2);
}

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

.btn-icon {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 6px;
    padding: 3px 8px;
    font-size: 0.7rem;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-icon:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.btn-icon.danger:hover {
    background: var(--danger);
    border-color: var(--danger);
}

/* Questions inside part */
.question-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-top: 8px;
}

.question-card {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px;
    position: relative;
    transition: all 0.3s ease;
}

.highlight-card {
    border-color: var(--accent) !important;
    box-shadow: 0 0 8px rgba(108, 99, 255, 0.6) !important;
    background: rgba(108, 99, 255, 0.05) !important;
}

.question-row {
    display: flex;
    gap: 8px;
    align-items: flex-start;
}

.qn-side {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.qn-number {
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    font-size: 0.7rem;
    border-radius: 5px;
    padding: 2px 7px;
}

.qn-move-btns {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.qn-move-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    width: 20px;
    height: 18px;
    font-size: 0.6rem;
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.qn-move-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.question-fields {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

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

.inline-row .field-group {
    flex: 1;
    margin-bottom: 0;
}

.remove-q-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.85rem;
    padding: 4px;
    transition: color 0.2s;
    flex-shrink: 0;
}

.remove-q-btn:hover {
    color: var(--danger);
}

.add-q-btn {
    width: 100%;
    margin-top: 8px;
    background: transparent;
    border: 1px dashed var(--border);
    border-radius: 7px;
    color: var(--text-muted);
    font-size: 0.78rem;
    padding: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.add-q-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(108, 99, 255, 0.06);
}

.apply-all-font-btn {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    font-size: 0.7rem;
    font-weight: 500;
    border-radius: 6px;
    padding: 0 8px;
    height: 32px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.apply-all-font-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: rgba(37, 99, 235, 0.05);
}

/* ── ADD PART BTN ── */
.add-part-btn {
    width: 100%;
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.08), rgba(96, 165, 250, 0.05));
    border: 1px dashed var(--accent);
    border-radius: var(--radius);
    color: var(--accent);
    font-size: 0.85rem;
    font-weight: 500;
    padding: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.add-part-btn:hover {
    background: linear-gradient(135deg, rgba(37, 99, 235, 0.12), rgba(96, 165, 250, 0.08));
}

/* ── ACTION BUTTONS ── */
.action-buttons {
    display: flex;
    gap: 10px;
}

.btn-preview,
.btn-download {
    flex: 1;
    padding: 11px;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.25s;
}

.btn-preview {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
}

.btn-preview:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.btn-download {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #fff;
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.25);
}

.btn-download:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 24px rgba(37, 99, 235, 0.35);
}

.btn-download:active {
    transform: translateY(0);
}

/* ── PREVIEW PANEL ── */
.preview-panel {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #e5e7eb;
    overflow: hidden;
}

.preview-toolbar {
    padding: 12px 24px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.preview-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.zoom-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--surface2);
    border: 1px solid var(--border);
    padding: 4px 8px;
    border-radius: 8px;
}

.btn-zoom {
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 1.2rem;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 4px;
    transition: all 0.2s;
}

.btn-zoom:hover {
    background: var(--accent);
    color: #fff;
}

.zoom-level {
    font-size: 0.8rem;
    font-weight: 600;
    min-width: 48px;
    text-align: center;
}

.btn-download-top {
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 600;
    padding: 8px 18px;
    cursor: pointer;
    box-shadow: 0 3px 12px rgba(37, 99, 235, 0.2);
    transition: all 0.2s;
}

.btn-download-top:hover {
    transform: translateY(-1px);
    box-shadow: 0 5px 20px rgba(37, 99, 235, 0.3);
}

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

.preview-viewport::-webkit-scrollbar {
    width: 6px;
}

.preview-viewport::-webkit-scrollbar-track {
    background: transparent;
}

.preview-viewport::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

/* ====================================================
   A4 PAPER PREVIEW – mimics actual printed paper
   ==================================================== */
.a4-page {
    width: 794px;
    /* 210mm at 96dpi */
    min-height: 1123px;
    /* 297mm at 96dpi */
    background: #fff;
    color: #000;
    font-family: 'Times New Roman', Times, serif;
    font-size: 12pt;
    padding: 28mm 20mm 20mm 20mm;
    box-shadow: 0 8px 48px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.3);
    border-radius: 2px;
    position: relative;
    transform-origin: top center;
    transition: transform 0.2s ease-out;
}

/* A3 Landscape Dual Copy Layout */
.a4-page.layout-a3-dual {
    width: 1588px; /* A3 Landscape width at 96dpi (twice A4 width 794px) */
    min-height: 1123px; /* A3 Landscape height */
    padding: 0;
}

.a4-page.layout-a3-dual .qp-columns-wrapper {
    display: flex;
    gap: 0;
    height: 100%;
    position: relative;
}

.a4-page.layout-a3-dual .qp-column-copy {
    width: 50%;
    padding: 28mm 20mm 20mm 20mm;
    box-sizing: border-box;
}

/* Center guideline for cutting A3 in half */
.a4-page.layout-a3-dual .qp-columns-wrapper::after {
    content: '';
    position: absolute;
    top: 0;
    bottom: 0;
    left: 50%;
    border-left: 1px dashed #bbb;
    transform: translateX(-50%);
}

/* Header area */
.qp-meta-line {
    font-size: 11pt;
    margin-bottom: 2px;
}

.qp-roll-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 1px;
}

.qp-roll-row span {
    white-space: nowrap;
}

.qp-class-row {
    margin-bottom: 16px;
}

.qp-title-block {
    text-align: center;
    margin-bottom: 8px;
}

.qp-title-block .t1 {
    font-weight: bold;
    font-size: 13pt;
    letter-spacing: 0.04em;
}

.qp-title-block .t2 {
    font-weight: bold;
    font-size: 13pt;
    letter-spacing: 0.04em;
}

.qp-title-block .t3 {
    font-weight: bold;
    font-size: 12pt;
    letter-spacing: 0.02em;
}

.qp-title-block .dept {
    font-size: 12pt;
}

.qp-title-block .subj {
    font-weight: bold;
    font-size: 12pt;
}

.qp-timemark {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    font-size: 11pt;
}

/* Part heading */
.qp-part-heading {
    text-align: center;
    margin: 18px 0 4px;
}

.qp-part-heading .ph-title {
    font-weight: bold;
    font-size: 12pt;
}

.qp-part-heading .ph-instr {
    font-size: 11pt;
}

.qp-part-heading .ph-instr em {
    font-style: italic;
}

/* Table */
.qp-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 6px;
    font-size: 11pt;
}

.qp-table th {
    border: 1.2px solid #000;
    padding: 4px 6px;
    font-weight: bold;
    text-align: left;
    background: #fff;
}

.qp-table td {
    border: 1.2px solid #000;
    padding: 4px 6px;
    vertical-align: top;
}

.qp-table .col-qn {
    width: 34px;
    text-align: center;
}

.qp-table .col-q {
    width: auto;
}

.qp-table .col-co {
    width: 44px;
    text-align: center;
}

.qp-table .col-btl {
    width: 38px;
    text-align: center;
}

/* Footer */
.qp-footer {
    text-align: center;
    margin-top: 32px;
    font-size: 12pt;
    font-weight: bold;
    letter-spacing: 0.06em;
}

/* ──────────────────────────────
   PRINT STYLES – for PDF export
   ────────────────────────────── */
@media print {
    * {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    body {
        background: #fff !important;
    }

    .app-wrapper {
        display: block;
    }

    .editor-panel {
        display: none !important;
    }

    .preview-toolbar {
        display: none !important;
    }

    .preview-panel {
        background: #fff !important;
    }

    .preview-viewport {
        padding: 0 !important;
    }

    .a4-page {
        width: 210mm !important;
        min-height: 297mm !important;
        padding: 20mm !important;
        box-shadow: none !important;
        margin: 0 auto;
        page-break-after: always;
    }

    .a4-page.layout-a3-dual {
        width: 420mm !important;
        min-height: 297mm !important;
        padding: 0 !important;
        page-break-after: always;
    }
}

/* ── RESPONSIVE: Tablet & below ── */
@media (max-width: 900px) {
    .app-wrapper {
        flex-direction: column;
    }

    .editor-panel {
        width: 100% !important;
        min-width: 100% !important;
        max-height: 50vh;
    }

    .editor-panel.collapsed {
        max-height: 44px;
    }

    .preview-panel {
        flex: 1;
    }

    .preview-toolbar {
        flex-wrap: wrap;
        gap: 6px;
        padding: 8px 12px;
    }

    .preview-toolbar > div {
        flex: 1 1 auto;
        min-width: 0;
    }

    .a4-page {
        width: 100%;
        transform-origin: top left;
    }
}

/* ── RESPONSIVE: Phone ── */
@media (max-width: 600px) {
    /* Bigger touch targets */
    .btn-head-icon,
    .btn-icon,
    .remove-q-btn,
    .add-block-btn,
    .btn-zoom,
    .btn-theme-toggle,
    .btn-download-top,
    .toggle-btn,
    .draw-tool-btn,
    .btn-close-modal,
    .apply-all-font-btn {
        min-height: 40px;
        min-width: 40px;
    }

    .qn-move-btn {
        min-height: 28px;
        min-width: 28px;
    }

    /* Stack field rows vertically */
    .field-row,
    .inline-row {
        flex-direction: column;
        gap: 6px;
    }

    .field-row .field-group,
    .inline-row .field-group {
        flex: none;
        width: 100%;
    }

    /* Tighter spacing */
    .editor-scroll {
        padding: 8px;
        gap: 8px;
    }

    .editor-section {
        padding: 8px;
    }

    .part-card {
        padding: 6px;
        margin-top: 8px;
    }

    .question-card {
        padding: 6px;
    }

    .block-card {
        padding: 6px;
    }

    .editor-header {
        padding: 10px 8px;
        gap: 6px;
    }

    .header-actions {
        gap: 3px;
    }

    .logo h1 {
        font-size: 1rem;
    }

    .logo p {
        font-size: 0.6rem;
    }

    /* Font size row: stack */
    .question-fields .field-group > div[style*="display: flex"] {
        flex-wrap: wrap;
    }

    .font-size-select {
        min-width: 0;
        font-size: 0.75rem !important;
        padding: 6px 8px !important;
    }

    .font-size-manual {
        width: 60px !important;
        padding: 6px 4px !important;
        font-size: 0.75rem !important;
    }

    /* Block insert buttons: smaller */
    .add-block-row {
        gap: 3px;
    }

    .add-block-btn {
        padding: 5px 6px;
        font-size: 0.62rem;
    }

    .add-block-label {
        font-size: 0.6rem;
    }

    /* Inline check label */
    .inline-check {
        font-size: 0.65rem;
    }

    /* Modal fills screen better */
    .modal-content {
        width: 96vw;
        max-width: 96vw;
        padding: 10px;
    }

    .modal-header h2 {
        font-size: 0.95rem;
    }

    .draw-toolbar {
        flex-wrap: wrap;
        gap: 4px;
        padding: 6px;
    }

    .draw-toolbar input[type="color"] {
        width: 36px;
        height: 36px;
        padding: 2px;
    }

    .draw-toolbar input[type="range"] {
        width: 80px;
    }

    .canvas-container canvas {
        width: 100% !important;
        height: auto !important;
        max-height: 50vh;
    }

    .modal-footer {
        flex-direction: column;
        gap: 6px;
    }

    .modal-footer button {
        width: 100%;
    }

    /* Footer */
    .app-footer {
        position: static;
        padding: 8px;
        font-size: 0.65rem;
    }

    /* Toast */
    .toast {
        bottom: 12px;
        right: 12px;
        left: 12px;
        text-align: center;
        font-size: 0.75rem;
        padding: 10px 16px;
    }

    /* Part card title + actions in one row */
    .part-card-header {
        flex-wrap: wrap;
        gap: 4px;
    }

    .part-card-title {
        font-size: 0.72rem;
    }

    /* Question number side */
    .qn-number {
        font-size: 0.6rem;
        padding: 1px 5px;
    }

    /* Action buttons at bottom */
    .action-buttons {
        flex-direction: column;
        gap: 6px;
    }

    .btn-preview,
    .btn-download {
        padding: 9px;
        font-size: 0.78rem;
    }

    /* Part action buttons */
    .part-actions {
        gap: 3px;
    }

    /* Add part button */
    .add-part-btn {
        font-size: 0.78rem;
        padding: 8px;
    }

    /* Blocks list spacing */
    .blocks-list {
        gap: 2px;
    }
}

/* ── RESPONSIVE: Small Phone ── */
@media (max-width: 400px) {
    .editor-header {
        padding: 6px 4px;
    }

    .header-actions {
        gap: 2px;
    }

    .btn-head-icon {
        min-height: 32px;
        min-width: 32px;
        padding: 0 4px;
        font-size: 0.6rem;
    }

    .logo-icon {
        width: 22px;
        height: 22px;
    }

    .logo h1 {
        font-size: 0.85rem;
    }

    .editor-scroll {
        padding: 4px;
        gap: 4px;
    }

    .editor-section {
        padding: 6px;
    }

    .add-block-btn {
        font-size: 0.55rem;
        padding: 4px 4px;
    }

    .part-card {
        padding: 4px;
    }

    .question-card {
        padding: 4px;
    }

    .block-card {
        padding: 4px;
    }

    .modal-content {
        padding: 6px;
    }
}

/* ── TOAST notification ── */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: linear-gradient(135deg, #22d3a5, #0ea5e9);
    color: #fff;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 12px 20px;
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(34, 211, 165, 0.4);
    z-index: 9999;
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s ease;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* ============================================================
   BLOCK EDITOR – Equation, Figure, Code
   ============================================================ */

/* Row of Insert buttons */
.add-block-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 2px;
}

.add-block-label {
    font-size: 0.68rem;
    color: var(--text-muted);
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    flex-shrink: 0;
}

.add-block-btn {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.72rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid;
    transition: all 0.18s;
    white-space: nowrap;
}

.eq-btn {
    border-color: #8b5cf6;
    color: #7c3aed;
    background: rgba(139, 92, 246, 0.08);
}

.fig-btn {
    border-color: #06b6d4;
    color: #0891b2;
    background: rgba(6, 182, 212, 0.08);
}

.code-btn {
    border-color: #10b981;
    color: #059669;
    background: rgba(16, 185, 129, 0.08);
}

.eq-btn:hover {
    background: #7c3aed;
    color: #fff;
}

.fig-btn:hover {
    background: #0891b2;
    color: #fff;
}

.code-btn:hover {
    background: #059669;
    color: #fff;
}

/* Block cards */
.block-card {
    border-radius: 8px;
    padding: 10px;
    margin-top: 6px;
    border: 1px solid;
}

.block-equation {
    border-color: rgba(124, 58, 237, 0.4);
    background: rgba(124, 58, 237, 0.06);
}

.block-figure {
    border-color: rgba(8, 145, 178, 0.4);
    background: rgba(8, 145, 178, 0.06);
}

.block-code {
    border-color: rgba(5, 150, 105, 0.4);
    background: rgba(5, 150, 105, 0.06);
}

.block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.block-tag {
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 4px;
}

.eq-tag {
    background: rgba(139, 92, 246, 0.15);
    color: #6d28d9;
}

.fig-tag {
    background: rgba(6, 182, 212, 0.15);
    color: #0369a1;
}

.code-tag {
    background: rgba(16, 185, 129, 0.15);
    color: #047857;
}

.block-opts {
    display: flex;
    align-items: center;
    gap: 8px;
}

.inline-check {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 0.72rem;
    color: var(--text-muted);
    cursor: pointer;
}

.inline-check input {
    width: auto;
    accent-color: var(--accent);
}

.remove-block-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.78rem;
    padding: 2px 4px;
    transition: color 0.2s;
    line-height: 1;
}

.remove-block-btn:hover {
    color: var(--danger);
}

/* Figure thumbnail */
.fig-thumb {
    max-width: 100%;
    max-height: 120px;
    border-radius: 6px;
    display: block;
    margin: 6px 0;
    border: 1px solid var(--border);
    object-fit: contain;
}

/* File input styling */
input[type="file"] {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 7px;
    color: var(--text-muted);
    font-size: 0.78rem;
    padding: 5px 8px;
    cursor: pointer;
}

input[type="file"]::file-selector-button {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 5px;
    padding: 3px 10px;
    cursor: pointer;
    font-size: 0.75rem;
    margin-right: 8px;
    transition: all 0.2s;
}

input[type="file"]::file-selector-button:hover {
    background: var(--accent);
    border-color: var(--accent);
}

/* Blocks list container */
.blocks-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

/* ============================================================
   A4 PREVIEW – Equation / Figure / Code block styles
   ============================================================ */
.a4-page .qp-eq {
    font-size: 11pt;
    margin: 4px 0;
    font-family: 'Times New Roman', Times, serif;
}

.a4-page .qp-eq-display {
    display: block;
    text-align: center;
    margin: 8px auto;
}

.a4-page .qp-eq-inline {
    display: inline;
}

.a4-page .qp-figure {
    margin: 8px 0;
}

.a4-page .qp-fig-caption {
    font-size: 9.5pt;
    color: #444;
    font-style: italic;
    margin-top: 3px;
}

.a4-page .qp-code {
    font-family: 'Courier New', Courier, monospace;
    font-size: 9.5pt;
    background: #f7f7f7;
    border: 1px solid #ccc;
    border-radius: 4px;
    padding: 6px 10px;
    margin: 6px 0;
    white-space: pre-wrap;
    word-break: break-all;
    color: #1a1a1a;
}

.app-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    padding: 10px;
    background: #ffffff;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    z-index: 1000;
}

.app-footer a {
    color: #6c63ff;
    text-decoration: none;
    font-weight: bold;
}

/* ============================================================
   DRAWING MODAL
   ============================================================ */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal.show {
    display: flex;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    width: 640px;
    max-width: 90vw;
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 1.1rem;
    color: var(--text);
}

.btn-close-modal {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    transition: color 0.2s;
}

.btn-close-modal:hover {
    color: var(--danger);
}

.draw-toolbar {
    display: flex;
    gap: 10px;
    background: var(--surface2);
    padding: 10px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    align-items: center;
}

.draw-tool-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 0.85rem;
}

.draw-tool-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.draw-tool-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.draw-tool-btn.danger:hover {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}

.canvas-container {
    background: #fff;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--border);
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: crosshair;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

.btn-theme-toggle {
    background: var(--surface2);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 600;
    padding: 8px 14px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}
.btn-theme-toggle:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

body.dark-mode {
    --bg: #0d0f14;
    --surface: #161a23;
    --surface2: #1e2433;
    --border: #2a3147;
    --text: #e2e8f0;
    --text-muted: #8892a8;
}

body.dark-mode .editor-header { background: #161a23; }
body.dark-mode .app-footer { background: #0d0f14; }
body.dark-mode .preview-panel { background: #1a1d27; }
body.dark-mode .add-part-btn {
    background: linear-gradient(135deg, rgba(108, 99, 255, 0.12), rgba(167, 139, 250, 0.08));
    border-color: #6c63ff;
    color: #a78bfa;
}
body.dark-mode .add-part-btn:hover {
    background: linear-gradient(135deg, rgba(108, 99, 255, 0.25), rgba(167, 139, 250, 0.15));
}
body.dark-mode .eq-btn { border-color: #7c3aed; color: #a78bfa; background: rgba(124, 58, 237, 0.08); }
body.dark-mode .fig-btn { border-color: #0891b2; color: #67e8f9; background: rgba(8, 145, 178, 0.08); }
body.dark-mode .code-btn { border-color: #059669; color: #6ee7b7; background: rgba(5, 150, 105, 0.08); }
body.dark-mode .eq-tag { background: rgba(124, 58, 237, 0.25); color: #c4b5fd; }
body.dark-mode .fig-tag { background: rgba(8, 145, 178, 0.25); color: #67e8f9; }
body.dark-mode .code-tag { background: rgba(5, 150, 105, 0.25); color: #6ee7b7; }