/* ToolHarbor — hand-written CSS, no build step, no CDN.
   Visual contract: docs/STYLE.md. Dark is the reference palette (an admin
   dashboard screenshot the owner supplied); light is its mirror. Colours
   live ONLY in the three token blocks below — never as literals in a rule.
   Theming: dark palette under prefers-color-scheme AND under
   [data-theme="dark"] so an explicit localStorage choice always wins over
   the system setting; light palette lives on bare :root. */

:root {
  --bg: #f4f7fa;
  --bg-sidebar: #ffffff;
  --bg-elevated: #ffffff;
  --bg-sunken: #eef2f6;
  --border: rgba(13, 148, 136, 0.18);
  --border-strong: rgba(13, 148, 136, 0.4);
  --fg: #0f1b26;
  --fg-muted: #51627a;
  --fg-faint: #7e8ea0;
  --accent: #0284c7;
  --accent-2: #0d9488;
  --accent-fg: #ffffff;
  --ok: #15803d;
  --warn: #b45309;
  --error: #dc2626;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-card: 0 0 0 1px var(--border), 0 8px 24px rgba(15, 27, 38, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  --glow: 0 0 20px rgba(13, 148, 136, 0.14);
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --sidebar-width: 260px;
  --header-height: 72px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0a1219;
    --bg-sidebar: #0c1821;
    --bg-elevated: #0f1e2a;
    --bg-sunken: #081017;
    --border: rgba(94, 234, 212, 0.14);
    --border-strong: rgba(94, 234, 212, 0.32);
    --fg: #e6edf3;
    --fg-muted: #8b9bab;
    --fg-faint: #5f7080;
    --accent: #38bdf8;
    --accent-2: #2dd4bf;
    --accent-fg: #06212b;
    --ok: #34d399;
    --warn: #f5a524;
    --error: #f87171;
    --shadow-card: 0 0 0 1px var(--border), 0 8px 30px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.03);
    --glow: 0 0 24px rgba(45, 212, 191, 0.12);
  }
}

:root[data-theme="dark"] {
  --bg: #0a1219;
  --bg-sidebar: #0c1821;
  --bg-elevated: #0f1e2a;
  --bg-sunken: #081017;
  --border: rgba(94, 234, 212, 0.14);
  --border-strong: rgba(94, 234, 212, 0.32);
  --fg: #e6edf3;
  --fg-muted: #8b9bab;
  --fg-faint: #5f7080;
  --accent: #38bdf8;
  --accent-2: #2dd4bf;
  --accent-fg: #06212b;
  --ok: #34d399;
  --warn: #f5a524;
  --error: #f87171;
  --shadow-card: 0 0 0 1px var(--border), 0 8px 30px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.03);
  --glow: 0 0 24px rgba(45, 212, 191, 0.12);
}

/* ---------- base ---------- */
/* An authored `display` rule on an element beats the UA stylesheet's
   `[hidden]{display:none}` regardless of specificity (author normal always
   wins over UA normal) — several elements here set display:flex, so without
   this guard `el.hidden = true` would silently stop hiding them. */
[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body {
  height: 100%;
  margin: 0;
  overflow-x: hidden;
}
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
@media (prefers-reduced-motion: no-preference) {
  .btn, .btn-icon, .card, .tree-item, .sidebar-row, input, select, textarea {
    transition: background-color 120ms ease, border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease, color 120ms ease;
  }
}
h1, h2, h3 { margin: 0 0 var(--space-3); line-height: 1.25; font-weight: 700; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.05rem; color: var(--fg-muted); margin-top: var(--space-5); }
p { margin: 0 0 var(--space-3); }
a { color: inherit; }
.icon { flex: 0 0 auto; display: inline-block; vertical-align: middle; color: inherit; }

/* genuine inline text links ONLY — never used for action controls */
.link {
  color: var(--accent);
  text-decoration: underline;
}

/* ---------- buttons ---------- */
.btn, .btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  height: 38px;
  padding: 0 var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 0.9rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; filter: none; }
