/* ============ Editor toolbar ============ */
.editor-toolbar {
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
}
.editor-toolbar-row {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 14px;
    border-bottom: 1px solid var(--border);
}
.editor-toolbar-row:last-child { border-bottom: none; }
.editor-toolbar-row.secondary {
    flex-wrap: wrap; padding: 6px 14px;
}

.title-input {
    flex: 1; min-width: 200px;
    padding: 8px 12px; font-size: 15px; font-weight: 600;
    border: 1px solid transparent; background: transparent;
    border-radius: var(--radius-sm);
    color: var(--text);
}
.title-input:focus {
    border-color: var(--border); background: var(--bg);
    outline: none; box-shadow: var(--ring);
}

.mode-switch {
    display: flex; background: var(--bg-subtle);
    padding: 3px; border-radius: var(--radius-sm);
    gap: 2px;
}
.mode-btn {
    padding: 6px 12px; border: 0; background: transparent;
    color: var(--text-muted); font-size: 12px; font-weight: 500;
    border-radius: var(--radius-sm); white-space: nowrap;
}
.mode-btn:hover { color: var(--text); }
.mode-btn.active {
    background: var(--bg-panel); color: var(--text);
    box-shadow: var(--shadow-sm); font-weight: 600;
}

.tool-group {
    display: flex; align-items: center; gap: 2px;
    padding: 0 4px; border-right: 1px solid var(--border);
}
.tool-group:last-child, .tool-group.right { border-right: none; }
.tool-group.right { margin-left: auto; }

.tb-btn {
    padding: 6px 10px; border: 0; background: transparent;
    color: var(--text); font-size: 14px;
    border-radius: var(--radius-sm); line-height: 1;
}
.tb-btn:hover { background: var(--bg-hover); }

.tb-select {
    padding: 5px 8px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text);
    border-radius: var(--radius-sm); font-size: 12px;
}
.tb-toggle {
    display: flex; align-items: center; gap: 4px;
    padding: 4px 8px; font-size: 12px; color: var(--text-muted);
    cursor: pointer; user-select: none;
}

/* ============ Rich Ribbon (Word-style) ============ */
.rich-ribbon {
    display: flex; flex-wrap: wrap; gap: 4px;
    padding: 8px 12px;
    background: linear-gradient(to bottom, var(--bg-panel), var(--bg-subtle));
    border-bottom: 1px solid var(--border);
}
.rich-ribbon[hidden] { display: none !important; }
.ribbon-group {
    display: flex; align-items: center; gap: 2px;
    padding: 0 8px; border-right: 1px solid var(--border);
}
.ribbon-group:last-child { border-right: none; }
.ribbon-group.right { margin-left: auto; }

.rb-btn {
    min-width: 32px; height: 30px; padding: 0 8px;
    border: 1px solid transparent; background: transparent;
    color: var(--text); font-size: 13px;
    border-radius: var(--radius-sm); line-height: 1;
}
.rb-btn:hover { background: var(--bg-hover); border-color: var(--border); }
.rb-btn.is-active { background: var(--brand-primary); color: #fff; }

.ribbon-select {
    padding: 6px 8px; border: 1px solid var(--border);
    background: var(--bg); color: var(--text);
    border-radius: var(--radius-sm); font-size: 12px;
    min-width: 100px;
}

.rb-color {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 4px 6px; border: 1px solid transparent;
    border-radius: var(--radius-sm); font-size: 12px;
    color: var(--text); cursor: pointer;
}
.rb-color:hover { background: var(--bg-hover); border-color: var(--border); }
.rb-color input[type="color"] {
    width: 24px; height: 22px; border: 1px solid var(--border);
    border-radius: 3px; cursor: pointer; background: transparent;
    padding: 0;
}

/* ============ Editor surfaces ============ */
.editor-surfaces {
    flex: 1; overflow: hidden;
    position: relative;
    background: var(--bg);
}
.surface {
    position: absolute; inset: 0;
    overflow: auto;
}
.surface[hidden] { display: none !important; }

/* Plain */
.surface-plain { display: flex; justify-content: center; }
#plain-editor {
    width: 100%; max-width: var(--dynamic-page-width);
    padding: 36px 48px; margin: 24px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: var(--font-sans); font-size: 16px; line-height: 1.75;
    color: var(--text);
    resize: none; outline: none; box-shadow: var(--shadow-sm);
    min-height: calc(100vh - 220px);
    transition: box-shadow .15s, border-color .15s;
}
#plain-editor::placeholder { color: var(--text-subtle); font-style: italic; }
#plain-editor:focus { border-color: var(--brand-primary); box-shadow: var(--shadow), var(--ring); }

