/* ============================================================
   Hermes Command Center — Design System (Phase 1c visual skeleton)
   Mission-control aesthetic: dense, dark-friendly, legible, fast.
   Anti-slop floor per memory/reference_site_design_standards.md:
   no purple/violet, no gradients-as-decoration, no glassmorphism,
   no fabricated numbers (placeholders always read "—" or a note).
   Fonts are system-stack only — no external font CDN (speed + no
   network dependency for an internal ops tool).
   ============================================================ */

:root {
  /* ---- Dark (default) palette ---- */
  --bg-0: #0b0e12;           /* page background */
  --bg-1: #12161c;           /* panel background */
  --bg-2: #1a1f27;           /* card background */
  --bg-3: #222834;           /* hover / raised */
  --border: #2a313d;
  --border-strong: #3a4351;

  --text-primary: #e6e9ee;
  --text-secondary: #a7b0bd;
  --text-dim: #6b7280;

  /* Accent: warm amber (NOT purple/violet — hard ban per design standards) */
  --accent: #e8952e;
  --accent-strong: #ffab3d;
  --accent-dim: #8a5c1f;

  /* Secondary accent: cyan, used for links / secondary actions */
  --accent-2: #2ec8c8;

  /* Status dots (dimension 15) */
  --status-active: #35c46a;
  --status-idle: #e8952e;
  --status-dormant: #5b6472;

  /* Gauge thresholds: green <50%, amber 50-80%, red >80% */
  --gauge-green: #35c46a;
  --gauge-amber: #e8952e;
  --gauge-red: #e5484d;

  --danger: #e5484d;
  --warn: #e8952e;
  --ok: #35c46a;

  --radius-sm: 4px;
  --radius-md: 8px;
  --shadow-card: 0 1px 2px rgba(0, 0, 0, 0.4);

  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", "IBM Plex Sans", Roboto, sans-serif;
  --font-mono: "JetBrains Mono", "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", monospace;

  color-scheme: dark;
}

/* ---- Light fallback ---- */
@media (prefers-color-scheme: light) {
  :root {
    --bg-0: #f4f5f7;
    --bg-1: #ffffff;
    --bg-2: #ffffff;
    --bg-3: #eef0f3;
    --border: #dadde2;
    --border-strong: #c3c8d1;
    --text-primary: #1a1f27;
    --text-secondary: #4a5361;
    --text-dim: #7a8290;
    --accent-dim: #f3d9b3;
    color-scheme: light;
  }
}

:root[data-theme="dark"] {
  --bg-0: #0b0e12; --bg-1: #12161c; --bg-2: #1a1f27; --bg-3: #222834;
  --border: #2a313d; --border-strong: #3a4351;
  --text-primary: #e6e9ee; --text-secondary: #a7b0bd; --text-dim: #6b7280;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg-0: #f4f5f7; --bg-1: #ffffff; --bg-2: #ffffff; --bg-3: #eef0f3;
  --border: #dadde2; --border-strong: #c3c8d1;
  --text-primary: #1a1f27; --text-secondary: #4a5361; --text-dim: #7a8290;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg-0);
  color: var(--text-primary);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
::selection { background: var(--accent-dim); color: var(--text-primary); }

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

button {
  font-family: inherit;
  cursor: pointer;
}

/* ============================================================
   App shell
   ============================================================ */
.app-shell {
  display: grid;
  grid-template-rows: 56px 44px 1fr 28px;
  min-height: 100vh;
}

/* ---- Header ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
}
.app-header__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.2px;
}
.app-header__brand .mark {
  width: 22px; height: 22px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #16110a;
  font-weight: 800;
  font-size: 12px;
}
.app-header__right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.clock {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.clock .tz-badge {
  font-size: 10px;
  padding: 1px 5px;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  color: var(--text-dim);
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-2);
  font-size: 12px;
  color: var(--text-secondary);
}
.user-chip__avatar {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--bg-3);
  border: 1px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center;
  font-size: 10px;
  color: var(--text-dim);
}

/* ---- Tab bar ---- */
.tab-bar {
  display: flex;
  align-items: stretch;
  gap: 2px;
  padding: 0 16px;
  background: var(--bg-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab-bar__btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  padding: 0 16px;
  height: 44px;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.tab-bar__btn:hover {
  color: var(--text-primary);
  background: var(--bg-2);
}
.tab-bar__btn.is-active {
  color: var(--accent-strong);
  border-bottom-color: var(--accent);
}

/* ---- Main content ---- */
.app-main {
  padding: 18px 20px 24px;
  overflow-y: auto;
}
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* ---- Footer / status bar ---- */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  background: var(--bg-1);
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}
.app-footer__dot {
  display: inline-block;
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--status-dormant);
  margin-right: 6px;
}

/* ============================================================
   Section headers / generic layout
   ============================================================ */
.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 12px;
}
.section-heading h2 {
  font-size: 15px;
  font-weight: 600;
  margin: 0;
  letter-spacing: 0.2px;
}
.section-heading .sub {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 2px;
}
.section-actions {
  display: flex;
  gap: 8px;
}

.btn {
  border: 1px solid var(--border-strong);
  background: var(--bg-2);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.btn:hover { background: var(--bg-3); border-color: var(--border-strong); }
.btn.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #16110a;
  font-weight: 600;
}
.btn.btn-primary:hover { background: var(--accent-strong); }
.btn.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
}
.btn.btn-ghost:hover { color: var(--text-primary); background: var(--bg-2); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  background: var(--bg-2);
}

.placeholder-note {
  color: var(--text-dim);
  font-size: 12px;
  font-style: normal;
  font-family: var(--font-mono);
}

.card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}
.card > .card__body { padding: 14px 16px; }
.card > .card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ============================================================
   Status dots (dimension 15: active <10min / idle <6h / dormant >6h)
   ============================================================ */
