:root {
  --ink: #1b1b1b;
  --muted: #5f6368;
  --line: #dadce0;
  --paper: #fff;
  --chrome: #f4f5f7;
  --accent: #1565c0;
  --accent-dark: #0d47a1;
  --danger: #8a1f1f;
  --danger-bg: #fdecec;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font: 13px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--chrome);
}

body {
  display: flex;
  flex-direction: column;
}

h1, h2, h3, h4, p { margin: 0; }

button, select { font: inherit; color: var(--ink); }

button {
  padding: 6px 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 4px;
  cursor: pointer;
}

button:hover { background: #f1f3f4; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

header {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

.title-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 20px;
  padding: 10px 16px 4px;
}

h1 { font-size: 15px; font-weight: 600; }

.family-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

select {
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--paper);
  min-width: 240px;
}

#summary { padding: 4px 16px 12px; }

#summary h2 { font-size: 14px; margin-bottom: 4px; }

.scope, .help, .hint, .parallel-note, #status, .diagnostic {
  color: var(--muted);
}

.scope { margin-top: 4px; }

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 24px;
  margin-top: 8px;
}

.meta div { flex: 1; min-width: 220px; }

.k {
  display: block;
  margin-bottom: 2px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

.workspace {
  display: flex;
  flex: 1;
  min-height: 0;
}

.questionnaire {
  width: 25%;
  min-width: 300px;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-right: 1px solid var(--line);
  min-height: 0;
}

.panel-title {
  padding: 10px 12px 0;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}

#questions-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

#questions { flex: 1; overflow: auto; padding: 8px 12px 12px; }

.q { margin: 0 0 14px; padding: 8px; border-radius: 4px; }

.q.invalid { background: var(--danger-bg); }

.qlabel { font-weight: 600; }

.help { margin: 4px 0 8px; }

.q-error { min-height: 0; color: var(--danger); }
.q-error:empty { display: none; }
.q-error:not(:empty) { margin-top: 6px; }

.segment {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 4px;
  overflow: hidden;
}

.segment label { padding: 6px 16px; cursor: pointer; }

.segment input { position: absolute; opacity: 0; width: 1px; height: 1px; }

.segment label:hover { background: #f4f5f7; }

.segment label:has(input:checked) {
  background: var(--accent);
  color: #fff;
}

.segment label:has(input:checked):hover { background: var(--accent-dark); }

.choices label {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  padding: 3px 0;
  cursor: pointer;
}

.generate-bar {
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--paper);
}

#form-alert { color: var(--danger); margin-bottom: 8px; }
#form-alert:empty { display: none; }

#generate {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}

#generate:hover { background: var(--accent-dark); }

.result {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--paper);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
}

[role="tablist"] { display: flex; gap: 6px; }

[role="tab"][aria-selected="true"] {
  background: #e8f0fe;
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

#status { flex: 1; }

#zoom { display: flex; gap: 6px; margin-left: auto; }
#zoom[hidden] { display: none; }
#zoom button { min-width: 34px; }

#stage { flex: 1; min-height: 0; position: relative; }
#stage.mode-flow { overflow: hidden; }
#stage.mode-plan { overflow: auto; }

#diagram { width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; background: #fff; }
#diagram.is-panning { cursor: grabbing; }
#diagram text { font-family: system-ui, -apple-system, "Segoe UI", sans-serif; }
#diagram .lane-label { font-size: 11px; font-weight: 600; }
#diagram .node-id { font-size: 11px; font-weight: 700; }
#diagram .node-title { font-size: 12px; fill: var(--ink); }
#diagram .edge { fill: none; stroke: #6b7280; stroke-width: 1.4; stroke-linejoin: miter; vector-effect: non-scaling-stroke; }
#diagram .edge.is-hot { stroke: var(--accent); stroke-width: 2; }
#diagram .card { fill: #fff; stroke: #d0d4d8; stroke-width: 1; vector-effect: non-scaling-stroke; }
#diagram .node.is-selected .card { stroke: var(--accent); stroke-width: 2; }
#diagram .node { cursor: pointer; }

.placeholder {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 24px;
  text-align: center;
  color: var(--muted);
}

.table-wrap { padding: 12px 16px 24px; }

.parallel-note { margin-bottom: 10px; }

table { border-collapse: collapse; min-width: 720px; }

th, td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

thead th {
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  background: var(--paper);
  position: sticky;
  top: 0;
}

tr.group th {
  background: var(--chrome);
  border-left: 4px solid var(--accent);
  font-size: 12px;
  letter-spacing: .04em;
  text-transform: uppercase;
}

td.activity, td.deliverable { min-width: 220px; }

tr[data-id] { cursor: pointer; }
tr[data-id]:hover { background: #f8f9fa; }
tr.is-selected { background: #e8f0fe; }

.id-link, .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
}

button.id-link {
  padding: 0 2px;
  border: 0;
  background: none;
  color: var(--accent);
}

button.id-link:hover { text-decoration: underline; background: none; }

#details {
  border-top: 1px solid var(--line);
  padding: 10px 14px;
  overflow: auto;
  background: #fafafa;
}

#details.open { max-height: 36%; }

#details h3 { font-size: 14px; margin: 2px 0 8px; }
#details h3:focus { outline: none; }

#details h4 {
  margin: 10px 0 4px;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 4px 24px;
}

