* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  background-color: #090f1d;
  color: #e2e8f0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 0 14px 0;
  border-bottom: 1px solid #1e293b;
  flex-wrap: wrap;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-badge {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, #0ea5e9, #1d4ed8);
  color: #f8fafc;
  font-weight: 700;
  font-size: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: 0.04em;
  box-shadow: 0 4px 14px rgba(14, 165, 233, 0.25);
}

.brand-copy h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 600;
  color: #f8fafc;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 2px 0 0 0;
  font-size: 12px;
  color: #94a3b8;
}

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

.meta-pill {
  background-color: #111c33;
  border: 1px solid #24344d;
  color: #cbd5e1;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.03em;
  border: 1px solid #24344d;
  background-color: #111c33;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: #94a3b8;
}

.status-live {
  color: #34d399;
  border-color: rgba(16, 185, 129, 0.45);
  background-color: rgba(16, 185, 129, 0.12);
}

.status-live .status-dot {
  background-color: #10b981;
  box-shadow: 0 0 8px #10b981;
}

.status-connecting {
  color: #fbbf24;
  border-color: rgba(245, 158, 11, 0.45);
  background-color: rgba(245, 158, 11, 0.12);
}

.status-connecting .status-dot {
  background-color: #f59e0b;
}

.status-offline {
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.45);
  background-color: rgba(239, 68, 68, 0.12);
}

.status-offline .status-dot {
  background-color: #ef4444;
}

.auth-banner {
  margin-top: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background-color: rgba(245, 158, 11, 0.14);
  border: 1px solid rgba(245, 158, 11, 0.45);
  color: #fde68a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.tab-nav {
  display: flex;
  gap: 8px;
  padding: 14px 0;
  border-bottom: 1px solid #1e293b;
  overflow-x: auto;
}

