/* FlowMap — one stylesheet. Drafting-table look: warm paper, ink, one signal colour. */
:root {
  --bg: #f5f2ea;
  --surface: #fffdf8;
  --surface-2: #efeadf;
  --ink: #1f1d18;
  --muted: #6b665b;
  --line: #ddd6c6;
  --accent: #c2410c;
  --accent-ink: #ffffff;
  --accent-soft: #fde7d9;
  --ok: #2f7d46;
  --warn: #b7791f;
  --danger: #b42318;
  --info: #1d5fa8;
  --grid: rgba(31, 29, 24, 0.07);
  --shadow: 0 1px 2px rgba(31, 29, 24, .06), 0 6px 20px rgba(31, 29, 24, .06);
  --radius: 12px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "Cascadia Code", "SFMono-Regular", Consolas, monospace;

  /* step-type palette (also read by map.js) */
  --t-start: #2f7d46; --t-end: #b42318; --t-screen: #1d5fa8; --t-user_action: #6d3fc0;
  --t-automation: #0f766e; --t-decision: #b7791f; --t-wait: #6b665b; --t-integration: #a3307a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171b; --surface: #1d2025; --surface-2: #262a31; --ink: #ece8df; --muted: #a29d92;
    --line: #343941; --accent: #f97316; --accent-ink: #1b1209; --accent-soft: #3a2414;
    --ok: #4ade80; --warn: #fbbf24; --danger: #f87171; --info: #60a5fa; --grid: rgba(236, 232, 223, .06);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --t-start: #4ade80; --t-end: #f87171; --t-screen: #60a5fa; --t-user_action: #a78bfa;
    --t-automation: #2dd4bf; --t-decision: #fbbf24; --t-wait: #a29d92; --t-integration: #f472b6;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171b; --surface: #1d2025; --surface-2: #262a31; --ink: #ece8df; --muted: #a29d92;
  --line: #343941; --accent: #f97316; --accent-ink: #1b1209; --accent-soft: #3a2414;
  --ok: #4ade80; --warn: #fbbf24; --danger: #f87171; --info: #60a5fa; --grid: rgba(236, 232, 223, .06);
  --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  --t-start: #4ade80; --t-end: #f87171; --t-screen: #60a5fa; --t-user_action: #a78bfa;
  --t-automation: #2dd4bf; --t-decision: #fbbf24; --t-wait: #a29d92; --t-integration: #f472b6;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); min-height: 100vh; }
a { color: var(--accent); text-underline-offset: 2px; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5rem; letter-spacing: -.01em; }
h1 { font-size: 1.7rem; } h2 { font-size: 1.2rem; } h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* top bar */
.topbar { display: flex; align-items: center; gap: 1rem; padding: .6rem 1rem; border-bottom: 1px solid var(--line);
  background: var(--surface); position: sticky; top: 0; z-index: 20; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 800; color: var(--ink); text-decoration: none; letter-spacing: -.02em; }
.brand-mark { width: 26px; height: 26px; }
.topbar nav { display: flex; gap: .25rem; margin-left: auto; align-items: center; flex-wrap: wrap; }
.topbar nav a, .linkish { color: var(--muted); text-decoration: none; padding: .35rem .6rem; border-radius: 8px;
  background: none; border: 0; font: inherit; cursor: pointer; }
.topbar nav a:hover, .linkish:hover { color: var(--ink); background: var(--surface-2); }

main.page { max-width: 1040px; margin: 0 auto; padding: 1.5rem 1rem 3rem; }
main.wide { max-width: none; padding: 0; }

/* buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1rem;
  border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; min-height: 40px; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { color: var(--danger); }
.btn.small { padding: .3rem .6rem; min-height: 32px; font-size: .85rem; }
.btn[disabled] { opacity: .45; cursor: not-allowed; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
form.stack { display: grid; gap: .9rem; max-width: 480px; }
label { display: grid; gap: .3rem; font-weight: 600; font-size: .9rem; }
input[type=text], input[type=email], input[type=password], input:not([type]), select, textarea {
  width: 100%; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 9px; background: var(--surface);
  color: var(--ink); font: inherit; font-weight: 400; min-height: 40px; }
textarea { min-height: 80px; resize: vertical; }
.field-help { font-weight: 400; color: var(--muted); font-size: .85rem; }
.field-error { color: var(--danger); font-weight: 500; font-size: .85rem; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem 1rem; margin: 0; }
legend { font-weight: 600; font-size: .9rem; padding: 0 .3rem; }
.radio { display: flex; gap: .5rem; align-items: center; font-weight: 400; }

.alert { padding: .6rem .8rem; border-radius: 10px; border: 1px solid var(--line); background: var(--surface-2); margin-bottom: .75rem; }
.alert.error { border-color: var(--danger); color: var(--danger); }
.alert.success { border-color: var(--ok); color: var(--ok); }
.alert.info { border-color: var(--info); color: var(--info); }
.flashes { max-width: 1040px; margin: 1rem auto 0; padding: 0 1rem; }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem; box-shadow: var(--shadow); }
.grid-cards { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.project-card h2 { font-size: 1.05rem; } .project-card h2 a { color: var(--ink); text-decoration: none; }
.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .1rem .5rem; border-radius: 999px;
  font-size: .75rem; font-weight: 700; border: 1px solid var(--line); background: var(--surface-2); color: var(--muted); }
.badge.ok { color: var(--ok); border-color: currentColor; }
.page-head { display: flex; justify-content: space-between; align-items: end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.25rem; }

/* landing */
.hero { display: grid; gap: 2rem; grid-template-columns: 1.1fr 1fr; align-items: center; padding: 2rem 0; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.1rem); letter-spacing: -.03em; }
.hero .lead { font-size: 1.1rem; color: var(--muted); }
.hero-art { background: var(--surface) radial-gradient(var(--grid) 1.2px, transparent 1.2px) 0 0/18px 18px;
  border: 1px solid var(--line); border-radius: 18px; padding: 1.2rem; box-shadow: var(--shadow); }
