/* DocEditor (editor.js): the Write / Edit dialog around Toast UI Editor and the Dictate recording panel.
   Colors come from app.css tokens, so both follow light and dark. --rec is the recording red. */
:root { --rec: #e2445c; --rec-soft: #fde8eb; --de-shadow: 0 24px 64px rgba(15, 21, 40, .28); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --rec: #ff6b81; --rec-soft: #45202a; --de-shadow: 0 24px 64px rgba(0, 0, 0, .55); } }
:root[data-theme="dark"] { --rec: #ff6b81; --rec-soft: #45202a; --de-shadow: 0 24px 64px rgba(0, 0, 0, .55); }

body.de-open { overflow: hidden; }
.de-back { position: fixed; inset: 0; z-index: 1000; background: rgba(15, 21, 40, .48); display: grid; place-items: center; padding: 24px; animation: de-fade .14s ease-out; }
.de-back-sm { z-index: 1010; }
@keyframes de-fade { from { opacity: 0; } }

/* ---------- editor dialog */
.de-dlg { width: min(1080px, 100%); height: min(860px, calc(100vh - 48px)); height: min(860px, calc(100dvh - 48px)); display: flex; flex-direction: column;
  background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--de-shadow); overflow: hidden; outline: none; }
.de-head { display: flex; align-items: flex-end; gap: 12px 20px; flex-wrap: wrap; padding: 16px 20px 12px; border-bottom: 1px solid var(--line); }
.de-titles { flex: 1 1 320px; min-width: 0; display: grid; gap: 8px; }
.de-titles h2 { font-size: 18px; font-weight: 800; overflow-wrap: anywhere; }
.de-namef { display: flex; align-items: center; gap: 10px; }
.de-namef span { font-size: 12px; font-weight: 700; color: var(--muted); white-space: nowrap; }
.de-namef input { flex: 1; min-width: 0; max-width: 420px; font: inherit; font-family: var(--f-mono); font-size: 13px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--ink); }
.de-namef input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.de-acts { display: flex; gap: 8px; margin-left: auto; }
.de-acts .btn { min-width: 84px; }
.de-note { margin: 0; padding: 9px 20px; font-size: 13px; background: var(--support-soft); color: var(--ink); border-bottom: 1px solid var(--line); }
.de-note::before { content: "i"; display: inline-grid; place-items: center; width: 17px; height: 17px; margin-right: 8px; border-radius: 50%; background: var(--support); color: var(--surface); font-weight: 800; font-size: 11px; font-style: italic; vertical-align: 1px; }
.de-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 8px 14px; padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--bg); }
.de-seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; background: var(--surface); }
.de-seg button { font: inherit; font-size: 13px; font-weight: 600; padding: 5px 12px; border: 0; background: none; color: var(--muted); cursor: pointer; }
.de-seg button + button { border-left: 1px solid var(--line); }
.de-seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.de-seg button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.de-dict { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.de-state { margin-left: auto; font-size: 12.5px; color: var(--muted); }
.de-err { margin: 0; padding: 9px 20px; font-size: 13.5px; background: var(--rec-soft); color: var(--ink); border-bottom: 1px solid var(--line); border-left: 4px solid var(--rec); }
.de-err[hidden] { display: none; }
.de-body { flex: 1; min-height: 0; display: flex; }
.de-ed { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.de-loading { margin: auto; color: var(--muted); font-size: 14px; padding: 24px; text-align: center; }
.de-loading.err { color: var(--rec); }
.de-foot { display: flex; justify-content: space-between; gap: 12px; padding: 7px 20px; border-top: 1px solid var(--line); font-size: 12px; color: var(--muted); }

/* buttons with an icon, the recording pill */
.de-ico { width: 16px; height: 16px; flex: none; fill: currentColor; }
.de-dictbtn, .de-iconbtn { display: inline-flex; align-items: center; gap: 6px; }
.de-dictbtn { font-size: 13px; padding: 5px 12px; }
.de-rec { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--rec); padding: 4px 12px 4px 10px; border-radius: 999px; background: var(--rec-soft); }
.de-rec.idle { color: var(--muted); background: none; font-weight: 500; padding-inline: 0; }
.de-rec b { font-family: var(--f-mono); font-variant-numeric: tabular-nums; font-weight: 600; }
.de-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--rec); animation: de-pulse 1.2s ease-in-out infinite; }
@keyframes de-pulse { 50% { opacity: .35; transform: scale(.8); } }
.de-spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: de-rot .8s linear infinite; }
@keyframes de-rot { to { transform: rotate(360deg); } }
.btn.de-stop { background: var(--rec); border-color: var(--rec); color: #fff; font-size: 13px; padding: 5px 14px; }
.btn.de-stop:disabled { opacity: .6; }

/* Toast UI restyled with the app tokens */
.de-dlg .toastui-editor-defaultUI { flex: 1; border: 0; border-radius: 0; font-family: var(--f-body); }
.de-dlg .toastui-editor-defaultUI .toastui-editor-toolbar { flex: none; }
.de-dlg .toastui-editor-defaultUI-toolbar { background: var(--surface); border-bottom: 1px solid var(--line); padding-inline: 14px; }
.de-dlg .toastui-editor-main, .de-dlg .toastui-editor-ww-container, .de-dlg .toastui-editor-md-container { background: var(--surface); }
.de-dlg .toastui-editor-contents { font-family: var(--f-body); font-size: 15px; line-height: 1.65; color: var(--ink); }
.de-dlg .toastui-editor-contents p, .de-dlg .toastui-editor-contents li { color: var(--ink); }
.de-dlg .toastui-editor-contents h1, .de-dlg .toastui-editor-contents h2, .de-dlg .toastui-editor-contents h3,
.de-dlg .toastui-editor-contents h4, .de-dlg .toastui-editor-contents h5, .de-dlg .toastui-editor-contents h6 { font-family: var(--f-display); color: var(--ink); border-bottom-color: var(--line); }
.de-dlg .toastui-editor-contents a { color: var(--accent); }
.de-dlg .toastui-editor-ww-container .toastui-editor-contents { padding: 20px max(24px, calc((100% - 760px) / 2)); }
.de-dlg .toastui-editor-md-container .toastui-editor { font-family: var(--f-mono); font-size: 13.5px; }
.de-dlg .toastui-editor-dark .toastui-editor-defaultUI-toolbar,
.de-dlg .toastui-editor-dark.toastui-editor-defaultUI .toastui-editor-toolbar { background: var(--surface); border-color: var(--line); }
.de-dlg .toastui-editor-dark .toastui-editor-md-container, .de-dlg .toastui-editor-dark .toastui-editor-ww-container,
.de-dlg .toastui-editor-dark .toastui-editor-main { background: var(--surface); }
.de-dlg .toastui-editor-dark .toastui-editor-md-splitter { background: var(--line); }
.de-dlg .toastui-editor-dark .toastui-editor-contents p, .de-dlg .toastui-editor-dark .toastui-editor-contents li { color: var(--ink); }
.de-dlg .toastui-editor-dark .toastui-editor-defaultUI-toolbar button:not(:disabled):hover { background-color: var(--accent-soft); border-color: var(--line); }

/* ---------- the Dictate recording panel */
.de-rp { width: min(400px, 100%); display: grid; justify-items: center; gap: 10px; text-align: center; padding: 26px 24px 20px; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--de-shadow); outline: none; }
.de-rp h2 { font-size: 18px; font-weight: 800; }
.de-rp-sub { margin: 0; font-size: 13px; color: var(--muted); max-width: 32ch; }
.de-rp-mic { width: 76px; height: 76px; margin-top: 6px; border-radius: 50%; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); position: relative; }
.de-rp-mic .de-ico { width: 32px; height: 32px; }
.de-rp.is-recording .de-rp-mic { background: var(--rec); color: #fff; cursor: pointer; }
.de-rp.is-recording .de-rp-mic::after { content: ""; position: absolute; inset: -8px; border-radius: 50%; border: 3px solid var(--rec); opacity: .5; animation: de-ring 1.4s ease-out infinite; }
@keyframes de-ring { from { transform: scale(.9); opacity: .6; } to { transform: scale(1.25); opacity: 0; } }
.de-rp.is-error .de-rp-mic { background: var(--rec-soft); color: var(--rec); }
.de-rp-time { margin: 0; font-family: var(--f-mono); font-size: 22px; font-weight: 600; font-variant-numeric: tabular-nums; }
.de-rp.is-error .de-rp-time { display: none; }
.de-rp-msg { margin: 0; min-height: 1.5em; font-size: 13.5px; color: var(--muted); }
.de-rp-msg.err { color: var(--ink); background: var(--rec-soft); border-left: 4px solid var(--rec); padding: 8px 12px; border-radius: 6px; text-align: left; }
.de-rp-acts { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 6px; }

/* ---------- Write / Dictate / Edit buttons on the pages (app.js) */
.wbtn { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 6px 12px; }
.wbtn .de-ico { width: 15px; height: 15px; }

/* phone: the editor fills the screen */
@media (max-width: 640px) {
  .de-back { padding: 0; }
  .de-back-sm { padding: 16px; align-items: end; }
  .de-dlg { width: 100%; height: 100vh; height: 100dvh; border-radius: 0; border: 0; }
  .de-head { padding: 12px 16px 10px; }
  .de-titles { flex-basis: 100%; }
  .de-acts { margin-left: 0; width: 100%; }
  .de-acts .btn { flex: 1; }
  .de-bar, .de-note, .de-err { padding-inline: 16px; }
  .de-foot { display: none; }
  .de-dlg .toastui-editor-ww-container .toastui-editor-contents { padding: 14px 16px; }
}
@media (prefers-reduced-motion: reduce) {
  .de-back, .de-dot, .de-spin, .de-rp.is-recording .de-rp-mic::after { animation: none; }
}
/* The editor's "Start writing…" placeholder at 4.5:1 (Toast UI draws it in #999) */
.de-dlg .placeholder.ProseMirror-widget, .de-dlg .toastui-editor-contents .placeholder { color: var(--muted) !important; }