.tab-btn {
  background-color: #111a2e;
  color: #94a3b8;
  border: 1px solid #1f2e47;
  border-radius: 8px;
  padding: 8px 13px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.tab-btn:hover {
  color: #f1f5f9;
  border-color: #38bdf8;
  background-color: #16233d;
}

.tab-btn.active {
  background-color: #0ea5e9;
  border-color: #38bdf8;
  color: #041222;
  font-weight: 600;
}

.main-content {
  flex: 1;
  padding: 20px 0 32px 0;
}

.tab-panel {
  display: none;
  flex-direction: column;
  gap: 18px;
}

.tab-panel.active {
  display: flex;
}

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

.kpi-card {
  background-color: #111a2e;
  border: 1px solid #1f2e47;
  border-radius: 10px;
  padding: 16px 18px;
}

.kpi-label {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
}

.kpi-value {
  font-size: 24px;
  font-weight: 700;
  color: #f8fafc;
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.kpi-ok {
  color: #34d399;
}

.kpi-warn {
  color: #fbbf24;
}

.kpi-danger {
  color: #f87171;
}

.kpi-sub {
  margin-top: 4px;
  font-size: 12px;
  color: #94a3b8;
}

.sensor-tile-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.sensor-tile {
  background-color: #0b1324;
  border: 1px solid #1f2e47;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sensor-tile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.sensor-tile-name {
  font-size: 12px;
  font-weight: 600;
  color: #e2e8f0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.sensor-tile-meta {
  font-size: 11px;
  color: #94a3b8;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.panel-card {
  background-color: #111a2e;
  border: 1px solid #1f2e47;
  border-radius: 10px;
  padding: 18px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.panel-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: #f8fafc;
}

.panel-desc {
  margin: 3px 0 0 0;
  font-size: 12px;
  color: #94a3b8;
}

.two-col {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  text-decoration: none;
  transition: background-color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:disabled,
.disabled-link {
  opacity: 0.45;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-primary {
  background-color: #0ea5e9;
  color: #031527;
  border-color: #38bdf8;
}

.btn-primary:hover {
  background-color: #38bdf8;
}

.btn-secondary {
  background-color: #18253f;
  color: #e2e8f0;
  border-color: #2d4062;
}

.btn-secondary:hover {
  background-color: #203152;
  border-color: #38bdf8;
}

.btn-accent {
  background-color: #10b981;
  color: #042218;
  border-color: #34d399;
}

.btn-accent:hover {
  background-color: #34d399;
}

.btn-danger {
  background-color: rgba(239, 68, 68, 0.16);
  color: #f87171;
  border-color: rgba(239, 68, 68, 0.45);
}

.btn-danger:hover {
  background-color: rgba(239, 68, 68, 0.28);
}

.btn-xs {
  padding: 4px 10px;
  font-size: 12px;
}

.segmented-toggle {
  display: inline-flex;
  border: 1px solid #263856;
  border-radius: 8px;
  overflow: hidden;
  background-color: #0b1324;
}

.seg-btn {
  border: none;
  background: transparent;
  color: #94a3b8;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

.seg-btn.active {
  background-color: #0ea5e9;
  color: #041222;
}

.noise-metrics-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.noise-chip {
  background-color: #0b1324;
  border: 1px solid #1f2e47;
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  color: #94a3b8;
}

.noise-chip strong {
  color: #e2e8f0;
}

.demo-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.demo-status {
  font-size: 12px;
  font-weight: 600;
  color: #38bdf8;
}

.result-banner {
  margin-top: 12px;
  margin-bottom: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  background-color: rgba(14, 165, 233, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.35);
  color: #e0f2fe;
  font-size: 13px;
}

.result-banner.error-banner {
  background-color: rgba(239, 68, 68, 0.12);
  border-color: rgba(248, 113, 113, 0.4);
  color: #fecaca;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

.compact-wrap {
  margin-top: 6px;
  margin-bottom: 14px;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.data-table th {
  text-align: left;
  padding: 9px 10px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #94a3b8;
  border-bottom: 1px solid #24344d;
  background-color: #0d1526;
  white-space: nowrap;
}

.data-table td {
  padding: 9px 10px;
  border-bottom: 1px solid #1b2840;
  color: #e2e8f0;
  vertical-align: middle;
}

.interactive-table tbody tr.incident-row {
  cursor: pointer;
}

.interactive-table tbody tr.incident-row:hover {
  background-color: #162440;
}

.empty-cell {
  text-align: center;
  padding: 22px 12px;
  color: #94a3b8;
}

.empty-box {
  padding: 20px 16px;
  border: 1px dashed #2b3f5e;
  border-radius: 8px;
  text-align: center;
  color: #94a3b8;
  background-color: #0d1526;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
}

.badge-ok {
  background-color: rgba(16, 185, 129, 0.16);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.badge-danger {
  background-color: rgba(239, 68, 68, 0.16);
  color: #f87171;
  border: 1px solid rgba(239, 68, 68, 0.4);
}

.badge-warn {
  background-color: rgba(245, 158, 11, 0.16);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.4);
}

.badge-info {
  background-color: rgba(14, 165, 233, 0.16);
  color: #38bdf8;
  border: 1px solid rgba(56, 189, 248, 0.35);
}

.badge-loopback {
  background-color: rgba(99, 102, 241, 0.18);
  color: #a5b4fc;
  border: 1px solid rgba(129, 140, 248, 0.4);
}

.badge-neutral {
  background-color: #18253f;
  color: #cbd5e1;
  border: 1px solid #2c3f61;
}

.filter-controls {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.form-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: #cbd5e1;
}

.checkbox-align {
  justify-content: flex-end;
  padding-bottom: 6px;
}

.input-field {
  background-color: #0b1324;
  border: 1px solid #263856;
  border-radius: 8px;
  padding: 8px 11px;
  color: #f8fafc;
  font-size: 13px;
  font-family: inherit;
}

.input-field:focus {
  outline: none;
  border-color: #38bdf8;
  box-shadow: 0 0 0 2px rgba(56, 189, 248, 0.2);
}

.input-compact {
  padding: 6px 10px;
  font-size: 12px;
}

.code-textarea {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  resize: vertical;
}

.field-hint {
  margin: 2px 0 0 0;
  font-size: 12px;
  color: #94a3b8;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: #cbd5e1;
  cursor: pointer;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 4px;
}

.row-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.inline-feedback {
  font-size: 12px;
  color: #34d399;
}

.inline-feedback.is-error {
  color: #f87171;
}

.output-section {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid #1f2e47;
}

.meta-kv-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.meta-kv {
  background-color: #0b1324;
  border: 1px solid #1e2d48;
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.meta-k {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #94a3b8;
}

.meta-v {
  font-size: 13px;
  color: #f1f5f9;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.break-all {
  word-break: break-all;
}

.code-label {
  display: block;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #94a3b8;
  margin-bottom: 6px;
}

.code-block {
  margin: 0;
  padding: 12px;
  background-color: #070d19;
  border: 1px solid #1e2d48;
  border-radius: 8px;
  color: #cbd5e1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 320px;
  overflow-y: auto;
}

.risk-summary-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.risk-item {
  background-color: #0b1324;
  border: 1px solid #1e2d48;
  border-radius: 8px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
}

.chip-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.chip-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 999px;
  background-color: #162440;
  border: 1px solid #2b4168;
  color: #e2e8f0;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.chip-remove {
  border: none;
  background: transparent;
  color: #f87171;
  cursor: pointer;
  font-weight: 700;
  padding: 0 2px;
}

.sub-heading {
  margin: 12px 0 6px 0;
  font-size: 13px;
  font-weight: 600;
  color: #f1f5f9;
}

.blueprint-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.blueprint-card {
  background-color: #0d1526;
  border: 1px solid #1f2e47;
  border-radius: 8px;
  padding: 15px 16px;
}

.blueprint-card h3 {
  margin: 0 0 10px 0;
  font-size: 14px;
  font-weight: 600;
  color: #38bdf8;
}

.checklist {
  margin: 0;
  padding-left: 18px;
  color: #cbd5e1;
}

.checklist li {
  margin-bottom: 7px;
}

.checklist li:last-child {
  margin-bottom: 0;
}

.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 0 20px 0;
  border-top: 1px solid #1e293b;
  font-size: 12px;
  color: #94a3b8;
  flex-wrap: wrap;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(2, 6, 18, 0.72);
  z-index: 40;
}

.modal-card {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, 92vw);
  background-color: #0f172a;
  border: 1px solid #263856;
  border-radius: 12px;
  z-index: 60;
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.65);
}

.modal-body {
  padding: 18px 20px 22px 20px;
}

.evidence-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(640px, 100vw);
  height: 100vh;
  background-color: #0f172a;
  border-left: 1px solid #263856;
  z-index: 50;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 32px rgba(0, 0, 0, 0.55);
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid #1f2e47;
}

.drawer-header h2 {
  margin: 0;
  font-size: 16px;
  color: #f8fafc;
}

.drawer-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 24px 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.drawer-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.drawer-section h3 {
  margin: 0 0 8px 0;
  font-size: 13px;
  font-weight: 600;
  color: #cbd5e1;
}

.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.section-row h3 {
  margin: 0;
}

.hash-box {
  background-color: #070d19;
  border: 1px solid #1f2e47;
  border-radius: 8px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.hash-row {
  display: flex;
  flex-direction: column;
  gap: 3px;
  font-size: 12px;
  color: #34d399;
}

.hidden {
  display: none !important;
}

@media (max-width: 1180px) {
  .sensor-tile-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 1024px) {
  .kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .two-col,
  .blueprint-grid {
    grid-template-columns: 1fr;
  }
  .risk-summary-bar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 640px) {
  .kpi-grid,
  .meta-kv-grid,
  .form-row,
  .sensor-tile-grid {
    grid-template-columns: 1fr;
  }
}
