/* Malcolm operator console v0. Connect brand only:
   ink #0a0a0a, paper #f7f4ed, burgundy #c8102e, cream/panel #f3ead4.
   Georgia (serif) for headings, Inter (sans) for body + UI. No external scripts.
   Keyboard-usable, labelled controls, AA contrast, same posture as the widget. */

:root {
  --ink: #0a0a0a;
  --paper: #f7f4ed;
  --panel: #f3ead4;
  --burgundy: #c8102e;
  --sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
  --line: #e2d8c0;
  --muted: #5c554a;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  background: var(--paper);
  color: var(--ink);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 400;
  letter-spacing: -0.01em;
  margin: 0;
}

a { color: var(--burgundy); }

/* Focus rings: visible on every interactive control (keyboard posture). */
:focus-visible {
  outline: 2px solid var(--burgundy);
  outline-offset: 2px;
}

button {
  font-family: var(--sans);
  cursor: pointer;
}

.btn-primary {
  background: var(--burgundy);
  color: #fff;
  border: none;
  font-weight: 600;
  font-size: 14px;
  padding: 9px 18px;
  border-radius: 2px;
}
.btn-primary:hover { filter: brightness(1.06); }

.btn-ghost {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
  font-weight: 600;
  font-size: 13px;
  padding: 7px 14px;
  border-radius: 2px;
}
.btn-ghost:hover { background: rgba(0, 0, 0, 0.04); }

/* ---- Header ---- */
header.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.brand h1 { font-size: 22px; }
.brand .sub {
  font-size: 12.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.session { display: flex; align-items: center; gap: 12px; }

/* ---- Login gate ---- */
.login-wrap {
  max-width: 420px;
  margin: 12vh auto;
  padding: 32px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
}
.login-wrap h2 { font-size: 24px; margin-bottom: 6px; }
.login-wrap p { color: var(--muted); font-size: 14px; margin: 0 0 20px; }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }

input[type="text"], input[type="password"], select, textarea {
  font-family: var(--sans);
  font-size: 14px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 9px 11px;
  width: 100%;
}
textarea { resize: vertical; min-height: 38px; }

.err {
  color: var(--burgundy);
  font-size: 13px;
  font-weight: 600;
  margin-top: 12px;
  min-height: 18px;
}

/* ---- Tabs ---- */
nav.tabs {
  display: flex;
  gap: 4px;
  padding: 0 28px;
  border-bottom: 1px solid var(--line);
  background: var(--paper);
}
nav.tabs button {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 13px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}
nav.tabs button[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--burgundy);
}

main { padding: 24px 28px 64px; max-width: 1100px; }

.panel-note {
  font-size: 12.5px;
  color: var(--muted);
  margin: 0 0 16px;
}

/* ---- KPI cards ---- */
.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}
.kpi {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 16px 18px;
}
.kpi .label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.kpi .value {
  font-family: var(--serif);
  font-size: 32px;
  margin-top: 6px;
}

.cols { display: grid; grid-template-columns: 1.4fr 1fr; gap: 24px; }
section.block { margin-bottom: 28px; }
section.block h3 { font-size: 18px; margin-bottom: 14px; }

/* ---- Volume bar chart (divs only, no chart library) ---- */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 8px; }
.bar-col { display: flex; flex-direction: column; align-items: center; flex: 1; height: 100%; justify-content: flex-end; gap: 6px; }
.bar {
  width: 100%;
  max-width: 34px;
  background: var(--burgundy);
  border-radius: 2px 2px 0 0;
  min-height: 2px;
}
.bar-col .n { font-size: 11px; color: var(--muted); }
.bar-col .d { font-size: 10px; color: var(--muted); transform: rotate(-45deg); transform-origin: top left; white-space: nowrap; height: 28px; }

/* ---- Lists + tables ---- */
.list { list-style: none; margin: 0; padding: 0; }
.list li {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.list li .count { font-weight: 600; color: var(--muted); }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 600; }
tbody tr:hover { background: rgba(0, 0, 0, 0.02); }
td.q { max-width: 460px; }

.row-controls { display: flex; gap: 8px; align-items: flex-start; }
.row-controls select { width: auto; }
.row-controls textarea { min-width: 200px; }

.filters { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; }
.filters select { width: auto; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
}
.badge.new { color: var(--burgundy); border-color: var(--burgundy); }
.badge.reviewed { color: var(--muted); }
.badge.resolved { color: #1d6b3a; border-color: #1d6b3a; }

.empty { color: var(--muted); font-size: 14px; padding: 24px 0; }
.saved { color: #1d6b3a; font-size: 12px; font-weight: 600; }

/* ---- Config editor (console v1) ---- */
/* The live bar: a clear, distinct band marking what visitors actually see, kept
   visually separate from the draft editor below it. */
.livebar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-left: 4px solid var(--burgundy);
  border-radius: 4px;
  margin-bottom: 14px;
}
.livebar .live-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--burgundy);
  flex: none;
}
.livebar .live-text { font-size: 13.5px; }
.livebar .live-text strong { font-weight: 600; }
.livebar.warn { border-left-color: #b06a00; background: #fbf1dd; }
.livebar .warn-text { color: #8a4b00; font-weight: 600; }

.draft-note { font-size: 13px; }
.draft-note strong { color: var(--burgundy); }

.config-panels { display: block; }
.cfg-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 18px 20px;
  margin-bottom: 18px;
}
.cfg-panel h3 { font-size: 18px; margin-bottom: 14px; }
.cfg-panel textarea { font-family: var(--sans); }
#cfg-system-prompt { min-height: 240px; line-height: 1.5; }
.counter { font-size: 12px; color: var(--muted); margin-top: 6px; text-align: right; }
.counter.over { color: var(--burgundy); font-weight: 600; }

.cfg-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px 20px;
}
.cfg-grid .field.full { grid-column: 1 / -1; }
.cfg-grid .field.check {
  display: flex;
  align-items: center;
  gap: 8px;
  align-self: end;
}
.cfg-grid .field.check input { width: auto; }
.cfg-grid .field.check label { margin-bottom: 0; }

.routing-table input { padding: 7px 9px; font-size: 13px; }
.routing-table td { vertical-align: middle; }
.routing-table .rm {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--burgundy);
  border-radius: 2px;
  padding: 5px 10px;
  font-weight: 600;
  font-size: 12px;
}
.routing-table .rm:hover { background: rgba(200, 16, 46, 0.08); }

.version-actions { margin-bottom: 14px; }
.badge.active { color: #fff; background: var(--burgundy); border-color: var(--burgundy); }

.cfg-errors {
  background: #fbe9ec;
  border: 1px solid var(--burgundy);
  border-radius: 4px;
  padding: 12px 16px;
  margin-bottom: 80px;
  color: #7a0a1c;
  font-size: 13px;
}
.cfg-errors ul { margin: 6px 0 0; padding-left: 20px; }

/* Sticky publish bar: always reachable, with a clear divider from content. */
.publish-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 2px solid var(--burgundy);
  border-radius: 4px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.publish-bar .pb-meta { display: flex; gap: 10px; flex: 1; min-width: 240px; }
.publish-bar .pb-meta input { width: auto; flex: 1; }
.publish-bar .pb-actions { display: flex; align-items: center; gap: 12px; }
.pb-status { font-size: 12.5px; color: var(--muted); }
.pb-status.ok { color: #1d6b3a; font-weight: 600; }
.pb-status.err { color: var(--burgundy); font-weight: 600; }

.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

@media (max-width: 820px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .cols { grid-template-columns: 1fr; }
}

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