/* Deskwatch console CSS (K1) - dark, dense, information-forward, per
   UI_SPEC.md's stated intent. Color tokens and general shape follow the
   design mockups reviewed with the project owner
   (deskwatch-design/{Main,IncidentDetail,BlastRadius,History}.dc.html) -
   reimplemented here as plain CSS, not copied markup. */

:root {
  --bg: #292521;
  --bg-elevated: #322d28;
  --bg-inset: #201d1a;
  --border: #4c453c;
  --border-subtle: #3b352e;
  --text: #eae7e2;
  --text-muted: #ada79c;
  --text-faint: #837c70;
  --accent: #e0c374;
  --accent-dim: #a68a4c;
  --sev1: #d0523a;
  --sev2: #d38b46;
  --sev3: #cbb85c;
  --good: #59b58a;
  --info: #5c9fc9;
  --bad: #cf5a44;
  --font-ui: "Segoe UI", system-ui, -apple-system, sans-serif;
  --font-mono: "Cascadia Code", Consolas, ui-monospace, "SFMono-Regular", monospace;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.tabular { font-variant-numeric: tabular-nums; }

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--bg-inset);
  border-right: 1px solid var(--border-subtle);
  padding: 20px 0;
  display: flex;
  flex-direction: column;
}
.sidebar .brand {
  padding: 0 20px 18px 20px;
  font-weight: 700;
  font-size: 15px;
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.sidebar nav a {
  display: block;
  padding: 9px 12px;
  border-radius: 6px;
  color: var(--text-muted);
  font-size: 13.5px;
}
.sidebar nav a.active { background: var(--bg-elevated); color: var(--text); font-weight: 600; }
.sidebar .who {
  margin-top: auto;
  padding: 12px 20px;
  border-top: 1px solid var(--border-subtle);
  font-size: 11.5px;
  color: var(--text-faint);
}

.main { flex: 1; min-width: 0; }
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border-subtle);
}
.topbar h1 { font-size: 19px; margin: 0; }
.topbar .sub { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

.content { padding: 22px 28px; display: flex; flex-direction: column; gap: 20px; }

.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  padding: 16px 18px;
  /* Safety net for wide content (long mono commands, wide inline-edit rows)
     so a card scrolls internally instead of forcing the page body wider
     than the viewport - the page itself must never scroll sideways. */
  overflow-x: auto;
}
.card.card-action { border-left: 3px solid var(--accent); background: rgba(224,195,116,.05); }
.card h2 {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 0 0 10px 0;
}

