@import url('https://fonts.googleapis.com/css2?family=DM+Mono:wght@400;500&family=Manrope:wght@400;600;700&family=Newsreader:opsz,wght@6..72,500;6..72,600&display=swap');

:root {
  color-scheme: light;
  --ink: #172321;
  --ink-soft: #29413b;
  --muted: #687874;
  --paper: #f4f5ef;
  --card: #fffef9;
  --line: #d9dfd7;
  --line-dark: #48635b;
  --teal: #0c746d;
  --teal-dark: #07564f;
  --mint: #dceee8;
  --amber: #d8953b;
  --amber-soft: #f7ead2;
  --red: #b84c42;
  --red-soft: #fae6e0;
  --shadow: 0 16px 40px rgba(22, 51, 45, .08);
  --shadow-deep: 0 24px 70px rgba(22, 51, 45, .18);
}

*, *::before, *::after { box-sizing: border-box; }

button, input, select, textarea { font: inherit; }
button, a, input, select, textarea, summary { -webkit-tap-highlight-color: transparent; }

html { min-width: 320px; scroll-behavior: smooth; }

body {
  overflow-x: hidden;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font: 15px/1.55 Manrope, system-ui, sans-serif;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  font-synthesis: none;
}

body::before {
  position: fixed;
  z-index: -1;
  inset: 0;
  pointer-events: none;
  content: "";
  opacity: .16;
  background-image: radial-gradient(#55736c .55px, transparent .55px);
  background-size: 7px 7px;
}

a { color: inherit; }
.skip-link { position: fixed; z-index: 10; top: 10px; left: 10px; padding: 10px 14px; color: white; background: var(--ink); transform: translateY(-150%); transition: transform .15s ease; }
.skip-link:focus { transform: translateY(0); }
button { min-height: 42px; cursor: pointer; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(216, 149, 59, .65);
  outline-offset: 3px;
}

.topbar {
  position: relative;
  z-index: 1;
  display: flex;
  height: 72px;
  align-items: center;
  justify-content: space-between;
  padding: 0 clamp(22px, 5vw, 76px);
  border-bottom: 1px solid var(--line);
  background: rgba(244, 245, 239, .86);
  backdrop-filter: blur(12px);
}

.brand {
  color: var(--ink);
  font: 500 18px/1 'DM Mono', monospace;
  letter-spacing: -1.2px;
  text-decoration: none;
}

.brand span { padding: 0 3px; color: var(--amber); }
.topbar nav { display: flex; align-items: center; gap: 18px; }
.page { width: min(1220px, 100%); margin: 0 auto; padding: clamp(42px, 7vw, 90px) clamp(22px, 5vw, 76px); }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { text-wrap: balance; }
h1 { margin-bottom: 24px; font: 600 clamp(44px, 7vw, 84px)/.95 Newsreader, Georgia, serif; letter-spacing: -3px; }
h1 em, h2 em { color: var(--teal); font-style: italic; }
h2 { margin-bottom: 18px; font: 600 34px/1 Newsreader, Georgia, serif; letter-spacing: -1px; }
h3 { margin: 24px 0 5px; font-size: 21px; line-height: 1.15; }
.eyebrow { margin-bottom: 15px; color: var(--teal); font: 500 11px/1.2 'DM Mono', monospace; letter-spacing: 1.6px; }
.lede { max-width: 540px; color: var(--muted); font-size: 17px; }
.muted { color: var(--muted); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.breadcrumb { display: flex; align-items: center; gap: 9px; margin-bottom: 18px; color: var(--muted); font: 11px 'DM Mono', monospace; }
.breadcrumb a { color: var(--teal); text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb strong { color: var(--ink); font-weight: 500; }
.hero, .case-title { display: flex; align-items: end; justify-content: space-between; gap: 24px; }
.signal { padding-bottom: 15px; color: var(--teal); font: 11px 'DM Mono', monospace; }
.signal span { color: var(--muted); }
.section-head { margin: 80px 0 20px; border-bottom: 1px solid var(--line); }
.section-head h2 { margin-bottom: 15px; }
.archive-filter { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin: 0 0 20px; }
.archive-filter > label { min-width: 220px; }
.archive-filter > div { display: flex; align-items: center; gap: 14px; width: min(520px, 100%); }
.archive-filter input { flex: 1; }

.case-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(255px, 1fr)); gap: 16px; }
.case-card, .empty, .new-case, .panel, .login-card { border: 1px solid var(--line); background: var(--card); box-shadow: var(--shadow); }
.case-card { min-height: 245px; padding: 24px; color: inherit; text-decoration: none; transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease; }
.case-card:hover { transform: translateY(-4px); border-color: var(--teal); box-shadow: var(--shadow-deep); }
.case-meta, .artifact-row, .job-row { display: flex; align-items: center; gap: 12px; }
.case-meta { justify-content: space-between; color: var(--muted); font: 11px 'DM Mono', monospace; text-transform: uppercase; }
.case-card p { color: var(--muted); }
.mini-track { display: flex; gap: 5px; margin: 34px 0 17px; }
.mini-track i { display: block; width: 18px; height: 4px; background: var(--line); }
.mini-track i.done { background: var(--teal); }
.arrow, .link-button { color: var(--teal); font-size: 12px; }
.empty { grid-column: 1 / -1; padding: 42px; }

.new-case { display: grid; grid-template-columns: 1fr 1.1fr; gap: 50px; margin-top: 72px; padding: clamp(24px, 4vw, 48px); }
.new-case h2 { font-size: 45px; }
.new-case form, .login-card form { display: grid; gap: 16px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; }
input, select, textarea { width: 100%; border: 0; border-bottom: 1px solid #aebbb5; outline: 0; color: var(--ink); background: transparent; }
input, select { padding: 10px 0; }
textarea { min-height: 84px; padding: 10px 0; resize: vertical; }
input::placeholder { color: #9aa9a3; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--teal); }
input:user-invalid, select:user-invalid, textarea:user-invalid { border-color: var(--red); }
button:disabled { cursor: not-allowed; opacity: .5; }
input[type="file"] { padding: 10px 0 12px; font-size: 12px; }
.check-label { display: flex; align-items: center; gap: 9px; min-height: 42px; }
.check-label input { flex: none; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }

button { padding: 11px 15px; border: 1px solid var(--line); color: var(--ink); background: transparent; font-weight: 700; font-size: 12px; }
button:hover { border-color: var(--teal); color: var(--teal); }
.quiet:hover { color: var(--teal); }
.primary { display: flex; align-items: center; justify-content: space-between; border-color: var(--teal); color: white; background: var(--teal); }
.primary:hover { border-color: var(--teal-dark); color: white; background: var(--teal-dark); }
.quiet { padding: 8px 0; border: 0; }
.login-card { max-width: 560px; margin: 7vh auto; padding: clamp(28px, 6vw, 65px); }
.login-card h1 { font-size: clamp(44px, 7vw, 72px); }
.login-card .primary { margin-top: 12px; }
.alert { padding: 12px; color: var(--red); background: var(--red-soft); font-size: 13px; }
.not-found { text-align: center; }
.not-found .lede { margin-right: auto; margin-left: auto; }
.not-found .button-link { width: fit-content; min-width: 190px; margin: 24px auto 0; }

.pipeline { display: grid; grid-template-columns: repeat(8, 1fr); margin: 60px 0 28px; border-top: 1px solid var(--line); }
.pipe-step { min-width: 0; padding: 14px 8px; border-top: 3px solid transparent; color: var(--muted); }
.pipe-step.active { border-color: var(--teal); color: var(--ink); }
.pipe-step small { display: block; color: var(--amber); font: 11px 'DM Mono', monospace; }
.pipe-step strong { display: block; overflow: hidden; font: 12px 'DM Mono', monospace; text-overflow: ellipsis; }
.pipe-step[aria-current="step"] { border-color: var(--teal); color: var(--ink); }
.panel { padding: 26px; }
.next-step { display: flex; align-items: center; justify-content: space-between; gap: 28px; margin-bottom: 18px; border-color: var(--teal); }
.next-step h2 { margin-bottom: 8px; }
.next-step p:last-child { max-width: 580px; margin-bottom: 0; color: var(--muted); }
.next-step.is-updated { animation: state-pulse .75s ease-out; }
.next-action { min-width: 210px; }
.upload-form { display: flex; align-items: center; gap: 12px; }
.upload-form input[type="file"] { min-width: 190px; }
.button-link { display: flex; align-items: center; justify-content: space-between; text-decoration: none; }
.complete-mark { display: grid; width: 48px; height: 48px; place-items: center; border-radius: 50%; color: var(--teal); background: var(--mint); font-size: 24px; }
.connection-status { margin-left: 8px; color: var(--muted); font-size: 9px; letter-spacing: 0; }
.connection-status.live::before { color: var(--teal); content: '● '; }
.connection-status.offline { color: var(--amber); }
.connection-status.offline::before { content: '◌ '; }
.secondary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.disclosure { margin-bottom: 18px; }
.disclosure summary { display: flex; align-items: center; justify-content: space-between; cursor: pointer; list-style: none; }
.disclosure summary::-webkit-details-marker { display: none; }
.disclosure summary h2 { margin-bottom: 0; }
.disclosure summary .eyebrow { margin-bottom: 8px; }
.disclosure-mark { color: var(--teal); font: 24px 'DM Mono', monospace; }
.disclosure[open] .disclosure-mark { transform: rotate(45deg); }
.artifact-list, .config-form { margin-top: 20px; }
.advanced { margin-top: 0; }
.advanced .stage-actions { grid-template-columns: repeat(4, 1fr); }
.disclosure-static { margin-top: 0; }
.panel-head { margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.panel h2 { font-size: 28px; }
.artifact-row { min-height: 66px; padding: 17px 0; border-bottom: 1px solid #e6e9e2; }
.artifact-row.is-updated { animation: state-flash .9s ease-out; }
.artifact-row > div { min-width: 0; flex: 1; }
.artifact-row small { display: block; overflow: hidden; color: var(--muted); font: 10px 'DM Mono', monospace; text-overflow: ellipsis; white-space: nowrap; }
.artifact-dot, .job-mark { width: 9px; height: 9px; flex: none; border-radius: 50%; background: var(--line); }
.artifact-dot.done, .job-mark.done { background: var(--teal); }
.status-pill { padding: 4px 7px; font: 10px 'DM Mono', monospace; }
.status-pill.ok { color: var(--teal); background: var(--mint); }
.status-pill.pending { color: var(--muted); background: #eef0e9; }
.link-button { padding: 4px 8px; }
.candidate-list { display: grid; gap: 8px; max-height: 52vh; overflow: auto; margin: 20px 0; padding: 0; border: 0; }
.candidate-card { display: grid; grid-template-columns: auto 1fr; gap: 12px; padding: 13px; border: 1px solid var(--line); cursor: pointer; }
.candidate-card:hover, .candidate-card.is-selected { border-color: var(--teal); background: var(--mint); }
.candidate-card input { width: auto; margin-top: 4px; }
.candidate-content { display: grid; gap: 4px; }
.candidate-content small, .candidate-reason { color: var(--muted); font-size: 11px; }
.candidate-reason { line-height: 1.4; }
.feasibility-blocked { border-left: 4px solid var(--red); }
.feasibility-gap { border-left: 4px solid var(--amber); }
.feasibility-feasible, .feasibility-today { border-left: 4px solid var(--teal); }
.emit-summary { min-height: 20px; color: var(--teal); font: 11px 'DM Mono', monospace; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 18px; }

.stage-actions { display: grid; gap: 8px; margin-top: 22px; }
.stage-actions button { color: var(--paper); border-color: var(--line-dark); text-align: left; }
.stage-actions button:hover { border-color: #9dd2bd; color: white; background: var(--ink-soft); }
.hitl-form { display: grid; gap: 12px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line-dark); }
.hitl-form input { color: var(--paper); border-color: var(--line-dark); }
.hitl-form button { color: var(--paper); border-color: var(--line-dark); }
.good { color: var(--teal); }
.notice { min-height: 18px; margin-top: 15px; color: #a9d6c2; font: 11px 'DM Mono', monospace; }

.jobs { margin-top: 18px; }
.job-row { display: block; padding: 13px 0; border-bottom: 1px solid var(--line); font-size: 12px; }
.job-row summary { display: flex; align-items: center; gap: 12px; cursor: pointer; list-style: none; }
.job-row summary::-webkit-details-marker { display: none; }
.job-row summary strong { width: 100px; font: 13px 'DM Mono', monospace; }
.job-row summary span:nth-child(3) { color: var(--muted); }
.job-row time { margin-left: auto; color: var(--muted); font: 10px 'DM Mono', monospace; }
.job-row pre { max-height: 260px; overflow: auto; margin: 14px 0 0; padding: 14px; color: var(--muted); background: #eef0e9; font: 11px/1.5 'DM Mono', monospace; white-space: pre-wrap; }
.job-mark.running { animation: status-pulse 1.4s ease-in-out infinite; background: var(--amber); }
.is-loading button { cursor: wait; opacity: .65; }
.notice { transition: opacity .2s ease; }

@keyframes state-pulse { 0% { box-shadow: 0 0 0 0 rgba(12, 116, 109, .18); } 100% { box-shadow: 0 0 0 16px rgba(12, 116, 109, 0); } }
@keyframes state-flash { 0% { background: var(--mint); } 100% { background: transparent; } }
@keyframes status-pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(216, 149, 59, .25); } 50% { box-shadow: 0 0 0 6px rgba(216, 149, 59, 0); } }

dialog { width: min(900px, 90vw); max-width: calc(100vw - 32px); height: min(700px, 85vh); max-height: calc(100vh - 32px); margin: auto; padding: clamp(20px, 4vw, 32px); border: 1px solid var(--line); color: var(--ink); background: var(--card); box-shadow: var(--shadow-deep); }
dialog::backdrop { background: rgba(23, 35, 33, .6); }
dialog pre { height: calc(100% - 145px); overflow: auto; margin: 18px 0 0; padding: 16px 0; border: 1px solid var(--line); background: #f0f2eb; color: var(--ink-soft); font: 12px/1.65 'DM Mono', monospace; white-space: pre; counter-reset: line; }
.preview-line { display: block; min-height: 1.65em; padding: 0 18px 0 58px; position: relative; }
.preview-line::before { position: absolute; left: 0; width: 42px; padding-right: 12px; color: #9aa9a3; content: counter(line); counter-increment: line; text-align: right; user-select: none; }
.preview-path { overflow: hidden; margin: -10px 0 0; color: var(--muted); font: 10px 'DM Mono', monospace; text-overflow: ellipsis; white-space: nowrap; }
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; margin-top: 18px; color: var(--muted); font: 10px 'DM Mono', monospace; }
.preview-output { min-height: 180px; }
.provider-output { min-height: 180px; margin: 0; padding: 18px; border: 1px solid var(--line); overflow: auto; background: #f0f2eb; color: var(--ink-soft); font: 12px/1.65 'DM Mono', monospace; white-space: pre-wrap; }
.dialog-close { float: right; }
dialog h2 { margin-top: 10px; }
dialog .primary:disabled { cursor: not-allowed; opacity: .45; }

@supports not selector(.candidate-card:has(input:checked)) {
  .candidate-card.is-selected { border-color: var(--teal); background: var(--mint); }
}

@media (max-width: 760px) {
  .page { padding-top: 38px; }
  .hero, .case-title { display: block; }
  .signal { margin-top: 25px; }
  .new-case { grid-template-columns: 1fr; gap: 25px; }
  .archive-filter { align-items: stretch; flex-direction: column; }
  .archive-filter > div { width: 100%; }
  .next-step, .secondary-grid { display: block; }
  .next-action { min-width: 0; margin-top: 20px; }
  .upload-form { align-items: stretch; flex-direction: column; }
  .upload-form input[type="file"] { min-width: 0; }
  .advanced .stage-actions { grid-template-columns: 1fr 1fr; }
  .new-case h2 { font-size: 38px; }
  .pipeline { overflow-x: auto; grid-template-columns: repeat(8, 100px); margin-top: 40px; }
  .pipe-step { padding-bottom: 10px; }
  .job-row time { display: none; }
  dialog { width: calc(100vw - 24px); max-width: none; height: calc(100vh - 24px); max-height: none; }
  dialog pre { font-size: 11px; }
  dialog .preview-line { padding-right: 12px; padding-left: 48px; white-space: pre-wrap; overflow-wrap: anywhere; }
}

@media (max-width: 480px) {
  .topbar { height: 62px; }
  h1 { letter-spacing: -2px; }
  .form-row { grid-template-columns: 1fr; gap: 16px; }
  .panel { padding: 20px; }
  .topbar nav { gap: 10px; }
  .artifact-row { align-items: flex-start; }
  .status-pill { display: none; }
  .dialog-actions { align-items: stretch; flex-direction: column-reverse; }
  .dialog-actions button { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
  .case-card { transition: none; }
}
