/* ---------- Design tokens ---------- */
:root {
  --color-bg: #ffffff;
  --color-surface: #f7f8f6;
  --color-surface-alt: #f0f2ef;
  --color-border: #e4e7e2;
  --color-text: #1c231c;
  --color-text-muted: #6b746a;
  --color-text-faint: #96a094;

  --color-primary: #46b839;
  --color-primary-dark: #379129;
  --color-primary-tint: #eaf7e6;

  --color-accent: #ff6900;
  --color-accent-dark: #d95a00;
  --color-accent-tint: #fff1e6;

  --color-danger: #c0392b;
  --color-danger-dark: #a02f22;
  --color-danger-tint: #fbeae7;

  --color-info: #3b6fb8;
  --color-info-tint: #eaf1fb;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;

  --shadow-sm: 0 1px 2px rgba(28, 35, 28, 0.06);
  --shadow-md: 0 4px 16px rgba(28, 35, 28, 0.08);
  --shadow-lg: 0 12px 32px rgba(28, 35, 28, 0.12);

  --font-sans: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --sidebar-w: 232px;
  --topbar-h: 64px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }

button {
  font-family: inherit;
  cursor: pointer;
}

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

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--color-bg);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 24px;
  border-bottom: 1px solid var(--color-border);
}

.sidebar-brand .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
}

.sidebar-brand .name {
  font-weight: 700;
  font-size: 16px;
  letter-spacing: -0.01em;
}

.sidebar-brand .sub {
  font-size: 11px;
  color: var(--color-text-muted);
  display: block;
  margin-top: 1px;
}

.nav {
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--color-text-muted);
  text-decoration: none;
  font-weight: 500;
  font-size: 13.5px;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-item:hover {
  background: var(--color-surface);
  color: var(--color-text);
}

.nav-item.active {
  background: var(--color-primary-tint);
  color: var(--color-primary-dark);
}

.nav-item .icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.nav-badge {
  margin-left: auto;
  background: var(--color-danger);
  color: #fff;
  font-size: 10.5px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  margin-top: auto;
  padding: 16px 20px;
  border-top: 1px solid var(--color-border);
  font-size: 11.5px;
  color: var(--color-text-faint);
}

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(6px);
  z-index: 10;
}

.topbar-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.topbar-title .subtitle {
  font-size: 12px;
  font-weight: 400;
  color: var(--color-text-muted);
  margin-top: 2px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.content {
  padding: 28px;
  flex: 1;
}

/* ---------- Buttons / inputs ---------- */
.btn {
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  color: var(--color-text);
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn:hover { background: var(--color-surface); }

.btn-primary {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.btn-primary:hover { background: var(--color-primary-dark); }

.select, .input {
  border: 1px solid var(--color-border);
  background: var(--color-bg);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--color-text);
}

.input::placeholder { color: var(--color-text-faint); }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--color-text-muted);
}

.toggle input { accent-color: var(--color-primary); }

/* ---------- Cards / KPIs ---------- */
.grid {
  display: grid;
  gap: 16px;
}

.kpi-grid {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  margin-bottom: 20px;
}

.card {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 18px 20px;
}

.kpi-card .kpi-label {
  font-size: 12px;
  color: var(--color-text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.kpi-card .kpi-value {
  font-size: 24px;
  font-weight: 700;
  margin-top: 6px;
  letter-spacing: -0.01em;
}

.kpi-card .kpi-sub {
  font-size: 12px;
  color: var(--color-text-faint);
  margin-top: 4px;
}

.kpi-card.accent .kpi-value { color: var(--color-primary-dark); }
.kpi-card.warn .kpi-value { color: var(--color-accent-dark); }
.kpi-card.danger .kpi-value { color: var(--color-danger-dark); }

.panel-title {
  font-size: 14px;
  font-weight: 700;
  margin: 0 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.panel-title .link { font-size: 12.5px; font-weight: 600; color: var(--color-primary-dark); text-decoration: none; }

.two-col {
  grid-template-columns: 2fr 1fr;
}

@media (max-width: 1000px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-green { background: var(--color-primary-tint); color: var(--color-primary-dark); }
.badge-orange { background: var(--color-accent-tint); color: var(--color-accent-dark); }
.badge-red { background: var(--color-danger-tint); color: var(--color-danger-dark); }
.badge-gray { background: var(--color-surface-alt); color: var(--color-text-muted); }
.badge-blue { background: var(--color-info-tint); color: var(--color-info); }

/* ---------- Tables ---------- */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  background: var(--color-bg);
}

table {
  border-collapse: collapse;
  width: 100%;
  font-size: 13px;
  min-width: 720px;
}

thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  font-weight: 700;
  padding: 12px 16px;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text);
  white-space: nowrap;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s ease; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--color-surface); }

