/* Magus Labs HQ fleet console. Self-contained: no web fonts, no external assets. */
:root {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-2: #f0f1f6;
  --border: #dadde7;
  --border-strong: #b9bed0;
  --text: #11141f;
  --text-2: #434a5f;
  --text-3: #5f667c;
  --brand: #6d28d9;
  --brand-hover: #5b21b6;
  --brand-text: #5b21b6;
  --brand-soft: #efe9fe;
  --accent: #047857;
  --ok: #157a3c; --ok-strong: #16a34a; --ok-soft: #e3f8ea;
  --warn: #9a4a06; --warn-strong: #d97706; --warn-soft: #fff3d6;
  --bad: #b42318; --bad-strong: #dc2626; --bad-soft: #fde7e5;
  --info: #1d4ed8; --info-soft: #e1ebff;
  --off: #6b7280;
  --focus: #2563eb;
  --shadow: 0 1px 2px rgba(17, 20, 31, .06), 0 4px 14px rgba(17, 20, 31, .05);
  --radius: 12px;
  --tap: 44px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #09090b;
    --surface: #17171b;
    --surface-2: #222228;
    --border: #2c2c33;
    --border-strong: #45454f;
    --text: #f4f4f5;
    --text-2: #d0d0d6;
    --text-3: #a0a0ab;
    --brand: #7c3aed;
    --brand-hover: #8b5cf6;
    --brand-text: #c4b5fd;
    --brand-soft: rgba(139, 92, 246, .16);
    --accent: #34d399;
    --ok: #4ade80; --ok-strong: #22c55e; --ok-soft: rgba(34, 197, 94, .13);
    --warn: #fbbf24; --warn-strong: #f59e0b; --warn-soft: rgba(245, 158, 11, .14);
    --bad: #fca5a5; --bad-strong: #ef4444; --bad-soft: rgba(239, 68, 68, .15);
    --info: #93c5fd; --info-soft: rgba(59, 130, 246, .15);
    --off: #8b8b96;
    --focus: #38bdf8;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 var(--font); min-height: 100vh; }
h1, h2, h3 { margin: 0; line-height: 1.25; }
p { margin: 0; }
a { color: var(--brand-text); }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
.ic { width: 1.2em; height: 1.2em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--text-3); }
.small { font-size: 13px; }
.mono { font-family: var(--mono); font-size: .92em; }
.num { font-variant-numeric: tabular-nums; }
.skip { position: absolute; left: -9999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 100; }
.skip:focus { left: 8px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: var(--tap); padding: 8px 16px; border-radius: 10px; border: 1px solid transparent; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-hover); }
.btn-secondary { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger { background: #c22a1f; color: #fff; }
.btn-danger:hover { filter: brightness(.92); }
.btn-sm { min-height: 36px; padding: 4px 12px; font-size: 14px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.icon-btn { display: inline-grid; place-items: center; width: var(--tap); height: var(--tap); border: 0; border-radius: 50%; background: transparent; color: var(--text-2); cursor: pointer; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.q { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--border-strong); background: var(--surface); color: var(--text-2); font-size: 12px; font-weight: 700; cursor: pointer; vertical-align: middle; position: relative; padding: 0; text-transform: none; letter-spacing: 0; }
.q::after { content: ""; position: absolute; inset: -10px; }
.q:hover { border-color: var(--brand); color: var(--brand-text); }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 28px 24px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 8px; text-align: center; }
.login-logo { width: 60px; height: 60px; margin: 0 auto 4px; border-radius: 16px; display: grid; place-items: center; background: var(--surface-2); color: var(--accent); }
.login-logo .ic { width: 32px; height: 32px; }
.login-card h1 { font-size: 24px; letter-spacing: .5px; }
.login-card .field-label { text-align: left; margin-top: 12px; }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 52px; }
.pw-toggle { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); width: 44px; height: 44px; border: 0; background: none; color: var(--text-3); cursor: pointer; border-radius: 8px; }
.pw-toggle[aria-pressed="true"] { color: var(--brand-text); }

.field-label { display: block; font-weight: 600; margin-bottom: 6px; }
.field-hint { display: block; font-size: 13px; color: var(--text-3); margin-top: 4px; }
.field { margin-bottom: 14px; }
input[type="text"], input[type="password"], input[type="search"], select {
  width: 100%; min-height: var(--tap); padding: 8px 12px; border-radius: 10px; border: 1.5px solid var(--border-strong); background: var(--surface); color: var(--text); font-size: 15px;
}
input:focus, select:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 28%, transparent); }
.form-error { color: var(--bad); font-weight: 600; min-height: 1.4em; font-size: 14px; }

