/* v7 shared web theme (ad-hoc-86 S298).
 *
 * Follows creality's print-manager site (creality/print-manager.git,
 * app/static/css/base.css): its tokens, type, layout and components, cut
 * down to what the v7 shell and module pages use. One stylesheet for the
 * whole site; the core serves it and every page links it.
 *
 * Rules carried over from that site:
 *   - Every color goes through a token, never a hex in a rule, so dark mode
 *     stays correct.
 *   - State is never color alone: a dot or a label always goes with it.
 *   - Accent means "primary action / current location" only; status colors
 *     mean status only.
 *   - Mono for labels, ids and numbers; sans for reading text.
 *   - Flat and bordered: 1px lines, 3px corners, no shadows.
 *   - Honor prefers-reduced-motion.
 *
 * Module pages use only the classes here (they can't add to <head>: the
 * core wraps their content). A new component goes here, not in a module.
 */

@font-face { font-family: 'Plex Mono'; font-weight: 400; font-style: normal; font-display: swap;
  src: url('/static/fonts/plex-mono-400.woff2') format('woff2'); }
@font-face { font-family: 'Plex Mono'; font-weight: 500; font-style: normal; font-display: swap;
  src: url('/static/fonts/plex-mono-500.woff2') format('woff2'); }
@font-face { font-family: 'Plex Mono'; font-weight: 600; font-style: normal; font-display: swap;
  src: url('/static/fonts/plex-mono-600.woff2') format('woff2'); }
@font-face { font-family: 'Public Sans'; font-weight: 400 700; font-style: normal; font-display: swap;
  src: url('/static/fonts/public-sans-var.woff2') format('woff2'); }

/* Light is the default. Dark follows the system; data-theme on <html> can
   force either (nothing sets it yet). Role colors: admin uses the
   print-manager "operator" pair, user the "local" pair. */
:root {
  --paper: #eef1ee;
  --paper-raised: #ffffff;
  --paper-sunken: #e3e8e3;
  --ink: #1a2733;
  --ink-dim: #55636d;
  --ink-faint: #85939c;
  --line: #c6d0c9;
  --line-strong: #1a2733;
  --accent: #c65d2e;
  --accent-ink: #fff8f4;
  --focus: #0e7c86;
  --role-admin: #3e5c76;
  --role-admin-bg: #e3e9ef;
  --role-user: #2f8f63;
  --role-user-bg: #e2f0e8;
  --good: #2f8f63;
  --warn: #b8863e;
  --bad: #b23b3b;
  --radius: 3px;
  --mono: 'Plex Mono', ui-monospace, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #101820;
    --paper-raised: #172029;
    --paper-sunken: #0b1116;
    --ink: #e7ebe6;
    --ink-dim: #99a6ad;
    --ink-faint: #64717a;
    --line: #2b363f;
    --line-strong: #cfd8d2;
    --accent: #e8824c;
    --accent-ink: #171009;
    --focus: #3fc2cd;
    --role-admin: #86a8cc;
    --role-admin-bg: #1c2733;
    --role-user: #6fca9d;
    --role-user-bg: #142720;
    --good: #6fca9d;
    --warn: #d4a668;
    --bad: #e07a7a;
  }
}
:root[data-theme="dark"] {
  --paper: #101820;
  --paper-raised: #172029;
  --paper-sunken: #0b1116;
  --ink: #e7ebe6;
  --ink-dim: #99a6ad;
  --ink-faint: #64717a;
  --line: #2b363f;
  --line-strong: #cfd8d2;
  --accent: #e8824c;
  --accent-ink: #171009;
  --focus: #3fc2cd;
  --role-admin: #86a8cc;
  --role-admin-bg: #1c2733;
  --role-user: #6fca9d;
  --role-user-bg: #142720;
  --good: #6fca9d;
  --warn: #d4a668;
  --bad: #e07a7a;
}

* { box-sizing: border-box; }
/* Author display: rules beat the browser's [hidden] otherwise. */
[hidden] { display: none !important; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Public Sans', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
.mono { font-family: var(--mono); }
.dim { color: var(--ink-dim); }
.num { font-variant-numeric: tabular-nums; }
.eyebrow {
  font-family: var(--mono); font-size: 0.6875rem; font-weight: 500;
  letter-spacing: 0.09em; text-transform: uppercase; color: var(--ink-dim);
}
h1, h2, h3 { text-wrap: balance; margin: 0; }
button { font: inherit; color: inherit; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }

/* ---- shell: topbar, tabs, main --------------------------------------- */
.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: 56px auto 1fr;
  grid-template-areas: "top" "rail" "main";
  min-height: 100vh;
}
.topbar {
  grid-area: top; display: flex; align-items: center; gap: 20px; padding: 0 20px;
  background: var(--paper-raised); border-bottom: 1px solid var(--line);
}
.wordmark { font-family: var(--mono); font-weight: 600; font-size: 0.9375rem; text-decoration: none; }
.wordmark .dim { font-weight: 500; }
/* The build mark: the quietest thing in the topbar, findable when looked
   for (after print-manager). Shown at every width (operator S298). */
