:root {
  color-scheme: dark;
  --background: #0a0a0a;
  --foreground: #fafafa;
  --card: #171717;
  --card-hover: #1f1f1f;
  --muted: #a1a1a1;
  --border: rgba(255, 255, 255, 0.1);
  --input: rgba(255, 255, 255, 0.06);
  --ring: #525252;
  --primary: #3b82f6;
  --primary-soft: rgba(59, 130, 246, 0.14);
  --green: #34d399;
  --green-soft: rgba(52, 211, 153, 0.12);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.12);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.12);
  --purple: #c084fc;
  --radius: 10px;
  --sidebar: #111111;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--background);
  color: var(--foreground);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.boot {
  display: grid;
  place-items: center;
  height: 100vh;
  color: var(--muted);
}

a { color: var(--primary); text-decoration: none; }

/* ---- layout ------------------------------------------------------------ */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 224px;
  flex: 0 0 224px;
  background: var(--sidebar);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 18px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), var(--purple));
  display: grid; place-items: center; font-size: 15px;
}
.brand-title { font-weight: 650; letter-spacing: -0.01em; }
.brand-sub { color: var(--muted); font-size: 11px; }

.nav-list { display: flex; flex-direction: column; gap: 6px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px; color: var(--muted);
  cursor: pointer; border: none; background: none; width: 100%;
  text-align: left; font: inherit; font-size: 13.5px;
  user-select: none;
}
.nav-item:hover { background: var(--card); color: var(--foreground); }
.nav-item.active { background: var(--primary-soft); color: #dbeafe; }
.nav-item .icon { width: 18px; text-align: center; opacity: .9; }
.nav-item .nav-label { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-move { display: none; align-items: center; gap: 1px; margin-left: auto; }
.nav-item:hover .nav-move, .nav-item:focus-within .nav-move { display: flex; }
.nav-move button {
  border: 0; background: transparent; color: var(--muted);
  cursor: pointer; padding: 2px 3px; font-size: 9px; line-height: 1;
  border-radius: 4px;
}
.nav-move button:hover:not(:disabled) { background: var(--card-hover); color: var(--foreground); }
.nav-move button:disabled { opacity: .25; cursor: default; }
@media (hover: none) {
  .nav-item .nav-move { display: flex; }
}

.sidebar-foot { margin-top: auto; padding: 10px; color: var(--muted); font-size: 11.5px; display: flex; flex-direction: column; gap: 6px; }

.main { flex: 1; min-width: 0; padding: 26px 30px 60px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.page-title { font-size: 20px; font-weight: 650; letter-spacing: -0.02em; margin: 0; }
.page-sub { color: var(--muted); font-size: 12.5px; margin-top: 3px; }

/* ---- cards ------------------------------------------------------------- */
.grid { display: grid; gap: 14px; }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.cols-6 { grid-template-columns: repeat(6, minmax(0, 1fr)); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.card-title { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.card-value { font-size: 26px; font-weight: 650; letter-spacing: -0.02em; margin-top: 6px; }
.card-hint { color: var(--muted); font-size: 11.5px; margin-top: 4px; }
.card-value.accent { color: var(--primary); }
.card-value.green { color: var(--green); }
.card-value.amber { color: var(--amber); }
.card-value.red { color: var(--red); }

.section { margin-top: 22px; }
.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.section-title { font-size: 14px; font-weight: 600; }

/* ---- tables ------------------------------------------------------------ */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; background: var(--card); }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-weight: 500; font-size: 11.5px; text-transform: uppercase; letter-spacing: .04em; background: rgba(255,255,255,.02); }
tbody tr:hover { background: var(--card-hover); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }

/* ---- badges ------------------------------------------------------------ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 500;
  border: 1px solid transparent;
}
.badge.green { background: var(--green-soft); color: var(--green); border-color: rgba(52,211,153,.25); }
.badge.amber { background: var(--amber-soft); color: var(--amber); border-color: rgba(251,191,36,.25); }
.badge.red { background: var(--red-soft); color: var(--red); border-color: rgba(248,113,113,.25); }
.badge.blue { background: var(--primary-soft); color: #93c5fd; border-color: rgba(59,130,246,.3); }
.badge.gray { background: rgba(255,255,255,.06); color: var(--muted); border-color: var(--border); }

/* ---- forms ------------------------------------------------------------- */
.input, .select {
  background: var(--input);
  border: 1px solid var(--border);
  color: var(--foreground);
  border-radius: 8px;
  padding: 8px 10px;
  font: inherit;
  font-size: 13px;
  outline: none;
}
.input:focus, .select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(59,130,246,.18); }
.select option { background: var(--card); color: var(--foreground); }
.select { color-scheme: dark; }
th.sortable { cursor: pointer; user-select: none; }
th.sortable:hover { color: var(--foreground); }
.input.sm { padding: 5px 8px; font-size: 12.5px; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 12px; }
.toolbar .spacer { flex: 1; }
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  color: var(--foreground);
  padding: 7px 12px; border-radius: 8px; font: inherit; font-size: 13px;
  cursor: pointer;
}
.btn:hover { background: rgba(255,255,255,.1); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--red); border-color: rgba(248,113,113,.35); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 4px 9px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: default; }

