/* ===========================================================================
   Dark theme surface mapping
   ---------------------------------------------------------------------------
   style.css hardcodes its surfaces (#fff, #fafbf8, #fefefd, #edf0eb) and its ink
   (#20332f, #6c7e74). Those are correct for the three light themes and wrong for
   the two dark ones, so each hardcoded value is re-mapped here rather than
   edited in place — that keeps the light themes pixel-identical and confines the
   dark work to one block.

   The rule: chrome darkens, the DOCUMENT does not. `.paper` and the editor
   canvas stay paper-white in every theme, because a document app whose page
   turns black cannot be proofread.
   =========================================================================== */

/* Sidebar and top bar: the shell chrome. */

/* Cards, rows and empty states: everything that was #fff. */

/* The TOC rail inside the workspace. */

/* Editor panel: dark, because it is a form control, not the page. */

/* Inputs and buttons. */

/* The page itself stays paper. This is the whole point. */

/* Auth screens. */

/* ---------- midnight (dark, blue) ---------- */
:root[data-theme="midnight"] {
  background: var(--dox-ground);
  color: var(--dox-ink);
}

:root[data-theme="midnight"] body {
  background: var(--dox-ground);
  color: var(--dox-ink);
}

:root[data-theme="midnight"] .sidebar {
  background: var(--dox-surface);
  border-right-color: var(--dox-line-warm);
}

:root[data-theme="midnight"] .topbar {
  background: var(--dox-surface);
  border-bottom-color: var(--dox-line-warm);
  color: var(--dox-muted);
}

:root[data-theme="midnight"] .sidebar footer { border-top-color: var(--dox-line-warm); }

/* Archive / restore controls (#66). The row is a wrapper now, so the buttons need the same
   hairline treatment as the row itself, or they float as light rectangles on a dark card. */
:root[data-theme="midnight"] .doc-row .doc-open:hover { background: var(--dox-raised); }
:root[data-theme="midnight"] .doc-archive,
:root[data-theme="midnight"] .doc-restore {
  border-left-color: var(--dox-line-warm);
  color: var(--dox-muted);
  background: transparent;
}
:root[data-theme="midnight"] .doc-archive:hover { background: #3a2626; color: #f3a6a6; }
:root[data-theme="midnight"] .doc-restore:hover { background: var(--dox-raised); color: var(--dox-accent); }
:root[data-theme="midnight"] .doc-row.archived { background: var(--dox-raised); border-color: var(--dox-line-warm); }
:root[data-theme="midnight"] .doc-row.archived h3 { color: var(--dox-muted); }

:root[data-theme="midnight"] .project-card,
:root[data-theme="midnight"] .doc-row,
:root[data-theme="midnight"] .empty,
:root[data-theme="midnight"] .workspace,
:root[data-theme="midnight"] dialog {
  background: var(--dox-card);
  border-color: var(--dox-line-warm);
  color: var(--dox-ink);
}

:root[data-theme="midnight"] .project-card p,
:root[data-theme="midnight"] .project-card footer { color: var(--dox-muted); }

:root[data-theme="midnight"] .toc {
  background: var(--dox-surface);
  border-right-color: var(--dox-line-warm);
}

:root[data-theme="midnight"] .toc button.section { color: var(--dox-ink); }
:root[data-theme="midnight"] .toc button.section.active {
  background: var(--dox-accent-tint);
  color: var(--dox-accent-deep);
}

:root[data-theme="midnight"] .panel { background: var(--dox-card); color: var(--dox-ink); }
:root[data-theme="midnight"] .editor { border-right-color: var(--dox-line-warm); }

:root[data-theme="midnight"] .editor textarea,
:root[data-theme="midnight"] #content {
  background: var(--dox-raised);
  color: var(--dox-ink);
  border-color: var(--dox-line-stronger);
}

:root[data-theme="midnight"] input,
:root[data-theme="midnight"] textarea,
:root[data-theme="midnight"] select {
  background: var(--dox-raised);
  color: var(--dox-ink);
  border-color: var(--dox-line-stronger);
}

:root[data-theme="midnight"] input::placeholder,
:root[data-theme="midnight"] textarea::placeholder { color: var(--dox-faint); }

:root[data-theme="midnight"] button:not(.dox-theme-sw) {
  background: var(--dox-raised);
  color: var(--dox-ink);
  border-color: var(--dox-line-stronger);
}

:root[data-theme="midnight"] button:not(.dox-theme-sw):hover { background: var(--dox-accent-soft-tint); }
:root[data-theme="midnight"] button.primary {
  background: var(--dox-accent);
  border-color: var(--dox-accent);
  color: #fff;
  font-weight: 680;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}

