:root {
  --bg: #0b0f17;
  --surface: #121826;
  --surface-2: #182133;
  --border: #253047;
  --text: #e6edf7;
  --muted: #8b9bb4;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --ok: #22c55e;
  --warn: #f59e0b;
  --danger: #ef4444;
  --radius: 10px;
  --font: Inter, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; margin: 2px 0 0; }
.error-text { color: var(--danger); margin-top: 10px; font-size: 13px; }

/* Login */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top, #172554 0%, var(--bg) 55%);
  padding: 20px;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}
.login-card h1 { margin: 0; font-size: 20px; }
.login-card p { margin: 2px 0 0; font-size: 13px; }
.login-card form { margin-top: 22px; display: flex; flex-direction: column; gap: 14px; }

.brand-row { display: flex; align-items: center; gap: 12px; }
.brand-row.compact { padding: 4px 2px 18px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.brand-mark {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #06b6d4);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 14px; letter-spacing: 0.5px; color: #fff;
}
.brand-title { font-weight: 700; font-size: 15px; }
.brand-sub { font-size: 12px; color: var(--muted); }

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 245px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  background: transparent;
  border: none;
  color: var(--muted);
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: rgba(59, 130, 246, 0.18); color: #93c5fd; font-weight: 600; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.user-pill { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text); overflow: hidden; text-overflow: ellipsis; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.dot.ok { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.err { background: var(--danger); }

.main { flex: 1; padding: 24px 28px; max-width: 1440px; width: 100%; overflow-x: auto; }
.topbar { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 22px; gap: 16px; }
.topbar h2 { margin: 0; font-size: 22px; }
.topbar p { margin: 3px 0 0; font-size: 13px; }

/* Cards & Grids */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.kpi-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }
.kpi-value { font-size: 24px; font-weight: 700; margin: 6px 0 4px; }
.kpi-sub { font-size: 12px; color: var(--muted); }

.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(400px, 1fr)); gap: 16px; margin-bottom: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 15.5px; }

/* Tables */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}
.data-table td { padding: 10px; border-bottom: 1px solid rgba(37, 48, 71, 0.55); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }

.services-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 8px; }
.svc-pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12.5px;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}
.badge.ok { background: rgba(34, 197, 94, 0.16); color: #4ade80; }
.badge.warn { background: rgba(245, 158, 11, 0.16); color: #fbbf24; }
.badge.err { background: rgba(239, 68, 68, 0.18); color: #f87171; }
.badge.info { background: rgba(59, 130, 246, 0.18); color: #93c5fd; }

/* Inputs & Buttons */
label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); }
input, textarea, select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 7px;
  padding: 8px 10px;
  font-family: var(--font);
  font-size: 13px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.code-area { font-family: var(--mono); font-size: 12px; width: 100%; resize: vertical; }

.btn {
  border: none;
  border-radius: 7px;
  padding: 8px 14px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  transition: opacity 0.15s, background 0.15s;
}
.btn.primary { background: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn.secondary:hover { background: #22304a; }
.btn.danger { background: rgba(239, 68, 68, 0.18); color: #f87171; border: 1px solid rgba(239, 68, 68, 0.35); }
.btn.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.full { width: 100%; padding: 10px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 12px;
}
.form-actions { grid-column: 1 / -1; margin-top: 6px; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.inline-form input[type="text"], .inline-form input[type="number"], .inline-form input[type="password"] { flex: 1; min-width: 140px; }
.inline-field { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.checkbox-inline { flex-direction: row; align-items: center; gap: 6px; color: var(--text); }
.stack-form { display: flex; flex-direction: column; gap: 10px; }
.sep { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

.code-box {
  margin-top: 16px;
  background: #090d14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
}
.code-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 10px; }
pre, .json-pre {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre-wrap;
  word-break: break-all;
  background: #090d14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: #cbd5e1;
}
.code-box pre { border: none; padding: 0; }
.mono { font-family: var(--mono); font-size: 12px; }

.simple-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.simple-list li {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--surface-2); padding: 7px 10px; border-radius: 7px;
}
.audit-list { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; }
.audit-row {
  background: var(--surface-2);
  border-radius: 7px;
  padding: 7px 10px;
  font-size: 12px;
}
.audit-row .meta { color: var(--muted); font-family: var(--mono); font-size: 11px; }

#toast-container {
  position: fixed; right: 20px; bottom: 20px;
  display: flex; flex-direction: column; gap: 8px; z-index: 9999;
}
.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.4);
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