/* Top bar */
.topbar { background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.topbar-inner { max-width: 1400px; margin: 0 auto; padding: 0 16px; min-height: 60px; display: flex; align-items: center; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; }
.brand-ic { width: 24px; height: 24px; color: var(--accent); }
.brand-name { font-weight: 800; letter-spacing: 1.5px; font-size: 14px; }
.brand-sub { color: var(--text-3); font-size: 14px; }
.demo-badge { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; padding: 2px 8px; border-radius: 999px; background: var(--warn-soft); color: var(--warn); border: 1px solid var(--warn-strong); white-space: nowrap; }
.tabs { display: flex; gap: 4px; flex: 1; }
.tabs a { display: inline-flex; align-items: center; gap: 8px; padding: 0 14px; min-height: 60px; text-decoration: none; color: var(--text-2); font-weight: 600; border-bottom: 3px solid transparent; }
.tabs a:hover { color: var(--text); }
.tabs a[aria-current="page"] { color: var(--text); border-bottom-color: var(--accent); }

main { max-width: 1400px; margin: 0 auto; padding: 24px 16px 48px; outline: none; }
.view-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; margin-bottom: 16px; }
.view-head h1 { font-size: 22px; }
.view-head p { color: var(--text-3); margin-top: 2px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.card-head h2 { font-size: 16px; display: flex; align-items: center; gap: 8px; }

/* KPI strip */
.kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); }
.kpi-label { font-size: 13px; color: var(--text-3); font-weight: 600; display: flex; align-items: center; gap: 6px; }
.kpi-value { font-size: 28px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; margin-top: 2px; }
.kpi-value.bad { color: var(--bad); } .kpi-value.warn { color: var(--warn); } .kpi-value.ok { color: var(--ok); }

/* Status dots */
.status { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }
.dot.online { background: var(--ok-strong); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.stale { background: var(--warn-strong); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot.offline { background: var(--bad-strong); box-shadow: 0 0 0 3px var(--bad-soft); }
.dot.never { background: transparent; border: 2px solid var(--off); }
.st-online { color: var(--ok); } .st-stale { color: var(--warn); } .st-offline { color: var(--bad); } .st-never { color: var(--text-3); }

/* Toolbar */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--border); }
.toolbar input[type="search"] { max-width: 300px; }
.toolbar select { width: auto; }
.toolbar .count { margin-left: auto; color: var(--text-3); font-size: 14px; }

/* Table */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3); font-weight: 700; background: var(--surface-2); white-space: nowrap; }
th.r, td.r { text-align: right; }
th button.sort { all: unset; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; border-radius: 4px; }
th button.sort:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
th button.sort::after { content: "↕"; opacity: .35; font-size: 11px; }
th[aria-sort="ascending"] button.sort::after { content: "↑"; opacity: 1; }
th[aria-sort="descending"] button.sort::after { content: "↓"; opacity: 1; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }
.row-name { all: unset; cursor: pointer; font-weight: 700; color: var(--text); border-radius: 4px; }
.row-name:hover { color: var(--brand-text); text-decoration: underline; }
.row-name:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
.zero { color: var(--text-3); }
.qbad { color: var(--bad); font-weight: 700; }
.empty { padding: 32px 16px; text-align: center; color: var(--text-3); }

