/* DREAD2-259: no-JS body editor chrome (reply composer, top comment composer,
   update composer, standalone editors). body-editor.css is the single source;
   the CRITICAL subset (panel chrome + format bar) is copied verbatim into
   site.css and _critical_style.html so the first paint matches the styled page.
   forum/tests/test_cold_load_css.py fails on any drift of those rules. */

/* === CRITICAL FIRST-PAINT SUBSET (keep in sync with site.css + _critical_style.html) === */
.body-editor {
  display: grid;
  gap: .55rem;
  padding: .85rem .9rem .9rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper-soft);
  min-width: 0;
}
.body-editor__bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: .45rem .75rem;
}
.body-editor__heading { margin: 0; font-size: .9rem; font-weight: 750; color: var(--ink); }
.body-editor__format { display: flex; align-items: center; gap: .5rem; }
.body-editor__format-label { margin: 0; color: var(--muted); font-size: .8rem; font-weight: 650; }
.body-editor__format-label label { margin: 0; font-weight: 650; }
.body-editor__format-radios {
  display: flex; align-items: center; gap: .15rem;
  padding: .12rem; border: 1px solid var(--line);
  border-radius: 999px; background: var(--paper);
}
.body-editor__format-radios input {
  position: absolute; width: 1px; height: 1px; margin: 0;
  opacity: 0; pointer-events: none;
}
.body-editor__format-radios label {
  display: inline-flex; align-items: center; min-height: 26px;
  margin: 0; padding: .1rem .55rem; border-radius: 999px;
  color: var(--muted); font-size: .78rem; font-weight: 650; cursor: pointer;
}
.body-editor__format-radios input:checked + label { background: var(--button-bg); color: #fff; }
.body-editor__format-radios input:focus-visible + label { outline: 2px solid var(--purple); outline-offset: 1px; }
.body-editor__help {
  display: inline-grid; place-items: center; flex: 0 0 auto;
  width: 26px; height: 26px; padding: 0;
  border: 1px solid var(--line); border-radius: 999px;
  background: var(--paper); color: var(--purple);
  font-size: .9rem; font-weight: 750; cursor: pointer;
}
.body-editor__help:hover { border-color: var(--purple); background: var(--purple-soft); }
.body-editor__format-errors { color: var(--danger); font-size: .8rem; }
.body-editor textarea, .body-editor .markdown-input { width: 100%; min-width: 0; }
.body-editor__actions { display: flex; flex-wrap: wrap; gap: .45rem; }
/* === END CRITICAL FIRST-PAINT SUBSET === */

/* Save-draft tooltip (hover + focus; touch fallback lives in the help popover). */
.body-editor__draft { position: relative; }
.body-editor__draftnote {
  display: none; position: absolute; z-index: 5; left: 0; bottom: calc(100% + .4rem);
  width: max-content; max-width: min(19rem, 72vw);
  padding: .5rem .6rem; border: 1px solid #b78b50; border-radius: .35rem;
  background: #fff9ec; color: #3d3020; box-shadow: 0 2px 8px #0002;
  font-size: .75rem; line-height: 1.35; font-weight: 500;
  text-align: left; white-space: normal;
}
.body-editor__draft:hover .body-editor__draftnote,
.body-editor__draft:focus .body-editor__draftnote,
.body-editor__draft:focus-visible .body-editor__draftnote { display: block; }

/* Single native help popover per document (base include). */
.editor-help-popover { display: none; }
.editor-help-popover:popover-open {
  display: block;
  position: fixed; z-index: 120; inset: 0; margin: auto;
  width: min(42rem, calc(100% - 2rem)); max-height: min(80dvh, 40rem);
  overflow: auto; padding: 1.1rem 1.25rem;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--paper); color: var(--ink);
  box-shadow: 0 18px 40px rgba(12, 12, 20, .3);
}
.editor-help-popover__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: .75rem; margin-bottom: .6rem;
}
.editor-help-popover h2 { margin: 0; font-size: 1.05rem; }
.editor-help-popover__close {
  display: inline-grid; place-items: center; flex: 0 0 auto;
  width: 32px; height: 32px; padding: 0;
  border: 1px solid var(--line); border-radius: 3px;
  background: var(--paper-soft); color: var(--ink);
  font-size: 1rem; cursor: pointer;
}
.editor-help-popover__close:hover { border-color: var(--purple); background: var(--purple-soft); }
.editor-help-popover dl { display: grid; grid-template-columns: minmax(11rem, 1fr) 2fr; gap: .6rem 1rem; }
.editor-help-popover dd { margin: 0; }
.editor-help-popover code { font-family: ui-monospace, monospace; }
.editor-help-popover pre {
  overflow-x: auto; padding: .7rem; border: 1px solid var(--line);
  border-radius: .5rem; white-space: pre;
}

@media (max-width: 480px) {
  .body-editor__format { flex-wrap: wrap; width: 100%; }
  .body-editor__help { margin-left: auto; }
  .editor-help-popover dl { grid-template-columns: minmax(0, 1fr); gap: .2rem; }
  .editor-help-popover dd { margin-bottom: .7rem; }
}

:root[data-theme="dark"] .body-editor__draftnote { background: #3d2f1b; border-color: #b78b50; color: #f3ddb0; }
:root[data-theme="dark"] .editor-help-popover__close { background: var(--paper-soft); color: var(--ink); }
