:root {
  color-scheme: dark;
  --bg: #080a0f;
  --surface: #0f131b;
  --surface-2: #151b26;
  --surface-3: #1b2332;
  --border: #1e2636;
  --border-strong: #2b374d;
  --text: #eef2f9;
  --text-2: #9aa7bd;
  --muted: #69778f;
  --accent: #10b981;
  --accent-soft: rgba(16, 185, 129, 0.14);
  --indigo: #6366f1;
  --indigo-soft: rgba(99, 102, 241, 0.16);
  --warn: #f59e0b;
  --warn-soft: rgba(245, 158, 11, 0.15);
  --danger: #f43f5e;
  --danger-soft: rgba(244, 63, 94, 0.15);
  --radius: 12px;
  --radius-sm: 8px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --font-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-sans); font-size: 14px; line-height: 1.5; -webkit-font-smoothing: antialiased; }
a { color: #7dd3fc; text-decoration: none; }
a:hover { text-decoration: underline; }
.hidden { display: none !important; }
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }
.text-2 { color: var(--text-2); }
.text-ok { color: #34d399; }
.text-warn { color: #fbbf24; }
.text-danger { color: #fb7185; }
.small { font-size: 12px; }

/* Auth Screen */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.12), transparent 45%),
              radial-gradient(circle at 80% 80%, rgba(16, 185, 129, 0.1), transparent 45%), var(--bg);
}
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.auth-brand h1 { font-size: 20px; margin: 2px 0 0; letter-spacing: -0.02em; }
.brand-kicker { font-size: 11px; letter-spacing: 0.08em; color: var(--accent); font-weight: 600; }
.auth-subtitle { color: var(--text-2); font-size: 13px; margin: 0 0 20px; }
.auth-footer { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; font-size: 12px; }

/* Brand Mark */
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #10b981, #6366f1);
  color: #061015; font-weight: 800; font-size: 13px;
  display: grid; place-items: center; flex-shrink: 0;
  letter-spacing: -0.03em;
}

/* Shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 252px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; z-index: 30;
}
.sidebar-top {
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.brand-row { display: flex; align-items: center; gap: 11px; }
.brand-title { font-weight: 700; font-size: 14px; letter-spacing: 0.02em; }
.brand-sub { font-size: 11px; color: var(--muted); }

.nav-list { padding: 12px 10px; display: flex; flex-direction: column; gap: 4px; flex: 1; overflow-y: auto; }
.nav-item {
  width: 100%; display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: transparent;
  color: var(--text-2); cursor: pointer; font-size: 13.5px; font-weight: 500;
  text-align: left; transition: background 0.14s, color 0.14s, border-color 0.14s;
}
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; opacity: 0.8; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active {
  background: var(--surface-2); color: var(--text);
  border-color: var(--border-strong);
}
.nav-item.active svg { color: var(--accent); opacity: 1; }
.nav-badge {
  margin-left: auto; font-size: 11px; font-family: var(--font-mono);
  padding: 1px 7px; border-radius: 999px;
  background: var(--surface-3); color: var(--text-2);
}

.sidebar-bottom { padding: 12px; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 10px; }
.estop-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: var(--radius-sm); font-size: 12px; font-weight: 500;
}
.estop-pill.ok { background: var(--accent-soft); color: #6ee7b7; border: 1px solid rgba(16, 185, 129, 0.25); }
.estop-pill.danger { background: var(--danger-soft); color: #fda4af; border: 1px solid rgba(244, 63, 94, 0.35); }
.estop-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.user-card {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--border);
}
.user-name { font-weight: 600; font-size: 13px; }
.user-role { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }

/* Main area */
.main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: rgba(8, 10, 15, 0.88); backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
}
.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.page-title { font-size: 18px; margin: 0; font-weight: 650; letter-spacing: -0.02em; }
.page-subtitle { margin: 2px 0 0; font-size: 12.5px; color: var(--text-2); }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.estop-banner {
  background: var(--danger-soft); border-bottom: 1px solid rgba(244, 63, 94, 0.4);
  color: #fecdd3; padding: 11px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13px;
}
.estop-banner strong { margin-right: 10px; }