.pill { display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.pill-ok { background: var(--ok-soft); color: var(--ok); }
.pill-bad { background: var(--bad-soft); color: var(--bad); }
.pill-warn { background: var(--warn-soft); color: var(--warn); }
.pill-info { background: var(--info-soft); color: var(--info); }
.pill-plain { background: var(--surface-2); color: var(--text-2); }

/* Drawer */
dialog.drawer { margin: 0 0 0 auto; height: 100vh; max-height: 100vh; width: min(560px, 100vw); max-width: 100vw; border: 0; border-left: 1px solid var(--border); padding: 0; background: var(--surface); color: var(--text); box-shadow: -10px 0 40px rgba(0,0,0,.25); }
dialog.drawer[open] { display: flex; flex-direction: column; animation: slide .18s ease-out; }
dialog.drawer::backdrop, dialog.sheet::backdrop { background: rgba(0, 0, 0, .5); }
@keyframes slide { from { transform: translateX(40px); opacity: .4; } }
.drawer-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 12px 12px 20px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: 19px; }
.drawer-body { padding: 18px 20px 28px; overflow-y: auto; flex: 1; }
.drawer-body h3 { font-size: 14px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-3); margin: 22px 0 10px; }
.facts { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin: 0; }
.facts div { background: var(--surface-2); border-radius: 10px; padding: 10px 12px; }
.facts dt { font-size: 12px; color: var(--text-3); font-weight: 600; }
.facts dd { margin: 2px 0 0; font-weight: 700; word-break: break-word; }
.ev-list { list-style: none; padding: 0; margin: 0; }
.ev { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.ev:last-child { border-bottom: 0; }
.ev-title { font-weight: 600; }
.ev-meta { grid-column: 2; font-size: 13px; color: var(--text-3); }
.danger-zone { margin-top: 28px; border: 1px solid var(--bad-strong); border-radius: 12px; padding: 14px; }
.danger-zone p { color: var(--text-2); font-size: 14px; margin: 4px 0 10px; }

/* Sheets */
dialog.sheet { border: 1px solid var(--border); border-radius: 16px; padding: 0; width: min(560px, calc(100vw - 24px)); max-height: calc(100vh - 32px); background: var(--surface); color: var(--text); box-shadow: 0 20px 60px rgba(0,0,0,.35); }
dialog.sheet-sm { width: min(440px, calc(100vw - 24px)); }
dialog.sheet[open] { display: flex; flex-direction: column; }
dialog.sheet > form { display: flex; flex-direction: column; min-height: 0; max-height: inherit; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 12px 4px 20px; }
.sheet-head h2 { font-size: 19px; }
.sheet-body { padding: 8px 20px 12px; overflow-y: auto; color: var(--text-2); }
.sheet-body p + p { margin-top: 8px; }
.sheet-foot { display: flex; gap: 10px; justify-content: flex-end; padding: 12px 20px 18px; border-top: 1px solid var(--border); }

.codebox { display: flex; align-items: stretch; gap: 0; border: 1.5px solid var(--border-strong); border-radius: 10px; overflow: hidden; margin: 6px 0 4px; background: var(--surface-2); }
.codebox code { flex: 1; padding: 10px 12px; font-family: var(--mono); font-size: 13.5px; color: var(--text); word-break: break-all; user-select: all; }
.codebox button { border: 0; border-left: 1.5px solid var(--border-strong); background: var(--surface); padding: 0 14px; display: inline-flex; align-items: center; gap: 6px; font-weight: 600; cursor: pointer; min-width: 92px; justify-content: center; }
.codebox button:hover { background: var(--brand-soft); color: var(--brand-text); }
.steps { padding-left: 20px; margin: 10px 0 0; }
.steps li { margin-bottom: 12px; }
.callout { border-radius: 10px; padding: 10px 12px; font-size: 14px; margin: 10px 0; }
.callout-warn { background: var(--warn-soft); border-left: 4px solid var(--warn-strong); color: var(--text); }
.callout-ok { background: var(--ok-soft); border-left: 4px solid var(--ok-strong); color: var(--text); }

/* Intel */
.intel-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 16px; }
.src-err { color: var(--bad); font-size: 13px; }
.section { margin-bottom: 16px; }
.held { border: 2px solid var(--warn-strong); }
.held .card-head { background: var(--warn-soft); border-radius: var(--radius) var(--radius) 0 0; }
.held .card-pad > * + * { margin-top: 12px; }
.examples-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.examples { list-style: none; padding: 0; margin: 0; display: grid; gap: 4px; }
.examples li { background: var(--surface-2); border-radius: 8px; padding: 4px 10px; word-break: break-all; }
.skip-list { margin: 8px 0 0; padding-left: 20px; }
.skip-list li { margin-bottom: 4px; }
.banner { display: flex; gap: 10px; align-items: flex-start; border-radius: var(--radius); padding: 12px 16px; margin-bottom: 16px; font-size: 15px; }
.banner .ic { flex: none; margin-top: 2px; }
.banner-warn { background: var(--warn-soft); border: 2px solid var(--warn-strong); color: var(--text); }

.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: grid; gap: 8px; width: min(460px, calc(100vw - 24px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; background: var(--text); color: var(--bg); font-weight: 600; box-shadow: var(--shadow); animation: pop .2s ease-out; }
.toast.error { background: #c22a1f; color: #fff; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.skeleton { padding: 40px 0; text-align: center; color: var(--text-3); }
.spin { display: inline-block; width: 20px; height: 20px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

@media (max-width: 1000px) {
  .kpis { grid-template-columns: repeat(3, 1fr); }
  .intel-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 720px) {
  .hide-sm { display: none !important; }
  .topbar-inner { gap: 4px 8px; padding: 0 4px 0 12px; flex-wrap: wrap; justify-content: space-between; min-height: 52px; }
  .brand-name { white-space: nowrap; }
  .tabs { order: 3; flex: 1 1 100%; border-top: 1px solid var(--border); margin: 0 -4px 0 -12px; }
  .tabs a { flex: 1; justify-content: center; padding: 0 10px; min-height: 50px; white-space: nowrap; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .toolbar input[type="search"] { max-width: none; flex: 1 1 100%; }
  .toolbar select { flex: 1; }
  /* Fleet table becomes a list of cards on phones */
  table.fleet thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.fleet, table.fleet tbody, table.fleet tr, table.fleet td { display: block; width: 100%; }
  table.fleet tr { padding: 12px 16px; border-bottom: 1px solid var(--border); display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; }
  table.fleet td { border: 0; padding: 0; text-align: left !important; font-size: 14px; }
  table.fleet td[data-label]::before { content: attr(data-label) ": "; color: var(--text-3); font-weight: 600; }
  table.fleet td.c-name { grid-column: 1 / -1; font-size: 16px; }
  table.fleet td.c-status { grid-column: 1 / -1; order: -1; }
  .facts { grid-template-columns: 1fr; }
  .examples-grid { grid-template-columns: 1fr; }
  dialog.sheet { margin: auto auto 0; width: 100vw; max-width: 100vw; border-radius: 16px 16px 0 0; }
  .sheet-foot .btn { flex: 1; }
  .codebox { flex-direction: column; }
  .codebox button { border-left: 0; border-top: 1.5px solid var(--border-strong); min-height: 44px; }
}
