/* Design tokens, reset, and shared primitives. */

:root {
  color-scheme: dark;

  --bg: #0b0d11;
  --bg-raised: #12151b;
  --bg-panel: #161a21;
  --bg-subtle: #1b2028;
  --bg-input: #0f1217;
  --bg-hover: #212734;
  --bg-active: #2a3140;

  --line: #232935;
  --line-strong: #303845;

  --text: #e9edf3;
  --text-dim: #a7b0bd;
  --text-muted: #8b95a3;
  --text-faint: #6a7482;

  --accent: #19bfa5;
  --accent-strong: #38d9bd;
  --accent-ink: #04211d;
  --accent-soft: rgba(25, 191, 165, .13);
  --accent-line: rgba(25, 191, 165, .42);
  --accent-glow: rgba(25, 191, 165, .3);

  --ok: #46b374;
  --ok-soft: rgba(70, 179, 116, .14);
  --warn: #d9a337;
  --warn-soft: rgba(217, 163, 55, .14);
  --danger: #e2645d;
  --danger-soft: rgba(226, 100, 93, .13);
  --danger-line: rgba(226, 100, 93, .42);
  --info: #5c9ddb;
  --info-soft: rgba(92, 157, 219, .14);
  --violet: #8d80e6;
  --violet-soft: rgba(141, 128, 230, .14);

  --radius: 8px;
  --radius-sm: 7px;
  --radius-xs: 5px;
  --shadow: 0 24px 56px rgba(0, 0, 0, .55);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --ring: 0 0 0 3px rgba(25, 191, 165, .26);

  --mono: ui-monospace, "SFMono-Regular", "Cascadia Mono", Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", sans-serif;

  --sidebar-w: 246px;
  --topbar-h: 62px;
}

:root[data-theme="light"] {
  color-scheme: light;

  --bg: #eef1f6;
  --bg-raised: #f7f9fc;
  --bg-panel: #ffffff;
  --bg-subtle: #f3f6fa;
  --bg-input: #ffffff;
  --bg-hover: #e8edf4;
  --bg-active: #dbe3ed;

  --line: #e2e7ef;
  --line-strong: #c9d2de;

  --text: #131b25;
  --text-dim: #4a5563;
  --text-muted: #646f7d;
  --text-faint: #85909d;

  --accent: #0d9184;
  --accent-strong: #0a7b70;
  --accent-ink: #ffffff;
  --accent-soft: rgba(13, 145, 132, .1);
  --accent-line: rgba(13, 145, 132, .34);
  --accent-glow: rgba(13, 145, 132, .2);

  --ok: #1f855a;
  --ok-soft: rgba(31, 133, 90, .1);
  --warn: #9d6d16;
  --warn-soft: rgba(157, 109, 22, .1);
  --danger: #c3423d;
  --danger-soft: rgba(195, 66, 61, .09);
  --danger-line: rgba(195, 66, 61, .34);
  --info: #2b6cab;
  --info-soft: rgba(43, 108, 171, .1);
  --violet: #6455cd;
  --violet-soft: rgba(100, 85, 205, .1);

  --shadow: 0 24px 54px rgba(20, 35, 54, .18);
  --shadow-sm: 0 1px 2px rgba(20, 35, 54, .07);
  --ring: 0 0 0 3px rgba(13, 145, 132, .2);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
html { background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--sans);
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, select, textarea { letter-spacing: 0; }
h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: 0; }
h1 { font-size: 18px; line-height: 1.35; }
h2 { font-size: 15px; line-height: 1.4; }
h3 { font-size: 13px; line-height: 1.4; }
p { margin: 0; }
a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }
code, pre, .mono { font-family: var(--mono); font-size: 12.5px; }

.muted { color: var(--text-dim); font-size: 13px; }
.faint { color: var(--text-faint); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.grow { flex: 1 1 auto; min-width: 0; }
.row { display: flex; align-items: center; gap: 8px; }
.row-wrap { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: 8px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 34px;
  padding: 0 12px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  font: inherit;
  font-size: 13px;
  font-weight: 520;
  cursor: pointer;
  white-space: nowrap;
  transition: background .14s ease, border-color .14s ease, color .14s ease, transform .12s ease, box-shadow .14s ease;
}
.btn:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--text-faint); }
.btn:active:not(:disabled) { transform: translateY(1px); background: var(--bg-active); }
.btn:disabled { opacity: .48; cursor: not-allowed; box-shadow: none; }
.btn:focus-visible, .btn-icon:focus-visible { outline: none; box-shadow: var(--ring); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
  font-weight: 650;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .2), 0 6px 16px -10px var(--accent-glow);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-danger { color: var(--danger); border-color: var(--danger-line); background: var(--danger-soft); box-shadow: none; }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text-dim); box-shadow: none; }