.status-dot {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot--active { background: var(--status-active); box-shadow: 0 0 0 3px rgba(53, 196, 106, 0.18); }
.status-dot--idle { background: var(--status-idle); box-shadow: 0 0 0 3px rgba(232, 149, 46, 0.15); }
.status-dot--dormant { background: var(--status-dormant); }

.status-label { font-size: 11px; color: var(--text-dim); }

/* ============================================================
   TAB 1 — Agent Roster
   ============================================================ */
.channel-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}
.channel-tabs__btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  padding: 6px 10px;
  border-bottom: 2px solid transparent;
}
.channel-tabs__btn.is-active {
  color: var(--text-primary);
  border-bottom-color: var(--accent-2);
}

.roster-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

.agent-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.agent-card:hover {
  border-color: var(--border-strong);
  background: var(--bg-2);
}
.agent-card.is-pinned {
  border-color: var(--accent-dim);
}
.agent-card__top {
  display: flex;
  align-items: center;
  gap: 8px;
}
.agent-card__icon {
  width: 28px; height: 28px;
  border-radius: var(--radius-sm);
  background: var(--bg-3);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.agent-card__name {
  font-weight: 600;
  font-size: 13px;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.agent-card__lane {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.agent-card__meta {
  font-size: 11px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}
.agent-card__last-task {
  font-size: 11px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.load-bar {
  height: 4px;
  border-radius: 2px;
  background: var(--bg-3);
  overflow: hidden;
}
.load-bar__fill {
  height: 100%;
  background: var(--accent-2);
  width: 0%; /* set inline per-agent by 1d wiring */
}
.agent-card__pin {
  position: absolute;
  top: 8px; right: 8px;
  font-size: 11px;
  color: var(--text-dim);
}

/* ============================================================
   TAB 2 — Operations (live tracking)
   ============================================================ */
.ops-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
@media (max-width: 1024px) {
  .ops-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 700px) {
  .ops-grid { grid-template-columns: 1fr; }
}

.stat-tile {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.stat-tile__label {
  font-size: 11px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}
.stat-tile__value {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  color: var(--text-primary);
}
.stat-tile__value.is-dim { color: var(--text-dim); font-size: 18px; }
.stat-tile__sub { font-size: 11px; color: var(--text-secondary); margin-top: 4px; }

.gauge {
  height: 8px;
  border-radius: 4px;
  background: var(--bg-3);
  overflow: hidden;
  margin-top: 8px;
}
.gauge__fill { height: 100%; width: 0%; }
.gauge__fill.gauge--green { background: var(--gauge-green); }
.gauge__fill.gauge--amber { background: var(--gauge-amber); }
.gauge__fill.gauge--red { background: var(--gauge-red); }

.health-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
@media (max-width: 700px) { .health-row { grid-template-columns: 1fr; } }

.vps-health-note {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin-bottom: 6px;
}

/* Route mission (Board tab) - classify a query into lanes + auto-create cards */
.route-mission {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  margin-bottom: 16px;
}
.route-mission__row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.route-mission__input {
  flex: 1 1 auto;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
  font-family: var(--font-mono);
  padding: 6px 10px;
  min-width: 0;
}
.route-mission__input:focus { outline: none; border-color: var(--accent); }
.route-mission__result {
  margin-top: 8px;
  font-size: 12px;
}
.route-mission__resolved {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}
.route-mission__lanes { display: inline-flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.route-mission__cards { color: var(--text-dim); font-size: 11px; }
.route-mission__reasoning {
  color: var(--text-dim);
  font-size: 11px;
  margin-top: 6px;
  font-family: var(--font-mono);
}
.route-mission__ambiguous { color: var(--warn); font-size: 11px; margin-bottom: 6px; }
.route-mission__chips { display: flex; flex-wrap: wrap; gap: 6px; }
.route-mission__chip { cursor: pointer; }
.route-mission__chip:hover { background: var(--bg-3); border-color: var(--accent); color: var(--text-primary); }
@media (max-width: 700px) { .route-mission__row { flex-direction: column; } }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}
table.data-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  font-size: 10px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-strong);
  cursor: pointer;
  white-space: nowrap;
}
table.data-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-family: var(--font-mono);
  white-space: nowrap;
}
table.data-table tbody tr:hover { background: var(--bg-2); cursor: pointer; }
.model-flag {
  color: var(--warn);
  font-family: var(--font-ui);
  font-size: 11px;
}

.budget-row {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 14px;
  align-items: start;
}
@media (max-width: 900px) { .budget-row { grid-template-columns: 1fr; } }

.provider-list { display: flex; flex-direction: column; gap: 8px; }
.provider-list__row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
}
.provider-list__row .dot { width: 8px; height: 8px; border-radius: 50%; }
.provider-list__row .name { flex: 1; color: var(--text-secondary); }
.provider-list__row .amount { font-family: var(--font-mono); color: var(--text-primary); }

.pie-placeholder {
  width: 100%;
  aspect-ratio: 1 / 1;
  max-width: 180px;
  border-radius: 50%;
  border: 1px dashed var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 11px;
  font-family: var(--font-mono);
  margin: 0 auto;
}

.activity-feed {
  display: flex;
  flex-direction: column;
  max-height: 220px;
  overflow-y: auto;
}
.activity-row {
  display: grid;
  grid-template-columns: 70px 90px 1fr 120px;
  gap: 10px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--text-secondary);
}
.activity-row:last-child { border-bottom: none; }
.activity-row__ts { color: var(--text-dim); }
.activity-row__agent { color: var(--accent-2); }
.activity-row__summary {
  color: var(--text-primary);
  font-family: var(--font-ui);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.activity-row__model { color: var(--text-dim); text-align: right; }

.alert-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 10px;
}

/* ============================================================
   TAB 3 — Board (Kanban / bridge cards)
   ============================================================ */