.btn:focus-visible, .btn-icon:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 1px;
}

.btn-primary { background: var(--accent); color: var(--accent-fg); }
.btn-secondary {
  background: transparent;
  color: var(--fg);
  border-color: var(--border-strong);
}
.btn-secondary:hover { background: color-mix(in srgb, var(--accent-2) 8%, transparent); filter: none; }
.btn-quiet {
  background: transparent;
  color: var(--fg-muted);
  border-color: transparent;
}
.btn-quiet:hover { background: color-mix(in srgb, var(--accent-2) 6%, transparent); color: var(--fg); filter: none; }
.btn-danger { background: transparent; color: var(--error); border-color: var(--error); }
.btn-danger:hover { background: var(--error); color: #fff; filter: none; }
.btn-small { height: 30px; padding: 0 var(--space-3); font-size: 0.8rem; }
.btn-block { width: 100%; }
.btn-icon {
  width: 38px;
  height: 38px;
  padding: 0;
  background: transparent;
  color: var(--fg-muted);
  border-color: transparent;
}
.btn-icon:hover { background: color-mix(in srgb, var(--accent-2) 8%, transparent); color: var(--fg); }

/* ---------- forms ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  margin-bottom: var(--space-3);
  font-size: 0.85rem;
  color: var(--fg-muted);
  max-width: 420px;
}
.field input[type="text"],
.field input[type="password"],
.field input[type="email"],
.field input[type="url"],
.field input[type="search"],
.field select {
  font: inherit;
  color: var(--fg);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  height: 38px;
}
.field input:focus, .field select:focus { border-color: var(--accent-2); }
.field-inline {
  flex-direction: row;
  align-items: center;
  gap: var(--space-2);
}
.field-inline input[type="checkbox"] { width: 16px; height: 16px; }
form { max-width: 480px; margin-bottom: var(--space-5); }
.inline-edit {
  font: inherit;
  color: var(--fg);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  height: 32px;
}

.form-message {
  white-space: pre-wrap;             /* review failures arrive one per line */
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--error);
  background: color-mix(in srgb, var(--error) 8%, transparent);
  color: var(--error);
  font-size: 0.85rem;
  margin-bottom: var(--space-3);
}

/* ---------- app shell layout ---------- */
#app-shell {
  display: flex;
  height: 100vh;
}
.content-col {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* ---------- sidebar ---------- */
.sidebar {
  flex: 0 0 var(--sidebar-width);
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
}
.sidebar-top { padding: var(--space-4) var(--space-4) var(--space-3); }
.brand { display: flex; align-items: center; gap: var(--space-3); }
.brand-icon {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--accent-2) 14%, transparent);
}
.brand-icon-img { width: 36px; height: 36px; display: block; object-fit: cover; }
.brand-text { min-width: 0; }
.brand-name { font-size: 1.1rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-subtitle { font-size: 0.75rem; color: var(--fg-muted); }

.sidebar-scroll { flex: 1 1 auto; overflow-y: auto; padding: 0 var(--space-3) var(--space-3); }
.nav-section-label {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--fg-faint);
  margin: var(--space-5) var(--space-2) var(--space-2);
}
.sidebar-scroll .nav-section-label:first-child { margin-top: var(--space-2); }

.tree-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 40px;
  padding: 0 var(--space-2) 0 calc(var(--space-2) - 3px);
  border-left: 3px solid transparent;
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--fg-muted);
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
}
.tree-item .tree-label { overflow: hidden; text-overflow: ellipsis; }
.tree-item:hover { background: color-mix(in srgb, var(--accent-2) 6%, transparent); color: var(--fg); }
.tree-item.active {
  background: color-mix(in srgb, var(--accent-2) 12%, transparent);
  border-left-color: var(--accent-2);
  color: var(--fg);
  font-weight: 600;
}
.tree-item.depth-1 { padding-left: calc(var(--space-2) - 3px + 16px); }
.tree-item.depth-2 { padding-left: calc(var(--space-2) - 3px + 32px); }
.tree-item.depth-3 { padding-left: calc(var(--space-2) - 3px + 48px); }
.admin-nav { display: flex; flex-direction: column; gap: 1px; }

