/* COS Monitor — HyperTree Cognitive OS */

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

:root {
  /* Modern light surface system — calm neutrals with a slight cool bias */
  --bg:       #f7f7f8;   /* app ground */
  --bg1:      #ffffff;   /* sidebar / header / raised */
  --bg2:      #ffffff;   /* cards */
  --bg3:      #f1f2f4;   /* insets, hover, code */
  --border:   #e9e9ee;
  --border2:  #dddde4;

  --text:     #1b1c1f;
  --text1:    #1b1c1f;
  --text2:    #6b6d76;

  /* Accent = a refined emerald (their green identity, modernised) */
  --green:    #0d9373;
  --green-dim:#7dc7b1;
  --green-bg: #e7f6f0;
  --amber:    #b7791f;
  --amber-dim:#e6c98a;
  --amber-bg: #fbf1dd;
  --red:      #d6353f;
  --red-dim:  #eaa6aa;
  --red-bg:   #fbe6e7;
  --blue:     #2f6bff;
  --blue-dim: #a9c1ff;
  --blue-bg:  #e8efff;
  --purple:   #7c5cff;
  --purple-bg:#eee9ff;

  --accent:      #0d9373;
  --accent-hover:#0a7d61;

  --mono:     'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
  --sans:     'Manrope', -apple-system, BlinkMacSystemFont, 'Segoe UI',
              Roboto, Helvetica, Arial, sans-serif;
  --heading:  'Space Grotesk', var(--sans);

  --radius:    14px;
  --radius-sm: 9px;

  --shadow-sm: 0 1px 2px rgba(17,18,20,0.05);
  --shadow-md: 0 2px 8px rgba(17,18,20,0.06), 0 1px 2px rgba(17,18,20,0.04);
  --shadow-lg: 0 12px 34px rgba(17,18,20,0.10);

  --header-h: 56px;
  --sidebar-w: 280px;
}

html { height: 100%; }

body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow: hidden; /* desktop: no body scroll, sections scroll individually */
}

/* ── Header ─────────────────────────────────────────────────────── */
.cos-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: var(--header-h);
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 300;
  flex-shrink: 0;
}

.cos-header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Mobile sidebar toggle */
.cos-sidebar-toggle {
  display: none;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: var(--radius-sm);
  width: 30px; height: 30px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color .15s, color .15s;
}
.cos-sidebar-toggle:hover { border-color: var(--accent); color: var(--accent); }
@media (max-width: 767px) { .cos-sidebar-toggle { display: flex; } }

.cos-back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text2);
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}
.cos-back-btn:hover { border-color: var(--accent); color: var(--accent); }

.cos-brand {
  font-family: var(--heading);
  font-size: 16px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 0.05em;
}

.cos-brand-sub {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text2);
  display: none;
}
@media (min-width: 900px) { .cos-brand-sub { display: inline; } }

.cos-status-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  overflow: hidden;
  min-width: 0;
}

.cos-stat {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
}

.cos-stat-label {
  color: var(--text2);
  font-size: 10px;
  margin-right: 2px;
}

.cos-stat-sep {
  color: var(--border2);
  margin: 0 4px;
}

/* Hide less critical stats on small screens */
@media (max-width: 599px) {
  .cos-stat-sep,
  .cos-stat:not(#stat-kernel) { display: none; }
  #stat-tick { display: flex; }
}

.cos-stat-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text2);
  transition: background 0.3s;
  flex-shrink: 0;
}
.cos-stat-dot.ready    { background: var(--green); box-shadow: 0 0 6px var(--green); }
.cos-stat-dot.building { background: var(--amber); box-shadow: 0 0 6px var(--amber); }
.cos-stat-dot.error    { background: var(--red); }

.cos-tick-btn {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text2);
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}
.cos-tick-btn:hover   { border-color: var(--accent); color: var(--accent); }
.cos-tick-btn:disabled { opacity: 0.4; cursor: default; }

#tick-status {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--green);
  min-width: 50px;
}

.cos-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.cos-refresh-label {
  font-size: 11px;
  color: var(--text2);
  display: none;
}
@media (min-width: 640px) { .cos-refresh-label { display: inline; } }

.cos-toggle { position: relative; display: inline-block; width: 32px; height: 18px; }
.cos-toggle input { opacity: 0; width: 0; height: 0; }
.cos-toggle-slider {
  position: absolute; inset: 0;
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: 18px; cursor: pointer; transition: 0.2s;
}
.cos-toggle-slider::before {
  content: '';
  position: absolute;
  width: 12px; height: 12px;
  left: 2px; top: 2px;
  background: var(--text2);
  border-radius: 50%;
  transition: 0.2s;
}
.cos-toggle input:checked + .cos-toggle-slider { background: var(--green-dim); border-color: var(--green); }
.cos-toggle input:checked + .cos-toggle-slider::before { transform: translateX(14px); background: var(--green); }

/* ── Shell layout — desktop: fixed sidebar + scrollable main ─────── */
.cos-shell {
  display: flex;
  height: calc(100vh - var(--header-h));
  margin-top: var(--header-h);
  overflow: hidden;
}

/* ── Sidebar ─────────────────────────────────────────────────────── */
.cos-sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  overflow-y: auto;
  overflow-x: hidden;
  background: var(--bg1);
  /* Desktop: normal in-flow */
}

/* Mobile: off-canvas drawer */
@media (max-width: 767px) {
  .cos-sidebar {
    position: fixed;
    left: 0;
    top: var(--header-h);
    height: calc(100vh - var(--header-h));
    width: min(var(--sidebar-w), 88vw);
    z-index: 250;
    transform: translateX(-110%);
    transition: transform 0.25s cubic-bezier(.4,0,.2,1);
    box-shadow: 4px 0 24px rgba(0,0,0,.5);
  }
  .cos-sidebar.open {
    transform: translateX(0);
  }
}

/* Overlay that closes the mobile sidebar */
.cos-sidebar-overlay {
  display: none;
  position: fixed;
  inset: var(--header-h) 0 0 0;
  background: rgba(0,0,0,.55);
  z-index: 240;
  backdrop-filter: blur(2px);
}
.cos-sidebar-overlay.open { display: block; }

/* ── Main column ─────────────────────────────────────────────────── */
.cos-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  /* Scroll is here on desktop; body scrolls on mobile */
}

/* Mobile: main is just a normal flow, body handles scroll */
@media (max-width: 767px) {
  body { overflow: auto; }
  .cos-shell {
    height: auto;
    min-height: calc(100vh - var(--header-h));
    overflow: visible;
  }
  .cos-main { overflow: visible; }
}

/* ── Cards ───────────────────────────────────────────────────────── */
.cos-card {
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
}

.cos-card-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
  flex-wrap: wrap;
}

.cos-card-title {
  font-family: var(--heading);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.cos-card-sub {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text2);
}

/* ── Layer Grid ──────────────────────────────────────────────────── */
.cos-layer-grid {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cos-layer-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 5px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.1s;
  border: 1px solid transparent;
}
.cos-layer-row:hover  { background: var(--bg2); border-color: var(--border); }
.cos-layer-row.active { background: var(--bg3); border-color: var(--accent); }

.cos-layer-id {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text2);
  width: 20px;
  flex-shrink: 0;
}

.cos-layer-name {
  font-size: 11px;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cos-layer-bar-wrap { width: 50px; flex-shrink: 0; }
.cos-layer-bar-bg {
  background: var(--bg3);
  border-radius: 2px;
  height: 4px;
  overflow: hidden;
}
.cos-layer-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.4s ease;
}

.cos-layer-count {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text2);
  width: 28px;
  text-align: right;
  flex-shrink: 0;
}

.cos-layer-status {
  font-size: 9px;
  font-weight: 600;
  padding: 1px 4px;
  border-radius: 2px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  flex-shrink: 0;
}
.cos-layer-status.active   { background: #00e87a18; color: var(--green);  border: 1px solid #00e87a40; }
.cos-layer-status.partial  { background: #ffaa0018; color: var(--amber);  border: 1px solid #ffaa0040; }
.cos-layer-status.planned  { background: #44444418; color: var(--text2);  border: 1px solid var(--border); }
.cos-layer-status.dynamic  { background: #aa66ff18; color: var(--purple); border: 1px solid #aa66ff40; }

/* ── Node Browser ────────────────────────────────────────────────── */
.cos-card-browser {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 200px;
}

.cos-browser-controls {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
}

.cos-search-input {
  flex: 1;
  min-width: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 8px;
  outline: none;
  transition: border-color 0.15s;
}
.cos-search-input:focus { border-color: var(--accent); }
.cos-search-input::placeholder { color: var(--text2); }

.cos-select {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 10px;
  padding: 6px 6px;
  outline: none;
  cursor: pointer;
  max-width: 90px;
}

.cos-node-list {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.cos-node-item {
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: border-color 0.1s, background 0.1s;
}
.cos-node-item:hover { border-color: var(--accent); background: var(--bg2); }

.cos-node-item-hdr {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
}

.cos-node-epistemic {
  font-size: 10px;
  font-family: var(--mono);
  flex-shrink: 0;
}
.cos-node-epistemic.Verified   { color: var(--green); }
.cos-node-epistemic.Likely     { color: #88cc88; }
.cos-node-epistemic.Hypothesis { color: var(--amber); }
.cos-node-epistemic.Unknown    { color: var(--text2); }
.cos-node-epistemic.Rejected   { color: var(--red); }
.cos-node-epistemic.Deprecated { color: var(--text2); }

.cos-node-label {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 500;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.cos-node-conf {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text2);
  flex-shrink: 0;
}

.cos-node-layer-tag {
  font-size: 9px;
  color: var(--text2);
  font-family: var(--mono);
}

/* ── Prompt card — the most important section ────────────────────── */
.cos-card-prompt {
  display: flex;
  flex-direction: column;
  /* Minimum so chat is always readable — grows to fill remaining space */
  min-height: clamp(340px, 45vh, 600px);
  flex-shrink: 0;
  border-bottom: 2px solid rgba(0,232,122,.18);
}

.cos-prompt-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.cos-meta-badge {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text2);
  background: var(--bg3);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
}

.cos-clear-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text2);
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 3px;
  cursor: pointer;
  margin-left: auto;
  transition: all 0.15s;
}
.cos-clear-btn:hover { border-color: var(--red); color: var(--red); }

/* Chat area */
.cos-chat {
  flex: 1;
  min-height: 160px;
  overflow-y: auto;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  /* Smooth scroll to latest message */
  scroll-behavior: smooth;
}

.cos-chat-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 20px;
  opacity: 0.5;
  padding: 24px;
}

.cos-tree-ascii {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--green);
  white-space: pre;
  line-height: 1.6;
}

.cos-chat-hint {
  font-size: 13px;
  color: var(--text2);
  text-align: center;
  line-height: 1.6;
}

/* Prompt input row */
.cos-prompt-input-row {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding: 10px 0 2px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
}

.cos-prompt-wrap { flex: 1; min-width: 0; }

.cos-prompt-input {
  width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--mono);
  font-size: 13px;
  padding: 10px 14px;
  outline: none;
  resize: none;
  line-height: 1.5;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.cos-prompt-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(0,232,122,.1);
}
.cos-prompt-input::placeholder { color: var(--text2); }

