:root {
  --bg: #0b0f17;
  --panel: #131a26;
  --panel-2: #1a2333;
  --border: #24304a;
  --text: #e6ecf5;
  --muted: #8b98b0;
  --accent: #5b8cff;
  --accent-2: #7c5cff;
  --green: #34d399;
  --amber: #fbbf24;
  --red: #f87171;
  --radius: 14px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 80% -10%, #1a2440 0%, transparent 60%), var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
}
a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; }

/* Layout */
.app { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--panel), #0e1420);
  border-right: 1px solid var(--border);
  padding: 20px 14px; position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
}
.brand { display: flex; align-items: center; gap: 11px; margin-bottom: 8px; }
.brand .logo { width: 38px; height: 38px; border-radius: 11px; flex: 0 0 38px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center;
  box-shadow: 0 4px 14px rgba(91,140,255,.35); }
.brand-name { font-weight: 800; font-size: 15px; line-height: 1.05; letter-spacing:.2px; }
.brand-name small { display:block; color: var(--muted); font-weight: 600; font-size: 9.5px; letter-spacing:1.4px; margin-top:3px; }
.nav { margin-top: 20px; display: flex; flex-direction: column; gap: 3px; }
.nav a { color: var(--muted); padding: 10px 12px; border-radius: 10px; display: flex; gap: 11px; align-items:center; font-weight: 500; }
.nav a svg { opacity: .85; }
.nav a.active, .nav a:hover { background: var(--panel-2); color: var(--text); }
.nav a.active { color: var(--accent); box-shadow: inset 2px 0 0 var(--accent); }
.sidebar-foot { margin-top: auto; border-top:1px solid var(--border); padding-top: 12px; }
.host-meta { font-size:12px; color:var(--muted); margin-bottom: 10px; }
.linkbtn { background:none; border:none; color:var(--muted); display:flex; gap:8px; align-items:center;
  font-size:13px; padding:6px 4px; border-radius:8px; }
.linkbtn:hover { color: var(--text); }

.main { padding: 26px 30px; }
.topbar { display:flex; align-items:center; justify-content: space-between; margin-bottom: 22px; }
.topbar h1 { margin: 0; font-size: 22px; }
.topbar .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* Buttons */
.btn { border: 1px solid var(--border); background: var(--panel-2); color: var(--text);
  padding: 9px 14px; border-radius: 10px; display:inline-flex; gap:8px; align-items:center; }
.btn:hover { border-color: var(--accent); }
.btn.primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; }
.btn.danger { color: var(--red); border-color: #4a2530; }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Cards / grid */
.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow); }
.card h3 { margin: 0 0 4px; font-size: 16px; }
.card .desc { color: var(--muted); font-size: 13px; min-height: 38px; }
.card .icon { font-size: 26px; }
.row { display:flex; align-items:center; justify-content: space-between; gap:10px; }
.tags { display:flex; gap:6px; flex-wrap: wrap; margin: 10px 0; }
.tag { font-size: 11px; color: var(--muted); background: var(--panel-2); border:1px solid var(--border);
  padding: 2px 8px; border-radius: 999px; }

.specs { display:flex; gap:16px; margin: 10px 0; font-size: 13px; color: var(--muted); }
.specs b { color: var(--text); }