/* Code (Monaco) */
.surface-code { padding: 0; }
.code-mount { position: absolute; inset: 0; }

/* Rich */
.surface-rich { display: flex; justify-content: center; }
.rich-canvas {
    width: 100%; max-width: var(--dynamic-page-width);
    min-height: calc(100vh - 280px);
    padding: 40px 60px; margin: 20px;
    background: #ffffff; color: #1a1a1a;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-family: Georgia, serif; font-size: 16px; line-height: 1.7;
    outline: none; box-shadow: var(--shadow);
}
html[data-theme="dark"] .rich-canvas { background: #1e1e1e; color: #e2e8f0; }
.rich-canvas:focus { box-shadow: var(--shadow-lg); }
.rich-canvas h1 { font-size: 2em; margin: .67em 0; }
.rich-canvas h2 { font-size: 1.5em; }
.rich-canvas h3 { font-size: 1.25em; }
.rich-canvas blockquote {
    border-left: 4px solid var(--brand-primary);
    padding-left: 14px; color: var(--text-muted);
    margin: 1em 0;
}
.rich-canvas pre {
    background: var(--bg-subtle); padding: 12px;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono); overflow-x: auto;
}
.rich-canvas table { border-collapse: collapse; margin: 1em 0; }
.rich-canvas td, .rich-canvas th {
    border: 1px solid var(--border-strong); padding: 6px 10px;
}
.rich-canvas img { max-width: 100%; height: auto; }
.rich-canvas a { color: var(--brand-primary); }

.surface-rich.is-fullscreen {
    position: fixed !important; inset: 0 !important;
    z-index: 500;
    background: var(--bg); padding-top: 50px;
    display: flex !important; justify-content: center; align-items: flex-start;
    overflow: auto;
}
body.rich-fullscreen-active { overflow: hidden; }

/* Markdown */
.surface-markdown { padding: 0; }
.md-split { display: grid; grid-template-columns: 1fr 1fr; height: 100%; }
.md-source, .md-preview { overflow: auto; position: relative; }
.md-source { border-right: 1px solid var(--border); }
.md-preview-body {
    padding: 30px 40px;
    font-family: var(--font-sans); font-size: 15px; line-height: 1.7;
}
.md-preview-body h1, .md-preview-body h2 {
    border-bottom: 1px solid var(--border); padding-bottom: 6px;
}
.md-preview-body code {
    background: var(--bg-subtle); padding: 2px 6px;
    border-radius: 4px; font-family: var(--font-mono); font-size: 90%;
}
.md-preview-body pre {
    background: var(--bg-subtle); padding: 14px;
    border-radius: var(--radius-sm); overflow-x: auto;
}
.md-preview-body pre code { background: transparent; padding: 0; }
.md-preview-body table { border-collapse: collapse; margin: 1em 0; }
.md-preview-body td, .md-preview-body th {
    border: 1px solid var(--border); padding: 6px 10px;
}
.md-preview-body blockquote {
    border-left: 4px solid var(--brand-primary);
    padding-left: 14px; margin-left: 0; color: var(--text-muted);
}
.md-preview-body img { max-width: 100%; height: auto; }

/* Compare */
.surface-compare { display: flex; flex-direction: column; padding: 0; }
.compare-head {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px; border-bottom: 1px solid var(--border);
    background: var(--bg-panel);
}
.compare-info { margin-left: auto; color: var(--text-muted); font-size: 12px; }
.compare-mount { position: relative; flex: 1; }

@media (max-width: 900px) {
    .md-split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
    .md-source { border-right: none; border-bottom: 1px solid var(--border); }
}

/* ============================================================
   Plain editor — paper / notebook styles
   Liniile se scalează automat cu font-size × line-height
   folosind unitatea CSS `lh` (= 1 rând de text).

   Stiluri disponibile:
     blank  — fără linii (default)
     lined  — caiet dictando: linii orizontale + linie roșie de margine
     lined2 — dictando fără margine roșie (Dictando II)
     math   — caiet matematică: grilă cu pătrate mici
   ============================================================ */