.board-columns {
  display: grid;
  grid-template-columns: repeat(4, minmax(220px, 1fr));
  gap: 12px;
  overflow-x: auto;
}
@media (max-width: 1024px) {
  .board-columns { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
}
@media (max-width: 640px) {
  .board-columns { grid-template-columns: 1fr; }
}
.board-column {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  min-height: 320px;
  display: flex;
  flex-direction: column;
}
.board-column__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}
.board-column__count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-3);
  border-radius: 999px;
  padding: 1px 7px;
}
.board-column__body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
}
.board-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 10px;
  font-size: 12px;
}
.board-card__title { font-weight: 600; margin-bottom: 6px; }
.board-card__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}
.board-card__provenance {
  display: flex;
  align-items: center;
  gap: 5px;
  margin-top: 6px;
  font-size: 10px;
  color: var(--text-dim);
}
.board-empty {
  padding: 20px 10px;
  text-align: center;
  color: var(--text-dim);
  font-size: 11px;
  font-family: var(--font-mono);
}

/* ============================================================
   TAB 4 — Gallery
   ============================================================ */
.gallery-search {
  display: flex;
  gap: 8px;
  margin-bottom: 14px;
}
.gallery-search input {
  flex: 1;
  background: var(--bg-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 8px 10px;
  font-size: 13px;
  font-family: var(--font-ui);
}
.gallery-search input:focus { outline: 1px solid var(--accent-2); }

.gallery-subtabs {
  display: flex;
  gap: 4px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.gallery-subtabs__btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--bg-1);
  color: var(--text-secondary);
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 999px;
}
.gallery-subtabs__btn.is-active {
  border-color: var(--accent);
  color: var(--accent-strong);
  background: var(--accent-dim);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
}
.gallery-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.gallery-card__thumb {
  aspect-ratio: 16 / 10;
  background: repeating-linear-gradient(
    45deg, var(--bg-2), var(--bg-2) 10px, var(--bg-3) 10px, var(--bg-3) 20px
  );
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 11px;
  font-family: var(--font-mono);
}
.gallery-card__body { padding: 10px 12px; }
.gallery-card__title { font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.gallery-card__stats {
  display: flex;
  gap: 10px;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}
.badge {
  display: inline-block;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 3px;
  border: 1px solid var(--border-strong);
}
.badge--live { color: var(--ok); border-color: var(--ok); }
.badge--pending { color: var(--warn); border-color: var(--warn); }
.badge--maintenance { color: var(--text-dim); }
.badge--warn { color: var(--warn); border-color: var(--warn); }
.badge--danger { color: var(--danger); border-color: var(--danger); }

.gallery-section-title {
  font-size: 13px;
  font-weight: 600;
  margin: 20px 0 10px;
  color: var(--text-secondary);
}
.gallery-section-title:first-child { margin-top: 0; }

/* ============================================================
   TAB 5 — Settings
   ============================================================ */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
@media (max-width: 900px) { .settings-grid { grid-template-columns: 1fr; } }

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.settings-row:last-child { border-bottom: none; }
.settings-row__label { color: var(--text-secondary); }
.settings-row__value { font-family: var(--font-mono); color: var(--text-dim); }

.config-path {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-dim);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
}

/* ============================================================
   Login shell
   ============================================================ */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-0);
}
.login-card {
  width: 340px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 32px 28px;
  text-align: center;
}
.login-card .mark {
  width: 44px; height: 44px;
  border-radius: var(--radius-md);
  background: var(--accent);
  color: #16110a;
  font-weight: 800;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 16px;
}
.login-card h1 {
  font-size: 16px;
  margin: 0 0 4px;
}
.login-card p.sub {
  font-size: 12px;
  color: var(--text-dim);
  margin: 0 0 24px;
}
.google-btn {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-2);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
}
.google-btn:hover { background: var(--bg-3); }
.google-btn__g {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: conic-gradient(#4285F4 0 25%, #34A853 25% 50%, #FBBC05 50% 75%, #EA4335 75% 100%);
  flex-shrink: 0;
}
.login-note {
  margin-top: 18px;
  font-size: 11px;
  color: var(--text-dim);
}
.dev-login__input {
  width: 100%;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 8px 10px;
  font-size: 12px;
  font-family: var(--font-mono);
}

/* ============================================================
   TAB — Chat (Hermes gateway live chat, slice 1)
   Three-column layout: agent roster | session list | chat view.
   Extends the existing design system -- no new palette, no new fonts.
   ============================================================ */
.chat-approval {
  margin: 12px 18px;
  padding: 14px;
  border: 1px solid rgba(245, 158, 11, .55);
  border-radius: 10px;
  background: rgba(120, 53, 15, .18);
}
.chat-approval.is-approved { border-color: rgba(34, 197, 94, .65); }
.chat-approval.is-denied { opacity: .72; }
.chat-approval__title { font-weight: 700; margin-bottom: 8px; }
.chat-approval__detail {
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0 0 10px;
  padding: 9px;
  border-radius: 6px;
  background: rgba(0, 0, 0, .22);
}
.chat-approval__actions { display: flex; gap: 8px; }
.chat-approval__status { margin-top: 8px; font-size: .85rem; opacity: .85; }
.chat-layout {
  display: grid;
  grid-template-columns: 240px 240px 1fr;
  gap: 0;
  height: calc(100vh - 56px - 44px - 28px - 36px); /* shell minus header/tabs/footer/main padding */
  min-height: 480px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-1);
}
@media (max-width: 1100px) {
  .chat-layout { grid-template-columns: 200px 200px 1fr; }
}
/* Narrow viewport: explicit single-pane state machine (roster -> sessions ->
   thread + Back). Panes are kept mounted (only display toggled) so the live
   stream + scroll position survive navigation. data-active-pane drives which
   pane shows; desktop (wider than 860px) shows all three regardless. */
