/* ============================================================
   AIBox Operations — design system
   Dark theme, medical blue. Tokens first; components after.
   ============================================================ */

:root {
  --bg: #0b1220;
  --bg-glow: radial-gradient(1200px 600px at 80% -10%, rgba(61, 139, 253, 0.10), transparent 60%),
             radial-gradient(900px 500px at -10% 110%, rgba(89, 194, 232, 0.07), transparent 60%);
  --surface: #111a2c;
  --surface-2: #16223a;
  --surface-3: #1b2a47;
  --border: #1e2c47;
  --border-strong: #2a3b5e;

  --text: #e6edf7;
  --text-2: #9fb0c9;
  --muted: #66799a;

  --accent: #3d8bfd;          /* medical blue */
  --accent-strong: #63a3ff;
  --accent-soft: rgba(61, 139, 253, 0.14);
  --cyan: #59c2e8;

  --good: #34d399;
  --good-soft: rgba(52, 211, 153, 0.13);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, 0.13);
  --bad: #f87171;
  --bad-soft: rgba(248, 113, 113, 0.13);

  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 10px 30px rgba(2, 8, 20, 0.45);
  --font: "Inter", -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sidebar-w: 236px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  background-image: var(--bg-glow);
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
::selection { background: rgba(61, 139, 253, 0.35); }

/* ---------- layout shell ---------- */

.boot { display: flex; align-items: center; justify-content: center; height: 100vh; }

.shell { display: grid; grid-template-columns: var(--sidebar-w) 1fr; min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: rgba(13, 20, 36, 0.85);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
}
.logo {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 10px 18px;
  font-weight: 700; font-size: 15px; letter-spacing: 0.2px;
}
.logo svg { flex: none; }
.logo .sub { display: block; font-size: 11px; font-weight: 500; color: var(--muted); letter-spacing: 0.4px; }

.nav { display: flex; flex-direction: column; gap: 2px; margin-top: 6px; }
.nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; border-radius: 8px;
  color: var(--text-2); font-weight: 500;
}
.nav a:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent-strong); }
.nav a svg { flex: none; opacity: 0.85; }

.sidebar .foot { margin-top: auto; padding: 10px 12px; font-size: 12px; color: var(--muted); }
.sidebar .foot .who { color: var(--text-2); font-weight: 500; overflow: hidden; text-overflow: ellipsis; }
.sidebar .foot button { margin-top: 8px; width: 100%; }

.main { padding: 26px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 20px; font-weight: 650; letter-spacing: -0.2px; }
.page-head .crumb { color: var(--muted); font-weight: 500; }
.page-head .actions { display: flex; gap: 10px; }

/* ---------- cards & tiles ---------- */

.card {
  background: linear-gradient(180deg, rgba(255,255,255,0.015), rgba(255,255,255,0)) , var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 20px;
}
.card + .card { margin-top: 16px; }
.card h2 { margin: 0 0 14px; font-size: 14px; font-weight: 600; color: var(--text); }
.card h2 .hint { font-weight: 400; color: var(--muted); font-size: 12.5px; margin-left: 8px; }

.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 18px;
}
.tile .label { font-size: 11.5px; font-weight: 600; letter-spacing: 0.7px; text-transform: uppercase; color: var(--muted); }
.tile .value { font-size: 28px; font-weight: 650; letter-spacing: -0.5px; margin-top: 6px; font-variant-numeric: tabular-nums; }
.tile .note { font-size: 12.5px; color: var(--text-2); margin-top: 2px; }
.tile .note .up { color: var(--good); }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }

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

.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
thead th {
  position: sticky; top: 0; z-index: 1;
  text-align: left; padding: 10px 14px;
  background: var(--surface-2); color: var(--text-2);
  font-size: 11.5px; font-weight: 600; letter-spacing: 0.6px; text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: rgba(61, 139, 253, 0.05); }
td.num { font-variant-numeric: tabular-nums; }
td .sub { display: block; font-size: 12px; color: var(--muted); }
.mono { font-family: var(--mono); font-size: 12.5px; }

.empty { padding: 34px; text-align: center; color: var(--muted); }
.empty .big { font-size: 15px; color: var(--text-2); margin-bottom: 4px; }

.pager { display: flex; align-items: center; gap: 12px; justify-content: flex-end; margin-top: 12px; color: var(--text-2); font-size: 13px; }
.pager button { min-width: 34px; }

/* ---------- badges, dots, status ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 2.5px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--text-2); border: 1px solid var(--border-strong);
}
.badge.accent { background: var(--accent-soft); color: var(--accent-strong); border-color: transparent; }
.badge.good   { background: var(--good-soft);  color: var(--good);  border-color: transparent; }
.badge.warn   { background: var(--warn-soft);  color: var(--warn);  border-color: transparent; }
.badge.bad    { background: var(--bad-soft);   color: var(--bad);   border-color: transparent; }

.dotline { display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.on  { background: var(--good); box-shadow: 0 0 0 3px var(--good-soft); }
.dot.off { background: var(--muted); }

/* ---------- buttons & forms ---------- */

