:root {
  --bg: #0b0e14;
  --surface-1: #131722;
  --surface-2: #1a1f2e;
  --border: #262b3a;
  --text-primary: #e6e8ee;
  --text-secondary: #8b91a5;
  --accent: #378add;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text-primary);
  font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
  direction: ltr;
}

.dashboard {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 500;
}

.brand-sub {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
  margin-left: 6px;
}

.conn-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
}
.conn-status.live { color: #63c37a; border-color: #63c37a44; background: #63c37a15; }
.conn-status.down { color: #e24b4a; border-color: #e24b4a44; background: #e24b4a15; }

.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
}

.stat-card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.tone-blue .stat-icon { background: #378add22; color: #378add; }
.tone-red .stat-icon { background: #e24b4a22; color: #e24b4a; }
.tone-amber .stat-icon { background: #ba751722; color: #ba7517; }
.tone-purple .stat-icon { background: #7f77dd22; color: #7f77dd; }

.stat-value { font-size: 22px; font-weight: 500; }
.stat-label { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }

.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.panel {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}

.panel h3 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-primary);
}

.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  color: var(--text-secondary);
  font-weight: 400;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}
td { padding: 10px 8px; border-bottom: 1px solid var(--border); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-2); }

.mono { font-family: "SF Mono", Consolas, monospace; font-size: 12px; }
.ts { color: var(--text-secondary); }

.badge {
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
}

.verdict-actions { display: flex; gap: 6px; }
.btn-verdict {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 10px; border-radius: 6px; font-size: 12px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-secondary); cursor: pointer;
}
.btn-verdict.btn-true:hover { color: #63c37a; border-color: #63c37a; }
.btn-verdict.btn-false:hover { color: #e24b4a; border-color: #e24b4a; }

.verdict-tag {
  display: flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 4px 10px; border-radius: 6px; width: fit-content;
}
.verdict-true { color: #63c37a; background: #63c37a15; }
.verdict-false { color: #8b91a5; background: #8b91a515; }

.btn-block {
  display: flex; align-items: center; gap: 4px;
  padding: 5px 10px; border-radius: 6px; font-size: 12px;
  border: 1px solid #e24b4a44; background: #e24b4a15;
  color: #e24b4a; cursor: pointer;
}
.btn-block:hover { background: #e24b4a25; }

.empty { text-align: center; color: var(--text-secondary); padding: 20px; }

.blocked-grid { display: flex; flex-wrap: wrap; gap: 10px; }
.blocked-chip {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: 8px; font-size: 12px;
}
.blocked-reason { color: var(--text-secondary); }

@media (max-width: 900px) {
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
}

/* Extra stat card tones for the new summary row */
.tone-green .stat-icon { background: #63c37a22; color: #63c37a; }
.tone-gray .stat-icon { background: #8b91a522; color: #8b91a5; }

/* Toast notifications for HIGH severity alerts */
.toast-stack {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--surface-1);
  border: 1px solid #e24b4a55;
  border-left: 3px solid #e24b4a;
  border-radius: 8px;
  padding: 12px 14px;
  min-width: 260px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  color: #e24b4a;
  animation: toast-in 0.25s ease-out;
}

@keyframes toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.toast-body { flex: 1; font-size: 13px; color: var(--text-primary); }
.toast-close {
  background: none; border: none; color: var(--text-secondary);
  cursor: pointer; padding: 2px;
}
.toast-close:hover { color: var(--text-primary); }

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

.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 50;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
  font-size: 15px;
}

.navbar-links { display: flex; gap: 6px; }

.nav-link {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 8px;
  font-size: 13px;
  color: var(--text-secondary);
  text-decoration: none;
}
.nav-link:hover { background: var(--surface-2); color: var(--text-primary); }
.nav-link.active { background: var(--accent)22; color: var(--accent); }

.navbar-user {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.username { color: var(--text-secondary); }

.btn-logout {
  display: flex; align-items: center; gap: 5px;
  padding: 6px 12px; border-radius: 6px; font-size: 12px;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text-secondary); cursor: pointer;
}
.btn-logout:hover { color: #e24b4a; border-color: #e24b4a; }

.app-content { padding: 0; }

/* Threats page filter bar */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.filter-bar select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 7px 10px;
  border-radius: 6px;
  font-size: 12px;
}

.search-field {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text-secondary);
}
.search-field input {
  background: none; border: none; outline: none;
  color: var(--text-primary); font-size: 12px; width: 140px;
}

.btn-clear-filter {
  display: flex; align-items: center; gap: 4px;
  background: none; border: 1px solid var(--border);
  color: var(--text-secondary); border-radius: 6px;
  padding: 6px 10px; font-size: 12px; cursor: pointer;
}
.btn-clear-filter:hover { color: #e24b4a; border-color: #e24b4a; }

.filter-count {
  margin-left: auto;
  font-size: 12px;
  color: var(--text-secondary);
}

/* Model performance page */
.model-card-header {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 16px;
}
.model-version { font-size: 12px; color: var(--text-secondary); }

.model-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.model-meta-grid > div {
  display: flex; flex-direction: column; gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
}
.meta-label { font-size: 11px; color: var(--text-secondary); }

.panel-note {
  font-size: 12px;
  color: var(--text-secondary);
  margin: -6px 0 12px;
}

.retrain-panel { border-width: 1px; }
.retrain-panel.retrain-warning { border-color: #ba751766; background: #ba751708; }
.retrain-panel.retrain-ok { border-color: #63c37a66; background: #63c37a08; }

.retrain-header {
  display: flex; align-items: center; gap: 8px;
  margin-bottom: 10px;
}
.retrain-warning .retrain-header { color: #ba7517; }
.retrain-ok .retrain-header { color: #63c37a; }

.retrain-reasons {
  margin: 0 0 14px;
  padding-left: 20px;
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.retrain-actions { display: flex; }
.btn-export {
  display: flex; align-items: center; gap: 6px;
  background: var(--accent); color: white;
  padding: 8px 14px; border-radius: 8px;
  font-size: 13px; text-decoration: none;
}
.btn-export:hover { filter: brightness(1.1); }

.btn-details {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
}
.btn-details:hover { filter: brightness(1.2); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-box {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  max-width: 500px;
  width: 90%;
  max-height: 80vh;
  overflow-y: auto;
}
.evidence-table td {
  padding: 4px 8px;
  font-family: monospace;
  font-size: 13px;
}
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 16px;
}

/* ── Retrain Button ── */
.btn-retrain {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
.btn-retrain:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-retrain:not(:disabled):hover { filter: brightness(1.1); }

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

/* ── Retrain Status Toast ── */
.retrain-toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 16px;
  border-radius: 10px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
}
.retrain-toast-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  flex: 1;
}
.retrain-toast-meta {
  font-size: 12px;
  opacity: 0.8;
}
.retrain-toast-close {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 14px;
  opacity: 0.7;
}
.retrain-toast-close:hover { opacity: 1; }

.tone-info    { background: #378add22; border-color: #378add55; color: #378add; }
.tone-success { background: #639922022; border-color: #63992255; color: #63b922; }
.tone-warning { background: #ba751722; border-color: #ba751755; color: #ba7517; }
.tone-error   { background: #e24b4a22; border-color: #e24b4a55; color: #e24b4a; }

.spin {
  animation: spin 1s linear infinite;
}
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