.btn-ghost:hover:not(:disabled) { color: var(--text); background: var(--bg-hover); border-color: var(--line-strong); }
.btn-sm { height: 28px; padding: 0 9px; font-size: 12px; }
.btn-block { width: 100%; }

.btn-icon {
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .14s ease, border-color .14s ease, color .14s ease, transform .12s ease, box-shadow .14s ease;
}
.btn-icon:hover { background: var(--bg-hover); color: var(--text); border-color: var(--line); }
.btn-icon:active { transform: translateY(1px); }
.btn-icon svg { width: 16px; height: 16px; }

.icon {
  width: 16px;
  height: 16px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-sm { width: 14px; height: 14px; }

/* ---------- form controls ---------- */

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > span { font-size: 12px; color: var(--text-dim); font-weight: 540; }
.field-hint { font-size: 11.5px; color: var(--text-faint); line-height: 1.45; }

input[type="text"], input[type="password"], input[type="number"],
input[type="url"], input:not([type]), select, textarea {
  width: 100%;
  min-height: 34px;
  padding: 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .02);
  font: inherit;
  font-size: 13px;
  transition: border-color .14s ease, box-shadow .14s ease, background .14s ease;
}
textarea { min-height: 84px; resize: vertical; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; }
input:hover, select:hover, textarea:hover { border-color: var(--text-faint); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); box-shadow: var(--ring); }
input::placeholder, textarea::placeholder { color: var(--text-faint); opacity: .8; }
select {
  appearance: none;
  padding-right: 32px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--text-faint) 50%),
    linear-gradient(135deg, var(--text-faint) 50%, transparent 50%);
  background-position: calc(100% - 14px) 14px, calc(100% - 10px) 14px;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
select option { background: var(--bg-panel); color: var(--text); }
input[type="checkbox"] { accent-color: var(--accent); }

.switch { position: relative; display: inline-flex; align-items: center; gap: 9px; cursor: pointer; font-size: 13px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  width: 36px;
  height: 20px;
  flex: none;
  border-radius: 999px;
  background: var(--bg-active);
  border: 1px solid var(--line-strong);
  transition: background .16s ease, border-color .16s ease, box-shadow .16s ease;
  position: relative;
}
.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--text-muted);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .28);
  transition: transform .16s ease, background .16s ease;
}
.switch input:checked + .switch-track { background: var(--accent-soft); border-color: var(--accent); }
.switch input:checked + .switch-track::after { transform: translateX(16px); background: var(--accent-strong); }
.switch input:focus-visible + .switch-track { box-shadow: var(--ring); }

.seg { display: inline-flex; gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: var(--radius-sm); background: var(--bg-subtle); }
.seg button {
  height: 28px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-xs);
  background: transparent;
  color: var(--text-dim);
  font: inherit;
  font-size: 12.5px;
  cursor: pointer;
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--bg-panel); color: var(--text); box-shadow: var(--shadow-sm); }

.form-error {
  padding: 8px 10px;
  border: 1px solid var(--danger-line);
  border-radius: var(--radius-sm);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12.5px;
}

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

.table-wrap { overflow: auto; scrollbar-gutter: stable; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th {
  position: sticky;
  top: 0;
  z-index: 1;
  padding: 9px 12px;
  text-align: left;
  font-size: 11px;
  font-weight: 650;
  text-transform: uppercase;
  color: var(--text-faint);
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.grid tbody tr { transition: background .12s ease; }
table.grid tbody tr:hover { background: var(--bg-subtle); }
table.grid tbody tr:last-child td { border-bottom: 0; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }

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

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 22px;
  max-width: 100%;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--bg-hover);
  border: 1px solid var(--line);
  color: var(--text-dim);
  font-size: 11.5px;
  line-height: 1.35;
  white-space: nowrap;
}
.tag-accent { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-strong); }

.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--text-faint); }
.dot-ok { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot-warn { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot-bad { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }
.dot-idle { background: var(--text-faint); box-shadow: 0 0 0 3px var(--bg-active); }
.status { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; }

.empty { padding: 44px 20px; text-align: center; color: var(--text-faint); font-size: 13px; }
.empty strong { display: block; margin-bottom: 5px; color: var(--text-dim); font-size: 14px; }

.spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid var(--line-strong);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.bar { height: 5px; border-radius: 999px; background: var(--bg-hover); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: inherit; background: var(--accent); }

::selection { background: var(--accent-soft); color: var(--text); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--line-strong);
  border: 3px solid transparent;
  border-radius: 999px;
  background-clip: content-box;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); background-clip: content-box; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
