/* Preview portal styles. Bars: 44px targets, 4.5:1 text contrast, 8pt grid,
   rem type, reduced-motion support. Layouts: 1600px desktop, 390px phone. */
:root {
  --bg: #ffffff;
  --ink: #161616;
  --muted: #4d4d4d;
  --line: #d8d8d8;
  --wash: #f4f4f4;
  --accent: #003ecb;
  --accent-ink: #ffffff;
  --good: #0a5c1f;
  --warn-bg: #fff4d6;
  --warn-line: #8a5a00;
  --error: #a10000;
  --error-bg: #fdecec;
  --info-bg: #e8f0fe;
  --info-line: #003ecb;
  --radius: 8px;
  --gap: 8px;
}

* { box-sizing: border-box; }

html { font-size: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 1rem;
  line-height: 1.5;
}

main {
  max-width: 100rem;
  margin: 0 auto;
  padding: 1rem;
  display: grid;
  gap: 1rem;
}

.page-head {
  max-width: 100rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 0;
}

.page-head h1 {
  margin: 0;
  font-size: 1.5rem;
  line-height: 2rem;
}

.page-head p { margin: 0.25rem 0 0; }

.muted { color: var(--muted); }
.mono { font-family: ui-monospace, monospace; font-size: 0.875rem; word-break: break-all; }
.error-text { color: var(--error); font-weight: 600; }
.expired { color: var(--error); font-weight: 600; }

/* Status strip (C4 first: What / For-me / Next without scrolling). */
.strip {
  display: flex;
  flex-wrap: wrap;
  gap: var(--gap);
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 2.75rem;
  padding: 0.5rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--wash);
  font-size: 0.875rem;
}

.chip .dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #6b6b6b;
}

.chip.live .dot { background: var(--good); }
.chip.stale .dot { background: var(--warn-line); }
.chip.offline .dot { background: var(--error); }
.chip.idle { color: var(--muted); }

/* Banners: LNA reason, node unreachable/denied, action errors. */
.banner {
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  display: grid;
  gap: 0.5rem;
}

.banner p { margin: 0; }
.banner.info { background: var(--info-bg); border-left-color: var(--info-line); }
.banner.warn { background: var(--warn-bg); border-left-color: var(--warn-line); }
.banner.error { background: var(--error-bg); border-left-color: var(--error); }
.banner-actions { display: flex; flex-wrap: wrap; gap: var(--gap); }

/* Buttons + inputs: 44px minimum target. */
button, .button, select, input {
  font: inherit;
  min-height: 2.75rem;
}

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--accent);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

button.primary, .button.primary {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
}

button.ghost, .button.ghost { border-color: var(--line); color: var(--ink); }

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

select, input {
  padding: 0.5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--ink);
  max-width: 100%;
}

label { display: inline-grid; gap: 0.25rem; font-size: 0.875rem; }
label.inline { display: inline-flex; align-items: center; gap: 0.5rem; }

/* Sections (C4: builds primary, runners/services after). */
section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  display: grid;
  gap: 1rem;
  align-content: start;
}

.section-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
}

.section-head h2 { margin: 0; font-size: 1.25rem; }

.columns { display: grid; gap: 1rem; }

.empty {
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}

.empty p { margin: 0 0 0.5rem; }
.empty p:last-child { margin-bottom: 0; }
.empty .next { color: var(--muted); }

.count { margin: 0; color: var(--muted); font-size: 0.875rem; }

/* Build panels: one primary action per buildable (B4). */
.build-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  display: grid;
  gap: 0.5rem;
  background: var(--wash);
}

.build-panel h3 { margin: 0; font-size: 1rem; }
.build-controls { display: flex; flex-wrap: wrap; align-items: end; gap: var(--gap); }

/* Records. */
.record {
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  display: grid;
  gap: 0.5rem;
}

.record.phase-queued { border-left-color: #6b6b6b; }
.record.phase-building { border-left-color: var(--accent); }
.record.phase-done { border-left-color: var(--good); }
.record.phase-failed { border-left-color: var(--error); }

.record-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }

.phase {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0 0.5rem;
  border-radius: 999px;
  background: var(--wash);
  border: 1px solid var(--line);
  font-size: 0.875rem;
  font-weight: 600;
}

.record.phase-building .phase { animation: pulse 1.5s ease-in-out infinite; }

@keyframes pulse {
  50% { opacity: 0.55; }
}

.flag {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding: 0 0.5rem;
  border-radius: 999px;
  background: var(--error-bg);
  color: var(--error);
  border: 1px solid var(--error);
  font-size: 0.875rem;
  font-weight: 600;
}

.flag.stale { background: var(--warn-bg); color: var(--warn-line); border-color: var(--warn-line); }

.record-meta { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; font-size: 0.875rem; }
.record-actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--gap); }

/* Runs. */
.run {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.5rem 1rem;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1rem;
  margin-top: 0.5rem;
}

/* Tables. */
table { border-collapse: collapse; width: 100%; font-size: 0.875rem; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--line); }
th { font-weight: 600; }

/* Seed view (B1): explicit first step, never a dead page. */
.seed {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.5rem;
  display: grid;
  gap: 1rem;
  background: var(--wash);
}

.seed h2 { margin: 0; }
.seed p { margin: 0; }
.seed-controls { display: flex; flex-wrap: wrap; align-items: end; gap: var(--gap); }
.seed-controls label { flex: 1 1 16rem; }
.seed-controls input { width: 100%; }

code {
  font-family: ui-monospace, monospace;
  font-size: 0.875rem;
  background: var(--wash);
  padding: 0 0.25rem;
  border-radius: 4px;
}

/* C6: reduced motion disables the live pulse; updates batch as plain text. */
@media (prefers-reduced-motion: reduce) {
  .record.phase-building .phase { animation: none; }
  * { transition: none !important; }
}

/* 390px phone: single column, full-width controls. */
@media (max-width: 45rem) {
  main { padding: 0.5rem; }
  .seed-controls button, .seed-controls .button { flex: 1 1 100%; }
  .build-controls button, .build-controls .button { flex: 1 1 100%; }
  .record-actions button, .record-actions .button { flex: 1 1 auto; }
}

/* 1600px desktop: runners + services side by side. */
@media (min-width: 75rem) {
  .columns { grid-template-columns: 1fr 1fr; }
}
