/* Doxifi UI themes.
 *
 * style.css carries hardcoded hex colours from before themes existed. Rather
 * than rewriting every rule, this layer redefines the same visual roles per
 * theme and overrides the rules that matter. Only colour is changed; no layout,
 * spacing or type rule is touched.
 *
 * Loaded after style.css so these win on equal specificity.
 */

/* ---------- accents only ----------
 * A theme changes the ACCENT and the accent tints. Text, muted text, borders and
 * the page ground stay constant across all three themes.
 *
 * Two separate concerns, deliberately kept apart:
 *   --dox-accent*        application accent. Chrome only.
 *   --doc-* / --accent   document format. Content only — set per document from
 *                        its own stored format, never from the theme.
 *
 * Tint tokens are the accent mixed into white, so a selected tab, an active nav
 * row, the preview toolbar and a history entry all pick up the theme accent
 * without tinting any text. */

/* Default theme: cobalt. The bare :root rule carries the DEFAULT values, so it
 * must match cobalt — otherwise a page that loads without a [data-theme]
 * attribute would render teal. Teal gets its own explicit block below. */
:root,
:root[data-theme="cobalt"] {
  --dox-accent:         #1d4ed8;
  --dox-accent-soft:    #4a6fa5;
  --dox-accent-deep:    #1637a0;

  /* The readable colour ON the accent. Needed per theme: without it, chat bubbles
     and any accent-filled surface fall back to the page ink (#107). */
  --dox-paper:             #ffffff;
  --dox-paper-ink:         #20332f;
  --dox-accent-tint:    #e6edfc;
  --dox-accent-soft-tint: #f2f6fd;
  --dox-accent-strong:  #ccdcfa;
  --dox-shadow:         rgba(11, 21, 36, 0.14);
  --dox-shadow-strong:  rgba(11, 21, 36, 0.24);

  /* Surface family. style.css hardcodes green-greys (#fafbf8, #dfe6e0, #d9e2d9,
     #f5f7f5) that were correct only for teal, so the TOC, sidebar divider and
     workspace border stayed green under cobalt and citrus. These carry the same
     lightness with the theme's own hue. */
  --dox-ground:         #f5f7fb;
  --dox-surface:        #fafbfe;
  --dox-line-warm:      #dfe4ee;
  --dox-line-stronger:  #d6dce9;


  /* --accent was NEVER DEFINED, so all 29 `var(--accent, #teal)` chrome rules in
     style.css silently fell back to teal under every theme: the account avatar, subtle
     buttons, badges, the active section tab and lock marks all stayed green under cobalt.
     Defining it per theme makes them follow the theme in one move instead of patching 29
     fallbacks. Document content (.paper/.tiptap) is unaffected: it sets its own --accent
     from the document format on the content container, which is closer in the tree. */
  --accent: #1d4ed8;
  /* --tint was only defined inside a narrow scope, so 28 `var(--tint, #teal)` rules
     fell back to teal-grey in every theme (#100). Defined here, per theme. */
  --tint: #f2f6fd;
  --tint-soft: #e6edfc;
  --accent-ink: #1d4ed8;
  --accent-tint: #e6edfc;

  /* Surface family for the light themes. These were only ever defined for midnight,
     because nothing in the light UI used them -- every light surface was a hardcoded
     hex in style.css. Chat reads them, so they must exist or an unset variable
     resolves to nothing and a bubble loses its background entirely. */
  --dox-card:             #ffffff;
  --dox-raised:           #f0f2f8;
  /* Identity colours (#135): per-person avatar hues, drawn from this theme's family. */
  --id-1: #1d4ed8;  --id-2: #0f766e;  --id-3: #b45309;  --id-4: #7c3aed;
  --id-5: #0369a1;  --id-6: #be123c;  --id-7: #4d7c0f;
  --dox-ink:              #20332f;
  --dox-muted:            #6c7e74;
  --dox-faint:            #8d9a92;
}