:root[data-theme="midnight"] .badge {
  background: var(--dox-accent-tint);
  border-color: var(--dox-accent-strong);
  color: var(--dox-accent-deep);
}

:root[data-theme="midnight"] .eyebrow { color: var(--dox-accent-deep); }
:root[data-theme="midnight"] small,
:root[data-theme="midnight"] .muted { color: var(--dox-muted); }
:root[data-theme="midnight"] .side-note { background: var(--dox-raised); color: var(--dox-muted); }
:root[data-theme="midnight"] .notice { background: var(--dox-raised); color: var(--dox-muted); }

:root[data-theme="midnight"] .icon,
:root[data-theme="midnight"] .avatar {
  background: var(--dox-accent-tint);
  color: var(--dox-accent-deep);
}

:root[data-theme="midnight"] .paper,
:root[data-theme="midnight"] .paper * { color: var(--dox-paper-ink); }
:root[data-theme="midnight"] .paper { background: var(--dox-paper); }

:root[data-theme="midnight"] .preview { background: var(--dox-ground); }

:root[data-theme="midnight"] #toast { background: var(--dox-raised); color: var(--dox-ink); }

:root[data-theme="midnight"] .auth-form { background: var(--dox-surface); }
:root[data-theme="midnight"] .auth-story { background: var(--dox-card); }
:root[data-theme="midnight"] .auth-story p,
:root[data-theme="midnight"] .auth-foot { color: var(--dox-muted); }
:root[data-theme="midnight"] .auth-invite {
  background: var(--dox-accent-tint);
  border-color: var(--dox-accent-strong);
  border-left-color: var(--dox-accent);
  color: var(--dox-ink);
}
:root[data-theme="midnight"] .auth-invite span { color: var(--dox-muted); }

/* ---------- selected-state clarity (both dark themes) ----------
   A tint alone was too subtle: on a dark ground the difference between "selected" and
   "hover" collapsed. A leading accent bar is the clearest signal at a glance and costs no
   extra colour. */
:root[data-theme="midnight"] .sidebar nav button.active {
  position: relative;
}

:root[data-theme="midnight"] .sidebar nav button.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 62%;
  border-radius: 2px;
  background: var(--dox-accent);
}

/* Secondary buttons: raise the border a step so they stop reading as disabled. */
:root[data-theme="midnight"] button:not(.primary):not(.subtle) {
  border-color: var(--dox-accent-strong);
}

/* Small print needs more ink than body copy at the same token: 11px grey on a near-black
   ground is legible in isolation but disappears at reading distance. Lifting these two
   without touching the shared --dox-muted. */
:root[data-theme="midnight"] .auth-foot {
  color: color-mix(in srgb, var(--dox-muted) 76%, var(--dox-ink) 24%);
  font-size: 11.5px;
}

/* ---------- the theme picker must never be a light-mode artefact ----------
   The swatches are buttons, so the generic `button` rules above repainted all five the same
   colour and the two-tone gradients never showed. They are colour chips, not actions. */
:root[data-theme="midnight"] .dox-theme-picker--fixed,
:root[data-theme="midnight"] .dox-theme-picker--inline {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
}

/* No halo: the chips sit directly on the header, which is already the theme's surface. */
:root[data-theme="midnight"] .dox-theme-sw {
  border-color: transparent;
  background-clip: border-box;
}

/* ===========================================================================
   Document view: the surfaces the first pass missed
   ---------------------------------------------------------------------------
   Measured on the live app in Ember, before this block:

     DIV.heading            rgb(255,255,255)  1363x100
     SECTION                rgb(255,255,255)  1363x980
     DIV.tiptap.ProseMirror rgb(255,255,255)   908x564
     DIV.editor-footer      rgb(250,251,248)   908x37

   These are defined in the second stylesheet (the one that supersedes
   style.css), not in style.css, which is why re-mapping style.css's selectors
   did not reach them.

   The rule still holds: the DOCUMENT PAGE (.paper, the rendered master) stays
   paper-white. But the WRITING SURFACE is an editor, not a page -- a white
   block filling a dark screen is not "dark mode", it is a mistake. So the
   editor takes the raised surface and the paper stays white.
   =========================================================================== */

:root[data-theme="midnight"] .heading {
  background: transparent;
}

/* The writing pane container. */
:root[data-theme="midnight"] .document-focus .page > section,
:root[data-theme="midnight"] section.editor,
:root[data-theme="midnight"] .workspace > section {
  background: var(--dox-raised);
  color: var(--dox-ink);
  border-color: var(--dox-line-warm);
}

