:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0f1214;
  color: #edf2f7;
  --panel: #171c20;
  --panel-2: #11171d;
  --line: #2b3541;
  --muted: #9ca8b8;
  --text: #edf2f7;
  --blue: #66a8ff;
  --green: #77d38a;
  --amber: #e9b65f;
  --red: #ff7a7a;
  --violet: #b694ff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: #0f1214;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  min-height: 42px;
  border: 1px solid #3a4654;
  border-radius: 8px;
  background: #202833;
  color: var(--text);
  padding: 0 16px;
  cursor: pointer;
}

button:hover {
  border-color: var(--blue);
}

button:disabled {
  color: #697484;
  cursor: not-allowed;
}

.ghost {
  background: #151b22;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #303a46;
  border-radius: 8px;
  background: #10161d;
  color: var(--text);
  padding: 11px 12px;
}

textarea {
  min-height: 138px;
  resize: vertical;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.shell {
  width: min(1680px, 100%);
  margin: 0 auto;
  padding: 28px;
}

.topbar,
.auth-strip,
.status-line,
.panel,
.metric {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
}

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

.brand img {
  width: 260px;
  max-width: 45vw;
  height: auto;
}

.brand div {
  display: grid;
  gap: 3px;
}

.brand strong {
  font-size: clamp(23px, 3vw, 34px);
  line-height: 1.05;
}

.brand span,
.muted {
  color: var(--muted);
}

.top-actions,
.head-actions,
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.pill {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  justify-content: center;
  border: 1px solid #3b4855;
  border-radius: 999px;
  color: #dfe7ef;
  padding: 0 14px;
  font-weight: 700;
  letter-spacing: 0;
}

.pill.ok {
  color: var(--green);
  border-color: rgba(119, 211, 138, 0.45);
}

.pill.warn {
  color: var(--amber);
  border-color: rgba(233, 182, 95, 0.45);
}

.pill.error {
  color: var(--red);
  border-color: rgba(255, 122, 122, 0.45);
}

.auth-strip {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 240px auto auto;
  gap: 12px;
  margin-top: 16px;
  padding: 14px;
}

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

.metric {
  display: grid;
  gap: 8px;
  padding: 15px;
  min-height: 88px;
}

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

.metric strong {
  font-size: 23px;
  line-height: 1.1;
}

.status-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 16px;
  padding: 12px 14px;
  color: var(--muted);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(420px, 1.2fr) minmax(320px, 0.95fr) minmax(320px, 0.95fr);
  grid-template-areas:
    "intake decision dispatch"
    "intake route maintenance";
  gap: 16px;
  margin-top: 16px;
}

.panel {
  min-width: 0;
  overflow: hidden;
}

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

.panel h1,
.panel h2 {
  margin: 0;
  line-height: 1.1;
}

.panel h1 {
  font-size: 28px;
}

.panel h2 {
  font-size: 22px;
}

.intake-panel {
  grid-area: intake;
}

.decision-panel {
  grid-area: decision;
}

.dispatch-panel {
  grid-area: dispatch;
}

.route-panel {
  grid-area: route;
}

.maintenance-panel {
  grid-area: maintenance;
}

.dense-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 16px;
}

.wide {
  grid-column: span 2;
}

.intake-panel > label,
.toggle-row {
  padding: 0 16px 16px;
}

.check {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 9px;
  color: var(--text);
}

.check input {
  width: auto;
}

.trace,
.dispatch-card,
.route-list,
.trigger-list {
  padding: 16px;
}

.empty {
  color: var(--muted);
}

.trace-grid {
  display: grid;
  gap: 12px;
}

.trace-card,
.candidate-card,
.trigger-card,
.route-stop {
  border: 1px solid #283441;
  background: var(--panel-2);
  border-radius: 8px;
  padding: 13px;
}

.trace-card {
  display: grid;
  gap: 9px;
}

.trace-card strong,
.candidate-card strong,
.trigger-card strong,
.route-stop strong {
  display: block;
  margin-bottom: 5px;
}

.kv {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 8px;
  color: var(--muted);
}

.kv b {
  color: var(--text);
}

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

.chip {
  border: 1px solid #344150;
  border-radius: 999px;
  color: #cbd5e1;
  padding: 6px 10px;
  font-size: 13px;
}

.route-stop {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  margin-bottom: 10px;
}

.seq {
  width: 30px;
  height: 30px;
  border-radius: 999px;
  background: #263649;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  color: var(--blue);
}

.risk {
  color: var(--red);
}

.good {
  color: var(--green);
}

.warn {
  color: var(--amber);
}

@media (max-width: 1180px) {
  .workspace {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "intake intake"
      "decision dispatch"
      "route maintenance";
  }
}

@media (max-width: 760px) {
  .shell {
    padding: max(14px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom));
  }

  .topbar,
  .brand {
    align-items: flex-start;
  }

  .topbar {
    flex-direction: column;
  }

  .brand {
    width: 100%;
    justify-content: space-between;
  }

  .brand img {
    width: min(210px, 48vw);
  }

  .auth-strip,
  .metric-grid,
  .workspace,
  .dense-grid {
    grid-template-columns: 1fr;
  }

  .workspace {
    grid-template-areas:
      "intake"
      "decision"
      "dispatch"
      "route"
      "maintenance";
  }

  .wide {
    grid-column: auto;
  }

  .panel-head {
    align-items: flex-start;
    flex-direction: column;
  }
}
