@layer components {
  .skip-link { position: absolute; inset-inline-start: var(--sp-3); inset-block-start: -48px; z-index: 100; padding: var(--sp-2) var(--sp-4); background: var(--primary); color: #fff; border-radius: var(--r-md); font-weight: 600; }
  .skip-link:focus { inset-block-start: var(--sp-3); }
  /* Confirmation toast for wireframe-only actions: shown by :target, closed by the x link */
  .toast { display: none; position: fixed; inset-inline-end: var(--sp-5); inset-block-end: 88px; z-index: 60; max-width: min(420px, calc(100vw - 2 * var(--sp-4))); align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); background: var(--text); color: var(--surface); border-radius: var(--r-md); box-shadow: var(--shadow-2); font-size: var(--fs-sm); }
  .toast:target { display: flex; }
  .toast .ph:first-child { color: #86efac; flex: none; }
  .toast a { color: inherit; display: grid; place-items: center; margin-inline-start: auto; padding: 4px; border-radius: var(--r-sm); }
  .toast a:hover { background: rgb(255 255 255 / 0.15); }
  @media (prefers-reduced-motion: no-preference) { .toast:target { animation: toast-in 0.18s ease-out; } }
  @keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
  .cell-main a { text-decoration: none; font-weight: 600; }
  .cell-main a:hover { text-decoration: underline; }
  /* Buttons */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: var(--sp-2);
    height: 38px; padding: 0 var(--sp-4); border-radius: var(--r-md);
    border: 1px solid var(--line-strong); background: var(--surface); color: var(--text);
    font-size: var(--fs-md); font-weight: 600; white-space: nowrap; cursor: pointer;
    transition: background 0.12s, border-color 0.12s, box-shadow 0.12s;
  }
  .btn:hover { background: var(--surface-3); }
  .btn--primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); box-shadow: var(--shadow-1); }
  .btn--primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
  .btn--danger { background: var(--bad); border-color: var(--bad); color: #fff; }
  .btn--danger:hover { background: #8f1c12; }
  .btn--ghost { border-color: transparent; background: transparent; color: var(--primary); }
  .btn--ghost:hover { background: var(--primary-weak); }
  .btn--quiet { border-color: transparent; background: transparent; color: var(--text-2); }
  .btn--quiet:hover { background: var(--surface-3); }
  .btn--sm { height: 30px; padding: 0 var(--sp-3); font-size: var(--fs-sm); }
  .btn--lg { height: 44px; padding: 0 var(--sp-5); font-size: var(--fs-lg); }
  .btn--block { width: 100%; }
  .btn[aria-disabled="true"], .btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
  /* Disabled buttons keep their tooltip ("Your role cannot do this") but never react to hover */
  .btn[aria-disabled="true"]:hover, .btn:disabled:hover { background: var(--surface); border-color: var(--line-strong); }
  .btn--primary[aria-disabled="true"]:hover { background: var(--primary); border-color: var(--primary); }
  .btn--danger[aria-disabled="true"]:hover { background: var(--bad); border-color: var(--bad); }
  .btn--ghost[aria-disabled="true"]:hover, .btn--quiet[aria-disabled="true"]:hover { background: transparent; border-color: transparent; }
  .icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border-radius: var(--r-md); border: 1px solid transparent; background: transparent; color: var(--text-2); cursor: pointer; position: relative; }
  .icon-btn:hover { background: var(--surface-3); }
  .icon-btn .dot { position: absolute; top: 7px; right: 8px; width: 8px; height: 8px; border-radius: 50%; background: var(--bad); border: 2px solid var(--surface); }

  /* Badges and chips */
  .badge { display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px; font-size: var(--fs-xs); font-weight: 600; background: var(--surface-3); color: var(--text-2); white-space: nowrap; }
  .badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }
  .badge--plain::before, .badge:has(> .ph)::before { display: none; } /* an icon already marks the badge; no second dot */
  .badge--ok { background: var(--ok-weak); color: var(--ok); }
  .badge--warn { background: var(--warn-weak); color: var(--warn); }
  .badge--bad { background: var(--bad-weak); color: var(--bad); }
  .badge--info { background: var(--info-weak); color: var(--info); }
  .badge--payer { background: var(--payer-weak); color: var(--payer); }
  .badge--primary { background: var(--primary-weak); color: var(--primary); }
  .chip { display: inline-flex; align-items: center; gap: 6px; height: 26px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--line-strong); background: var(--surface); font-size: var(--fs-xs); color: var(--text-2); }
  .chip--on { background: var(--primary-weak); border-color: var(--primary); color: var(--primary); font-weight: 600; }
  .tag { display: inline-block; padding: 1px 8px; border-radius: var(--r-sm); background: var(--surface-3); color: var(--text-2); font-size: var(--fs-xs); font-weight: 600; letter-spacing: 0.02em; }

  /* Cards */
  .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-1); min-width: 0; }
  .card-head { display: flex; align-items: center; justify-content: flex-start; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
  .card-head h2, .card-head h3 { display: flex; align-items: center; gap: var(--sp-2); }
  .card-head > h2 > .ph, .card-head > h3 > .ph { color: var(--teal); }
  /* A status next to the title stays with the title; the actions sit at the far end */
  .card-head > :last-child:not(:first-child) { margin-left: auto; }
  .card-head > .row:last-child:empty { display: none; }
  .card-body { padding: var(--sp-5); }
  .card-body--tight { padding: 0; }
  .card-foot { padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--line); background: var(--surface-2); border-radius: 0 0 var(--r-lg) var(--r-lg); display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; }
  .card--flat { box-shadow: none; }
  .card--soft { background: var(--surface-2); }
  .tile { padding: var(--sp-4) var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-1); }
  .tile .label { color: var(--muted); font-size: var(--fs-sm); display: flex; align-items: center; gap: var(--sp-2); }
  .tile .value { font-size: var(--fs-3xl); font-weight: 600; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; line-height: 1.1; }
  .tile .value a { color: var(--primary); text-decoration: none; }
  .tile .value a:hover { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
  .tile .hint { color: var(--muted); font-size: var(--fs-xs); }

  /* Tables */
  .table-wrap { overflow-x: auto; }
  .table th { text-align: left; font-size: var(--fs-xs); font-weight: 600; color: var(--muted); padding: 10px var(--sp-4); background: var(--surface-2); border-bottom: 1px solid var(--line); white-space: nowrap; }
  .table td { padding: 12px var(--sp-4); border-bottom: 1px solid var(--line); vertical-align: middle; font-size: var(--fs-md); }
  .table tr:last-child td { border-bottom: 0; }
  .table tbody tr:hover td { background: var(--surface-2); }
  .table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
  /* IDs, codes and amounts never break across lines; the table scrolls instead */
  .table td .mono, .table td code, .table td .input--mono, .table td .badge, .table td .btn, .table td .chip { white-space: nowrap; }
  .table td .num { white-space: nowrap; }
  .table td .row { flex-wrap: nowrap; gap: var(--sp-2); }
  .owner { flex-wrap: nowrap; gap: var(--sp-2); white-space: nowrap; }
  .table .cell-main { font-weight: 600; display: block; }
  .table .cell-sub { color: var(--muted); font-size: var(--fs-xs); display: block; }
  .table a.cell-link { color: var(--primary); font-weight: 600; }
  .table a.cell-link:hover { text-decoration: underline; }
  .table--compact td { padding: 8px var(--sp-4); }

  /* Toolbar and filters */
  .toolbar { display: flex; align-items: center; gap: var(--sp-3); flex-wrap: wrap; padding: var(--sp-3) var(--sp-5); border-bottom: 1px solid var(--line); }
  .search { position: relative; flex: 1; min-width: 220px; max-width: 420px; }
  .search .ph { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); }
  .search input { width: 100%; height: 38px; padding: 0 12px 0 38px; border: 1px solid var(--line-input, var(--line-strong)); border-radius: var(--r-md); background: var(--surface); }
  .pager { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--line); color: var(--muted); font-size: var(--fs-sm); }
  .pager .pages { display: flex; align-items: center; gap: var(--sp-1); }
  .pager .pages a, .pager .pages span { min-width: 32px; height: 32px; display: grid; place-items: center; border-radius: var(--r-sm); border: 1px solid var(--line); background: var(--surface); }
  .pager .pages .on { background: var(--primary); border-color: var(--primary); color: var(--on-primary); font-weight: 600; }

  /* Forms */
  .form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--sp-4) var(--sp-5); }
  .form-grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .form-grid .span-2 { grid-column: span 2; }
  .form-grid .span-all { grid-column: 1 / -1; }
  .field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
  .field > label, .label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); display: flex; align-items: center; gap: 6px; }
  .req { color: var(--bad); }
  .opt { color: var(--faint); font-weight: 400; }
  .field .help { font-size: var(--fs-xs); color: var(--muted); }
  .field .err { display: none; align-items: center; gap: 6px; font-size: var(--fs-xs); color: var(--bad); font-weight: 600; }
  .input, .select, .textarea {
    width: 100%; min-height: 38px; padding: 0 12px; border: 1px solid var(--line-input, var(--line-strong)); border-radius: var(--r-md);
    background: var(--surface); color: var(--text); font-size: var(--fs-md);
  }
  .textarea { padding: 10px 12px; min-height: 92px; resize: vertical; }
  .select { appearance: none; padding-right: 36px; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 16px, calc(100% - 13px) 16px; background-size: 5px 5px; background-repeat: no-repeat; }
  .input:hover, .select:hover, .textarea:hover { border-color: var(--muted); }
  .input:focus, .select:focus, .textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }
  .input[readonly], .input:disabled, .select:disabled, .textarea:disabled { background: var(--surface-3); color: var(--text-2); border-color: var(--line-strong); }
  .input:disabled, .select:disabled, .textarea:disabled { cursor: not-allowed; color: var(--muted); }
  .input--mono { font-family: var(--mono); letter-spacing: 0.04em; }
  .field.is-invalid .input, .field.is-invalid .select, .field.is-invalid .textarea { border-color: var(--bad); background: color-mix(in srgb, var(--bad-weak) 45%, var(--surface)); }
  .field.is-invalid .err { display: flex; }
  .input-affix { position: relative; }
  .input-affix .affix { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: var(--fs-xs); display: flex; gap: 4px; align-items: center; }
  .input-affix .input { padding-right: 70px; }
  .check, .radio { display: flex; align-items: flex-start; gap: var(--sp-3); font-size: var(--fs-md); cursor: pointer; }
  .check input, .radio input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--primary); flex: none; }
  .check small, .radio small { display: block; color: var(--muted); font-size: var(--fs-xs); }
  .switch { display: inline-flex; align-items: center; gap: var(--sp-3); cursor: pointer; }
  .switch input { appearance: none; width: 38px; height: 22px; border-radius: 999px; background: var(--line-input, var(--line-strong)); position: relative; transition: background 0.15s; flex: none; }
  .switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform 0.15s; box-shadow: var(--shadow-1); }
  .switch input:checked { background: var(--primary); }
  .switch input:checked::after { transform: translateX(16px); }
  .segmented { display: inline-flex; padding: 3px; border-radius: var(--r-md); background: var(--surface-3); border: 1px solid var(--line); }
  .segmented a, .segmented span { padding: 5px 14px; border-radius: 8px; font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
  .segmented .on { background: var(--surface); color: var(--primary); box-shadow: var(--shadow-1); }
  .fieldset { border: 1px solid var(--line); border-radius: var(--r-md); padding: var(--sp-4); display: grid; gap: var(--sp-4); }
  .fieldset > legend, .fieldset-title { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); padding: 0 6px; }

  /* Alerts and banners */
  .alert { display: flex; gap: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: var(--r-md); border: 1px solid; font-size: var(--fs-md); align-items: flex-start; }
  .alert > .ph { margin-top: 2px; }
  .alert b { font-weight: 600; }
  .alert--info { background: var(--info-weak); border-color: color-mix(in srgb, var(--info) 30%, transparent); color: var(--text); }
  .alert--info > .ph { color: var(--info); }
  .alert--ok { background: var(--ok-weak); border-color: color-mix(in srgb, var(--ok) 30%, transparent); }
  .alert--ok > .ph { color: var(--ok); }
  .alert--warn { background: var(--warn-weak); border-color: color-mix(in srgb, var(--warn) 35%, transparent); }
  .alert--warn > .ph { color: var(--warn); }
  .alert--bad { background: var(--bad-weak); border-color: color-mix(in srgb, var(--bad) 30%, transparent); }
  .alert--bad > .ph { color: var(--bad); }
  .alert .alert-actions { margin-left: auto; display: flex; gap: var(--sp-2); flex: none; }
  .banner { display: flex; align-items: center; gap: var(--sp-3); padding: var(--sp-3) var(--sp-5); border-radius: var(--r-md); background: var(--payer-weak); color: var(--text); border: 1px solid color-mix(in srgb, var(--payer) 25%, transparent); }
  .banner > .ph { color: var(--payer); }

  /* Tabs (CSS only: radio inputs before the bar and the panels) */
  .tabs > input { position: absolute; opacity: 0; pointer-events: none; }
  .tab-bar { display: flex; gap: var(--sp-1); border-bottom: 1px solid var(--line); overflow-x: auto; }
  .tab-bar label, .tab-bar a { display: flex; align-items: center; gap: var(--sp-2); padding: 11px var(--sp-4); font-weight: 600; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; cursor: pointer; white-space: nowrap; }
  .tab-bar label:hover, .tab-bar a:hover { color: var(--text); }
  .tab-bar .is-active { color: var(--primary); border-bottom-color: var(--primary); }
  .tab-bar .done .ph { color: var(--ok); }
  .tab-panel { display: none; padding-top: var(--sp-5); }
  .tabs > input:nth-of-type(1):checked ~ .tab-bar label:nth-child(1),
  .tabs > input:nth-of-type(2):checked ~ .tab-bar label:nth-child(2),
  .tabs > input:nth-of-type(3):checked ~ .tab-bar label:nth-child(3),
  .tabs > input:nth-of-type(4):checked ~ .tab-bar label:nth-child(4),
  .tabs > input:nth-of-type(5):checked ~ .tab-bar label:nth-child(5),
  .tabs > input:nth-of-type(6):checked ~ .tab-bar label:nth-child(6),
  .tabs > input:nth-of-type(7):checked ~ .tab-bar label:nth-child(7),
  .tabs > input:nth-of-type(8):checked ~ .tab-bar label:nth-child(8) { color: var(--primary); border-bottom-color: var(--primary); }
  .tabs > input:nth-of-type(1):checked ~ .tab-panels > .tab-panel:nth-child(1),
  .tabs > input:nth-of-type(2):checked ~ .tab-panels > .tab-panel:nth-child(2),
  .tabs > input:nth-of-type(3):checked ~ .tab-panels > .tab-panel:nth-child(3),
  .tabs > input:nth-of-type(4):checked ~ .tab-panels > .tab-panel:nth-child(4),
  .tabs > input:nth-of-type(5):checked ~ .tab-panels > .tab-panel:nth-child(5),
  .tabs > input:nth-of-type(6):checked ~ .tab-panels > .tab-panel:nth-child(6),
  .tabs > input:nth-of-type(7):checked ~ .tab-panels > .tab-panel:nth-child(7),
  .tabs > input:nth-of-type(8):checked ~ .tab-panels > .tab-panel:nth-child(8) { display: block; }
  .tabs > input:nth-of-type(1):focus-visible ~ .tab-bar label:nth-child(1),
  .tabs > input:nth-of-type(2):focus-visible ~ .tab-bar label:nth-child(2),
  .tabs > input:nth-of-type(3):focus-visible ~ .tab-bar label:nth-child(3),
  .tabs > input:nth-of-type(4):focus-visible ~ .tab-bar label:nth-child(4),
  .tabs > input:nth-of-type(5):focus-visible ~ .tab-bar label:nth-child(5),
  .tabs > input:nth-of-type(6):focus-visible ~ .tab-bar label:nth-child(6),
  .tabs > input:nth-of-type(7):focus-visible ~ .tab-bar label:nth-child(7),
  .tabs > input:nth-of-type(8):focus-visible ~ .tab-bar label:nth-child(8) { outline: 2px solid var(--focus); outline-offset: -2px; border-radius: 6px 6px 0 0; }

  /* Workspace sections (the real portal lays long forms out as sections with a rail, not a blind wizard) */
  .workspace { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: var(--sp-5); align-items: start; }
  .rail { position: sticky; top: calc(var(--topbar-h) + var(--sp-4)); display: flex; flex-direction: column; gap: 2px; padding: var(--sp-3); }
  .rail h4 { padding: var(--sp-2) var(--sp-3); font-size: 0.8125rem; color: var(--faint); }
  .rail-item { display: flex; align-items: center; gap: var(--sp-3); padding: 9px var(--sp-3); border-radius: var(--r-md); color: var(--text-2); font-size: var(--fs-md); }
  .rail-item:hover { background: var(--surface-3); }
  .rail-item .mark { width: 22px; height: 22px; border-radius: 50%; border: 1.5px solid var(--line-strong); display: grid; place-items: center; font-size: 11px; font-weight: 600; color: var(--muted); flex: none; background: var(--surface); }
  .rail-item.is-done .mark { background: var(--ok); border-color: var(--ok); color: #fff; }
  /* Rail progress: a thread joins the marks; it turns green once the section above is done */
  .rail-item { position: relative; }
  .rail-item .mark { position: relative; }
  .rail-item + .rail-item .mark::before { content: ""; position: absolute; left: 50%; bottom: calc(100% + 1.5px); width: 2px; height: 20px; margin-left: -1px; background: var(--line-strong); border-radius: 1px; }
  .rail-item.is-done + .rail-item .mark::before { background: var(--ok); }
  .rail-item.is-active { background: var(--primary-weak); color: var(--primary); font-weight: 600; }
  .rail-item.is-active .mark { border-color: var(--primary); color: var(--primary); }
  .rail-item.is-error .mark { border-color: var(--bad); background: var(--bad-weak); color: var(--bad); }
  .rail-item.is-locked { color: var(--faint); }
  .rail-item .opt-tag { margin-left: auto; font-size: var(--fs-xs); color: var(--faint); font-weight: 400; }
  .rail-item.is-active .opt-tag { color: var(--muted); }
  .rail-item .req-tag { margin-left: auto; color: var(--bad); font-weight: 600; }
  .panel-foot { position: sticky; bottom: 0; z-index: 5; display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-3) var(--sp-5); background: color-mix(in srgb, var(--surface) 96%, transparent); backdrop-filter: blur(6px); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-2); flex-wrap: wrap; }
  .draft-note { display: inline-flex; align-items: center; gap: var(--sp-2); color: var(--muted); font-size: var(--fs-sm); }
  .draft-note .ph { color: var(--ok); }

  /* Key-value, timeline, empty, progress */
  .kv { display: grid; grid-template-columns: fit-content(180px) minmax(0, 1fr); gap: 10px var(--sp-4); font-size: var(--fs-md); }
  .kv dt { color: var(--muted); }
  .kv dd { font-weight: 400; min-width: 0; overflow-wrap: anywhere; }
  .kv--tight { grid-template-columns: fit-content(150px) minmax(0, 1fr); }
  .kv dt { min-width: 7.5rem; }
  .idchain { display: grid; gap: 0; }
  .idrow { display: grid; grid-template-columns: 170px minmax(0, 1fr) auto; align-items: center; gap: var(--sp-3); padding: 10px 0; border-bottom: 1px dashed var(--line); }
  .idrow:last-child { border-bottom: 0; }
  .idrow .k { color: var(--muted); font-size: var(--fs-sm); }
  .idrow .v { font-family: var(--mono); font-size: var(--fs-sm); overflow-wrap: anywhere; }
  .idrow .v.pending { font-family: var(--font); color: var(--warn); font-weight: 600; display: flex; align-items: center; gap: 6px; }
  .timeline { display: flex; flex-direction: column; }
  .tl-item { position: relative; display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: var(--sp-3); padding-bottom: var(--sp-4); }
  .tl-item::before { content: ""; position: absolute; left: 13px; top: 28px; bottom: 0; width: 2px; background: var(--line); }
  .tl-item:last-child::before { display: none; }
  .tl-dot { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-weak); color: var(--primary); }
  .tl-dot--ok { background: var(--ok-weak); color: var(--ok); }
  .tl-dot--payer { background: var(--payer-weak); color: var(--payer); }
  .tl-dot--bad { background: var(--bad-weak); color: var(--bad); }
  .tl-dot--wait { background: var(--warn-weak); color: var(--warn); }
  .tl-dot--info { background: var(--info-weak); color: var(--info); }
  .tl-item b { font-weight: 600; }
  .tl-item .when { color: var(--muted); font-size: var(--fs-xs); }
  .empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: var(--sp-3); padding: var(--sp-6) var(--sp-5); color: var(--muted); }
  .empty .ph { width: 40px; height: 40px; color: var(--faint); }
  .empty p { max-width: 52ch; }
  .empty-art { display: block; width: 136px; height: 102px; background: center / contain no-repeat; margin-bottom: var(--sp-1); }
  .empty-art--inbox { background-image: url("../img/empty-inbox.svg"); }
  .empty-art--search { background-image: url("../img/empty-search.svg"); }
  .empty-art--no-access { background-image: url("../img/empty-no-access.svg"); }
  .empty-art--session { background-image: url("../img/empty-session.svg"); }
  .empty-art--offline { background-image: url("../img/empty-offline.svg"); }
  .empty-art--404 { background-image: url("../img/empty-404.svg"); }
  .empty h3 { color: var(--text); }
  .progress { height: 8px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
  .progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--accent)); border-radius: 999px; }
  .skeleton { display: block; border-radius: var(--r-sm); background: var(--surface-3); height: 12px; }
  .sk { display: flex; flex-direction: column; gap: var(--sp-3); }
  .sk--lines .skeleton:nth-child(3n + 2) { width: 86%; }
  .sk--lines .skeleton:nth-child(3n) { width: 64%; }
  .sk--rows { gap: 0; }
  .sk-row { display: flex; align-items: center; gap: var(--sp-3); padding: 14px var(--sp-4); border-bottom: 1px solid var(--line); }
  .sk-row:last-child { border-bottom: 0; }
  .sk-row:nth-child(2n) .sk-col .skeleton:first-child { width: 72%; }
  .sk-col { flex: 1; display: flex; flex-direction: column; gap: 8px; }
  .sk-dot { width: 28px; height: 28px; border-radius: 50%; flex: none; }
  .sk-pill { width: 72px; height: 22px; border-radius: 999px; flex: none; }
  .sk-short { width: 38%; }
  .sk--tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--sp-4); }
  .sk-tile { padding: var(--sp-4) var(--sp-5); display: flex; flex-direction: column; gap: 10px; }
  .sk-big { width: 48%; height: 28px; }
  .chart { height: 180px; border-radius: var(--r-md); background: repeating-linear-gradient(0deg, transparent 0 35px, var(--line) 35px 36px), var(--surface-2); position: relative; overflow: hidden; }
  .chart svg { position: absolute; inset: 0; width: 100%; height: 100%; }
  .copybtn { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: var(--r-sm); color: var(--muted); border: 1px solid transparent; background: transparent; cursor: pointer; }
  .copybtn:hover { background: var(--surface-3); color: var(--primary); }
  .avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--primary); color: #fff; font-weight: 600; font-size: var(--fs-sm); flex: none; }
  .avatar--sm { width: 26px; height: 26px; font-size: var(--fs-xs); }
  .lock { color: var(--faint); }

  /* Menus (details) */
  .menu { position: relative; }
  .menu > summary { display: inline-flex; align-items: center; gap: var(--sp-2); cursor: pointer; }
  .menu > summary:not(.btn):not(.icon-btn) { border-radius: 999px; }
  .menu-panel { position: absolute; right: 0; max-width: calc(100vw - 32px); top: calc(100% + 6px); z-index: 50; min-width: 240px; padding: var(--sp-2); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-2); display: flex; flex-direction: column; gap: 2px; }
  .menu-panel a, .menu-panel .menu-row { display: flex; align-items: center; gap: var(--sp-3); padding: 8px var(--sp-3); border-radius: var(--r-sm); font-size: var(--fs-md); color: var(--text-2); }
  .menu-panel a:hover { background: var(--surface-3); color: var(--text); }
  .menu-panel a.is-current { background: var(--primary-weak); color: var(--primary); font-weight: 600; }
  .menu-panel hr { border: 0; border-top: 1px solid var(--line); margin: var(--sp-1) 0; }
  .menu-panel .menu-title { padding: 6px var(--sp-3); font-size: 0.8125rem; color: var(--faint); font-weight: 600; }
  .menu[open] > summary.btn { background: var(--surface-3); }

  /* Modals (CSS only, opened by linking to #id) */
  .modal { position: fixed; inset: 0; z-index: 100; display: none; place-items: center; padding: var(--sp-4); }
  .modal:target { display: grid; }
  .modal-scrim { position: absolute; inset: 0; background: var(--scrim); }
  .modal-box { position: relative; width: min(560px, 100%); max-height: calc(100vh - 48px); overflow: auto; background: var(--surface); border-radius: var(--r-lg); box-shadow: var(--shadow-2); border: 1px solid var(--line); }
  .modal-box--wide { width: min(840px, 100%); }
  .modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); padding: var(--sp-4) var(--sp-5); border-bottom: 1px solid var(--line); }
  .modal-body { padding: var(--sp-5); display: flex; flex-direction: column; gap: var(--sp-4); }
  .modal-foot { display: flex; justify-content: flex-end; gap: var(--sp-2); padding: var(--sp-4) var(--sp-5); border-top: 1px solid var(--line); background: var(--surface-2); }

  /* Policy checklist, scope tree, matrix */
  .checklist { display: grid; gap: var(--sp-2); font-size: var(--fs-sm); }
  .checklist li { display: flex; align-items: center; gap: var(--sp-2); color: var(--muted); }
  .checklist li.ok { color: var(--ok); }
  .checklist li.bad { color: var(--bad); }
  .tree { display: flex; flex-direction: column; gap: 2px; font-size: var(--fs-md); }
  .tree-row { display: flex; align-items: center; gap: var(--sp-3); padding: 8px var(--sp-3); border-radius: var(--r-md); }
  .tree-row:hover { background: var(--surface-2); }
  .tree-row .ph { color: var(--teal); }
  .tree-row .meta { margin-left: auto; display: flex; align-items: center; gap: var(--sp-3); color: var(--muted); font-size: var(--fs-sm); }
  .tree-l1 { padding-left: 28px; } .tree-l2 { padding-left: 56px; } .tree-l3 { padding-left: 84px; }
  .matrix { font-size: var(--fs-sm); }
  .matrix th { text-align: center; }
  .matrix th:first-child, .matrix td:first-child { text-align: left; }
  .matrix td { text-align: center; }
  .perm { display: inline-flex; gap: 3px; }
  .perm i { font-style: normal; width: 20px; height: 20px; border-radius: 5px; display: grid; place-items: center; font-size: 11px; font-weight: 700; background: var(--surface-3); color: var(--faint); }
  .perm i.on { background: var(--primary-weak); color: var(--primary); }
  .perm i.warn { background: var(--warn-weak); color: var(--warn); }

  /* One button height in the page header, whatever size the helper asked for */
  .page-actions .btn--sm, .page-actions .menu > summary.btn--sm { height: 38px; padding: 0 var(--sp-4); font-size: var(--fs-md); }
  @media (max-width: 600px) {
    .card-head, .card-body, .toolbar, .pager, .card-foot, .modal-head, .modal-body, .modal-foot { padding-left: var(--sp-4); padding-right: var(--sp-4); }
    .tile { padding: var(--sp-3) var(--sp-4); }
    .tile .value { font-size: var(--fs-2xl); overflow-wrap: anywhere; }
    .search { min-width: 0; flex-basis: 100%; }
    .idrow { grid-template-columns: minmax(0, 1fr) auto; }
    .idrow .k { grid-column: 1 / -1; }
    .panel-foot { padding: var(--sp-3) var(--sp-4); }
    .card-head .badge { white-space: normal; height: auto; min-height: 24px; padding-block: 3px; }
    .alert { flex-wrap: wrap; }
    .alert > div:not(.alert-actions) { flex: 1 1 0; min-width: 0; }
    .alert .alert-actions { margin-left: calc(1.25em + var(--sp-3)); flex-basis: 100%; flex-wrap: wrap; }
  }
  @media (max-width: 1100px) { .workspace { grid-template-columns: minmax(0, 1fr); } .rail { position: static; flex-direction: row; flex-wrap: wrap; } .rail-item + .rail-item .mark::before { display: none; } }
  @media (max-width: 900px) { .form-grid, .form-grid--3 { grid-template-columns: minmax(0, 1fr); } .form-grid .span-2 { grid-column: auto; } .kv { grid-template-columns: minmax(0, 1fr); } }

  /* Journey maps */
  .flow { display: flex; flex-wrap: wrap; align-items: stretch; gap: var(--sp-2); padding: var(--sp-1) var(--sp-1) var(--sp-3); }
  .flow-arrow { align-self: center; color: var(--faint); flex: none; }
  .step { flex: 1 1 200px; max-width: 260px; display: flex; flex-direction: column; gap: 6px; padding: var(--sp-3) var(--sp-4); background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md); transition: border-color 0.12s, box-shadow 0.12s; }
  a.step:hover { border-color: var(--primary); box-shadow: var(--shadow-1); }
  .step .n { width: 24px; height: 24px; border-radius: 50%; background: var(--primary-weak); color: var(--primary); display: grid; place-items: center; font-size: 12px; font-weight: 600; }
  .step b { font-weight: 600; line-height: 1.3; }
  .step p { color: var(--muted); font-size: var(--fs-sm); }
  .step .go { margin-top: auto; color: var(--primary); font-size: var(--fs-xs); font-weight: 600; display: flex; align-items: center; gap: 4px; }
  .step--locked { background: var(--surface-2); border-style: dashed; }
  .nw { white-space: nowrap; }
  .step-role { align-self: flex-start; display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--r-pill, 999px); background: var(--surface-2); border: 1px solid var(--line); color: var(--text); font-size: var(--fs-xs); font-weight: 600; }
  .swatch { display: flex; align-items: center; gap: var(--sp-3); font-size: var(--fs-sm); }
  .swatch i { width: 36px; height: 36px; border-radius: var(--r-md); border: 1px solid var(--line); flex: none; }
  .docs-top { display: flex; align-items: center; gap: var(--sp-4); padding: 0 var(--sp-5); height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 30; flex-wrap: wrap; }
  .docs-top nav { display: flex; gap: var(--sp-1); flex-wrap: wrap; margin-left: var(--sp-4); }
  .docs-top nav a { padding: 7px var(--sp-3); border-radius: var(--r-md); font-weight: 600; color: var(--text-2); }
  .docs-top nav a:hover { background: var(--surface-3); }
  .docs-top nav a.is-active { background: var(--primary-weak); color: var(--primary); }
  .docs-main { max-width: 1180px; width: 100%; margin: 0 auto; padding: var(--sp-6) var(--sp-5) 64px; display: flex; flex-direction: column; gap: var(--sp-5); }
  .role-card { display: flex; flex-direction: column; gap: var(--sp-3); padding: var(--sp-5); }
  .role-card h3 { display: flex; align-items: center; gap: var(--sp-3); }
  .docs-top .brand { flex-direction: row; align-items: center; gap: var(--sp-3); padding: 0; }
  .docs-top .brand img { height: 30px; }
  .docs-top .brand > div { padding-left: var(--sp-3); border-left: 1px solid var(--line); }
  .hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: var(--sp-6); align-items: center; padding: var(--sp-5) 0 var(--sp-2); }
  .hero h1 { font-size: 2.4rem; line-height: 1.1; letter-spacing: -0.02em; max-width: 16ch; }
  .hero-stats { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-5); padding-top: var(--sp-4); border-top: 1px solid var(--line); margin-top: var(--sp-2); }
  .hero-stats div { display: flex; align-items: baseline; gap: 6px; }
  .hero-stats dt { order: 2; color: var(--muted); font-size: var(--fs-sm); }
  .hero-stats dd { order: 1; font-weight: 600; font-size: var(--fs-xl); color: var(--navy); font-variant-numeric: tabular-nums; }
  .hero-art { position: relative; padding: var(--sp-5) var(--sp-5) var(--sp-4); border-radius: var(--r-lg); border: 1px solid var(--line); background: url("../img/ledger-light.svg") 0 0 / 24px 24px, var(--surface); box-shadow: var(--shadow-1); }
  .hero-art > p { margin-top: var(--sp-3); padding-top: var(--sp-3); border-top: 1px dashed var(--line); }
  .page-intro { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 520px); gap: var(--sp-6); align-items: end; }
  @media (max-width: 900px) { .page-intro { grid-template-columns: minmax(0, 1fr); } }
  .legend { display: flex; gap: var(--sp-4); flex-wrap: wrap; color: var(--muted); font-size: var(--fs-sm); }
  @media (max-width: 900px) { .hero { grid-template-columns: minmax(0, 1fr); } }

  /* Status that is still waiting (Pending, Queued) carries a live dot; see the motion block for its pulse */
  .badge--live::before { opacity: 1; }

  /* The claim route illustration (core.claim_route). Strokes and fills are themed per variant. */
  .route { margin: 0; }
  .route svg { width: 100%; height: auto; overflow: visible; font-family: var(--font); }
  .route-track { stroke: var(--rt-track); stroke-width: 2; stroke-dasharray: 2 6; stroke-linecap: round; }
  .route-line { stroke: var(--rt-line); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
  .route-halo { fill: var(--rt-halo); }
  .route-ring { fill: var(--rt-ring-fill); stroke: var(--rt-line); stroke-width: 2.5; }
  .route-core { fill: var(--rt-line); }
  .st-payer .route-ring { stroke: var(--rt-payer); }
  .st-payer .route-core { fill: var(--rt-payer); }
  .st-end .route-ring { fill: var(--rt-end); stroke: var(--rt-end); }
  .route-check { stroke: var(--rt-check); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
  .route-lbl { fill: var(--rt-text); font-size: 15px; font-weight: 600; }
  .route-sub { fill: var(--rt-sub); font-size: 13px; }
  .route--dark { --rt-line: #7fe3f7; --rt-track: rgba(255, 255, 255, 0.22); --rt-halo: rgba(127, 227, 247, 0.12); --rt-ring-fill: #133c7c; --rt-payer: #f5a623; --rt-end: #7fe3f7; --rt-check: #0f2f63; --rt-text: #ffffff; --rt-sub: rgba(255, 255, 255, 0.78); }
  .route--light { --rt-line: var(--navy); --rt-track: var(--line-strong); --rt-halo: var(--primary-weak); --rt-ring-fill: var(--surface); --rt-payer: var(--payer); --rt-end: var(--navy); --rt-check: #ffffff; --rt-text: var(--text); --rt-sub: var(--muted); }

  /* Page head: a short navy run on a hairline, the first leg of the route */
  .content > .page-head { padding-bottom: var(--sp-4); background: linear-gradient(var(--navy), var(--navy)) left bottom / 40px 2px no-repeat, linear-gradient(var(--line), var(--line)) left bottom / 100% 1px no-repeat; }
  .tile .label .ph { color: var(--teal); }

  /* Illustration gallery on the design page */
  .art-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-4); }
  .art-grid figure { margin: 0; display: flex; flex-direction: column; align-items: center; gap: var(--sp-2); padding: var(--sp-3); border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-2); font-size: var(--fs-sm); color: var(--muted); }
}