.sidebar-bottom {
  flex: 0 0 auto;
  border-top: 1px solid var(--border);
  padding: var(--space-2);
}
.sidebar-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  height: 40px;
  padding: 0 var(--space-2);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg-muted);
  font: inherit;
  font-size: 15px;
  text-align: left;
  cursor: pointer;
}
.sidebar-row:hover { background: color-mix(in srgb, var(--accent-2) 6%, transparent); color: var(--fg); }
.nav-icon { flex: 0 0 auto; display: inline-flex; }

#view {
  flex: 1 1 auto;
  min-width: 0;
  overflow-y: auto;
  background: var(--bg);
}
.browse-view, .admin-view, .settings-view { padding: var(--space-5); }

/* ---------- page header band ---------- */
.page-header {
  flex: 0 0 var(--header-height);
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 0 var(--space-5);
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
}
.page-title {
  margin: 0;
  flex: 1 1 auto;
  min-width: 0;
  font-size: 1.75rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.page-header-actions { display: flex; align-items: center; gap: var(--space-3); flex: 0 0 auto; }
.phone-only { display: none; }

.search-wrap { position: relative; width: 280px; flex: 0 0 auto; }
.search-icon-btn {
  position: absolute;
  left: 0;
  top: 0;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  color: var(--fg-faint);
  cursor: pointer;
  padding: 0;
}
.search-box {
  width: 100%;
  height: 38px;
  padding: 0 var(--space-3) 0 36px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-sunken);
  color: var(--fg);
  font: inherit;
}
.search-box:focus { border-color: var(--accent-2); outline: none; }
.search-box::placeholder { color: var(--fg-faint); }

.user-chip-wrap { position: relative; flex: 0 0 auto; }
.user-chip {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  height: 38px;
  padding: 0 var(--space-3) 0 var(--space-1);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  font: inherit;
}
.user-chip:hover { background: color-mix(in srgb, var(--accent-2) 8%, transparent); }
.user-chip-avatar {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--accent-2) 20%, transparent);
  color: var(--accent-2);
  font-weight: 700;
  font-size: 0.8rem;
}
.user-chip-name { font-size: 0.88rem; font-weight: 600; max-width: 140px; overflow: hidden; text-overflow: ellipsis; }
.user-chip-panel {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + var(--space-2));
  min-width: 180px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: var(--space-2);
  z-index: 50;
}
.user-chip-panel.open { display: block; }
.menu-item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--fg);
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-sm);
  font: inherit;
  cursor: pointer;
}
.menu-item:hover { background: color-mix(in srgb, var(--accent-2) 8%, transparent); }

/* ---------- breadcrumbs ---------- */
#crumbs {
  display: flex;
  align-items: center;
  gap: var(--space-1);
  margin-bottom: var(--space-4);
  font-size: 0.85rem;
  color: var(--fg-muted);
  flex-wrap: wrap;
}
#crumbs a { text-decoration: none; color: var(--fg-muted); }
#crumbs a:hover { text-decoration: underline; color: var(--fg); }
.crumb-sep { color: var(--fg-faint); display: inline-flex; }
.crumb-current { color: var(--fg); font-weight: 600; }