.view-container { padding: 22px 24px 40px; max-width: 1460px; width: 100%; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }

/* Grid & Cards */
.kpi-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 15px 16px; display: flex; flex-direction: column; gap: 6px; min-width: 0; overflow: hidden;
}
.kpi-label { font-size: 12px; color: var(--text-2); display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 6px; }
.kpi-value { font-size: 24px; font-weight: 700; letter-spacing: -0.03em; font-family: var(--font-mono); }
.kpi-sub { font-size: 11.5px; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.grid-accounts { display: grid; grid-template-columns: 310px minmax(0, 1fr); gap: 16px; align-items: start; }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; display: flex; flex-direction: column; gap: 14px; min-width: 0;
}
.card-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.card-title { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.card-sub { margin: 2px 0 0; font-size: 12px; color: var(--text-2); }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border-radius: var(--radius-sm); padding: 8px 13px;
  font-size: 13px; font-weight: 500; cursor: pointer;
  border: 1px solid transparent; transition: all 0.14s; white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-xs { padding: 4px 8px; font-size: 11.5px; }
.btn-block { width: 100%; }
.btn-primary { background: var(--accent); color: #05130f; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: #34d399; }
.btn-indigo { background: var(--indigo); color: #fff; font-weight: 600; }
.btn-indigo:hover:not(:disabled) { background: #818cf8; }
.btn-secondary { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover:not(:disabled) { background: var(--surface-3); }
.btn-danger { background: var(--danger-soft); color: #fda4af; border-color: rgba(244, 63, 94, 0.35); }
.btn-danger:hover:not(:disabled) { background: rgba(244, 63, 94, 0.28); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-2); border-color: var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.icon-btn {
  background: var(--surface-2); color: var(--text-2); border: 1px solid var(--border);
  width: 32px; height: 32px; border-radius: var(--radius-sm); cursor: pointer;
  display: grid; place-items: center; font-size: 15px;
}
.icon-btn:hover { color: var(--text); background: var(--surface-3); }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 500;
  border: 1px solid transparent; white-space: nowrap;
}
.badge-ok { background: var(--accent-soft); color: #6ee7b7; border-color: rgba(16, 185, 129, 0.25); }
.badge-info { background: var(--indigo-soft); color: #a5b4fc; border-color: rgba(99, 102, 241, 0.3); }
.badge-warn { background: var(--warn-soft); color: #fcd34d; border-color: rgba(245, 158, 11, 0.3); }
.badge-danger { background: var(--danger-soft); color: #fda4af; border-color: rgba(244, 63, 94, 0.32); }
.badge-neutral { background: var(--surface-3); color: var(--text-2); border-color: var(--border-strong); }

/* Alerts */
.alert { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 12.5px; border: 1px solid transparent; }
.alert-danger { background: var(--danger-soft); color: #fecdd3; border-color: rgba(244, 63, 94, 0.35); }
.alert-warn { background: var(--warn-soft); color: #fde68a; border-color: rgba(245, 158, 11, 0.3); }
.alert-info { background: var(--indigo-soft); color: #c7d2fe; border-color: rgba(99, 102, 241, 0.3); }
.alert-ok { background: var(--accent-soft); color: #a7f3d0; border-color: rgba(16, 185, 129, 0.3); }

/* Forms & Filters */
.form-stack { display: flex; flex-direction: column; gap: 13px; }
.form-grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--text-2); }
.field input, .field select, .field textarea,
.filter-bar input, .filter-bar select {
  background: var(--bg); color: var(--text); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); padding: 8px 10px; font-size: 13px; font-family: inherit;
  outline: none; width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus,
.filter-bar input:focus, .filter-bar select:focus {
  border-color: var(--accent); box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.15);
}
.checkbox-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.checkbox-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 9px; border-radius: 6px; background: var(--surface-2);
  border: 1px solid var(--border); font-size: 12.5px; cursor: pointer;
}
.checkbox-item input { width: auto; }

.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.filter-bar input { max-width: 240px; }
.filter-bar select { width: auto; min-width: 140px; }

/* Tables */
.table-wrap { width: 100%; overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-sm); }
table { width: 100%; border-collapse: collapse; text-align: left; font-size: 13px; }
thead th {
  background: var(--surface-2); color: var(--text-2); font-weight: 600; font-size: 11.5px;
  text-transform: uppercase; letter-spacing: 0.04em;
  padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: rgba(255, 255, 255, 0.02); }
.actions-cell { display: flex; gap: 6px; flex-wrap: nowrap; }

.pagination {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 12.5px; color: var(--text-2); padding-top: 4px;
}
.pagination-controls { display: flex; align-items: center; gap: 8px; }

/* Account Selector List */
.acc-list { display: flex; flex-direction: column; gap: 8px; }
.acc-card-btn {
  width: 100%; text-align: left; padding: 12px; border-radius: var(--radius-sm);
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text);
  cursor: pointer; display: flex; flex-direction: column; gap: 5px; transition: all 0.14s;
}
.acc-card-btn:hover { border-color: var(--border-strong); background: var(--surface-3); }
.acc-card-btn.active { border-color: var(--accent); background: rgba(16, 185, 129, 0.09); }
.acc-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }

/* Bar Chart & Progress (100% CSP style-src 'self' compliant — zero inline styles) */
.bar-list { display: flex; flex-direction: column; gap: 9px; }
.bar-row { display: flex; flex-direction: column; gap: 4px; }
.bar-meta { display: flex; justify-content: space-between; font-size: 12px; }
progress.bar-progress {
  appearance: none; -webkit-appearance: none;
  width: 100%; height: 7px; border: none; border-radius: 999px;
  background: var(--surface-3); overflow: hidden; display: block;
}
progress.bar-progress::-webkit-progress-bar { background: var(--surface-3); border-radius: 999px; }
progress.bar-progress::-webkit-progress-value { background: linear-gradient(90deg, var(--accent), var(--indigo)); border-radius: 999px; }
progress.bar-progress::-moz-progress-bar { background: linear-gradient(90deg, var(--accent), var(--indigo)); border-radius: 999px; }

/* Score meter */
.score-pill { display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-mono); font-size: 12px; }
progress.score-progress {
  appearance: none; -webkit-appearance: none;
  width: 48px; height: 5px; border: none; border-radius: 999px;
  background: var(--surface-3); overflow: hidden;
}
progress.score-progress::-webkit-progress-bar { background: var(--surface-3); border-radius: 999px; }
progress.score-progress::-webkit-progress-value { background: var(--accent); border-radius: 999px; }
progress.score-progress::-moz-progress-bar { background: var(--accent); border-radius: 999px; }

/* Utility layout classes (replacing inline styles for strict CSP) */
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row-gap-sm { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.check-item { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 10px; background: var(--surface-2); border-radius: 8px; border: 1px solid var(--border); }
.check-title { font-size: 13px; font-weight: 500; }
.meta-strip { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; font-size: 12px; }
.fw-600 { font-weight: 600; }
.fw-650 { font-weight: 650; }
.mb-xs { margin-bottom: 6px; }
.mb-sm { margin-bottom: 8px; }
.mt-xxs { margin-top: 3px; }
.mt-xs { margin-top: 4px; }
.mt-sm { margin-top: 6px; }
.cell-note { max-width: 260px; }
.cell-caveat { max-width: 290px; }
.cell-trunc { max-width: 320px; overflow: hidden; text-overflow: ellipsis; }
.input-narrow { max-width: 190px; }
.card-danger { border-color: rgba(244, 63, 94, 0.55); }
.policy-list { margin: 6px 0 0; padding-left: 18px; color: var(--text-2); font-size: 12.5px; }
.policy-list li { margin-bottom: 4px; }
.tiny { font-size: 10.5px; }

/* V3.1 Additions (100% CSP-compliant) */
.kpi-grid-5 { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 12px; }
.star-btn { background: transparent; border: 1px solid var(--border-strong); color: var(--muted); border-radius: 6px; padding: 3px 7px; cursor: pointer; font-size: 13px; }
.star-btn.active { color: #fbbf24; border-color: rgba(245, 158, 11, 0.5); background: var(--warn-soft); }
.star-btn:hover { color: #fbbf24; }
.log-box { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; font-family: var(--font-mono); font-size: 12px; max-height: 300px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.log-line { display: flex; gap: 10px; border-bottom: 1px solid rgba(30, 38, 54, 0.55); padding-bottom: 4px; }
.log-line:last-child { border-bottom: none; padding-bottom: 0; }
.log-ts { color: var(--muted); flex-shrink: 0; }
.tab-pills { display: inline-flex; background: var(--bg); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 3px; gap: 3px; }
.tab-pill { border: none; background: transparent; color: var(--text-2); padding: 5px 11px; border-radius: 6px; font-size: 12.5px; font-weight: 500; cursor: pointer; }
.tab-pill.active { background: var(--surface-3); color: var(--text); }
.fx-banner { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 12px; padding: 12px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.semantic-cell { max-width: 280px; }
.modal-dialog-lg { max-width: 680px; }
.input-xs { max-width: 96px; }
.res-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.res-item { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; display: flex; flex-direction: column; gap: 6px; }
@media (max-width: 1120px) {
  .kpi-grid-5, .res-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .kpi-grid-5, .res-grid { grid-template-columns: 1fr; }
}

/* V3.2 Additions (100% CSP-compliant, zero inline styles) */
.badge-purple { background: rgba(139, 92, 246, 0.16); color: #c4b5fd; border: 1px solid rgba(139, 92, 246, 0.36); }
.btn-warn { background: var(--warn-soft); color: #fcd34d; border: 1px solid rgba(245, 158, 11, 0.4); }
.btn-warn:hover { background: rgba(245, 158, 11, 0.24); }
.stat-mini-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.stat-mini { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 9px 11px; }
.stat-mini-val { font-family: var(--font-mono); font-size: 16px; font-weight: 700; margin-top: 2px; }

/* Code / CLI box */
.cli-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 10px 12px; font-family: var(--font-mono); font-size: 12px; color: #cbd5e1;
  display: flex; align-items: center; justify-content: space-between; gap: 10px; overflow-x: auto;
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0, 0, 0, 0.72); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-dialog {
  width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border-strong); border-radius: 14px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
}
.modal-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h2 { margin: 0; font-size: 16px; }
.modal-body { padding: 18px 20px; }

/* Toasts */
.toast-root { position: fixed; right: 20px; bottom: 20px; z-index: 80; display: flex; flex-direction: column; gap: 8px; max-width: 360px; }
.toast {
  background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--text);
  padding: 11px 14px; border-radius: var(--radius-sm); font-size: 13px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5);
}
.toast.ok { border-left: 3px solid var(--accent); }
.toast.error { border-left: 3px solid var(--danger); }

/* Mobile */
.mobile-only { display: none; }
.sidebar-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.65); z-index: 25; }

@media (max-width: 1120px) {
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-2, .grid-accounts { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .mobile-only { display: inline-grid; }
  .sidebar { position: fixed; left: 0; top: 0; transform: translateX(-100%); transition: transform 0.2s ease; }
  .sidebar.open { transform: translateX(0); }
  .topbar { padding: 12px 16px; }
  .view-container { padding: 16px; }
  .form-grid-2, .checkbox-grid { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