@media (max-width: 860px) {
  .chat-layout { grid-template-columns: 1fr; }
  .chat-layout .chat-roster,
  .chat-layout .chat-sessions,
  .chat-layout .chat-main { display: none; }
  .chat-layout[data-active-pane="roster"] .chat-roster,
  .chat-layout[data-active-pane="sessions"] .chat-sessions,
  .chat-layout[data-active-pane="thread"] .chat-main { display: flex; }
  .chat-back { display: inline-flex; } /* show Back only when a pane is in front */
}


.chat-roster,
.chat-sessions {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-1);
  min-height: 0;
}
.chat-roster__head,
.chat-sessions__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--text-dim);
  font-weight: 600;
}
.chat-roster__title { flex: 1; }
.chat-sessions__title-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-roster__count {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  background: var(--bg-3);
  border-radius: 999px;
  padding: 1px 7px;
}
.chat-roster__list,
.chat-sessions__list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
  min-height: 0;
}

/* Mobile Back button (hidden on desktop; revealed by the <=860 media query) */
.chat-back {
  display: none;
  align-items: center;
  gap: 4px;
  appearance: none;
  background: transparent;
  border: none;
  color: var(--accent-2);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  min-height: 32px;
  text-transform: none;
  letter-spacing: 0;
}
.chat-back:hover { background: var(--bg-2); }
.chat-back--thread { font-size: 16px; padding: 2px 8px; }

/* Agent row in the roster */
.chat-agent {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
  border-left: 2px solid transparent;
  color: var(--text-secondary);
}
.chat-agent:hover { background: var(--bg-2); color: var(--text-primary); }
.chat-agent:focus-visible { outline: 2px solid var(--accent-2); outline-offset: -2px; }
.chat-agent.is-active {
  background: var(--bg-2);
  border-left-color: var(--accent);
  color: var(--text-primary);
}
.chat-agent__avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--c);
  color: #0b0e12;
  font-weight: 700;
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  text-transform: none;
}
.chat-agent__namecol { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.chat-agent__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}
.chat-agent__id {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-dim);
  text-transform: none;
  letter-spacing: 0;
}

/* Session row */
.chat-session {
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  border-left: 2px solid transparent;
}
.chat-session:hover { background: var(--bg-2); }
.chat-session.is-active {
  background: var(--bg-2);
  border-left-color: var(--accent-2);
}
.chat-session__title {
  color: var(--text-primary);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chat-session__meta {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
  margin-top: 2px;
  display: flex;
  gap: 8px;
}

/* Chat main column */
.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-1);
  gap: 10px;
}
.chat-header__left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.chat-header__avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--c, var(--bg-3));
  color: #0b0e12;
  font-weight: 700;
  font-size: 13px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.chat-header__id { display: flex; flex-direction: column; min-width: 0; }
.chat-header__identity { display: inline-flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.chat-header__agent { font-weight: 600; font-size: 13px; line-height: 1.2; }
.chat-runtime-badge,
.chat-agent__runtime {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 6px;
  font-family: var(--font-mono);
  font-size: 8px;
  font-weight: 700;
  letter-spacing: .08em;
  line-height: 1.2;
  white-space: nowrap;
}
.chat-runtime-badge.runtime-codex,
.chat-agent__runtime.runtime-codex { color: #8ee8c0; border-color: rgba(79, 209, 158, .45); background: rgba(79, 209, 158, .10); }
.chat-runtime-badge.runtime-hermes,
.chat-agent__runtime.runtime-hermes { color: #a9c8ff; border-color: rgba(93, 151, 255, .45); background: rgba(93, 151, 255, .10); }
.chat-runtime-badge.is-connected::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--status-active); margin-right: 4px; }
.chat-runtime-badge.is-checking { opacity: .72; }
.chat-runtime-badge.is-unavailable { color: var(--warn); border-color: rgba(232, 149, 46, .5); background: rgba(232, 149, 46, .10); }
.chat-agent__runtime { margin-left: 6px; vertical-align: 1px; }
.chat-header__model {
  display: inline-flex; align-items: center; gap: 5px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}
.chat-header__model-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--status-active);
  box-shadow: 0 0 0 2px rgba(53,196,106,0.15);
}
.chat-header__model.is-mismatch .chat-header__model-dot { background: var(--warn); box-shadow: 0 0 0 2px rgba(232,149,46,0.18); }
.chat-header__model.is-mismatch { color: var(--warn); }
.chat-header__model.is-unknown .chat-header__model-dot { background: var(--text-dim); box-shadow: none; }
.chat-header__right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.chat-search-btn { min-height: 30px; }
.chat-header__hint {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
}
@media (max-width: 860px) { .chat-header__hint { display: none; } }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
}
.chat-empty {
  margin: auto;
  color: var(--text-dim);
  font-size: 13px;
  text-align: center;
  font-family: var(--font-mono);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px;
}
.chat-empty__icon {
  width: 44px; height: 44px;
  border-radius: var(--radius-md);
  background: var(--accent-dim);
  color: var(--accent-strong);
  font-weight: 800;
  font-size: 18px;
  display: flex; align-items: center; justify-content: center;
}
.chat-empty__title { color: var(--text-secondary); font-family: var(--font-ui); font-size: 14px; font-weight: 600; }
.chat-empty__sub { color: var(--text-dim); font-size: 12px; max-width: 320px; }