.cos-send-btn {
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #000;
  cursor: pointer;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.15s, transform 0.1s;
  font-weight: 700;
}
.cos-send-btn:hover  { opacity: 0.85; }
.cos-send-btn:active { transform: scale(0.95); }
.cos-send-btn:disabled { opacity: 0.3; cursor: default; }

.cos-session-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding-top: 8px;
  font-size: 11px;
}
.cos-meta-label    { color: var(--text2); font-family: var(--mono); font-size: 10px; }
.cos-session-id    { font-family: var(--mono); font-size: 10px; color: var(--text2); }
.cos-new-session-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text2);
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 3px;
  cursor: pointer;
  margin-left: auto;
  transition: all 0.15s;
}
.cos-new-session-btn:hover { border-color: var(--blue); color: var(--blue); }

/* Chat messages */
.cos-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cos-msg-user {
  align-self: flex-end;
  align-items: flex-end;
  max-width: min(78%, 560px);
}
.cos-msg-user .cos-msg-bubble {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius) var(--radius) 4px var(--radius);
  padding: 10px 15px;
  font-size: 14px;
  line-height: 1.55;
  width: fit-content;
  max-width: 100%;
  overflow-wrap: break-word;
  word-break: normal;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

.cos-msg-assistant {
  align-self: flex-start;
  width: 100%;
  max-width: 100%;
}
.cos-msg-assistant .cos-msg-bubble {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  padding: 12px 16px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.75;
  overflow-wrap: break-word;
  word-break: normal;
  color: var(--text);
}
.cos-msg-assistant .cos-msg-bubble .bar-hi  { color: var(--green); }
.cos-msg-assistant .cos-msg-bubble .bar-med { color: var(--amber); }
.cos-msg-assistant .cos-msg-bubble .bar-lo  { color: var(--red); }

.cos-msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text2);
  padding: 0 4px;
}
.cos-msg-meta .tag-intent  { color: var(--blue); }
.cos-msg-meta .tag-latency { color: var(--text2); }
.cos-msg-meta .tag-nodes   { color: var(--green-dim); }
.cos-msg-meta .tag-model   { color: var(--purple); }

/* Typing indicator */
.cos-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  width: fit-content;
}
.cos-typing span {
  width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
  animation: cos-bounce 1s infinite;
  opacity: 0.4;
}
.cos-typing span:nth-child(2) { animation-delay: 0.2s; }
.cos-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes cos-bounce {
  0%, 100% { opacity: 0.2; transform: translateY(0); }
  50%       { opacity: 1;   transform: translateY(-4px); }
}

/* ── Code blocks in chat ──────────────────────────────────────────── */
.cos-code-block {
  position: relative;
  background: #0a0a14;
  border: 1px solid var(--border2);
  border-radius: 6px;
  margin: 10px 0;
  overflow: hidden;
}
.cos-code-lang {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text2);
  padding: 5px 12px 4px;
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.cos-code-pre {
  margin: 0;
  padding: 14px 16px;
  overflow-x: auto;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.65;
  color: #e8e8f8;
  white-space: pre;
  tab-size: 4;
}
.cos-code-pre code { color: inherit; background: none; }
.cos-code-copy {
  position: absolute;
  top: 6px;
  right: 10px;
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text2);
  border-radius: 4px;
  padding: 3px 8px;
  font-size: 10px;
  cursor: pointer;
  font-family: var(--mono);
  opacity: 0;
  transition: opacity .15s;
}
.cos-code-block:hover .cos-code-copy { opacity: 1; }
.cos-code-copy:hover { border-color: var(--green); color: var(--green); }

/* Chat bubble pre-wrap.
   overflow-wrap (not word-break:break-word) so a shrink-to-fit bubble's
   min-content width stays word-sized — word-break:break-word collapses it to
   one character, which stacked short messages like "hey" vertically. */
.cos-msg-bubble {
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
}

/* ── Bottom row: DAG + Activity ──────────────────────────────────── */
.cos-bottom-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex-shrink: 0;
  border-top: 1px solid var(--border);
}

.cos-card-dag,
.cos-card-activity {
  overflow-y: auto;
  border-bottom: none;
  min-height: 180px;
  max-height: 260px;
}
.cos-card-dag { border-right: 1px solid var(--border); }

