/*
 * Legenex AI OS — dashboard stylesheet.
 *
 * Visual language = the Legenex business dashboard (dark, production):
 * canvas #0A0E15, card #131924, raised #182030, sidebar #0F1319, border
 * #243044, input #1A2532, text #EEF2F8 / muted #8B95A8, brand red #E5484D
 * (primary + focus ring), green #3DD68C healthy, amber/orange warning,
 * red risk. Inter for UI, JetBrains Mono for code. Radius 10px. No heavy
 * shadows: depth comes from the surface hierarchy canvas < card < raised.
 * Dark only. No framework, no build step.
 */

:root {
  color-scheme: dark;

  /* surfaces */
  --bg: #0A0E15;
  --surface: #131924;
  --raised: #182030;
  --raised-2: #1D2638;
  --sidebar: #0F1319;
  --input: #1A2532;
  --border: #243044;
  --border-soft: #1C2432;
  --hover: #182030;

  /* text */
  --text: #EEF2F8;
  --text-2: #A8B1C0;
  --muted: #8B95A8;
  --faint: #5D6778;

  /* brand + semantic */
  --primary: #E5484D;
  --primary-hover: #EC5D62;
  --primary-rgb: 229, 72, 77;
  --ok: #3DD68C;
  --ok-rgb: 61, 214, 140;
  --warn: #F5B83D;
  --warn-rgb: 245, 184, 61;
  --orange: #F97316;
  --orange-rgb: 249, 115, 22;
  --bad: #E5484D;
  --bad-rgb: 229, 72, 77;
  --info: #4A9EDB;
  --info-rgb: 74, 158, 219;
  --purple: #8B7FEB;
  --purple-rgb: 139, 127, 235;

  /* legacy names used by older page scripts (inline styles) */
  --fg: var(--text);
  --card: var(--surface);
  --accent: var(--primary);
  --code-bg: #0D121B;

  --radius: 10px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --sidebar-w: 248px;
  --font: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --ease: 150ms ease;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

/* Faint 1px grid on the canvas, as in the business dashboard. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background-image:
    linear-gradient(to right, rgba(36, 48, 68, 0.22) 1px, transparent 1px),
    linear-gradient(to bottom, rgba(36, 48, 68, 0.22) 1px, transparent 1px);
  background-size: 40px 40px;
}

main, .sidebar, .mobile-bar, .toasts { position: relative; z-index: 1; }

a { color: var(--text); text-decoration: none; }
a:hover { color: var(--primary); }
p a, td a, li a, .link { color: var(--text); text-decoration: underline; text-decoration-color: rgba(var(--primary-rgb), 0.5); text-underline-offset: 3px; }
p a:hover, td a:hover, li a:hover, .link:hover { color: var(--primary); }
a.btn, .nav-item, .tile a { text-decoration: none; }

h1, h2, h3, h4 { margin: 0 0 0.5rem; font-weight: 600; letter-spacing: -0.01em; color: var(--text); }
h1 { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.2; }
h2 { font-size: 15px; }
h3 { font-size: 14px; }
p { margin: 0 0 0.75rem; }
hr { border: 0; border-top: 1px solid var(--border); margin: 1rem 0; }
ul, ol { padding-left: 1.25rem; }

::selection { background: rgba(var(--primary-rgb), 0.35); }

:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #2A3847; }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------------ icons */

svg.icon {
  width: 16px;
  height: 16px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -3px;
}
svg.icon.lg { width: 20px; height: 20px; }
svg.icon.sm { width: 14px; height: 14px; vertical-align: -2px; }
svg.icon.xs { width: 12px; height: 12px; vertical-align: -1px; }

/* ------------------------------------------------------------------ app shell */

.sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--border-soft);
  border-top-right-radius: 16px;
  border-bottom-right-radius: 16px;
  display: flex;
  flex-direction: column;
  z-index: 50;
  overflow-y: auto;
}
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 16px 14px 20px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand img { height: 34px; width: auto; max-width: 150px; object-fit: contain; display: block; }
.brand-tag {
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.08em;
  color: var(--primary);
  border: 1px solid rgba(var(--primary-rgb), 0.35);
  background: rgba(var(--primary-rgb), 0.08);
  border-radius: 999px;
  padding: 2px 7px;
  white-space: nowrap;
}
.sidebar-head .sidebar-close { display: none; }
.sidebar-cta { padding: 4px 12px 14px; }
.side-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 12px; flex: 1; }
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
  transition: background var(--ease), color var(--ease);
}
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item.active { background: rgba(var(--primary-rgb), 0.1); color: var(--text); }
.nav-item.active svg.icon { color: var(--primary); }
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 20px;
  background: var(--primary);
  border-radius: 0 3px 3px 0;
}
.sidebar-foot { padding: 12px; border-top: 1px solid var(--border-soft); margin-top: 12px; }
.nav-item.subtle { font-size: 12.5px; }

.mobile-bar { display: none; }
.sidebar-backdrop { display: none; }

body.has-shell main { margin-left: var(--sidebar-w); }

main.page {
  max-width: 1320px;
  padding: 28px 32px 48px;
}

@media (min-width: 1580px) {
  body.has-shell main.page { margin-left: calc(var(--sidebar-w) + (100vw - var(--sidebar-w) - 1320px) / 2); }
}

@media (max-width: 899px) {
  body.has-shell main { margin-left: 0; }
  main.page { padding: 18px 14px 40px; }
  .mobile-bar {
    display: flex;
    position: sticky;
    top: 0;
    z-index: 40;
    height: 56px;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 0 10px;
    padding-top: env(safe-area-inset-top);
    background: rgba(15, 19, 25, 0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border-soft);
  }
  .mobile-brand { display: flex; align-items: center; gap: 8px; }
  .mobile-brand img { height: 26px; width: auto; }
  .sidebar {
    transform: translateX(-102%);
    transition: transform 200ms ease;
    width: min(300px, 86vw);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-head .sidebar-close { display: inline-flex; }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(5, 8, 12, 0.6);
    z-index: 45;
  }
  .sidebar-backdrop[hidden] { display: none; }
  .nav-item { padding: 11px 12px; font-size: 14px; }
}