.cell-mono { font-variant-numeric: tabular-nums; font-family: "SFMono-Regular", Consolas, monospace; font-size: 12.5px; }
.cell-muted { color: var(--color-text-muted); }
.cell-strong { font-weight: 700; }

.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-size: 12.5px;
  color: var(--color-text-muted);
}

.pagination .controls { display: flex; gap: 6px; }

/* ---------- States ---------- */
.empty-state, .loading-state, .error-state {
  padding: 48px 16px;
  text-align: center;
  color: var(--color-text-muted);
  font-size: 13px;
}

.error-state { color: var(--color-danger-dark); }

.spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 3px solid var(--color-surface-alt);
  border-top-color: var(--color-primary);
  animation: spin 0.7s linear infinite;
  margin: 0 auto 10px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Charts ---------- */
.chart-legend {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 10px;
  flex-wrap: wrap;
}

.chart-legend .item { display: flex; align-items: center; gap: 6px; }
.chart-legend .swatch { width: 9px; height: 9px; border-radius: 2px; }

svg.chart text { font-family: var(--font-sans); fill: var(--color-text-muted); }
svg.chart .gridline { stroke: var(--color-border); stroke-width: 1; }
svg.chart .tooltip-dot { fill: var(--color-bg); stroke-width: 2; }

/* ---------- Anomaly / detail ---------- */
.severity-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.anomaly-card {
  border: 1px solid var(--color-border);
  border-left: 4px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.anomaly-card.sev-high { border-left-color: var(--color-danger); }
.anomaly-card.sev-medium { border-left-color: var(--color-accent); }
.anomaly-card.sev-low { border-left-color: var(--color-text-faint); }

.anomaly-card .rule-name { font-weight: 700; font-size: 13.5px; margin-bottom: 3px; }
.anomaly-card .description { color: var(--color-text-muted); font-size: 13px; line-height: 1.5; }
.anomaly-card .meta { display: flex; gap: 10px; margin-top: 8px; font-size: 12px; color: var(--color-text-faint); }
.anomaly-card .amount { font-weight: 700; font-size: 15px; white-space: nowrap; }

/* ---------- Login page ---------- */
.login-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--color-surface);
}

.login-card {
  width: 360px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 32px;
  text-align: center;
}

.login-card .dot-lockup {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  margin: 0 auto 16px;
}

.login-card h1 { font-size: 18px; margin: 0 0 4px; }
.login-card p { font-size: 13px; color: var(--color-text-muted); margin: 0 0 22px; }
.login-card .input { width: 100%; margin-bottom: 12px; }
.login-card .btn-primary { width: 100%; justify-content: center; padding: 10px; }
.login-card .login-error { color: var(--color-danger-dark); font-size: 12.5px; margin-top: 10px; min-height: 16px; }

/* ---------- Modal / drawer ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(28, 35, 28, 0.35);
  display: flex;
  justify-content: flex-end;
  z-index: 100;
}

.drawer {
  width: min(480px, 92vw);
  height: 100%;
  background: var(--color-bg);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  overflow-y: auto;
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 18px;
}

.drawer-close {
  border: none;
  background: var(--color-surface);
  border-radius: 50%;
  width: 28px;
  height: 28px;
  font-size: 15px;
  line-height: 1;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  padding: 9px 0;
  border-bottom: 1px solid var(--color-border);
  font-size: 13px;
  gap: 12px;
}

.detail-row .k { color: var(--color-text-muted); }
.detail-row .v { text-align: right; font-weight: 600; word-break: break-word; }

.section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-faint);
  font-weight: 700;
  margin: 20px 0 6px;
}
