:root {
  color-scheme: dark;
  --bg: #071019;
  --bg-2: #08131d;
  --panel: #0d1c27;
  --panel-2: #102534;
  --panel-3: #142d3e;
  --line: #28475d;
  --line-strong: #3a6882;
  --text: #eef7fb;
  --muted: #9eb4c3;
  --soft: #c7d8e4;
  --blue: #5a9cff;
  --blue-dim: #14355c;
  --green: #31c46b;
  --green-dim: #123f2a;
  --lime: #31c46b;
  --gold: #f7c948;
  --yellow: #f7c948;
  --yellow-dim: #443814;
  --amber: #ffae42;
  --orange: #ffae42;
  --orange-dim: #472d13;
  --purple: #ffae42;
  --red: #ff5b64;
  --red-dim: #42191e;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.34);
  --radius: 8px;
  --max: 1840px;
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(13, 37, 54, 0.82), rgba(5, 13, 21, 0.98)),
    var(--bg);
  overflow-x: hidden;
}

button {
  font: inherit;
}

.dashboard-shell {
  width: min(var(--max), calc(100% - 28px));
  margin: 0 auto;
  padding: 16px 0 18px;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(240px, 0.8fr) minmax(520px, 1.7fr) minmax(210px, 0.7fr);
  gap: 18px;
  align-items: center;
  min-height: 86px;
  min-width: 0;
  max-width: 100%;
}

.topbar > *,
.source-banner > *,
.mode-and-source > *,
.dashboard-grid > * {
  min-width: 0;
  max-width: 100%;
}

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

.brand-mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  color: var(--blue);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  font-size: 26px;
  font-family: "Segoe UI", Arial, sans-serif;
  line-height: 1;
  background: rgba(90, 156, 255, 0.08);
}

.brand-name {
  font-size: 34px;
  line-height: 0.95;
  font-weight: 760;
  letter-spacing: 0;
}

.brand-subtitle {
  margin-top: 6px;
  color: var(--soft);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
}

.title-block {
  text-align: center;
  min-width: 0;
  max-width: 100%;
}

.title-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  min-width: 0;
  max-width: 100%;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(27px, 2.2vw, 36px);
  font-weight: 760;
  letter-spacing: 0;
  min-width: 0;
  overflow-wrap: break-word;
  line-height: 1.13;
}

.title-block p {
  margin-top: 6px;
  color: var(--soft);
  font-size: 15px;
}

.public-pill {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border: 1px solid rgba(49, 196, 107, 0.38);
  border-radius: 7px;
  color: #a8f7a0;
  background: rgba(49, 196, 107, 0.1);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.cadence-row {
  display: flex;
  justify-content: center;
  gap: 16px;
  flex-wrap: wrap;
  margin-top: 8px;
  color: var(--muted);
  font-size: 13px;
}

.cadence-row span {
  max-width: 100%;
  overflow-wrap: break-word;
}

.status-block {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 5px;
  font-size: 14px;
}

.micro-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.live-state {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #a8f7a0;
}

.live-state i {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 18px rgba(49, 196, 107, 0.52);
}

.mode-and-source {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(580px, 1.8fr);
  gap: 10px;
  margin-top: 10px;
}

.mode-panel,
.source-banner,
.panel,
.metric-card {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(20, 45, 62, 0.98), rgba(9, 26, 38, 0.98)),
    var(--panel);
  box-shadow: var(--shadow);
}

.mode-panel,
.source-banner {
  min-height: 96px;
  padding: 14px 18px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
}

.panel-heading h2 {
  font-size: 15px;
  font-weight: 780;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.info-button {
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border: 1px solid rgba(90, 156, 255, 0.42);
  border-radius: 50%;
  color: #9ed0ff;
  background: rgba(90, 156, 255, 0.1);
  cursor: help;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 9px;
  margin-top: 13px;
}

.mode-button,
.simulation-actions button,
.table-actions button,
#drawerClose {
  min-height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  color: var(--text);
  background: rgba(8, 19, 29, 0.9);
  cursor: pointer;
  transition: border-color 160ms ease, background 160ms ease, transform 160ms ease;
}

.mode-button:hover,
.mode-button:focus-visible,
.simulation-actions button:hover,
.table-actions button:hover,
#drawerClose:hover {
  border-color: rgba(90, 156, 255, 0.72);
  background: rgba(90, 156, 255, 0.08);
}

