:root {
  color-scheme: light;
  --bg: #eceff3;
  --panel: #ffffff;
  --panel-2: #f4f6f9;
  --text: #1a2230;
  --muted: #5b6573;
  --faint: #8a93a1;
  --line: #e0e5ec;
  --line-strong: #cbd3dd;
  --brand: #1f4e79;
  --brand-ink: #163a5c;
  --brand-soft: #e9eff5;
  --ok: #2f7d54;
  --ok-bg: #e7f1ec;
  --info: #1f4e79;
  --info-bg: #e9eff5;
  --danger: #b23b32;
  --danger-bg: #fbecea;
  --warn: #936413;
  --warn-bg: #f8efdc;
  --shadow: 0 1px 1px rgba(20,30,45,.04), 0 1px 3px rgba(20,30,45,.05);
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, "SF Mono", monospace;
  --radius: 7px;
}

body.dark {
  color-scheme: dark;
  --bg: #0d1117;
  --panel: #161c25;
  --panel-2: #1b232e;
  --text: #e4eaf1;
  --muted: #95a1b1;
  --faint: #6b7686;
  --line: #28313d;
  --line-strong: #3a4554;
  --brand: #4d88c9;
  --brand-ink: #6ea4dc;
  --brand-soft: #15273b;
  --ok: #46b277;
  --ok-bg: #11281c;
  --info: #4d88c9;
  --info-bg: #14263a;
  --danger: #e2675c;
  --danger-bg: #2c1816;
  --warn: #d6a444;
  --warn-bg: #2a2310;
  --shadow: 0 1px 2px rgba(0,0,0,.35), 0 2px 6px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, system-ui, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
h1 { font-size: 20px; font-weight: 700; }
h2 { font-size: 15px; font-weight: 650; }
a, .link { color: var(--brand); cursor: pointer; }
code, .mono { font-family: var(--mono); font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.break { word-break: break-all; }
.grow { flex: 1; }

.ic { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; vertical-align: middle; }
.ic.sm { width: 15px; height: 15px; }

/* ----------------------------------------------------------- buttons */
.btn, button.btn {
  display: inline-flex; align-items: center; gap: 7px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 8px 13px;
  font: inherit; font-weight: 600; cursor: pointer;
  background: var(--panel); color: var(--text);
  transition: background .12s, border-color .12s, color .12s;
  white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-ink); border-color: var(--brand-ink); }
.btn.ghost { background: transparent; }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.block { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; font: inherit; font-weight: 600; text-decoration: none; display: inline-flex; align-items: center; gap: 5px; }
.link:hover { text-decoration: underline; }
.icon-btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 6px; width: 30px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); border-color: var(--line-strong); }
.icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); background: var(--danger-bg); }

/* ----------------------------------------------------------- logo */
.logo {
  width: 34px; height: 34px; border-radius: 8px; flex: none;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
}
.logo .ic { width: 20px; height: 20px; stroke: #fff; }

/* ----------------------------------------------------------- layout */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  padding: 16px 12px; display: flex; flex-direction: column; gap: 16px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px; }
.brand strong { display: block; line-height: 1.15; font-size: 15px; letter-spacing: -.01em; }
.brand small { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .08em; }
.menu { display: flex; flex-direction: column; gap: 2px; }
.menu button {
  display: flex; align-items: center; gap: 10px; text-align: left;
  border: 0; background: none; color: var(--muted);
  padding: 9px 11px; border-radius: 6px; font: inherit; font-weight: 600; cursor: pointer;
}
.menu button .ic { color: var(--faint); }
.menu button:hover { background: var(--panel-2); color: var(--text); }
.menu button.active { background: var(--brand-soft); color: var(--brand); }
.menu button.active .ic { color: var(--brand); }
.sidebar-foot { margin-top: auto; display: flex; flex-direction: column; gap: 9px; padding-top: 12px; border-top: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; overflow: hidden; }
.who span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); flex: none; }

.content { padding: 22px 26px 56px; min-width: 0; }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; padding-bottom: 16px; border-bottom: 1px solid var(--line); }
.topbar .muted { margin-top: 3px; font-size: 13px; }

