/* MSP Ops Copilot — "Operations Console". Vanilla, no external deps, no CDN. */

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

:root {
  /* ---- Surfaces: canvas → subtle → surface → raised → hover */
  --bg-base:    oklch(0.17 0.006 265);
  --bg-subtle:  oklch(0.20 0.007 265);
  --bg-panel:   oklch(0.205 0.007 265);
  --bg-card:    oklch(0.225 0.008 265);
  --bg-raised:  oklch(0.255 0.009 265);
  --bg-hover:   oklch(0.30 0.010 265);

  /* ---- Borders: translucent white so they read on any surface */
  --border-subtle: oklch(1 0 0 / 0.06);
  --border:        oklch(1 0 0 / 0.10);
  --border-light:  oklch(1 0 0 / 0.16);

  /* ---- Foreground hierarchy, never pure white */
  --text-primary:   oklch(0.96 0.004 265);
  --text-secondary: oklch(0.74 0.006 265);
  --text-muted:     oklch(0.56 0.006 265);
  --text-link:      oklch(0.72 0.13 250);

  /* ---- ONE rationed accent (primary action only) */
  --accent-blue:    oklch(0.62 0.17 250);
  --accent-hover:   oklch(0.67 0.17 250);
  --accent-fg:      oklch(0.98 0 0);
  --accent-subtle:  oklch(0.62 0.17 250 / 0.14);
  --focus-ring:     oklch(0.70 0.16 250 / 0.55);

  /* ---- Severity / triage semantics (kept names; JS depends on these) */
  --accent-green:  oklch(0.74 0.15 162);
  --accent-yellow: oklch(0.80 0.14 80);
  --accent-red:    oklch(0.64 0.20 25);
  --accent-purple: oklch(0.62 0.17 295);

  --class-escalate:      var(--accent-red);
  --class-needs-human:   var(--accent-yellow);
  --class-auto-close:    var(--accent-blue);
  --class-informational: var(--accent-green);

  --sev-critical: var(--accent-red);
  --sev-warning:  var(--accent-yellow);
  --sev-info:     var(--accent-blue);

  /* tinted chip backgrounds */
  --tint-red:    oklch(0.64 0.20 25  / 0.14);
  --tint-yellow: oklch(0.80 0.14 80  / 0.14);
  --tint-blue:   oklch(0.62 0.17 250 / 0.14);
  --tint-green:  oklch(0.74 0.15 162 / 0.14);
  --tint-purple: oklch(0.62 0.17 295 / 0.14);

  /* ---- Type: system stacks, no CDN */
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", "Source Code Pro", Menlo, Consolas, monospace;

  --text-xs: 0.6875rem;  --lh-xs: 1rem;
  --text-sm: 0.8125rem;  --lh-sm: 1.25rem;
  --text-base: 0.875rem; --lh-base: 1.375rem;
  --text-md: 1rem;       --lh-md: 1.5rem;
  --text-lg: 1.25rem;    --lh-lg: 1.6rem;
  --text-stat: 1.75rem;  --lh-stat: 1;

  --fw-normal: 440; --fw-medium: 510; --fw-semibold: 600; --fw-bold: 700;
  --tracking-tight: -0.011em; --tracking-label: 0.07em;

  /* ---- Spacing 4/8 rhythm */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px; --sp-4: 16px;
  --sp-5: 20px; --sp-6: 24px; --sp-8: 32px; --sp-10: 40px;
  --control-h: 36px;
  --control-h-touch: 44px;

  /* ---- Radius */
  --radius-sm: 6px; --radius-md: 8px; --radius-lg: 12px; --radius-full: 9999px;

  /* ---- Shadow + lit-edge */
  --shadow-sm: 0 1px 2px oklch(0 0 0 / 0.25);
  --shadow-md: 0 4px 12px oklch(0 0 0 / 0.30), 0 1px 2px oklch(0 0 0 / 0.20);
  --shadow-lg: 0 12px 32px oklch(0 0 0 / 0.40), 0 2px 6px oklch(0 0 0 / 0.25);
  --edge-highlight: inset 0 1px 0 oklch(1 0 0 / 0.05);

  /* ---- Motion */
  --ease: cubic-bezier(0.22, 1, 0.36, 1); --dur: 140ms;

  /* ---- runtime-set (mobile keyboard fallback) */
  --kb: 0px;
}