.mode-button.is-active {
  border-color: #2f78b7;
  color: var(--text);
  background: #0c457e;
  box-shadow: inset 3px 0 0 #8fc1ff;
}

.source-banner {
  display: grid;
  grid-template-columns: minmax(220px, 0.9fr) minmax(150px, 0.45fr) minmax(300px, 1.2fr);
  gap: 20px;
  align-items: center;
}

.source-banner p {
  color: var(--soft);
  font-size: 14px;
  line-height: 1.45;
}

.source-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.source-item strong {
  display: block;
  margin-top: 5px;
  max-width: 100%;
  white-space: normal;
  overflow: visible;
  text-overflow: clip;
  overflow-wrap: anywhere;
  line-height: 1.25;
}

.source-icon,
.shield-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 8px;
  color: var(--soft);
  background: rgba(158, 180, 195, 0.08);
  border: 1px solid var(--line);
  font-size: 13px;
  font-weight: 800;
}

.shield-icon {
  color: #a8f7a0;
  background: rgba(49, 196, 107, 0.1);
  border-color: rgba(49, 196, 107, 0.34);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.metric-card {
  display: flex;
  align-items: center;
  gap: 13px;
  min-height: 88px;
  padding: 14px;
  cursor: help;
}

.metric-card h3 {
  color: var(--soft);
  font-size: 11px;
  font-weight: 720;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.metric-card strong {
  display: block;
  margin-top: 6px;
  font-size: clamp(22px, 1.6vw, 29px);
  line-height: 1.08;
  letter-spacing: 0;
}

.metric-card span:last-child {
  color: var(--muted);
  font-size: 12px;
}

.metric-icon {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  font-weight: 850;
  border: 2px solid currentColor;
  background: rgba(255, 255, 255, 0.04);
}

.metric-icon.blue { color: var(--blue); }
.metric-icon.green { color: var(--green); }
.metric-icon.lime { color: var(--lime); }
.metric-icon.gold { color: var(--yellow); background: rgba(247, 201, 72, 0.1); }
.metric-icon.purple { color: var(--purple); }
.metric-icon.amber { color: var(--amber); }
.gold-edge {
  border-color: rgba(247, 201, 72, 0.42);
  box-shadow: inset 0 0 0 1px rgba(247, 201, 72, 0.1), var(--shadow);
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(720px, 1.35fr) minmax(460px, 0.85fr);
  gap: 10px;
  margin-top: 10px;
}

.panel {
  padding: 14px;
  min-width: 0;
}

.table-panel {
  min-height: 520px;
}

.table-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.table-actions button {
  min-height: 30px;
  padding: 0 12px;
}

.table-wrap {
  margin-top: 12px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 7px;
}

table {
  width: 100%;
  min-width: 1180px;
  border-collapse: collapse;
}

th,
td {
  padding: 10px 12px;
  border-bottom: 1px solid rgba(40, 71, 93, 0.82);
  border-right: 1px solid rgba(40, 71, 93, 0.58);
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

th {
  position: sticky;
  top: 0;
  z-index: 2;
  color: var(--muted);
  background: #17354a;
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

tbody tr {
  background: rgba(20, 45, 62, 0.48);
  cursor: pointer;
}

tbody tr:hover,
tbody tr.is-selected {
  background: rgba(90, 156, 255, 0.08);
}

tbody tr.is-blocked {
  opacity: 0.66;
}

.agent-cell strong {
  display: block;
  color: #ffffff;
  font-size: 13px;
}

.agent-cell small,
.muted-text {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.value-green {
  color: #a8f7a0;
}

.status-chip,
.confidence-chip {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
}

.status-chip.verified,
.confidence-chip.high,
.confidence-chip.verified {
  color: #a8f7a0;
  border-color: rgba(49, 196, 107, 0.34);
  background: rgba(49, 196, 107, 0.1);
}

.status-chip.partial,
.confidence-chip.medium,
.confidence-chip.partial {
  color: #f7d978;
  border-color: rgba(247, 201, 72, 0.34);
  background: rgba(247, 201, 72, 0.1);
}

.status-chip.sandbox,
.confidence-chip.low {
  color: #9ed0ff;
  border-color: rgba(90, 156, 255, 0.28);
  background: rgba(90, 156, 255, 0.1);
}

.status-chip.blocked,
.confidence-chip.blocked {
  color: #ffb7bd;
  border-color: rgba(255, 91, 100, 0.3);
  background: rgba(255, 91, 100, 0.1);
}

.chart-panel {
  min-height: 338px;
}

.chart-legend {
  display: flex;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
  margin-top: 8px;
  color: var(--soft);
  font-size: 13px;
}

.chart-legend span,
.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
}

.swatch.green { background: var(--green); }
.swatch.purple { background: var(--orange); }
.swatch.orange { background: var(--orange); }
.swatch.blue { background: var(--blue); }

.trend-chart {
  width: 100%;
  height: 260px;
  margin-top: 4px;
  overflow: visible;
}

.chart-note {
  color: var(--muted);
  font-size: 12px;
}

.compact-panel {
  min-height: 250px;
}

.donut-row {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  margin-top: 12px;
}

.donut {
  width: 174px;
  aspect-ratio: 1;
  border-radius: 50%;
  position: relative;
  background: conic-gradient(var(--green) 0 65%, var(--blue) 65% 82%, var(--yellow) 82% 100%);
  box-shadow: inset 0 0 0 1px var(--line), 0 14px 36px rgba(0, 0, 0, 0.25);
}

.donut.small {
  width: 154px;
}

.donut::after {
  content: attr(data-center);
  position: absolute;
  inset: 29%;
  display: grid;
  place-items: center;
  text-align: center;
  border-radius: 50%;
  color: var(--text);
  background: #071725;
  border: 1px solid var(--line);
  font-size: 13px;
  line-height: 1.28;
  white-space: pre-line;
}

.donut-legend {
  display: grid;
  gap: 9px;
  min-width: 0;
}

.legend-item {
  justify-content: space-between;
  gap: 12px;
  min-height: 27px;
  padding: 0;
  border: 0;
  color: var(--soft);
  background: transparent;
  text-align: left;
  cursor: pointer;
}

.legend-item:hover,
.legend-item:focus-visible {
  color: #ffffff;
}

.legend-left {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.legend-left span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.legend-value {
  white-space: nowrap;
  color: #dbe8f8;
  font-variant-numeric: tabular-nums;
}

.confidence-bars {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.confidence-row {
  display: grid;
  grid-template-columns: minmax(150px, 1fr) 120px 42px;
  gap: 10px;
  align-items: center;
  color: var(--soft);
  font-size: 12px;
}

.bar-track {
  height: 9px;
  border-radius: 999px;
  background: rgba(158, 180, 195, 0.12);
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--blue), var(--green));
}

.engine-panel,
.source-panel,
.system-panel {
  min-height: 248px;
}

.engine-steps {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 13px;
}

.engine-step {
  display: grid;
  grid-template-columns: 34px 1fr;
  gap: 10px;
  align-items: center;
  min-height: 58px;
  padding: 9px;
  border: 1px solid rgba(40, 71, 93, 0.82);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.035);
}

.engine-step span:first-child {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: #9ed0ff;
  background: rgba(90, 156, 255, 0.1);
  border: 1px solid rgba(90, 156, 255, 0.28);
  font-weight: 800;
}

.engine-step strong {
  display: block;
  font-size: 12px;
}

.engine-step small {
  color: var(--muted);
  font-size: 11px;
}

.engine-card {
  display: grid;
  gap: 6px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid rgba(90, 156, 255, 0.38);
  border-radius: 7px;
  background: rgba(90, 156, 255, 0.08);
}

.engine-card span {
  color: var(--muted);
  font-size: 12px;
}

.source-list {
  display: grid;
  gap: 9px;
  margin-top: 12px;
}

.source-record {
  display: grid;
  grid-template-columns: minmax(130px, 0.7fr) minmax(240px, 1.3fr) 86px;
  gap: 12px;
  align-items: center;
  padding: 9px 10px;
  border: 1px solid rgba(40, 71, 93, 0.82);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.035);
  font-size: 12px;
}

.source-record span {
  color: var(--muted);
}

.system-list {
  display: grid;
  gap: 0;
  margin: 12px 0 0;
}

.system-list div {
  display: grid;
  grid-template-columns: minmax(130px, 0.8fr) minmax(190px, 1fr);
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(40, 71, 93, 0.82);
}

.system-list dt {
  color: var(--muted);
}

.system-list dd {
  margin: 0;
  color: var(--soft);
}

.simulation-actions {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-top: 13px;
}

.simulation-actions button {
  min-height: 36px;
  font-size: 12px;
}

.dashboard-footer {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 18px;
  align-items: center;
  margin-top: 14px;
  padding: 14px 16px 2px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 13px;
}

.agent-drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(520px, 100vw);
  padding: 18px;
  color: var(--text);
  background: rgba(8, 19, 29, 0.98);
  border-left: 1px solid var(--line-strong);
  box-shadow: -20px 0 55px rgba(0, 0, 0, 0.42);
  transform: translateX(105%);
  transition: transform 180ms ease;
  z-index: 60;
  overflow: auto;
}

.agent-drawer.is-open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.drawer-header h2 {
  margin-top: 4px;
  font-size: 25px;
}

#drawerClose {
  min-height: 34px;
  padding: 0 14px;
}