button, .btn {
  font: inherit; font-weight: 600; font-size: 13.5px;
  color: var(--text); background: var(--surface-3);
  border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 8px 14px; cursor: pointer;
  transition: background 0.12s, border-color 0.12s, opacity 0.12s;
}
button:hover { background: var(--surface-2); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: transparent; color: #fff; }
button.primary:hover { background: var(--accent-strong); }
button.danger { background: transparent; border-color: rgba(248, 113, 113, 0.4); color: var(--bad); }
button.danger:hover { background: var(--bad-soft); }
button.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
button.ghost:hover { background: var(--surface-2); color: var(--text); }
button.small { padding: 5px 10px; font-size: 12.5px; }

label.field { display: block; margin-bottom: 13px; }
label.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
label.field .req { color: var(--accent-strong); }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text);
  background: #0d1526; border: 1px solid var(--border-strong); border-radius: 8px;
  padding: 8.5px 11px; outline: none;
  transition: border-color 0.12s, box-shadow 0.12s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(61, 139, 253, 0.18); }
input::placeholder { color: var(--muted); }
textarea { resize: vertical; min-height: 70px; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%239fb0c9' fill='none' stroke-width='1.5' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 30px; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters label.field { margin: 0; min-width: 130px; flex: 0 1 auto; }
.filters .grow { flex: 1 1 220px; }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.form-err { color: var(--bad); font-size: 13px; margin: 4px 0 10px; min-height: 0; }

/* ---------- modal & drawer ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4, 9, 20, 0.66); backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 8vh 20px 40px; overflow-y: auto;
}
.modal {
  width: 100%; max-width: 520px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  animation: pop 0.14s ease-out;
}
.modal.wide { max-width: 700px; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }
.modal header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px 0; }
.modal header h3 { margin: 0; font-size: 15.5px; font-weight: 650; }
.modal .body { padding: 16px 20px; }
.modal footer { display: flex; justify-content: flex-end; gap: 10px; padding: 0 20px 18px; }

.overlay.drawer { justify-content: flex-end; padding: 0; align-items: stretch; }
.drawer-panel {
  width: 480px; max-width: 92vw; height: 100vh; overflow-y: auto;
  background: var(--surface); border-left: 1px solid var(--border-strong);
  animation: slide 0.16s ease-out; padding-bottom: 30px;
}
@keyframes slide { from { transform: translateX(24px); opacity: 0.5; } }
.drawer-panel header { position: sticky; top: 0; z-index: 2; background: var(--surface); display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 12px; border-bottom: 1px solid var(--border); }
.drawer-panel header h3 { margin: 0; font-size: 15.5px; }
.drawer-panel .body { padding: 16px 22px; }

.kv { display: grid; grid-template-columns: 150px 1fr; gap: 7px 14px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

.token-box {
  font-family: var(--mono); font-size: 13px;
  background: #0d1526; border: 1px dashed var(--accent); border-radius: 8px;
  padding: 12px 14px; margin: 10px 0; overflow-wrap: anywhere;
}

/* ---------- toasts ---------- */

#toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: var(--surface-2); border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: 10px; box-shadow: var(--shadow);
  padding: 11px 16px; max-width: 380px; font-size: 13.5px;
  animation: pop 0.15s ease-out;
}
.toast.good { border-left-color: var(--good); }
.toast.bad { border-left-color: var(--bad); }

/* ---------- login ---------- */

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 16px; padding: 34px 32px 28px; box-shadow: var(--shadow); }
.login-card .logo { justify-content: center; padding-bottom: 8px; }
.login-card p.tag { text-align: center; color: var(--muted); margin: 0 0 24px; font-size: 13px; }
.login-card button.primary { width: 100%; padding: 10px; margin-top: 4px; }

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

.spinner {
  width: 26px; height: 26px; border-radius: 50%;
  border: 3px solid var(--surface-3); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite; margin: 30px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.chiprow { display: flex; flex-wrap: wrap; gap: 6px; }
.section-gap { height: 18px; }
.muted { color: var(--muted); }
.right { text-align: right; }
pre.json {
  font-family: var(--mono); font-size: 12px; color: var(--text-2);
  background: #0d1526; border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; overflow-x: auto; margin: 0;
}

/* media viewer */
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 16px; }
.media-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.media-card .head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.media-card .tabs { display: flex; gap: 4px; padding: 8px 10px 0; flex-wrap: wrap; }
.media-card .tabs button { padding: 4px 10px; font-size: 12px; border-radius: 6px; }
.media-card .tabs button.active { background: var(--accent-soft); color: var(--accent-strong); border-color: transparent; }
.media-card .frame { aspect-ratio: 4 / 3; display: flex; align-items: center; justify-content: center; background: #060b16; margin: 10px; border-radius: 8px; overflow: hidden; }
.media-card .frame img, .media-card .frame video { max-width: 100%; max-height: 100%; object-fit: contain; }
.media-card .frame .ph { color: var(--muted); font-size: 12.5px; text-align: center; padding: 20px; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; align-items: center; overflow-x: auto; }
  .nav { flex-direction: row; }
  .sidebar .foot { display: none; }
  .main { padding: 18px 16px 40px; }
}
