/* base.css — theme, shell layout, shared components */
* { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Theme root ─────────────────────────────────────────────── */
/* Tell the browser every native control (select popups, option lists,
   scrollbars, number-input spinners, checkboxes, file pickers) renders
   with its dark palette. Without this, <select> dropdowns pop open in
   the OS light theme even though the page is dark. */
:root {
  color-scheme: dark;
  --bg:     #0e1116;
  --panel:  #1a1f29;
  --border: #2c333d;
  --accent: #88c0d0;
  --fg:     #d8dee9;
  --muted:  #6c7280;
}

/* Native <option> elements inside a <select> popup (Firefox honours
   these; Chromium follows :root color-scheme above). */
option { background: #1a1f29; color: #d8dee9; }

/* ── Scrollbars: one consistent dark style everywhere ────────── */
* { scrollbar-width: thin; scrollbar-color: #3b4252 transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: #3b4252;
  border-radius: 5px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover { background: #4c566a; background-clip: padding-box; }
*::-webkit-scrollbar-corner { background: transparent; }

html, body { height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  font-size: 13px;
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
}
.app {
  display: grid;
  grid-template-rows: 48px 1fr;
  grid-template-columns: 48px 1fr;
  height: 100vh;
  height: 100dvh;   /* iOS Safari: visible height, not URL-bar-inflated */
}
/* Explicit grid placement for every track. REQUIRED: the splitters go
   display:none when their panel is collapsed — without explicit placement,
   auto-placement would shift the panel into the splitter's 0px track and
   the panel would vanish entirely (the old "can't un-collapse" bug). */
.toolbar     { grid-row: 1; grid-column: 1 / -1; }
.activity-bar{ grid-row: 2; grid-column: 1; }
.content     { grid-row: 2; grid-column: 2; min-height: 0; display: flex; }
.page        { flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.page.hidden { display: none; }
#page-nodes  { display: grid; grid-template-rows: 1fr 6px var(--out-h, 166px); }
#page-nodes .main { grid-row: 1; }
#page-nodes #split-out { grid-row: 2; }
#page-nodes #output    { grid-row: 3; }
.canvas-wrap { grid-column: 1; }
#split-insp  { grid-column: 2; }
#inspector   { grid-column: 3; }
.app.out-collapsed #page-nodes { grid-template-rows: 1fr 0 28px; }

/* ── Toolbar ───────────────────────────────────── */
.toolbar {
  background: #1a1f29;
  border-bottom: 1px solid #2c333d;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 16px;
}
.brand { font-weight: 600; font-size: 15px; color: #88c0d0; flex: 0 0 auto; white-space: nowrap; }
.brand-sub { color: #6c7280; font-size: 11px; }
.spacer { flex: 1 1 0; min-width: 4px; }
.status { color: #8fbcbb; font-family: monospace; font-size: 11px; flex: 0 0 auto; white-space: nowrap; }

.btn {
  background: #2c333d; color: #d8dee9; border: 1px solid #3b4252;
  border-radius: 4px; padding: 6px 12px; cursor: pointer; font: inherit;
}
.btn:hover { background: #3b4252; }
select.btn { padding-right: 24px; }
select.btn:focus { outline: none; border-color: #88c0d0; }
.btn.primary { background: #5e81ac; border-color: #5e81ac; color: white; }
.btn.primary:hover { background: #81a1c1; }

/* ── Main area ─────────────────────────────────── */
.main {
  display: grid;
  grid-template-columns: 1fr 6px var(--insp-w, 286px);
  overflow: hidden;
}
.app.insp-collapsed .main { grid-template-columns: 1fr 0 28px; }
.inspector {
  background: #14181f;
  border-left: 1px solid #2c333d;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.inspector .panel-body { padding: 0 12px 12px; overflow-y: auto; flex: 1; }
.panel-title {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #6c7280;
  margin-bottom: 8px;
}
.muted { color: #6c7280; font-size: 11px; line-height: 1.5; }

/* ─── Activity bar (VS Code-style left rail) ──────────────────────────── */
.activity-bar { display:flex; flex-direction:column; align-items:center; background:var(--panel); border-right:1px solid var(--border); padding:8px 0; gap:4px; }
.ab-spacer { flex:1; }
.ab-item { width:40px; height:40px; display:grid; place-items:center; background:none; border:none; border-left:2px solid transparent; color:var(--muted); cursor:pointer; }
.ab-item:hover { color:var(--fg); }
.ab-item.active { color:var(--accent); border-left-color:var(--accent); }
/* ─── Triggers + Settings pages ───────────────────────────────────────── */
.page-body { padding:20px 24px; overflow:auto; max-width:920px; width:100%; margin:0 auto; }
.page-body h2 { margin:0 0 8px; font-size:18px; }
.trig-rows { display:flex; flex-direction:column; gap:8px; margin:12px 0; }
.settings-section { margin:14px 0; }
.settings-section h3 { font-size:13px; text-transform:uppercase; letter-spacing:.04em; color:var(--muted); margin:0 0 6px; }
.kv { display:grid; grid-template-columns:160px 1fr; gap:4px 12px; font-size:13px; }
.kv .k { color:var(--muted); }
.kv code { font-size:12px; }


/* ── Modal / browse overlay ─────────────────────────────────────────── */
.browse-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9000;
}
.browse-overlay.hidden { display: none; }

.browse-card {
  background: var(--bg1, #1e2030);
  border: 1px solid var(--border, #2d3250);
  border-radius: 10px;
  padding: 28px 28px 20px;
  min-width: 360px;
  max-width: 90vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.6);
}
.browse-card h3 {
  margin: 0 0 18px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text, #cdd6f4);
}
.browse-card .insp-help { color: #f38ba8; font-size: 0.82rem; margin: 6px 0 0; }

/* ── Phase 12: keys page (table + modal) ─────────────────────────── */
.page-wide { max-width: 1240px; }

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 18px;
}
.page-head h2 { margin: 0 0 6px; }

.kv-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
  background: var(--bg1, #151923);
  border: 1px solid var(--border); border-radius: 8px; overflow: hidden;
}
.kv-table th {
  text-align: left; font-size: 11px; font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: #6c7280;
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.02);
}
.kv-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); }
.kv-table tbody tr:last-child td { border-bottom: none; }
.kv-table tbody tr:hover { background: rgba(136,192,208,.05); }
.row-revoked td { opacity: .45; }
.cell-name { font-weight: 600; }
.cell-id {
  font-size: 11.5px; color: var(--accent);
  display: inline-block; max-width: 180px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  vertical-align: middle;
}
.muted-cell { color: #6c7280; font-size: 12px; white-space: nowrap; }
.col-actions { width: 44px; text-align: right; }

.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 600; letter-spacing: .02em;
  border: 1px solid var(--border);
}
.badge-active  { color: #a3be8c; border-color: #3a4a35; background: rgba(163,190,140,.08); }
.badge-revoked { color: #6c7280; }
.badge-agent   { color: var(--accent); border-color: #2e4a54; background: rgba(136,192,208,.08); }
.badge-read    { color: #d8dee9; }
.badge-admin   { color: #ebcb8b; border-color: #55492e; background: rgba(235,203,139,.08); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; padding: 0;
  background: transparent; border: 1px solid transparent; border-radius: 6px;
  color: #8b93a1; cursor: pointer;
}
.icon-btn:hover { background: #3b4252; color: var(--fg); }
.icon-danger:hover { color: #bf616a; background: rgba(191,97,106,.12); }

.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(8,10,14,.6); backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
}
.modal-overlay.hidden, .hidden { display: none !important; }
.modal-panel {
  width: 440px; max-width: calc(100vw - 48px);
  background: var(--bg1, #151923);
  border: 1px solid var(--border); border-radius: 10px;
  padding: 18px 20px; box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.modal-head h3 { margin: 0; font-size: 15px; }
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.form-row label { font-size: 12px; color: #8b93a1; }
.form-row input, .form-row select { width: 100%; box-sizing: border-box; }
.form-err { color: #bf616a; font-size: 12px; min-height: 16px; margin-bottom: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }

.reveal-warn { color: #ebcb8b; font-size: 13px; margin: 0 0 10px; }
.reveal-key {
  display: block; padding: 12px; border-radius: 6px;
  background: rgba(136,192,208,.08); border: 1px solid #2e4a54;
  color: var(--accent); font-size: 13px;
  user-select: all; word-break: break-all;
}

/* ── Phase 13: agents page (roster cards) ────────────────────────── */
.agents-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
}
.agent-card {
  background: var(--bg1, #151923); border: 1px solid var(--border);
  border-radius: 10px; padding: 14px 16px;
  transition: border-color .15s;
}
.agent-card:hover { border-color: #3d4552; }
.agent-card.status-busy { border-color: #2e4a54; }
.agent-top { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.agent-avatar { flex: 0 0 auto; display: flex; }
.agent-id-block { flex: 1; min-width: 0; }
.agent-name { font-size: 15px; font-weight: 600; }
.agent-role {
  font-size: 12px; color: #8b93a1;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.agent-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.agent-meta div { font-size: 12px; color: var(--fg); }
.agent-meta span {
  display: block; font-size: 10px; text-transform: uppercase;
  letter-spacing: .05em; color: #6c7280; margin-bottom: 1px;
}
.badge.st-idle   { color: #8b93a1; }
.badge.st-busy   { color: #a3be8c; border-color: #3a4a35; background: rgba(163,190,140,.10); }
.badge.st-cancelling { color: #ebcb8b; border-color: #55492e; background: rgba(235,203,139,.10); }

/* ── Phase 13: models page ─────────────────────────────────────────── */
.section-head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 22px 0 8px;
}
.section-head h3 { margin: 0; font-size: 14px; }
.modal-panel form label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: #8b93a1; margin-bottom: 12px;
}
.modal-panel form label.check { flex-direction: row; align-items: center; gap: 8px; }
.modal-panel form input, .modal-panel form select {
  background: #0f1319; border: 1px solid var(--border); border-radius: 6px;
  color: var(--fg); padding: 8px 10px; font-size: 13px;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.modal-head h3 { margin: 0; font-size: 15px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.discover-list { max-height: 320px; overflow-y: auto; margin-bottom: 10px; }
.discover-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; padding: 6px 4px; border-bottom: 1px solid #1c212b;
  font-size: 13px;
}
.star { color: #6c7280; }
.star-on { color: #ebcb8b; }
.badge-ok { color: #a3be8c; border-color: #3a4a35; background: rgba(163,190,140,.10); }

/* ── tasks page ────────────────────────────────────────────────────── */
.day-picker { display: flex; gap: 10px; flex-wrap: wrap; margin: 4px 0 8px; }
.day-picker label { display: flex; align-items: center; gap: 4px; font-size: 13px; }
.modal-panel textarea { width: 100%; box-sizing: border-box; background: #2e3440;
  border: 1px solid #4c566a; border-radius: 6px; color: inherit; padding: 6px 8px;
  font: inherit; resize: vertical; }

/* ── skills page chips ── */
.skill-chip { border: 1px solid var(--border, #444); background: transparent;
  color: inherit; border-radius: 999px; padding: 2px 10px; font-size: 12px;
  cursor: pointer; opacity: 0.65; }
.skill-chip:hover { opacity: 1; }
.skill-chip-on { opacity: 1; background: var(--accent, #3584e4);
  border-color: var(--accent, #3584e4); color: #fff; }

.busy-dot { color: var(--accent, #3584e4); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ── Mobile / narrow viewports (≤760px) ─────────────────────────────── */
@media (max-width: 760px) {
  .toolbar { padding: 0 10px; gap: 10px; }
  .brand { font-size: 14px; }
  .brand-sub { display: none; }               /* keep the bar one line */

  .ab-item { width: 44px; height: 44px; }     /* touch targets ≥44px */

  .page-body { padding: 12px 12px; }
  .page-body h2 { font-size: 16px; }

  /* Titles + action buttons wrap instead of squeezing */
  .page-head, .section-head { flex-wrap: wrap; gap: 8px; }

  /* Tables collapse into labeled cards — no sideways scrolling at all.
     data-label attributes are auto-filled by main.js from the thead. */
  .kv-table { display: block; background: none; border: none; }
  .kv-table thead { display: none; }
  .kv-table tbody { display: block; }
  .kv-table tbody tr {
    display: block; margin-bottom: 10px; padding: 4px 12px;
    background: var(--bg1, #151923);
    border: 1px solid var(--border); border-radius: 8px;
  }
  .kv-table td {
    display: flex; justify-content: space-between; align-items: baseline;
    gap: 12px; padding: 7px 0; border-bottom: 1px solid rgba(255,255,255,.05);
    white-space: normal; word-break: break-word;
  }
  .kv-table td:last-child { border-bottom: none; }
  .kv-table td::before {
    content: attr(data-label); flex: 0 0 auto;
    font-size: 10px; font-weight: 600; letter-spacing: .04em;
    text-transform: uppercase; color: #6c7280;
  }
  .kv-table td[rowspan], .kv-table td[colspan] { display: block; text-align: center; }
  .kv-table td[colspan]::before { content: none; }
  .cell-id { max-width: 60%; }

  /* Cards: single column, no min track width */
  .agents-grid { grid-template-columns: 1fr; }

  /* Modals: near-full-width, no fixed minimums */
  .modal-panel { width: auto; min-width: 0; max-width: calc(100vw - 24px);
                 max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px); overflow-y: auto;
                 padding: 14px 16px; }
  .browse-card { min-width: 0; width: calc(100vw - 24px); padding: 18px 16px 14px; }

  /* Settings key/value grid: stack labels over values */
  .kv { grid-template-columns: 1fr; gap: 2px 0; }
  .kv .k { margin-top: 6px; }
}

/* Phase 6: Agent Computer modal (noVNC iframe) */
.screen-panel { width: min(1320px, 96vw); max-width: 96vw; }
.screen-body  { min-height: 300px; }
.screen-frame { width: 100%; height: min(82dvh, 800px); border: 0;
                border-radius: 6px; background: #111; }
.agent-actions { margin-top: 10px; display: flex; gap: 8px; }

/* Phase 16: auto-review rules editor */
.rule-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.rule-row .rule-cmd { flex: 1; }
.rule-row select, .rule-row input { background: #1a1d23; color: #d8dee9;
  border: 1px solid #3b4252; border-radius: 4px; padding: 6px 8px; font-size: 13px; }
@media (max-width: 760px) {
  .rule-row { flex-wrap: wrap; }
  .rule-row .rule-cmd { flex-basis: 100%; order: 2; }
}

/* Phase 19: structured error toasts */
#error-toasts {
  position: fixed; right: 16px; bottom: 16px; z-index: 999;
  display: flex; flex-direction: column; gap: 8px; max-width: min(480px, 92vw);
}
.error-toast {
  display: flex; align-items: center; gap: 8px;
  background: var(--card, #22252b); border: 1px solid #e01b24; border-radius: 8px;
  padding: 10px 12px; box-shadow: 0 4px 16px rgba(0,0,0,.35);
  transition: opacity .4s;
}
.error-toast.fade { opacity: 0; }
.error-toast-msg { flex: 1; font-size: 13px; word-break: break-word; }
.error-toast-id { font-size: 11px; opacity: .75; user-select: all; }

/* Phase 19: light theme (Settings → Appearance; persisted client-side) */
[data-theme="light"] {
  color-scheme: light;
  --bg:     #f2f4f8;
  --panel:  #ffffff;
  --bg1:    #e8ebf0;
  --card:   #ffffff;
  --border: #cdd3dc;
  --accent: #1c71d8;
  --fg:     #1d2330;
  --muted:  #667085;
}
[data-theme="light"] option { background: #ffffff; color: #1d2330; }
[data-theme="light"] * { scrollbar-color: #b8c0cc transparent; }
[data-theme="light"] *::-webkit-scrollbar-thumb { background: #b8c0cc; }
[data-theme="light"] .error-toast { border-color: #d92d20; box-shadow: 0 4px 16px rgba(0,0,0,.15); }
[data-theme="light"] .icon-btn:hover { background: #e2e6ec; }