/* ---------- cards ---------- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: var(--space-4);
}
.card {
  display: block;
  padding: var(--space-5);
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  text-decoration: none;
  color: var(--fg);
}
.card:hover { box-shadow: var(--shadow-card), var(--glow); border-color: var(--border-strong); transform: translateY(-1px); }
.card-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--space-3); }
.card-icon {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--accent-2) 14%, transparent);
  color: var(--accent-2);
  font-size: 1.3rem;
}
.card.folder .card-icon { color: var(--accent-2); background: transparent; width: auto; height: auto; }
.card-name { font-weight: 600; font-size: 1rem; margin-bottom: var(--space-1); }
.card-desc { font-size: 0.82rem; color: var(--fg-muted); }
.empty-note { color: var(--fg-muted); font-style: italic; }

/* ---------- status dots ---------- */
.status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex: 0 0 auto;
}
.status-dot.status-running { background: var(--ok); }
.status-dot.status-stopped { background: var(--fg-faint); }
.status-dot.status-error { background: var(--error); }
.status-dot.status-installing { background: var(--warn); }

/* ---------- tool view ---------- */
.tool-view { height: 100%; display: flex; flex-direction: column; }
.tool-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-bottom: 1px solid var(--border);
  background: var(--bg-sidebar);
  flex-wrap: wrap;
}
.tool-toolbar #crumbs { margin: 0; }
.tool-actions { display: flex; gap: var(--space-2); }
#tool-frame {
  flex: 1 1 auto;
  width: 100%;
  border: 0;
  /* Always white, in BOTH themes: an iframe is transparent, so a tool that
     paints no background would otherwise show the portal's dark ground
     behind its default black text. A tool owns its own theme. */
  background: #fff;
}

/* select + button on one row (tool page folder picker) */
.field-inline-row { flex-direction: row; align-items: center; gap: var(--space-2); }
.field-inline-row select { flex: 1 1 auto; min-width: 0; }

/* informational callout (new-tool page) */
.callout {
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--accent-2);
  box-shadow: var(--shadow-card);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-4);
  max-width: 760px;
}
.callout p { margin: 0 0 var(--space-3); color: var(--fg-muted); }
.log-bar { margin-bottom: var(--space-2); }

/* ---------- login ---------- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: var(--space-4);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: var(--space-6) var(--space-5);
}
.login-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-5);
}
.login-brand-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: color-mix(in srgb, var(--accent-2) 14%, transparent);
}
.login-brand-icon img { width: 48px; height: 48px; display: block; object-fit: cover; }
.login-brand-name { font-size: 1.3rem; font-weight: 700; text-align: center; }
.login-card form { max-width: none; margin-bottom: 0; }

/* ---------- settings ---------- */
.settings-note {
  display: flex;
  align-items: flex-start;
  gap: var(--space-2);
  background: color-mix(in srgb, var(--warn) 10%, transparent);
  color: var(--fg);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  margin-bottom: var(--space-4);
}

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; max-width: 100%; }
.data-table {
  border-collapse: collapse;
  width: 100%;
  min-width: 560px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}
.data-table th, .data-table td {
  text-align: left;
  padding: 0 var(--space-3);
  height: 44px;
  border-bottom: 1px solid var(--border);
  font-size: 0.85rem;
  vertical-align: middle;
}
.data-table th {
  color: var(--fg-faint);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  height: 38px;
}
.data-table tr:last-child td { border-bottom: none; }
.row-actions { display: flex; gap: var(--space-1); flex-wrap: wrap; }
/* Inside a table the actions cell must stay a table cell: display:flex on a
   <td> freezes it at the row height and its buttons wrap onto the next row
   (seen at 1280px once the Email column landed). Never wrap; the
   .table-scroll wrapper scrolls instead. */
.data-table td.row-actions { display: table-cell; white-space: nowrap; }
.data-table td.row-actions .btn { margin-right: var(--space-1); vertical-align: middle; }

/* ---------- admin: review wizard ---------- */
.review-summary {
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: var(--space-4);
  margin-bottom: var(--space-4);
  max-width: 480px;
}
.review-facts { display: grid; grid-template-columns: auto 1fr; gap: var(--space-1) var(--space-3); margin: 0; font-variant-numeric: tabular-nums; }
.review-facts dt { color: var(--fg-muted); }
.review-facts dd { margin: 0; }
.review-warnings { color: var(--warn); margin: var(--space-3) 0 0; padding-left: var(--space-4); }