:root[data-theme="teal"] {
  --dox-accent:         #245e4f;
  --dox-accent-soft:    #526c65;
  --dox-accent-deep:    #1b453c;

  /* The readable colour ON the accent. Needed per theme: without it, chat bubbles
     and any accent-filled surface fall back to the page ink (#107). */
  --dox-paper:             #ffffff;
  --dox-paper-ink:         #20332f;
  --dox-accent-tint:    #e9f1ec;
  --dox-accent-soft-tint: #f4f8f5;
  --dox-accent-strong:  #d7e8dd;
  --dox-shadow:         rgba(16, 41, 31, 0.16);
  --dox-shadow-strong:  rgba(16, 41, 31, 0.28);

  /* Teal IS the origin of the hardcoded values, so these reproduce today's
     appearance exactly -- teal must look unchanged after this change. */
  --dox-ground:         #f5f7f5;
  --dox-surface:        #fafbf8;
  --dox-line-warm:      #dfe6e0;
  --dox-line-stronger:  #d9e2d9;


  /* --accent was NEVER DEFINED, so all 29 `var(--accent, #teal)` chrome rules in
     style.css silently fell back to teal under every theme: the account avatar, subtle
     buttons, badges, the active section tab and lock marks all stayed green under cobalt.
     Defining it per theme makes them follow the theme in one move instead of patching 29
     fallbacks. Document content (.paper/.tiptap) is unaffected: it sets its own --accent
     from the document format on the content container, which is closer in the tree. */
  --accent: #245e4f;
  /* --tint was only defined inside a narrow scope, so 28 `var(--tint, #teal)` rules
     fell back to teal-grey in every theme (#100). Defined here, per theme. */
  --tint: #f1f5f2;
  --tint-soft: #e9f1ec;
  --accent-ink: #245e4f;
  --accent-tint: #e9f1ec;

  /* Surface family for the light themes. These were only ever defined for midnight,
     because nothing in the light UI used them -- every light surface was a hardcoded
     hex in style.css. Chat reads them, so they must exist or an unset variable
     resolves to nothing and a bubble loses its background entirely. */
  --dox-card:             #ffffff;
  --dox-raised:           #f0f3f0;
  --id-1: #245e4f;  --id-2: #1d4ed8;  --id-3: #b45309;  --id-4: #7c3aed;
  --id-5: #0369a1;  --id-6: #be123c;  --id-7: #4d7c0f;
  --dox-ink:              #20332f;
  --dox-muted:            #6c7e74;
  --dox-faint:            #8d9a92;
}

:root[data-theme="citrus"] {
  --dox-accent:         #c2410c;
  --dox-accent-soft:    #96613f;
  --dox-accent-deep:    #93300a;

  /* The readable colour ON the accent. Needed per theme: without it, chat bubbles
     and any accent-filled surface fall back to the page ink (#107). */
  --dox-paper:             #ffffff;
  --dox-paper-ink:         #20332f;
  --dox-accent-tint:    #fbeade;
  --dox-accent-soft-tint: #fdf4ee;
  --dox-accent-strong:  #f6d7c3;
  --dox-shadow:         rgba(28, 18, 6, 0.14);
  --dox-shadow-strong:  rgba(28, 18, 6, 0.24);

  /* Same lightness, warm hue, so citrus reads warm-grey rather than green. */
  --dox-ground:         #fdfaf7;
  --dox-surface:        #fefcf9;
  --dox-line-warm:      #efe4da;
  --dox-line-stronger:  #e8dbcf;


  /* --accent must be defined per theme (#100): without it every `var(--accent, #teal)`
     chrome rule falls back to teal. Values here are each theme’s own accent, never a
     borrowed hue. Document content keeps its own --accent from the document format. */
  --accent: #c2410c;
  /* --tint was only defined inside a narrow scope, so 28 `var(--tint, #teal)` rules
     fell back to teal-grey in every theme (#100). Defined here, per theme. */
  --tint: #fdf3ec;
  --tint-soft: #fdece0;
  --accent-ink: #c2410c;
  --accent-tint: #fdece0;

  /* Surface family for the light themes. These were only ever defined for midnight,
     because nothing in the light UI used them -- every light surface was a hardcoded
     hex in style.css. Chat reads them, so they must exist or an unset variable
     resolves to nothing and a bubble loses its background entirely. */
  --dox-card:             #ffffff;
  --dox-raised:           #f7f1ea;
  --id-1: #c2410c;  --id-2: #1d4ed8;  --id-3: #0f766e;  --id-4: #7c3aed;
  --id-5: #0369a1;  --id-6: #be123c;  --id-7: #4d7c0f;
  --dox-ink:              #20332f;
  --dox-muted:            #6c7e74;
  --dox-faint:            #8d9a92;
}

/* ---------- theme picker ---------- */
.dox-theme-picker { display: flex; align-items: center; gap: 6px; }

/* Fallback when neither header exists (the auth screen). Offset below the top
 * of the viewport so it cannot sit on top of anything in a header row. */