html, body { height: 100%; }

body {
  background: var(--bg-base);
  color: var(--text-primary);
  font: var(--fw-normal) var(--text-base)/var(--lh-base) var(--font);
  font-feature-settings: "cv11";
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.num, .stat-value, .raw-count-item span, code, .sweep-time { font-variant-numeric: tabular-nums; }

:focus { outline: none; }
:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg-base), 0 0 0 4px var(--focus-ring);
  border-radius: var(--radius-sm);
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ── App shell — phone base: stacked surfaces + bottom tab bar ── */

#app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  grid-template-areas: "topbar" "surface" "tabbar";
  height: 100dvh;
  min-height: 100svh;
  overflow: hidden;
}
#topbar { grid-area: topbar; }

#main {
  grid-area: surface;
  display: grid;
  grid-template-columns: 1fr;
  min-height: 0;
  overflow: hidden;
}

#ops-board, #chat-panel {
  grid-column: 1;
  grid-row: 1;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#ops-board {
  display: none;
  flex-direction: column;
  gap: var(--sp-4);
  padding: var(--sp-4);
  padding-inline: max(var(--sp-4), env(safe-area-inset-left)) max(var(--sp-4), env(safe-area-inset-right));
}
#chat-panel { display: none; flex-direction: column; }
#app[data-tab="board"] #ops-board { display: flex; }
#app[data-tab="chat"]  #chat-panel { display: flex; }

/* bottom tab bar — phone only */
#tabbar {
  grid-area: tabbar;
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-btn {
  flex: 1; min-height: var(--control-h-touch);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: none; color: var(--text-muted);
  font-size: var(--text-xs); cursor: pointer; touch-action: manipulation;
  position: relative;
  transition: color var(--dur) var(--ease);
}
.tab-btn[aria-selected="true"] { color: var(--accent-blue); }
.tab-btn span { display: inline-flex; align-items: center; gap: 4px; }
.tab-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: var(--radius-full);
  background: var(--accent-red); color: var(--accent-fg);
  font-size: 10px; font-weight: var(--fw-bold); line-height: 1;
}

#btn-chat-toggle, .chat-close-btn { display: none; }

/* ── Topbar ──────────────────────────────────────────── */

#topbar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  flex-wrap: wrap;
  min-height: 52px; height: auto;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  padding-top: max(var(--sp-2), env(safe-area-inset-top));
  padding-bottom: var(--sp-2);
  padding-inline: max(var(--sp-4), env(safe-area-inset-left)) max(var(--sp-4), env(safe-area-inset-right));
}

#topbar .logo {
  font-weight: var(--fw-bold);
  font-size: var(--text-md);
  letter-spacing: var(--tracking-tight);
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
#topbar .logo-dot {
  width: 8px; height: 8px;
  background: var(--accent-blue);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent-blue);
  flex-shrink: 0;
}
.logo-mark { display: none; }

#topbar .sep { flex: 1; }

.tenant-selector {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
}
.tenant-selector label {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
}

#tenant-input {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  padding: 0 var(--sp-3);
  height: var(--control-h);
  width: 170px;
  min-width: 0;
  outline: none;
  transition: border-color var(--dur);
}
#tenant-input:focus { border-color: var(--border-light); }
#tenant-input::placeholder { color: var(--text-muted); }

#apply-tenant {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  background: var(--accent-blue);
  border: none;
  border-radius: var(--radius-sm);
  color: var(--accent-fg);
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  height: var(--control-h);
  padding: 0 var(--sp-3);
  cursor: pointer;
  touch-action: manipulation;
  transition: background var(--dur), transform .1s;
}
#apply-tenant:hover { background: var(--accent-hover); }
#apply-tenant:active { transform: scale(.97); }
#apply-tenant .i { display: none; }

