/* iAuto Machine cloud app. Same look as the Phase I page (public/app.css). */
:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --ink: #1d232b;
  --muted: #69707a;
  --line: #dedad3;
  --accent: #315f9a;
  --accent-ink: #ffffff;
  --accent-soft: #e5edf7;
  --ok: #2f7d4f;
  --warn: #a8641a;
  --bad: #b3372f;
  --paper: #ffffff;
  --pen: #1b2a4a;
  --radius: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15181c;
    --panel: #1e2227;
    --ink: #e8e6e2;
    --muted: #9aa1aa;
    --line: #333940;
    --accent: #7aa7e0;
    --accent-ink: #0f1520;
    --accent-soft: #24303f;
    --ok: #5fb383;
    --warn: #e0a35a;
    --bad: #ec7b72;
    --paper: #fbfaf7;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overflow-x: hidden;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
code { background: var(--accent-soft); padding: 0 4px; border-radius: 4px; font-size: .92em; }
h2 { font-size: 1.05rem; margin: 0 0 6px; }
h3 { font-size: .98rem; margin: 0 0 6px; }
.muted { color: var(--muted); }
.hint { color: var(--muted); margin: 0 0 12px; font-size: .92rem; }
.loading { text-align: center; margin-top: 15vh; }

/* ---------------------------------------------------------------- top bar */
.topbar {
  display: flex; align-items: center; gap: 12px 16px; flex-wrap: wrap;
  padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 650; font-size: 1.05rem; white-space: nowrap; }
.brand svg { width: 26px; height: 26px; fill: none; stroke: var(--accent); stroke-width: 3; stroke-linecap: round; }
.brand.big { font-size: 1.4rem; justify-content: center; margin-bottom: 8px; }
.brand.big svg { width: 36px; height: 36px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; min-width: 0; flex: 1 1 auto; scrollbar-width: thin; }
.tabs a {
  color: var(--muted); padding: 7px 12px; border-radius: 8px; text-decoration: none; white-space: nowrap;
}
.tabs a:hover { color: var(--ink); background: var(--accent-soft); }
.tabs a[aria-current="page"] { background: var(--accent-soft); color: var(--ink); font-weight: 600; }
.who { display: flex; align-items: center; gap: 10px; font-size: .9rem; margin-left: auto; min-width: 0; }
.who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 260px; }

/* ------------------------------------------------------------------ pages */
main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; min-width: 0; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.stack { display: grid; gap: 20px; max-width: 1000px; margin: 0 auto; }
.coming-soon { max-width: 640px; margin: 10vh auto 0; text-align: center; }

.signin { max-width: 440px; margin: 10vh auto 0; text-align: center; display: grid; gap: 10px; }
.signin p { margin: 0; }
.dev-login { margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); display: grid; gap: 10px; text-align: left; }
button.wide { width: 100%; padding: 12px; font-size: 1rem; }