/* ------------------------------------------------------------------ page header */

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}
.page-header h1 { margin: 0; }
.page-header .sub { color: var(--muted); font-size: 13px; margin: 4px 0 0; max-width: 72ch; }
.page-header .actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.eyebrow {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.eyebrow a { color: var(--muted); }
.eyebrow a:hover { color: var(--text); }

.section-title {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 26px 0 10px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ------------------------------------------------------------------ cards */

.card {
  background: linear-gradient(180deg, var(--raised) 0%, var(--surface) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
  min-width: 0;
}
.card > h2:first-child, .card > h3:first-child { margin-bottom: 12px; }
.card .card { background: var(--surface); }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.card-head h2, .card-head h3 { margin: 0; display: flex; align-items: center; gap: 8px; }
.card-head h2 svg.icon { color: var(--muted); }
.card.flush { padding: 0; overflow: hidden; }
.card.flush > .card-head { padding: 14px 18px 0; }
.card.accent { border-left: 3px solid rgba(var(--primary-rgb), 0.5); }
.card.danger-zone { border-color: rgba(var(--bad-rgb), 0.35); }

.grid { display: grid; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
@media (max-width: 1100px) { .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }
.grid-2 > .card, .grid-3 > .card { margin-bottom: 0; }
.grid-2 > *, .grid-3 > * { min-width: 0; }

/* ------------------------------------------------------------------ stat tiles */

.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.tile {
  position: relative;
  background: linear-gradient(180deg, var(--raised) 0%, var(--surface) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color var(--ease), transform var(--ease);
}
a.tile:hover, .tile.is-link:hover { border-color: rgba(var(--primary-rgb), 0.35); transform: translateY(-1px); color: var(--text); }
.tile .label, .tile-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.tile .label { align-items: flex-start; }
.tile .label .left { display: flex; align-items: flex-start; gap: 7px; min-width: 0; line-height: 1.35; }
.tile .label .left svg.icon { margin-top: 1px; }
.tile .label .pill { margin-top: -2px; }
.tile .value { font-size: 20px; font-weight: 650; line-height: 1.25; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.tile .value small { font-size: 13px; color: var(--muted); font-weight: 500; }
.tile .meta { color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.tile .tile-actions { margin-top: 4px; display: flex; gap: 6px; flex-wrap: wrap; }
.tile::after {
  content: '';
  position: absolute;
  left: -1px;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: transparent;
}
.tile.s-ok::after { background: var(--ok); }
.tile.s-warn::after { background: var(--warn); }
.tile.s-fail::after, .tile.s-blocked::after { background: var(--bad); }
.tile.s-offline::after { background: var(--faint); }
.tile.s-na { opacity: 0.72; }
.tile.wide { grid-column: span 2; }
@media (max-width: 520px) {
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .tile { padding: 12px; }
  .tile .value { font-size: 17px; }
  .tile.wide { grid-column: span 2; }
}
.ok { color: var(--ok); }
.bad { color: var(--bad); }
.warn { color: var(--warn); }

.meter { height: 5px; border-radius: 999px; background: var(--input); overflow: hidden; }
.meter > span { display: block; height: 100%; background: var(--ok); border-radius: 999px; }
.meter.warn > span { background: var(--warn); }
.meter.bad > span { background: var(--bad); }

/* ------------------------------------------------------------------ pills / badges */

.pill, .badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: 0.01em;
  border: 1px solid var(--border);
  background: rgba(24, 32, 48, 0.8);
  color: var(--text-2);
  white-space: nowrap;
  vertical-align: middle;
}
.pill::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}
.pill.plain::before { display: none; }
.pill.ok, .badge.ok { color: var(--ok); background: rgba(var(--ok-rgb), 0.1); border-color: rgba(var(--ok-rgb), 0.3); }
.pill.warn, .badge.warn { color: var(--warn); background: rgba(var(--warn-rgb), 0.1); border-color: rgba(var(--warn-rgb), 0.3); }
.pill.orange { color: var(--orange); background: rgba(var(--orange-rgb), 0.1); border-color: rgba(var(--orange-rgb), 0.3); }
.pill.fail, .pill.bad, .badge.bad { color: #FF6B70; background: rgba(var(--bad-rgb), 0.12); border-color: rgba(var(--bad-rgb), 0.35); }
.pill.blocked { color: var(--orange); background: rgba(var(--orange-rgb), 0.1); border-color: rgba(var(--orange-rgb), 0.35); }
.pill.info, .badge.info { color: var(--info); background: rgba(var(--info-rgb), 0.1); border-color: rgba(var(--info-rgb), 0.3); }
.pill.purple { color: var(--purple); background: rgba(var(--purple-rgb), 0.1); border-color: rgba(var(--purple-rgb), 0.3); }
.pill.unknown, .pill.muted, .badge.muted { color: var(--muted); }
.pill.offline { color: var(--faint); border-color: var(--border); }
.pill.running::before { animation: pulse 1.2s ease-in-out infinite; }
.pill.mono { font-family: var(--mono); font-weight: 500; }
.badge { padding: 2px 9px; }
p.badge { display: inline-flex; margin: 0 0 10px; white-space: normal; }
div.badge { display: inline-flex; margin: 4px 6px 4px 0; white-space: normal; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  background: var(--faint);
  vertical-align: 1px;
}
.dot.online { background: var(--ok); box-shadow: 0 0 0 3px rgba(var(--ok-rgb), 0.15); }
.dot.offline { background: var(--bad); }
.dot.stale { background: var(--warn); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 8px;
  border-radius: var(--radius-xs);
  font-size: 11.5px;
  font-family: var(--mono);
  background: var(--input);
  border: 1px solid var(--border);
  color: var(--text-2);
  white-space: nowrap;
}
.chip.write { color: var(--warn); border-color: rgba(var(--warn-rgb), 0.3); }
.chips { display: flex; flex-wrap: wrap; gap: 5px; }

/* ------------------------------------------------------------------ buttons */

button, .btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 34px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--primary);
  background: var(--primary);
  color: #fff;
  font-family: inherit;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: background var(--ease), border-color var(--ease), color var(--ease), opacity var(--ease);
  user-select: none;
  -webkit-user-select: none;
}
button:hover, .btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); color: #fff; }
button.secondary, .btn.secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
button.secondary:hover, .btn.secondary:hover { background: var(--hover); border-color: #2E3B52; color: var(--text); }
button.ghost, .btn.ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
}
button.ghost:hover, .btn.ghost:hover { background: var(--hover); color: var(--text); border-color: transparent; }
button.danger, .btn.danger { border-color: var(--bad); background: var(--bad); color: #fff; }
button.danger.outline, .btn.danger.outline, button.danger-ghost {
  background: transparent;
  color: #FF6B70;
  border-color: rgba(var(--bad-rgb), 0.4);
}
button.danger.outline:hover, .btn.danger.outline:hover, button.danger-ghost:hover { background: rgba(var(--bad-rgb), 0.1); color: #FF8589; }
button.warn-btn, .btn.warn-btn { background: rgba(var(--warn-rgb), 0.12); border-color: rgba(var(--warn-rgb), 0.45); color: var(--warn); }
.btn.lg, button.lg { min-height: 42px; padding: 10px 18px; font-size: 14px; font-weight: 600; }
.btn.sm, button.sm { min-height: 28px; padding: 4px 10px; font-size: 12px; }
.btn.block, button.block { display: flex; width: 100%; }
button:disabled, .btn:disabled, .btn.disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }
button:disabled:hover { background: inherit; }

.icon-btn, button.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  min-height: 0;
  padding: 0;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--muted);
}
.icon-btn:hover, button.icon-btn:hover { background: var(--hover); color: var(--text); border-color: transparent; }
.icon-btn.primary { background: var(--primary); color: #fff; }
.icon-btn.primary:hover { background: var(--primary-hover); color: #fff; }
.icon-btn svg.icon { width: 18px; height: 18px; }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.sm svg.icon { width: 15px; height: 15px; }

/* table-cell action groups (project/storage JS put several buttons in a td) */
td > button, td > .btn { min-height: 28px; padding: 4px 10px; font-size: 12px; margin: 2px 4px 2px 0; }

.action-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}

/* ------------------------------------------------------------------ forms */

input[type=text], input[type=password], input[type=search], input[type=email], input[type=number], input[type=url],
input:not([type]), textarea, select {
  width: 100%;
  min-height: 36px;
  padding: 8px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--input);
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.4;
  transition: border-color var(--ease), box-shadow var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--faint); }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: rgba(var(--primary-rgb), 0.6);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.18);
}
input:disabled, textarea:disabled, select:disabled { opacity: 0.5; cursor: not-allowed; }
select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238B95A8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
textarea { font-family: var(--mono); font-size: 12.5px; min-height: 320px; resize: vertical; }
textarea.plain { font-family: var(--font); font-size: 13.5px; min-height: 90px; }
input[type=checkbox], input[type=radio] { accent-color: var(--primary); width: 15px; height: 15px; vertical-align: -2px; margin: 0 6px 0 0; }
input[type=file] { color: var(--muted); font-size: 13px; }
input[type=file]::file-selector-button {
  font-family: inherit; font-size: 12.5px; color: var(--text); background: var(--raised);
  border: 1px solid var(--border); border-radius: var(--radius-xs); padding: 6px 10px; margin-right: 10px; cursor: pointer;
}