/* Message bubbles */
.chat-msg {
  max-width: 78%;
  padding: 9px 13px;
  border-radius: var(--radius-md);
  font-size: 13px;
  word-wrap: break-word;
  line-height: 1.5;
  display: flex;
  gap: 9px;
  animation: chat-msg-in 0.16s ease;
}
@keyframes chat-msg-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.chat-msg--user {
  align-self: flex-end;
  background: var(--accent-dim);
  color: var(--text-primary);
  border: 1px solid var(--accent);
  border-bottom-right-radius: 2px;
  flex-direction: row-reverse;
}
.chat-msg--assistant {
  align-self: flex-start;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
}
.chat-msg__avatar {
  width: 26px; height: 26px;
  border-radius: 50%;
  background: var(--c, var(--bg-3));
  color: #0b0e12;
  font-weight: 700;
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}
.chat-msg__col { min-width: 0; flex: 1; display: flex; flex-direction: column; }
.chat-msg--user .chat-msg__col { align-items: flex-end; }
.chat-msg__meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  flex-wrap: wrap;
}
.chat-msg__role {
  text-transform: uppercase;
  letter-spacing: 0.3px;
  color: var(--text-secondary);
  font-weight: 600;
}
.chat-msg__model {
  font-size: 9px;
  padding: 1px 5px;
  border-radius: 3px;
  border: 1px solid var(--border-strong);
  color: var(--text-dim);
}
.chat-msg__time { cursor: default; }
.chat-msg__copy {
  appearance: none;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-dim);
  font-size: 10px;
  font-family: var(--font-mono);
  padding: 1px 6px;
  border-radius: 3px;
  opacity: 0;
  transition: opacity 0.12s ease, color 0.12s ease, border-color 0.12s ease;
  cursor: pointer;
  min-height: 20px;
}
.chat-msg:hover .chat-msg__copy,
.chat-msg__copy:focus-visible { opacity: 1; }
.chat-msg__copy:hover { color: var(--accent-2); border-color: var(--border-strong); }
.chat-msg__copy.is-copied { color: var(--ok); opacity: 1; border-color: var(--ok); }
.chat-msg.is-flash { animation: chat-flash 1.6s ease; }
@keyframes chat-flash {
  0% { box-shadow: 0 0 0 2px var(--accent-2); }
  70% { box-shadow: 0 0 0 2px var(--accent-2); }
  100% { box-shadow: 0 0 0 2px transparent; }
}

/* Typing cursor: CSS blinking block at the END of the partial text only.
   No per-char reveal -- text lands as it arrives. */
.chat-msg.is-streaming .chat-msg__text::after {
  content: "▍";
  display: inline-block;
  margin-left: 1px;
  color: var(--accent-2);
  animation: chat-blink 1s steps(2) infinite;
}
@keyframes chat-blink { 50% { opacity: 0; } }

/* search highlight (TreeWalker-wrapped, never raw-injected) */
mark.search-hit {
  background: var(--accent-dim);
  color: var(--text-primary);
  border-radius: 2px;
  padding: 0 1px;
}

/* Action-lifecycle cards: one collapsible region per turn, one compact row
   per tool lifecycle. Hides raw tool spam (tool.progress never renders). */
.chat-actions {
  align-self: flex-start;
  max-width: 78%;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
}
.chat-actions__head {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 7px 10px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 11px;
  font-family: var(--font-mono);
  text-align: left;
  cursor: pointer;
}
.chat-actions__head:hover { background: var(--bg-2); }
.chat-actions__icon {
  width: 12px; height: 12px;
  border: 1.5px solid var(--border-strong);
  border-top-color: var(--accent-2);
  border-radius: 50%;
  animation: chat-spin 0.8s linear infinite;
  flex-shrink: 0;
}
.chat-actions.is-done .chat-actions__icon {
  animation: none;
  border: none;
  border-radius: 50%;
  background: var(--ok);
}
.chat-actions__summary { flex: 1; color: var(--accent-2); font-weight: 600; }
.chat-actions.is-done .chat-actions__summary { color: var(--text-secondary); }
.chat-actions__count {
  font-size: 10px;
  color: var(--text-dim);
  background: var(--bg-3);
  border-radius: 999px;
  padding: 1px 7px;
}
.chat-actions__list {
  display: flex; flex-direction: column;
  border-top: 1px solid var(--border);
  padding: 4px 0;
}
.chat-actions:not(.is-open) .chat-actions__list { display: none; }
.chat-action {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 5px 10px;
  font-size: 11px;
  border-bottom: 1px solid var(--border);
}
.chat-action:last-child { border-bottom: none; }
.chat-action__icon {
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-top: 3px;
  flex-shrink: 0;
  background: var(--text-dim);
}
.chat-action--running .chat-action__icon {
  background: transparent;
  border: 1.5px solid var(--border-strong);
  border-top-color: var(--accent-2);
  animation: chat-spin 0.8s linear infinite;
}
.chat-action--done .chat-action__icon { background: var(--ok); }
.chat-action--error .chat-action__icon { background: var(--danger); }
.chat-action__body { min-width: 0; flex: 1; }
.chat-action__title { color: var(--text-primary); font-weight: 600; font-family: var(--font-mono); }
.chat-action__detail {
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin-top: 1px;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-action--error .chat-action__detail { color: var(--danger); }
.chat-action__detail.is-empty { display: none; }

/* legacy inline tool indicator (unused by v1 render, kept for any stray refs) */
.chat-tool {
  align-self: flex-start;
  background: var(--bg-1);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  max-width: 75%;
  display: flex; align-items: center; gap: 6px;
}
@keyframes chat-spin { to { transform: rotate(360deg); } }

.chat-error {
  align-self: center;
  background: rgba(229, 72, 77, 0.08);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-size: 11px;
  color: var(--danger);
  font-family: var(--font-mono);
  max-width: 90%;
}

/* Composer */
.chat-composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--border);
  background: var(--bg-1);
}
.chat-composer__input {
  flex: 1;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 9px 11px;
  font-size: 13px;
  font-family: var(--font-ui);
  resize: none;
  min-height: 38px;
  max-height: 160px;
  line-height: 1.4;
}
.chat-composer__input:focus { outline: 1px solid var(--accent-2); border-color: var(--accent-2); }
.chat-composer__input:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-model-select {
  flex: 0 0 auto;
  min-height: 38px;
  max-width: 150px;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 7px 8px;
  font-size: 12px;
  font-family: var(--font-ui);
  cursor: pointer;
}
.chat-model-select:focus { outline: 1px solid var(--accent-2); border-color: var(--accent-2); }
.chat-model-select:disabled { opacity: 0.5; cursor: not-allowed; }
.chat-send-btn { min-height: 38px; }
.chat-stop-btn {
  min-height: 38px;
  background: var(--danger);
  border-color: var(--danger);
  color: #1a0606;
  font-weight: 600;
}
.chat-stop-btn:hover { filter: brightness(1.08); }
.chat-stop-btn.is-stopping { opacity: 0.7; cursor: progress; }
.chat-stop-btn__icon { font-size: 10px; }