/* ----------------------------------------------------------- rows/grids */
.row { display: flex; align-items: center; }
.row.gap { gap: 10px; }
.row.end { justify-content: flex-end; }
.row.between { justify-content: space-between; }
.end-base { align-items: flex-end; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }

/* ----------------------------------------------------------- panels */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }
.panel.no-pad { padding: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.empty { color: var(--muted); padding: 22px; text-align: center; font-size: 13px; }
.loading { color: var(--muted); padding: 40px; text-align: center; }

/* ----------------------------------------------------------- stat cards */
.stat-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 14px; margin-bottom: 16px; }
.stat-card { background: var(--panel); border: 1px solid var(--line); border-top: 3px solid var(--line-strong); border-radius: var(--radius); padding: 15px 16px; display: flex; flex-direction: column; gap: 3px; box-shadow: var(--shadow); }
.stat-card.ok { border-top-color: var(--ok); }
.stat-card.info { border-top-color: var(--brand); }
.stat-card.danger { border-top-color: var(--danger); }
.stat-card.muted { border-top-color: var(--faint); }
.stat-val { font-size: 26px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; }

.mini-list { display: flex; flex-direction: column; }
.mini-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 9px 2px; border-bottom: 1px solid var(--line); }
.mini-row:last-child { border-bottom: 0; }

