/* ═══════════════════════════════════════════════════════════════════════
   Design language: quiet precision.

   No boxes. Structure comes from a vertical rail, whitespace, and a strict
   type scale — not from bordered cards. One jade accent, used only where it
   means something. Surfaces are warm off-white / near-black, following the
   system theme. Floating layers (popovers, dialogs) are the only elements
   allowed real depth, and they get glass.
   ═══════════════════════════════════════════════════════════════════════ */

:root {
  color-scheme: light dark;

  --bg: #faf9f7;
  --well: #f0efeb;            /* filled inputs, code, quiet surfaces */
  --well-hover: #e9e8e3;
  --ink: #191b1a;
  --ink-2: #4b504c;           /* secondary text */
  --muted: #8a8f8a;
  --hairline: rgb(25 27 26 / .10);
  --hairline-soft: rgb(25 27 26 / .06);

  --accent: #0e7a5f;          /* jade */
  --accent-hover: #0a6650;
  --accent-ink: #ffffff;
  --accent-tint: rgb(14 122 95 / .09);

  --ok: #0e7a5f;
  --err: #b3372b;
  --err-tint: rgb(179 55 43 / .08);
  --warn-tint: rgb(180 130 20 / .10);

  --glass: rgb(255 255 255 / .82);
  --shadow-pop:
    0 0 0 1px rgb(25 27 26 / .06),
    0 2px 8px rgb(25 27 26 / .06),
    0 24px 80px rgb(25 27 26 / .16);

  --r-sm: 9px;
  --r-md: 13px;
  --r-lg: 18px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e100f;
    --well: #1a1d1b;
    --well-hover: #212522;
    --ink: #e8eae7;
    --ink-2: #b0b5b0;
    --muted: #7c827c;
    --hairline: rgb(232 234 231 / .12);
    --hairline-soft: rgb(232 234 231 / .07);

    --accent: #38d0a2;
    --accent-hover: #4cdcb0;
    --accent-ink: #06130e;
    --accent-tint: rgb(56 208 162 / .10);

    --ok: #38d0a2;
    --err: #ef8577;
    --err-tint: rgb(239 133 119 / .10);
    --warn-tint: rgb(214 168 60 / .12);

    --glass: rgb(23 26 24 / .84);
    --shadow-pop:
      0 0 0 1px rgb(232 234 231 / .08),
      0 2px 8px rgb(0 0 0 / .5),
      0 24px 80px rgb(0 0 0 / .65);
  }
}

/* ── base ─────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }

body {
  margin: 0;
  padding: 0 1.5rem 7rem;
  background: var(--bg);
  color: var(--ink);
  font: 14.5px/1.6 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3 { margin: 0; font-weight: 620; letter-spacing: -0.02em; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .84em; }

::selection { background: var(--accent-tint); }

/* micro-label: the voice of the whole UI */
.eyebrow, label, th, .stat span, .step-summary {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* ── header ───────────────────────────────────────────────────────────── */
.top {
  max-width: 720px;
  margin: 0 auto;
  padding: 4.5rem 0 3.5rem;
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.5rem;
}

.brand .eyebrow { margin: 0 0 .5rem; }
.brand h1 { font-size: 2.1rem; line-height: 1.1; }
.brand .tagline { margin: .6rem 0 0; color: var(--ink-2); font-size: .95rem; max-width: 34rem; }

.top-actions { display: flex; gap: .5rem; align-items: center; }

.chip {
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--ink-2);
  border-radius: 999px;
  padding: .42rem .95rem;
  font: inherit;
  font-size: .8rem;
  cursor: pointer;
  white-space: nowrap;
  transition: all .15s ease;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }

/* ── the rail ─────────────────────────────────────────────────────────── */
main { max-width: 720px; margin: 0 auto; }

.steps {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}
.steps::before {
  content: "";
  position: absolute;
  left: 13px;
  top: 14px;
  bottom: 14px;
  width: 1px;
  background: var(--hairline);
}

.step {
  position: relative;
  padding: 0 0 3.25rem 3.25rem;
  transition: opacity .3s ease;
}
.step:last-child { padding-bottom: 0; }

.step-dot {
  position: absolute;
  left: 0;
  top: -1px;
  width: 27px;
  height: 27px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: .78rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  background: var(--bg);
  color: var(--muted);
  box-shadow: inset 0 0 0 1px var(--hairline);
  transition: all .3s ease;
}