#btn-chat-toggle, #btn-profile-copy, .icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  touch-action: manipulation;
  width: var(--control-h); height: var(--control-h);
  position: relative;
  transition: background var(--dur), color var(--dur), transform .1s;
}
#btn-chat-toggle:hover, .icon-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
#btn-chat-toggle:active, .icon-btn:active { transform: scale(.94); }
.chat-toggle-dot {
  position: absolute; top: -3px; right: -3px;
  min-width: 16px; height: 16px; padding: 0 4px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-full);
  background: var(--accent-red); color: var(--accent-fg);
  font-size: 10px; font-weight: var(--fw-bold); line-height: 1;
  border: 2px solid var(--bg-panel);
}

/* ── Shared card/panel ──────────────────────────────────── */

.panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  box-shadow: var(--shadow-md), var(--edge-highlight);
  min-width: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-2);
  margin-bottom: var(--sp-3);
}

.panel-title {
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--text-secondary);
}

/* ── Stat strip ─────────────────────────────────────────── */

.stat-grid {
  display: grid; gap: var(--sp-3);
  grid-template-columns: repeat(auto-fit, minmax(min(160px, 100%), 1fr));
  max-width: 1280px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--sp-3) var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  position: relative;
  overflow: hidden;
  min-width: 0;
  box-shadow: var(--edge-highlight);
}
.stat-card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
}
.stat-card.escalate::before       { background: var(--class-escalate); }
.stat-card.needs-human::before    { background: var(--class-needs-human); }
.stat-card.auto-close::before     { background: var(--class-auto-close); }
.stat-card.informational::before  { background: var(--class-informational); }

.stat-label {
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--text-secondary);
}
.stat-value {
  font-size: var(--text-stat);
  line-height: var(--lh-stat);
  font-weight: var(--fw-bold);
  font-variant-numeric: tabular-nums;
  letter-spacing: var(--tracking-tight);
}
.stat-card.escalate      .stat-value { color: var(--class-escalate); }
.stat-card.needs-human   .stat-value { color: var(--class-needs-human); }
.stat-card.auto-close    .stat-value { color: var(--class-auto-close); }
.stat-card.informational .stat-value { color: var(--class-informational); }

/* ── Raw counts bar ─────────────────────────────────────── */

.raw-counts {
  display: flex;
  gap: var(--sp-2);
  flex-wrap: wrap;
}
.raw-count-item {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 3px var(--sp-2);
}
.raw-count-item span {
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

/* ── Sweep metadata row ─────────────────────────────────── */

.sweep-meta {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--sp-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--fw-semibold);
  letter-spacing: .04em;
  text-transform: uppercase;
  white-space: nowrap;
}
.badge-blue   { background: var(--tint-blue);   color: var(--accent-blue); }
.badge-green  { background: var(--tint-green);  color: var(--accent-green); }
.badge-yellow { background: var(--tint-yellow); color: var(--accent-yellow); }
.badge-red    { background: var(--tint-red);    color: var(--accent-red); }
.badge-purple { background: var(--tint-purple); color: var(--accent-purple); }
.badge-muted  { background: var(--bg-hover);    color: var(--text-secondary); }

.sweep-time {
  font-size: var(--text-xs);
  color: var(--text-muted);
  font-family: var(--font-mono);
}

/* ── Sweep items list ───────────────────────────────────── */

.item-list {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
}

.triage-item {
  display: grid;
  grid-template-columns: 3px 1fr auto;
  gap: 0 var(--sp-3);
  align-items: start;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  min-width: 0;
  transition: border-color var(--dur);
}
.triage-item:hover { border-color: var(--border-light); }
.triage-item { cursor: pointer; }
.triage-item-selected { border-color: var(--accent-blue) !important; background: var(--accent-subtle); }

