:root {
  color-scheme: dark;
  --bg: #0e1116;
  --panel: #151a22;
  --panel-2: #10151d;
  --line: #27313f;
  --text: #edf2f7;
  --muted: #8d99a8;
  --accent: #8fc7ff;
  --ok: #62d391;
  --warn: #f5bd5a;
  --bad: #f07178;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: #1c2430;
  color: var(--text);
  border-radius: 6px;
  min-height: 36px;
  padding: 0 12px;
  cursor: pointer;
}

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

button.primary {
  background: #1d3a55;
  border-color: #315d82;
}

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

input,
select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0f141c;
  color: var(--text);
  padding: 0 10px;
}

.topbar {
  height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  padding: 0 18px;
  background: #0b0f14;
}

.brand,
.authbar,
.panel-head,
.metric-row,
.action-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.authbar input {
  width: min(36vw, 420px);
}

.layout {
  height: calc(100vh - 86px);
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(480px, 1fr) minmax(320px, 420px);
  gap: 12px;
  padding: 12px;
}

.rail,
.workbench,
.trace {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: auto;
}

.panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 14px;
  min-width: 0;
}

.panel.stretch {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.panel-head {
  justify-content: space-between;
  margin-bottom: 12px;
}

h1,
h2 {
  margin: 0;
  font-weight: 650;
}

h1 {
  font-size: 20px;
}

h2 {
  font-size: 14px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: #202a36;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.pill.ok {
  color: var(--ok);
}

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

.pill.bad {
  color: var(--bad);
}

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

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

.metric {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-2);
  padding: 10px;
  min-height: 58px;
}

.metric small {
  display: block;
  color: var(--muted);
  margin-bottom: 6px;
}

.metric b {
  font-size: 18px;
}

.list {
  display: grid;
  gap: 8px;
  overflow: auto;
}

.list.horizontal {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.radar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 10px;
}

.pack-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 10px;
  max-height: 420px;
  overflow: auto;
}

.item {
  border: 1px solid var(--line);
  background: var(--panel-2);
  border-radius: 8px;
  padding: 12px;
  min-width: 0;
}

.item.selected {
  border-color: var(--accent);
}

.item h3 {
  margin: 0 0 8px;
  font-size: 15px;
  line-height: 1.3;
}

.item p {
  margin: 0 0 8px;
  color: #c9d3df;
  line-height: 1.35;
}

.pack-title {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

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

.policy-grid div {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #111720;
  padding: 8px;
  min-width: 0;
}

.policy-grid small,
.policy-grid span {
  display: block;
}

.policy-grid small {
  color: var(--muted);
  margin-bottom: 4px;
}

.policy-grid span {
  color: #c9d3df;
  overflow-wrap: anywhere;
}

.draft-text {
  white-space: pre-line;
  max-height: 220px;
  overflow: auto;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 7px;
  color: var(--muted);
  font-size: 12px;
}

.chip.ok {
  color: var(--ok);
}

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

.chip.bad {
  color: var(--bad);
}

.trace-detail {
  display: grid;
  gap: 10px;
}

.trace-step {
  border-left: 2px solid var(--line);
  padding-left: 10px;
}

.trace-step strong {
  display: block;
  margin-bottom: 4px;
}

.action-row {
  flex-wrap: wrap;
  margin-top: 10px;
}

.status {
  height: 28px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  padding: 0 12px;
  color: var(--muted);
  background: #0b0f14;
  font-size: 12px;
}

@media (max-width: 1100px) {
  .layout {
    grid-template-columns: 1fr;
    height: auto;
  }

  .panel.stretch {
    max-height: none;
  }

  .authbar input {
    width: 42vw;
  }
}

@media (max-width: 640px) {
  .topbar {
    height: auto;
    min-height: 72px;
    align-items: stretch;
    flex-direction: column;
    padding: 10px;
    gap: 8px;
  }

  .authbar {
    flex-wrap: wrap;
  }

  .authbar input {
    width: 100%;
  }

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