/* Status dot */
.dot { width: 9px; height: 9px; border-radius: 50%; display:inline-block; }
.dot.running { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dot.exited, .dot.created { background: var(--muted); }
.pill { font-size:12px; padding:3px 9px; border-radius:999px; border:1px solid var(--border);
  display:inline-flex; align-items:center; gap:6px; }

/* Meters */
.meter { height: 8px; background: var(--panel-2); border-radius: 999px; overflow: hidden; }
.meter > span { display:block; height:100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.metric { margin: 10px 0; }
.metric .lbl { display:flex; justify-content: space-between; font-size:12px; color:var(--muted); margin-bottom:4px; }

/* ---- Instance detail: cockpit layout ---- */
.ihead { display:flex; align-items:center; justify-content:space-between; gap:16px; margin-bottom: 16px; }
.ihead-l { display:flex; align-items:center; gap:14px; min-width:0; }
.ihead-l h1 { margin:0; font-size: 21px; white-space:nowrap; }
.ihead-r { display:flex; gap:8px; flex:0 0 auto; }
.chips { display:flex; gap:8px; flex-wrap:wrap; margin-top:6px; }
.chip { display:inline-flex; align-items:center; gap:6px; font-size:12px; color:var(--text);
  background: var(--panel-2); border:1px solid var(--border); padding:3px 10px; border-radius:999px; white-space:nowrap; }
.chip.mono { font-family: ui-monospace, Menlo, monospace; color: var(--muted); font-size:11px; }
.chip svg { opacity:.7; }
.btn.sm { padding:7px 9px; }

.istage { display:flex; gap:16px; align-items:flex-start; }
.istage-main { flex:1; min-width:0; display:flex; flex-direction:column; gap:14px; }
.chatrail { flex:0 0 380px; display:flex; flex-direction:column;
  position: sticky; top: 20px; height: calc(100vh - 40px); min-height: 460px;
  background: var(--panel); border:1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow:hidden; }
.chatrail-head { padding:14px 16px; border-bottom:1px solid var(--border); font-weight:700; font-size:15px;
  display:flex; align-items:center; gap:8px; }
.chatrail .chatlog { flex:1; max-height:none; margin:0; padding:14px; }
.chatrail .chatbar { padding:12px 14px; border-top:1px solid var(--border); }
.chatrail .hint { padding:0 14px 12px; }

/* Desktop viewer (hero — sized to the desktop's exact aspect ratio, no black bars) */
.viewer { display:flex; flex-direction:column;
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background:#000; box-shadow: var(--shadow); }
.viewer .bar { display:flex; align-items:center; gap:10px; padding: 8px 12px; background: var(--panel-2);
  border-bottom: 1px solid var(--border); flex:0 0 auto; }
.viewer .v-title { color:var(--text); font-size:13px; display:flex; align-items:center; gap:7px; }
.viewer .v-title .muted { color:var(--muted); }
.screen { width:100%; background:#0a0e16; position:relative; max-height: calc(100vh - 210px); }
.screen iframe { position:absolute; inset:0; width: 100%; height: 100%; border: 0; display:block; background:#111; }
.deskoff { position:absolute; inset:0; display:grid; place-items:center; color:var(--muted); text-align:center; }
.dots { display:flex; gap:6px; }
.dots i { width:11px;height:11px;border-radius:50%; display:inline-block; }
.dots i:nth-child(1){background:#ff5f57}.dots i:nth-child(2){background:#febc2e}.dots i:nth-child(3){background:#28c840}

/* Tabbed secondary panel */
.panel { flex:0 0 auto; height: 264px; display:flex; flex-direction:column; min-height:0;
  background: var(--panel); border:1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow:hidden; }
.tabs { display:flex; gap:2px; padding:6px 6px 0; border-bottom:1px solid var(--border); overflow-x:auto; }
.tab { background:none; border:none; color:var(--muted); padding:9px 12px; border-radius:8px 8px 0 0;
  font-size:13px; font-weight:600; display:inline-flex; align-items:center; gap:7px; white-space:nowrap; border-bottom:2px solid transparent; }
.tab:hover { color:var(--text); }
.tab.active { color:var(--accent); border-bottom-color: var(--accent); background: var(--panel-2); }
.tabbody { flex:1; overflow:auto; padding:14px; }
.tabpane { display:none; }
.tabpane.active { display:block; }
.grid2 { display:grid; grid-template-columns:1fr 1fr; gap:10px; }
.tabbody .field { margin:0 0 8px; }
.tabbody input, .tabbody select { width:100%; padding:9px 11px; background: var(--panel-2);
  border:1px solid var(--border); border-radius:9px; color:var(--text); font:inherit; }

/* Files tab */
.files { display:grid; grid-template-columns: 200px 1fr; gap:12px; height:100%; }
.files-list { border:1px solid var(--border); border-radius:10px; overflow:auto; padding:6px; }
.fgroup { font-size:11px; letter-spacing:.6px; text-transform:uppercase; color:var(--muted); padding:8px 8px 4px; }
.fitem { display:flex; justify-content:space-between; gap:8px; width:100%; background:none; border:none;
  color:var(--text); padding:7px 8px; border-radius:7px; font-size:13px; text-align:left; }
.fitem:hover { background: var(--panel-2); }
.fname { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
.fsize { color:var(--muted); font-size:11px; flex:0 0 auto; }
.file-view { border:1px solid var(--border); border-radius:10px; overflow:auto; padding:12px; }
.file-view .fv-path { font-weight:700; margin-bottom:8px; font-size:13px; }
.file-view pre { margin:0; white-space:pre-wrap; word-wrap:break-word; font:12px/1.55 ui-monospace, Menlo, monospace; color:#b7c3d8; }
.muted { color: var(--muted); }

/* Skills tab */
.skills-grid { display:grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap:10px; }
.skill { border:1px solid var(--border); border-radius:10px; padding:10px 12px; background: var(--panel-2); }
.skill-h { display:flex; align-items:center; gap:7px; font-size:14px; }
.skill-h .fsize { margin-left:auto; }
.skill-h svg { color: var(--accent); }
.skill-d { color:var(--muted); font-size:12px; margin-top:5px; line-height:1.4; }

@media (max-width: 1040px){
  .istage { flex-direction:column; }
  .chatrail { position:static; flex-basis:auto; height:440px; width:100%; }
  .app{grid-template-columns:1fr;} .sidebar{display:none;}
  .files { grid-template-columns:1fr; }
}

.logs { background:#0a0e16; border:1px solid var(--border); border-radius:10px; padding:12px;
  font: 12px/1.5 ui-monospace, Menlo, monospace; color:#b7c3d8; max-height: 260px; overflow:auto; white-space:pre-wrap; }

/* Modal */
.modal-bg { position: fixed; inset: 0; background: rgba(3,6,12,.6); backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 50; }
.modal { width: min(520px, 92vw); background: var(--panel); border:1px solid var(--border);
  border-radius: 16px; padding: 22px; box-shadow: var(--shadow); }
.modal h2 { margin: 0 0 4px; }
.field { margin: 14px 0; }
.field label { display:block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.field input, .field select { width:100%; padding: 10px 12px; background: var(--panel-2);
  border:1px solid var(--border); border-radius: 10px; color: var(--text); }
.modal .actions { display:flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.hint { font-size:12px; color:var(--muted); margin-top:6px; }

/* Chat */
.chatlog { margin: 12px 0; max-height: 320px; overflow-y: auto; display:flex; flex-direction: column; gap: 10px; padding-right: 4px; }
.cmsg { max-width: 82%; padding: 10px 13px; border-radius: 13px; font-size: 14px; line-height: 1.45; white-space: pre-wrap; word-wrap: break-word; }
.cmsg.user { align-self: flex-end; background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: #fff; border-bottom-right-radius: 4px; }
.cmsg.bot, .cmsg.typing { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.cmsg.typing { color: var(--muted); }
.cmsg em { color: var(--accent); font-style: italic; }
.chatbar { display:flex; gap: 8px; }
.chatbar input { flex:1; padding: 11px 13px; background: var(--panel-2); border:1px solid var(--border); border-radius: 10px; color: var(--text); }
.chatbar input:focus { outline: none; border-color: var(--accent); }

.empty { text-align:center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-size: 40px; margin-bottom: 10px; }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--panel-2); border:1px solid var(--border);
  padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow); z-index: 60; max-width: 360px; }
.toast.err { border-color: #4a2530; }
.spin { width:14px;height:14px;border:2px solid var(--border); border-top-color: var(--accent);
  border-radius:50%; animation: sp .7s linear infinite; display:inline-block; }
@keyframes sp { to { transform: rotate(360deg); } }

/* Onboard / ingest tab */
.onb-sec { background: var(--panel-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; margin-bottom: 12px; }
.onb-h { display:flex; align-items:center; gap:8px; font-weight:600; margin-bottom:4px; }
.onb-h svg { width:18px; height:18px; color: var(--accent); }
.onb-ta { width:100%; min-height:150px; margin:8px 0; padding:10px 12px; background: var(--panel);
  color: var(--fg, #e6ecf7); border:1px solid var(--border); border-radius:8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size:12.5px; line-height:1.5; resize:vertical; }

/* ── Maverick board ─────────────────────────────────────────────────────────
   These classes were used by renderMaverick() before they existed. The board
   rendered its data correctly and looked broken: "2computer(s)" with the
   number welded to its label, because <b> and <span> had no styling to
   separate them. Caught by screenshotting the page rather than by checking
   that the endpoint returned 200 — an API test would have passed all day.
   Uses the existing theme variables so the board cannot drift from the rest
   of the UI when the palette changes.                                        */

.stats { display: flex; flex-wrap: wrap; gap: 12px; margin: 18px 0 6px; }
.stat {
  display: flex; flex-direction: column; gap: 2px;
  min-width: 140px; padding: 14px 16px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius);
}
.stat b { font-size: 22px; line-height: 1.1; color: var(--text); }
.stat span { font-size: 12px; color: var(--muted); }

.sec { margin: 28px 0 10px; font-size: 15px; color: var(--text); font-weight: 600; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 14px; }
.card {
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px; box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; margin-bottom: 2px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip {
  font-size: 11px; padding: 3px 9px; border-radius: 999px;
  background: rgba(91,140,255,.12); color: var(--accent);
  border: 1px solid rgba(91,140,255,.28);
}
/* A screenshot is the point of this card — give it room, and a neutral
   backdrop so a black desktop is distinguishable from a failed load. */
.shot {
  width: 100%; border-radius: 10px; border: 1px solid var(--border);
  background: #000; display: block; margin-top: 4px;
}

.tbl { width: 100%; border-collapse: collapse; font-size: 13px; margin-top: 4px; }
.tbl th {
  text-align: left; font-weight: 600; color: var(--muted); font-size: 11px;
  text-transform: uppercase; letter-spacing: .04em;
  padding: 8px 10px; border-bottom: 1px solid var(--border);
}
.tbl td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.tbl tr:last-child td { border-bottom: 0; }

.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.ok   { color: var(--green); }
.bad  { color: var(--red); }
