/* edet-cm.css — make the vendored CodeMirror 6 editor look identical to
   the old .dr-textarea (calm iA-Writer column). Tokens from site.css :root. */

/* Slim, calm formatting toolbar pinned to the top of the editor pane. */
.dr-toolbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 0.15rem;
    padding: 0.3rem clamp(0.6rem, 4vw, 1rem);
    border-bottom: 1px solid var(--rule);
    background: var(--bg);
}
/* Every chrome control shares ONE height (30px) + 6px radius so the whole top
   row reads as a single uniform set. Icon buttons are square + borderless; the
   labelled pills (.dr-tb-mode) add a border. */
.dr-tb-btn {
    min-width: 30px;
    height: 30px;
    padding: 0 0.4rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--fg);                 /* full-contrast (white in dark themes) icons/glyphs */
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    cursor: pointer;
    line-height: 1;
}
.dr-tb-btn:hover { background: var(--btn-bg-hover); color: var(--accent); }   /* cyan-on-hover, like the rest of the site */
.dr-tb-btn.dr-tb-i { font-style: italic; }
/* monochrome line icons (checklist/link/image/comment) — same muted colour +
   weight as the text glyphs, never colour emoji */
.dr-tb-ico { width: 16px; height: 16px; display: block; }
.dr-tb-sep { width: 1px; height: 16px; background: var(--rule); margin: 0 0.3rem; }
/* Labelled chrome pills (View, Focus, …) match the site's shared .ms-btn:
   a filled --btn-bg base with --btn-border, hovering to the cyan accent. */
.dr-tb-mode {
    min-width: auto;
    height: 30px;
    padding: 0 0.65rem;
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    border-radius: 6px;
    color: var(--fg);
    font-size: var(--text-xs, 0.72rem);
    white-space: nowrap;
}
.dr-tb-mode:hover { color: var(--accent); border-color: var(--accent); background: var(--btn-bg-hover); }
.dr-tb-mode[aria-pressed="true"] { color: var(--accent); border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }

/* Phase 6: rich toolbar — paragraph-style dropdown, color picker, active state.
   The toolbar can scroll horizontally when crowded rather than push the right-side
   chrome off the row. */
