/* The Dynamo - app shell. Brand palette from www.cogmachina.com.
   ASCII only (RB charset notes). */

:root {
  --ink-0: #0c0e12;
  --ink-1: #12151c;
  --ink-2: #1a1e28;
  --ink-3: #242a37;
  --text-hi: #eef0f4;
  --text-mid: #a8afbd;
  --text-low: #6b7280;
  /* Brand accent follows Cog Machina's gold identity. */
  --accent: #d7a765;
  --accent-hi: #f1c88f;
  --accent-dim: rgba(215, 167, 101, 0.14);
  --on-accent: #06131f;  /* text on a filled accent surface */
  /* Legacy aliases - existing rules still say --brass*. */
  --brass: var(--accent);
  --brass-hi: var(--accent-hi);
  --brass-dim: var(--accent-dim);
  /* Estate brand colours (owner, 2026-10-10) - the site selector, estate chips and anything that
     names an estate wear its own: Cog Machina gold, DamagePort seafoam (its --mint-2), Ravenbreath crimson. */
  --brand-cogmachina: #d7a765;
  --brand-damageport: #63cdb1;
  --brand-ravenbreath: #dc143c;
  --good: #5fbf7d;
  --warn: #e0a53f;
  --radius: 10px;
  --font-head: "Space Grotesk", "Segoe UI", system-ui, sans-serif;
  --font-body: "Inter", "Segoe UI", system-ui, sans-serif;
  --font-mono: "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--ink-0); color: var(--text-mid);
  font-family: var(--font-body); font-size: 15px; line-height: 1.55;
}

/* ONE scrollbar, app-wide (owner, 2026-10-10: "all scrollbars app-wide should match"): the window, the
   sidebar, sticky columns, tables and every textarea / select list draw the same thin dark bar. color-scheme
   dark also stops form controls (textareas, date pickers) falling back to light native chrome. */