.admin-view-header { display: flex; align-items: center; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-4); }
.admin-view-header h1 { margin: 0; }

/* ---------- folder tree editor ---------- */
.folder-admin-level { margin-left: var(--space-4); }
.folder-row {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-2);
  border-radius: var(--radius-sm);
}
.folder-row:hover { background: var(--bg-sunken); }
.folder-icon { color: var(--accent-2); display: inline-flex; flex: 0 0 auto; }
.access-panel {
  margin: var(--space-2) 0 var(--space-4) var(--space-5);
  padding: var(--space-4);
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  max-width: 480px;
}
.access-heading { margin-top: 0; }
.grant-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}
.grant-row:last-child { border-bottom: none; }
.grant-list { margin-bottom: var(--space-3); }
.grant-icon { color: var(--accent-2); display: inline-flex; flex: 0 0 auto; }
.grant-path { flex: 1 1 auto; }

/* ---------- group-first access hub (SPEC §11) ---------- */
/* Overrides .data-table th/td's own height + border-bottom, which otherwise
   leave a stray 44px empty strip under every CLOSED group row — a
   [hidden] .group-panel is display:none (zero box) but the td around it
   still carries the base rule's fixed height and hairline. */
.data-table td.group-panel-cell { height: auto; padding: 0; border-bottom: none; }
.group-panel {
  margin: var(--space-2) 0 var(--space-3);
  padding: var(--space-4);
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
}
.group-panel-columns { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5); }
.group-panel-col h3 { margin-top: 0; }
.field-inline.inactive { color: var(--fg-faint); }

@media (max-width: 720px) {
  .group-panel-columns { grid-template-columns: 1fr; gap: var(--space-4); }
}

/* ---------- tool detail ---------- */
.tool-detail-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.tool-status { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-4); }
.tool-log {
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-3);
  max-height: 360px;
  overflow: auto;
  font: 12.5px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
}
.checkbox-list { display: flex; flex-direction: column; gap: var(--space-1); max-height: 240px; overflow-y: auto; }

/* ---------- toasts ---------- */
.toast-container {
  position: fixed;
  right: var(--space-4);
  bottom: var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  z-index: 100;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-width: 220px;
  max-width: 360px;
  padding: var(--space-3) var(--space-3);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  color: var(--fg);
  box-shadow: var(--shadow-card);
  border-left: 3px solid var(--border-strong);
}
.toast-success { border-left-color: var(--ok); }
.toast-error { border-left-color: var(--error); }
.toast-message { flex: 1 1 auto; font-size: 0.85rem; }
.toast-dismiss { font-size: 1rem; }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 12, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: var(--space-4);
}
.modal-panel {
  width: 100%;
  max-width: 420px;
  background: var(--bg-elevated);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: var(--space-5);
}
.modal-title { margin-top: 0; }
.modal-message { color: var(--fg-muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-4); }

/* ---------- phone width (390px target) ---------- */
@media (max-width: 720px) {
  .phone-only { display: inline-flex; }
  .page-header { padding: 0 var(--space-3); gap: var(--space-2); }
  .page-title { font-size: 1.2rem; }
  .user-chip-name { display: none; }

  .search-wrap { width: 38px; }
  .search-wrap .search-box { display: none; }
  .search-wrap.search-expanded {
    position: absolute;
    right: var(--space-3);
    top: calc(100% + var(--space-2));
    width: min(78vw, 280px);
    z-index: 40;
  }
  .search-wrap.search-expanded .search-box { display: block; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(82vw, 280px);
    transform: translateX(-100%);
    z-index: 60;
    box-shadow: var(--shadow-card);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(4, 8, 12, 0.5);
    z-index: 55;
  }
  .sidebar-overlay[hidden] { display: none; }

  .browse-view, .admin-view, .settings-view { padding: var(--space-4); }
  .cards-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .tool-toolbar { flex-direction: column; align-items: stretch; padding: var(--space-3) var(--space-4); }
  .tool-actions { justify-content: stretch; }
  .tool-actions .btn { flex: 1 1 auto; }
  .admin-view-header { flex-direction: column; align-items: stretch; }
}
@media not all and (max-width: 720px) {
  .sidebar-overlay { display: none; }
}