/* Culorile liniilor — se adaptează la tema light/dark */
:root {
    --paper-line-color:   rgba(59, 130, 246, 0.22);
    --paper-grid-h-color: rgba(59, 130, 246, 0.22);
    --paper-grid-v-color: rgba(59, 130, 246, 0.13);
    --paper-margin-color: rgba(220, 53,  69,  0.35);
    --paper-pt: 36px;   /* padding-top al #plain-editor */
    --paper-pl: 48px;   /* padding-left al #plain-editor */
}
html[data-theme="dark"] {
    --paper-line-color:   rgba(99, 160, 255, 0.20);
    --paper-grid-h-color: rgba(99, 160, 255, 0.20);
    --paper-grid-v-color: rgba(99, 160, 255, 0.11);
    --paper-margin-color: rgba(255, 100, 110, 0.28);
}

/* ── Dictando (linii orizontale + linie roșie de margine la 24px) ── */
#plain-editor[data-paper="lined"] {
    background-image:
        /* linia roșie de margine — la 24px, adică în interiorul padding-ului */
        linear-gradient(to right,
            transparent 24px,
            var(--paper-margin-color) 24px,
            var(--paper-margin-color) 25px,
            transparent 25px
        ),
        /* linii orizontale la fiecare rând (1lh) */
        repeating-linear-gradient(
            to bottom,
            transparent 0,
            transparent calc(1lh - 1px),
            var(--paper-line-color) calc(1lh - 1px),
            var(--paper-line-color) 1lh
        );
    background-attachment: local;
    background-position:
        0 0,
        0 var(--paper-pt);
    background-size:
        100% 100%,
        100% 1lh;
}

/* ── Dictando II (linii orizontale, fără margine roșie) ── */
#plain-editor[data-paper="lined2"] {
    background-image:
        repeating-linear-gradient(
            to bottom,
            transparent 0,
            transparent calc(1lh - 1px),
            var(--paper-line-color) calc(1lh - 1px),
            var(--paper-line-color) 1lh
        );
    background-attachment: local;
    background-position: 0 var(--paper-pt);
    background-size: 100% 1lh;
}

/* ── Matematică (grilă cu pătrate mici)
      Regula: o literă mică stă într-un pătrat, o literă mare în 2 pătrate suprapuse.
      Înălțimea pătratelor = lh/2  (jumătate de rând)
      Lățimea pătratelor   = lh/2  (forțăm pătrat perfect cu o valoare fixă legată de font)
      La font-size 16px, line-height 1.75 → lh ≈ 28px → celula = 14px
      Lățimea verticală = lh/2, lățimea orizontală = tot lh/2 (pătrat).
   ── */
#plain-editor[data-paper="math"] {
    background-image:
        /* linii orizontale — la fiecare jumătate de rând (lh/2) */
        repeating-linear-gradient(
            to bottom,
            transparent 0,
            transparent calc(0.5lh - 1px),
            var(--paper-grid-h-color) calc(0.5lh - 1px),
            var(--paper-grid-h-color) calc(0.5lh)
        ),
        /* linii verticale — același pas ca orizontalele (pătrat) */
        repeating-linear-gradient(
            to right,
            transparent 0,
            transparent calc(0.5lh - 1px),
            var(--paper-grid-v-color) calc(0.5lh - 1px),
            var(--paper-grid-v-color) calc(0.5lh)
        );
    background-attachment: local;
    background-position:
        0 var(--paper-pt),
        var(--paper-pl) 0;
    background-size:
        100%  0.5lh,
        0.5lh 100%;
}

/* ── Blank — fără nicio modificare ── */
#plain-editor[data-paper="blank"],
#plain-editor:not([data-paper]) {
    background-image: none;
}

/* ============================================================
   Plain Editor — Classic Menubar  (plain-menu.js)
   ============================================================ */