.kpi-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; }
.kpi { background: var(--bg-elevated); border: 1px solid var(--border-subtle); border-radius: 10px; padding: 16px; }
.kpi .label { font-size: 11.5px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.kpi .value.faint { font-size: 15px; color: var(--text-faint); font-style: italic; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 100px; font-size: 11px; font-weight: 600;
  letter-spacing: .02em; text-transform: uppercase;
}
.pill.sev-sev1 { background: rgba(208,82,58,.22); color: var(--sev1); }
.pill.sev-sev2 { background: rgba(211,139,70,.22); color: var(--sev2); }
.pill.sev-sev3, .pill.sev-sev4 { background: rgba(203,184,92,.20); color: var(--sev3); }
.pill.status-closed { background: rgba(89,181,138,.20); color: var(--good); }
.pill.status-resolved, .pill.status-mitigated { background: rgba(92,159,201,.20); color: var(--info); }
.pill.status-open, .pill.status-investigating, .pill.status-actions-pending {
  background: rgba(224,195,116,.18); color: var(--accent);
}
/* L2.5 - Problem/known-error status pills, same status-<slug> convention. */
.pill.status-root-caused { background: rgba(224,195,116,.18); color: var(--accent); }
.pill.status-eliminated { background: rgba(89,181,138,.20); color: var(--good); }
.pill.status-accepted { background: rgba(92,159,201,.20); color: var(--info); }
/* L2.75 - post-incident review state pills, same convention. */
.pill.status-not-required { background: rgba(255,255,255,.06); color: var(--text-muted); }
.pill.status-draft { background: rgba(224,195,116,.18); color: var(--accent); }
.pill.status-in-review { background: rgba(92,159,201,.20); color: var(--info); }
.pill.status-changes-requested { background: rgba(211,139,70,.22); color: var(--sev2); }
.pill.status-approved { background: rgba(92,159,201,.20); color: var(--info); }
.pill.status-published { background: rgba(89,181,138,.20); color: var(--good); }
/* L3 - investigation-entry outcome pills, same convention. */
.pill.status-pending { background: rgba(255,255,255,.06); color: var(--text-muted); }
.pill.status-confirmed { background: rgba(224,195,116,.18); color: var(--accent); }
.pill.status-ruled-out { background: rgba(211,139,70,.22); color: var(--sev2); }
.pill.status-no-effect { background: rgba(211,139,70,.22); color: var(--sev2); }
.pill.chip-auto { background: rgba(255,255,255,.06); color: var(--text-muted); }
.pill.chip-agent { background: rgba(92,159,201,.20); color: var(--info); }
.pill.chip-human { background: rgba(224,195,116,.20); color: var(--accent); }
.pill.calc-status { background: rgba(255,255,255,.06); color: var(--text-faint); }

.incident-card { display: flex; background: var(--bg-elevated); border: 1px solid var(--border-subtle); border-radius: 10px; overflow: hidden; margin-bottom: 10px; }
.incident-card .stripe { width: 5px; flex-shrink: 0; }
.incident-card .stripe.sev-sev1 { background: var(--sev1); }
.incident-card .stripe.sev-sev2 { background: var(--sev2); }
.incident-card .stripe.sev-sev3, .incident-card .stripe.sev-sev4 { background: var(--sev3); }
.incident-card .body { flex: 1; padding: 12px 16px; }
.incident-card .id { font-family: var(--font-mono); font-size: 12px; color: var(--text-faint); margin-right: 8px; }
.incident-card .title { font-size: 14.5px; font-weight: 600; margin-top: 4px; }
.incident-card .meta { font-size: 12px; color: var(--text-muted); margin-top: 3px; }
.incident-card .detected-at { font-size: 11.5px; color: var(--text-faint); margin-left: 4px; }

.timeline-day {
  font-size: 12px; font-weight: 700; letter-spacing: .03em; text-transform: uppercase;
  color: var(--text-faint); margin: 18px 0 8px; padding-top: 8px; border-top: 1px solid var(--border-subtle);
}
.timeline-day:first-child { margin-top: 4px; border-top: none; padding-top: 0; }
.timeline-day .notice { display: inline; margin: 0 0 0 6px; text-transform: none; letter-spacing: normal; }

.empty-state {
  background: var(--bg-inset);
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 11px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .04em; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 9px 10px; font-size: 13px; border-bottom: 1px solid var(--border-subtle); vertical-align: top; }

.kv-row { display: grid; grid-template-columns: 150px 1fr; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border-subtle); font-size: 13px; }
.kv-row:last-child { border-bottom: none; }
.kv-label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: .03em; }

.action-item-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border-subtle); font-size: 13px; }
.action-item-row:last-of-type { border-bottom: none; }
.action-item-toggle { display: flex; align-items: center; padding-top: 2px; }
.action-item-row input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }
.action-item-row .btn { padding: 3px 9px; font-size: 14px; line-height: 1; color: var(--text-faint); }
.action-item-row .btn:hover { color: var(--bad); border-color: var(--bad); }
.action-item-reorder { display: flex; flex-direction: column; gap: 2px; }
.action-item-reorder .btn { padding: 1px 7px; color: var(--text-faint); }
.action-item-reorder .btn:hover:not(:disabled) { color: var(--accent); border-color: var(--accent); }
.action-item-reorder .btn:disabled { opacity: .3; cursor: default; }

.order-lifecycle-row { padding: 10px 0; border-bottom: 1px solid var(--border-subtle); }
.order-lifecycle-row:last-child { border-bottom: none; }
.order-lifecycle-row .kv-row { border-bottom: none; padding-bottom: 4px; }
.lifecycle-stages { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.lifecycle-stages .pill { text-transform: capitalize; cursor: default; }

.timeline-row { display: flex; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--border-subtle); font-size: 12.5px; }
.timeline-row .ts { width: 150px; flex-shrink: 0; font-family: var(--font-mono); font-size: 11.5px; color: var(--text-faint); }
.timeline-row .evidence {
  font-family: var(--font-mono); font-size: 11px; color: var(--text-faint);
  background: var(--bg-inset); border-radius: 5px; padding: 6px 8px; margin-top: 5px;
  white-space: pre-wrap; word-break: break-word;
}
.evidence-gated {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-inset); border: 1px dashed var(--border); border-radius: 8px;
  padding: 12px 14px; font-size: 12.5px; color: var(--text-muted);
}

.two-col { display: flex; gap: 20px; align-items: flex-start; }
.two-col .left { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 16px; }
.two-col .right { width: 340px; flex-shrink: 0; display: flex; flex-direction: column; gap: 16px; }