/* The rich-text surface itself. */
:root[data-theme="midnight"] .tiptap,
:root[data-theme="midnight"] .ProseMirror,
:root[data-theme="midnight"] .editor-content {
  background: var(--dox-raised);
  color: var(--dox-ink);
  caret-color: var(--dox-accent);
}

/* Placeholder ink inside the editor. */
:root[data-theme="midnight"] .ProseMirror p.is-editor-empty::before {
  color: var(--dox-faint);
}

/* The footer strip under the editor. */
:root[data-theme="midnight"] .editor-footer {
  background: var(--dox-card);
  border-top-color: var(--dox-line-warm);
  color: var(--dox-muted);
}

/* ===========================================================================
   Editor surfaces: the second stylesheet's selectors
   ---------------------------------------------------------------------------
   Measured on the live app in Ember before this block:

     DIV.heading            rgb(255,255,255)  1363x100
     SECTION                rgb(255,255,255)  1363x980
     DIV.tiptap.ProseMirror rgb(255,255,255)   908x564
     DIV.editor-footer      rgb(250,251,248)   908x37

   These come from rules the first pass did not name: `.document-focus .page >
   .heading`, `.document-views > section`, `.rich-editor`, `.editor-canvas .tiptap`.

   The editor is an EDITING surface, not the document page. The rendered master
   (.paper) stays paper-white; the thing you type into follows the theme.
   =========================================================================== */

:root[data-theme="midnight"] .document-focus .page > .heading {
  background: transparent;
  border-bottom-color: var(--dox-line-warm);
}

:root[data-theme="midnight"] .document-views > section,
:root[data-theme="midnight"] #view-write,
:root[data-theme="midnight"] #view-preview,
:root[data-theme="midnight"] #view-people,
:root[data-theme="midnight"] #view-settings {
  background: var(--dox-card);
}

:root[data-theme="midnight"] .document-tabs {
  background: var(--dox-card);
  border-bottom-color: var(--dox-line-warm);
}

/* .rich-editor wraps the toolbar + canvas. It carried `background: white` AND
   `overflow: hidden` -- the hidden was there to clip the rounded corners, but it also
   stopped the canvas scrolling inside its own box, so long content could not be reached. */
:root[data-theme="midnight"] .rich-editor {
  background: var(--dox-raised);
  border-color: var(--dox-line-stronger);
  /* Keep the rounding, drop the trap: the CTA that needed clipping is the toolbar's own
     corners, which are square. */
  overflow: visible;
}

:root[data-theme="midnight"] .editor-canvas {
  background: var(--dox-raised);
}

:root[data-theme="midnight"] .editor-canvas .tiptap {
  background: var(--dox-raised);
  color: var(--dox-ink);
  caret-color: var(--dox-accent);
}

:root[data-theme="midnight"] .format-toolbar {
  background: var(--dox-card);
  border-bottom-color: var(--dox-line-warm);
}

:root[data-theme="midnight"] .editor-footer {
  background: var(--dox-card);
  border-top-color: var(--dox-line-warm);
  color: var(--dox-muted);
}

/* Rich text inside the editor borrows the light theme's ink and inline code colours. */
:root[data-theme="midnight"] .tiptap pre {
  background: var(--dox-ground);
  color: var(--dox-ink);
}

:root[data-theme="midnight"] .tiptap td,
:root[data-theme="midnight"] .tiptap th {
  border-color: var(--dox-line-stronger);
}

:root[data-theme="midnight"] .tiptap th {
  background: var(--dox-card);
  color: var(--dox-ink);
}

/* ===========================================================================
   History and Settings: the surfaces the third pass missed
   ---------------------------------------------------------------------------
   Measured on the live app in Ember, before this block:

     History   DIV.tabs               rgb(255,255,255)  938x56
               ARTICLE.rich-content   rgb(255,255,255)  938x312
     Settings  DIV.settings-savebar   rgb(255,255,255)  1225x66
               SECTION.               rgb(255,255,255)  912x170

   All four take a light background from style.css that the dark theme never named.
   =========================================================================== */

/* Compare toolbar / tab strip. It is sticky, so an unthemed copy is pinned over the
   history list as a white band that never scrolls away. */
:root[data-theme="midnight"] .tabs {
  background: var(--dox-card);
  border-bottom: 1px solid var(--dox-line-warm);
}