.topbar .buildmark { font-family: var(--mono); font-size: 9.5px; letter-spacing: 0.04em;
  color: var(--ink-faint); opacity: 0.55; cursor: default; white-space: nowrap; }
.topbar .buildmark:hover { opacity: 1; }
.topbar-spacer { flex: 1; }
.userpill { font-size: 0.8125rem; color: var(--ink-dim); display: flex; align-items: center; gap: 10px; }
.userpill form { margin: 0; }
.userpill button {
  border: 1px solid var(--line); background: transparent; color: var(--ink-dim);
  padding: 5px 10px; border-radius: var(--radius); cursor: pointer; font-size: 0.75rem;
}
/* Tabs at every width; they scroll rather than wrap. */
.rail {
  grid-area: rail; display: flex; min-width: 0;
  background: var(--paper-raised); border-bottom: 1px solid var(--line); padding: 8px 34px 0;
}
.rail nav { display: flex; gap: 6px; overflow-x: auto; min-width: 0; }
.rail a.navlink {
  flex: none; white-space: nowrap; text-decoration: none; padding: 9px 12px;
  border-radius: var(--radius) var(--radius) 0 0; font-size: 0.875rem; color: var(--ink);
  border-bottom: 2px solid transparent;
}
.rail a.navlink:hover { background: var(--paper-sunken); }
.rail a.navlink.current { background: var(--paper-sunken); border-bottom-color: var(--accent); font-weight: 600; }
main.screen-wrap { grid-area: main; min-width: 0; padding: 26px 34px 60px; }
@media (max-width: 900px) {
  .rail { padding: 8px 12px 0; }
  .topbar { gap: 10px; padding: 0 12px; }
  .wordmark .dim { display: none; }
  main.screen-wrap { padding: 20px 16px 40px; }
}
@media (max-width: 560px) { main.screen-wrap { padding: 18px 14px 40px; } }

.titleblock {
  display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap;
  border-bottom: 1px solid var(--line); padding-bottom: 14px; margin-bottom: 22px;
}
.titleblock h1 { font-size: 1.375rem; font-weight: 700; }
.titleblock .purpose { color: var(--ink-dim); font-size: 0.875rem; }
.rolebadge {
  font-family: var(--mono); font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.05em;
  text-transform: uppercase; padding: 3px 8px; border-radius: 999px;
  background: var(--paper-sunken); color: var(--ink-dim);
}
.rolebadge.admin { background: var(--role-admin-bg); color: var(--role-admin); }
.rolebadge.user { background: var(--role-user-bg); color: var(--role-user); }

/* ---- components -------------------------------------------------------- */
.panel {
  background: var(--paper-raised); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px;
}
.panel + .panel { margin-top: 14px; }
.panel h3 { font-size: 0.9375rem; font-weight: 600; margin-bottom: 10px; }
.row { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.row.tight { gap: 8px; align-items: center; }
.row.end { align-items: flex-end; }
.actions { margin-top: 10px; }
.actions-top { margin-bottom: 14px; }

.chip {
  display: inline-flex; align-items: center; gap: 5px; white-space: nowrap;
  font-family: var(--mono); font-size: 0.6875rem; font-weight: 500;
  padding: 3px 8px; border-radius: 999px; background: var(--paper-sunken); color: var(--ink-dim);
}
.chip.good { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.chip.warn { background: color-mix(in srgb, var(--warn) 18%, transparent); color: var(--warn); }
.chip.bad { background: color-mix(in srgb, var(--bad) 18%, transparent); color: var(--bad); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }

.banner {
  display: flex; align-items: center; gap: 10px; margin-bottom: 14px;
  border: 1px solid var(--warn); background: color-mix(in srgb, var(--warn) 14%, var(--paper-raised));
  border-radius: var(--radius); padding: 12px 14px; font-size: 0.875rem; font-weight: 600;
}
.banner .dot { background: var(--warn); }
.banner.good { border-color: var(--good); background: color-mix(in srgb, var(--good) 14%, var(--paper-raised)); }
.banner.good .dot { background: var(--good); }
.banner.bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 14%, var(--paper-raised)); }
.banner.bad .dot { background: var(--bad); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line-strong); background: var(--ink); color: var(--paper);
  padding: 9px 14px; border-radius: var(--radius); font-size: 0.8125rem; font-weight: 600;
  cursor: pointer; text-decoration: none;
}
.btn.accent { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.sm { padding: 5px 10px; font-size: 0.75rem; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; }

/* Form fields: mono uppercase label over a bordered control. */
.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.field label, label.eyebrow-label {
  font-family: var(--mono); font-size: 0.6875rem; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--ink-dim);
}
.field input, .field textarea, .field select {
  font: inherit; color: var(--ink); background: var(--paper-raised);
  border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 10px; width: 100%;
}
.field textarea { min-height: 7em; resize: vertical; }
.field .hint { font-size: 0.8125rem; color: var(--ink-dim); }
.field + .field { margin-top: 12px; }
fieldset.field { border: 0; padding: 0; margin: 0; }
fieldset.field legend { padding: 0; margin-bottom: 4px; }
.checks { display: flex; flex-wrap: wrap; gap: 6px 16px; }
label.check { display: inline-flex; align-items: center; gap: 6px; font-size: 0.875rem; cursor: pointer; }
label.check input { accent-color: var(--accent); width: auto; }