/* Persistent runbook rail on the incident detail page (K1, extended
   2026-08-20) - a third column alongside .left/.right, not nested inside
   either, so it keeps its own scroll/width independent of the metadata
   card stack. */
.two-col .runbook-rail {
  width: 380px; flex-shrink: 0;
  display: flex; flex-direction: column; gap: 12px;
  position: sticky; top: 16px;
}
.runbook-rail .card { max-height: calc(100vh - 32px); overflow-y: auto; }

.markdown-body { font-size: 13px; line-height: 1.6; color: var(--text); }
.markdown-body h1, .markdown-body h2, .markdown-body h3 {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--text-muted); margin: 16px 0 6px; border-bottom: 1px solid var(--border-subtle);
  padding-bottom: 4px;
}
.markdown-body h1:first-child, .markdown-body h2:first-child, .markdown-body h3:first-child { margin-top: 0; }
.markdown-body p { margin: 0 0 10px; }
.markdown-body ul, .markdown-body ol { margin: 0 0 10px; padding-left: 20px; }
.markdown-body li { margin-bottom: 4px; }
.markdown-body code {
  font-family: var(--font-mono); font-size: 12px; background: var(--bg-inset);
  border-radius: 4px; padding: 1px 5px;
}
.markdown-body pre {
  font-family: var(--font-mono); font-size: 12px; background: var(--bg-inset);
  border: 1px solid var(--border-subtle); border-radius: 6px; padding: 10px 12px;
  overflow-x: auto; margin: 0 0 12px; position: relative;
}
.markdown-body pre code { background: none; padding: 0; }
.markdown-body strong { color: var(--text); }
.markdown-body a { color: var(--info); }
/* L6.5 - copy button (top-right of the code block it copies) and mermaid
   diagram container (a runbook-authored ```mermaid fence, rendered client-
   side - see base.html's enhanceMarkdownBodies). */
.markdown-body pre .code-copy-btn {
  position: absolute; top: 6px; right: 6px; font-size: 10px; padding: 3px 8px;
  opacity: 0.7;
}
.markdown-body pre .code-copy-btn:hover { opacity: 1; }
.markdown-body .mermaid {
  background: var(--bg-inset); border: 1px solid var(--border-subtle);
  border-radius: 6px; padding: 12px; margin: 0 0 12px; overflow-x: auto;
  text-align: center;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  font-size: 12px; padding: 5px 10px; border-radius: 100px;
  border: 1px solid var(--border); background: var(--bg-inset); color: var(--text-muted);
}
.chip.active { border-color: var(--accent); color: var(--accent); background: rgba(224,195,116,.12); }
.disabled-filter { text-decoration: line-through; opacity: .5; }

form.filters label { display: block; font-size: 11px; color: var(--text-faint); margin: 10px 0 4px; }
form.filters select, form.filters input, form.filters textarea {
  width: 100%; background: var(--bg-inset); color: var(--text); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 8px; font-size: 12.5px; font-family: var(--font-ui);
}
form.filters textarea { resize: vertical; }
.search-box { display: flex; align-items: center; gap: 10px; background: var(--bg-elevated); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; }
.search-box input { flex: 1; background: transparent; border: none; outline: none; color: var(--text); font-size: 13.5px; font-family: var(--font-ui); }