.steps-demo { display: grid; gap: .55rem; }
.steps-demo .s { border-left: 4px solid var(--c); background: var(--surface); border-radius: 8px; padding: .45rem .7rem;
  box-shadow: var(--shadow); font-weight: 600; font-size: .92rem; }
.steps-demo .s small { display: block; color: var(--muted); font-weight: 500; }
.features { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); margin-top: 1rem; }

/* project workspace */
.workspace { display: grid; grid-template-columns: minmax(0, 1fr) 400px; height: calc(100vh - 53px); }
.map-wrap { position: relative; min-height: 0; border-right: 1px solid var(--line);
  background: var(--bg) radial-gradient(var(--grid) 1.2px, transparent 1.2px) 0 0/20px 20px; }
#map { position: absolute; inset: 0; }
.map-toolbar { position: absolute; top: .6rem; left: .6rem; right: .6rem; z-index: 5; display: flex; gap: .4rem;
  flex-wrap: wrap; align-items: center; pointer-events: none; }
.map-toolbar > * { pointer-events: auto; }
.map-title { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .3rem .7rem;
  box-shadow: var(--shadow); font-weight: 700; max-width: 40ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score { display: inline-flex; align-items: center; gap: .45rem; background: var(--surface); border: 1px solid var(--line);
  border-radius: 999px; padding: .25rem .7rem .25rem .3rem; box-shadow: var(--shadow); font-weight: 700; cursor: pointer; color: var(--ink); font: inherit; }
.score-ring { --p: 0; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: .7rem;
  background: conic-gradient(var(--score-color, var(--accent)) calc(var(--p) * 1%), var(--surface-2) 0); }
.score-ring span { width: 22px; height: 22px; border-radius: 50%; background: var(--surface); display: grid; place-items: center; }
.legend { position: absolute; left: .6rem; bottom: .6rem; z-index: 5; display: flex; flex-wrap: wrap; gap: .3rem .7rem;
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: .35rem .6rem; font-size: .75rem; color: var(--muted); max-width: calc(100% - 1.2rem); }
.legend i { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: .3rem; background: var(--c); }

.panel { background: var(--surface); overflow-y: auto; min-height: 0; }
.panel-inner { padding: 1rem 1.1rem 2rem; }
.sheet-handle { display: none; }
.panel-head { margin-bottom: 1rem; }
.panel-head h2 { font-size: 1.15rem; margin: .35rem 0 .15rem; overflow-wrap: anywhere; }
.type-chip { display: inline-flex; align-items: center; gap: .3rem; font-size: .72rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .04em; color: var(--c, var(--muted)); }
.type-chip::before { content: ""; width: 8px; height: 8px; border-radius: 2px; background: currentColor; }
.t-start { --c: var(--t-start); } .t-end { --c: var(--t-end); } .t-screen { --c: var(--t-screen); }
.t-user_action { --c: var(--t-user_action); } .t-automation { --c: var(--t-automation); } .t-decision { --c: var(--t-decision); }
.t-wait { --c: var(--t-wait); } .t-integration { --c: var(--t-integration); }

.question h3 { font-size: 1.15rem; margin-bottom: .25rem; }
.question .hint { color: var(--muted); font-size: .88rem; }
.tiles { display: grid; gap: .55rem; margin: .8rem 0; }
.tile { text-align: left; display: grid; gap: .2rem; padding: .7rem .85rem; border-radius: 12px; border: 1px solid var(--line);
  border-left: 4px solid var(--c, var(--line)); background: var(--surface); color: var(--ink); font: inherit; cursor: pointer;
  box-shadow: var(--shadow); transition: transform .08s ease, border-color .08s ease; }
.tile:hover { transform: translateY(-1px); border-color: var(--c, var(--accent)); }
.tile:active { transform: translateY(0); }
.tile strong { font-size: .97rem; overflow-wrap: anywhere; }
.tile .meta { font-size: .8rem; color: var(--muted); overflow-wrap: anywhere; }
.htmx-request .tile, .htmx-request.tile { opacity: .6; }
details { border-top: 1px solid var(--line); padding: .55rem 0; }
details > summary { cursor: pointer; font-weight: 600; list-style: none; display: flex; align-items: center; gap: .4rem; }
details > summary::before { content: "+"; width: 1.1rem; color: var(--accent); font-weight: 800; }
details[open] > summary::before { content: "–"; }
details > form, details > div { margin-top: .6rem; display: grid; gap: .6rem; }
.other { border: 1px dashed var(--line); border-radius: 12px; padding: .55rem .8rem; }
.edge-list { list-style: none; padding: 0; margin: .3rem 0 0; display: grid; gap: .3rem; }
.edge-list li { display: flex; justify-content: space-between; gap: .5rem; align-items: center; font-size: .88rem; }
.done { text-align: center; padding: 1.5rem .5rem; }
.done .big { font-size: 2.2rem; }
.issue-list { list-style: none; padding: 0; margin: .5rem 0; display: grid; gap: .5rem; }
.issue-list li { border: 1px solid var(--line); border-left: 4px solid var(--danger); border-radius: 10px; padding: .55rem .7rem; display: grid; gap: .35rem; }
.issue-list li.suggestion { border-left-color: var(--info); }

/* admin */
.stat-grid { display: grid; gap: .8rem; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); }
.stat { display: grid; gap: .1rem; }
.stat strong { font-size: 1.9rem; line-height: 1.1; }
.stat small { color: var(--muted); }
.table-wrap { overflow-x: auto; }
.settings-form { display: grid; gap: .7rem; }
.code-inline { font: .85rem var(--mono); background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  padding: .4rem .6rem; overflow-wrap: anywhere; max-width: 100%; }