.triage-item-bar {
  grid-row: 1 / 4;
  align-self: stretch;
  width: 3px;
}
.bar-escalate     { background: var(--class-escalate); }
.bar-needs-human  { background: var(--class-needs-human); }
.bar-auto-close   { background: var(--class-auto-close); }
.bar-informational{ background: var(--class-informational); }

.triage-item-body {
  padding: var(--sp-3) 0;
  min-width: 0;
}

.triage-item-title {
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  color: var(--text-primary);
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.triage-item-meta {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--sp-1);
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.meta-chip {
  display: inline-flex; align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 1px 6px;
  overflow-wrap: anywhere;
}
.meta-chip.mono { font-family: var(--font-mono); font-size: 10px; }
.meta-chip.muted { color: var(--text-muted); }
.meta-chip.low { color: var(--accent-yellow); border-color: oklch(0.80 0.14 80 / 0.40); }

.triage-item-reason {
  font-size: var(--text-xs);
  color: var(--text-secondary);
  margin-top: var(--sp-1);
  line-height: 1.45;
  overflow-wrap: anywhere;
}
.triage-item-reason.action { color: var(--text-link); }

.triage-item-badges {
  padding: var(--sp-3) var(--sp-3) var(--sp-3) 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: var(--sp-1);
}
.confidence {
  font-size: 10px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}
.confidence.low { color: var(--accent-yellow); border-bottom: 1px dashed currentColor; }

/* severity colour helpers */
.sev-critical { color: var(--sev-critical); }
.sev-warning  { color: var(--sev-warning); }
.sev-info     { color: var(--sev-info); }

/* ── Approvals queue ────────────────────────────────────── */

.approval-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-3);
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-width: 0;
  transition: opacity var(--dur) var(--ease);
}
.approval-item + .approval-item { margin-top: var(--sp-2); }

.approval-info { flex: 1; min-width: 0; }

.approval-title {
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  overflow-wrap: anywhere;
}
.approval-title .title-text { overflow-wrap: anywhere; }
.approval-sub {
  font-size: var(--text-xs);
  color: var(--text-muted);
  margin-top: var(--sp-1);
  overflow-wrap: anywhere;
}

.approval-actions {
  display: flex;
  gap: var(--sp-2);
  flex-shrink: 0;
}

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: none;
  border-radius: var(--radius-sm);
  font-size: var(--text-sm);
  font-weight: var(--fw-semibold);
  padding: 0 var(--sp-3);
  min-height: var(--control-h);
  cursor: pointer;
  touch-action: manipulation;
  transition: background var(--dur), border-color var(--dur), opacity var(--dur), transform .1s;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-approve {
  background: var(--tint-green);
  color: var(--accent-green);
  border: 1px solid oklch(0.74 0.15 162 / 0.40);
  min-width: 64px;
}
.btn-approve:hover:not(:disabled) { background: oklch(0.74 0.15 162 / 0.22); }

.btn-reject {
  background: var(--tint-red);
  color: var(--accent-red);
  border: 1px solid oklch(0.64 0.20 25 / 0.40);
  min-width: 64px;
}
.btn-reject:hover:not(:disabled) { background: oklch(0.64 0.20 25 / 0.22); }

.btn-sweep {
  background: var(--accent-blue);
  color: var(--accent-fg);
  padding: 0 var(--sp-4);
  border-radius: var(--radius-md);
}
.btn-sweep:hover:not(:disabled) { background: var(--accent-hover); }
.btn-sweep:disabled { background: var(--bg-hover); color: var(--text-muted); opacity: 1; }

.btn-send {
  background: var(--accent-blue);
  color: var(--accent-fg);
  padding: 0 var(--sp-3);
  min-width: var(--control-h);
  align-self: flex-end;
}
.btn-send:hover:not(:disabled) { background: var(--accent-hover); }
.btn-send .i-stop { display: none; }
#app[data-streaming="1"] .btn-send .i-send { display: none; }
#app[data-streaming="1"] .btn-send .i-stop { display: inline; }

/* ── Profile block ──────────────────────────────────────── */

