:root {
  --bg: #0e1116;
  --bg-soft: #151a21;
  --panel: #1a2029;
  --panel-2: #212934;
  --line: #2b3543;
  --text: #e6edf5;
  --muted: #93a1b3;
  --accent: #4ea1ff;
  --accent-soft: rgba(78, 161, 255, 0.14);
  --ok: #3ddc97;
  --warn: #ffb454;
  --err: #ff6b6b;
  --radius: 12px;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --mono: "JetBrains Mono", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

/* ---------------------------------------------------------------- layout */
.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  padding: 18px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 16px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, #4ea1ff, #7b5cff);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 15px;
  color: #fff;
}

.brand-title { font-weight: 650; letter-spacing: .2px; }
.brand-sub { font-size: 11.5px; color: var(--muted); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-group { margin: 14px 8px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .9px; color: var(--muted); }
.nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 9px;
  color: var(--text);
  font-size: 14px;
  text-decoration: none;
}
.nav a:hover { background: var(--panel); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: #cfe4ff; }
.nav .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.nav a.active .dot { background: var(--accent); }

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(14, 17, 22, .86);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar h1 { font-size: 18px; margin: 0; font-weight: 620; }
.topbar .spacer { flex: 1; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--panel);
  font-size: 12px;
  color: var(--muted);
}
.badge.ok { color: var(--ok); border-color: rgba(61, 220, 151, .35); }
.badge.warn { color: var(--warn); border-color: rgba(255, 180, 84, .35); }
.badge.err { color: var(--err); border-color: rgba(255, 107, 107, .35); }

.content { padding: 22px 24px 60px; max-width: 1500px; width: 100%; }

/* ---------------------------------------------------------------- pieces */
.grid { display: grid; gap: 14px; }
.grid.c2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.c3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.c4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card h3 { margin: 0 0 4px; font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .7px; }
.card .big { font-size: 26px; font-weight: 650; letter-spacing: -.4px; }
.card .sub { color: var(--muted); font-size: 12.5px; margin-top: 4px; }

.section { margin-bottom: 26px; }
.section-head { display: flex; align-items: baseline; gap: 12px; margin: 0 0 12px; }
.section-head h2 { font-size: 16px; margin: 0; font-weight: 620; }
.section-head .hint { color: var(--muted); font-size: 12.5px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 550; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--panel-2); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }

.state { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; }
.state i { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); display: inline-block; }
.state.active i { background: var(--ok); box-shadow: 0 0 8px rgba(61, 220, 151, .55); }
.state.failed i { background: var(--err); }
.state.inactive i { background: #6b7a8f; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  cursor: pointer;
  font-size: 13.5px;
  transition: border-color .15s, background .15s;
}
.btn:hover { border-color: #3b4a5e; background: #263040; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #06111f; font-weight: 600; }
.btn.primary:hover { background: #66b0ff; }
.btn.danger { color: #ffd7d7; border-color: rgba(255, 107, 107, .45); background: rgba(255, 107, 107, .12); }
.btn.small { padding: 4px 9px; font-size: 12.5px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

input[type="text"], input[type="password"], input[type="number"], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: #10151c;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 110px; resize: vertical; font-family: var(--mono); font-size: 12.5px; }
label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 5px; }
label.field .help { font-size: 11.5px; color: #6f7f93; margin-top: 4px; }
.switch { display: flex; align-items: center; gap: 10px; }
.switch input { width: auto; }

pre, .mono {
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
  background: #0c1117;
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 12px 14px;
  overflow: auto;
  max-height: 420px;
  white-space: pre-wrap;
  word-break: break-word;
}

.kv { display: grid; grid-template-columns: minmax(140px, 220px) 1fr; gap: 6px 16px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.pill { display: inline-block; padding: 1px 8px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); font-size: 11.5px; color: var(--muted); }
.pill.ok { color: var(--ok); border-color: rgba(61, 220, 151, .3); }
.pill.err { color: var(--err); border-color: rgba(255, 107, 107, .3); }
.pill.warn { color: var(--warn); border-color: rgba(255, 180, 84, .3); }

.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 12px; }

.diag { display: flex; flex-direction: column; gap: 8px; }
.diag-item {
  display: grid;
  grid-template-columns: 10px 1fr auto;
  gap: 12px;
  align-items: start;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel-2);
}
.diag-item .bar { width: 10px; height: 100%; border-radius: 6px; background: var(--muted); }
.diag-item.error .bar { background: var(--err); }
.diag-item.warning .bar { background: var(--warn); }
.diag-item.info .bar { background: var(--accent); }
.diag-item b { font-weight: 600; }
.diag-item .detail { color: var(--muted); font-size: 12.5px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs button {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 9px 14px;
  color: var(--muted);
  cursor: pointer;
  font-size: 13.5px;
}
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

/* ---------------------------------------------------------------- drawer */
.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 7, 11, .62);
  z-index: 40;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(760px, 96vw);
  height: 100vh;
  background: var(--bg-soft);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  z-index: 41;
  display: flex;
  flex-direction: column;
}
.drawer-head { padding: 16px 20px; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 12px; }
.drawer-head h2 { margin: 0; font-size: 16px; }
.drawer-body { padding: 18px 20px 40px; overflow-y: auto; }

/* ---------------------------------------------------------------- login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card {
  width: min(400px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 20px; }
.login-card p { color: var(--muted); margin: 0 0 20px; font-size: 13.5px; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 420px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: 10px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  z-index: 60;
  font-size: 13.5px;
}
.toast.err { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }

.empty { color: var(--muted); padding: 18px; text-align: center; font-size: 13.5px; }
.spinner { width: 16px; height: 16px; border: 2px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }

.hamburger { display: none; }

/* ---------------------------------------------------------------- responsive */
@media (max-width: 1100px) {
  .grid.c4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.c3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 260px;
    transform: translateX(-105%);
    transition: transform .2s ease;
    z-index: 50;
  }
  .sidebar.open { transform: translateX(0); }
  .hamburger { display: inline-flex; }
  .content { padding: 16px 14px 50px; }
  .topbar { padding: 12px 14px; }
  .grid.c2, .grid.c3, .grid.c4 { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; }
  .kv dt { margin-top: 8px; }
  .drawer { width: 100vw; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