/* ── Menubar container ── */
.pm-menubar {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 2px 8px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    user-select: none;
    flex-shrink: 0;
    /* Scroll orizontal pe mobil când butoanele nu încap */
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.pm-menubar::-webkit-scrollbar { display: none; }
.pm-menubar[hidden] { display: none !important; }

/* Pe mobil: butoanele de meniu nu se micșorează */
.pm-menu { position: relative; flex-shrink: 0; }
.pm-menu-btn {
    padding: 4px 10px;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 13px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
}
.pm-menu-btn:hover,
.pm-menu-btn:focus { background: var(--bg-hover); outline: none; }
.pm-menu:focus-within .pm-menu-btn { background: var(--brand-primary); color: #fff; }

/* ── Dropdown list ── */
.pm-dropdown {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 9000;
    min-width: 220px;
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    list-style: none;
    margin: 0; padding: 4px 0;
}
.pm-dropdown[hidden] { display: none !important; }

.pm-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 12px 5px 8px;
    cursor: pointer;
    color: var(--text);
    font-size: 13px;
    white-space: nowrap;
}
.pm-item:hover { background: var(--bg-hover); }
.pm-item-check  { width: 16px; text-align: center; font-size: 11px; color: var(--brand-primary); flex-shrink: 0; }
.pm-item-label  { flex: 1; }
.pm-item-kbd    { font-size: 11px; color: var(--text-muted); margin-left: auto; }
.pm-sep         { height: 1px; background: var(--border); margin: 3px 0; }
.pm-checked .pm-item-check { font-weight: bold; }

/* ── Modal overlay ── */
#pm-overlay {
    position: fixed; inset: 0; z-index: 10000;
    background: rgba(0,0,0,0.45);
    display: flex; align-items: center; justify-content: center;
}
#pm-overlay[hidden] { display: none !important; }

.pm-modal {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    min-width: 320px;
    max-width: 90vw;
    max-height: 90vh;
    display: flex; flex-direction: column;
    overflow: hidden;
}

.pm-modal-head {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-weight: 600; font-size: 14px;
    background: var(--bg-subtle);
    flex-shrink: 0;
}
.pm-modal-close {
    background: transparent; border: none;
    font-size: 18px; line-height: 1;
    color: var(--text-muted); cursor: pointer;
    padding: 0 4px; border-radius: var(--radius-sm);
}
.pm-modal-close:hover { background: var(--bg-hover); color: var(--text); }

.pm-modal-body {
    padding: 14px 16px;
    overflow-y: auto;
    flex: 1;
    display: flex; flex-direction: column; gap: 10px;
}

/* ── Find & Replace ── */
.pm-find-body label {
    display: flex; flex-direction: column; gap: 4px;
    font-size: 12px; color: var(--text-muted);
}
.pm-find-body label input[type="text"] {
    padding: 6px 10px; font-size: 13px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg); color: var(--text);
}
.pm-find-body label input[type="text"]:focus { outline: none; border-color: var(--brand-primary); box-shadow: var(--ring); }
.pm-inline { flex-direction: row !important; align-items: center; gap: 6px !important; font-size: 13px !important; color: var(--text) !important; }
.pm-find-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.pm-find-actions button {
    padding: 6px 14px; font-size: 13px;
    background: var(--bg-subtle); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text); cursor: pointer;
}
.pm-find-actions button:hover { background: var(--bg-hover); }
.pm-find-actions button:first-child { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }
.pm-find-actions button:first-child:hover { opacity: .88; }
.pm-find-status { font-size: 12px; color: var(--text-muted); min-height: 16px; }

/* ── Character Map ── */
.pm-charmap-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pm-charmap-bar select { flex: 1; min-width: 140px; padding: 5px 8px; border: 1px solid var(--border); background: var(--bg); color: var(--text); border-radius: var(--radius-sm); }
.pm-charmap-bar input[type="text"] { padding: 4px; border: 1px solid var(--border); background: var(--bg); color: var(--text); border-radius: var(--radius-sm); }
.pm-charmap-bar button { padding: 5px 12px; font-size: 13px; background: var(--brand-primary); color: #fff; border: none; border-radius: var(--radius-sm); cursor: pointer; }
.pm-char-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(32px, 1fr));
    gap: 2px;
    max-height: 320px;
    overflow-y: auto;
    margin-top: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px;
    background: var(--bg);
}
.pm-char-cell {
    width: 30px; height: 30px;
    display: flex; align-items: center; justify-content: center;
    font-size: 15px;
    background: transparent; border: 1px solid transparent;
    border-radius: 3px; cursor: pointer; color: var(--text);
}
.pm-char-cell:hover { background: var(--bg-hover); border-color: var(--border); }