/* ---- login ------------------------------------------------------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 360px; background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 26px; }
.login-card h1 { margin: 0 0 4px; font-size: 18px; }
.login-card p { margin: 0 0 18px; color: var(--muted); font-size: 12.5px; }
.login-card .field { margin-bottom: 12px; }
.login-card .btn { width: 100%; justify-content: center; margin-top: 6px; }
.error { color: var(--red); font-size: 12.5px; min-height: 18px; margin-top: 8px; }

/* ---- dialog ------------------------------------------------------------ */
.overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: grid; place-items: center; padding: 20px; z-index: 50;
}
.dialog {
  width: min(760px, 100%);
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}
.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  position: sticky;
  top: -20px;
  margin: -20px -20px 10px;
  padding: 20px 20px 10px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  z-index: 5;
}
.dialog-head h3 { margin: 0 0 2px; font-size: 16px; }
.dialog-head .hint { margin-bottom: 0; }
.dialog h3 { margin: 0 0 4px; font-size: 16px; }
.dialog .hint { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
.dialog textarea {
  width: 100%; min-height: 220px; resize: vertical;
  background: var(--input); color: var(--foreground);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px;
  font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace; outline: none;
}
.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 14px;
  padding-top: 12px;
  padding-bottom: 2px;
  position: sticky;
  bottom: 0;
  background: var(--card);
  border-top: 1px solid var(--border);
}

/* ---- toast ------------------------------------------------------------- */
.toast {
  position: fixed; right: 18px; bottom: 18px; z-index: 60;
  background: var(--card); border: 1px solid var(--border);
  padding: 10px 14px; border-radius: 10px; font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast.error { border-color: rgba(248,113,113,.4); color: var(--red); }

.empty { padding: 28px; text-align: center; color: var(--muted); font-size: 13px; }

.account-link {
  color: var(--primary);
  cursor: pointer;
  text-decoration: underline dotted;
  text-underline-offset: 3px;
}
.account-link:hover { text-decoration: underline; }
.stat-flag { margin-left: 6px; font-size: 12px; cursor: pointer; opacity: .85; }
.stat-flag:hover { opacity: 1; }
.stat-flag.missing { opacity: .55; }

.stats-cols {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
}
.kv { width: 100%; border-collapse: collapse; }
.kv td {
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  vertical-align: top;
  white-space: normal;
}
.kv td:first-child { color: var(--muted); width: 48%; }
.kv tr:last-child td { border-bottom: 0; }

@media (max-width: 760px) {
  .stats-cols { grid-template-columns: 1fr; }
}

/* ---- console ----------------------------------------------------------- */
.console-check { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12.5px; }
.console-meta {
  color: var(--muted); font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace;
  margin: 0 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.console {
  margin: 0; padding: 14px; border: 1px solid var(--border); border-radius: var(--radius);
  background: #0b0b0b; color: #d4d4d4; height: calc(100vh - 190px); min-height: 320px;
  overflow: auto; font: 12px/1.55 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap; word-break: break-word;
}

@media (max-width: 1100px) {
  .grid.cols-6 { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
@media (max-width: 820px) {
  .sidebar { display: none; }
  .main { padding: 18px; }
  .grid.cols-3, .grid.cols-4, .grid.cols-6 { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

/* ---- stacked status bars ---------------------------------------------- */
.bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: rgba(255,255,255,.06); }
.bar.thin { height: 9px; }
.seg { height: 100%; min-width: 2px; }
.legend { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; font-size: 12px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 6px; }
.legend-item i { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.legend-item b { color: var(--foreground); font-weight: 600; }
.wrow { display: flex; align-items: center; gap: 12px; margin: 8px 0; }
.wlabel { width: 72px; color: var(--muted); font-size: 12px; }
.wval { width: 72px; text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; }
.wrow .bar { flex: 1; }

/* ---- graphics ---------------------------------------------------------- */
.graphics-tabs {
  display: inline-flex; gap: 4px; padding: 4px; margin-bottom: 12px;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
}
.graphics-tab {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 12.5px; font-weight: 550; padding: 6px 16px;
  border-radius: 7px; cursor: pointer;
}
.graphics-tab:hover { color: var(--foreground); background: rgba(255,255,255,.05); }
.graphics-tab.active { background: var(--primary-soft); color: #dbeafe; }
.graphics-frame {
  position: relative; height: calc(100vh - 210px); min-height: 520px;
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; background: #111217;
}
.graphics-frame iframe { display: block; width: 100%; height: 100%; border: 0; background: #111217; }
.graphics-setup {
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--card); padding: 20px;
}
.graphics-setup h3 { margin: 0 0 8px; font-size: 15px; }
.graphics-setup p { margin: 0 0 10px; color: var(--muted); font-size: 12.5px; }
.graphics-setup pre {
  margin: 0; padding: 12px; border: 1px solid var(--border); border-radius: 8px;
  background: #0b0b0b; color: #d4d4d4;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace;
  overflow: auto;
}
@media (max-width: 820px) {
  .graphics-frame { height: calc(100vh - 230px); min-height: 420px; }
}