.profile-well {
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--edge-highlight);
  overflow: hidden;
}
.profile-text {
  font-size: var(--text-sm);
  color: var(--text-secondary);
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--font-mono);
  padding: var(--sp-3);
  max-height: 220px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}
.profile-text.collapsed { max-height: 140px; }
.profile-more {
  margin-top: var(--sp-2);
  background: none; border: none;
  color: var(--text-link);
  font-size: var(--text-xs); font-weight: var(--fw-semibold);
  cursor: pointer; padding: 4px 0;
  touch-action: manipulation;
}

/* ── Chat panel ─────────────────────────────────────────── */

#chat-header {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-4);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-panel);
}
.chat-title-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-right: auto;
  min-width: 0;
}
.chat-title {
  font-size: var(--text-xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--text-secondary);
}
.chat-ticket-label {
  font-size: var(--text-xs);
  color: var(--text-primary);
  font-weight: var(--fw-medium);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 220px;
}

#ws-status, .ws-chip {
  font-size: var(--text-xs);
  font-weight: var(--fw-medium);
  padding: 3px var(--sp-2);
  border-radius: var(--radius-full);
  display: inline-flex; align-items: center; gap: 5px;
  white-space: nowrap;
}
.ws-chip::before {
  content: ""; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor;
}
#ws-status.connecting { background: var(--tint-yellow); color: var(--accent-yellow); }
#ws-status.open       { background: var(--tint-green);  color: var(--accent-green); }
#ws-status.closed     { background: var(--tint-red);    color: var(--sev-critical); }
#ws-status.error      { background: var(--tint-red);    color: var(--sev-critical); }
#ws-status.degraded   { background: var(--tint-purple); color: var(--accent-purple); }

#messages-wrap {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
}
#messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.scroll-fab {
  position: absolute;
  bottom: var(--sp-3); left: 50%;
  transform: translateX(-50%) translateY(8px);
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--bg-raised);
  border: 1px solid var(--border-light);
  color: var(--text-primary);
  border-radius: var(--radius-full);
  padding: 6px var(--sp-3);
  font-size: var(--text-xs); font-weight: var(--fw-semibold);
  box-shadow: var(--shadow-md);
  cursor: pointer;
  opacity: 0; pointer-events: none;
  transition: opacity var(--dur), transform var(--dur) var(--ease);
  touch-action: manipulation;
}
.scroll-fab.show { opacity: 1; pointer-events: auto; transform: translateX(-50%) translateY(0); }

.msg {
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-width: 90%;
  min-width: 0;
}
.msg.user { align-self: flex-end; align-items: flex-end; max-width: 85%; }
.msg.assistant { align-self: stretch; max-width: 100%; }
.msg.system, .msg.error-msg { align-self: center; max-width: 92%; }

.msg-role {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: var(--tracking-label);
  color: var(--text-muted);
  padding: 0 var(--sp-1);
}

.msg-bubble {
  padding: var(--sp-2) var(--sp-3);
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  line-height: 1.55;
  overflow-wrap: anywhere;
  min-width: 0;
}

.msg.user .msg-bubble {
  background: var(--accent-subtle);
  border: 1px solid oklch(0.62 0.17 250 / 0.35);
  color: var(--text-primary);
  border-radius: var(--radius-lg) var(--radius-lg) var(--radius-sm) var(--radius-lg);
  white-space: pre-wrap;
}

.msg.assistant .msg-bubble {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-primary);
  padding-inline: var(--sp-1);
  border-radius: var(--radius-md);
  transition: background var(--dur);
}
.msg.assistant:hover .msg-bubble { background: var(--bg-card); border-color: var(--border-subtle); }
.msg.assistant .msg-bubble.streaming { white-space: pre-wrap; }

.msg.system .msg-bubble {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: var(--text-xs);
  font-style: italic;
  text-align: center;
}

.msg.error-msg .msg-bubble {
  background: var(--tint-red);
  border: 1px solid oklch(0.64 0.20 25 / 0.30);
  color: var(--sev-critical);
  font-size: var(--text-xs);
}