.btn {
  font-family: var(--font-ui); font-size: 12.5px; font-weight: 700; cursor: pointer;
  border-radius: 6px; padding: 7px 14px; border: 1px solid var(--border);
  background: var(--bg-elevated); color: var(--text);
}
.btn.primary { background: var(--accent); color: #241f1a; border-color: var(--accent); }

.graph-wrap { background: var(--bg-inset); border-radius: 8px; padding: 10px; }
.relation-approved { stroke: var(--accent); }
.relation-unapproved { stroke: var(--text-faint); stroke-dasharray: 5 4; }
.node-box { fill: var(--bg-elevated); stroke: var(--border); }
.node-label { font-family: var(--font-ui); font-size: 11px; fill: var(--text); }

.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { width: 340px; background: var(--bg-elevated); border: 1px solid var(--border-subtle); border-radius: 10px; padding: 26px; }
.login-card h1 { font-size: 18px; margin: 0 0 16px 0; }
.login-card label { display: block; font-size: 12px; color: var(--text-muted); margin: 12px 0 4px; }
.login-card input { width: 100%; background: var(--bg-inset); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 9px 10px; }
.login-error { color: var(--bad); font-size: 12.5px; margin-bottom: 14px; }

.ms-signin {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; padding: 9px 14px; background: var(--bg-elevated);
  border: 1px solid var(--accent-dim); color: var(--text);
}
.ms-signin:hover { border-color: var(--accent); }
.ms-logo { width: 16px; height: 16px; flex-shrink: 0; }
.login-divider { display: flex; align-items: center; gap: 10px; margin: 16px 0; color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.login-divider::before, .login-divider::after { content: ""; flex: 1; height: 1px; background: var(--border-subtle); }

.notice { font-size: 11.5px; color: var(--text-faint); margin-top: 8px; }
.section-gap { margin-top: 6px; }

/* K2: admin grid / diff-approval / ingest - same token system as K1, no
   second visual language. */
.tab-groups { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.tab-group { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.tab-group-label {
  width: 96px; flex-shrink: 0; font-size: 10.5px; font-weight: 700; color: var(--text-faint);
  text-transform: uppercase; letter-spacing: .05em;
}
.tab-row { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px; }
.tab-groups .tab-row { margin-bottom: 0; }
.tab-row a {
  padding: 6px 11px; font-size: 12.5px; font-weight: 600; color: var(--text-muted);
  background: var(--bg-inset); border: 1px solid var(--border-subtle); border-radius: 6px;
}
.tab-row a.active { color: #241f1a; background: var(--accent); border-color: var(--accent); }
.error-banner {
  background: rgba(207,90,68,.14); border: 1px solid var(--bad); color: var(--bad);
  border-radius: 8px; padding: 10px 14px; font-size: 12.5px;
}
.notice-banner {
  background: rgba(89,181,138,.14); border: 1px solid var(--good); color: var(--good);
  border-radius: 8px; padding: 10px 14px; font-size: 12.5px;
}
form.inline-edit { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
form.inline-edit input, form.inline-edit select {
  background: var(--bg-inset); color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 4px 7px; font-size: 12px; font-family: var(--font-ui);
}
.field-row { display: flex; gap: 10px; padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border-subtle); background: var(--bg-inset); margin-bottom: 10px; }
.field-row.rejected { opacity: .45; }
.field-row .badge {
  display: flex; align-items: center; justify-content: center; width: 20px; height: 20px;
  border-radius: 100px; font-size: 10px; font-weight: 700; font-family: var(--font-mono);
  background: var(--accent); color: #241f1a; flex-shrink: 0;
}
.field-unknown { background: rgba(255,255,255,.06); color: var(--text-faint); }
.field-proposed { background: rgba(224,195,116,.18); color: var(--accent); }
.clarify-box { margin-top: 8px; background: var(--bg-elevated); border: 1px solid var(--info); border-radius: 8px; padding: 10px 12px; }
.split-panel { display: flex; gap: 0; align-items: flex-start; }
.split-panel .left { width: 46%; flex-shrink: 0; padding-right: 20px; border-right: 1px solid var(--border-subtle); }
.split-panel .right { flex: 1; min-width: 0; padding-left: 20px; }
mark.src-hl { background: rgba(224,195,116,.28); color: var(--text); padding: 0 1px; border-radius: 2px; }

/* Responsive breakpoints (2026-08-20 UX pass, punch-list item #7).
   `.two-col .right` (340px) + `.runbook-rail` (380px) is 720px of fixed
   sidebar before the main column even starts - on anything at or below
   ~1400px wide (the Playwright test viewport itself is 1280x720, so this
   is exercised on every browser test, not just a real narrow window) that
   squeezes the main column unreadably rather than reflowing. Stacking
   never hides content (`display:none` would break Playwright's
   `.inner_text()`/`.is_visible()` on anything still checking these
   sections, the same lesson `x-show` already forces elsewhere) - it only
   reorders a flex axis, so every element stays exactly as visible as it
   was in the wide layout. */
@media (max-width: 1400px) {
  .two-col { flex-direction: column; }
  .two-col .left { order: 1; }
  .two-col .right { order: 2; width: 100%; }
  .two-col .runbook-rail {
    order: 3; width: 100%;
    /* Sticky + a viewport-height cap only make sense as a THIRD column
       beside scrollable siblings - stacked in normal flow it would pin an
       awkward scrolling box mid-page instead of just reading top-to-bottom. */
    position: static; max-height: none;
  }
  .runbook-rail .card { max-height: none; overflow-y: visible; }
}

@media (max-width: 900px) {
  .kpi-row { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .split-panel { flex-direction: column; }
  .split-panel .left {
    width: 100%; padding-right: 0; padding-bottom: 16px;
    border-right: none; border-bottom: 1px solid var(--border-subtle);
  }
  .split-panel .right { padding-left: 0; padding-top: 16px; }
}

@media (max-width: 620px) {
  .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content { padding: 16px; }
}