/* The draft body and the read-only section view.
   --
   `:not(.paper .rich-content)` was wrong: the element carrying .paper ALSO carries
   .rich-content, so `.paper.rich-content` matched itself through the descendant-only test
   and got darkened -- which is backwards, since .paper is the rendered document and must
   stay paper-white.
   --
   These elements also carry an INLINE `background` written from d.format.background, which
   no stylesheet rule can override without !important. So the property is re-pointed rather
   than competed with: the inline value feeds --document-background, and the surface follows
   that variable instead of the literal colour. */
:root[data-theme="midnight"] .history-detail .rich-content,
:root[data-theme="midnight"] .readonly-content {
  background: var(--dox-raised) !important;
  color: var(--dox-ink) !important;
}

/* The rendered document itself keeps its paper treatment, in every theme. */
:root[data-theme="midnight"] .paper {
  background: var(--document-background, #ffffff);
  color: var(--document-color, #20332f);
}

/* The Save / Back-to-writing row. Sticky above the form, so it reads as a white band with
   a white button on it. Give it the card surface and a divider so it reads as a footer bar. */
:root[data-theme="midnight"] .settings-savebar {
  background: var(--dox-card);
  border-top: 1px solid var(--dox-line-warm);
  color: var(--dox-ink);
}

/* The settings tab pane. */
:root[data-theme="midnight"] #view-settings,
:root[data-theme="midnight"] .settings-inline,
:root[data-theme="midnight"] .settings-category-layout {
  background: var(--dox-card);
  color: var(--dox-ink);
}

:root[data-theme="midnight"] .settings-inline fieldset {
  background: var(--dox-raised);
  border-color: var(--dox-line-warm);
}

:root[data-theme="midnight"] .settings-inline legend {
  color: var(--dox-ink);
}

:root[data-theme="midnight"] .settings-inline .settings-grid label {
  color: var(--dox-muted);
}

/* The settings sub-navigation is a list of destinations, not actions. Neutral unless
   current. */
:root[data-theme="midnight"] .settings-subnav button {
  background: transparent;
  color: var(--dox-muted);
}

:root[data-theme="midnight"] .settings-subnav button.active {
  background: var(--dox-accent-tint);
  color: var(--dox-accent-deep);
}

/* ---------------------------------------------------------------------------
   Tabs carry the accent only when selected.
   ---------------------------------------------------------------------------
   The five view tabs are navigation. Painting every one with an accent tint made the row
   read as a set of coloured buttons and left the selected tab indistinguishable at a
   glance. Neutral by default, accent on selection.
   --------------------------------------------------------------------------- */
:root[data-theme="midnight"] .document-tabs button:not([aria-selected="true"]) {
  background: transparent;
  color: var(--dox-muted);
  border-bottom-color: transparent;
}

:root[data-theme="midnight"] .document-tabs button:not([aria-selected="true"]):hover {
  background: var(--dox-accent-soft-tint);
  color: var(--dox-ink);
}

:root[data-theme="midnight"] .document-tabs button[aria-selected="true"] {
  background: var(--dox-accent-tint);
  color: var(--dox-accent-deep);
  border-bottom-color: var(--dox-accent);
  font-weight: bold;
}

/* The settings form card. `.settings-category-content > section` paints itself white in
   style.css; the pane around it was themed but this inner card was not, so the settings
   screen kept one bright white rectangle sitting in the middle of a dark page. */
:root[data-theme="midnight"] .settings-category-content > section {
  background: var(--dox-raised);
  color: var(--dox-ink);
  border-color: var(--dox-line-warm);
}

:root[data-theme="midnight"] .settings-category-content label,
:root[data-theme="midnight"] .settings-category-content .muted {
  color: var(--dox-muted);
}

:root[data-theme="midnight"] .settings-category-nav button {
  background: transparent;
  color: var(--dox-muted);
}

:root[data-theme="midnight"] .settings-category-nav button.active {
  background: var(--dox-accent-tint);
  color: var(--dox-accent-deep);
}

/* The zoom controls and the theme swatches carry no border on the dark theme.
   --
   It came from the generic button rule (rgb(94,60,31), --dox-accent-strong) and read as a
   ring around every control in the top bar. The swatches are already defined by their own
   inset ring and the zoom buttons by their labels, so the outer border was pure noise.
   --
   Dark-only: the light themes need the hairline to separate these controls from a white bar. */
:root[data-theme="midnight"] .app-zoom-controls button,
:root[data-theme="midnight"] .app-zoom-controls button:not(.primary):not(.subtle) {
  /* Color alone leaves the 1px of layout the base rule reserved, which keeps a faint
     inset and a 1px size difference between these and the labels beside them. */
  border: 0;
}

:root[data-theme="midnight"] .dox-theme-sw {
  border-width: 0;
}