/* comments */
.comments { border-top: 1px solid var(--line); margin-top: 1rem; padding-top: .8rem; }
.comment-list { list-style: none; padding: 0; margin: .4rem 0 .8rem; display: grid; gap: .5rem; }
.comment-list li { border: 1px solid var(--line); border-radius: 10px; padding: .5rem .65rem; }
.comment-list li.resolved { opacity: .6; }
.comment-list p { margin: .2rem 0 .4rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-meta { display: flex; gap: .4rem; align-items: center; flex-wrap: wrap; font-size: .85rem; }
.comment-form { display: grid; gap: .4rem; }
.comment-form textarea { min-height: 60px; }

/* simulation */
.sim { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr) 280px; align-items: start; }
.phone { max-width: 420px; margin: 0 auto; width: 100%; border: 10px solid var(--ink); border-radius: 34px; background: var(--surface);
  min-height: 460px; padding: 1.2rem 1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .8rem; }
.phone.other-actor { border-color: var(--muted); }
.phone .screen-title { font-size: 1.25rem; font-weight: 800; overflow-wrap: anywhere; }
.phone .fake-field { border: 1px solid var(--line); border-radius: 8px; padding: .5rem .6rem; color: var(--muted); font-size: .9rem; }
.phone .choices { margin-top: auto; display: grid; gap: .5rem; }
.trail { list-style: none; padding: 0; margin: 0; display: grid; gap: .3rem; font-size: .88rem; }
.trail li { border-left: 3px solid var(--c, var(--line)); padding-left: .5rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; text-align: center; }
.stats div { background: var(--surface-2); border-radius: 10px; padding: .6rem .3rem; }
.stats strong { display: block; font-size: 1.5rem; }

