/* ==========================================================================
   "Auto" skin: one skin that follows the OS light/dark preference.

   How it works
   - `color-scheme: light dark` + the CSS light-dark() function: every colour
     token below is written once as light-dark(<light>, <dark>), and the
     browser picks the right half from the user's OS setting.
   - The header's toggle button can pin Light or Dark (stored in
     localStorage); that just sets <html data-theme="light|dark">, which
     forces color-scheme and therefore every light-dark() token.
   - --inv is 0 in light mode and 1 in dark mode. It drives `filter: invert()`
     for content whose colours Fossil bakes in server-side (timeline graph
     rails, pikchr diagrams), so they stay legible in both modes.
   - Fossil's own default.css is loaded before this file; rules here override
     the colours it hard-codes.
   ========================================================================== */

:root {
  color-scheme: light dark;
  --inv: 0;

  --bg:          light-dark(#f8f8f6, #131518);
  --surface:     light-dark(#ffffff, #1b1e22);
  --surface-2:   light-dark(#f0f1f3, #23272c);
  --surface-3:   light-dark(#e6e8eb, #2c3137);
  --fg:          light-dark(#1d2126, #e2e5e9);
  --muted:       light-dark(#626a73, #98a1ab);
  --border:      light-dark(#d9dce0, #32373e);
  --border-soft: light-dark(#e8eaed, #272b30);

  --accent:      light-dark(#1f6f8b, #6cc0e0);
  --accent-soft: light-dark(#e1f0f5, #16323d);
  --on-accent:   light-dark(#ffffff, #0b1216);
  --link:        light-dark(#17607a, #79c7e6);
  --link-visited:light-dark(#5b4a8a, #b6a6e8);

  --danger:      light-dark(#b42318, #ff8c82);
  --warn-bg:     light-dark(#fff4c2, #3b3214);
  --warn-fg:     light-dark(#5c4400, #f3d77a);
  --ok:          light-dark(#1a7f37, #6fd08c);

  --sel-bg:      light-dark(#fff6bf, #3a3417);
  --sel-border:  light-dark(#e3c84c, #8a7a2c);
  --second-bg:   light-dark(#d9f4f4, #153a3c);

  --ins-bg:      light-dark(#dafbe1, #13301d);
  --ins-strong:  light-dark(#a0e4b2, #1f5a33);
  --del-bg:      light-dark(#ffe8e8, #3a1a1d);
  --del-strong:  light-dark(#ffc0c0, #6e2930);
  --edit-bg:     light-dark(#d4d4ff, #34396e);

  /* Darkening veil laid over Fossil's server-computed pastel backgrounds
     (branch-coloured timeline rows, tags, etc.) in dark mode. */
  --veil:        light-dark(transparent, rgb(19 21 24 / 0.72));

  --radius: 8px;
  --mono: ui-monospace, "SF Mono", "Cascadia Code", "JetBrains Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --inv: 1; }
}
:root[data-theme="light"] { color-scheme: light; --inv: 0; }
:root[data-theme="dark"]  { color-scheme: dark;  --inv: 1; }

/* ---------- Base ---------------------------------------------------------- */
html { background: var(--bg); }
body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
a, a:link       { color: var(--link); text-decoration: none; }
a:visited       { color: var(--link-visited); }
a:hover         { text-decoration: underline; }
hr              { border: 0; border-top: 1px solid var(--border); }
code, kbd, pre, tt, samp, textarea { font-family: var(--mono); font-size: 0.92em; }
pre, .verbatim  {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 0.6em 0.8em;
  overflow-x: auto;
}
blockquote, .markdown blockquote, p.blockquote, .sidebar {
  background: var(--surface-2);
  border-left: 3px solid var(--border);
  margin-left: 0;
  padding: 0.4em 1em;
}
input, select, textarea, button {
  font: inherit;
  color: var(--fg);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.25em 0.5em;
}
input[type="submit"], input[type="button"], button {
  cursor: pointer;
  background: var(--surface-2);
}
input[type="submit"]:hover, input[type="button"]:hover, button:hover {
  border-color: var(--accent);
}
input[type="checkbox"], input[type="radio"] { accent-color: var(--accent); }
table { border-color: var(--border); }
::selection { background: var(--accent-soft); }

/* ---------- Header -------------------------------------------------------- */
.site-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.6rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.brand-home {
  display: inline-grid;
  place-items: center;
  width: 34px; height: 34px;
  border-radius: var(--radius);
  color: var(--on-accent) !important;
  background: var(--accent);
  flex: none;
}
.brand-home:hover { text-decoration: none; filter: brightness(1.1); }
.repo-current { font-weight: 650; font-size: 1.1rem; white-space: nowrap; }
.page-title-wrap { flex: 1; min-width: 0; }
.page-title {
  color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block;
}
.status { display: flex; align-items: center; gap: 0.75rem; flex: none; }
.status .login { color: var(--muted); }

/* Repository switcher (populated by js.txt from the server's repo list) */
.repo-switch { position: relative; flex: none; }
.repo-switch > summary {
  list-style: none;
  display: flex; align-items: center; gap: 0.4rem;
  cursor: pointer;
  padding: 0.25rem 0.55rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
}
.repo-switch > summary::-webkit-details-marker { display: none; }
.repo-switch > summary:hover, .repo-switch[open] > summary {
  background: var(--surface-2);
  border-color: var(--border);
}
.repo-switch .caret {
  width: 0; height: 0;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid var(--muted);
}
.repo-menu {
  position: absolute; z-index: 50;
  top: calc(100% + 6px); left: 0;
  min-width: 260px;
  padding: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px light-dark(rgb(0 0 0 / 0.12), rgb(0 0 0 / 0.5));
}
.repo-menu a {
  display: block;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  color: var(--fg) !important;
}
.repo-menu a:hover { background: var(--surface-2); text-decoration: none; }
.repo-menu a.current { background: var(--accent-soft); }
.repo-menu a small { display: block; color: var(--muted); font-size: 0.82em; }
.repo-menu .repo-all {
  margin-top: 0.3rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-soft);
  border-radius: 0;
  color: var(--link) !important;
}
.repo-menu .repo-all:first-child { margin-top: 0; border-top: 0; padding-top: 0.4rem; }

/* Theme menu: the button shows the current mode's icon; the menu offers
   System (follow the OS), Light and Dark. */
/* Fixed-size wrapper + block-level summary: the open menu floats over the
   page and never affects the header's layout. */
.theme-menu { position: relative; flex: none; width: 32px; height: 32px; }
.theme-toggle {
  display: grid; place-items: center;
  box-sizing: border-box;
  width: 32px; height: 32px; padding: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
  list-style: none;
}
.theme-toggle::-webkit-details-marker { display: none; }
.theme-toggle:hover, .theme-menu[open] > .theme-toggle { color: var(--fg); background: var(--surface-2); }
.theme-toggle svg { display: none; }
:root:not([data-theme]) .theme-toggle .i-auto,
:root[data-theme="light"] .theme-toggle .i-light,
:root[data-theme="dark"]  .theme-toggle .i-dark { display: block; }
.theme-options {
  position: absolute; z-index: 50;
  top: calc(100% + 6px); right: 0;
  min-width: 150px;
  padding: 0.35rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px light-dark(rgb(0 0 0 / 0.12), rgb(0 0 0 / 0.5));
}
.theme-options button {
  display: flex; align-items: center; gap: 0.6rem;
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--fg);
  text-align: left;
}
.theme-options button:hover { background: var(--surface-2); }
.theme-options button svg { color: var(--muted); flex: none; }
.theme-options button span { flex: 1; }
.theme-options button[aria-checked="true"] { background: var(--accent-soft); }
.theme-options button[aria-checked="true"]::after {
  /* checkmark drawn with borders, so it never depends on font glyphs */
  content: "";
  width: 5px; height: 10px;
  margin: 0 3px 3px 0;
  border: solid var(--accent);
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* ---------- Main menu ----------------------------------------------------- */
.mainmenu {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.15rem;
  padding: 0.35rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.mainmenu a {
  padding: 0.3rem 0.7rem;
  border-radius: 6px;
  color: var(--muted) !important;
}
.mainmenu a:hover { background: var(--surface-2); color: var(--fg) !important; text-decoration: none; }
.mainmenu a.active { background: var(--accent-soft); color: var(--accent) !important; font-weight: 600; }
/* Sitemap ("hamburger") button: draw the three bars in CSS rather than
   relying on the U+2630 glyph being present in the user's fonts. */
#hbbtn { font-size: 0; display: inline-flex; align-items: center; min-height: 1.5rem; }
#hbbtn::before {
  content: "";
  width: 16px; height: 12px;
  background:
    linear-gradient(currentColor 0 0) top    / 100% 2px no-repeat,
    linear-gradient(currentColor 0 0) center / 100% 2px no-repeat,
    linear-gradient(currentColor 0 0) bottom / 100% 2px no-repeat;
}
.hbdrop {
  display: none;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0.5rem 1.25rem;
}
.hbdrop a { color: var(--link); }

/* ---------- Content area -------------------------------------------------- */
.content { padding: 1rem 1.25rem 2rem; max-width: 1400px; }
.content > h1.page-title { display: none; }
h1, h2, h3, h4 { line-height: 1.25; }
.submenu {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.5rem;
  padding: 0.45rem 1.25rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 0.92em;
}
.submenu a, .submenu label { color: var(--fg); }
.submenu a {
  padding: 0.15rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
}
.submenu a:hover { border-color: var(--accent); text-decoration: none; }
.submenu select, .submenu input { padding: 0.1rem 0.35rem; }
.site-footer {
  padding: 1rem 1.25rem;
  color: var(--muted);
  font-size: 0.8em;
  border-top: 1px solid var(--border-soft);
}
div.sidebox, .sidebox { background: var(--surface); border-color: var(--border); }

/* ---------- Timeline ------------------------------------------------------ */
.timelineDate, .timelineDateCell {
  color: var(--muted);
  font-weight: 600;
}
.timelineDateCell { border-bottom: 1px solid var(--border-soft); }
.timelineTable { border-spacing: 0; }
.timelineModernCell, .timelineColumnarCell, .timelineDetailCell,
.timelineCompactCell, .timelineVerboseCell {
  border-radius: var(--radius);
}
.timelineModernCell[id], .timelineColumnarCell[id], .timelineDetailCell[id] {
  background-color: var(--surface-2);
}
.timelineSelected {
  background-color: var(--sel-bg) !important;
  border: 1px solid var(--sel-border);
}
.timelineSecondary { background-color: var(--second-bg) !important; }
tr.timelineCurrent { border: 1px dashed var(--accent); }
.timelineHistDsp, .timelineDetail, .timelineModernDetail,
.timelineDetailCell, .timelineCompactDetail { color: var(--muted); }
span.timelineLeaf, .timelineLeaf { color: var(--ok); }
.timelineTime, .timelineTimeCell { color: var(--muted); font-family: var(--mono); font-size: 0.88em; }
.tl-tooltip { background: var(--surface); color: var(--fg); border: 1px solid var(--border); border-radius: 6px; }

/* Graph rails/nodes: Fossil draws them in black with server-computed branch
   colours tuned for a light page. In dark mode, invert + hue-rotate keeps
   each branch's hue while flipping its lightness. */
.tl-canvas { filter: invert(var(--inv)) hue-rotate(calc(var(--inv) * 180deg)); }

/* Server-computed pastel backgrounds (timeline rows coloured by branch,
   tagged check-ins, ticket rows, ...) arrive as inline styles. In dark mode
   lay a translucent veil over them: the hue survives, the glare does not. */
[style*="background-color"]:not(.tl-canvas *):not(.tl-canvas):not(tr),
tr[style*="background-color"] > td {
  box-shadow: inset 0 0 0 100vmax var(--veil);
}
td[bgcolor], tr[bgcolor] > td { box-shadow: inset 0 0 0 100vmax var(--veil); }

/* ---------- Diffs ---------------------------------------------------------- */
table.diff { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
/* Same text size and line spacing as the file view (table.numbered-lines).
   Fossil's default CSS shrinks diffs to 80%, and the generic pre rule above
   would shrink them again. The line-number, separator and text columns are
   separate <pre>s, so all of them get the same metrics to stay aligned. */
table.diff { font-size: 0.88em; }
table.diff pre { font-size: inherit; line-height: 1.35; }
td.diffln ins, td.difftxt ins > ins { background-color: var(--ins-strong); }
td.diffln del, td.difftxt del > del { background-color: var(--del-strong); }
td.difftxt ins { background-color: var(--ins-bg); }
td.difftxt del { background-color: var(--del-bg); }
td.difftxt del > del.edit, td.difftxt ins > ins.edit { background-color: var(--edit-bg); }
td.diffln, td.diffsep { color: var(--muted); }
tr.diffskip.jchunk { background-color: var(--accent-soft); }
tr.diffskip { color: var(--muted); }
.diff ins, .diff del { color: inherit; }
/* File header above each diff. Fossil's JS adds a "show/hide" <label> and
   makes clicks on the description <span> (but not its links) toggle the
   diff. Lay it out as /vdiff does, with the label filling the rest of the
   row, so the whole row except the links is the toggle, and show that on
   hover. Rows without the label (e.g. /fdiff) aren't toggles. */
div.file-change-line {
  display: flex;
  align-items: baseline;
  gap: 1em;
  padding: 0.25em 0.5em;
  border-radius: var(--radius);
}
div.file-change-line:has(> label) > :is(span, label) { cursor: pointer; }
div.file-change-line:has(> label):has(> span:hover, > label:hover):not(:has(a:hover)) {
  background: var(--surface-2);
}

/* ---------- File views, tables, misc -------------------------------------- */
.filetree li li:before, .filetree li > ul:before { border-color: var(--border); }
div.filetreeline:hover, .fileage tr:hover { background-color: var(--surface-2); }
.fileage td { border-top: 1px solid var(--border-soft); }
/* Line-numbered file view: Fossil aligns the number column and the code
   column by giving both identical font metrics (everything "inherit"). Set
   the size once on the table and undo the generic pre/code box styling on
   the inner <pre>s, or the columns drift apart line by line. */
table.numbered-lines {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
}
table.numbered-lines td > pre,
table.numbered-lines td > pre > code {
  font-size: inherit;
  border: 0;
  border-radius: 0;
  background: transparent;
}
/* Fossil wraps file contents in <blockquote class="file-content">; it's not
   a quotation, so drop the quote styling. */
blockquote.file-content { background: none; border: 0; padding: 0; margin: 1em 0; }
table.numbered-lines td.line-numbers { color: var(--muted); border-right: 1px solid var(--border-soft); }
table.numbered-lines td.line-numbers span.selected-line {
  color: var(--accent); background-color: var(--accent-soft); border-color: var(--accent);
}
table.report, table.sortable, .brlist table, table.label-value {
  border-collapse: collapse;
  border: 1px solid var(--border);
}
table.report th, table.sortable th { background: var(--surface-2); color: var(--fg); }
th.sort:after { text-shadow: none; color: var(--muted); }
th.sort.none:after { content: "\2191\2193"; letter-spacing: -0.15em; opacity: 0.55; }
th.nosort { pointer-events: none; }
th.nosort:after { content: none !important; }
th.sort.asc:after, th.sort.desc:after { color: var(--accent); }
table.report td, table.sortable td, .brlist td { border-color: var(--border-soft); }
body.branch .brlist > table > tbody > tr:hover:not(.selected),
body.branch .brlist > table > tbody > tr.selected { background-color: var(--sel-bg); }
td.tktDspValue { background-color: var(--surface-2); }
td.tktTlOpen { color: var(--danger); }
td.tktTlClosed { color: var(--muted); }
span.forum_author, span.forum_age, span.forum_npost, span.forum_buttons::before { color: var(--muted); }
div.forumSel { background-color: var(--accent-soft); }
div.forumObs { color: var(--muted); }
div.forumEdit, div.forumTimeline, div.forumTime { border-color: var(--border); }
.forum-post-collapser { border-color: var(--border); background-color: var(--surface-2); }
.capsumOff   { background-color: var(--surface-3); }
.capsumRead  { background-color: var(--ins-strong); }
.capsumWrite { background-color: var(--warn-bg); }
.error, .fossil-toast-message.error { color: var(--danger); background: var(--warn-bg); }
.warning, .fossil-toast-message.warning { color: var(--warn-fg); background: var(--warn-bg); }
.debug { background-color: var(--warn-bg); border-color: var(--sel-border); }
span.disabled, span.wikiError, span.loginError, span.tktError, p.generalError,
p.reportError, span.brokenlink, pre.th1error, span.thTrace { color: var(--danger); }
span.modpending { color: var(--warn-fg); }
p.missingPriv, p.noMoreShun, p.shunned { color: var(--link); }
.statistics-report-graph-line { border-color: var(--accent); background-color: var(--accent); }
.statistics-report-graph-extra { border-color: var(--accent); }
.fossil-tooltip { background: var(--surface); color: var(--fg); border-color: var(--border); }
.tabs .tab-bar > .tab-button, .tab-bar button { background: var(--surface-2); color: var(--fg); }
.tabs .tab-bar > .tab-button.selected, .tab-bar button.selected { background: var(--accent-soft); }
div.markdown ol.footnotes > li.fn-joined > sup.fn-joined { color: var(--muted); }

/* Pikchr diagrams are rendered black-on-transparent; flip them in dark mode. */
svg.pikchr { filter: invert(var(--inv)) hue-rotate(calc(var(--inv) * 180deg)); }

/* Images in wiki/docs keep their own colours. */
.markdown img, .wiki img { background: transparent; }

/* ---------- Repository list (served at the server root) ------------------- */
body.repolist .content { max-width: 1100px; margin: 0 auto; }
.repolist-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.repolist-table th {
  text-align: left;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border);
}
.repolist-table td {
  padding: 0.65rem 0.9rem;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}
body.repolist .repo-links a {
  display: inline-block;
  margin: 0 0.35rem 0.2rem 0;
  padding: 0.1rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.85em;
  color: var(--fg);
  background: var(--surface);
}
body.repolist .repo-links a:hover { border-color: var(--accent); text-decoration: none; }
body.repolist td.repo-name a { font-weight: 600; }
body.repolist td.repo-name small { display: block; color: var(--muted); font-family: var(--mono); font-size: 0.8em; }
.repolist-table tr:last-child td { border-bottom: 0; }
.repolist-table tbody tr:hover td { background: var(--surface-2); }

/* ---------- Small screens -------------------------------------------------- */
@media (max-width: 700px) {
  .site-header { padding: 0.5rem 0.75rem; gap: 0.5rem; }
  .page-title-wrap { display: none; }
  .brand { flex: 1; }
  .content { padding: 0.75rem; }
  .mainmenu { padding: 0.3rem 0.5rem; }
  .repo-menu { min-width: min(260px, calc(100vw - 24px)); }
}