.dr-toolbar { flex: 0 1 auto; min-width: 0; overflow-x: auto; scrollbar-width: thin; }
.dr-tb-btn.is-active { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
/* Focus-preserving dropdown BUTTONS (style / font / size) — a bordered pill with a
   label + caret; clicking opens an openContextMenu (so the editor keeps focus). */
.dr-tb-dd {
    min-width: auto; padding: 0 0.5rem; gap: 0.3rem;
    border: 1px solid var(--btn-border); background: var(--btn-bg); font-size: var(--text-xs);
}
.dr-tb-dd:hover { border-color: var(--accent); }
.dr-tb-dd-label { display: inline-block; max-width: 6rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dr-tb-dd-caret { color: var(--fg-muted); font-size: 0.7em; }
#dr-tb-style .dr-tb-dd-label { max-width: 5.5rem; }
#dr-tb-fontsize .dr-tb-dd-label { max-width: 2.5rem; }
/* text-color button = an "A" over a color bar showing the current color */
.dr-tb-colorwrap { flex-direction: column; gap: 1px; padding: 0 0.35rem; }
.dr-tb-colorglyph { font-weight: 600; line-height: 1; }
.dr-tb-colorwrap::after { content: ''; display: block; width: 16px; height: 3px; border-radius: 2px; background: var(--dr-tb-color, #e06c75); }
.dr-tb-hl { background: #ffe08a; color: #222; border-radius: 2px; padding: 0 2px; font-weight: 600; }
/* color swatch chips inside the color dropdown menu */
.dr-swatch { display: inline-block; width: 13px; height: 13px; border-radius: 3px; margin-right: 0.5rem; vertical-align: -2px; border: 1px solid rgba(127,127,127,0.4); }

/* customizable toolbar density (edet-prefs.js → #edet-app[data-toolbar]).
   Compact drops the rarer marks; Minimal keeps just bold/italic/underline/link + the
   always-on chrome pills. Separators hide too so nothing is left orphaned. */
.edet-app[data-toolbar="compact"] #dr-toolbar [data-cmd="code"],
.edet-app[data-toolbar="compact"] #dr-toolbar [data-cmd="strike"],
.edet-app[data-toolbar="compact"] #dr-toolbar [data-cmd="subscript"],
.edet-app[data-toolbar="compact"] #dr-toolbar [data-cmd="superscript"],
.edet-app[data-toolbar="compact"] #dr-toolbar [data-cmd="tasklist"],
.edet-app[data-toolbar="compact"] #dr-toolbar [data-cmd="clear"],
.edet-app[data-toolbar="compact"] #dr-toolbar .dr-tb-sep { display: none; }
.edet-app[data-toolbar="minimal"] #dr-toolbar .dr-tb-btn:not([data-cmd="bold"]):not([data-cmd="italic"]):not([data-cmd="underline"]):not([data-cmd="link"]):not(.dr-tb-mode),
.edet-app[data-toolbar="minimal"] #dr-toolbar .dr-tb-style,
.edet-app[data-toolbar="minimal"] #dr-toolbar .dr-tb-sep { display: none; }

/* track-changes review bar (edet-suggest.js) — only when suggesting / pending */
.dr-suggest-bar { display: none; }
.dr-suggest-bar[data-open="true"] {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.35rem clamp(0.6rem, 4vw, 1rem);
    border-bottom: 1px solid var(--rule);
    background: color-mix(in srgb, var(--accent) 9%, var(--bg));
    font-family: var(--font-mono);
    font-size: var(--text-xs);   /* match the read-only banner's text size */
}
.dr-suggest-label { flex: 1 1 auto; min-width: 0; color: var(--fg-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
/* white in dark / black in light, like the rest of the chrome text — --fg is promoted on
   .dr-suggest-bar (edet-editor.css max-contrast rule). No accent tint on the label. */
.dr-suggest-bar[data-active="true"] .dr-suggest-label { color: var(--fg); }
/* per-change accept/reject popover — click any tracked change to resolve just it
   (the bar's Accept-all / Reject-all stays for bulk). Buttons are canonical .dr-btn. */
.dr-sug-pop {
    position: fixed;
    z-index: 80;
    display: inline-flex;
    gap: 2px;
    padding: 3px;
    background: var(--bg-elevated, var(--bg-raised));
    border: 1px solid var(--rule);
    border-radius: 8px;
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
}
.dr-sug-pop-accept:hover { color: var(--status-ok); border-color: color-mix(in srgb, var(--status-ok) 45%, var(--rule)); }
.dr-sug-pop-reject:hover { color: var(--status-err); border-color: color-mix(in srgb, var(--status-err) 45%, var(--rule)); }
/* On the grid desk the bar FLOATS over the top of the desk instead of taking layout
   height — otherwise toggling Suggest edits pushes the whole canvas/grid down. The pane
   is position:relative; z-index sits above the canvas (z-2) + frost (z-6), below the
   chrome (z-20). */
/* Float over the top of the desk (no layout push). It's TRANSPARENT here (site.css
   transparent-grid rule) and frosted by the shared body::before top pane — which
   setTopFrostHeight extends to cover the bar — so its frost is IDENTICAL to the toolbar
   (same single pane, same tint/blur), not a separate glass layer. The cyan label is the
   only "suggesting" cue. */
.edet-app[data-desk="grid"] .dr-suggest-bar[data-open="true"] {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    border-bottom: none;
}
.dr-suggest-actions { display: flex; gap: 0.3rem; flex: 0 0 auto; }
/* identical to the read-only banner's .dr-readonly-btn (same chip: --btn-bg base,
   --btn-border, accent hover); the "Done" primary matches .dr-rb-merge (accent). */
.dr-suggest-btn {
    flex: 0 0 auto;
    height: 26px;
    padding: 0 0.7rem;
    background: var(--btn-bg);
    border: 1px solid var(--btn-border);
    border-radius: 6px;
    color: var(--fg);
    font: inherit;
    font-size: var(--text-xs);
    cursor: pointer;
}
.dr-suggest-btn:hover { color: var(--accent); border-color: var(--accent); background: var(--btn-bg-hover); }
.dr-suggest-stop { color: var(--accent); border-color: var(--accent); }

.dr-editor-host {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    display: flex;
}
.dr-editor-host .cm-editor {
    flex: 1 1 auto;
    min-height: 0;
    width: 100%;
    background: var(--bg);
    color: var(--fg);
}
.dr-editor-host .cm-scroller {
    font-family: var(--font-mono);
    font-size: var(--dr-font-size, 18px);
    line-height: var(--dr-line, 1.85);
    letter-spacing: 0.01em;
    overflow-y: auto;
    -webkit-tap-highlight-color: transparent;
}
/* Centered reading measure shared with the preview (mirrors .dr-textarea). */
.dr-editor-host .cm-content {
    width: 100%;
    max-width: var(--dr-page-width, 44rem);
    margin: 0 auto;
    box-sizing: border-box;
    padding: 2.6rem clamp(1.1rem, 4vw, 2.25rem) 8rem;
    caret-color: var(--accent);
    color: var(--fg);
    outline: none;   /* caret is the focus indicator; no ring around the column */
}
.edet-app[data-preview="split"] .dr-editor-host .cm-content { max-width: 38rem; }
.dr-editor-host .cm-line { padding: 0; }
.dr-editor-host .cm-placeholder { color: var(--fg-deep); }

/* Source mode renders as the SAME page sheet on the SAME desk as WYSIWYG, so
   toggling Rich⇄Source is seamless (vars from edet-tiptap.css themes). */
.edet-app[data-editor-mode="source"] .dr-editor-host {
    background: var(--dr-desk);
    display: block;          /* the DESK scrolls (outer), exactly like Rich */
    overflow-y: auto;
    padding: 2.4rem 1.5rem 5rem;
}
.edet-app[data-editor-mode="source"] .cm-editor {
    max-width: var(--dr-page-width, 50rem);
    width: 100%;
    margin: 0 auto;
    min-height: calc(100dvh - 13rem);   /* always a full-height sheet, like Rich */
    background: var(--dr-paper);
    color: var(--dr-ink);
    border: 1px solid var(--rule);
    border-radius: 3px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.10), 0 10px 34px rgba(0, 0, 0, 0.12);
}
/* let CodeMirror GROW with its content instead of inner-scrolling — the desk
   scrolls instead, matching Rich (no short sheet, no double scrollbar). */
.edet-app[data-editor-mode="source"] .cm-scroller { overflow: visible; }
.edet-app[data-editor-mode="source"] .cm-content {
    max-width: none;
    margin: 0;
    padding: 3.5rem clamp(1.5rem, 6vw, 4.5rem) 6rem;   /* matches Rich so text doesn't shift on toggle */
    color: var(--dr-ink);
}
.edet-app[data-editor-mode="source"][data-preview="split"] .dr-editor-host .cm-content { max-width: none; }
@media (max-width: 820px) {
    .edet-app[data-editor-mode="source"] .dr-editor-host { background: var(--bg); padding: 0; }
    .edet-app[data-editor-mode="source"] .cm-editor { min-height: 100%; border: none; border-radius: 0; box-shadow: none; }
    .edet-app[data-editor-mode="source"] .cm-content { padding: 1.8rem clamp(1.1rem, 5vw, 1.6rem) 6rem; }
}

/* readonly (scenes manuscript synthesis) + disabled (no doc) → dimmed, like
   the textarea's :disabled / [readonly] states. CM drops contenteditable on
   both. */
.dr-editor-host .cm-content[contenteditable="false"] { color: var(--fg-dim); }

/* The editor shows focus via its caret; no ring around the whole column
   (mirrors the .dr-textarea exemption in edet-base.css). */
.dr-editor-host .cm-editor.cm-focused { outline: none; }
.edet-app .dr-editor-host :focus-visible { outline: none; }

/* selection tint on-brand */
.dr-editor-host .cm-selectionBackground,
.dr-editor-host .cm-content ::selection { background: color-mix(in srgb, var(--accent) 28%, transparent); }

/* ---- appearance controls (edet-prefs.js — reused by the Appearance overlay) ---- */
.dr-pref-section { margin-bottom: 0.7rem; }
.dr-pref-label {
    color: var(--fg-deep);
    font-size: var(--text-xs, 0.72rem);
    text-transform: uppercase;
    letter-spacing: 0.08em;
    margin-bottom: 0.35rem;
}
/* segmented control (theme / width / toolbar) */
.dr-pref-seg { display: flex; gap: 2px; background: var(--bg); border: 1px solid var(--rule); border-radius: 7px; padding: 2px; flex-wrap: wrap; }
.dr-pref-seg-btn {
    flex: 1 1 auto;
    min-width: 0;
    padding: 0.3rem 0.4rem;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: var(--fg-muted);
    font-family: var(--font-mono);
    font-size: var(--text-xs);
    cursor: pointer;
    white-space: nowrap;
}
.dr-pref-seg-btn:hover { color: var(--fg); }
.dr-pref-seg-btn.active { background: var(--accent-muted); color: var(--accent); }
/* typeface picker */
.dr-pref-fonts { max-height: 168px; overflow-y: auto; border: 1px solid var(--rule); border-radius: 7px; padding: 2px; background: var(--bg); }
.dr-pref-fontgroup { color: var(--fg-deep); font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.08em; padding: 0.35rem 0.4rem 0.15rem; }
.dr-pref-font {
    display: block;
    width: 100%;
    text-align: left;
    padding: 0.35rem 0.5rem;
    border: none;
    border-radius: 5px;
    background: transparent;
    color: var(--fg);
    font-size: 0.95rem;
    cursor: pointer;
}
.dr-pref-font:hover { background: var(--row-hover); }
.dr-pref-font.active { background: var(--accent-muted); color: var(--accent); }
/* numeric size / line height row */
.dr-pref-num { display: flex; align-items: center; gap: 0.5rem; }
.dr-pref-numinput {
    width: 3.4rem;
    flex: 0 0 auto;
    padding: 0.3rem 0.4rem;
    background: var(--bg);
    border: 1px solid var(--rule);
    border-radius: 6px;
    color: var(--fg);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    text-align: center;
}
.dr-pref-readout { background: transparent; border-color: transparent; color: var(--fg-muted); }
.dr-pref-unit { color: var(--fg-dim); font-size: var(--text-xs); margin-left: -0.3rem; }
.dr-pref-slider { flex: 1 1 auto; min-width: 0; accent-color: var(--accent); cursor: pointer; }
/* focus toggle row */
.dr-pref-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.4rem 0.2rem 0.1rem;
    background: transparent;
    border: none;
    color: var(--fg);
    font-family: var(--font-mono);
    font-size: var(--text-sm);
    cursor: pointer;
}
.dr-pref-switch { width: 34px; height: 18px; border-radius: 10px; background: var(--rule); position: relative; transition: background var(--dur-fast) var(--ease-smooth); flex: 0 0 auto; }
.dr-pref-switch::after { content: ''; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%; background: var(--fg-muted); transition: transform var(--dur-fast) var(--ease-smooth); }
.dr-pref-toggle.on .dr-pref-switch { background: var(--accent); }
.dr-pref-toggle.on .dr-pref-switch::after { transform: translateX(16px); background: #fff; }

/* ---- Appearance overlay (the "View" button → frosted full overlay) ---- */
.dr-appear { max-width: 60rem; margin: 0 auto; }
.dr-appear-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 20rem); gap: 1.5rem; align-items: start; }
.dr-appear-controls { display: flex; flex-direction: column; gap: 1.1rem; min-width: 0; }
.dr-appear-group { border: 1px solid var(--rule); border-radius: 10px; padding: 0.85rem 1rem 1rem; background: color-mix(in srgb, var(--bg-elevated) 55%, transparent); }
.dr-appear-group-h { margin: 0 0 0.4rem; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--fg-muted); }
.dr-appear-group-desc { margin: 0 0 0.85rem; font-size: var(--text-xs); line-height: 1.45; color: var(--fg-dim); }
.dr-appear-sliderrow { margin-bottom: 0.55rem; }
.dr-appear-sliderrow .dr-pref-label { margin-bottom: 0.2rem; }
.dr-appear-reset { margin-top: 0.4rem; }
/* sticky live preview = a tiny document page (paper bg + ink set inline by JS) */
.dr-appear-preview { position: sticky; top: 0; }
.dr-appear-preview-label { font-size: var(--text-xs); text-transform: uppercase; letter-spacing: 0.08em; color: var(--fg-muted); margin-bottom: 0.45rem; }
.dr-appear-sample { border: 1px solid var(--rule); border-radius: 10px; padding: 1.1rem 1.2rem; background: var(--bg-elevated); overflow: auto; max-height: 62vh; }
.dr-appear-sample h1, .dr-appear-sample h2, .dr-appear-sample h3 { margin: 0 0 0.4em; line-height: 1.2; }
.dr-appear-sample p { margin: 0 0 0.7em; }
.dr-appear-sample blockquote { margin: 0 0 0.7em; padding-left: 0.8em; border-left: 3px solid currentColor; opacity: 0.85; }
/* custom-theme color builder (Appearance → Theme) */
.dr-appear-custom { display: flex; gap: 1rem; flex-wrap: wrap; }
.dr-appear-color { display: inline-flex; align-items: center; gap: 0.4rem; color: var(--fg); font-size: var(--text-sm); cursor: pointer; }
.dr-appear-color input[type="color"] { width: 28px; height: 22px; padding: 0; border: 1px solid var(--rule); border-radius: 5px; background: transparent; cursor: pointer; }
@media (max-width: 720px) {
    .dr-appear-cols { grid-template-columns: 1fr; }
    .dr-appear-preview { position: static; }
}
