:root {
  --bg: #0b0f17;
  --bg-elev: #121826;
  --bg-card: #161e2e;
  --bg-hover: #1d273b;
  --border: #253147;
  --text: #e6edf7;
  --muted: #93a4bd;
  --primary: #4f8cff;
  --primary-hover: #3b78eb;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

code, pre { font-family: var(--mono); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small-text { font-size: 12px; }
.mt-sm { margin-top: 12px; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, #17233b 0%, var(--bg) 60%);
}
.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.45);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 22px;
}
.login-brand h1 { margin: 0; font-size: 19px; }
.login-brand p { margin: 2px 0 0; font-size: 12px; }
.login-hint { margin: 16px 0 0; font-size: 12px; text-align: center; }

.brand-badge {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(79, 140, 255, 0.14);
  border: 1px solid rgba(79, 140, 255, 0.35);
  color: var(--primary);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.brand-badge svg { width: 22px; height: 22px; }
.brand-badge.small { width: 36px; height: 36px; border-radius: 10px; }
.brand-badge.small svg { width: 18px; height: 18px; }

/* Layout */
.app-shell {
  display: flex;
  min-height: 100vh;
}
.sidebar {
  width: 245px;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 16px;
  border-bottom: 1px solid var(--border);
}
.brand-text { display: flex; flex-direction: column; overflow: hidden; }
.brand-text strong { font-size: 15px; }
.brand-text span { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px 0;
  flex: 1;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s, color 0.15s;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active {
  background: rgba(79, 140, 255, 0.16);
  color: #fff;
  border: 1px solid rgba(79, 140, 255, 0.35);
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.user-pill { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; background: var(--muted); }
.dot.online { background: var(--success); box-shadow: 0 0 8px rgba(34, 197, 94, 0.7); }

.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: rgba(11, 15, 23, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 12px 22px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-left h2 { margin: 0; font-size: 17px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.content {
  padding: 20px 22px 40px;
  max-width: 1440px;
  width: 100%;
  margin: 0 auto;
}
.tab-panel { display: none; flex-direction: column; gap: 16px; }
.tab-panel.active { display: flex; }

/* Cards & Grids */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.card-head.wrap { flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 15px; }
.card-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}
.kpi-grid.compact { gap: 10px; }
.kpi-card { display: flex; flex-direction: column; gap: 8px; }
.kpi-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.kpi-value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.kpi-sub { font-size: 12px; }

.mini-stat {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.mini-stat strong { font-size: 16px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.compact-gap { gap: 10px; }

/* Progress & Badges */
.progress-bar {
  height: 7px;
  background: #0f1522;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--border);
}
.progress-bar.tall { height: 10px; margin-top: 12px; }
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.progress-fill.warn { background: var(--warning); }
.progress-fill.danger { background: var(--danger); }
.progress-fill.ok { background: var(--success); }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge-ok { background: rgba(34, 197, 94, 0.15); color: #6ee79a; border-color: rgba(34, 197, 94, 0.3); }
.badge-warn { background: rgba(245, 158, 11, 0.15); color: #fcd34d; border-color: rgba(245, 158, 11, 0.3); }
.badge-danger { background: rgba(239, 68, 68, 0.15); color: #fca5a5; border-color: rgba(239, 68, 68, 0.3); }
.badge-neutral { background: rgba(147, 164, 189, 0.12); color: var(--muted); border-color: var(--border); }

/* Key-Value & Provider Mini */
.kv-list { display: flex; flex-direction: column; gap: 8px; }
.kv-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(37, 49, 71, 0.6);
  font-size: 13px;
}
.kv-row:last-child { border-bottom: 0; }
.kv-row span { color: var(--muted); }
.kv-row strong, .kv-row code { text-align: right; word-break: break-word; }

.provider-mini-list { display: flex; flex-direction: column; gap: 10px; }
.provider-mini-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
}

.provider-card { display: flex; flex-direction: column; gap: 10px; }
.quota-box {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.quota-row { display: flex; flex-direction: column; gap: 4px; font-size: 12px; }
.quota-label { display: flex; justify-content: space-between; }

/* Buttons & Forms */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: #fff;
  background: var(--bg-hover);
  transition: background 0.15s, opacity 0.15s;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 11.5px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-secondary { background: #222e46; border-color: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #2b3a57; }
.btn-success { background: #16a34a; }
.btn-success:hover:not(:disabled) { background: #15803d; }
.btn-warning { background: #d97706; }
.btn-warning:hover:not(:disabled) { background: #b45309; }
.btn-danger { background: #dc2626; }
.btn-danger:hover:not(:disabled) { background: #b91c1c; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); }
.btn-icon { padding: 6px; }
.btn-icon svg { width: 18px; height: 18px; }
.btn-group { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.form-stack { display: flex; flex-direction: column; gap: 12px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); }
input, select, textarea {
  width: 100%;
  background: #0e1420;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-family: inherit;
  font-size: 13px;
}
textarea { font-family: var(--mono); font-size: 12px; resize: vertical; }
.input-sm { padding: 5px 9px; font-size: 12.5px; width: auto; min-width: 150px; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.alert-error {
  padding: 8px 10px;
  border-radius: 8px;
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  font-size: 12.5px;
}

/* Tables & Logs */
.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid rgba(37, 49, 71, 0.7);
  vertical-align: middle;
}
.data-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.data-table tbody tr:hover { background: rgba(255, 255, 255, 0.025); }
.cmd-cell { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--mono); font-size: 11.5px; color: var(--muted); }

.log-viewer {
  background: #080b11;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 12px;
  line-height: 1.5;
  color: #cbd5e1;
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
}

/* Charts */
.chart-box { min-height: 190px; width: 100%; }
.chart-box svg { width: 100%; height: 190px; display: block; }
.legend { display: flex; gap: 12px; font-size: 12px; color: var(--muted); }
.legend-item { display: inline-flex; align-items: center; gap: 5px; }
.swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.swatch.cpu { background: #4f8cff; }
.swatch.ram { background: #22c55e; }

/* Modals & Toasts */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 60;
}
.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
}
.modal-card.modal-wide { max-width: 820px; }
.modal-card h3 { margin: 0 0 8px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }

.toast-container {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
}
.toast {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  max-width: 360px;
  font-size: 13px;
}
.toast.ok { border-left-color: var(--success); }
.toast.err { border-left-color: var(--danger); }

.mobile-only { display: none; }

@media (max-width: 1050px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 780px) {
  .mobile-only { display: inline-flex; }
  .sidebar {
    position: fixed;
    left: -260px;
    top: 0;
    z-index: 50;
    transition: left 0.2s ease;
  }
  .sidebar.open { left: 0; }
  .kpi-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .content { padding: 14px; }
}