/* markdown inside assistant bubbles */
.md p { margin: 0 0 .5em; }
.md p:last-child { margin-bottom: 0; }
.md ul, .md ol { margin: .25em 0 .5em; padding-left: 1.3em; }
.md li { margin: .15em 0; }
.md a { color: var(--text-link); overflow-wrap: anywhere; }
.md strong { font-weight: var(--fw-semibold); }
.md code.inline {
  background: var(--bg-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 1px 5px;
  font-family: var(--font-mono);
  font-size: 0.85em;
  overflow-wrap: anywhere;
}
.code-block {
  position: relative;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin: .5em 0;
  overflow: hidden;
}
.code-block .code-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 4px var(--sp-2);
  border-bottom: 1px solid var(--border-subtle);
  background: var(--bg-base);
}
.code-block .code-lang {
  font-size: 10px; text-transform: uppercase; letter-spacing: var(--tracking-label);
  color: var(--text-muted); font-family: var(--font-mono);
}
.copy-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: var(--text-xs); cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 6px; border-radius: var(--radius-sm);
  touch-action: manipulation;
  transition: color var(--dur), background var(--dur);
}
.copy-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.code-block pre {
  margin: 0; padding: var(--sp-2) var(--sp-3);
  overflow-x: auto; -webkit-overflow-scrolling: touch;
}
.code-block code {
  font-family: var(--font-mono); font-size: 0.82rem; line-height: 1.5;
  color: var(--text-primary); white-space: pre;
}

/* streaming caret (replaces ▋) */
.streaming::after {
  content: ""; display: inline-block; width: 2px; height: 1.05em; margin-left: 2px;
  background: var(--accent-blue); vertical-align: text-bottom;
  animation: caret 1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }

/* chat empty state + suggestion chips */
.chat-empty {
  margin: auto;
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-3);
  padding: var(--sp-6) var(--sp-4); text-align: center;
  color: var(--text-muted);
}
.chat-empty .icon svg { color: var(--text-muted); }
.suggestion-chips { display: flex; flex-wrap: wrap; gap: var(--sp-2); justify-content: center; }
.suggestion-chip {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-full);
  padding: 8px var(--sp-3);
  font-size: var(--text-xs);
  cursor: pointer;
  min-height: var(--control-h);
  touch-action: manipulation;
  transition: background var(--dur), color var(--dur), border-color var(--dur);
}
.suggestion-chip:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border-light); }

#chat-input-row {
  display: flex;
  gap: var(--sp-2);
  align-items: flex-end;
  padding: var(--sp-3);
  padding-bottom: max(var(--sp-3), env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  flex-shrink: 0;
}

#chat-input {
  flex: 1;
  min-width: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: var(--text-sm);
  line-height: 1.4;
  padding: 10px var(--sp-3);
  resize: none;
  outline: none;
  transition: border-color var(--dur);
  min-height: var(--control-h-touch);
  max-height: 200px;
}
#chat-input:focus { border-color: var(--border-light); }
#chat-input::placeholder { color: var(--text-muted); }

/* ── Empty / loading states ─────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: var(--sp-8) var(--sp-4);
  color: var(--text-muted);
  font-size: var(--text-sm);
  text-align: center;
}
.empty-state .icon { color: var(--text-muted); opacity: .7; display: inline-flex; }
.empty-state .icon svg { display: block; }

/* skeleton loaders */
.skeleton {
  background:
    linear-gradient(100deg, var(--bg-subtle) 30%, var(--bg-hover) 50%, var(--bg-subtle) 70%) var(--bg-subtle);
  background-size: 200% 100%;
  border-radius: var(--radius-sm);
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.skel-stat { height: 78px; border-radius: var(--radius-md); }
.skel-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.skel-row { height: 56px; }

/* scrollbar styling */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: var(--radius-full); }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* error banner */
.error-banner {
  background: var(--tint-red);
  border: 1px solid oklch(0.64 0.20 25 / 0.30);
  border-radius: var(--radius-md);
  color: var(--sev-critical);
  font-size: var(--text-xs);
  padding: var(--sp-2) var(--sp-3);
  overflow-wrap: anywhere;
}