.field { margin-bottom: 14px; }
.field > label, .field-label {
  display: block;
  margin-bottom: 6px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-2);
}
.field label.small, label.small { display: inline-flex; align-items: center; margin-right: 14px; font-size: 13px; color: var(--text); font-weight: 400; }
.field .hint, .hint { color: var(--muted); font-size: 12px; margin-top: 5px; }
form button[type=submit] { margin-right: 8px; }

.search-row { margin-bottom: 12px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search-row input, .search-row select { max-width: 340px; }
.search-input { position: relative; flex: 1; max-width: 420px; min-width: 200px; }
.search-input svg.icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.search-input input { padding-left: 34px; max-width: none; }

/* ------------------------------------------------------------------ tables */

.table-wrap { overflow-x: auto; margin: 0 -2px; }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
th, td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
  background: rgba(15, 19, 25, 0.35);
}
tbody tr { transition: background var(--ease); }
tbody tr:hover { background: rgba(24, 32, 48, 0.7); }
tbody tr:last-child td { border-bottom: none; }
tr.row-fail { background: rgba(var(--bad-rgb), 0.06); }
tr.row-fail td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
td.mono, .mono { font-family: var(--mono); font-size: 12px; }
td .sub { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.card > table:not(.kv), .card > .table-wrap { margin: -4px 0; }
.card.flush table th:first-child, .card.flush table td:first-child { padding-left: 18px; }
.card.flush table th:last-child, .card.flush table td:last-child { padding-right: 18px; }

/* key/value tables: th in the first column of each row */
table.kv th { width: 170px; text-transform: none; letter-spacing: 0; font-size: 12.5px; font-weight: 500; background: transparent; vertical-align: top; }
table.kv tbody tr:hover, table.kv tr:hover { background: transparent; }

/* Mobile: tables with a header become stacked cards. AiOs.labelTables()
 * copies each column header into its cells' data-label attribute. */
@media (max-width: 760px) {
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack thead { display: none; }
  table.stack tr {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    padding: 8px 12px;
    margin-bottom: 10px;
  }
  table.stack tbody tr:hover { background: var(--surface); }
  table.stack td {
    position: relative;
    padding: 7px 0 7px calc(34% + 10px);
    min-height: 32px;
    border-bottom: 1px dashed var(--border-soft);
    overflow-wrap: anywhere;
    text-align: left;
  }
  table.stack td:last-child { border-bottom: none; }
  table.stack td::before {
    content: attr(data-label);
    position: absolute;
    left: 0;
    top: 9px;
    width: 34%;
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    line-height: 1.3;
  }
  table.stack td[data-label=""], table.stack td:not([data-label]), table.stack td[colspan] { padding-left: 0; }
  table.stack td[data-label=""]::before, table.stack td:not([data-label])::before, table.stack td[colspan]::before { display: none; }
  table.stack td.num { text-align: left; }
  tr.row-fail td:first-child { box-shadow: none; }
  tr.row-fail { border-left: 3px solid var(--bad) !important; }
  .card.flush table.stack { padding: 10px; }
  .card.flush table.stack td:first-child { padding-left: calc(34% + 10px); }
  .card.flush table.stack td:last-child { padding-right: 0; }
  .card.flush table.stack td:not([data-label]):first-child, .card.flush table.stack td[data-label=""]:first-child, .card.flush table.stack td[colspan] { padding-left: 0; }
  table.kv th { width: 38%; }
  table.kv th, table.kv td { padding: 8px 6px; }
}

/* ------------------------------------------------------------------ tabs */

.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs button, .tabs a {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 0;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  margin-bottom: -1px;
  color: var(--muted);
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.tabs button:hover, .tabs a:hover { color: var(--text); background: none; }
.tabs button.active, .tabs a.active { color: var(--text); border-bottom-color: var(--primary); background: none; }

/* segmented control */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 100%;
}
.seg button {
  flex: 1;
  min-height: 30px;
  padding: 5px 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-xs);
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
}
.seg button:hover { background: var(--raised); color: var(--text); border-color: transparent; }
.seg button.active { background: var(--raised-2); color: var(--text); border-color: var(--border); }
.seg button.writes.active { color: var(--warn); border-color: rgba(var(--warn-rgb), 0.45); background: rgba(var(--warn-rgb), 0.1); }
.seg button.writes:not(.active) { color: rgba(var(--warn-rgb), 0.75); }