/* Voice: push-to-talk mic button (turn-based STT). Matches the
   .chat-send-btn / .chat-stop-btn idiom. Listening = pulsing red,
   speaking = dim accent ring. Hidden entirely when unsupported (the
   [hidden] attribute is honored for the base element). */
.chat-voice-btn {
  min-height: 38px;
  background: var(--bg-2);
  border: 1px solid var(--border-strong);
  color: var(--text-secondary);
  padding: 6px 10px;
  font-size: 15px;
  line-height: 1;
  flex: 0 0 auto;
}
.chat-voice-btn:hover { background: var(--bg-3); color: var(--text-primary); }
.chat-voice-btn:focus-visible { outline: 1px solid var(--accent-2); border-color: var(--accent-2); }
.chat-voice-btn[hidden] { display: none; }
.chat-voice-btn.is-listening {
  background: var(--danger);
  border-color: var(--danger);
  color: #1a0606;
  animation: chat-voice-pulse 1.1s ease-in-out infinite;
}
.chat-voice-btn.is-speaking {
  border-color: var(--accent-2);
  color: var(--accent-2);
}
@keyframes chat-voice-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(229, 72, 77, 0.55); }
  50%      { box-shadow: 0 0 0 6px rgba(229, 72, 77, 0); }
}

/* Voice-mode toggle (TTS on/off). Ghost style so it sits in the chat
   header next to Search; .is-on flips to accent when replies will be
   spoken aloud. */
.chat-voice-toggle { white-space: nowrap; }
.chat-voice-toggle[hidden] { display: none; }
.chat-voice-toggle.is-on {
  color: var(--accent-strong);
  background: var(--accent-dim);
  border-color: var(--accent);
}
.chat-voice-toggle.is-on:hover { color: #16110a; background: var(--accent); }

.btn-sm { padding: 3px 8px; font-size: 11px; min-height: 26px; }

/* ============================================================
   Utility
   ============================================================ */
.text-dim { color: var(--text-dim); }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.hidden { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ============================================================
   TAB — Second Brain (slice B: ARMS-framework layered graph)
   Typed layered workspace graph. NOT an Obsidian-style dot blob:
   departments (lanes) as labeled columns crossed with the 4 ARMS
   layers (A/R/M/S) as colored rows. Each cell holds typed nodes.
   Zoom/pan via CSS transform on .sb-canvas-inner.
   Palette extends the existing system -- no purple/violet (design
   standards ban), no gradients-as-decoration.
   ============================================================ */
.sb-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 8px 12px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  font-size: 12px;
  color: var(--text-secondary);
}
.sb-legend__item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.sb-legend__item b { color: var(--text-primary); font-weight: 700; }
.sb-legend__swatch {
  width: 12px; height: 12px;
  border-radius: 3px;
  background: var(--c);
  display: inline-block;
}

.sb-layout {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 12px;
  align-items: stretch;
}
@media (max-width: 1100px) {
  .sb-layout { grid-template-columns: 1fr; }
}

.sb-canvas-wrap {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  height: calc(100vh - 56px - 44px - 28px - 36px - 110px);
  min-height: 440px;
  position: relative;
  /* the wrap is the pan/zoom viewport -- it never scrolls itself, the inner
     canvas is transformed. */
  cursor: grab;
}
.sb-canvas {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
}
.sb-canvas-inner {
  position: absolute;
  top: 0; left: 0;
  transform-origin: 0 0;
  padding: 14px;
  /* the inner canvas holds the grid at natural size; transform does the rest */
  will-change: transform;
  user-select: none;
}

.sb-grid {
  display: grid;
  /* columns set inline by JS: 120px + N department columns */
  gap: 0;
  background: var(--border);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  /* the grid is laid out as: header row, then 4 (layer-label + 8 cells) rows */
}

.sb-grid__corner {
  background: var(--bg-2);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
}
.sb-grid__corner-arm {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: 1.5px;
}
.sb-grid__corner-dept {
  font-size: 10px;
  color: var(--text-dim);
  font-family: var(--font-mono);
}

.sb-grid__dept-hd {
  background: var(--bg-2);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}
.sb-grid__dept-hd:last-child { border-right: none; }
.sb-grid__dept-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.3px;
}
.sb-grid__dept-count {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-dim);
  background: var(--bg-3);
  border-radius: 999px;
  padding: 1px 7px;
}