/* ---------- tool requests (SPEC §14) ---------- */
/* textarea was never styled under .field — every other input type was. */
.field textarea {
  font: inherit;
  color: var(--fg);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  min-height: 90px;
  resize: vertical;
}
.field textarea:focus { border-color: var(--accent-2); }

/* small helper copy under a field — the §14 "prompt text under the field",
   and doubles as the live character-count hint on problem/desired. */
.field-hint { font-size: 0.78rem; color: var(--fg-faint); margin-top: 2px; }
.field-hint-warn { color: var(--warn); }
.field-hint-ok { color: var(--ok); }
.field-required { color: var(--error); margin-left: 2px; }

.field-radio-group { display: flex; flex-direction: column; gap: var(--space-2); }
.field-radio { display: flex; align-items: center; gap: var(--space-2); font-size: 0.85rem; color: var(--fg); }
.field-radio input[type="radio"] { width: 16px; height: 16px; }

/* the long form, grouped into cards ("What and why" / "Who" / "Data and
   systems" / "Priority and done") — each card reuses .card's bg/shadow. */
.request-form-cards { display: flex; flex-direction: column; gap: var(--space-4); max-width: 720px; }
.request-card h2 { margin-top: 0; }
.request-card .field, .request-card form { max-width: none; }

/* status pill — colours per docs/SPEC.md worker brief:
   new=accent, reviewing=warn, approved/building=accent-2, done=ok, declined=error */
.status-pill {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 var(--space-3);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}
.status-pill-accent { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent); }
.status-pill-accent-2 { background: color-mix(in srgb, var(--accent-2) 16%, transparent); color: var(--accent-2); }
.status-pill-warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); }
.status-pill-ok { background: color-mix(in srgb, var(--ok) 16%, transparent); color: var(--ok); }
.status-pill-error { background: color-mix(in srgb, var(--error) 16%, transparent); color: var(--error); }

/* read-only field list on a request's detail page */
.request-fields { display: flex; flex-direction: column; gap: var(--space-4); max-width: 720px; }
.request-field-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-faint);
  margin-bottom: var(--space-1);
}
.request-field-value { white-space: pre-wrap; color: var(--fg); }
.request-links { margin: 0; padding-left: var(--space-4); }

/* comment thread */
.comment-list { display: flex; flex-direction: column; gap: var(--space-3); margin-bottom: var(--space-4); max-width: 720px; }
.comment {
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  padding: var(--space-3);
}
.comment-meta { font-size: 0.78rem; color: var(--fg-muted); margin-bottom: var(--space-1); display: flex; gap: var(--space-2); align-items: baseline; }
.comment-author { font-weight: 600; color: var(--fg); }
.comment-body { white-space: pre-wrap; margin: 0; }

/* sidebar nav badge (e.g. #requests-badge — count of `new` requests) */
.nav-badge {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-fg);
  font-size: 0.68rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}

@media (max-width: 720px) {
  .request-form-cards, .request-fields, .comment-list { max-width: none; }
}

/* ---------- mail (SPEC §13) ---------- */
/* one more .status-pill colour — "disabled" is neither success nor failure,
   it's "nothing was attempted", so it gets the muted tone, not warn/error. */
.status-pill-faint { background: color-mix(in srgb, var(--fg-faint) 18%, transparent); color: var(--fg-faint); }

/* the "mail is disabled" banner on #/admin/mail reuses .callout but wants
   the warn colour, not .callout's default teal accent — it is telling the
   admin something needs attention, not just offering information. */
#mail-banner { border-left-color: var(--warn); }
#mail-banner p { margin-bottom: 0; }

.tool-mail .field { max-width: 480px; }

