:root {
  --sidebar-bg: #121a2b;
  --sidebar-text: #aab3c5;
  --sidebar-text-active: #ffffff;
  --sidebar-active-bg: #1d2a44;
  --accent: #2a78d6;
  --accent-dark: #184f95;
  --page-bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e1e0d9;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --good: #0ca30c;
  --warning: #b9790a;
  --critical: #d03b3b;
  --radius: 10px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--page-bg);
  color: var(--text-primary);
  -webkit-font-smoothing: antialiased;
}

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

.app-shell {
  display: flex;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 20px 20px;
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: linear-gradient(135deg, var(--accent), #6da7ec);
  flex: 0 0 auto;
}

.sidebar-brand-name {
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.2px;
}

.sidebar-section-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #5c6785;
  padding: 16px 20px 6px;
}

.sidebar-nav { list-style: none; margin: 0; padding: 0; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  text-decoration: none;
  border-left: 3px solid transparent;
}

.sidebar-nav a:hover {
  background: rgba(255,255,255,0.04);
  color: #fff;
}

.sidebar-nav a.active {
  background: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
  border-left-color: var(--accent);
}

.sidebar-nav .icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  opacity: 0.85;
}

.sidebar-footer {
  margin-top: auto;
  padding: 14px 20px 4px;
  border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 10px;
}

.sidebar-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  font-weight: 700;
  flex: 0 0 auto;
}