.sb-grid__layer-label {
  background: var(--bg-2);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  border-right: 1px solid var(--border);
  border-top: 1px solid var(--border);
  position: sticky;
  left: 0;
  z-index: 2;
}
.sb-grid__arm {
  width: 22px; height: 22px;
  border-radius: var(--radius-sm);
  background: var(--c);
  color: #0b0e12;
  font-weight: 800;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
}
.sb-grid__layer-name {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

.sb-cell {
  background: var(--bg-1);
  padding: 8px;
  min-height: 110px;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: 5px;
  border-right: 1px solid var(--border);
  border-top: 1px solid var(--border);
  align-self: start;
}
.sb-cell:nth-last-child(-n+9) { /* last row's cells */ }
.sb-cell.is-empty {
  background: var(--bg-0);
}
.sb-cell__empty {
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 14px;
  margin: auto;
  opacity: 0.5;
}
.sb-cell__more {
  font-size: 10px;
  font-family: var(--font-mono);
  color: var(--text-dim);
  background: var(--bg-3);
  border: 1px dashed var(--border-strong);
  border-radius: 999px;
  padding: 2px 8px;
  align-self: center;
}

/* ---- Node chips (typed per layer) ---- */
.sb-node {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px 3px 4px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg-2);
  font-size: 11px;
  color: var(--text-primary);
  font-family: var(--font-ui);
  cursor: pointer;
  transition: border-color 0.1s ease, background 0.1s ease, transform 0.05s ease;
  max-width: 100%;
  line-height: 1.3;
}
.sb-node:hover {
  border-color: var(--border-strong);
  background: var(--bg-3);
}
.sb-node:active { transform: translateY(1px); }
.sb-node.is-selected {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--text-primary);
}
.sb-node.is-disabled { opacity: 0.55; text-decoration: line-through; }

.sb-node__letter {
  width: 16px; height: 16px;
  border-radius: 3px;
  background: var(--c);
  color: #0b0e12;
  font-weight: 800;
  font-size: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: var(--font-mono);
}
.sb-node__label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 150px;
}

/* layer-specific left border accent so the type reads at a glance even
   without the letter badge */
.sb-node--applications { border-left: 3px solid #2ec8c8; }
.sb-node--routines     { border-left: 3px solid #e8952e; }
.sb-node--memory       { border-left: 3px solid #7a9cc6; }
.sb-node--skills       { border-left: 3px solid #35c46a; }

/* the canonical memory index gets a star so it stands out */
.sb-node--memory_index .sb-node__label::before {
  content: "★ ";
  color: var(--accent);
}
.sb-node--skill_pack .sb-node__label::before {
  content: "▣ ";
  color: #35c46a;
}
.sb-node--skill_pack { border-style: dashed; }

.sb-node__cred {
  font-family: var(--font-mono);
  font-size: 9px;
  color: var(--text-dim);
  background: var(--bg-3);
  border-radius: 999px;
  padding: 0 5px;
}
.sb-node__disabled { color: var(--warn); font-size: 11px; }

/* risk marks on application nodes */
.sb-node__risk {
  font-family: var(--font-mono);
  font-size: 9px;
  font-weight: 800;
  padding: 0 4px;
  border-radius: 3px;
  text-transform: uppercase;
}
.sb-risk-high   { color: #0b0e12; background: var(--danger); }
.sb-risk-medium { color: #0b0e12; background: var(--warn); }
.sb-risk-low    { color: #0b0e12; background: var(--ok); }
/* emphasis ring on the highest-risk apps */
.sb-node.sb-risk-high {
  border-color: var(--danger);
  box-shadow: 0 0 0 1px rgba(229, 72, 77, 0.25);
}

/* ---- Right-side detail panel ---- */
.sb-detail {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0;
  overflow-y: auto;
  max-height: calc(100vh - 56px - 44px - 28px - 36px - 110px);
  min-height: 440px;
}
.sb-detail__empty {
  padding: 32px 18px;
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--font-mono);
  text-align: center;
}
.sb-detail__body { padding: 14px 16px; }
.sb-detail__hd {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
}
.sb-detail__letter {
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  background: var(--c);
  color: #0b0e12;
  font-weight: 800;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-family: var(--font-mono);
}
.sb-detail__label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  word-break: break-all;
}
.sb-detail__layer {
  font-size: 11px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin-top: 2px;
}
.sb-detail__row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
}
.sb-detail__row:last-child { border-bottom: none; }
.sb-detail__row > span:first-child {
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-size: 10px;
  font-weight: 600;
  flex-shrink: 0;
  padding-top: 2px;
}
.sb-detail__row > span:last-child {
  color: var(--text-primary);
  text-align: right;
  word-break: break-all;
  font-family: var(--font-ui);
}
.sb-detail__row--hint > span:last-child {
  color: var(--text-secondary);
  font-size: 11px;
  font-family: var(--font-mono);
}
.sb-detail__path {
  font-family: var(--font-mono) !important;
  font-size: 11px !important;
  color: var(--accent-2) !important;
  text-align: left !important;
}
.sb-detail__cred-list {
  padding: 10px 0 4px;
}
.sb-detail__row-label {
  font-size: 10px;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  margin-bottom: 6px;
}
.sb-detail__cred-list ul {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 3px;
  max-height: 240px;
  overflow-y: auto;
}
.sb-detail__cred-list li code {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-primary);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 2px 6px;
  display: inline-block;
  word-break: break-all;
}

/* ---- Source health tiles (under the graph) ---- */
.sb-sources {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 10px;
}
.sb-source {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 12px;
}
.sb-source.is-unavailable {
  border-color: var(--warn);
  background: rgba(232, 149, 46, 0.05);
}
.sb-source__hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
}
.sb-source__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-primary);
}
.sb-source__count {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent-2);
  background: var(--bg-2);
  border-radius: 999px;
  padding: 1px 8px;
  border: 1px solid var(--border);
}
.sb-source__note {
  display: block;
  font-size: 10px;
  color: var(--text-dim);
  font-family: var(--font-mono);
  margin-top: 3px;
  line-height: 1.4;
}