.dox-theme-picker--fixed {
  position: fixed; top: 72px; right: 16px; z-index: 20;
  padding: 6px 8px;
  /* Was hardcoded #fff, so on a dark theme the pill stayed white and the swatches read as
     washed-out blobs against it. Theme tokens now drive it. */
  background: var(--dox-card, #fff);
  border: 1px solid var(--dox-line-warm, #dfe6dc);
  border-radius: 100px;
  box-shadow: 0 2px 8px var(--dox-shadow);
}

.dox-theme-sw {
  /* Rectangles, not circles: a rectangle reads as a colour chip you pick from a palette,
     a circle reads as a status light. Wider than tall so five fit a side rail. */
  width: 26px; height: 16px; flex: none;
  border-radius: 4px;
  border: 2px solid transparent;
  padding: 0; cursor: pointer;
  /* No background-clip: content-box -- it clipped linear-gradient fills to the padding box
     and erased the two-tone chips entirely. The inset ring gives the same separation. */
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.14);
  transition: transform .16s ease;
}
.dox-theme-sw:hover { transform: scale(1.12); }
.dox-theme-sw:focus-visible { outline: 2px solid #20332f; outline-offset: 3px; }
.dox-theme-sw[data-theme-value="teal"]   { background-color: #0E5F55; --sw-c: #0E5F55; }
.dox-theme-sw[data-theme-value="cobalt"] { background-color: #1D4ED8; --sw-c: #1D4ED8; }
.dox-theme-sw[data-theme-value="citrus"] { background-color: #C2410C; --sw-c: #C2410C; }
/* The dark themes are identified by their accent, so the chip is the accent over the ground
   they actually produce -- recognisable at 26x16 without a label. */
/* The two dark themes show BOTH halves of their identity: the dark ground they paint and the
   accent they use. A single-colour chip could not tell you it was a dark theme at all. */
.dox-theme-sw[data-theme-value="midnight"] {
  background-image: linear-gradient(90deg, #0d1017 0 50%, #5b8cff 50% 100%);
  --sw-c: #5b8cff;
  box-shadow: inset 0 0 0 1px #1b2436, 0 0 0 1px rgba(0,0,0,.25);
}
.dox-theme-sw[aria-checked="true"] {
  /* The white ring was #fff hardcoded, which on a dark theme reads as a bright halo around
     the chip -- the loudest thing on the page. Use the surface it sits on so the ring
     separates the chip without glowing. */
  box-shadow: inset 0 0 0 1px rgba(0,0,0,.10), 0 0 0 2px var(--dox-card, #fff), 0 0 0 4px var(--sw-c, currentColor);
}

@media (max-width: 750px) {
  .dox-theme-sw { width: 18px; height: 18px; }
}
/* ---------- header layout ----------
 * The header holds several children (title, controls, tabs, zoom). theme.js wraps
 * zoom + picker in .dox-header-group so they are ONE flex child and always share
 * a line — otherwise flex-wrap sends the picker to a second row once the header
 * fills, which put it far from zoom at 1024px.
 *
 * style.css gives .app-zoom-controls margin-left:auto to claim the free space.
 * Inside the group that auto margin would push the picker out, so it is reset and
 * the group itself takes the free space. */
.topbar { justify-content: flex-start; gap: 10px; }
#page > .heading { justify-content: flex-start; }
.dox-header-group {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex: none;
}
.dox-header-group .app-zoom-controls { margin-left: 0; margin-right: 0; flex: none; }
.dox-theme-picker--inline { margin: 0; flex: none; }

/* ---------- brand mark ----------
 * Matches the landing page: a rounded square with two white rules, drawn with a
 * pseudo-element so no icon file or extra markup is needed. Sized up for the
 * app's larger chrome (28px) versus the marketing nav (20px). */
.mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: var(--dox-accent);
  color: transparent;
  position: relative;
  flex: none;
  display: inline-block;
  font-size: 0;
  line-height: 0;
  overflow: hidden;
}
.mark::after {
  content: "";
  position: absolute;
  inset: 7px 7px 7px 8px;
  border-top: 2.5px solid #fff;
  border-bottom: 2.5px solid #fff;
  border-radius: 1px;
}
.brand { gap: 10px; }

/* ---------- theme-aware surfaces ----------
 * style.css hardcodes green-greys on these five surfaces. Re-pointing them at the
 * --dox-* surface family makes them follow the accent's hue instead of staying
 * teal. Document CONTENT is deliberately NOT included: .paper, .tiptap and
 * .rich-content read --doc-* from the document's own format, never the theme. */
:root { background: var(--dox-ground); }
.sidebar { border-right-color: var(--dox-line-warm); }
.workspace { border-color: var(--dox-line-stronger); }
.toc { background: var(--dox-surface); border-right-color: var(--dox-line-warm); }
.document-focus .workspace > .toc { background: var(--dox-surface); }

/* A note like the removed sidebar note should read in the current theme, not the
   old green. Kept so the pattern is defined before anything needs it again. */
.side-note {
  background: var(--dox-accent-soft-tint);
  color: var(--dox-accent-soft);
}

/* ---------- history header ----------
 * The scope select used to sit in its own full-width band ABOVE the timeline, so a
 * lone control floated on its own row while the heading it belongs to sat below it.
 * It now lives in the header, right-aligned on the same line as the heading, with
 * the Close button. .history-scope is kept as an inline control group so nothing
 * that still targets that class gets the old band styling. */
.history-header {
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 20px;
}
/* Was `flex: 1 1 320px`, which forced the heading block to claim the full row and
   pushed the toolbar onto a second line. The heading is now a single line (#55), so it
   only needs its natural width. */
/* Must be allowed to SHRINK to zero basis, not just "not grow". With flex-basis:auto
   the heading kept its natural 657px title width; adding the toolbar's 827px exceeded the
   1297px header and the toolbar wrapped to a second line. flex-basis 0 lets the heading
   give up space (the h2 ellipsises) so both stay on one row (#55). */
.history-header > div:first-child { min-width: 0; flex: 1 1 0; }
.history-header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
  flex: none;
}
.history-header-controls label { margin: 0; white-space: nowrap; }
.history-header-controls select {
  width: auto;
  min-width: 210px;
}

/* No band any more: inline group, no padding strip, no bottom rule. */
.history-scope {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0;
  border-bottom: 0;
}

@media (max-width: 760px) {
  .history-header-controls { margin-left: 0; width: 100%; flex-wrap: wrap; }
  .history-header-controls select { min-width: 0; flex: 1 1 160px; }
}

/* ===========================================================================
   Dark theme — "midnight" (blue)
   ---------------------------------------------------------------------------
   style.css hardcodes white surfaces (#fff, #fafbf8, #fefefd) throughout, so a
   dark theme cannot be an accent swap: the surfaces themselves have to move.
   Each dark theme redefines the SAME variables the light themes use, plus a set
   of surface/ink tokens the shell now reads, so one mechanism serves both.

   Deliberately NOT inverted: the document paper (.paper) and the editor canvas
   stay light in both dark themes. A document app whose page turns black is not
   dark mode, it is broken — you cannot proofread a proposal on #111. Only the
   chrome darkens; the page you are writing stays paper.
   =========================================================================== */



:root[data-theme="midnight"] {
  color-scheme: dark;

  --dox-accent:            #5b8cff;
  --dox-accent-soft:       #6d85b8;
  --dox-accent-deep:       #7aa3ff;
  --dox-accent-tint:       #1b2436;
  --dox-accent-soft-tint:  #161d2b;
  --dox-accent-strong:     #2f4368;
  --dox-shadow:            rgba(0, 0, 0, 0.55);
  --dox-shadow-strong:     rgba(0, 0, 0, 0.70);

  --dox-ground:            #0d1017;
  --dox-surface:           #131722;
  --dox-card:              #181d29;
  --dox-dox-raised:        #1f2534;
  --dox-raised:            #1f2534;
  /* Brighter on a dark ground, same role. */
  --id-1: #5b8cff;  --id-2: #2dd4bf;  --id-3: #fbbf24;  --id-4: #a78bfa;
  --id-5: #38bdf8;  --id-6: #fb7185;  --id-7: #a3e635;
  --dox-line-warm:         #262d3d;
  --dox-line-stronger:     #333c50;

  --dox-ink:               #e8edf7;
  --dox-muted:             #919cb1;
  --dox-faint:             #6c7688;

  --dox-paper:             #ffffff;
  --dox-paper-ink:         #20332f;


  /* --accent must be defined per theme (#100): without it every `var(--accent, #teal)`
     chrome rule falls back to teal. Values here are each theme’s own accent, never a
     borrowed hue. Document content keeps its own --accent from the document format. */
  --accent: #5b8cff;
  /* --tint was only defined inside a narrow scope, so 28 `var(--tint, #teal)` rules
     fell back to teal-grey in every theme (#100). Defined here, per theme. */
  --tint: #1f2836;
  --tint-soft: #22314a;
  --accent-ink: #8fb3ff;
  --accent-tint: #22314a;
}