/* Dense data table with rules between rows. */
table.data { width: 100%; border-collapse: collapse; font-size: 0.8125rem; }
table.data th {
  text-align: left; font-family: var(--mono); font-size: 0.6875rem; font-weight: 500;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-dim);
  padding: 6px 10px; border-bottom: 1px solid var(--line);
}
table.data td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tr:last-child td { border-bottom: 0; }
table.data a { font-weight: 600; }
@media (max-width: 640px) { table.data .wide-only { display: none; } }

/* Feed: a run of entries, each a meta line over a body (chat messages). */
.feed { display: flex; flex-direction: column; }
.feed .entry { padding: 10px 0; border-bottom: 1px solid var(--line); }
.feed .entry:first-child { padding-top: 0; }
.feed .entry:last-child { border-bottom: 0; padding-bottom: 0; }
.feed .meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; font-size: 0.8125rem; margin-bottom: 4px; }
.feed .meta .who { font-weight: 600; }
.feed .meta .when { font-family: var(--mono); font-size: 0.6875rem; color: var(--ink-faint); }
.feed .body { white-space: pre-wrap; overflow-wrap: anywhere; max-width: 80ch; }

/* Rendered markdown (chat message bodies). Overrides .feed .body's
   pre-wrap: the renderer already turned line structure into elements, and
   the newlines it leaves between them would show as blank lines (S298;
   .feed .body.prose so it outranks .feed .body). */
.prose, .feed .body.prose { white-space: normal; }
.prose > :first-child { margin-top: 0; }
.prose > :last-child { margin-bottom: 0; }
.prose p, .prose ul, .prose ol, .prose pre, .prose blockquote, .prose table { margin: 0 0 6px; }
.prose ul, .prose ol { padding-left: 22px; }
.prose li + li { margin-top: 2px; }
.prose h1, .prose h2, .prose h3, .prose h4 { font-size: 0.9375rem; font-weight: 700; margin: 12px 0 6px; }
.prose a { text-decoration: underline; }
.prose code { font-family: var(--mono); font-size: 0.8125rem; background: var(--paper-sunken);
  padding: 1px 4px; border-radius: var(--radius); }
.prose pre { background: var(--paper-sunken); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 12px; overflow-x: auto; }
.prose pre code { background: none; padding: 0; }
.prose blockquote { border-left: 2px solid var(--line-strong); padding-left: 12px; color: var(--ink-dim); }
.prose table { border-collapse: collapse; font-size: 0.8125rem; display: block; overflow-x: auto; }
.prose th, .prose td { border: 1px solid var(--line); padding: 4px 8px; text-align: left; }
.prose hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }

.back { display: inline-block; font-size: 0.8125rem; color: var(--ink-dim); margin-bottom: 14px; }
.empty { color: var(--ink-dim); }

/* ---- login ------------------------------------------------------------- */
.loginwrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.loginbox { width: 320px; max-width: 100%; }
.loginbox .wordmark { display: block; font-size: 1.125rem; margin-bottom: 18px; text-align: center; }
.loginbox .field { margin: 0 0 14px; }
.loginbox .btn { width: 100%; justify-content: center; }
.loginerror { color: var(--bad); font-size: 0.8125rem; margin-bottom: 12px; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