label { display: flex; flex-direction: column; gap: 5px; font-size: .88rem; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--ink); }
label.check input { width: auto; }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; width: 100%; min-width: 0;
}
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.row-inline { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row-inline.end { justify-content: flex-end; }
.row-inline > label { flex: 1 1 180px; }

button {
  font: inherit; cursor: pointer; border-radius: 8px; padding: 8px 14px;
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
}
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
button.ghost:hover:not(:disabled) { background: var(--accent-soft); }
button.icon { padding: 2px 10px; font-size: 1.1rem; line-height: 1.2; }
button.danger { color: var(--bad); }
button.small { padding: 4px 10px; font-size: .85rem; }
button.link { border: 0; background: none; color: var(--accent); padding: 0; text-decoration: underline; }
.file-btn {
  flex: 0 0 auto !important; flex-direction: row; display: inline-flex; cursor: pointer; align-items: center;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 14px; color: var(--ink);
}
.file-btn:hover { background: var(--accent-soft); }
.file-btn input { display: none; }

.status { min-height: 1.4em; font-size: .92rem; margin: 0; }
.status.ok { color: var(--ok); }
.status.bad { color: var(--bad); }
.status.warn { color: var(--warn); }
.badge {
  display: inline-block; font-size: .78rem; padding: 1px 8px; border-radius: 999px;
  background: var(--accent-soft); color: var(--ink); vertical-align: middle;
}
.badge.off { background: var(--line); color: var(--muted); }

details summary { cursor: pointer; font-size: .92rem; }
details[open] summary { margin-bottom: 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip {
  border: 1px solid var(--line); border-radius: 999px; padding: 2px 10px; font-size: .82rem;
  background: var(--panel); color: var(--ink); cursor: pointer;
}
.chip:hover { background: var(--accent-soft); }
.font-chip { display: inline-flex; align-items: center; gap: 4px; cursor: default; }
.font-chip button { border: 0; padding: 0 4px; background: none; color: var(--muted); }
.font-chip button:hover { color: var(--bad); }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 20;
  max-width: min(560px, calc(100vw - 32px)); padding: 10px 16px; border-radius: 10px;
  background: var(--ink); color: var(--bg); box-shadow: 0 6px 24px rgba(0, 0, 0, .25);
}
.toast.bad { background: var(--bad); color: #fff; }
.toast.ok { background: var(--ok); color: #fff; }
.toast.warn { background: var(--warn); color: var(--bg); }

/* ------------------------------------------------------------------ write */
.write { display: grid; grid-template-columns: minmax(300px, 420px) 1fr; gap: 20px; align-items: start; }
.controls { display: flex; flex-direction: column; gap: 14px; position: sticky; top: 76px; }
.message { font-size: 1rem; min-height: 170px; }
.wording { background: var(--bg); border-radius: 8px; padding: 10px 12px; font-size: .92rem; white-space: pre-wrap; color: var(--ink); }
.actions { justify-content: flex-end; }
.actions .copies { flex: 0 0 auto; flex-direction: row; align-items: center; gap: 6px; margin-right: auto; }
.actions .copies input { width: 70px; }
.preview-panel { min-height: 420px; display: flex; flex-direction: column; gap: 12px; }
.preview-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.pager { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--muted); }
.preview {
  flex: 1; display: grid; place-items: center; padding: 18px; border-radius: 8px; min-height: 300px;
  background: repeating-linear-gradient(45deg, transparent 0 12px, rgba(127,127,127,.04) 12px 24px);
}
.preview svg { width: 100%; height: auto; max-height: 72vh; overflow: visible; }
.preview.busy svg { opacity: .55; transition: opacity .2s; }
.sheet { fill: var(--paper); filter: drop-shadow(0 2px 8px rgba(0,0,0,.15)); }
.margin { fill: none; stroke: #8fb0d8; stroke-width: .25; stroke-dasharray: 1.5 1.5; }
.ink { fill: none; stroke: var(--pen); stroke-linecap: round; stroke-linejoin: round; }
.empty { color: var(--muted); text-align: center; max-width: 360px; }
.warnings { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: .9rem; }
.warnings li { color: var(--warn); }

/* ------------------------------------------------- lists, tables, editors */
.cards { display: grid; gap: 12px; margin-top: 12px; }
.card-row { border: 1px solid var(--line); border-radius: 8px; padding: 12px; display: grid; gap: 8px; }
.card-row header { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; }
.card-row.retired { opacity: .7; }
.sample { background: var(--paper); border-radius: 6px; padding: 6px 10px; min-height: 40px; }
.sample svg { width: 100%; height: auto; max-height: 64px; }
.coverage { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .85rem; word-break: break-all; color: var(--ink); }

.table-wrap { overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; font-size: .92rem; }
table.list th { text-align: left; color: var(--muted); font-weight: 500; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.list td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list td.actions-cell { text-align: right; white-space: nowrap; }
table.list tr.retired td { color: var(--muted); }
table.list select { width: auto; }

.editor { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.editor form { display: grid; gap: 12px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; border-radius: 0; padding: 5px 12px; }
.seg button.on { background: var(--accent); color: var(--accent-ink); }

.variation { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; align-items: start; }
.sliders { display: grid; gap: 10px; }
.slider { display: grid; grid-template-columns: 1fr 140px 56px; align-items: center; gap: 10px; font-size: .9rem; }
.slider span:first-child { color: var(--ink); }
.slider output { text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; }
.slider input { padding: 0; border: 0; accent-color: var(--accent); }
.mini-preview { background: var(--paper); border-radius: 8px; padding: 10px; position: sticky; top: 80px; min-height: 60px; }
.mini-preview svg { width: 100%; height: auto; }

dialog {
  border: 1px solid var(--line); border-radius: 12px; padding: 0; width: min(640px, calc(100vw - 32px));
  background: var(--panel); color: var(--ink); max-height: calc(100vh - 32px);
}
dialog::backdrop { background: rgba(0, 0, 0, .35); }
dialog form { padding: 20px; display: grid; gap: 14px; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px 12px; margin: 0; min-width: 0; }
legend { font-size: .88rem; color: var(--muted); padding: 0 4px; }

@media (max-width: 860px) {
  main { padding: 12px 16px; }
  .topbar { padding: 8px 16px; }
  .tabs { order: 3; flex-basis: 100%; }
  .write, .editor, .variation { grid-template-columns: 1fr; }
  .controls { position: static; }
  .grid3, .grid4 { grid-template-columns: 1fr 1fr; }
  .slider { grid-template-columns: 1fr 110px 50px; }
  .who span { max-width: 160px; }
}

@media (max-width: 600px) {
  /* Every page tab stays in sight on a phone: they wrap instead of scrolling sideways. */
  .tabs { flex-wrap: wrap; overflow-x: visible; }
  .who { flex-wrap: wrap; }
  .who span { white-space: normal; overflow-wrap: anywhere; max-width: none; }
}

@media (max-width: 480px) {
  .grid2 { grid-template-columns: 1fr; }
}