.sidebar-user-name { font-size: 12.5px; color: #fff; font-weight: 600; line-height: 1.3; }
.sidebar-user-role { font-size: 11px; color: #6b7590; line-height: 1.3; }

.sidebar-logout {
  display: block;
  font-size: 12px;
  color: #8b96b3;
  cursor: pointer;
  padding: 4px 0;
}
.sidebar-logout:hover { color: #fff; }

/* ---------- Main column ---------- */
.main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 60px;
  flex: 0 0 auto;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar-title { font-size: 16px; font-weight: 700; }

.topbar-right { display: flex; align-items: center; gap: 14px; }

.env-badge {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--warning);
  background: rgba(185,121,10,0.12);
  border: 1px solid rgba(185,121,10,0.3);
  padding: 3px 9px;
  border-radius: 999px;
}

.content {
  flex: 1 1 auto;
  padding: 26px 28px 60px;
  max-width: 1240px;
  width: 100%;
}

.page-title { font-size: 21px; font-weight: 700; margin: 0 0 4px; }
.page-sub { font-size: 13.5px; color: var(--text-secondary); margin: 0 0 22px; }

/* ---------- Cards & grids ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.card-title { font-size: 14px; font-weight: 700; margin: 0 0 2px; }
.card-sub { font-size: 12px; color: var(--text-muted); margin: 0 0 16px; }

.grid {
  display: grid;
  gap: 18px;
}

.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: 1.4fr 1fr; }

@media (max-width: 1000px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}

.section { margin-bottom: 22px; }

/* ---------- Stat tiles ---------- */
.stat-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.stat-label { font-size: 12px; color: var(--text-secondary); font-weight: 600; margin-bottom: 8px; }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
.stat-delta { font-size: 12px; font-weight: 600; margin-top: 6px; display: flex; align-items: center; gap: 4px; }
.stat-delta.up { color: var(--good); }
.stat-delta.down { color: var(--critical); }
.stat-delta-note { color: var(--text-muted); font-weight: 500; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
  padding: 0 12px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  white-space: nowrap;
}
.data-table tbody tr:hover { background: #fafafa; }
.data-table td.wrap { white-space: normal; }
.mono { font-variant-numeric: tabular-nums; font-family: ui-monospace, "SF Mono", Menlo, monospace; }

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 13px;
  width: 260px;
  background: var(--surface);
  color: var(--text-primary);
}
.search-input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.count-note { font-size: 12.5px; color: var(--text-muted); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11.5px;
  font-weight: 700;
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge .dot { width: 6px; height: 6px; border-radius: 50%; flex: 0 0 auto; }
.badge-good { background: rgba(12,163,12,0.10); color: #086b08; }
.badge-good .dot { background: var(--good); }
.badge-warning { background: rgba(185,121,10,0.12); color: #8a5c08; }
.badge-warning .dot { background: var(--warning); }
.badge-critical { background: rgba(208,59,59,0.10); color: #a52323; }
.badge-critical .dot { background: var(--critical); }
.badge-neutral { background: #eeeeec; color: var(--text-secondary); }
.badge-neutral .dot { background: var(--text-muted); }

/* ---------- Side panel (record detail drawer) ---------- */
.data-table tbody tr.clickable { cursor: pointer; }

.side-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11, 11, 11, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.28s ease;
  z-index: 40;
}
.side-panel-overlay.open { opacity: 1; pointer-events: auto; }

.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  width: 400px;
  max-width: 92vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -16px 0 40px rgba(11, 11, 11, 0.16);
  transform: translateX(100%);
  transition: transform 0.32s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 41;
  display: flex;
  flex-direction: column;
}
.side-panel.open { transform: translateX(0); }

.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 22px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
}

.side-panel-title-group { display: flex; align-items: center; gap: 12px; min-width: 0; }

.side-panel-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 15px;
  flex: 0 0 auto;
}

.side-panel-name { font-size: 15.5px; font-weight: 700; line-height: 1.3; }
.side-panel-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.side-panel-close {
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border: 1px solid var(--border);
  background: none;
  flex: 0 0 auto;
  font-size: 15px;
  line-height: 1;
}
.side-panel-close:hover { background: #f4f4f2; }

.side-panel-body { padding: 6px 22px 22px; overflow-y: auto; flex: 1 1 auto; }

.detail-row { padding: 13px 0; border-bottom: 1px solid var(--border); }
.detail-row:last-child { border-bottom: none; }
.detail-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 4px;
}
.detail-value { font-size: 13.5px; color: var(--text-primary); }

/* ---------- Login page ---------- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at 20% 20%, #16233d, #0b1120 60%);
  padding: 20px;
}

.login-card {
  width: 380px;
  background: var(--surface);
  border-radius: 14px;
  padding: 32px 30px 26px;
  box-shadow: 0 24px 60px rgba(0,0,0,0.35);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}

.login-brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), #6da7ec);
}

.login-brand-name { font-weight: 800; font-size: 17px; }

.login-title { font-size: 18px; font-weight: 700; margin: 0 0 4px; }
.login-sub { font-size: 13px; color: var(--text-secondary); margin: 0 0 20px; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-secondary); margin-bottom: 5px; }
.field input {
  width: 100%;
  padding: 9px 11px;
  font-size: 13.5px;
  border: 1px solid #d5d6d2;
  border-radius: 8px;
  background: #fff;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
}
.btn:hover { border-color: #c7c6c0; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  width: 100%;
  padding: 10px 14px;
  font-size: 13.5px;
}
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }

.login-error {
  background: rgba(208,59,59,0.08);
  border: 1px solid rgba(208,59,59,0.25);
  color: #a52323;
  font-size: 12.5px;
  padding: 8px 10px;
  border-radius: 8px;
  margin-bottom: 14px;
}

.login-hint {
  margin-top: 18px;
  padding: 11px 12px;
  border-radius: 8px;
  background: #f3f6fb;
  border: 1px solid #dbe6f4;
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
}
.login-hint strong { color: var(--text-primary); }
.login-hint code {
  background: #e7edf6;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11.5px;
}

/* ---------- Chart chrome ---------- */
.viz-tooltip {
  position: absolute;
  pointer-events: none;
  background: #0b0b0b;
  color: #fff;
  font-size: 11.5px;
  padding: 7px 10px;
  border-radius: 7px;
  line-height: 1.5;
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
  opacity: 0;
  transition: opacity 0.08s;
  z-index: 20;
  white-space: nowrap;
}
.viz-tooltip.visible { opacity: 1; }
.viz-tooltip .tt-value { font-weight: 700; }
.viz-tooltip .tt-key { display: inline-block; width: 8px; height: 2px; margin-right: 6px; vertical-align: middle; }

.chart-legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: 12px;
  color: var(--text-secondary);
}
.chart-legend .item { display: flex; align-items: center; gap: 6px; }
.chart-legend .swatch { width: 9px; height: 9px; border-radius: 2px; flex: 0 0 auto; }

.chart-wrap { position: relative; }

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