/* ---- single live status indicator (replaces the per-tool-call flood) ---- */
.chat-status {
  position: sticky; bottom: 0; z-index: 2;
  display: flex; align-items: center; gap: 8px;
  padding: 9px 12px; margin-top: 10px;
  background: linear-gradient(180deg, rgba(11,14,18,0) 0%, var(--bg-1) 55%);
  color: var(--text-dim); font-size: 13px;
  border-top: 1px solid var(--border);
}
.chat-status.hidden { display: none; }
.chat-status__icon { font-size: 14px; line-height: 1; }
.chat-status--thinking .chat-status__icon,
.chat-status--working .chat-status__icon {
  animation: cc-status-spin 1.1s linear infinite;
  color: var(--accent-2);
}
.chat-status--thinking, .chat-status--working { color: var(--accent-2); }
.chat-status--stalled, .chat-status--stalled .chat-status__icon { color: var(--warn); }
.chat-status--error, .chat-status--error .chat-status__icon { color: var(--danger); }
@keyframes cc-status-spin { from { transform: rotate(0); } to { transform: rotate(360deg); } }

/* ---- chat markdown rendering ---- */
.chat-msg__text { --txt: var(--text-primary); }
.chat-msg__text p { margin: .35em 0; line-height: 1.55; }
.chat-msg__text p:first-child { margin-top: 0; }
.chat-msg__text p:last-child { margin-bottom: 0; }
.chat-msg__text h1,.chat-msg__text h2,.chat-msg__text h3,.chat-msg__text h4,.chat-msg__text h5,.chat-msg__text h6 { margin: .7em 0 .3em; line-height: 1.3; color: var(--txt); }
.chat-msg__text h1 { font-size: 1.3rem; }
.chat-msg__text h2 { font-size: 1.15rem; }
.chat-msg__text h3 { font-size: 1.05rem; }
.chat-msg__text h4,.chat-msg__text h5,.chat-msg__text h6 { font-size: 1rem; }
.chat-msg__text ul { margin: .35em 0 .6em; padding-left: 1.35em; }
.chat-msg__text li { margin: .2em 0; }
.chat-msg__text strong { font-weight: 600; color: var(--txt); }
.chat-msg__text em { font-style: italic; }
.chat-msg__text a { color: var(--accent-2); text-decoration: underline; }
.chat-msg__text a:hover { color: var(--accent-strong); }
.chat-msg__text .md-inline { font-family: var(--font-mono); font-size: .85em; background: rgba(255,255,255,0.07); padding: 1px 5px; border-radius: 4px; }
.chat-msg__text .md-code { background: var(--bg-0); border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; overflow-x: auto; margin: .5em 0; }
.chat-msg__text .md-code code { font-family: var(--font-mono); font-size: .85em; color: var(--text-primary); white-space: pre; }
/* user bubble: keep markdown legible on the amber tint */
.chat-msg--user .chat-msg__text a { color: #1a1f27; text-decoration: underline; }
.chat-msg--user .chat-msg__text .md-inline { background: rgba(0,0,0,0.12); }

/* ============================================================
   CHAT SEARCH PALETTE (Ctrl+K)
   ============================================================ */
.chat-search-overlay {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(7, 9, 12, 0.62);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 8vh 16px 0;
}
.chat-search-overlay[hidden] { display: none; }
.chat-search-modal {
  width: 100%; max-width: 620px;
  background: var(--bg-1);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 18px 60px rgba(0,0,0,0.55);
  overflow: hidden;
  display: flex; flex-direction: column;
  max-height: 74vh;
}
.chat-search-modal__input-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.chat-search-modal__icon { color: var(--text-dim); font-size: 16px; }
.chat-search-modal__input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-size: 15px;
  font-family: var(--font-ui);
  outline: none;
}
.chat-search-modal__input::placeholder { color: var(--text-dim); }
.chat-search-modal__esc {
  font-family: var(--font-mono); font-size: 10px;
  padding: 2px 6px; border: 1px solid var(--border-strong);
  border-radius: 3px; color: var(--text-dim);
}
.chat-search-modal__results {
  overflow-y: auto;
  padding: 6px;
  flex: 1; min-height: 80px;
}
.chat-search-modal__empty {
  padding: 22px 14px;
  text-align: center;
  color: var(--text-dim);
  font-size: 12px;
  font-family: var(--font-mono);
}
.chat-result {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  border: 1px solid transparent;
}
.chat-result:hover, .chat-result.is-selected {
  background: var(--bg-2);
  border-color: var(--border);
}
.chat-result.is-selected { border-color: var(--accent-2); }
.chat-result__dot {
  width: 8px; height: 8px; border-radius: 50%;
  margin-top: 6px; flex-shrink: 0;
  background: var(--accent-2);
}
.chat-result__dot--user { background: var(--accent); }
.chat-result__body { min-width: 0; flex: 1; }
.chat-result__meta {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 2px;
}
.chat-result__label { font-size: 11px; font-weight: 600; color: var(--text-secondary); }
.chat-result__time { font-size: 10px; color: var(--text-dim); font-family: var(--font-mono); }
.chat-result__snippet {
  font-size: 12px; color: var(--text-secondary);
  line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.chat-search-modal__hint {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 14px;
  border-top: 1px solid var(--border);
  font-size: 10px; color: var(--text-dim);
  font-family: var(--font-mono);
  flex-wrap: wrap; gap: 6px;
}
.chat-search-modal__hint kbd {
  font-family: var(--font-mono); font-size: 10px;
  padding: 1px 5px; border: 1px solid var(--border-strong);
  border-radius: 3px; margin: 0 1px;
}

/* ============================================================
   Accessibility polish (coherent system)
   ============================================================ */
:focus-visible { outline: 2px solid var(--accent-2); outline-offset: 1px; }
.btn:focus-visible, .tab-bar__btn:focus-visible, .chat-agent:focus-visible,
.chat-session:focus-visible, .chat-actions__head:focus-visible,
.chat-msg__copy:focus-visible, .chat-result:focus-visible { outline-offset: -2px; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
  .chat-msg.is-streaming .chat-msg__text::after { animation: none; opacity: 0.6; }
}