/* export */
.tabs { display: flex; gap: .3rem; flex-wrap: wrap; margin-bottom: .8rem; }
pre.code { background: var(--surface-2); border: 1px solid var(--line); border-radius: 10px; padding: .9rem; overflow: auto;
  font: .82rem/1.5 var(--mono); max-height: 480px; white-space: pre-wrap; overflow-wrap: anywhere; }
.export-grid { display: grid; gap: 1rem; }
table.versions { width: 100%; border-collapse: collapse; }
table.versions td, table.versions th { padding: .55rem .4rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.current-row { background: var(--accent-soft); }

/* responsive */
@media (max-width: 900px) {
  .hero { grid-template-columns: 1fr; padding-top: .5rem; }
  .sim { grid-template-columns: 1fr; }
  .workspace { display: block; height: auto; }
  .map-wrap { height: calc(100vh - 53px); height: calc(100dvh - 53px); border-right: 0; }
  .panel { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; max-height: 58vh; max-height: 58dvh;
    border-top: 1px solid var(--line); border-radius: 18px 18px 0 0; box-shadow: 0 -8px 28px rgba(0, 0, 0, .18);
    transition: max-height .2s ease; }
  .panel.collapsed { max-height: 64px; overflow: hidden; }
  .sheet-handle { display: flex; justify-content: center; align-items: center; gap: .5rem; width: 100%; padding: .55rem 0 .2rem;
    background: none; border: 0; color: var(--muted); font: inherit; font-size: .8rem; cursor: pointer; position: sticky; top: 0;
    background: var(--surface); z-index: 2; }
  .sheet-handle::before { content: ""; width: 42px; height: 5px; border-radius: 3px; background: var(--line); }
  .panel-inner { padding-top: .2rem; padding-bottom: 5rem; }
  .map-toolbar { flex-wrap: nowrap; overflow-x: auto; right: 0; padding-right: .6rem; scrollbar-width: none; }
  .map-toolbar::-webkit-scrollbar { display: none; }
  .map-toolbar > * { flex: 0 0 auto; }
  .map-title { max-width: 14ch; }
  .legend { display: none; }
  .topbar nav a.hide-sm { display: none; }
}
@media (max-width: 420px) {
  .topbar { gap: .4rem; padding: .5rem .6rem; }
  .stats strong { font-size: 1.2rem; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