.step-head {
  display: flex;
  align-items: baseline;
  gap: 1rem;
  min-height: 27px;
}
.step-head h2 { font-size: 1.15rem; }
.step-summary {
  margin-left: auto;
  text-align: right;
  letter-spacing: .04em;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.edit-btn { display: none; flex: none; }

.step-body { padding-top: 1.1rem; }

/* states — the rail tells the story */
.step[data-state="locked"] { opacity: .38; }
.step[data-state="locked"] .step-body { display: none; }

.step[data-state="idle"] .step-body { display: block; }

.step[data-state="active"] .step-dot {
  background: var(--ink);
  color: var(--bg);
  box-shadow: none;
}

.step[data-state="done"] .step-body { display: none; }
.step[data-state="done"] .step-dot {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: none;
  font-size: 0;
}
.step[data-state="done"] .step-dot::before { content: "✓"; font-size: .85rem; }
.step[data-state="done"] .step-summary { color: var(--ink-2); }
.step[data-state="done"] .edit-btn { display: inline-block; }

.step.open .step-body { display: block; }

/* gentle reveal when a body appears */
.step[data-state="active"] .step-body,
.step.open .step-body {
  animation: reveal .3s ease both;
}
@keyframes reveal {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: none; }
}

/* ── forms: filled, borderless, calm ─────────────────────────────────── */
label { display: block; margin: 0 0 .45rem; }

input:not([type=checkbox]):not([type=file]), select {
  width: 100%;
  padding: .62rem .8rem;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: var(--well);
  color: var(--ink);
  font: inherit;
  font-size: .93rem;
  transition: background .15s ease, box-shadow .15s ease;
}
input:not([type=checkbox]):hover, select:hover { background: var(--well-hover); }
input:focus-visible, select:focus-visible, button:focus-visible, .dropzone:focus-within {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.1rem 1.25rem;
  margin: 1.1rem 0;
}
.row { margin: 1.1rem 0; }

.checks { display: flex; flex-wrap: wrap; gap: .6rem 1.6rem; margin: 1.1rem 0 0; }
.check {
  display: flex; align-items: center; gap: .5rem;
  font-size: .88rem; font-weight: 450; letter-spacing: 0; text-transform: none;
  color: var(--ink); margin: 0;
}
.check input { accent-color: var(--accent); width: 15px; height: 15px; }

/* ── buttons ──────────────────────────────────────────────────────────── */
button {
  font: inherit;
  font-size: .89rem;
  font-weight: 550;
  border-radius: var(--r-sm);
  border: none;
  background: var(--well);
  color: var(--ink);
  padding: .6rem 1.15rem;
  cursor: pointer;
  transition: all .15s ease;
}
button:hover:not(:disabled) { background: var(--well-hover); }
button:active:not(:disabled) { transform: translateY(1px); }
button:disabled { opacity: .4; cursor: default; }

button.primary { background: var(--accent); color: var(--accent-ink); }
button.primary:hover:not(:disabled) { background: var(--accent-hover); }

button.secondary { background: var(--accent-tint); color: var(--accent); }
button.secondary:hover:not(:disabled) { background: var(--accent-tint); filter: brightness(.96); }

button.ghost { background: transparent; color: var(--muted); font-weight: 500; }
button.ghost:hover:not(:disabled) { color: var(--accent); background: var(--accent-tint); }