:root { color-scheme: dark; --scroll-thumb: #3a4252; }
* { scrollbar-width: thin; scrollbar-color: var(--scroll-thumb) transparent; }
html { scrollbar-color: var(--scroll-thumb) var(--ink-0); }
/* A text box grows to fit what is in it - never a scrollbar inside the page's scrollbar. */
textarea { field-sizing: content; overflow: hidden; }

a { color: var(--brass-hi); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }

h1, h2 { font-family: var(--font-head); color: var(--text-hi); letter-spacing: -0.01em; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.02rem; margin-bottom: 12px; }

/* ---------- shell ---------- */

.shell { display: flex; flex-direction: column; min-height: 100vh; }
.shell-body { display: grid; grid-template-columns: 220px 1fr; flex: 1 1 auto; }

/* The sticky top bar: logo, the site selector (which estate every page shows), who is signed in. */
.topbar {
  position: sticky; top: 0; z-index: 40; height: 56px;
  display: flex; align-items: center; gap: 28px; padding: 0 22px;
  background: var(--ink-1); border-bottom: 1px solid var(--ink-3);
}
.topbar .brand { padding: 0; }
.site-switch { display: flex; align-items: stretch; gap: 2px; height: 100%; }
.site-switch a {
  display: flex; align-items: center; padding: 0 16px; color: var(--text-mid);
  font-family: var(--font-head); font-weight: 600; font-size: 0.9rem; letter-spacing: 0.01em;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.site-switch a:hover { color: var(--text-hi); text-decoration: none; }
.site-switch a.on { color: var(--brass-hi); border-bottom-color: var(--brass); }
/* Each estate tab wears its brand colour, always; the underline marks the one in view. */
.site-switch a.estate-cogmachina  { color: var(--brand-cogmachina); }
.site-switch a.estate-damageport  { color: var(--brand-damageport); }
.site-switch a.estate-ravenbreath { color: var(--brand-ravenbreath); }
.site-switch a.estate-cogmachina.on  { border-bottom-color: var(--brand-cogmachina); }
.site-switch a.estate-damageport.on  { border-bottom-color: var(--brand-damageport); }
.site-switch a.estate-ravenbreath.on { border-bottom-color: var(--brand-ravenbreath); }
.site-switch a[class*="estate-"]:hover { filter: brightness(1.2); }
.topbar-who { margin-left: auto; display: flex; align-items: baseline; gap: 14px; font-size: 0.85rem; }
.topbar-who .who { color: var(--text-hi); font-weight: 600; }

/* The sidebar's BACKGROUND runs the full page height (it stretches with the grid row); the MENU inside it is
   sticky and, when taller than the window, travels with the page until its end shows (assets/js/ui.sticky.js).
   Never a scrollbar of its own (owner, 2026-10-10: "NEVER a double scrollbar"). */
.side {
  background: var(--ink-1); border-right: 1px solid var(--ink-3);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 22px;
}
.side > nav { position: sticky; top: 76px; }
.brand { display: flex; align-items: center; gap: 9px; color: var(--text-hi); padding: 2px 8px; }
.brand:hover { text-decoration: none; }
.brand svg { width: 24px; height: 24px; color: var(--brass); flex: none; }
.brand span { font-family: var(--font-head); font-weight: 700; font-size: 0.98rem; }
.brand b { color: var(--brass); }

.side nav { display: grid; gap: 2px; }
.side nav a {
  color: var(--text-mid); padding: 9px 10px; border-radius: 8px; font-size: 0.94rem;
}
.side nav a:hover { color: var(--text-hi); background: var(--ink-2); text-decoration: none; }
.side nav a.on { color: var(--brass-hi); background: var(--brass-dim); font-weight: 600; }

.side-foot { margin-top: auto; padding: 0 10px; font-size: 0.85rem; display: grid; gap: 2px; }
.side-foot .who { color: var(--text-hi); font-weight: 600; }

.main { padding: 30px 34px 60px; }   /* full width on every page (owner, 2026-10-10) */

.page-top { margin-bottom: 24px; }
.page-top p { color: var(--text-low); margin-top: 4px; }
.page-top h1 .chip { vertical-align: middle; margin-left: 8px; }

/* ---------- tiles ---------- */

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 26px; }
.tile { background: var(--ink-2); border: 1px solid var(--ink-3); border-radius: var(--radius); padding: 16px 18px; }
.tile-n {
  font-family: var(--font-head); font-weight: 700; font-size: 1.5rem; color: var(--text-hi);
  font-variant-numeric: tabular-nums;
}
.tile-l { font-size: 0.82rem; color: var(--text-low); margin-top: 2px; }

/* ---------- panels & tables ---------- */

.panel {
  background: var(--ink-2); border: 1px solid var(--ink-3); border-radius: var(--radius);
  padding: 20px 22px; margin-bottom: 20px; overflow-x: auto;
}
.panel .empty { color: var(--text-low); font-size: 0.9rem; }
.panel > p { font-size: 0.94rem; }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th {
  font-family: var(--font-head); font-size: 0.72rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.09em; color: var(--text-low);
  text-align: left; padding: 6px 12px 8px; border-bottom: 1px solid var(--ink-3);
  white-space: nowrap;
}
td { padding: 10px 12px; border-bottom: 1px solid rgba(36, 42, 55, 0.6); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
td .sub { color: var(--text-low); font-size: 0.84rem; margin-top: 3px; max-width: 480px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: var(--font-mono); font-size: 0.85rem; }

/* ---------- chips ---------- */

.chip {
  display: inline-block; font-family: var(--font-head); font-size: 0.72rem; font-weight: 600;
  letter-spacing: 0.05em; text-transform: uppercase;
  padding: 2px 10px; border-radius: 999px; border: 1px solid transparent;
}
.chip-ok   { color: var(--good); border-color: var(--good); background: rgba(95, 191, 125, 0.1); }
.chip-mid  { color: var(--brass-hi); border-color: var(--brass); background: var(--brass-dim); }
.chip-warn { color: var(--warn); border-color: var(--warn); background: rgba(224, 165, 63, 0.12); }
.chip-off  { color: var(--text-low); border-color: var(--ink-3); background: var(--ink-1); }

/* ---------- pricing editor ---------- */

td .hi { color: var(--text-hi); font-weight: 600; }
.cur { color: var(--text-low); margin-right: 2px; font-size: 0.85rem; }
input.money {
  width: 92px; background: var(--ink-0); border: 1px solid var(--ink-3);
  border-radius: 7px; color: var(--text-hi); padding: 5px 8px;
  font-family: var(--font-body); font-size: 0.88rem; text-align: right;
  font-variant-numeric: tabular-nums;
}
input.money:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.flash-ok {
  background: rgba(95, 191, 125, 0.1); border: 1px solid var(--good);
  color: var(--good); border-radius: 8px; padding: 9px 14px;
  font-size: 0.9rem; margin-bottom: 18px;
}

/* ---------- forms ---------- */

.inline-form { display: inline; }
.btn-mini {
  font-family: var(--font-head); font-weight: 600; font-size: 0.78rem;
  background: var(--brass-dim); color: var(--brass-hi);
  border: 1px solid var(--brass); border-radius: 999px; padding: 3px 12px; cursor: pointer;
}
.btn-mini:hover { background: var(--accent); color: var(--on-accent); }

select {
  background: var(--ink-0); color: var(--text-hi); border: 1px solid var(--ink-3);
  border-radius: 7px; padding: 5px 8px; font-family: var(--font-body); font-size: 0.86rem;
}

/* ---------- licensing panels (customer detail) ---------- */

.form-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 12px;
}
.form-row input[type="text"], .form-row input[type="date"] {
  background: var(--ink-0); color: var(--text-hi); border: 1px solid var(--ink-3);
  border-radius: 7px; padding: 5px 9px; font-family: var(--font-body); font-size: 0.86rem;
}
.form-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.form-row input[type="date"] { color-scheme: dark; }
.hint { color: var(--text-low); font-size: 0.84rem; }
.panel > .hint { display: block; margin: -6px 0 12px; }

.key-line { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.key-line code {
  font-family: var(--font-mono); font-size: 0.88rem; color: var(--brass-hi);
  background: var(--ink-0); border: 1px solid var(--ink-3); border-radius: 7px;
  padding: 6px 11px; letter-spacing: 0.03em; word-break: break-all;
}

.tile-n .chip { font-size: 0.85rem; vertical-align: 3px; }

/* ---------- auto-save indicator (pricing et al.) ---------- */

.save-cell { min-width: 110px; }
.save-state {
  font-family: var(--font-head); font-size: 0.76rem; font-weight: 600;
  letter-spacing: 0.04em; color: var(--text-low);
}
.save-state.ok { color: var(--good); }
.save-state.err { color: var(--warn); }
/* App-wide (owner, 2026-10-11): on a form field the Saving / Saved / error note sits OVER the field, on the label's
   line at the right, so it never adds a line and never shifts the row when it appears or fades. Table cells keep
   their inline note (a cell has its own room). */
div.save-row, span.save-row, label.save-row { position: relative; }
div.save-row > .save-state, span.save-row > .save-state, label.save-row > .save-state {
  position: absolute; top: 0; right: 0; min-height: 0; line-height: 1.2; pointer-events: none; text-align: right;
}
/* Chrome paints a field it autofilled (a phone, a place, a name) its own pale blue - painted back to the house
   field colours app-wide, so a remembered value never looks like a different control (owner, 2026-10-11). */
input:-webkit-autofill, input:-webkit-autofill:hover, input:-webkit-autofill:focus,
textarea:-webkit-autofill, select:-webkit-autofill {
  -webkit-box-shadow: 0 0 0 1000px var(--ink-0) inset; -webkit-text-fill-color: var(--text-hi);
  caret-color: var(--text-hi); transition: background-color 999999s ease-out;
}
/* a field that failed the house validation (admin.autosave.js) - nothing was sent */
input.is-invalid, textarea.is-invalid { border-color: var(--warn) !important; box-shadow: 0 0 0 1px rgba(224, 165, 63, 0.35); }
/* a smaller chip, for a status beside a name */
.chip-sm { font-size: 0.62rem; padding: 1px 8px; letter-spacing: 0.04em; }

/* ---------- customer x add-on matrix ---------- */

.matrix-table th, .matrix-table td { text-align: center; }
.matrix-table th:first-child, .matrix-table td:first-child { text-align: left; min-width: 220px; }
.matrix-table .sub-th { margin-top: 3px; }
.matrix-toggle { width: 17px; height: 17px; accent-color: var(--brass); cursor: pointer; }
.matrix-toggle:disabled { cursor: wait; opacity: 0.5; }
.deal-note { color: var(--brass-hi); font-size: 0.78rem; margin-top: 2px; }
.matrix-table .hint { display: block; }

/* ---------- bolt-on catalog editor (pricing) ---------- */

/* makeControl inside table cells: the .ctl wrapper flattens out. */
td .ctl { display: block; }
.money-cell { text-align: right; white-space: nowrap; }
.money-cell .cur { margin-right: 4px; }
.money-cell .ctl { display: inline-block; vertical-align: middle; }

.bolt-name {
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  color: var(--text-hi); font: 600 0.95rem var(--font-body); padding: 4px 6px; margin-left: -6px;
  width: 100%; min-width: 140px;
}
.bolt-desc {
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  color: var(--text-low); font: 400 0.88rem var(--font-body); padding: 4px 6px; margin-left: -6px;
  width: 100%;
}
.bolt-name:hover, .bolt-desc:hover { border-color: var(--ink-3); }
.bolt-name:focus, .bolt-desc:focus {
  outline: none; background: var(--ink-0); border-color: var(--brass); color: var(--text-hi);
}
/* Description soaks up whatever width the row has left. */
.desc-th, .bolt-desc-cell { width: 100%; }
.bolt-name-cell { white-space: nowrap; }

/* Drag to reorder */
.drag-cell { width: 26px; padding-right: 0; }
.drag-handle {
  cursor: grab; color: var(--text-low); font-size: 0.9rem; letter-spacing: -2px;
  user-select: none; padding: 4px 2px; display: inline-block;
}
.drag-handle:hover { color: var(--brass-hi); }
.drag-handle:active { cursor: grabbing; }
tr.dragging { opacity: 0.45; background: var(--brass-dim); }
h2 .save-state { margin-left: 10px; text-transform: none; }

.addon-create { align-items: end; }
.addon-create .ctl input, .addon-create .ctl select { min-width: 150px; }
.addon-create .ctl-grow { flex: 1 1 240px; }
.addon-create .ctl-grow input { width: 100%; }
.addon-create button { margin-bottom: 2px; }

/* ---------- auth screen ---------- */

.auth-body {
  display: grid; place-items: center; min-height: 100vh; padding: 24px;
  background:
    radial-gradient(55% 70% at 70% 20%, rgba(215, 167, 101, 0.1), transparent 60%),
    var(--ink-0);
}
/* The sign-in card = the Citadel's (owner, 2026-10-10: "use that format across all apps"): a centred head over a rule,
   uppercase field labels, full-width buttons, the code in a big spaced monospace box, an underlined way back. */
.auth-card {
  width: min(400px, 100%); background: var(--ink-2); border: 1px solid var(--ink-3);
  border-radius: 12px; overflow: hidden; box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}
.auth-head { padding: 24px 24px 20px; border-bottom: 1px solid var(--ink-3); text-align: center; }
.auth-mark { width: 38px; height: 38px; color: var(--brass); margin-bottom: 10px; }
.auth-card h1 { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; margin: 0 0 4px; }
.auth-sub { font-size: 0.8rem; color: var(--text-low); margin: 0; }
.auth-main { padding: 24px; }
.auth-hint { font-size: 0.82rem; line-height: 1.55; color: var(--text-low); text-align: center; margin: 0 0 18px; }
.auth-hint strong { color: var(--text-mid); font-weight: 600; overflow-wrap: anywhere; }
.auth-card form { display: flex; flex-direction: column; }
.auth-label {
  font-size: 0.75rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--text-mid); margin-bottom: 5px;
}
.auth-card input[type="email"], .auth-card input[type="text"] {
  width: 100%; box-sizing: border-box; margin-bottom: 16px;
  background: var(--ink-0); border: 1px solid var(--ink-3); border-radius: 8px;
  color: var(--text-hi); padding: 10px 12px; font-size: 1rem;
}
.auth-card input.auth-code {
  font-family: Consolas, "Courier New", monospace; font-size: 1.5rem; letter-spacing: 0.18em;
  text-align: center; text-transform: uppercase; padding: 11px 12px;
}
.auth-card input.auth-code::placeholder { letter-spacing: 0.18em; opacity: 0.55; }
.auth-card input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.auth-card button {
  width: 100%; font-family: var(--font-head); font-weight: 600; font-size: 0.95rem;
  background: var(--accent); color: var(--on-accent);
  border: 0; border-radius: 8px; padding: 10px 16px; cursor: pointer; transition: background 0.15s, opacity 0.15s;
}
.auth-card button:hover:not(:disabled) { background: var(--accent-hi); }
.auth-card button:disabled { opacity: 0.55; cursor: not-allowed; }
.auth-err {
  margin: 12px 0 0; padding: 8px 12px; font-size: 0.82rem; text-align: center;
  background: rgba(224, 82, 82, 0.1); border: 1px solid rgba(224, 82, 82, 0.35); color: #f87171; border-radius: 6px;
}
.auth-dev {
  background: var(--brass-dim); border: 1px solid var(--brass); border-radius: 8px; text-align: center;
  padding: 6px 12px; font-size: 0.8rem; margin: 0 0 16px; color: var(--text-mid);
}
.auth-back {
  display: block; margin-top: 13px; font-size: 0.79rem; text-align: center;
  color: var(--text-low); text-decoration: underline;
}
.auth-back:hover { color: var(--text-mid); }

/* ---------- responsive ---------- */

@media (max-width: 800px) {
  .shell-body { grid-template-columns: 1fr; }
  .topbar { height: auto; flex-wrap: wrap; gap: 10px 18px; padding: 10px 16px; }
  .site-switch a { padding: 6px 10px; }
  .side { position: static; height: auto; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 10px; }
  .side > nav { position: static; }
  .side nav { display: flex; gap: 4px; }
  .side-foot { margin: 0 0 0 auto; }
  .main { padding: 20px 18px 50px; }
}

/* Line of business switch (010): All | Mainspring | DamagePort, under the brand. */
.line-switch { display: flex; gap: 2px; margin: 10px -4px 14px; padding: 3px; background: var(--ink-2); border-radius: 8px; }
.line-switch a { flex: 1 1 auto; min-width: 0; white-space: nowrap; text-align: center; padding: 4px 5px; border-radius: 6px; font-size: 0.78rem; color: var(--text-lo, inherit); }
.line-switch a:hover { text-decoration: none; color: var(--text-hi); }
.line-switch a.on { background: var(--brass-dim); color: var(--brass-hi); font-weight: 600; }
.chip-line-damageport { background: rgba(99, 205, 177, 0.14); color: var(--brand-damageport); }   /* DamagePort seafoam (brand, 2026-10-10) */
.chip-line-mainspring { background: var(--brass-dim); color: var(--brass-hi); }

/* Pricing > Plans (011): an offering per row - name / tagline / description stacked, the small number boxes narrow. */
.plans-table .plan-cell { min-width: 16rem; }
.plans-table .plan-cell .ctl + .ctl { margin-top: 4px; }
.plans-table .plan-name { font-weight: 600; }
.plans-table .plan-tagline, .plans-table .plan-desc { font-size: 0.85rem; }
.plans-table .num-small { width: 4.5rem; text-align: right; }

/* ---------- collapsible panels (ui.panels.js) ---------- */
/* Default collapsed; the expanded state is remembered per panel (cookie cm_panels). */
.panel.is-collapsible > h2 { cursor: pointer; user-select: none; margin-bottom: 0; display: flex; align-items: center; gap: 8px; }
.panel.is-collapsible > h2:hover { color: var(--brass-hi); }
.panel-toggle { width: 0; height: 0; border-left: 5px solid transparent; border-right: 5px solid transparent; border-top: 7px solid var(--text-low); transition: transform 0.22s ease; transform: rotate(-90deg); flex: none; }
.panel.is-open > h2 .panel-toggle { transform: rotate(0deg); }
.panel-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.28s ease; }
.panel.is-open > .panel-body { grid-template-rows: 1fr; }
.panel.no-anim > .panel-body, .panel.no-anim .panel-toggle { transition: none; }
.panel-body-inner { overflow: hidden; min-height: 0; }
.panel.is-open > .panel-body > .panel-body-inner { padding-top: 12px; }
.panel.is-collapsible { padding-bottom: 16px; }

/* Chips in a panel title sit at the far right of the heading (owner, 2026-10-10). */
.panel.is-collapsible > h2 > :not(.chip) + .chip { margin-left: auto; }   /* the first chip after the words; chips after it follow it */