.drawer-section {
  margin-top: 16px;
  padding: 13px;
  border: 1px solid rgba(40, 71, 93, 0.82);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.035);
}

.drawer-section h3 {
  margin-bottom: 8px;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.drawer-section p,
.drawer-section li {
  color: var(--soft);
  font-size: 13px;
  line-height: 1.5;
}

.drawer-section ul {
  margin: 8px 0 0;
  padding-left: 18px;
}

.tooltip {
  position: fixed;
  z-index: 90;
  max-width: min(380px, calc(100vw - 28px));
  padding: 12px 13px;
  border: 1px solid rgba(90, 156, 255, 0.42);
  border-radius: 7px;
  color: var(--text);
  background: rgba(7, 16, 25, 0.98);
  box-shadow: 0 20px 48px rgba(0, 0, 0, 0.45);
  font-size: 12px;
  line-height: 1.45;
  pointer-events: none;
}

.tooltip strong {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
}

.tooltip dl {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 4px 8px;
  margin: 0;
}

.tooltip dt {
  color: var(--muted);
}

.tooltip dd {
  margin: 0;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translateX(-50%);
  z-index: 100;
  max-width: min(720px, calc(100vw - 32px));
  padding: 12px 16px;
  border: 1px solid rgba(49, 196, 107, 0.34);
  border-radius: 7px;
  color: var(--text);
  background: rgba(7, 23, 37, 0.97);
  box-shadow: var(--shadow);
  font-size: 13px;
}

svg text {
  fill: var(--muted);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 11px;
}

.grid-line {
  stroke: rgba(40, 71, 93, 0.82);
  stroke-width: 1;
}

.trend-line {
  fill: none;
  stroke-width: 3;
}

.trend-area {
  opacity: 0.13;
}

.trend-point {
  cursor: help;
  stroke: #071019;
  stroke-width: 2;
}

@media (max-width: 1500px) {
  .metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .table-panel,
  .chart-panel {
    min-height: auto;
  }
}

@media (max-width: 1050px) {
  .topbar,
  .mode-and-source,
  .source-banner {
    grid-template-columns: 1fr;
  }

  .status-block {
    align-items: flex-start;
  }

  .title-block {
    text-align: left;
  }

  .title-row,
  .cadence-row {
    justify-content: flex-start;
  }

  .metric-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .source-banner {
    gap: 12px;
  }
}

@media (max-width: 720px) {
  .dashboard-shell {
    width: min(calc(100% - 18px), var(--max));
    padding-top: 10px;
    overflow-x: clip;
  }

  .brand-name {
    font-size: 28px;
  }

  h1 {
    font-size: 25px;
    line-height: 1.15;
  }

  .title-row {
    align-items: flex-start;
  }

  .title-row h1 {
    flex: 1 1 100%;
    width: 100%;
    max-width: 340px;
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .title-block p {
    max-width: 340px;
    overflow-wrap: anywhere;
  }

  .cadence-row {
    max-width: 340px;
    justify-content: flex-start;
  }

  .source-item {
    align-items: flex-start;
    width: 100%;
  }

  .source-item strong {
    max-width: 260px;
    white-space: normal;
    overflow: visible;
    text-overflow: clip;
    overflow-wrap: anywhere;
  }

  .source-banner p {
    max-width: 340px;
    overflow-wrap: anywhere;
  }

  .metric-grid,
  .segmented,
  .engine-steps,
  .simulation-actions,
  .dashboard-footer,
  .donut-row {
    grid-template-columns: 1fr;
  }

  .metric-card {
    min-height: 82px;
  }

  .source-record {
    grid-template-columns: 1fr;
  }

  .system-list div {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .donut,
  .donut.small {
    width: min(210px, 68vw);
    justify-self: center;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
  }
}