.cos-dag-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cos-dag-edge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 10px;
  padding: 3px 4px;
  border-radius: 3px;
  transition: background 0.1s;
}
.cos-dag-edge:hover { background: var(--bg2); }
.cos-dag-src { color: var(--blue);  max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cos-dag-rel { color: var(--text2); flex-shrink: 0; }
.cos-dag-tgt { color: var(--green); max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cos-dag-w   { color: var(--text2); font-size: 9px; flex-shrink: 0; }

.cos-activity-feed {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.cos-event {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-family: var(--mono);
  font-size: 10px;
  padding: 4px 4px;
  border-radius: 3px;
  transition: background 0.1s;
}
.cos-event:hover { background: var(--bg2); }

.cos-event-type {
  flex-shrink: 0;
  padding: 1px 5px;
  border-radius: 2px;
  font-size: 9px;
  font-weight: 600;
  text-transform: uppercase;
}
.cos-event-type.prompt_processed       { background: #4488ff22; color: var(--blue);   border: 1px solid #4488ff44; }
.cos-event-type.environment_collected  { background: #00e87a22; color: var(--green);  border: 1px solid #00e87a44; }
.cos-event-type.hypertree_updated      { background: #aa66ff22; color: var(--purple); border: 1px solid #aa66ff44; }
.cos-event-type.layer_spawned          { background: #ffaa0022; color: var(--amber);  border: 1px solid #ffaa0044; }
.cos-event-type.optimisation_complete  { background: #ff446622; color: var(--red);    border: 1px solid #ff446644; }
.cos-event-type.default { background: var(--bg3); color: var(--text2); border: 1px solid var(--border); }

.cos-event-body { flex: 1; color: var(--text2); line-height: 1.4; }
.cos-event-time { flex-shrink: 0; color: #444466; font-size: 9px; }

/* ── Epistemic trees row ─────────────────────────────────────────── */
.cos-epistemic-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid var(--border);
}

.cos-card-epi,
.cos-card-experiments,
.cos-card-changelog {
  display: flex;
  flex-direction: column;
  min-height: 200px;
  max-height: 300px;
  border-bottom: none;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.cos-epi-list,
.cos-exp-list,
.cos-cl-list {
  overflow-y: auto;
  flex: 1;
  padding: 6px 0;
}

.cos-epi-title   { font-size: 11px; font-weight: 700; letter-spacing: .04em; }
.cos-epi-hypo    { color: var(--amber); }
.cos-epi-verified { color: var(--green); }
.cos-epi-rejected { color: var(--red); }

.cos-card-hypo     { border-color: rgba(255,170,0,.28); }
.cos-card-verified { border-color: rgba(0,232,122,.28); }
.cos-card-rejected { border-color: rgba(255,68,102,.28); }

.cos-epi-item {
  display: flex;
  align-items: flex-start;
  gap: 6px;
  padding: 5px 10px;
  cursor: pointer;
  border-radius: 4px;
  transition: background .1s;
}
.cos-epi-item:hover { background: var(--bg3); }

.cos-epi-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  margin-top: 5px;
  flex-shrink: 0;
}
.dot-hypo     { background: var(--amber); }
.dot-verified { background: var(--green); }
.dot-rejected { background: var(--red); }

.cos-epi-info  { flex: 1; min-width: 0; }
.cos-epi-label {
  font-size: 11px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cos-epi-reason {
  font-size: 10px;
  color: var(--text2);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cos-epi-conf {
  font-size: 10px;
  font-family: var(--mono);
  flex-shrink: 0;
  opacity: .7;
}

/* ── Experiments + Changelog row ─────────────────────────────────── */
.cos-experiment-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 0 12px 10px;
}

/* Experiment items */
.cos-exp-item {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.cos-exp-item:hover { background: var(--bg3); }
.cos-exp-header { display: flex; align-items: center; gap: 6px; }
.cos-exp-status {
  font-size: 9px;
  font-family: var(--mono);
  padding: 1px 5px;
  border-radius: 3px;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.status-running   { background: rgba(255,170,0,.2);  color: var(--amber); }
.status-solved    { background: rgba(0,232,122,.2);  color: var(--green); }
.status-abandoned { background: rgba(255,68,102,.2); color: var(--red); }

.cos-exp-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.cos-exp-attempts { font-size: 10px; color: var(--text2); font-family: var(--mono); }
.cos-exp-goal {
  font-size: 10px;
  color: var(--text2);
  margin-top: 3px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Changelog items */
.cos-cl-item {
  display: flex;
  gap: 8px;
  padding: 5px 10px;
  border-bottom: 1px solid var(--border);
  align-items: flex-start;
}
.cos-cl-type {
  font-size: 9px;
  font-family: var(--mono);
  padding: 1px 5px;
  border-radius: 3px;
  flex-shrink: 0;
  margin-top: 1px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.cl-promoted          { background: rgba(0,232,122,.15);  color: var(--green); }
.cl-rejected          { background: rgba(255,68,102,.15); color: var(--red); }
.cl-created           { background: rgba(68,136,255,.15); color: var(--blue); }
.cl-experiment_solved { background: rgba(170,102,255,.15);color: var(--purple); }
.cl-hypothesis_added  { background: rgba(255,170,0,.12);  color: var(--amber); }
.cl-state_change      { background: rgba(255,255,255,.08);color: var(--text2); }
.cl-experiment_created{ background: rgba(68,136,255,.12); color: var(--blue); }

.cos-cl-summary {
  font-size: 11px;
  color: var(--text);
  flex: 1;
  line-height: 1.4;
}

/* ── Health & Timeline panel ─────────────────────────────────────── */
.cos-card-health {
  border-color: rgba(120,160,255,.22);
  margin: 0 12px 16px;
  border: 1px solid rgba(120,160,255,.22);
  border-radius: var(--radius);
}
.cos-health-body { padding: 4px 0 0; }
.cos-health-score-row {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.cos-health-score {
  font-size: 2.6rem;
  font-weight: 700;
  font-family: var(--mono);
  color: var(--green);
  min-width: 56px;
  line-height: 1;
}
.cos-health-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text2);
}
.cos-health-summary {
  font-size: 12px;
  color: var(--text2);
  flex: 1;
  min-width: 160px;
  line-height: 1.5;
}
.cos-health-stats {
  display: flex;
  gap: 18px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  font-size: 11px;
  color: var(--text2);
}
.cos-health-stat { display: flex; flex-direction: column; gap: 2px; }
.cos-health-stat-val {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text1);
  font-weight: 600;
}
.cos-health-stat-key { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; }

.cos-milestone-list { display: flex; flex-direction: column; gap: 8px; }
.cos-milestone {
  display: grid;
  grid-template-columns: 130px 1fr 100px;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 6px;
  background: var(--bg3);
  border: 1px solid var(--border2);
}
.cos-milestone.ms-reached { border-color: rgba(0,232,122,.3); }
.cos-milestone.ms-pending  { border-color: rgba(255,170,0,.2); }
.cos-ms-label { font-size: 11px; font-weight: 600; color: var(--text1); }
.cos-ms-desc  { font-size: 10.5px; color: var(--text2); }
.cos-ms-eta {
  font-size: 11px;
  font-family: var(--mono);
  text-align: right;
  color: var(--text2);
}
.cos-ms-eta.eta-reached { color: var(--green); font-weight: 700; }
.cos-ms-eta.eta-pending  { color: rgba(255,170,0,.85); }

/* ── Node / Experiment Modals ─────────────────────────────────────── */
.cos-modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.72);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.cos-modal-overlay.open { display: flex; }

.cos-modal {
  background: var(--bg1);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  width: min(600px, 95vw);
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 24px 80px rgba(0,0,0,.6);
}

.cos-modal-hdr {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.cos-modal-title {
  font-family: var(--heading);
  font-size: 14px;
  font-weight: 600;
  color: var(--accent);
}

.cos-modal-close {
  background: none;
  border: none;
  color: var(--text2);
  font-size: 14px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 3px;
  transition: color 0.15s;
  line-height: 1;
}
.cos-modal-close:hover { color: var(--red); }

.cos-modal-body {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
  font-family: var(--mono);
  font-size: 11px;
  line-height: 1.7;
  white-space: pre-wrap;
  color: var(--text);
}

/* Form */
.cos-form-label {
  display: block;
  font-size: 10px;
  font-family: var(--mono);
  color: var(--text2);
  margin: 12px 0 4px;
  text-transform: uppercase;
  letter-spacing: .06em;
}
.cos-form-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border2);
  border-radius: 4px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  padding: 7px 10px;
  outline: none;
}
.cos-form-input:focus { border-color: var(--green); }
.cos-form-textarea { min-height: 80px; resize: vertical; }
.cos-btn-primary {
  margin-top: 14px;
  background: var(--green);
  color: #000;
  border: none;
  border-radius: 4px;
  padding: 8px 16px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}
.cos-btn-primary:hover { opacity: .85; }
.cos-btn-sm {
  background: var(--bg3);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 10px;
  cursor: pointer;
  margin-left: auto;
  white-space: nowrap;
}
.cos-btn-sm:hover { border-color: var(--green); color: var(--green); }
.cos-modal-exp { max-width: 460px; }

/* ── Scrollbar ───────────────────────────────────────────────────── */
::-webkit-scrollbar        { width: 5px; height: 5px; }
::-webkit-scrollbar-track  { background: transparent; }
::-webkit-scrollbar-thumb  { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }

/* ── Utilities ───────────────────────────────────────────────────── */
.text-green  { color: var(--green); }
.text-amber  { color: var(--amber); }
.text-red    { color: var(--red); }
.text-blue   { color: var(--blue); }
.text-purple { color: var(--purple); }
.text-dim    { color: var(--text2); }

.cos-empty-state {
  padding: 20px;
  text-align: center;
  color: var(--text2);
  font-family: var(--mono);
  font-size: 11px;
  opacity: 0.6;
}

/* ── Responsive breakpoints ──────────────────────────────────────── */

/* Tablet (768–1023px): narrow sidebar, 2-col epistemic */
@media (min-width: 768px) and (max-width: 1023px) {
  :root { --sidebar-w: 220px; }
  .cos-epistemic-row {
    grid-template-columns: 1fr 1fr;
  }
  .cos-bottom-row .cos-card-dag,
  .cos-bottom-row .cos-card-activity {
    max-height: 220px;
  }
}

/* Mobile (<768px): single column, off-canvas sidebar */
@media (max-width: 767px) {
  body { overflow-y: auto; }
  html { height: auto; }

  .cos-shell {
    height: auto;
    min-height: calc(100vh - var(--header-h));
    overflow: visible;
    flex-direction: column;
  }

  /* Main fills full width */
  .cos-main {
    width: 100%;
    overflow: visible;
    flex: 1;
  }

  /* Prompt: compact but still usable */
  .cos-card-prompt {
    min-height: clamp(280px, 60vh, 500px);
  }

  /* Bottom row: stack */
  .cos-bottom-row {
    grid-template-columns: 1fr;
    height: auto;
  }
  .cos-card-dag   { border-right: none; max-height: 200px; }
  .cos-card-activity { max-height: 200px; }

  /* Epistemic: stack */
  .cos-epistemic-row {
    grid-template-columns: 1fr;
    padding: 8px;
    gap: 8px;
  }
  .cos-card-epi { min-height: 160px; max-height: 240px; }

  /* Exp/changelog: stack */
  .cos-experiment-row {
    grid-template-columns: 1fr;
    padding: 0 8px 8px;
  }

  /* Health: full bleed on mobile */
  .cos-card-health {
    margin: 0 8px 16px;
  }
  .cos-milestone {
    grid-template-columns: 1fr auto;
  }
  .cos-ms-desc { display: none; }

  /* Header: tighter */
  .cos-header { padding: 0 12px; gap: 8px; }
}

/* Very small (<400px) */
@media (max-width: 399px) {
  .cos-brand-sub { display: none; }
  .cos-card { padding: 12px 12px; }
  .cos-card-prompt { min-height: clamp(240px, 55vh, 400px); }
  .cos-health-score { font-size: 2rem; }
}

/* ── Feedback bar ─────────────────────────────────────────────────── */
.cos-feedback-bar {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 4px;
  padding: 0 2px;
}

.cos-feedback-bar > div:first-child,
.cos-fb-btn {
  display: inline-flex;
}

/* row containing the two thumb buttons + status */
.cos-feedback-bar > .cos-fb-up,
.cos-feedback-bar > .cos-fb-down {
  display: inline-flex;
}

.cos-fb-ask {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.cos-fb-ask-label {
  font-size: 11.5px;
  color: var(--text2);
  font-weight: 500;
}
.cos-fb-row { display: inline-flex; gap: 7px; }

.cos-fb-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 12px 4px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: transform .12s ease, border-color .15s, background .15s, box-shadow .15s;
  line-height: 1.4;
}
.cos-fb-emoji { font-size: 14px; line-height: 1; }
.cos-fb-up:hover:not(:disabled) {
  border-color: var(--green);
  background: var(--green-bg, rgba(13,147,115,.10));
  transform: translateY(-1px);
  box-shadow: 0 3px 10px rgba(13,147,115,.18);
}
.cos-fb-down:hover:not(:disabled) {
  border-color: var(--amber);
  background: rgba(217,163,13,.10);
  transform: translateY(-1px);
}
.cos-fb-btn:active:not(:disabled) { transform: scale(.94); }
.cos-fb-btn:disabled { opacity: 0.45; cursor: default; }

/* satisfying pop on the thumbs-up when clicked */
.cos-fb-pop { animation: cos-fb-pop .45s cubic-bezier(.2,1.4,.4,1); }
@keyframes cos-fb-pop {
  0%   { transform: scale(1); }
  35%  { transform: scale(1.28); }
  60%  { transform: scale(.92); }
  100% { transform: scale(1); }
}
/* gentle nudge on the thumbs-down to invite a correction */
.cos-fb-nudge { animation: cos-fb-nudge .4s ease; }
@keyframes cos-fb-nudge {
  0%,100% { transform: translateX(0); }
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

/* flying celebration particles */
.cos-fb-particle {
  position: fixed;
  z-index: 9999;
  pointer-events: none;
  transform: translate(-50%, -50%);
  animation: cos-fb-fly .9s cubic-bezier(.15,.7,.3,1) forwards;
  will-change: transform, opacity;
}
@keyframes cos-fb-fly {
  0%   { transform: translate(-50%,-50%) scale(.25); opacity: 0; }
  18%  { opacity: 1; }
  100% { transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1) rotate(var(--rot)); opacity: 0; }
}

/* the "you trained me" confirmation */
.cos-fb-cheer {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 12px;
  border-radius: 10px;
  background: linear-gradient(135deg, rgba(13,147,115,.12), rgba(13,147,115,.04));
  border: 1px solid var(--green, #0d9373);
  animation: cos-fb-cheer-in .5s cubic-bezier(.2,1.2,.4,1);
}
.cos-fb-cheer.cos-fb-cheer-learn {
  background: linear-gradient(135deg, rgba(217,163,13,.12), rgba(217,163,13,.04));
  border-color: var(--amber, #d9a30d);
}
.cos-fb-cheer-icon { font-size: 20px; animation: cos-fb-icon-bob .6s ease; }
.cos-fb-cheer-txt  { font-size: 12px; line-height: 1.45; color: var(--text); }
.cos-fb-cheer-sub  { color: var(--text2); font-size: 11px; }
@keyframes cos-fb-cheer-in {
  from { opacity: 0; transform: translateY(6px) scale(.97); }
  to   { opacity: 1; transform: none; }
}
@keyframes cos-fb-icon-bob {
  0% { transform: scale(.4) rotate(-12deg); }
  55% { transform: scale(1.25) rotate(8deg); }
  100% { transform: scale(1) rotate(0); }
}

/* green ring pulse around the reinforced answer */
.cos-msg-reinforced {
  animation: cos-fb-reinforce 1.4s ease;
  border-radius: 12px;
}
@keyframes cos-fb-reinforce {
  0%   { box-shadow: 0 0 0 0 rgba(13,147,115,.45); }
  70%  { box-shadow: 0 0 0 8px rgba(13,147,115,0); }
  100% { box-shadow: 0 0 0 0 rgba(13,147,115,0); }
}

.cos-fb-correction {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.cos-fb-textarea {
  width: 100%;
  min-height: 72px;
  max-height: 180px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
  padding: 7px 10px;
  outline: none;
  resize: vertical;
  line-height: 1.5;
}
.cos-fb-textarea:focus { border-color: var(--accent); }
.cos-fb-textarea::placeholder { color: var(--text2); }

.cos-fb-actions {
  display: flex;
  gap: 6px;
}

.cos-fb-send {
  background: var(--green);
  color: #000;
  border: none;
  border-radius: 4px;
  padding: 5px 14px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.cos-fb-send:hover    { opacity: .85; }
.cos-fb-send:disabled { opacity: .4; cursor: default; }

.cos-fb-cancel {
  background: none;
  border: 1px solid var(--border);
  color: var(--text2);
  border-radius: 4px;
  padding: 5px 12px;
  font-size: 11px;
  cursor: pointer;
}
.cos-fb-cancel:hover { border-color: var(--red); color: var(--red); }

.cos-fb-status {
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text2);
  padding: 2px 0;
  line-height: 1.4;
  white-space: pre-wrap;
}
.cos-fb-positive       { color: var(--green); }
.cos-fb-negative-learned { color: var(--amber); }

/* ── World Model — prediction becomes simulation ─────────────────────── */
.cos-card-world { border-top: 1px solid var(--border); }

.cos-world-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cos-world-stats {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text2);
}
.cos-world-kind b { color: var(--accent); }
.cos-world-arrow { color: var(--border2); }

.cos-world-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}
.cos-world-select {
  flex: 1;
  min-width: 180px;
  max-width: 340px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 8px;
}
.cos-world-shock {
  width: 72px;
  background: var(--bg2);
  border: 1px solid var(--border2);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 8px;
}
.cos-world-btn {
  background: var(--green-dim);
  border: 1px solid var(--green);
  color: var(--green);
  border-radius: var(--radius-sm);
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 12px;
  cursor: pointer;
}
.cos-world-btn:hover { background: var(--green); color: #000; }
.cos-world-btn-alt {
  background: var(--blue-dim);
  border-color: var(--blue);
  color: var(--blue);
}
.cos-world-btn-alt:hover { background: var(--blue); color: #000; }

.cos-world-result {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  max-height: 380px;
  overflow-y: auto;
}
.cos-world-hint { color: var(--text2); font-size: 11px; }
.cos-world-verdict {
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 4px;
}
.cos-world-drivers-title {
  margin-top: 8px;
  font-size: 11px;
  color: var(--text2);
}

.cos-world-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
  font-family: var(--mono);
  font-size: 11px;
}
.cos-world-imp { min-width: 48px; text-align: right; font-weight: 700; }
.cos-world-imp.neg { color: var(--red); }
.cos-world-imp.pos { color: var(--green); }
.cos-world-hop {
  color: var(--text2);
  font-size: 10px;
  min-width: 20px;
}
.cos-world-ekind {
  color: var(--purple);
  font-size: 10px;
  min-width: 56px;
}
.cos-world-ename {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cos-world-bar {
  width: 90px;
  height: 6px;
  background: var(--bg3);
  border-radius: 3px;
  overflow: hidden;
  flex-shrink: 0;
}
.cos-world-bar-neg { height: 100%; background: var(--red); }
.cos-world-bar-pos { height: 100%; background: var(--green); }

@media (max-width: 767px) {
  .cos-world-select { max-width: none; }
  .cos-world-bar { width: 56px; }
}

/* ── Code Harvester ──────────────────────────────────────────────────── */
.cos-harvest-body {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cos-harvest-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  gap: 8px;
}
.cos-harvest-stat {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  text-align: center;
}
.cos-harvest-num {
  font-family: var(--mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}
.cos-harvest-key {
  font-size: 10px;
  color: var(--text2);
  margin-top: 2px;
}

.cos-harvest-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  max-height: 300px;
  overflow-y: auto;
}
.cos-harvest-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 3px 4px;
  font-family: var(--mono);
  font-size: 11px;
  border-bottom: 1px solid var(--border);
}
.cos-harvest-st { min-width: 14px; font-weight: 700; }
.cos-harvest-st.ok   { color: var(--green); }
.cos-harvest-st.wait { color: var(--amber); }
.cos-harvest-st.bad  { color: var(--red); }
.cos-harvest-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cos-harvest-lang {
  color: var(--purple);
  font-size: 10px;
  min-width: 32px;
}
.cos-harvest-detail {
  color: var(--text2);
  font-size: 10px;
  white-space: nowrap;
}

/* ══ Cognition stepper — watch it think, then reveal ═══════════════════════ */
.cos-cognition {
  margin: 10px 0 6px;
  padding: 14px 16px 12px;
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  background:
    radial-gradient(120% 100% at 0% 0%, rgba(0,232,122,0.06), transparent 60%),
    var(--bg2);
  box-shadow: 0 0 0 1px rgba(0,232,122,0.04), 0 8px 30px rgba(0,0,0,0.35);
  animation: cog-in 0.28s cubic-bezier(.4,0,.2,1);
}
.cos-cognition.cog-out { animation: cog-out 0.26s cubic-bezier(.4,0,1,1) forwards; }
@keyframes cog-in  { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@keyframes cog-out { to   { opacity: 0; transform: translateY(-4px); } }

.cog-head {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 12px;
}
.cog-orb {
  width: 12px; height: 12px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #7dffc0, var(--accent) 60%, #007a44);
  box-shadow: 0 0 10px rgba(0,232,122,0.7);
  animation: cog-orb 1.1s ease-in-out infinite;
}
@keyframes cog-orb { 0%,100% { transform: scale(0.82); opacity: .8; } 50% { transform: scale(1.12); opacity: 1; } }
.cog-title {
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  background: linear-gradient(90deg, var(--accent), #66e0ff, var(--accent));
  background-size: 200% auto;
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: transparent;
  animation: cog-shimmer 2.4s linear infinite;
}
@keyframes cog-shimmer { to { background-position: 200% center; } }
.cog-elapsed {
  margin-left: auto;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text2);
  font-variant-numeric: tabular-nums;
}
.cos-cognition.resolved .cog-orb {
  animation: none;
  background: var(--green);
  box-shadow: 0 0 14px rgba(0,232,122,0.9);
}
.cos-cognition.resolved .cog-title {
  -webkit-text-fill-color: var(--green); color: var(--green);
  animation: none; background: none;
}

.cog-stages { display: flex; flex-direction: column; }
.cog-stage {
  position: relative;
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  padding: 4px 0;
}
/* the rail connecting the nodes */
.cog-stage::before {
  content: '';
  position: absolute;
  left: 10px; top: 20px; bottom: -4px;
  width: 2px;
  background: var(--border2);
  transition: background 0.3s;
}
.cog-stage:last-child::before { display: none; }
.cog-stage.done::before { background: var(--green-dim); }

.cog-node {
  position: relative;
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border2);
  background: var(--bg1);
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.3s, background 0.3s, box-shadow 0.3s;
  z-index: 1;
}
.cog-stage.active .cog-node {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(0,232,122,0.12), 0 0 12px rgba(0,232,122,0.35);
}
/* rotating arc on the active node */
.cog-stage.active .cog-node::after {
  content: '';
  position: absolute; inset: -2px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--accent);
  animation: cog-spin 0.7s linear infinite;
}
@keyframes cog-spin { to { transform: rotate(360deg); } }
.cog-stage.done .cog-node {
  border-color: var(--green);
  background: var(--green);
}
.cog-check {
  fill: none; stroke: var(--bg); stroke-width: 3;
  stroke-linecap: round; stroke-linejoin: round;
  opacity: 0; transform: scale(0.5);
  transition: opacity 0.2s, transform 0.2s;
}
.cog-stage.done .cog-check { opacity: 1; transform: scale(1); }

.cog-body { display: flex; flex-direction: column; gap: 1px; padding-top: 1px; min-width: 0; }
.cog-label {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--text2);
  transition: color 0.25s;
}
.cog-stage.active .cog-label { color: var(--text); }
.cog-stage.done   .cog-label { color: var(--text); }
.cog-sub {
  font-size: 11px;
  color: var(--text2);
  max-height: 0; opacity: 0; overflow: hidden;
  transition: max-height 0.3s ease, opacity 0.3s ease;
}
.cog-stage.active .cog-sub { max-height: 20px; opacity: 0.85; }
/* accent tints for the intent-specific stages */
.cog-stage.cog-reason.active .cog-node,
.cog-stage.cog-belief.active .cog-node { border-color: var(--purple); box-shadow: 0 0 0 4px rgba(170,102,255,0.14), 0 0 12px rgba(170,102,255,0.4); }
.cog-stage.cog-reason.active .cog-node::after,
.cog-stage.cog-belief.active .cog-node::after { border-top-color: var(--purple); }
.cog-stage.cog-sim.active .cog-node { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(68,136,255,0.14), 0 0 12px rgba(68,136,255,0.4); }
.cog-stage.cog-sim.active .cog-node::after { border-top-color: var(--blue); }

/* layer chips pulsing during traversal */
.cog-chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 5px;
  max-height: 0; opacity: 0; overflow: hidden; transition: max-height 0.3s, opacity 0.3s; }
.cog-stage.active .cog-chips { max-height: 24px; opacity: 1; }
.cog-chips i {
  font-family: var(--mono); font-style: normal; font-size: 9.5px;
  padding: 1px 5px; border-radius: 3px;
  color: var(--text2); background: var(--bg3); border: 1px solid var(--border);
  animation: cog-chip 1.3s ease-in-out infinite;
}
.cog-chips i:nth-child(2){ animation-delay: .12s } .cog-chips i:nth-child(3){ animation-delay: .24s }
.cog-chips i:nth-child(4){ animation-delay: .36s } .cog-chips i:nth-child(5){ animation-delay: .48s }
.cog-chips i:nth-child(6){ animation-delay: .60s }
@keyframes cog-chip {
  0%,100% { color: var(--text2); border-color: var(--border); box-shadow: none; }
  50%     { color: var(--accent); border-color: var(--green-dim); box-shadow: 0 0 8px rgba(0,232,122,0.25); }
}

/* answer reveal — fade-up + one-time highlight sweep */
.cos-msg-reveal { animation: msg-reveal 0.4s cubic-bezier(.4,0,.2,1); }
@keyframes msg-reveal { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.cos-msg-reveal .cos-msg-bubble { position: relative; overflow: hidden; }
.cos-msg-reveal .cos-msg-bubble::after {
  content: '';
  position: absolute; inset: 0;
  background: linear-gradient(105deg, transparent 30%, rgba(0,232,122,0.10) 50%, transparent 70%);
  transform: translateX(-100%);
  animation: msg-sweep 0.9s ease 0.15s 1;
  pointer-events: none;
}
@keyframes msg-sweep { to { transform: translateX(100%); } }

/* ── Theme polish: send button + brand, tasteful ──────────────────────── */
.cos-send-btn {
  background: linear-gradient(135deg, var(--accent), #00b866);
  border: none;
  box-shadow: 0 2px 10px rgba(0,232,122,0.25);
  transition: transform 0.12s, box-shadow 0.2s, filter 0.2s;
}
.cos-send-btn:hover:not(:disabled) {
  filter: brightness(1.08);
  box-shadow: 0 3px 16px rgba(0,232,122,0.45);
  transform: translateY(-1px);
}
.cos-send-btn:active:not(:disabled) { transform: translateY(0); }
.cos-send-btn:disabled { opacity: 0.45; filter: grayscale(0.4); }

@media (prefers-reduced-motion: reduce) {
  .cos-cognition, .cos-cognition.cog-out, .cog-orb, .cog-title,
  .cog-stage.active .cog-node::after, .cog-chips i, .cos-msg-reveal,
  .cos-msg-reveal .cos-msg-bubble::after {
    animation: none !important;
  }
  .cos-msg-reveal { opacity: 1; transform: none; }
  .cog-sub, .cog-chips { transition: none; }
}

/* ═══════════════════════════════════════════════════════════════════════
   MODERN THEME v2 — clean, spacious, product-grade (ChatGPT/Claude/Linear)
   Appended last so it re-skins the surfaces above.
   ═══════════════════════════════════════════════════════════════════════ */

/* thin, quiet scrollbars */
* { scrollbar-width: thin; scrollbar-color: #cfd0d6 transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: #d3d4da; border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: #b9bac2; background-clip: content-box; }

/* ── Header ─────────────────────────────────────────────────────────────── */
.cos-header {
  background: rgba(255,255,255,0.82);
  backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  gap: 16px;
}
.cos-brand { font-family: var(--sans); font-weight: 650; letter-spacing: -0.01em; color: var(--text); font-size: 15px; }
.cos-brand-sub { color: var(--text2); }
.cos-back-btn { background: var(--bg3); border: 1px solid var(--border); color: var(--text2); border-radius: 8px; }
.cos-back-btn:hover { border-color: var(--border2); color: var(--text); }
.cos-stat { color: var(--text2); }
.cos-stat-label { color: var(--text2); }
.cos-stat-sep { color: var(--border2); }
.cos-stat-dot { background: #c3c4cc; }
.cos-stat-dot.ready { background: var(--green); box-shadow: 0 0 0 3px var(--green-bg); }
.cos-stat-dot.building { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-bg); }
.cos-tick-btn {
  background: var(--bg1); border: 1px solid var(--border2); color: var(--text);
  border-radius: 8px; padding: 5px 12px; font-family: var(--sans);
  font-weight: 550; box-shadow: var(--shadow-sm); transition: all .15s;
}
.cos-tick-btn:hover { border-color: var(--accent); color: var(--accent); }
#tick-status { color: var(--accent); font-family: var(--mono); }
.cos-refresh-label { color: var(--text2); }
.cos-toggle-slider { background: #d5d6dc; border: none; }
.cos-toggle-slider::before { background: #fff; box-shadow: var(--shadow-sm); }
.cos-toggle input:checked + .cos-toggle-slider { background: var(--accent); border: none; }
.cos-toggle input:checked + .cos-toggle-slider::before { background: #fff; }
.cos-sidebar-toggle { background: var(--bg3); border: 1px solid var(--border); color: var(--text2); border-radius: 8px; }

/* ── Sidebar + layer rows ───────────────────────────────────────────────── */
.cos-sidebar { background: var(--bg1); border-right: 1px solid var(--border); }
.cos-sidebar-hdr, .cos-layer-grid-hdr { color: var(--text2); }
.cos-layer-row {
  border-radius: 10px; margin: 1px 8px; padding: 7px 10px;
  transition: background .12s;
}
.cos-layer-row:hover { background: var(--bg3); }
.cos-layer-row.active { background: var(--green-bg); }
.cos-layer-id { color: var(--text2); font-family: var(--mono); font-size: 10px; font-weight: 600; }
.cos-layer-name { color: var(--text); font-weight: 500; }
.cos-layer-bar-bg { background: var(--bg3); border-radius: 6px; height: 6px; }
.cos-layer-bar-fill { border-radius: 6px; }
.cos-layer-count { color: var(--text2); font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 11px; }

/* status pills — soft tinted, modern */
.cos-layer-status {
  font-family: var(--sans); font-weight: 600; font-size: 9px;
  letter-spacing: 0.04em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 999px; border: none;
}
.cos-layer-status.active   { background: var(--green-bg); color: var(--accent); }
.cos-layer-status.partial  { background: var(--amber-bg); color: var(--amber); }
.cos-layer-status.dynamic  { background: var(--purple-bg); color: var(--purple); }
.cos-layer-status.planned  { background: var(--bg3); color: var(--text2); }

/* ── Cards ──────────────────────────────────────────────────────────────── */
.cos-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin: 12px;
  padding: 18px 20px;
}
.cos-main { background: var(--bg); padding: 4px; }
.cos-card-hdr { margin-bottom: 12px; }
.cos-card-title { font-family: var(--sans); font-weight: 640; font-size: 14px; letter-spacing: -0.01em; color: var(--text); }
.cos-card-sub { color: var(--text2); font-size: 12px; }

/* ── Prompt + chat: the centrepiece ─────────────────────────────────────── */
.cos-card-prompt { padding: 0; overflow: hidden; }
.cos-card-prompt > .cos-card-hdr { padding: 16px 20px 12px; margin: 0; border-bottom: 1px solid var(--border); }
.cos-prompt-meta { display: flex; align-items: center; gap: 8px; }
.cos-meta-badge {
  background: var(--bg3); color: var(--text2); border: none;
  border-radius: 999px; padding: 3px 10px; font-size: 11px; font-family: var(--mono);
}
.cos-clear-btn { background: none; border: none; color: var(--text2); font-size: 12px; }
.cos-clear-btn:hover { color: var(--red); }

.cos-chat { padding: 20px; background: var(--bg); gap: 18px; }
.cos-chat-empty { color: var(--text2); }
.cos-tree-ascii { color: var(--green-dim); opacity: .8; }
.cos-chat-hint { color: var(--text2); }

/* messages — user bubble right, assistant clean block (Claude/ChatGPT feel) */
.cos-msg { max-width: 100%; }
.cos-msg-user { display: flex; justify-content: flex-end; }
.cos-msg-user .cos-msg-bubble {
  background: var(--accent); color: #fff;
  border-radius: 18px 18px 4px 18px;
  padding: 11px 15px; max-width: 78%;
  font-size: 14px; box-shadow: var(--shadow-sm); border: none;
}
.cos-msg-assistant .cos-msg-bubble {
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px 16px 16px 16px;
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  font-family: var(--mono); font-size: 12.5px; line-height: 1.65;
  white-space: pre-wrap; word-break: break-word;
}
.cos-msg-meta { display: flex; gap: 8px; margin-top: 6px; padding-left: 4px; }
.cos-msg-meta span {
  font-size: 10.5px; color: var(--text2); font-family: var(--mono);
  background: var(--bg3); padding: 1px 8px; border-radius: 999px;
}

/* input row */
.cos-prompt-input-row { padding: 14px 16px; background: var(--bg1); border-top: 1px solid var(--border); gap: 10px; align-items: flex-end; }
.cos-prompt-wrap { flex: 1; }
.cos-prompt-input {
  background: var(--bg2); color: var(--text);
  border: 1px solid var(--border2); border-radius: 14px;
  padding: 12px 15px; font-family: var(--sans); font-size: 14px; line-height: 1.5;
  box-shadow: var(--shadow-sm); transition: border-color .15s, box-shadow .15s;
  resize: none;
}
.cos-prompt-input::placeholder { color: var(--text2); }
.cos-prompt-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--green-bg); }
.cos-send-btn {
  width: 44px; height: 44px; border-radius: 12px;
  color: #fff; display: flex; align-items: center; justify-content: center;
}
.cos-session-row { padding: 10px 16px; background: var(--bg1); border-top: 1px solid var(--border); color: var(--text2); }
.cos-session-id { background: var(--bg3); color: var(--text2); padding: 2px 8px; border-radius: 6px; font-family: var(--mono); }
.cos-new-session-btn { background: none; border: 1px solid var(--border2); color: var(--text2); border-radius: 8px; padding: 3px 10px; }
.cos-new-session-btn:hover { border-color: var(--accent); color: var(--accent); }

/* ── Code blocks (fixes the split-language bug + modern look) ────────────── */
.cos-code-block {
  position: relative; margin: 12px 0;
  background: #0f1117; border: 1px solid #1e2230; border-radius: 12px;
  overflow: hidden;
}
.cos-code-lang {
  position: static; display: inline-block;
  padding: 8px 14px 6px; font-family: var(--mono); font-size: 11px;
  color: #8b95b5; text-transform: lowercase; letter-spacing: .04em;
  background: transparent; border: none;
}
.cos-code-pre {
  margin: 0; padding: 4px 16px 16px; overflow-x: auto;
  background: transparent;
}
.cos-code-pre code {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.6;
  color: #d4d9e6; white-space: pre;
}
.cos-code-copy {
  position: absolute; top: 8px; right: 8px;
  background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.10);
  color: #aab2cc; font-size: 11px; padding: 3px 10px; border-radius: 7px;
  font-family: var(--sans); cursor: pointer; transition: all .15s;
}
.cos-code-copy:hover { background: rgba(255,255,255,0.12); color: #fff; }

/* semantic text helpers — readable on light */
.text-green { color: var(--accent); }
.text-amber { color: var(--amber); }
.text-red   { color: var(--red); }
.text-blue  { color: var(--blue); }
.text-dim   { color: var(--text2); }

/* generic inputs / buttons inside cards */
.cos-form-input, .cos-world-select, .cos-world-shock, .cos-fb-textarea {
  background: var(--bg2); border: 1px solid var(--border2); color: var(--text);
  border-radius: 10px;
}
.cos-form-input:focus, .cos-fb-textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--green-bg); outline: none; }

/* ── Cognition stepper — recolour for light ─────────────────────────────── */
.cos-cognition {
  background: var(--bg2);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
}
.cog-node { background: var(--bg2); border-color: var(--border2); }
.cog-stage::before { background: var(--border2); }
.cog-stage.done::before { background: var(--accent); }
.cog-label { color: var(--text2); }
.cog-stage.active .cog-label, .cog-stage.done .cog-label { color: var(--text); }
.cog-check { stroke: #fff; }
.cog-chips i { background: var(--bg3); border-color: var(--border); color: var(--text2); }

/* ── Health / stat tiles, world, harvester, cluster cards ───────────────── */
.cos-harvest-stat, .cos-world-stat, .cos-health-stat {
  background: var(--bg3); border: 1px solid var(--border); border-radius: 10px;
}
.cos-harvest-num, .cos-health-score { color: var(--accent); }
.cos-harvest-row, .cos-world-row { border-bottom: 1px solid var(--border); }
.cos-world-btn { border-radius: 9px; }



/* @self-dev:code-theme — syntax highlighting for code blocks */
.cos-code-block { box-shadow: 0 6px 20px rgba(15,17,23,0.18); }
.cos-code-pre code .hl-kw   { color: #c792ea; }
.cos-code-pre code .hl-type { color: #82aaff; }
.cos-code-pre code .hl-str  { color: #c3e88d; }
.cos-code-pre code .hl-com  { color: #6b7594; font-style: italic; }
.cos-code-pre code .hl-num  { color: #f78c6c; }
.cos-code-pre code .hl-fn   { color: #82aaff; }
.cos-code-pre code .hl-pp   { color: #89ddff; }
.cos-code-lang {
  background: linear-gradient(90deg, rgba(130,170,255,0.14), transparent);
  border-bottom: 1px solid #1e2230; width: 100%;
}

/* ── Ask / Direct mode switch ───────────────────────────────────────────── */
.cos-mode-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px 0; background: var(--bg1); flex-wrap: wrap;
}
.cos-mode-switch {
  display: inline-flex; background: var(--bg3);
  border: 1px solid var(--border); border-radius: 10px; padding: 2px;
}
.cos-mode-opt {
  border: none; background: none; cursor: pointer;
  font-family: var(--sans); font-size: 12px; font-weight: 550;
  color: var(--text2); padding: 5px 12px; border-radius: 8px;
  transition: all .15s;
}
.cos-mode-opt:hover { color: var(--text); }
.cos-mode-opt.active { color: #fff; background: var(--accent); box-shadow: var(--shadow-sm); }
.cos-mode-opt[data-mode="direct"].active { background: #e0821a; }  /* directing = amber, distinct from green ask */
.cos-mode-hint {
  font-size: 11.5px; color: var(--text2); flex: 1; min-width: 180px;
}
.cos-mode-hint code {
  background: var(--bg3); padding: 0 5px; border-radius: 4px;
  font-family: var(--mono); font-size: 10.5px; color: var(--text);
}
/* Direct mode makes the input visibly "armed" */
.cos-prompt-input-row.direct { background: #fff7ec; }
.cos-prompt-input-row.direct .cos-prompt-input {
  border-color: #e0a044; box-shadow: 0 0 0 3px rgba(224,130,26,0.12);
}
.cos-prompt-input-row.direct .cos-send-btn {
  background: linear-gradient(135deg, #e8961e, #cf6f10);
  box-shadow: 0 2px 10px rgba(224,130,26,0.3);
}

/* ── Live System Map ────────────────────────────────────────────────────── */
.cos-sysmap-wrap { position: relative; width: 100%; }
#cos-sysmap {
  display: block; width: 100%;   /* height set by JS, scales with width */
  background:
    radial-gradient(130% 130% at 50% 42%, #ffffff, #eef0f4 70%, #e8eaef);
  border: 1px solid var(--border); border-radius: 14px;
  cursor: crosshair;
}
.cos-sysmap-legend {
  display: flex; flex-wrap: wrap; gap: 12px; padding: 8px 4px 2px;
  font-size: 11px; color: var(--text2);
}
.cos-sysmap-legend span { display: inline-flex; align-items: center; gap: 5px; }
.cos-sysmap-legend i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.lg-active { background: #0d9373; } .lg-partial { background: #b7791f; }
.lg-planned { background: #9aa0ad; }
.lg-pulse { background: #2f6bff; } .lg-learn { background: #0d9373; box-shadow: 0 0 0 2px #7dc7b1; }
.cos-sysmap-tip {
  display: none; position: absolute; transform: translate(-50%,-100%);
  background: #1b1c1f; color: #fff; font-size: 10.5px; font-family: var(--mono);
  padding: 4px 8px; border-radius: 6px; white-space: nowrap; pointer-events: none;
  box-shadow: var(--shadow-md); z-index: 5;
}
.cos-dag-details { margin-top: 8px; }
.cos-dag-details summary { cursor: pointer; font-size: 12px; color: var(--text2); padding: 4px 0; }
.cos-dag-details summary:hover { color: var(--text); }
.cos-dag-details[open] .cos-dag-list { max-height: 200px; overflow-y: auto; margin-top: 6px; }

/* ── Monitoring theme refinements ───────────────────────────────────────── */
.cos-card-title {
  text-transform: none; letter-spacing: -0.01em;
}
/* card header labels feel more like a monitoring console */
.cos-card > .cos-card-hdr .cos-card-sub {
  font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 11px;
}
/* the System Map is the hero of the bottom row — give it room */
.cos-bottom-row { gap: 12px; }
.cos-card-dag { min-width: 0; }
.cos-card-dag .cos-card-title::before { content: '◉ '; color: var(--accent); }
/* layer rows: dynamic branches read distinctly */
.cos-layer-row .cos-layer-id { min-width: 20px; text-align: center; }
.cos-layer-status.dynamic { background: var(--purple-bg); color: var(--purple); }
/* tighten sidebar layer bars for a denser monitoring feel */
.cos-layer-bar-bg { height: 5px; }
/* status dots in header get a soft ring */
.cos-stat-dot.ready { box-shadow: 0 0 0 3px var(--green-bg); }
/* learning-loop / tree cards: monospace numbers align */
.cos-epi-count, .cos-event-time, .cos-cl-time { font-variant-numeric: tabular-nums; }

/* ── Roles: regular sees only the prompt page ───────────────────────────── */
.cos-role-badge {
  font-size: 11px; font-weight: 650; padding: 3px 10px; border-radius: 999px;
  background: var(--bg3); color: var(--text2);
}
body.role-director .cos-role-badge { background: #fff2df; color: #b7791f; }
.cos-signin-btn {
  background: none; border: 1px solid var(--border2); color: var(--text2);
  border-radius: 8px; padding: 4px 10px; font-size: 11px; cursor: pointer;
}
.cos-signin-btn:hover { border-color: var(--accent); color: var(--accent); }

/* Regular users: hide everything except the prompt; centre it cleanly. */
/* Regulars see ONLY the prompt + support. Hide every director panel —
   sidebar, all row wrappers, and any card that isn't prompt/support. */
body.role-regular .cos-sidebar,
body.role-regular #stat-tick,
body.role-regular .cos-mode-row,
body.role-regular .cos-main > div,
body.role-regular .cos-main .cos-card:not(.cos-card-prompt):not(.cos-card-support) {
  display: none !important;
}
body.role-regular .cos-main {
  align-items: center; padding: 24px 16px; gap: 16px;
}
body.role-regular .cos-card-prompt,
body.role-regular .cos-card-support {
  max-width: 880px; width: 100%; margin: 0 auto;
}
body.role-regular .cos-card-prompt { box-shadow: var(--shadow-lg); }
body.role-regular .cos-chat { min-height: 44vh; }

/* ── Support Us card ────────────────────────────────────────────────────── */
.cos-card-support {
  background: linear-gradient(120deg, #0d9373 0%, #0b8f8a 100%);
  border: none; color: #fff; overflow: hidden; position: relative;
}
.cos-card-support::after {
  content: ''; position: absolute; right: -40px; top: -40px;
  width: 180px; height: 180px; border-radius: 50%;
  background: rgba(255,255,255,0.08);
}
.cos-support-inner {
  display: flex; align-items: center; justify-content: space-between;
  gap: 24px; flex-wrap: wrap; position: relative; z-index: 1;
}
.cos-support-copy { flex: 1; min-width: 240px; }
.cos-support-eyebrow {
  font-size: 11px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: rgba(255,255,255,0.75);
}
.cos-support-title {
  font-size: 19px; font-weight: 700; margin: 4px 0 6px; letter-spacing: -0.01em;
}
.cos-support-text {
  font-size: 13px; line-height: 1.5; color: rgba(255,255,255,0.9);
  max-width: 52ch;
}
.cos-support-actions { display: flex; flex-direction: column; gap: 8px; align-items: flex-end; }
.cos-support-tiers { display: flex; gap: 8px; flex-wrap: wrap; }
.cos-tier {
  background: rgba(255,255,255,0.16); border: 1px solid rgba(255,255,255,0.3);
  color: #fff; font-weight: 650; font-size: 14px; padding: 9px 16px;
  border-radius: 10px; cursor: pointer; transition: all .15s; backdrop-filter: blur(4px);
}
.cos-tier:hover { background: #fff; color: #0d9373; transform: translateY(-1px); }
.cos-tier-custom { background: transparent; }
.cos-support-note { font-size: 11px; color: rgba(255,255,255,0.8); }
@media (max-width: 640px) {
  .cos-support-actions { align-items: stretch; width: 100%; }
  .cos-support-tiers { justify-content: space-between; }
}


/* ── Chat: attractive for clients, informative for directors ────────────── */
.cos-msg-avatar {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 650; color: var(--accent);
  margin: 0 0 5px 2px; letter-spacing: 0.02em;
}
.cos-av-dot {
  width: 14px; height: 14px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #7dffc0, var(--accent) 65%);
  box-shadow: 0 0 8px rgba(13,147,115,0.4);
}

/* assistant bubble: clean prose, not a mono terminal dump */
.cos-msg-assistant .cos-msg-bubble {
  font-family: var(--sans); font-size: 14px; line-height: 1.62;
  white-space: normal; border-radius: 4px 16px 16px 16px;
  background: var(--bg2); border: 1px solid var(--border);
  padding: 15px 18px; box-shadow: var(--shadow-sm);
}
.cos-answer > *:first-child { margin-top: 0; }
.cos-answer > *:last-child { margin-bottom: 0; }
.cos-ans-head {
  font-weight: 680; font-size: 14.5px; color: var(--text);
  letter-spacing: -0.01em; margin: 14px 0 8px;
}
.cos-ans-head:first-child { margin-top: 0; }
.cos-ans-p { margin: 7px 0; color: var(--text); }
.cos-ans-list { margin: 6px 0 6px 2px; padding-left: 18px; list-style: none; }
.cos-ans-list li { position: relative; margin: 4px 0; padding-left: 4px; }
.cos-ans-list li::before {
  content: ''; position: absolute; left: -13px; top: 8px;
  width: 5px; height: 5px; border-radius: 50%; background: var(--green-dim);
}
.cos-ans-ok {
  display: inline-block; margin: 8px 0; padding: 4px 12px;
  background: var(--green-bg); color: var(--accent);
  border-radius: 999px; font-size: 13px; font-weight: 600;
}
.cos-ans-improve {
  margin: 8px 0; padding: 8px 12px; border-radius: 10px;
  background: var(--amber-bg); color: var(--amber);
  font-size: 13px; font-weight: 600;
}
.cos-inline-code {
  font-family: var(--mono); font-size: 12.5px;
  background: var(--bg3); padding: 1px 6px; border-radius: 5px; color: #b5478a;
}
.cos-chip-layer {
  font-family: var(--mono); font-size: 11px; font-weight: 600;
  background: var(--blue-bg); color: var(--blue);
  padding: 1px 7px; border-radius: 5px;
}

/* developer detail — director only, collapsible */
.cos-dev-detail {
  margin-top: 12px; border-top: 1px dashed var(--border2); padding-top: 8px;
}
.cos-dev-detail > summary {
  cursor: pointer; font-family: var(--mono); font-size: 11px;
  color: var(--text2); font-weight: 600; letter-spacing: 0.04em;
  text-transform: uppercase; list-style: none; user-select: none;
}
.cos-dev-detail > summary::before { content: '▸ '; }
.cos-dev-detail[open] > summary::before { content: '▾ '; }
.cos-dev-detail > summary:hover { color: var(--accent); }
.cos-dev-body {
  margin-top: 8px; font-family: var(--mono); font-size: 12px; line-height: 1.55;
  color: var(--text2); background: var(--bg3);
  border-radius: 10px; padding: 12px 14px;
  max-height: 420px; overflow: auto; white-space: normal;
}
.cos-dev-body .cos-ans-head { font-family: var(--mono); font-size: 12px; color: var(--text); }
.cos-dev-body .cos-ans-p, .cos-dev-body .cos-ans-list li { color: var(--text2); }

/* meta row */
.cos-msg-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; padding-left: 4px; align-items: center; }
.cos-msg-meta span {
  font-size: 10.5px; font-family: var(--mono); color: var(--text2);
  background: var(--bg3); padding: 1px 8px; border-radius: 999px;
}
.tag-mode.direct { background: var(--amber-bg); color: var(--amber); }
.tag-quiet { background: none !important; color: var(--text2); font-family: var(--sans) !important; font-size: 11px !important; font-style: italic; }

/* client view: warmer, roomier chat */
body.role-regular .cos-msg-assistant .cos-msg-bubble { font-size: 15px; padding: 17px 20px; }
body.role-regular .cos-chat { gap: 22px; }

/* ═══════════════════════════════════════════════════════════════════════
   User accounts + Training Governance
   ═══════════════════════════════════════════════════════════════════════ */

/* Header account chip */
.cos-account-chip { display: inline-flex; align-items: center; gap: 6px; }
.cos-acct-btn {
  background: var(--accent); color: #fff; border: none;
  border-radius: 999px; padding: 5px 13px; font-size: 12px; font-weight: 600;
  cursor: pointer; transition: background .15s;
}
.cos-acct-btn:hover { background: var(--accent-hover); }
.cos-acct-user {
  font-size: 12.5px; font-weight: 600; color: var(--text);
  background: var(--bg3); border: 1px solid var(--border);
  padding: 4px 10px; border-radius: 999px;
}
.cos-acct-logout {
  background: none; border: none; color: var(--text2);
  font-size: 11px; cursor: pointer; text-decoration: underline;
}
.cos-acct-logout:hover { color: var(--red); }

/* Modal shell */
.cos-modal-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(20,22,28,.44); backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.cos-modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 24px 60px rgba(0,0,0,.28);
  width: 100%; max-width: 420px; overflow: hidden;
  animation: cos-modal-in .28s cubic-bezier(.2,1,.35,1);
}
@keyframes cos-modal-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }

/* Auth modal */
.cos-auth-tabs { display: flex; border-bottom: 1px solid var(--border); }
.cos-auth-tab {
  flex: 1; background: none; border: none; padding: 13px; cursor: pointer;
  font-size: 13px; font-weight: 600; color: var(--text2);
  border-bottom: 2px solid transparent;
}
.cos-auth-tab.is-active { color: var(--accent); border-bottom-color: var(--accent); }
.cos-auth-body { padding: 20px; display: flex; flex-direction: column; gap: 11px; }
.cos-auth-title { font-size: 18px; font-weight: 700; margin: 0; color: var(--text); }
.cos-auth-sub { font-size: 12.5px; color: var(--text2); margin: -4px 0 4px; line-height: 1.45; }
.cos-auth-input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border2, var(--border));
  border-radius: var(--radius-sm); font-size: 14px; background: var(--bg);
  color: var(--text); outline: none;
}
.cos-auth-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--green-bg, rgba(13,147,115,.12)); }
.cos-auth-msg { font-size: 12px; color: var(--red); min-height: 15px; }
.cos-auth-submit {
  background: var(--accent); color: #fff; border: none; border-radius: var(--radius-sm);
  padding: 11px; font-size: 14px; font-weight: 700; cursor: pointer; transition: background .15s;
}
.cos-auth-submit:hover { background: var(--accent-hover); }
.cos-auth-close {
  background: none; border: none; color: var(--text2); font-size: 12px;
  cursor: pointer; padding: 4px;
}
.cos-fb-signin { color: var(--accent); font-weight: 600; text-decoration: underline; margin-left: 4px; }

/* Users card + list */
.cos-card-users .cos-users-intro { font-size: 12.5px; color: var(--text2); line-height: 1.5; margin: 0 0 12px; }
.cos-users-list { display: flex; flex-direction: column; gap: 8px; }
.cos-users-empty { font-size: 12.5px; color: var(--text2); padding: 12px; text-align: center; }
.cos-user-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 11px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--bg); cursor: pointer; transition: border-color .15s, transform .1s, box-shadow .15s;
}
.cos-user-row:hover { border-color: var(--accent); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,.05); }
.cos-user-main { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cos-user-name { font-weight: 700; font-size: 13.5px; color: var(--text); }
.cos-user-arch {
  font-size: 11px; font-weight: 600; color: var(--accent);
  background: var(--green-bg, rgba(13,147,115,.10)); padding: 2px 8px; border-radius: 999px;
}
.cos-user-meta { display: flex; gap: 12px; font-size: 11.5px; color: var(--text2);
  font-variant-numeric: tabular-nums; white-space: nowrap; }
.cos-user-trust { font-weight: 600; color: var(--text); }
.cos-user-pill { font-size: 10px; font-weight: 700; padding: 2px 7px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; }
.cos-user-pend { background: rgba(183,121,31,.14); color: var(--amber); }
.cos-user-susp { background: rgba(214,53,63,.12); color: var(--red); }
.cos-user-dir  { background: rgba(13,147,115,.14); color: var(--accent); }

/* User detail modal */
.cos-user-modal { max-width: 560px; max-height: 86vh; display: flex; flex-direction: column; }
.cos-user-modal-hdr {
  display: flex; justify-content: space-between; align-items: center;
  padding: 15px 18px; border-bottom: 1px solid var(--border);
}
.cos-user-modal-title { font-size: 16px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.cos-user-modal-body { padding: 16px 18px; overflow-y: auto; }
.cos-user-blurb { font-size: 13px; color: var(--text2); margin: 0 0 14px; line-height: 1.5; }
.cos-user-stats { display: flex; gap: 8px; margin-bottom: 16px; }
.cos-user-stats > div {
  flex: 1; text-align: center; background: var(--bg); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 4px;
}
.cos-user-stats b { display: block; font-size: 17px; color: var(--text); font-variant-numeric: tabular-nums; }
.cos-user-stats span { font-size: 10.5px; color: var(--text2); }
.cos-user-section-t { font-size: 12px; font-weight: 700; color: var(--text); margin: 16px 0 8px; text-transform: uppercase; letter-spacing: .04em; }
.cos-user-section-t .cos-dim { font-weight: 400; text-transform: none; letter-spacing: 0; }
.cos-dim { color: var(--text2); }
.cos-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.cos-chip { font-size: 11.5px; background: var(--bg3); color: var(--text); padding: 3px 9px; border-radius: 999px; }

/* Beliefs */
.cos-beliefs { display: flex; flex-direction: column; gap: 8px; }
.cos-belief {
  border: 1px solid var(--border); border-left: 3px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 11px; background: var(--bg);
}
.cos-belief.is-pending { border-left-color: var(--amber); background: rgba(183,121,31,.05); }
.cos-belief-claim { font-size: 12.5px; color: var(--text); line-height: 1.45; margin-bottom: 6px; }
.cos-belief-meta { display: flex; align-items: center; gap: 10px; font-size: 11px; color: var(--text2); font-variant-numeric: tabular-nums; }
.cos-belief-state { font-weight: 700; padding: 1px 7px; border-radius: 999px; }
.cos-belief-state.s-Verified { color: var(--green); background: var(--green-bg, rgba(13,147,115,.10)); }
.cos-belief-state.s-Hypothesis { color: var(--amber); background: rgba(183,121,31,.10); }
.cos-belief-state.s-Rejected { color: var(--red); background: rgba(214,53,63,.10); }
.cos-belief-actions { margin-left: auto; display: flex; gap: 6px; }
.cos-mini-ok, .cos-mini-no {
  border: none; border-radius: 6px; padding: 3px 10px; font-size: 11px; font-weight: 600; cursor: pointer;
}
.cos-mini-ok { background: var(--green); color: #fff; }
.cos-mini-no { background: var(--bg3); color: var(--red); border: 1px solid var(--border); }

/* Governance controls */
.cos-user-controls { display: flex; flex-direction: column; gap: 12px; }
.cos-trust-ctl { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--text); font-weight: 600; }
.cos-trust-ctl input[type=range] { flex: 1; accent-color: var(--accent); }
.cos-trust-val { font-variant-numeric: tabular-nums; min-width: 34px; text-align: right; color: var(--accent); }
.cos-user-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.cos-btn-ghost, .cos-btn-warn, .cos-btn-danger {
  border-radius: var(--radius-sm); padding: 8px 13px; font-size: 12px; font-weight: 600; cursor: pointer;
  border: 1px solid var(--border); background: var(--bg2); color: var(--text);
}
.cos-btn-ghost:hover { border-color: var(--accent); color: var(--accent); }
.cos-btn-warn { color: var(--amber); border-color: rgba(183,121,31,.4); }
.cos-btn-warn:hover { background: rgba(183,121,31,.08); }
.cos-btn-danger { color: #fff; background: var(--red); border-color: var(--red); }
.cos-btn-danger:hover { filter: brightness(1.06); }
.cos-user-action-msg { font-size: 12px; color: var(--accent); min-height: 15px; }

@media (prefers-reduced-motion: reduce) { .cos-modal { animation: none; } }

/* ═══════════════════════════════════════════════════════════════════════
   Public client page (/train) — slim, centered, welcoming
   ═══════════════════════════════════════════════════════════════════════ */
body.client-only { background: var(--bg); }
.cos-client-main {
  max-width: 760px; margin: 0 auto; padding: 26px 18px 60px;
  display: flex; flex-direction: column; gap: 20px;
}
.cos-client-hero { font-size: 46px; text-align: center; margin-bottom: 6px; }
.cos-client-main .cos-chat { min-height: 220px; max-height: 60vh; }
.cos-client-text { font-size: 15px; line-height: 1.6; color: var(--text); }
.cos-client-text + .cos-client-text { margin-top: 10px; }
.cos-client-code {
  background: var(--bg3); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 12px 14px; overflow-x: auto; font-family: var(--mono); font-size: 12.5px;
  line-height: 1.5; margin: 10px 0; color: var(--text);
}
.cos-client-think { color: var(--text2); font-style: italic; }
.cos-client-text code { background: var(--bg3); padding: 1px 5px; border-radius: 4px; font-family: var(--mono); font-size: .9em; }

/* Empty-state suggestion chips */
.cos-suggest-row {
  display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  margin-top: 14px;
}
.cos-suggest {
  background: var(--bg2); border: 1px solid var(--border);
  color: var(--text2); border-radius: 999px; padding: 7px 14px;
  font-size: 12.5px; cursor: pointer;
  transition: border-color .15s, color .15s, transform .12s, box-shadow .15s;
}
.cos-suggest:hover {
  border-color: var(--accent); color: var(--accent);
  transform: translateY(-1px); box-shadow: 0 3px 10px rgba(13,147,115,.12);
}

/* ═══════════════════════════════════════════════════════════════════════
   CHAT v2 — single authoritative message layout & style.
   Supersedes ALL earlier .cos-msg* rules (three generations of chat CSS had
   accumulated; their interaction collapsed the user bubble to 1-letter width:
   a shrink-to-fit wrapper + a %-max-width child is circular and resolves to
   ~zero). Pattern here: the wrapper is always FULL-WIDTH (definite size), the
   bubble is inline-block so it shrinks to its text naturally, and %-max-width
   resolves against the definite wrapper. Higher-specificity selectors so this
   block wins regardless of what remains above.
   ═══════════════════════════════════════════════════════════════════════ */

.cos-chat { gap: 22px; padding: 22px; }

/* every message row spans the chat; direction is handled inside */
.cos-chat .cos-msg {
  display: block;
  width: 100%;
  max-width: 100%;
  align-self: stretch;
}

/* ── user message: right-aligned emerald bubble ── */
.cos-chat .cos-msg-user { text-align: right; }
.cos-chat .cos-msg-user .cos-msg-bubble {
  display: inline-block;
  text-align: left;
  width: auto;
  max-width: min(72%, 560px);
  background: linear-gradient(135deg, #10a37f, #0d9373);
  color: #fff;
  border: none;
  border-radius: 18px 18px 4px 18px;
  padding: 11px 16px;
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  box-shadow: 0 2px 8px rgba(13, 147, 115, .22);
}

/* ── assistant message: friendly card with the Cog avatar ── */
.cos-chat .cos-msg-assistant { text-align: left; }
.cos-chat .cos-msg-assistant .cos-msg-bubble {
  display: block;
  width: fit-content;
  min-width: 220px;
  max-width: 100%;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 4px 18px 18px 18px;
  padding: 15px 19px;
  font-size: 14px;
  line-height: 1.65;
  white-space: normal;
  overflow-wrap: break-word;
  word-break: normal;
  box-shadow: 0 1px 3px rgba(15, 23, 32, .05), 0 4px 14px rgba(15, 23, 32, .04);
}
/* short conversational replies read as chat, not documents */
.cos-chat .cos-msg-assistant .cos-msg-bubble .cos-answer { font-size: 14.5px; }

/* wide content stays inside the bubble */
.cos-chat .cos-msg-bubble pre,
.cos-chat .cos-msg-bubble .cos-client-code { overflow-x: auto; max-width: 100%; }

/* meta chips: quieter, aligned with the bubble edge */
.cos-chat .cos-msg-user .cos-msg-meta { justify-content: flex-end; }
.cos-chat .cos-msg-meta { opacity: .85; }

/* feedback bar sits with the answer, indented like a reply control */
.cos-chat .cos-feedback-bar { margin-top: 8px; }

/* smooth entrance for both roles */
@media (prefers-reduced-motion: no-preference) {
  .cos-chat .cos-msg { animation: msg-reveal .35s cubic-bezier(.2, .8, .3, 1); }
}

/* ── "Just learned this for you" research banner ───────────────────────── */
.cos-learn-banner {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  background: linear-gradient(135deg, rgba(13,147,115,.10), rgba(45,196,158,.05));
  border: 1px solid rgba(13,147,115,.28);
  animation: cos-learn-in .45s cubic-bezier(.2,1,.35,1);
}
.cos-learn-ico {
  font-size: 17px;
  line-height: 1.2;
  animation: cos-learn-spark 1.1s ease 1;
}
.cos-learn-txt { display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.cos-learn-txt b {
  font-size: 12.5px; font-weight: 700; color: var(--accent);
  letter-spacing: .01em;
}
.cos-learn-txt span {
  font-size: 12px; color: var(--text2); line-height: 1.5;
  overflow-wrap: break-word;
}
@keyframes cos-learn-in {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: none; }
}
@keyframes cos-learn-spark {
  0%,100% { transform: scale(1) rotate(0); }
  40% { transform: scale(1.35) rotate(12deg); }
  70% { transform: scale(.92) rotate(-6deg); }
}
@media (prefers-reduced-motion: reduce) {
  .cos-learn-banner, .cos-learn-ico { animation: none; }
}

/* ── source attribution chip ("from wikipedia") ────────────────────────── */
.cos-source-chip {
  display: inline-block;
  margin-top: 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text2);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 11px;
  letter-spacing: .02em;
  text-transform: capitalize;
}

/* ═══════════════════════════════════════════════════════════════════════
   NAVBAR v2 — professional, modern, friendly. Final authoritative header
   styles (same pattern as Chat v2: last in cascade, higher specificity).
   ═══════════════════════════════════════════════════════════════════════ */

header.cos-header {
  height: 58px;
  padding: 0 18px;
  gap: 16px;
  background: rgba(255, 255, 255, .82);
  backdrop-filter: saturate(1.4) blur(14px);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid rgba(20, 24, 28, .07);
  box-shadow: 0 1px 2px rgba(15, 23, 32, .03);
}

/* ── logo lockup ── */
.cos-logo {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; color: inherit;
}
.cos-logo-tile {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: linear-gradient(135deg, #10a37f, #0b7a60);
  color: #fff; font-size: 15px; font-weight: 700;
  box-shadow: 0 2px 6px rgba(13, 147, 115, .35),
              inset 0 1px 0 rgba(255, 255, 255, .25);
}
.cos-logo-word {
  display: flex; flex-direction: column; line-height: 1.05;
  font-family: var(--heading);
  font-weight: 700; font-size: 17px; letter-spacing: -0.01em;
  color: var(--text);
}
.cos-logo-sub {
  font-family: var(--sans);
  font-weight: 500; font-size: 10.5px; letter-spacing: .01em;
  color: var(--text2); margin-top: 2px; white-space: nowrap;
}
@media (max-width: 900px) { .cos-logo-sub { display: none; } }

/* ── status cluster: quiet pills, tabular numbers ── */
.cos-header .cos-status-bar { gap: 6px; }
.cos-header .cos-stat {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--bg3);
  border: 1px solid rgba(20, 24, 28, .05);
  border-radius: 999px;
  padding: 4px 11px;
  font-family: var(--sans); font-size: 11.5px; font-weight: 600;
  color: var(--text2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.cos-header .cos-stat-sep { display: none; }
.cos-header .cos-stat-label { color: var(--text2); font-weight: 500; }
.cos-header .cos-stat span:not(.cos-stat-label):not(.cos-stat-dot) { color: var(--text); }
.cos-header .cos-stat-tick { background: none; border: none; padding: 0; }
.cos-header .cos-tick-btn {
  background: var(--bg3); border: 1px solid rgba(20, 24, 28, .06);
  border-radius: 999px; padding: 4px 12px;
  font-family: var(--sans); font-size: 11.5px; font-weight: 600;
  color: var(--text2); cursor: pointer;
  transition: color .15s, border-color .15s;
}
.cos-header .cos-tick-btn:hover { color: var(--accent); border-color: var(--accent); }

/* ── right cluster: one primary action, quiet secondaries ── */
.cos-header .cos-header-right { gap: 10px; }
.cos-header .cos-acct-btn {
  padding: 7px 16px; font-size: 12.5px; font-weight: 700;
  font-family: var(--sans);
  box-shadow: 0 2px 8px rgba(13, 147, 115, .28);
  transition: background .15s, transform .12s, box-shadow .15s;
}
.cos-header .cos-acct-btn:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(13,147,115,.32); }
.cos-header .cos-role-badge {
  background: var(--bg3); border: 1px solid rgba(20,24,28,.05);
  border-radius: 999px; padding: 5px 12px;
  font-family: var(--sans); font-size: 11.5px; font-weight: 600; color: var(--text2);
}
.cos-header .cos-signin-btn {
  background: none; border: 1px solid var(--border);
  border-radius: 999px; padding: 5px 13px;
  font-family: var(--sans); font-size: 11.5px; font-weight: 600;
  color: var(--text2); cursor: pointer;
  transition: color .15s, border-color .15s;
}
.cos-header .cos-signin-btn:hover { color: var(--accent); border-color: var(--accent); }
.cos-header .cos-refresh-label { font-family: var(--sans); font-size: 11px; color: var(--text2); }

/* headings/cards pick up the display face */
.cos-card-title { font-family: var(--heading); letter-spacing: -0.01em; }
.cos-support-title { font-family: var(--heading); }
.cos-auth-title { font-family: var(--heading); }

/* keep content clear of the slightly taller header */
:root { --header-h: 58px; }

/* ═══════════════════════════════════════════════════════════════════════
   CLIENT PAGE v2 + form-control typography.
   Fixes: (1) buttons/inputs rendered in the UA's default serif because form
   controls never inherit fonts unless told to; (2) the chat card sat under
   the fixed navbar (no header offset on .cos-client-main); (3) donation tier
   buttons had no styles at all — raw browser buttons on a gradient card.
   ═══════════════════════════════════════════════════════════════════════ */

button, input, textarea, select {
  font-family: var(--sans);
  font-size: inherit;
}

/* clear the fixed header + breathe */
.cos-client-main {
  margin-top: var(--header-h);
  padding-top: 30px;
}
body.client-only {
  background:
    radial-gradient(900px 420px at 85% -8%, rgba(13,147,115,.07), transparent 60%),
    radial-gradient(700px 380px at -10% 30%, rgba(45,196,158,.05), transparent 55%),
    var(--bg);
  min-height: 100vh;
}
body.client-only .cos-card {
  border-radius: 16px;
  box-shadow: 0 1px 3px rgba(15,23,32,.04), 0 8px 30px rgba(15,23,32,.06);
}

/* donation tiers: white pills that pop on the gradient */
.cos-support-tier {
  background: rgba(255,255,255,.94);
  color: #0b7a60;
  border: none;
  border-radius: 999px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.12);
  transition: transform .12s ease, box-shadow .15s, background .15s;
}
.cos-support-tier:hover {
  transform: translateY(-2px);
  box-shadow: 0 5px 14px rgba(0,0,0,.18);
  background: #fff;
}
.cos-support-tier:active { transform: scale(.96); }
.cos-support-tier.cos-support-other {
  background: transparent;
  color: rgba(255,255,255,.92);
  border: 1.5px solid rgba(255,255,255,.55);
  box-shadow: none;
}
.cos-support-tier.cos-support-other:hover { border-color: #fff; background: rgba(255,255,255,.12); }

/* suggestion chips inherit the product face now; tune weight */
.cos-suggest { font-weight: 600; }

/* prompt input: roomier, focus ring on brand colour */
body.client-only .cos-prompt-input {
  font-family: var(--sans);
  font-size: 14.5px;
  line-height: 1.55;
  border-radius: 14px;
}
body.client-only .cos-prompt-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13,147,115,.14);
}
body.client-only .cos-send-btn {
  width: 46px; height: 46px;
  border-radius: 13px;
  box-shadow: 0 3px 10px rgba(13,147,115,.30);
  transition: transform .12s, box-shadow .15s;
}
body.client-only .cos-send-btn:hover { transform: translateY(-1px); box-shadow: 0 5px 14px rgba(13,147,115,.36); }

/* meta badges: quiet, never overlap the title */
body.client-only .cos-prompt-meta { gap: 6px; }
body.client-only .cos-meta-badge { font-family: var(--mono); font-size: 10.5px; }

/* mobile comfort */
@media (max-width: 640px) {
  .cos-client-main { padding-left: 12px; padding-right: 12px; }
  body.client-only .cos-chat { max-height: none; }
}