/* chat post-fallback note */
.fallback-note {
  font-size: 10px;
  color: var(--text-muted);
  text-align: center;
  padding: 4px 0;
  font-style: italic;
}

/* spinner (kept for inline button states) */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid var(--border-light);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Global overflow guards ─────────────────────────────── */

#main, #ops-board, #chat-panel, .panel, .triage-item, .msg, .msg-bubble { min-width: 0; }
.msg-bubble, .triage-item-reason { overflow-wrap: anywhere; }
pre, code { overflow-wrap: normal; }
.profile-text { overflow-x: auto; max-width: 100%; -webkit-overflow-scrolling: touch; }

/* ── Phone-only adjustments (< 720px) ───────────────────── */

@media (max-width: 719px) {
  .tenant-selector { flex: 1 1 100%; }
  .tenant-selector label { display: none; }
  #tenant-input { flex: 1; width: auto; height: var(--control-h-touch); }
  #apply-tenant {
    height: var(--control-h-touch);
    width: var(--control-h-touch);
    padding: 0;
  }
  #apply-tenant .i { display: inline; }
  #apply-tenant .apply-label { display: none; }
  .btn { min-height: var(--control-h-touch); }
  .icon-btn, #btn-profile-copy { width: var(--control-h-touch); height: var(--control-h-touch); }
  /* lift composer by keyboard height if interactive-widget meta wasn't honored */
  #chat-input-row { transform: translateY(calc(-1 * var(--kb))); transition: transform .15s; }
}

/* mobile triage card reflow (< 640px) */
@media (max-width: 639px) {
  .triage-item { grid-template-columns: 3px 1fr; }
  .triage-item-badges {
    grid-column: 2;
    flex-direction: row;
    align-items: center;
    padding: 0 var(--sp-3) var(--sp-3);
  }
  .approval-item { flex-direction: column; align-items: stretch; }
  .approval-actions { display: flex; }
  .approval-actions .btn { flex: 1; min-height: var(--control-h-touch); }
}

/* ── Tablet: board full width, chat as off-canvas drawer ── */
@media (min-width: 720px) {
  #app { grid-template-areas: "topbar" "surface"; grid-template-rows: auto 1fr; }
  #tabbar { display: none; }
  #ops-board { display: flex; }
  #btn-chat-toggle { display: inline-flex; }
  #chat-panel {
    position: fixed; inset: 0 0 0 auto;
    width: min(380px, 92vw);
    transform: translateX(100%);
    transition: transform .25s var(--ease);
    border-left: 1px solid var(--border);
    background: var(--bg-panel);
    z-index: 60;
    display: flex;
    box-shadow: var(--shadow-lg);
    padding-bottom: env(safe-area-inset-bottom);
  }
  #app[data-chat="open"] #chat-panel { transform: translateX(0); }
  .chat-close-btn { display: inline-flex; }
  #chat-scrim {
    position: fixed; inset: 0; background: oklch(0 0 0 / 0.45);
    opacity: 0; pointer-events: none; transition: opacity .25s; z-index: 55;
  }
  #app[data-chat="open"] #chat-scrim { opacity: 1; pointer-events: auto; }
  #app[data-chat="open"] { overflow: hidden; }
}

/* ── Desktop: true two-pane, fixed chat rail ────────────── */
@media (min-width: 1024px) {
  #main { grid-template-columns: 1fr 380px; }
  #ops-board { grid-column: 1; padding: var(--sp-5); }
  #chat-panel {
    position: static; transform: none; width: auto;
    grid-column: 2; grid-row: 1;
    border-left: 1px solid var(--border);
    z-index: auto; box-shadow: none;
    display: flex;
  }
  #chat-scrim { display: none; }
  .chat-close-btn, #btn-chat-toggle { display: none; }
}

/* small phones: shorten logo to mark + dot under 480px */
@media (max-width: 479px) {
  .logo-full { display: none; }
  .logo-mark { display: inline; }
}