button.tiny { padding: .32rem .7rem; font-size: .8rem; }
button.danger { background: var(--err); color: #fff; }

.actions { display: flex; align-items: center; gap: .65rem; flex-wrap: wrap; margin-top: 1.35rem; }
.run-actions button.primary, .run-actions button.secondary { padding: .7rem 1.7rem; font-size: .95rem; }

.status { font-size: .87rem; color: var(--ink-2); }
.status.ok { color: var(--ok); }
.status.err { color: var(--err); }
.status.busy { color: var(--muted); }
.status.busy::before {
  content: ""; display: inline-block; width: .75em; height: .75em; margin-right: .5em;
  border: 1.5px solid var(--hairline); border-top-color: var(--accent);
  border-radius: 50%; vertical-align: -.05em;
  animation: spin .65s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── dropzone ─────────────────────────────────────────────────────────── */
.dropzone {
  display: grid;
  justify-items: center;
  gap: .35rem;
  padding: 2.4rem 1rem;
  border-radius: var(--r-lg);
  background: var(--well);
  cursor: pointer;
  text-align: center;
  transition: all .18s ease;
  letter-spacing: 0;
  text-transform: none;
}
.dropzone:hover, .dropzone.drag { background: var(--accent-tint); }
.dropzone.drag { outline: 1.5px dashed var(--accent); outline-offset: -8px; }
.dropzone input { display: none; }
.dz-icon { color: var(--accent); margin-bottom: .2rem; }
.dz-text { font-size: .97rem; font-weight: 450; color: var(--ink); }
.dz-text strong { font-weight: 620; }
.dz-sub { color: var(--muted); font-size: .8rem; font-weight: 450; }

/* ── notes & banners ──────────────────────────────────────────────────── */
.hint { font-size: .84rem; color: var(--muted); margin: .8rem 0 0; }

.banner {
  border-radius: var(--r-md);
  padding: .95rem 1.15rem;
  margin: 1.2rem 0 0;
  font-size: .88rem;
  background: var(--warn-tint);
  color: var(--ink);
}
.banner.danger { background: var(--err-tint); }
.banner.danger strong { color: var(--err); }
.banner .check { margin-top: .7rem; }

/* ── tables ───────────────────────────────────────────────────────────── */
.table-scroll {
  overflow-x: auto;
  margin-top: 1.2rem;
  border-radius: var(--r-md);
  box-shadow: inset 0 0 0 1px var(--hairline-soft);
}

table { border-collapse: collapse; font-size: .855rem; width: 100%; }
th, td {
  padding: .55rem .85rem;
  text-align: left;
  white-space: nowrap;
  max-width: 26ch;
  overflow: hidden;
  text-overflow: ellipsis;
  border-bottom: 1px solid var(--hairline-soft);
}
tr:last-child td { border-bottom: none; }
th { position: sticky; top: 0; background: var(--bg); }
.pop th { background: transparent; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
td.null { color: var(--muted); font-style: italic; }

.mapping td { white-space: normal; max-width: none; }
.mapping select { font-size: .855rem; padding: .38rem .55rem; }
.map-key { text-align: center; }

.type-tag {
  display: inline-block;
  padding: .05rem .45rem;
  border-radius: 999px;
  background: var(--well);
  font-size: .72rem;
  font-weight: 550;
  letter-spacing: .02em;
  color: var(--muted);
}

/* ── results: numbers, not boxes ──────────────────────────────────────── */
.stats {
  display: flex;
  flex-wrap: wrap;
  margin: 1.6rem 0 .4rem;
}
.stat {
  padding: 0 1.6rem 0 0;
  margin: 0 1.6rem .8rem 0;
  border-right: 1px solid var(--hairline-soft);
}
.stat:last-child { border-right: none; }
.stat b {
  display: block;
  font-size: 1.7rem;
  font-weight: 650;
  line-height: 1.15;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.stat.good b { color: var(--ok); }
.stat.bad b { color: var(--err); }

pre {
  background: var(--well);
  border-radius: var(--r-sm);
  padding: .85rem 1rem;
  overflow-x: auto;
  font-size: .78rem;
  line-height: 1.55;
  margin: .8rem 0 0;
}

details { margin-top: 1.2rem; }
summary { cursor: pointer; font-size: .87rem; color: var(--muted); }
summary:hover { color: var(--ink); }

ul.errors { margin: .7rem 0 0; padding-left: 1.2rem; font-size: .84rem; }
ul.errors li { margin-bottom: .25rem; }

.inline { display: flex; gap: .45rem; align-items: center; }

/* ── floating layers: the only depth in the app ──────────────────────── */
.pop {
  border: none;
  border-radius: var(--r-lg);
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px) saturate(1.5);
  backdrop-filter: blur(24px) saturate(1.5);
  color: var(--ink);
  box-shadow: var(--shadow-pop);
  padding: 1.6rem 1.75rem 1.75rem;
  width: min(480px, calc(100vw - 2rem));
  margin: auto;
  /* Never taller than the viewport: long content scrolls inside the panel. */
  max-height: calc(100dvh - 2.5rem);
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* A long field list scrolls within its own region, so the Apply/Create button
   below it stays visible instead of drifting off-screen. */
#schemaProposal .table-scroll,
#driversList .table-scroll {
  max-height: min(30vh, 18rem);
  overflow-y: auto;
}
.pop.wide { width: min(640px, calc(100vw - 2rem)); }
.pop h3 { font-size: 1.05rem; margin-bottom: .4rem; }

[popover]::backdrop, dialog::backdrop {
  background: rgb(10 12 11 / .30);
}

[popover], dialog {
  opacity: 0;
  transform: translateY(10px) scale(.985);
  transition:
    opacity .2s ease, transform .2s ease,
    overlay .2s allow-discrete, display .2s allow-discrete;
}
[popover]:popover-open, dialog[open] { opacity: 1; transform: none; }
@starting-style {
  [popover]:popover-open, dialog[open] { opacity: 0; transform: translateY(10px) scale(.985); }
}

dialog {
  border: none;
  border-radius: var(--r-lg);
  background: var(--glass);
  -webkit-backdrop-filter: blur(24px) saturate(1.5);
  backdrop-filter: blur(24px) saturate(1.5);
  color: var(--ink);
  box-shadow: var(--shadow-pop);
  padding: 1.7rem 1.8rem;
  width: min(430px, calc(100vw - 2rem));
  max-height: calc(100dvh - 2.5rem);
  overflow-y: auto;
  overscroll-behavior: contain;
}
dialog h3 { font-size: 1.05rem; }
dialog p { font-size: .9rem; color: var(--ink-2); white-space: pre-line; }
dialog .actions { justify-content: flex-end; margin-top: 1.5rem; }

/* ── small screens ────────────────────────────────────────────────────── */
@media (max-width: 560px) {
  .top { flex-direction: column; align-items: flex-start; padding-top: 3rem; }
  .step { padding-left: 2.6rem; }
  .step-summary { display: none; }
}
