:root {
  color-scheme: light;
  --ink: #1c2230;
  --muted: #646c7d;
  --paper: #f3f4f8;
  --surface: #ffffff;
  --line: #d2d6e0;
  --indigo: #4b4aa1;
  --indigo-dark: #363571;
  --teal: #137b75;
  --green: #28734f;
  --amber: #9d620e;
  --red: #a13b4c;
  --blue: #2f6696;
  --shadow: 0 10px 28px rgba(45, 46, 83, 0.1);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(75, 74, 161, 0.25);
  outline-offset: 2px;
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 0 24px;
  color: #ffffff;
  background: #202039;
  border-bottom: 3px solid #6ec5bd;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.brand strong {
  font-size: 18px;
}

.brand span {
  overflow: hidden;
  color: #d8d8e8;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.icon-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  color: inherit;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 6px;
  text-decoration: none;
}

.icon-link:hover {
  background: rgba(255, 255, 255, 0.1);
}

.icon-link svg {
  width: 19px;
  height: 19px;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
}

.app-grid {
  display: grid;
  grid-template-columns: minmax(390px, 450px) minmax(0, 1fr);
  min-height: calc(100vh - 58px);
}

.controls {
  min-width: 0;
  padding: 24px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.workspace {
  min-width: 0;
  padding: 24px;
}

h1 {
  margin: 0;
  font-size: 23px;
}

.intro {
  margin: 5px 0 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.scenario-row,
.actions,
.result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.scenario-row {
  margin-bottom: 17px;
}

.secondary,
.primary,
.remove-sensor {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 7px 11px;
  border-radius: 5px;
  font-weight: 800;
  cursor: pointer;
}

.secondary,
.remove-sensor {
  color: var(--ink);
  background: #ffffff;
  border: 1px solid var(--line);
}

.secondary:hover {
  color: #ffffff;
  background: var(--teal);
  border-color: var(--teal);
}

.remove-sensor {
  min-height: 31px;
  padding: 4px 8px;
  color: var(--red);
  font-size: 11px;
}

.primary {
  width: 100%;
  min-height: 45px;
  margin-top: 4px;
  color: #ffffff;
  background: var(--indigo);
  border: 1px solid var(--indigo);
}

.primary:hover {
  background: var(--indigo-dark);
}

.sensor-table {
  width: 100%;
  margin-bottom: 15px;
  border-collapse: collapse;
}

.sensor-table th,
.sensor-table td {
  padding: 5px 4px;
  text-align: left;
  font-size: 11px;
}

.sensor-table th {
  color: var(--muted);
  text-transform: uppercase;
}

.sensor-table input {
  width: 100%;
  min-width: 0;
  min-height: 36px;
  padding: 7px 8px;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid #b8bdc9;
  border-radius: 4px;
}

.sensor-table .sensor-id {
  min-width: 64px;
}

.sensor-table .remove-cell {
  width: 1%;
  white-space: nowrap;
}

.settings {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
  margin: 16px 0;
}

.field label {
  display: block;
  margin-bottom: 6px;
  color: #3e4353;
  font-size: 12px;
  font-weight: 800;
}

.field input {
  width: 100%;
  min-height: 39px;
  padding: 8px 9px;
  color: var(--ink);
  background: #ffffff;
  border: 1px solid #b8bdc9;
  border-radius: 5px;
}

.privacy {
  margin: 11px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.form-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-left: 3px solid var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12px;
  line-height: 1.45;
}

.empty {
  display: grid;
  place-items: center;
  min-height: 70vh;
  color: var(--muted);
  text-align: center;
}

.empty strong {
  display: block;
  margin-bottom: 7px;
  color: var(--ink);
  font-size: 21px;
}

.sensor-visual {
  position: relative;
  width: min(100%, 480px);
  height: 170px;
  margin: 0 auto 20px;
}

.sensor-visual::before,
.sensor-visual::after {
  position: absolute;
  left: 50%;
  content: "";
  transform: translateX(-50%);
}

.sensor-visual::before {
  top: 30px;
  width: 300px;
  height: 2px;
  background: #aeb4c1;
  box-shadow: 0 50px 0 #aeb4c1, 0 100px 0 #aeb4c1;
}

.sensor-visual::after {
  top: 16px;
  width: 16px;
  height: 16px;
  background: var(--teal);
  border: 4px solid #ffffff;
  border-radius: 50%;
  box-shadow:
    -105px 50px 0 -4px #ffffff,
    -105px 50px 0 0 var(--teal),
    112px 50px 0 -4px #ffffff,
    112px 50px 0 0 var(--red),
    34px 100px 0 -4px #ffffff,
    34px 100px 0 0 var(--teal);
}

.results-shell {
  max-width: 1100px;
  margin: 0 auto;
}

.result-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 17px;
}

.result-head h2 {
  margin: 0;
  font-size: 25px;
}

.result-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.decision {
  flex: 0 0 auto;
  padding: 7px 10px;
  color: #ffffff;
  background: var(--amber);
  border-radius: 5px;
  font-size: 12px;
  font-weight: 900;
}

.decision.commit { background: var(--green); }
.decision.escalate { background: var(--red); }

.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: var(--shadow);
}

.metric {
  min-width: 0;
  padding: 15px;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.metric span {
  display: block;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.metric strong {
  overflow-wrap: anywhere;
  font-size: 18px;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(280px, 0.8fr);
  gap: 17px;
  margin-top: 17px;
}

.panel {
  min-width: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 7px;
  box-shadow: var(--shadow);
}

.panel-header {
  min-height: 48px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-header h3 {
  margin: 0;
  font-size: 15px;
}

.panel-body {
  padding: 14px;
}

.plot {
  width: 100%;
  height: 290px;
  background: #f8f9fc;
  border: 1px solid #dce0e8;
  border-radius: 5px;
}

.decision-note {
  padding: 12px;
  margin-top: 12px;
  color: #4b4f5e;
  background: #f2f1fa;
  border-left: 3px solid var(--indigo);
  border-radius: 3px;
  font-size: 13px;
  line-height: 1.5;
}

.probe-list {
  display: grid;
  gap: 9px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.probe-list li {
  padding: 10px;
  background: #eef7f5;
  border-left: 3px solid var(--teal);
  border-radius: 3px;
  font-size: 13px;
  line-height: 1.4;
}

.table-wrap {
  overflow: auto;
}

.trace-table {
  width: 100%;
  min-width: 700px;
  border-collapse: collapse;
}

.trace-table th,
.trace-table td {
  padding: 9px;
  text-align: left;
  border-bottom: 1px solid #e1e4ea;
  font-size: 12px;
}

.trace-table th {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
}

.flag {
  color: var(--red);
  font-weight: 900;
}

.scope {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

@media (max-width: 1020px) {
  .app-grid,
  .dashboard-grid {
    grid-template-columns: 1fr;
  }

  .controls {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 650px) {
  .topbar {
    padding: 0 14px;
  }

  .brand span {
    display: none;
  }

  .controls,
  .workspace {
    padding: 18px 14px;
  }

  .settings,
  .metrics {
    grid-template-columns: 1fr;
  }

  .metric {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .metric:last-child {
    border-bottom: 0;
  }

  .result-head {
    flex-direction: column;
  }
}