/* ------------------------------------------------------------------------------------------------
   Motion. Everything here answers an action (open, switch, choose) or plays once, except the
   indicators for work that is still waiting (skeletons, spinners, Pending and Queued badges).
   With reduced motion the finished state shows, because nothing outside this block animates.
   ------------------------------------------------------------------------------------------------ */
@layer components {
  @media (prefers-reduced-motion: no-preference) {
    :root { --ease-out: cubic-bezier(0.22, 1, 0.36, 1); }

    /* Loading: a soft sheen across the placeholders */
    .skeleton { background: linear-gradient(90deg, var(--surface-3) 0%, var(--surface-3) 35%, #f7f9fd 50%, var(--surface-3) 65%, var(--surface-3) 100%) 0 0 / 300% 100%; animation: wf-sheen 1.6s linear infinite; }
    .spin { animation: wf-spin 1s linear infinite; }

    /* Pending and Queued: the dot breathes while the request waits */
    .badge--live::before { animation: wf-breathe 1.8s ease-in-out infinite; }
    .idrow .v.pending .ph { animation: wf-tip 2.4s var(--ease-out) infinite; }

    /* Menus and modals open from where they were asked for */
    .menu[open] > .menu-panel { animation: wf-drop 0.16s var(--ease-out); transform-origin: top right; }
    .modal:target .modal-scrim { animation: wf-fade 0.18s ease-out; }
    .modal:target .modal-box { animation: wf-rise 0.22s var(--ease-out); }
    .ann details[open] .crit { animation: wf-fade 0.2s ease-out; }
    .ann summary .ph { transition: transform 0.15s var(--ease-out); }

    /* Tabs: the underline slides in colour, a panel fades in only after someone changes tab */
    .tab-bar label, .tab-bar a { transition: color 0.15s, border-color 0.2s var(--ease-out); }
    .tabs > input:checked:not([checked]) ~ .tab-panels > .tab-panel { animation: wf-in 0.22s var(--ease-out); }

    /* State switcher: the chosen pill settles, and what the new state shows eases in */
    .wf-seg label { transition: background 0.18s var(--ease-out), color 0.15s, box-shadow 0.18s; }
    /* Only the outermost block of a state eases in, and never from fully transparent, so a capture taken
       mid-switch never shows a washed-out card (nested blocks used to multiply their fades) */
    .wf > input:checked:not([checked]) ~ .wf-body [data-show]:not([data-show] [data-show]) { animation: wf-settle 0.2s var(--ease-out); }
    .wf-seg label:active { transform: scale(0.97); }

    /* Section rail: marks change state smoothly; the current step gets a ring that settles once */
    .rail-item { transition: background 0.15s, color 0.15s; }
    .rail-item .mark { transition: background 0.2s, border-color 0.2s, color 0.2s; }
    .rail-item.is-active .mark { animation: wf-ring 0.9s var(--ease-out) 0.15s both; }
    .switch input, .switch input::after { transition-timing-function: var(--ease-out); }
    .btn, .chip, .nav-item, .step { transition: background 0.12s, border-color 0.12s, box-shadow 0.12s, color 0.12s; }

    /* The one orchestrated moment: the sign in panel. Copy settles, then the claim travels its route. */
    .auth-side--intro .auth-copy > * { animation: wf-in 0.6s var(--ease-out) both; }
    .auth-side--intro .auth-copy > p { animation-delay: 0.08s; }
    .auth-side--intro .auth-copy > ul { animation-delay: 0.16s; }
    .route--play .route-line { stroke-dasharray: 1; animation: wf-draw 2.6s cubic-bezier(0.45, 0, 0.2, 1) 0.5s both; }
    .route--play .route-st { animation: wf-stop 0.45s var(--ease-out) both; transform-box: fill-box; transform-origin: center; }
    .route--play .route-st text { animation: wf-fade 0.4s ease-out both; }
    .route--play .st-1, .route--play .st-1 text { animation-delay: 0.45s; }
    .route--play .st-2, .route--play .st-2 text { animation-delay: 1.15s; }
    .route--play .st-3, .route--play .st-3 text { animation-delay: 1.95s; }
    .route--play .st-4, .route--play .st-4 text { animation-delay: 2.95s; }
    .route--play .st-4 .route-halo { animation: wf-arrive 1.1s var(--ease-out) 3s both; transform-box: fill-box; transform-origin: center; }
    .route--play .route-check { stroke-dasharray: 20; animation: wf-check 0.35s ease-out 3.2s both; }
  }

  @keyframes wf-sheen { from { background-position: 100% 0; } to { background-position: 0 0; } }
  @keyframes wf-spin { to { transform: rotate(360deg); } }
  @keyframes wf-breathe { 0%, 100% { box-shadow: 0 0 0 0 color-mix(in srgb, currentColor 40%, transparent); } 60% { box-shadow: 0 0 0 4px color-mix(in srgb, currentColor 0%, transparent); } }
  @keyframes wf-tip { 0%, 70% { transform: rotate(0); } 85%, 100% { transform: rotate(180deg); } }
  @keyframes wf-fade { from { opacity: 0; } }
  @keyframes wf-in { from { opacity: 0; transform: translateY(6px); } }
  @keyframes wf-settle { from { opacity: 0.7; transform: translateY(4px); } }
  @keyframes wf-drop { from { opacity: 0; transform: translateY(-4px) scale(0.98); } }
  @keyframes wf-rise { from { opacity: 0; transform: translateY(10px) scale(0.985); } }
  @keyframes wf-ring { from { box-shadow: 0 0 0 6px color-mix(in srgb, var(--primary) 22%, transparent); } to { box-shadow: 0 0 0 0 transparent; } }
  @keyframes wf-draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
  @keyframes wf-stop { from { opacity: 0; transform: scale(0.6); } }
  @keyframes wf-arrive { 0% { transform: scale(0.6); opacity: 0; } 50% { transform: scale(1.5); opacity: 1; } 100% { transform: scale(1); opacity: 1; } }
  @keyframes wf-check { from { stroke-dashoffset: 20; } to { stroke-dashoffset: 0; } }
}