/* ----------------------------------------------------------- toolbar */
.toolbar { display: flex; gap: 9px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar input[type="search"] { flex: 1; min-width: 220px; }

/* ----------------------------------------------------------- forms */
.form { display: grid; gap: 14px; }
label { display: grid; gap: 6px; color: var(--muted); font-weight: 600; font-size: 12px; }
input, select, textarea { width: 100%; border: 1px solid var(--line-strong); border-radius: 6px; padding: 9px 11px; color: var(--text); font: inherit; background: var(--panel); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { min-height: 90px; resize: vertical; }
textarea.mono { font-family: var(--mono); font-size: 13px; min-height: 120px; }
.check-inline { display: flex; flex-direction: row; align-items: center; gap: 9px; color: var(--text); font-weight: 600; }
.check-inline input { width: auto; }

/* ----------------------------------------------------------- tables */
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { padding: 11px 14px; text-align: left; vertical-align: middle; border-bottom: 1px solid var(--line); }
table.data thead th { color: var(--faint); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; background: var(--panel-2); }
table.data tbody tr:hover { background: var(--panel-2); }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tr.dim { opacity: .55; }
table.data code { background: var(--panel-2); padding: 2px 6px; border-radius: 4px; border: 1px solid var(--line); }
.actions { display: flex; gap: 6px; justify-content: flex-end; }
.msg { max-width: 460px; overflow-wrap: anywhere; }
.chips { display: flex; gap: 5px; flex-wrap: wrap; }
.chip { font-size: 10px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: 4px; padding: 2px 6px; color: var(--muted); white-space: nowrap; }
.chip.auto { color: var(--brand); border-color: var(--brand); background: var(--brand-soft); }

/* ----------------------------------------------------------- badges */
.badge { display: inline-block; font-size: 10.5px; font-weight: 700; padding: 3px 8px; border-radius: 4px; text-transform: uppercase; letter-spacing: .04em; border: 1px solid transparent; }
.badge.ok { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 22%, transparent); }
.badge.danger { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 22%, transparent); }
.badge.info { background: var(--info-bg); color: var(--info); border-color: color-mix(in srgb, var(--info) 22%, transparent); }
.badge.muted { background: var(--panel-2); color: var(--muted); border-color: var(--line-strong); }
.badge.type-app { background: var(--info-bg); color: var(--info); border-color: color-mix(in srgb, var(--info) 22%, transparent); }
.badge.type-driver { background: #efe9fb; color: #6b46c1; border-color: #d8caf3; }
.badge.type-script { background: var(--warn-bg); color: var(--warn); border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.badge.type-deployer { background: var(--ok-bg); color: var(--ok); border-color: color-mix(in srgb, var(--ok) 22%, transparent); }
body.dark .badge.type-driver { background: #211a33; color: #b69af0; border-color: #38305a; }

/* ----------------------------------------------------------- alerts */
.alert { border-radius: 6px; padding: 11px 14px; background: var(--info-bg); border: 1px solid color-mix(in srgb, var(--info) 25%, transparent); margin-bottom: 14px; font-size: 13.5px; }
.alert.danger { color: var(--danger); background: var(--danger-bg); border-color: color-mix(in srgb, var(--danger) 30%, transparent); }

/* ----------------------------------------------------------- modal */
.overlay { position: fixed; inset: 0; background: rgba(15,22,33,.46); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; animation: fade .14s ease; }
.modal { background: var(--panel); border: 1px solid var(--line-strong); border-radius: 10px; width: min(560px, 100%); max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 18px 50px rgba(15,22,33,.28); animation: pop .15s ease; }
.modal.wide { width: min(760px, 100%); }
.modal-head, .drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 15px 20px; border-bottom: 1px solid var(--line); }
.modal-body { padding: 20px; overflow: auto; }
.confirm p { margin: 0 0 18px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: translateY(6px); opacity: 0; } }

/* ----------------------------------------------------------- drawer */
.drawer-overlay { position: fixed; inset: 0; background: rgba(15,22,33,.4); z-index: 49; animation: fade .14s ease; }
.drawer { position: absolute; top: 0; right: 0; height: 100%; width: min(520px, 100%); background: var(--panel); border-left: 1px solid var(--line-strong); box-shadow: -12px 0 40px rgba(15,22,33,.18); display: flex; flex-direction: column; transform: translateX(100%); transition: transform .2s ease; }
.drawer.open { transform: translateX(0); }
.drawer-body { padding: 20px; overflow: auto; display: flex; flex-direction: column; gap: 16px; }
.detail-head h3 { font-size: 17px; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; margin: 0; }
.kv dt { color: var(--muted); font-weight: 600; }
.kv dd { margin: 0; }
.kv-block { display: flex; flex-direction: column; gap: 6px; }
.kv-block p { margin: 0; white-space: pre-wrap; }
.sha { margin-top: 6px; }
pre.code { background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px; padding: 12px; overflow: auto; margin: 0; max-height: 320px; font-family: var(--mono); font-size: 12.5px; }
pre.code code { white-space: pre; background: none; border: 0; padding: 0; }

/* ----------------------------------------------------------- token modal */
.token-row, .file-row { display: flex; gap: 10px; align-items: center; }
.token-row code { flex: 1; background: var(--panel-2); border: 1px solid var(--line-strong); border-radius: 6px; padding: 10px 12px; font-family: var(--mono); }
.token-modal { display: flex; flex-direction: column; gap: 12px; }

/* ----------------------------------------------------------- toasts */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 100; }
.toast { display: flex; align-items: center; gap: 9px; background: var(--text); color: var(--panel); padding: 11px 15px; border-radius: 7px; box-shadow: var(--shadow); opacity: 0; transform: translateY(10px); transition: opacity .18s, transform .18s; max-width: 360px; font-weight: 600; font-size: 13.5px; border-left: 3px solid transparent; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.danger { background: var(--danger); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }

/* ----------------------------------------------------------- auth pages */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.auth-card { background: var(--panel); border: 1px solid var(--line-strong); border-radius: 10px; padding: 30px; width: min(400px, 100%); box-shadow: var(--shadow); }
.auth-card .brand { margin-bottom: 20px; padding: 0; }
.auth-card h1 { font-size: 19px; margin-bottom: 4px; }
.auth-card form { display: grid; gap: 14px; margin-top: 18px; }
.auth-card button { width: 100%; border: 1px solid var(--brand); border-radius: 6px; padding: 11px; background: var(--brand); color: #fff; font: inherit; font-weight: 700; cursor: pointer; }
.auth-card button:hover { background: var(--brand-ink); }

/* ----------------------------------------------------------- responsive */
@media (max-width: 920px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .sidebar .menu { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { margin: 0 0 0 auto; flex-direction: row; align-items: center; border: 0; padding: 0; }
  .sidebar-foot form { margin: 0; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