#details ol, #details ul { margin: 0; padding-left: 18px; }

.pred-list { display: flex; flex-wrap: wrap; gap: 6px; }

.desktop-only { display: block; }
.mobile-only { display: none; }

@media (max-width: 760px) {
  html, body { height: 100%; font-size: 15px; }
  .desktop-only { display: none !important; }
  .mobile-only { display: block; }

  body {
    min-height: 100%;
    padding-bottom: env(safe-area-inset-bottom);
  }

  .workspace {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    height: calc(100vh - env(safe-area-inset-top));
    height: calc(100dvh - env(safe-area-inset-top));
  }

  body.mobile-wizard-active .workspace { height: 100dvh; }
  body.mobile-wizard-active .result { display: none !important; }
  body.mobile-result-active .result {
    display: flex !important;
    flex: 1;
    min-height: 0;
    flex-direction: column;
  }
  body.mobile-result-active #mobile-wizard { display: none !important; }

  #mobile-wizard {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    background: var(--paper);
    padding: max(12px, env(safe-area-inset-top)) 16px 16px;
  }

  .wizard-top {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 40px;
    margin-bottom: 8px;
  }

  .wizard-back {
    padding: 8px 12px;
    border: 0;
    background: transparent;
    color: var(--accent);
    font-weight: 600;
  }

  .wizard-progress {
    flex: 1;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
  }

  .wizard-viewport {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
  }

  .wizard-panel {
    height: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 0 16px;
  }

  .wizard-panel.is-enter-forward {
    animation: wizardInForward 0.28s ease;
  }
  .wizard-panel.is-enter-back {
    animation: wizardInBack 0.28s ease;
  }

  @keyframes wizardInForward {
    from { opacity: 0; transform: translateX(24px); }
    to { opacity: 1; transform: translateX(0); }
  }
  @keyframes wizardInBack {
    from { opacity: 0; transform: translateX(-24px); }
    to { opacity: 1; transform: translateX(0); }
  }

  @media (prefers-reduced-motion: reduce) {
    .wizard-panel.is-enter-forward,
    .wizard-panel.is-enter-back { animation: none; }
  }

  .wizard-title {
    font-size: 22px;
    font-weight: 600;
    line-height: 1.25;
    margin-bottom: 10px;
  }

  .wizard-help {
    color: var(--muted);
    margin-bottom: 20px;
    line-height: 1.45;
  }

  .wizard-options { display: flex; flex-direction: column; gap: 10px; }

  .wizard-option {
    width: 100%;
    text-align: left;
    padding: 16px 18px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--paper);
    font-size: 16px;
    line-height: 1.35;
  }

  .wizard-option:hover { background: #f8f9fa; }
  .wizard-option.is-selected {
    border-color: var(--accent);
    background: #e8f0fe;
    color: var(--accent-dark);
    font-weight: 600;
  }

  .wizard-family-card {
    width: 100%;
    text-align: left;
    padding: 18px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--paper);
  }

  .wizard-family-card h3 {
    font-size: 17px;
    margin-bottom: 6px;
  }

  .wizard-family-card p {
    color: var(--muted);
    line-height: 1.4;
  }

  .wizard-family-card.is-selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 1px var(--accent);
  }

  .mobile-result-bar {
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    background: var(--paper);
  }

  #edit-answers {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--paper);
    font-weight: 600;
  }

  .toolbar { flex-wrap: wrap; }
  [role="tab"] { padding: 8px 14px; min-height: 44px; }
  #stage.mode-plan { flex: 1; min-height: 0; overflow: auto; }
  #stage.mode-flow.is-vertical {
    flex: 1;
    min-height: 0;
    overflow: auto;
    touch-action: pan-x pan-y;
    -webkit-overflow-scrolling: touch;
  }
  #diagram.vertical {
    display: block;
    max-width: none;
    touch-action: auto;
    cursor: default;
  }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 640px; }
  #details.open { max-height: 40vh; flex-shrink: 0; }
  .detail-grid { grid-template-columns: 1fr; }
}