/* ── Emoji Picker ── */
.pm-emoji-body { gap: 6px; }
.pm-emoji-tabs { display: flex; gap: 2px; flex-wrap: wrap; }
.pm-emoji-tab {
    padding: 4px 8px; font-size: 16px;
    background: transparent; border: 1px solid transparent;
    border-radius: var(--radius-sm); cursor: pointer;
}
.pm-emoji-tab:hover { background: var(--bg-hover); }
.pm-emoji-tab.active { background: var(--bg-subtle); border-color: var(--border); }
.pm-emoji-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(36px, 1fr));
    gap: 2px;
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 4px;
    background: var(--bg);
}
.pm-emoji-cell {
    width: 34px; height: 34px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    background: transparent; border: 1px solid transparent;
    border-radius: 4px; cursor: pointer;
}
.pm-emoji-cell:hover { background: var(--bg-hover); border-color: var(--border); }

/* ── Font Settings ── */
.pm-font-body label {
    display: flex; flex-direction: column; gap: 3px;
    font-size: 12px; color: var(--text-muted);
}
.pm-font-body select,
.pm-font-body input[type="number"] {
    padding: 5px 8px; font-size: 13px;
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--bg); color: var(--text);
}
.pm-font-preview {
    border: 1px solid var(--border); border-radius: var(--radius-sm);
    padding: 10px 14px; background: var(--bg);
    min-height: 48px; font-size: 16px; color: var(--text);
    transition: all .1s;
}

/* ── Shortcuts table ── */
.pm-sc-body { max-width: 480px; }
.pm-sc-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.pm-sc-table th { text-align: left; padding: 6px 8px; border-bottom: 2px solid var(--border); color: var(--text-muted); font-weight: 600; }
.pm-sc-table td { padding: 5px 8px; border-bottom: 1px solid var(--border); }
.pm-sc-table tr:last-child td { border-bottom: none; }
kbd {
    display: inline-block;
    padding: 2px 6px; font-size: 11px;
    background: var(--bg-subtle); border: 1px solid var(--border);
    border-radius: 3px; font-family: var(--font-mono);
    white-space: nowrap;
}

/* ── About ── */
.pm-about-body { max-width: 360px; }
.pm-about-body h2 { margin: 0 0 6px; font-size: 18px; }
.pm-about-body p  { margin: 0; font-size: 13px; line-height: 1.6; color: var(--text); }
.pm-about-body a  { color: var(--brand-primary); }

/* ── Status Bar ── */
.pm-status-bar {
    display: flex; gap: 16px;
    padding: 3px 48px;
    font-size: 11px; color: var(--text-muted);
    border-top: 1px solid var(--border);
    background: var(--bg-panel);
    flex-shrink: 0;
}
.pm-status-bar[hidden] { display: none !important; }
.pm-status-bar span { white-space: nowrap; }

/* ── Fullscreen mode ── */
body.pm-fullscreen-mode .app-editor.pm-fullscreen {
    position: fixed !important;
    inset: 0 !important;
    z-index: 8000 !important;
    border-radius: 0 !important;
}

/* tb-icons-only: vizibilitate gestionată complet de plain-menu.js syncVisibility() */
.tb-icons-only { display: none; } /* ascuns implicit; JS îl arată când e necesar */

/* În modul Classic, ascundem grupurile de butoane din toolbar (File IO, icons extra)
   dar păstrăm ctx-controls (paper style, code language/theme) */
[data-toolbar-style="classic"] .editor-toolbar-row.secondary .tool-group:not(.tb-keep) { display: none !important; }
[data-toolbar-style="classic"] .editor-toolbar-row.secondary .tb-icons-only { display: none !important; }

/* ── Plain Menu — mobile adjustments ── */
@media (max-width: 840px) {
    .pm-menu-btn {
        padding: 4px 8px;
        font-size: 12px;
    }
    .pm-dropdown {
        min-width: 180px;
        font-size: 12px;
    }
    .pm-item {
        padding: 6px 10px 6px 6px;
        font-size: 12px;
    }
    .pm-item-kbd {
        display: none; /* ascundem shortcut-urile pe mobil — spațiu limitat */
    }
}