/* ------------------------------------------------------------------ flash / toasts / empty */

.flash {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  border: 1px solid var(--border);
  background: var(--raised);
  font-size: 13px;
  overflow-wrap: anywhere;
}
.flash.error { background: rgba(var(--bad-rgb), 0.1); border-color: rgba(var(--bad-rgb), 0.35); color: #FF8589; }
.flash.success { background: rgba(var(--ok-rgb), 0.08); border-color: rgba(var(--ok-rgb), 0.3); color: var(--ok); }
.flash.warn { background: rgba(var(--warn-rgb), 0.08); border-color: rgba(var(--warn-rgb), 0.3); color: var(--warn); }
.flash.info { background: rgba(var(--info-rgb), 0.08); border-color: rgba(var(--info-rgb), 0.3); color: #8CC4EC; }
.flash.small { font-size: 12px; padding: 7px 10px; margin-bottom: 8px; }

.toasts {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, calc(100vw - 36px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--raised-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--info);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  animation: toast-in 180ms ease;
  overflow-wrap: anywhere;
}
.toast.ok { border-left-color: var(--ok); }
.toast.error { border-left-color: var(--bad); }
.toast.warn { border-left-color: var(--warn); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
@media (max-width: 899px) { .toasts { left: 12px; right: 12px; bottom: 12px; max-width: none; } }

.empty {
  text-align: center;
  padding: 28px 16px;
  color: var(--muted);
  font-size: 13px;
}
.empty svg.icon { width: 26px; height: 26px; color: var(--faint); margin-bottom: 8px; }
.empty strong { display: block; color: var(--text); font-size: 14px; margin-bottom: 4px; }

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12px; }
.hidden { display: none !important; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack-sm > * + * { margin-top: 6px; }
.spacer { flex: 1; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

/* skeleton shimmer */
.skeleton {
  display: block;
  height: 12px;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--raised) 0%, var(--raised-2) 50%, var(--raised) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

.spinner {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 2px solid rgba(139, 149, 168, 0.3);
  border-top-color: var(--text);
  animation: spin 0.8s linear infinite;
  display: inline-block;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ code / diff */

code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  border: 1px solid var(--border-soft);
  border-radius: 5px;
  padding: 1px 5px;
  overflow-wrap: anywhere;
}
pre {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  overflow-x: auto;
  margin: 0 0 12px;
  white-space: pre;
  color: var(--text-2);
}
pre code { background: none; border: 0; padding: 0; font-size: inherit; }
pre.code { white-space: pre-wrap; word-break: break-word; }
.copy-row { display: flex; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.copy-row pre, .copy-row pre.code { flex: 1; margin: 0; min-width: 0; }
.copy-row > input { flex: 1; }
.copy-btn { flex: none; }

.diff {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.55;
  background: var(--code-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: auto;
  max-height: 60vh;
}
.diff .ln { display: block; padding: 0 12px; white-space: pre; min-width: max-content; color: var(--text-2); }
.diff .ln.add { background: rgba(var(--ok-rgb), 0.1); color: #7EE6B3; }
.diff .ln.del { background: rgba(var(--bad-rgb), 0.12); color: #FF9A9D; }
.diff .ln.hunk { color: var(--info); background: rgba(var(--info-rgb), 0.07); }
.diff .ln.meta { color: var(--muted); font-weight: 600; }

.code-view { font-family: var(--mono); font-size: 12px; line-height: 1.55; background: var(--code-bg); border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: auto; max-height: 65vh; }
.code-view .ln { display: grid; grid-template-columns: 44px 1fr; white-space: pre; min-width: max-content; }
.code-view .ln .n { color: var(--faint); text-align: right; padding-right: 12px; user-select: none; -webkit-user-select: none; border-right: 1px solid var(--border-soft); }
.code-view .ln .t { padding-left: 12px; padding-right: 12px; color: var(--text-2); }

/* ------------------------------------------------------------------ dialogs */

dialog.aios {
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--raised);
  color: var(--text);
  padding: 22px;
  width: min(560px, calc(100vw - 24px));
  max-height: 88vh;
  overflow: auto;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5);
}
dialog.aios::backdrop { background: rgba(5, 8, 12, 0.65); backdrop-filter: blur(2px); }
dialog.aios h2 { margin-top: 0; font-size: 17px; }
dialog.aios h3 { font-size: 13px; color: var(--text-2); margin-top: 14px; }
dialog.aios .dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
  flex-wrap: wrap;
}
dialog.aios .field > label { color: var(--text); font-weight: 400; font-size: 13px; }
dialog.aios label strong { color: var(--text); }
@media (max-width: 600px) {
  dialog.aios { padding: 18px 16px; margin: auto auto 0; border-radius: 16px 16px 0 0; width: 100vw; max-width: 100vw; max-height: 90vh; }
  dialog.aios .dialog-actions button { flex: 1; }
}

.checklist { list-style: none; padding: 0; margin: 6px 0 10px; }
.checklist li { padding: 5px 0; font-size: 13px; overflow-wrap: anywhere; }

/* ------------------------------------------------------------------ misc lists */

.job-line {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 9px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}
.job-line:last-child { border-bottom: none; }

.list { list-style: none; margin: 0; padding: 0; }
.list > li {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}
.list > li:last-child { border-bottom: none; }
.list > li .grow { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.list > li svg.icon { margin-top: 2px; }

.tree-list { list-style: none; padding: 0; margin: 0; }
.tree-list li { margin: 0; }
.tree-list a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  color: var(--text);
  text-decoration: none;
}
.tree-list a:hover { background: var(--hover); color: var(--text); }
.tree-list a svg.icon { color: var(--muted); }
.tree-list a.dir svg.icon { color: var(--warn); }

.breadcrumb { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.breadcrumb a { color: var(--text-2); }
.breadcrumb a:hover { color: var(--primary); }

/* markdown prose (guide, project notes, agent answers) */
.prose { font-size: 14px; line-height: 1.65; color: var(--text); overflow-wrap: anywhere; }
.prose h1 { font-size: 22px; margin: 6px 0 14px; }
.prose h2 { font-size: 17px; margin: 22px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border-soft); }
.prose h3 { font-size: 15px; margin: 18px 0 8px; }
.prose h4 { font-size: 14px; margin: 14px 0 6px; }
.prose p, .prose ul, .prose ol { margin: 0 0 12px; }
.prose li { margin: 3px 0; }
.prose a { color: var(--text); text-decoration: underline; text-decoration-color: rgba(var(--primary-rgb), 0.6); text-underline-offset: 3px; }
.prose a:hover { color: var(--primary); }
.prose blockquote { margin: 0 0 12px; padding: 4px 14px; border-left: 3px solid var(--border); color: var(--text-2); }
.prose table { margin: 0 0 14px; display: block; overflow-x: auto; }
.prose pre { margin: 0 0 14px; }
.prose > :last-child { margin-bottom: 0; }

/* login */
body.no-shell main.page { margin: 0 auto; }
.login-wrap { min-height: calc(100vh - 80px); display: grid; place-items: center; }
.login-card { width: min(400px, 100%); padding: 30px 28px; }
.login-card .brand img { height: 40px; }
.login-card h1 { font-size: 20px; margin: 22px 0 4px; }

/* page scripts that set inline error-row backgrounds */
tr[style*="rgba(192"] { background: rgba(var(--bad-rgb), 0.06) !important; }

@media (max-width: 600px) {
  h1 { font-size: 21px; }
  .card { padding: 14px; }
  .page-header { margin-bottom: 16px; }
  .page-header .actions { width: 100%; }
  .action-bar > button, .action-bar > .btn { flex: 1 1 auto; }
}

/* ================================================================== page bits */

.card.narrow { max-width: 720px; }
.card.flush > div > p, .card.flush > p, .card.flush > div > .flash { margin: 14px 18px; }
.card.flush > .table-wrap, .card.flush > div > .table-wrap { margin: 0; }
.log-pre { max-height: 60vh; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 0; }
.notes { max-height: 460px; overflow-y: auto; }
.guide { padding: 28px 32px; }
@media (max-width: 600px) { .guide { padding: 18px 16px; } }
.web-clients .card h3 { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.web-clients pre.code { margin: 0; font-size: 11.5px; }

/* projects list */
a.strong-link { font-weight: 600; color: var(--text); text-decoration: none; }
a.strong-link:hover { color: var(--primary); }
.name-cell .sub { display: block; }
a.repo-link { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); text-decoration: none; font-family: var(--mono); font-size: 12px; }
a.repo-link:hover { color: var(--primary); }
.wc-inline { display: flex; align-items: center; flex-wrap: wrap; gap: 5px; }
td.row-actions { text-align: right; white-space: nowrap; }
td.cell-actions { white-space: nowrap; }
@media (max-width: 760px) { td.cell-actions { white-space: normal; } }
@media (max-width: 760px) {
  td.row-actions { text-align: left; }
  .name-cell .sub { max-width: none !important; white-space: normal; }
}

/* work status pills (project priority / lifecycle) */
.pill.now { color: #fff; background: var(--primary); border-color: var(--primary); letter-spacing: 0.04em; }
.pill.now::before { background: #fff; }
.work-status { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: -8px 0 16px; }
.ws-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.ws-label + span { margin-right: 10px; }
.project-seg { width: auto; }
.project-seg button { flex: none; padding: 5px 12px; }
@media (max-width: 600px) { .project-seg { width: 100%; overflow-x: auto; } }

/* integrations hub */
.hub-section { scroll-margin-top: 16px; }
@media (max-width: 899px) { .hub-section { scroll-margin-top: 70px; } }
.integration-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
@media (max-width: 1100px) { .integration-grid { grid-template-columns: 1fr; } }
.integration-grid > .card { margin: 0; }
.integration-card { display: flex; flex-direction: column; gap: 10px; border-left: 3px solid var(--border); }
.integration-card.s-ok { border-left-color: var(--ok); }
.integration-card.s-fail { border-left-color: var(--bad); }
.integration-card.s-warn { border-left-color: var(--warn); }
.integration-card.s-blocked { border-left-color: var(--orange); }
.int-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.int-title { min-width: 0; }
.int-title h3 { font-size: 15px; margin: 0 0 6px; overflow-wrap: anywhere; }
.int-desc { margin: 0; }
.int-actions { margin-top: auto; padding-top: 4px; }
.ikv-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 16px; }
@media (max-width: 600px) { .ikv-grid { grid-template-columns: 1fr; } }
.ikv { min-width: 0; }
.ikv .k { font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); margin-bottom: 3px; }
.ikv .v { font-size: 13px; overflow-wrap: anywhere; }
.test-box { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface); padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.test-box .flash { margin: 0; }
.test-box .tb-label { margin: 2px 0 0; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 4px 12px; }
label.check { display: flex; align-items: center; gap: 2px; font-size: 13px; color: var(--text); font-weight: 400; padding: 3px 0; }
.form-grid { gap: 0 14px; }
.form-grid .field { margin-bottom: 14px; }
table.compact-table th, table.compact-table td { padding: 7px 8px; }
.vm-summary { padding: 12px 18px 4px; }
.vm-table td { white-space: nowrap; }
.vm-table td:last-child { white-space: normal; min-width: 180px; }
@media (max-width: 760px) { .vm-table td, .vm-table td:last-child { white-space: normal; min-width: 0; } }

/* cluster */
.cluster-error { align-items: flex-start; }
.cluster-error strong { display: block; font-weight: 600; }
.model-strip .chips { justify-content: flex-end; }
.node-select { width: auto; min-width: 160px; min-height: 28px; padding: 3px 28px 3px 8px; font-size: 12px; }

/* ================================================================== generic JSON view */

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.kv-cell {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  min-width: 0;
}
.kv-cell .k { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 4px; }
.kv-cell .v { font-size: 14px; font-weight: 500; overflow-wrap: anywhere; }
.json-section { margin-top: 6px; }
.json-h { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-2); margin: 14px 0 8px; }

/* ================================================================== overview */

.dash-top { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 16px; }
.dash-top > .card { margin-bottom: 0; }
@media (max-width: 1000px) { .dash-top { grid-template-columns: 1fr; } }
.attention-card .list { max-height: 330px; overflow-y: auto; }
.attention-card .list > li .pill { min-width: 70px; justify-content: center; }
.model-card { border-left: 3px solid rgba(var(--primary-rgb), 0.55); }
.model-name { font-size: 20px; font-weight: 650; letter-spacing: -0.01em; overflow-wrap: anywhere; }
.node-tiles { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.node-tiles .tile { gap: 8px; }
.metric .row { gap: 6px; margin-bottom: 4px; }

/* ================================================================== agent page */

body.page-agent { overflow: hidden; }
body.page-agent::before { display: none; }
main.agent-main {
  height: 100vh;
  height: 100dvh;
  padding: 0;
  max-width: none;
}
.agent {
  --ctx-w: 284px;
  --drawer-w: 400px;
  height: 100%;
  display: grid;
  grid-template-columns: var(--ctx-w) minmax(0, 1fr) 0;
  transition: grid-template-columns 200ms ease;
}
.agent[data-drawer="open"] { grid-template-columns: var(--ctx-w) minmax(0, 1fr) var(--drawer-w); }

/* context bar */
.agent-context {
  border-right: 1px solid var(--border-soft);
  background: rgba(15, 19, 25, 0.55);
  overflow-y: auto;
  min-height: 0;
}
.ctx-toggle { display: none; }
.ctx-body { padding: 18px 16px 24px; display: flex; flex-direction: column; gap: 18px; }
.ctx-section { min-width: 0; }
.ctx-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--muted); margin-bottom: 8px;
}
.mode-desc { font-size: 12px; color: var(--muted); margin: 8px 0 0; line-height: 1.45; }
.mode-desc.writes { color: var(--text-2); }
.mode-desc .pill { margin-right: 4px; }
.model-warn { margin: 8px 0 0; align-items: flex-start; }
.model-warn button { color: var(--text); }

/* combobox */
.combo { position: relative; }
.combo-btn {
  width: 100%;
  justify-content: space-between;
  background: var(--input);
  border: 1px solid var(--border);
  color: var(--text);
  font-weight: 500;
}
.combo-btn:hover { background: var(--raised); border-color: #2E3B52; color: var(--text); }
.combo-btn:disabled { opacity: 0.75; }
.combo-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  z-index: 30;
  background: var(--raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  padding: 8px;
}
.combo-search { max-width: none; min-width: 0; margin-bottom: 6px; }
.combo-list { list-style: none; margin: 0; padding: 0; max-height: 300px; overflow-y: auto; }
.combo-item { padding: 7px 10px; border-radius: var(--radius-xs); cursor: pointer; }
.combo-item:hover, .combo-item.hover { background: var(--raised-2); }
.combo-item.selected .combo-item-label { color: var(--primary); }
.combo-item-label { font-size: 13px; font-weight: 500; }
.combo-item-sub { font-size: 11.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.combo-empty { padding: 10px; color: var(--muted); font-size: 12.5px; }

/* working copy cards */
.wc-list { display: flex; flex-direction: column; gap: 6px; }
.wc-card, button.wc-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 5px;
  width: 100%;
  min-height: 0;
  padding: 9px 11px;
  text-align: left;
  white-space: normal;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 400;
}
button.wc-card:hover { background: var(--raised); border-color: #2E3B52; color: var(--text); }
button.wc-card.selected { border-color: rgba(var(--primary-rgb), 0.6); background: rgba(var(--primary-rgb), 0.07); box-shadow: inset 3px 0 0 var(--primary); }
button.wc-card:disabled { opacity: 1; cursor: default; pointer-events: none; }
button.wc-card.disabled { opacity: 0.55; }
button.wc-card.wc-none { color: var(--muted); padding: 7px 11px; }
button.wc-card.wc-none.selected { color: var(--text); }
.wc-top { display: flex; align-items: center; gap: 6px; font-size: 13px; min-width: 0; }
.wc-top .dot { margin-right: 0; }
.wc-top .chip { margin-left: auto; max-width: 55%; overflow: hidden; text-overflow: ellipsis; }
.wc-path { color: var(--muted); font-size: 11.5px; }
.wc-pills { display: flex; flex-wrap: wrap; gap: 4px; }
.wc-reason { font-size: 11.5px; color: var(--warn); }

.tools-summary { display: flex; flex-direction: column; gap: 8px; }
.tg-label { font-size: 11.5px; color: var(--text-2); margin-bottom: 4px; }
.hint.warn { color: var(--warn); }

.ctx-sessions summary {
  display: flex; align-items: center; gap: 6px; cursor: pointer; list-style: none;
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.07em; color: var(--muted);
}
.ctx-sessions summary::-webkit-details-marker { display: none; }
.ctx-sessions summary .chev { margin-left: auto; transition: transform var(--ease); }
.ctx-sessions[open] summary .chev { transform: rotate(180deg); }
.session-list { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.session-item { display: block; padding: 7px 9px; border-radius: var(--radius-xs); color: var(--text); }
.session-item:hover { background: var(--hover); color: var(--text); }
.session-item.active { background: rgba(var(--primary-rgb), 0.1); }
.si-title { font-size: 13px; font-weight: 500; }
.si-meta { display: flex; gap: 8px; justify-content: space-between; font-size: 11.5px; color: var(--muted); }
.session-item .pill { margin-top: 4px; }

/* conversation */
.agent-chat { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); position: relative; }
.chat-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(10, 14, 21, 0.9);
}
.chat-title { min-width: 0; }
.chat-title .row { flex-wrap: nowrap; }
.chat-title h1 { font-size: 16px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
.chat-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.chat-actions { display: flex; gap: 6px; flex: none; }
.count-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 18px; height: 18px; padding: 0 5px; border-radius: 999px;
  background: var(--warn); color: #1a1300; font-size: 10.5px; font-weight: 700;
}
.count-badge[hidden] { display: none; }
#chat-banner { padding: 0 20px; }
#chat-banner .flash { margin: 12px 0 0; }

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 22px 20px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 0;
  overscroll-behavior: contain;
}
.chat-log > * { flex: none; width: 100%; max-width: 860px; margin-left: auto; margin-right: auto; }
.chat-empty { text-align: center; margin: auto; padding: 30px 10px; max-width: 560px; }
.chat-empty[hidden] { display: none; }
.chat-empty-icon {
  display: inline-flex; width: 52px; height: 52px; align-items: center; justify-content: center;
  border-radius: 14px; background: rgba(var(--primary-rgb), 0.1); color: var(--primary); margin-bottom: 14px;
  border: 1px solid rgba(var(--primary-rgb), 0.25);
}
.chat-empty-icon svg.icon { width: 26px; height: 26px; }
.chat-empty h2 { font-size: 20px; margin-bottom: 8px; }
.chat-empty p { font-size: 13px; line-height: 1.6; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 18px; }
.suggestions button { white-space: normal; text-align: left; }

.msg { display: flex; gap: 10px; }
.msg.user { justify-content: flex-end; }
.msg.user .bubble {
  max-width: min(640px, 85%);
  background: var(--raised-2);
  border: 1px solid var(--border);
  border-radius: 14px 14px 4px 14px;
  padding: 9px 14px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 14px;
}
.msg.user.pending .bubble { opacity: 0.7; }
.msg.user.failed .bubble { border-color: rgba(var(--bad-rgb), 0.5); }
.msg.assistant .avatar {
  flex: none; width: 28px; height: 28px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  background: rgba(var(--primary-rgb), 0.12); color: var(--primary); margin-top: 2px;
}
.msg.assistant .bubble { flex: 1; min-width: 0; padding-top: 3px; }
.msg.assistant pre.md-code { position: relative; padding-right: 40px; }
.msg.assistant pre.md-code[data-lang]::before {
  content: attr(data-lang);
  position: absolute; top: 6px; right: 38px;
  font-size: 10px; color: var(--faint); text-transform: uppercase; letter-spacing: 0.06em;
}
.code-copy { position: absolute; top: 4px; right: 4px; }

.tool-row {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  background: rgba(19, 25, 36, 0.7);
  font-size: 12.5px;
  overflow: hidden;
}
.tool-row.writes { border-left: 3px solid rgba(var(--warn-rgb), 0.55); }
.tool-row.fail { border-color: rgba(var(--bad-rgb), 0.35); }
button.tool-head {
  display: flex; align-items: center; gap: 8px;
  width: 100%; min-height: 0; padding: 7px 11px;
  background: transparent; border: 0; border-radius: 0;
  color: var(--text-2); font-size: 12.5px; font-weight: 400; text-align: left;
}
button.tool-head:hover { background: var(--hover); color: var(--text); border: 0; }
.tool-head svg.icon { color: var(--muted); }
.tool-name { font-family: var(--mono); font-weight: 600; color: var(--text); flex: none; }
.tool-args { font-family: var(--mono); color: var(--muted); flex: 1; min-width: 0; font-size: 11.5px; }
.tool-status { display: inline-flex; align-items: center; gap: 6px; flex: none; }
.tool-dur { color: var(--faint); font-family: var(--mono); font-size: 11px; }
.tool-head .chev { transition: transform var(--ease); }
.tool-row.open .tool-head .chev { transform: rotate(90deg); }
.tool-body { padding: 4px 11px 10px; border-top: 1px solid var(--border-soft); }
.tool-body pre { max-height: 280px; overflow: auto; margin: 0 0 6px; font-size: 11.5px; white-space: pre-wrap; word-break: break-word; }
.tb-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--faint); margin: 8px 0 4px; }

.status-line { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); padding: 0 4px; }
.status-line svg.icon { color: var(--info); }
.event-error { margin: 0 auto; }
.files-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 12.5px; }
.files-line svg.icon { color: var(--warn); }
button.file-chip {
  min-height: 0; padding: 2px 8px; gap: 5px;
  font-family: var(--mono); font-size: 11.5px; font-weight: 500;
  background: var(--input); border: 1px solid var(--border); color: var(--text-2); border-radius: var(--radius-xs);
  white-space: nowrap; max-width: 100%; overflow: hidden; text-overflow: ellipsis;
}
button.file-chip:hover { background: var(--raised-2); color: var(--text); border-color: #2E3B52; }
.done-card {
  border: 1px solid var(--border);
  border-left: 3px solid var(--ok);
  border-radius: var(--radius-sm);
  background: var(--surface);
  padding: 11px 14px;
  font-size: 13px;
}
.done-card .row > svg.icon { color: var(--ok); }
.done-card.s-fail { border-left-color: var(--bad); }
.done-card.s-fail .row > svg.icon { color: var(--bad); }
.done-card.s-warn { border-left-color: var(--warn); }
.done-card.s-warn .row > svg.icon { color: var(--warn); }

/* composer */
.composer { padding: 10px 20px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.composer-box {
  max-width: 860px;
  margin: 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 8px 8px 14px;
  transition: border-color var(--ease), box-shadow var(--ease);
}
.composer-box:focus-within { border-color: rgba(var(--primary-rgb), 0.55); box-shadow: 0 0 0 3px rgba(var(--primary-rgb), 0.14); }
.composer-box.writes { border-color: rgba(var(--warn-rgb), 0.45); }
.composer-box.writes:focus-within { border-color: rgba(var(--warn-rgb), 0.7); box-shadow: 0 0 0 3px rgba(var(--warn-rgb), 0.14); }
.composer-box textarea {
  flex: 1;
  min-height: 24px;
  max-height: 40vh;
  resize: none;
  border: 0;
  background: transparent;
  padding: 6px 0;
  box-shadow: none;
  font-size: 14px;
  line-height: 1.5;
}
.composer-box textarea:focus { box-shadow: none; }
.composer-actions { display: flex; align-items: center; gap: 6px; }
.send-btn.writes { background: var(--warn); color: #1a1300; }
.send-btn.writes:hover { background: #F8C75E; color: #1a1300; }
.composer-hint {
  max-width: 860px; margin: 7px auto 0; font-size: 11.5px; color: var(--muted);
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap; min-height: 18px;
}
.composer-hint code { font-size: 11px; }

/* drawer */
.agent-drawer {
  border-left: 1px solid var(--border-soft);
  background: var(--sidebar);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
}
.agent[data-drawer="closed"] .agent-drawer { visibility: hidden; }
.drawer-grip { display: none; }
.drawer-head { display: flex; align-items: center; gap: 4px; padding: 6px 8px 0 4px; border-bottom: 1px solid var(--border); }
.drawer-tabs { border-bottom: 0; margin: 0; flex: 1; }
.drawer-tabs button { padding: 10px 9px; font-size: 12.5px; }
.drawer-tabs button svg.icon { display: none; }
.drawer-body { flex: 1; overflow-y: auto; padding: 14px 16px 24px; min-height: 0; }
.drawer-backdrop { display: none; }
.pane[hidden] { display: none; }
.pane-sub { display: flex; align-items: center; gap: 8px; margin: 14px 0 8px; font-size: 12.5px; min-width: 0; }
.git-head { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.file-list { list-style: none; padding: 0; margin: 0 0 6px; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.file-list li { display: flex; align-items: center; gap: 4px; border-bottom: 1px solid var(--border-soft); padding-right: 4px; }
.file-list li:last-child { border-bottom: 0; }
button.file-open {
  flex: 1; min-width: 0; justify-content: flex-start; gap: 8px;
  min-height: 0; padding: 8px 10px; background: transparent; border: 0; border-radius: 0;
  color: var(--text); font-family: var(--mono); font-size: 12px; font-weight: 400;
}
button.file-open:hover { background: var(--hover); color: var(--text); border: 0; }
.fs-code {
  flex: none; width: 22px; text-align: center; font-family: var(--mono); font-size: 11px; font-weight: 700;
  border-radius: 4px; padding: 1px 0;
}
.fs-code.mod { color: var(--warn); background: rgba(var(--warn-rgb), 0.12); }
.fs-code.add { color: var(--ok); background: rgba(var(--ok-rgb), 0.12); }
.fs-code.del { color: #FF6B70; background: rgba(var(--bad-rgb), 0.12); }
.icon-btn.danger-icon:hover { color: #FF6B70; background: rgba(var(--bad-rgb), 0.1); }
.commit-result { margin-top: 12px; }
.commit-list > li { align-items: center; }
.agent-drawer table.kv th { width: 110px; }
.agent-drawer .diff { max-height: none; }

/* agent: below 1500px the drawer overlays the conversation instead of squeezing it */
@media (max-width: 1499px) {
  .agent, .agent[data-drawer="open"] { grid-template-columns: var(--ctx-w) minmax(0, 1fr); }
  .agent-drawer {
    position: fixed;
    top: 0; right: 0; bottom: 0;
    width: min(460px, 92vw);
    z-index: 60;
    transform: translateX(102%);
    transition: transform 200ms ease;
    box-shadow: -20px 0 50px rgba(0, 0, 0, 0.45);
  }
  .agent[data-drawer="closed"] .agent-drawer { visibility: visible; }
  .agent[data-drawer="open"] .agent-drawer { transform: none; }
  .drawer-backdrop { display: block; position: fixed; inset: 0; background: rgba(5, 8, 12, 0.55); z-index: 55; }
  .drawer-backdrop[hidden] { display: none; }
}
@media (min-width: 1500px) { .drawer-backdrop { display: none !important; } }
@media (max-width: 1100px) { .agent { --ctx-w: 250px; } }

/* agent: phone/small tablet — context bar collapses to the top; drawer is a bottom sheet */
@media (max-width: 899px) {
  main.agent-main { height: calc(100vh - 56px); height: calc(100dvh - 56px - env(safe-area-inset-top)); }
  .agent, .agent[data-drawer="open"] { display: flex; flex-direction: column; }
  .agent-context { flex: none; border-right: 0; border-bottom: 1px solid var(--border-soft); overflow: visible; background: var(--sidebar); }
  .ctx-toggle {
    display: flex; width: 100%; min-height: 44px; justify-content: flex-start; gap: 10px;
    padding: 10px 14px; border: 0; border-radius: 0; background: transparent; color: var(--text-2); font-size: 13px;
  }
  .ctx-toggle:hover { background: var(--hover); color: var(--text); border: 0; }
  .ctx-toggle .ctx-summary { flex: 1; text-align: left; }
  .ctx-toggle .chev { transition: transform var(--ease); }
  .agent.ctx-open .ctx-toggle .chev { transform: rotate(180deg); }
  .ctx-body { display: none; max-height: 62vh; overflow-y: auto; padding: 4px 14px 16px; border-top: 1px solid var(--border-soft); }
  .agent.ctx-open .ctx-body { display: flex; }
  .agent-chat { flex: 1; }
  .chat-head { padding: 10px 14px; }
  .chat-head h1 { font-size: 15px; }
  .chat-meta { display: none; }
  .chat-log { padding: 16px 12px 8px; }
  #chat-banner { padding: 0 12px; }
  .composer { padding: 8px 10px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .composer-hint { display: none; }
  .composer-hint.alert { display: flex; }
  .msg.user .bubble { max-width: 92%; }
  .drawer-toggle span:not(.count-badge) { display: none; }
  .agent-drawer {
    top: auto; left: 0; right: 0; bottom: 0; width: 100%;
    height: 82vh; height: 82dvh;
    border-left: 0; border-top: 1px solid var(--border);
    border-radius: 18px 18px 0 0;
    transform: translateY(102%);
  }
  .agent[data-drawer="open"] .agent-drawer { transform: none; }
  .drawer-grip { display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--border); margin: 8px auto 2px; flex: none; }
  .drawer-tabs button { padding: 10px 8px; }
}

/* ================================================================== cluster page */

.cluster-tabs { position: sticky; top: 0; z-index: 5; background: var(--bg); }
@media (max-width: 899px) { .cluster-tabs { top: 56px; } }
.node-card .node-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; }
.node-card .node-head h3 { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 15px; }
.node-metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; margin-bottom: 12px; }
.node-facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.node-facts .kv-cell { padding: 8px 10px; }
.node-facts .kv-cell .v { font-size: 12.5px; }
.action-card { display: flex; flex-direction: column; gap: 8px; }
.action-card.dangerous { border-color: rgba(var(--bad-rgb), 0.4); }
.action-card .row { margin-top: auto; }
.actions-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.actions-grid .card { margin: 0; }

/* ---------------------------------------------------------------------------
 * Sortable table headers (static/table-sort.js). The header label is a real
 * button so sorting is keyboard- and screen-reader-operable; the <th> carries
 * aria-sort.
 * ------------------------------------------------------------------------- */
th[data-sort] { padding: 0; }
button.th-sort {
  all: unset;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 10px 14px;
  cursor: pointer;
  font: inherit;
  color: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
  white-space: nowrap;
}
button.th-sort:hover { color: var(--text); }
button.th-sort:focus-visible { outline: 2px solid var(--accent, #E5484D); outline-offset: -2px; border-radius: 4px; }
.th-sort-arrow { width: 0; height: 0; border-left: 4px solid transparent; border-right: 4px solid transparent; opacity: 0.25; border-top: 5px solid currentColor; }
button.th-sort[data-dir="asc"] .th-sort-arrow { opacity: 1; border-top: 0; border-bottom: 5px solid currentColor; }
button.th-sort[data-dir="desc"] .th-sort-arrow { opacity: 1; }

/* Source locations (static/source-policy.js): where project code lives on a
 * machine, and what a registered location IS (source vs deployment/runtime). */
.src-summary { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.src-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.src-root { overflow-wrap: anywhere; color: var(--text); }
.src-role { max-width: 32ch; }
.src-disabled { color: var(--muted); font-size: 12.5px; }
.warn-text { color: var(--warn); }
.src-loc { font-size: 12.5px; overflow-wrap: anywhere; line-height: 1.45; }
.src-loc.strong .src-loc-machine { font-weight: 600; color: var(--text); }
.src-loc.strong .src-loc-path { color: var(--text); }
.src-loc-machine { color: var(--text-2); }
.src-loc-path { color: var(--text-2); }
.pill.src-canonical { font-weight: 600; }