/* ---------- monitoring (SPEC §15) ---------- */
/* #/admin/monitor tab bar (Overview / Logs / API calls) */
.tab-bar {
  display: flex;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}
.tab-btn {
  background: transparent;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--fg-muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  padding: var(--space-2) var(--space-3) var(--space-3);
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--fg); }
.tab-btn.active { color: var(--fg); border-bottom-color: var(--accent-2); }

/* filter rows shared by the Logs and API calls tabs */
.filters-bar { display: flex; flex-wrap: wrap; gap: var(--space-3); align-items: flex-end; margin-bottom: var(--space-3); }
.filters-bar .field { margin-bottom: 0; min-width: 150px; }
.filters-bar .field-inline { min-width: auto; }

/* Overview stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-5); }
.stat-card { background: var(--bg-elevated); border-radius: var(--radius); box-shadow: var(--shadow-card); padding: var(--space-4); }
.stat-card-value { font-size: 1.6rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-card-label { font-size: 0.8rem; color: var(--fg-muted); margin-top: var(--space-1); }

/* per-tool health table rows — clickable through to Logs, pre-filtered */
.monitor-row { cursor: pointer; }
.monitor-row:hover { background: color-mix(in srgb, var(--accent-2) 6%, transparent); }
.monitor-row:focus-visible { outline: 2px solid var(--accent-2); outline-offset: -2px; }
.monitor-crashlooping { color: var(--error); font-weight: 700; }
.monitor-last-error {
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--fg-muted);
  font-size: 0.8rem;
}

/* Logs tab: mono log lines, stderr tinted, error-level rows marked */
.log-line-cell {
  font: 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  word-break: break-word;
  max-width: 560px;
}
.log-row-stderr { background: color-mix(in srgb, var(--warn) 5%, transparent); }
.log-row-error { background: color-mix(in srgb, var(--error) 8%, transparent); }

/* API calls tab: per-tool / per-upstream summary cards */
.summary-heading { margin-top: var(--space-4); margin-bottom: var(--space-2); font-size: 0.9rem; color: var(--fg-muted); }
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }
.summary-card { background: var(--bg-elevated); border-radius: var(--radius-sm); box-shadow: var(--shadow-card); padding: var(--space-3); }
.summary-card-label { font-weight: 600; margin-bottom: var(--space-1); font-size: 0.85rem; word-break: break-word; }
.summary-card-stats { display: flex; flex-direction: column; gap: 2px; font-size: 0.78rem; color: var(--fg-muted); font-variant-numeric: tabular-nums; }
.summary-stat-error { color: var(--error); }

/* #/admin/upstreams headers editor */
.upstream-headers { display: flex; flex-direction: column; gap: var(--space-2); margin: var(--space-2) 0; }
.upstream-header-row { display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.upstream-header-row input[type="text"],
.upstream-header-row input[type="password"] {
  font: inherit;
  color: var(--fg);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3);
  height: 34px;
  flex: 1 1 160px;
  min-width: 0;
}

/* tool-detail page: Connections checkbox list (SPEC §15.7 — per granted
   connection, a proxy/direct mode select + its one-line explanation) */
.tool-upstreams .checkbox-list { margin-bottom: var(--space-3); }
.connection-grant-row { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; padding: var(--space-2) 0; border-bottom: 1px solid var(--border); }
.connection-grant-row:last-child { border-bottom: none; }
.connection-grant-row .field-inline { margin-bottom: 0; min-width: 160px; }
.connection-mode {
  font: inherit;
  color: var(--fg);
  background: var(--bg-sunken);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-1) var(--space-2);
  height: 34px;
}
.connection-mode-explain { margin: 0; flex: 1 1 220px; }

@media (max-width: 720px) {
  .filters-bar { flex-direction: column; align-items: stretch; }
  .filters-bar .field { min-width: 0; max-width: none; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .summary-grid { grid-template-columns: 1fr; }
  .monitor-last-error { max-width: 160px; }
  .log-line-cell { max-width: 220px; }
}
