:root {
  --ink: #172321;
  --muted: #64706d;
  --paper: #f4f6f3;
  --surface: #ffffff;
  --line: #d9dfda;
  --line-strong: #bcc8c0;
  --brand: #135f4b;
  --brand-dark: #0d4537;
  --brand-soft: #e3f1eb;
  --accent: #ba6b25;
  --danger: #a12d33;
  --danger-soft: #f9e6e7;
  --warning: #8b5a12;
  --warning-soft: #fff2d8;
  --success: #176641;
  --success-soft: #e1f4e9;
  --shadow: 0 12px 32px rgba(23, 35, 33, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--paper); }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--brand); }

.skip-link {
  position: fixed;
  left: 1rem;
  top: -4rem;
  z-index: 100;
  padding: .7rem 1rem;
  color: white;
  background: var(--brand-dark);
  border-radius: .35rem;
}
.skip-link:focus { top: 1rem; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px minmax(420px, 1fr) minmax(300px, 390px);
  grid-template-rows: auto 1fr;
  grid-template-areas: "top top top" "nav main trace";
}

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 76px;
  padding: .8rem 1.2rem;
  color: white;
  background: var(--brand-dark);
  border-bottom: 3px solid var(--accent);
}
.brand-block { display: flex; align-items: center; gap: .8rem; }
.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  font: 800 1.3rem/1 Georgia, serif;
  color: var(--brand-dark);
  background: #f3e3ca;
  border-radius: 50%;
}
.brand-block h1 { margin: .1rem 0 0; font-size: 1.12rem; letter-spacing: .01em; }
.eyebrow { margin: 0; font-size: .7rem; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.topbar .eyebrow { color: #b8d4ca; }
.runtime-strip { display: flex; align-items: center; justify-content: flex-end; gap: .45rem; flex-wrap: wrap; }

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: .3rem .65rem;
  border: 1px solid rgba(255,255,255,.24);
  border-radius: 999px;
  font-size: .76rem;
  font-weight: 700;
  white-space: nowrap;
}
.status-pill::before { content: ""; width: 7px; height: 7px; margin-right: .42rem; border-radius: 50%; background: currentColor; }
.status-neutral { color: #d2dcda; }
.status-good { color: #9ce0bb; }
.status-warn { color: #ffd18c; }
.status-bad { color: #ff9da2; }

.journey-nav {
  grid-area: nav;
  padding: 1.3rem .8rem;
  background: #e8ece8;
  border-right: 1px solid var(--line-strong);
}
.nav-label { margin: 0 .65rem .65rem; color: var(--muted); font-size: .72rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.journey-nav > a {
  display: block;
  margin: .2rem 0;
  padding: .72rem .8rem;
  color: var(--ink);
  text-decoration: none;
  border-left: 3px solid transparent;
  border-radius: 0 .35rem .35rem 0;
}
.journey-nav > a:hover { background: rgba(255,255,255,.65); }
.journey-nav > a.active { color: var(--brand-dark); background: var(--surface); border-left-color: var(--accent); font-weight: 750; box-shadow: 0 2px 10px rgba(23,35,33,.05); }
.nav-note { margin: 1.4rem .6rem; padding: .8rem; color: var(--muted); background: rgba(255,255,255,.55); border: 1px solid var(--line); border-radius: .45rem; font-size: .78rem; line-height: 1.45; }
.nav-note strong { display: block; color: var(--ink); margin-bottom: .25rem; }

.workspace { grid-area: main; min-width: 0; padding: 1.5rem; overflow: auto; }
.diagnostics { grid-area: trace; min-width: 0; padding: 1.1rem; background: #202927; color: #eaf0ed; overflow: auto; border-left: 1px solid #111917; }
.diagnostics.collapsed { display: none; }
.app-shell.trace-collapsed { grid-template-columns: 220px minmax(420px, 1fr); grid-template-areas: "top top" "nav main"; }
.diagnostics-header { display: flex; align-items: center; justify-content: space-between; gap: .8rem; }
.diagnostics h2 { margin: .1rem 0; font-size: 1rem; }
.diagnostics .eyebrow { color: #91aaa3; }
.diagnostics-help { color: #9eb0ab; font-size: .74rem; line-height: 1.4; }

.view-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.1rem; }
.view-heading h2 { margin: .12rem 0 .3rem; font: 700 1.65rem/1.2 Georgia, serif; }
.view-heading p { max-width: 700px; margin: 0; color: var(--muted); line-height: 1.5; }
.section-heading { display: flex; align-items: center; justify-content: space-between; gap: .8rem; margin: 1.5rem 0 .65rem; }
.section-heading h3 { margin: 0; font-size: 1.05rem; }

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.card { padding: 1rem; background: var(--surface); border: 1px solid var(--line); border-radius: .55rem; box-shadow: 0 3px 12px rgba(23,35,33,.035); }
.card h3, .card h4 { margin: 0 0 .55rem; }
.card p { color: var(--muted); line-height: 1.45; }
.card-inset { background: #f7f9f7; box-shadow: none; }
.card-danger { border-color: #e6b6b9; background: #fffafa; }
.card-warning { border-color: #ecd39d; background: #fffcf5; }
.metric { display: block; margin-top: .25rem; font-size: 1.2rem; font-weight: 800; }
.metric-small { font-size: .9rem; overflow-wrap: anywhere; }

.button-row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: .5rem .8rem;
  color: white;
  background: var(--brand);
  border: 1px solid var(--brand);
  border-radius: .35rem;
  font-weight: 750;
  cursor: pointer;
}
.button:hover { background: var(--brand-dark); }
.button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, a:focus-visible { outline: 3px solid #e3a858; outline-offset: 2px; }
.button:disabled { opacity: .52; cursor: not-allowed; }
.button-secondary { color: var(--brand-dark); background: var(--surface); border-color: var(--brand); }
.button-secondary:hover { color: white; }
.button-danger { background: var(--danger); border-color: var(--danger); }
.button-danger:hover { background: #792126; }
.button-quiet { color: inherit; background: transparent; border-color: currentColor; }
.button-quiet:hover { color: white; background: rgba(255,255,255,.12); }
.button-small { min-height: 30px; padding: .3rem .55rem; font-size: .76rem; }
.count { display: inline-grid; place-items: center; min-width: 1.35rem; height: 1.35rem; margin-left: .35rem; padding: 0 .25rem; color: var(--brand-dark); background: #dbe9e4; border-radius: 999px; font-size: .7rem; }

.field { display: grid; gap: .32rem; margin-bottom: .8rem; }
.field label, .field-label { font-size: .8rem; font-weight: 750; }
.field-hint { color: var(--muted); font-size: .74rem; line-height: 1.35; }
input, select, textarea { width: 100%; padding: .58rem .65rem; color: var(--ink); background: white; border: 1px solid var(--line-strong); border-radius: .35rem; }
textarea { min-height: 110px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .8rem; line-height: 1.5; }
input[type="checkbox"] { width: auto; accent-color: var(--brand); }
.check-field { display: flex; align-items: flex-start; gap: .55rem; margin: .8rem 0; }
.check-field label { line-height: 1.4; }
fieldset { margin: 0; padding: 0; border: 0; }
fieldset + fieldset { margin-top: 1.2rem; padding-top: 1.2rem; border-top: 1px solid var(--line); }
legend { margin-bottom: .8rem; font-size: .95rem; font-weight: 800; }

.definition-list { display: grid; grid-template-columns: minmax(120px, .5fr) 1fr; gap: .45rem .8rem; margin: 0; font-size: .85rem; }
.definition-list dt { color: var(--muted); }
.definition-list dd { margin: 0; overflow-wrap: anywhere; }
.issue-list { display: grid; gap: .5rem; margin: .7rem 0 0; padding: 0; list-style: none; }
.issue { padding: .65rem .75rem; background: var(--warning-soft); border-left: 3px solid var(--warning); border-radius: .2rem; }
.issue strong { display: block; color: var(--warning); font-size: .78rem; }
.issue span { display: block; margin-top: .2rem; font-size: .82rem; line-height: 1.4; }
.empty-state { padding: 1.2rem; color: var(--muted); background: rgba(255,255,255,.55); border: 1px dashed var(--line-strong); border-radius: .45rem; text-align: center; }
.inline-message { padding: .7rem .8rem; border-radius: .35rem; font-size: .82rem; line-height: 1.45; }
.message-good { color: var(--success); background: var(--success-soft); }
.message-warn { color: var(--warning); background: var(--warning-soft); }
.message-bad { color: var(--danger); background: var(--danger-soft); }

.profile-list { display: grid; gap: .55rem; }
.profile-option { display: flex; align-items: center; justify-content: space-between; gap: .7rem; padding: .75rem; border: 1px solid var(--line); border-radius: .4rem; }
.profile-option.active { background: var(--brand-soft); border-color: #96bfaf; }
.profile-option p { margin: .15rem 0 0; font-size: .76rem; }
.profile-option strong { display: block; }

.trace-list { display: grid; gap: .55rem; margin-top: .8rem; }
.trace-entry { overflow: hidden; border: 1px solid #3e4c48; border-radius: .35rem; background: #17201e; }
.trace-entry summary { display: grid; grid-template-columns: auto 1fr auto; gap: .5rem; align-items: center; padding: .55rem .6rem; cursor: pointer; font-size: .75rem; }
.trace-method { color: #efbf7c; font-weight: 850; }
.trace-path { overflow: hidden; color: #dae5e1; text-overflow: ellipsis; white-space: nowrap; }
.trace-status { font-weight: 800; }
.trace-ok .trace-status { color: #81d1a5; }
.trace-fail .trace-status { color: #ff9298; }
.trace-body { padding: .6rem; border-top: 1px solid #34413e; }
.trace-meta { display: flex; gap: .7rem; flex-wrap: wrap; margin-bottom: .45rem; color: #9fb2ac; font-size: .68rem; }
pre { max-width: 100%; margin: 0; padding: .7rem; overflow: auto; color: #dce8e3; background: #111816; border-radius: .3rem; font: .74rem/1.5 ui-monospace, SFMono-Regular, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }
.response-panel pre { min-height: 180px; max-height: 560px; }

.table-wrap { max-height: 420px; overflow: auto; border: 1px solid var(--line); border-radius: .35rem; }
.data-table { width: 100%; border-collapse: collapse; font-size: .8rem; }
.data-table th { position: sticky; top: 0; z-index: 1; padding: .55rem; color: var(--muted); background: #f1f4f1; text-align: left; border-bottom: 1px solid var(--line-strong); }
.data-table td { padding: .5rem .55rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table select, .data-table input { min-width: 74px; padding: .38rem .45rem; }
.data-table .money-input { min-width: 105px; text-align: right; font-variant-numeric: tabular-nums; }
.subflow-list { display: grid; gap: .6rem; }
.subflow-row { display: flex; align-items: center; justify-content: space-between; gap: .7rem; padding: .65rem; background: #f7f9f7; border: 1px solid var(--line); border-radius: .35rem; }
.subflow-row p { margin: .15rem 0 0; font-size: .75rem; }
.setup-steps { display: grid; gap: .45rem; margin: 1rem 0 0; padding: 0; list-style: none; }
.setup-step { display: grid; grid-template-columns: 30px minmax(0, 1fr) auto; gap: .65rem; align-items: start; padding: .65rem; background: #f7f9f7; border: 1px solid var(--line); border-radius: .35rem; }
.setup-step-number { display: grid; place-items: center; width: 28px; height: 28px; color: var(--muted); background: white; border: 1px solid var(--line); border-radius: 50%; font-size: .72rem; font-weight: 800; }
.setup-step p { margin: .15rem 0 0; font-size: .75rem; }
.step-state { padding: .25rem .42rem; border-radius: .25rem; font-size: .68rem; font-weight: 850; text-transform: uppercase; }
.step-complete, .step-skipped { color: var(--success); background: var(--success-soft); }
.step-action_required { color: var(--warning); background: var(--warning-soft); }
.step-blocked { color: var(--muted); background: #e8ece9; }

.endpoint-groups { display: grid; gap: .8rem; }
.endpoint-row { display: grid; grid-template-columns: 62px 1fr auto; align-items: center; gap: .65rem; padding: .55rem 0; border-bottom: 1px solid var(--line); }
.endpoint-row:last-child { border-bottom: 0; }
.method-badge { display: inline-flex; justify-content: center; padding: .22rem .35rem; color: var(--brand-dark); background: var(--brand-soft); border-radius: .25rem; font-size: .7rem; font-weight: 850; }
.endpoint-path { overflow-wrap: anywhere; font: .76rem/1.35 ui-monospace, SFMono-Regular, Consolas, monospace; }

.toast-region { position: fixed; right: 1rem; bottom: 1rem; z-index: 50; display: grid; gap: .5rem; width: min(380px, calc(100vw - 2rem)); }
.toast { padding: .8rem 1rem; color: white; background: #24302d; border-left: 4px solid #8fc8b0; border-radius: .35rem; box-shadow: var(--shadow); animation: toast-in .18s ease-out; }
.toast.error { border-left-color: #ff858c; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }

.spinner { width: 18px; height: 18px; border: 2px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 190px minmax(390px, 1fr); grid-template-areas: "top top" "nav main"; }
  .diagnostics { position: fixed; z-index: 20; top: 76px; right: 0; bottom: 0; width: min(420px, 92vw); box-shadow: -12px 0 32px rgba(0,0,0,.22); }
  .diagnostics.collapsed { display: none; }
}
@media (max-width: 760px) {
  .app-shell { display: block; }
  .topbar { align-items: flex-start; flex-direction: column; }
  .journey-nav { display: flex; gap: .25rem; padding: .55rem; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .journey-nav .nav-label, .journey-nav .nav-note { display: none; }
  .journey-nav > a { min-width: max-content; border-left: 0; border-bottom: 3px solid transparent; border-radius: .35rem .35rem 0 0; }
  .journey-nav > a.active { border-left: 0; border-bottom-color: var(--accent); }
  .workspace { padding: 1rem; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .view-heading { display: block; }
  .definition-list { grid-template-columns: 1fr; }
  .definition-list dd { margin-bottom: .4rem; }
}
