/* components.css
   The shared parts: buttons, fields, badges, notices, the synthetic-data banner, the shell and its
   navigation, toasts, dialogs, loading skeletons and the still Tess figure.
   Family rules kept from the website: pills for anything interactive, flat panels on a plain page,
   one yellow action inside a navy or blue panel, status as words plus an icon. */

portal-shell, portal-nav, synthetic-banner, state-block, portal-toasts, portal-field, portal-dialog, tess-figure { display: block; }
portal-badge, source-label, redaction-chip { display: inline; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 11px 22px;
  border: 1.5px solid transparent; border-radius: var(--r-pill);
  font-family: var(--font-body); font-size: var(--t-body); font-weight: 600; line-height: 1.2;
  text-decoration: none; text-align: center; cursor: pointer;
  user-select: none; -webkit-user-select: none;
  transition: background-color 150ms ease, color 150ms ease, border-color 150ms ease;
}
.btn--lg { padding: 14px 28px; }
.btn--block { width: 100%; }
.btn--primary { background: var(--ink); color: var(--bg); }
.btn--brand { background: var(--brand); color: var(--on-brand); }
.btn--accent { background: var(--accent); color: var(--on-accent); }
.btn--outline { border-color: var(--ink); color: var(--ink); background: transparent; }
.btn--outline-light { border-color: var(--inverse-line); color: var(--on-inverse); background: transparent; }
.btn--quiet { color: var(--ink); background: transparent; padding-inline: 14px; text-decoration: underline; text-underline-offset: 3px; }
/* A control that cannot be used yet keeps readable text. The reason is always written beside it. */
.btn[aria-disabled="true"], .btn:disabled { background: var(--surface-hover); border-color: transparent; color: var(--muted); cursor: not-allowed; }
@media (hover: hover) and (pointer: fine) {
  .btn--primary:not([aria-disabled="true"]):hover { background: var(--brand); color: var(--on-brand); }
  .btn--brand:not([aria-disabled="true"]):hover { background: var(--brand-hover); }
  .btn--accent:not([aria-disabled="true"]):hover { background: var(--accent-hover); }
  .btn--outline:not([aria-disabled="true"]):hover { background: var(--ink); color: var(--bg); }
  .btn--outline-light:hover { border-color: var(--on-inverse); }
  .btn--quiet:hover { color: var(--link); }
}

.icon-btn {
  display: inline-grid; place-items: center; flex: none; width: 44px; height: 44px;
  border: 0; border-radius: 50%; background: transparent; color: inherit; cursor: pointer;
  transition: background-color 150ms ease;
}
@media (hover: hover) and (pointer: fine) {
  .icon-btn:hover { background: var(--surface-hover); }
}

.link-btn { padding: 0; border: 0; background: none; color: var(--link); cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }

@media (prefers-reduced-motion: no-preference) {
  .btn, .icon-btn, .choices label, .nav__item { transition: transform 160ms var(--ease-out), background-color 150ms ease, color 150ms ease, border-color 150ms ease; }
  .btn:not([aria-disabled="true"]):active, .choices label:active { transform: scale(0.97); }
  .icon-btn:active { transform: scale(0.94); }
}

/* ---------- Fields ---------- */

.form-panel { background: var(--surface); border-radius: var(--r-panel); padding: clamp(24px, 3vw, 36px); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .choices legend { font-weight: 500; font-size: var(--t-label); }
.field input, .field textarea, .field select {
  width: 100%; min-height: 48px; padding: 12px 16px;
  font-size: var(--t-body); line-height: 1.4;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--field-border); border-radius: var(--r-input);
  transition: border-color 150ms ease;
}
.field textarea { resize: vertical; min-height: 96px; }
.field select { appearance: none; -webkit-appearance: none; padding-right: 44px; text-overflow: ellipsis; }
.field__select { position: relative; }
.field__select .icon { position: absolute; right: 14px; top: 50%; margin-top: -10px; pointer-events: none; }
.field input:focus-visible, .field textarea:focus-visible, .field select:focus-visible { outline-offset: 1px; border-color: var(--focus); }
.field [aria-invalid="true"] { border-color: var(--danger); border-width: 2px; }
.field__hint { font-size: var(--t-label); color: var(--muted); }
.field__error { display: flex; gap: 6px; align-items: flex-start; font-size: var(--t-label); font-weight: 500; color: var(--danger); }
.field__error .icon { margin-top: 2px; }
.field--code input { font-variant-numeric: tabular-nums; letter-spacing: 0.3em; font-size: 22px; max-width: 12em; }
@media (prefers-reduced-motion: no-preference) {
  .field__error, .notice { transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out); }
  @starting-style { .field__error, .notice { opacity: 0; transform: translateY(-4px); } }
}

/* Radio pills, as on the website's urgency picker. Nothing is preselected unless the screen says so. */
.choices legend { margin-bottom: 8px; }
.choices__opts { display: flex; flex-wrap: wrap; gap: 8px; }
.choices input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.choices label {
  display: inline-flex; align-items: center; min-height: 48px; padding: 10px 18px;
  font-weight: 500; cursor: pointer; user-select: none; -webkit-user-select: none;
  color: var(--ink); background: var(--bg);
  border: 1px solid var(--field-border); border-radius: var(--r-pill);
}
.choices input:checked + label { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.choices input:focus-visible + label { outline: 3px solid var(--focus); outline-offset: 3px; }
@media (hover: hover) and (pointer: fine) {
  .choices input:not(:checked) + label:hover { border-color: var(--ink); }
}

.check { display: inline-flex; align-items: center; gap: 12px; min-height: 48px; cursor: pointer; font-weight: 500; }
.check input { width: 24px; height: 24px; margin: 0; accent-color: var(--brand); }

/* ---------- Badges, labels and the removal chip ---------- */

.badge {
  display: inline-flex; align-items: center; gap: 6px; vertical-align: middle;
  font-size: var(--t-small); font-weight: 500; line-height: 1.3; white-space: nowrap;
  padding: 3px 12px; border-radius: var(--r-pill);
  border: 1px solid var(--field-border); color: var(--muted); background: transparent;
}
.badge--brand { background: var(--brand); border-color: var(--brand); color: var(--on-brand); }
.badge--synthetic, .badge--warning { background: var(--warning-bg); border-color: var(--status-line); color: var(--warning); }
.badge--success { background: var(--success-bg); border-color: var(--status-line); color: var(--success); }
.badge--danger { background: var(--danger-bg); border-color: var(--status-line); color: var(--danger); }
.badge--info { background: var(--info-bg); border-color: var(--status-line); color: var(--info); }
.badge--wrap { white-space: normal; }
.count-pill {
  display: inline-grid; place-items: center; min-width: 26px; padding: 1px 8px;
  font-size: var(--t-small); font-weight: 600; font-variant-numeric: tabular-nums;
  border-radius: var(--r-pill); background: var(--ink); color: var(--bg);
}

.redaction {
  display: inline-flex; align-items: center; gap: 5px; vertical-align: baseline;
  margin-inline: 2px; padding: 0 9px 0 7px;
  font-size: var(--t-label); font-weight: 500; line-height: 1.5; white-space: nowrap;
  color: var(--ink); background: var(--surface);
  border: 1.5px dashed var(--field-border); border-radius: var(--r-pill);
  scroll-margin-block: 96px;
}
.redaction:target, .redaction:focus-visible { border-style: solid; border-color: var(--focus); }

/* ---------- Notices: a status sentence with an icon ---------- */

.notice {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 14px 16px; border-radius: var(--r-input);
  background: var(--info-bg); color: var(--ink); border: 1px solid var(--status-line);
}
.notice > .icon { margin-top: 3px; color: var(--info); }
.notice--warning { background: var(--warning-bg); }
.notice--warning > .icon { color: var(--warning); }
.notice--danger { background: var(--danger-bg); }
.notice--danger > .icon { color: var(--danger); }
.notice--success { background: var(--success-bg); }
.notice--success > .icon { color: var(--success); }
.notice--plain { background: var(--surface); }
.notice p + p { margin-top: 4px; }

/* ---------- Synthetic-data banner: always there, never dismissible ---------- */

synthetic-banner { position: sticky; top: 0; z-index: 30; background: var(--bg); padding-block: 8px; }
.synthetic-banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 9px 16px; border-radius: var(--r-card);
  background: var(--warning-bg); color: var(--warning); border: 1px solid var(--status-line);
  font-size: var(--t-label); font-weight: 500; line-height: 1.4;
}
.synthetic-banner .icon { margin-top: 1px; }
.synthetic-banner strong { font-weight: 600; }
@media (max-width: 639px) {
  synthetic-banner { padding-block: 6px; }
  .synthetic-banner { font-size: var(--t-small); padding: 8px 12px; border-radius: 18px; }
}

/* ---------- Shell ---------- */

.shell { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 var(--s-5); min-height: calc(100dvh - var(--banner-h)); grid-template-rows: auto 1fr auto; }
.shell__header { display: flex; flex-wrap: wrap; gap: 12px 24px; align-items: center; justify-content: space-between; padding-block: 12px 16px; }
.shell__main { min-width: 0; padding-bottom: var(--s-7); }
.shell__footer {
  border-top: 1px solid var(--line); padding-block: 20px calc(20px + var(--bottombar-h));
  font-size: var(--t-label); color: var(--muted);
  display: flex; flex-wrap: wrap; gap: 6px 32px; justify-content: space-between;
}
.shell__footer a { color: inherit; }
.brand { display: inline-flex; align-items: center; gap: 14px; color: var(--ink); text-decoration: none; font-weight: 600; border-radius: 10px; }
.brand img { height: var(--logo-h, 44px); width: auto; }
@media (max-width: 639px) { .brand img { height: var(--logo-h-phone, 36px); } }
/* A logo drawn only for white surfaces sits on a white plate in the dark scheme. The file is never altered. */
.brand--plate img { background: #FFFFFF; border-radius: 12px; padding: 6px 10px; box-sizing: content-box; }
.brand__name { font-family: var(--font-head); font-size: 20px; letter-spacing: -0.02em; }
.shell__where { font-size: var(--t-label); color: var(--muted); }

/* Navigation: the mist pill, with the current page as a white pill inside it. */
.nav { display: flex; gap: 4px; background: var(--surface); border-radius: var(--r-panel); padding: 6px; }
.nav__item {
  display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 10px 16px;
  color: var(--ink); text-decoration: none; font-weight: 500; font-size: 16px; line-height: 1.2;
  border-radius: var(--r-pill);
}
.nav__item[aria-current="page"] { background: var(--bg); font-weight: 600; }
.nav__label { flex: 1 1 auto; min-width: 0; }
@media (hover: hover) and (pointer: fine) {
  .nav__item:not([aria-current="page"]):hover { background: var(--surface-hover); }
}

/* 1000px and up: a left rail. */
@media (min-width: 1000px) {
  .shell { grid-template-columns: 248px minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .shell--plain { grid-template-columns: minmax(0, 1fr); }
  .shell__header { grid-column: 1; grid-row: 1 / span 2; align-self: start; position: sticky; top: calc(var(--banner-h) + 8px);
    flex-direction: column; flex-wrap: nowrap; align-items: stretch; justify-content: flex-start; gap: 20px; padding-block: 8px 24px; }
  .shell--plain .shell__header { position: static; grid-row: 1; flex-direction: row; align-items: center; justify-content: space-between; }
  .shell__body { grid-column: 2; grid-row: 1 / span 2; display: flex; flex-direction: column; min-width: 0; min-height: calc(100dvh - var(--banner-h)); }
  .shell--plain .shell__body { grid-column: 1; grid-row: 2; min-height: 0; }
  .shell__main { flex: 1 1 auto; padding-top: 12px; }
  .nav { flex-direction: column; }
  .shell__who { padding: 4px 12px; font-size: var(--t-label); color: var(--muted); overflow-wrap: anywhere; }
  .shell__who strong { display: block; color: var(--ink); font-weight: 600; }
}
/* Between 640 and 999px: the menu pill sits in the header row, as on the website. */
@media (max-width: 999px) {
  .shell__body { display: contents; }
  .shell__who { display: none; }
  .nav { flex-wrap: wrap; }
}
/* Under 640px: a bottom bar, clear of the home indicator. Four items fit on one row; a fifth wraps on a narrow phone. */
@media (max-width: 639px) {
  .shell__header { padding-block: 8px 12px; }
  portal-nav {
    position: fixed; z-index: 25; left: 0; right: 0; bottom: 0;
    background: var(--bg); border-top: 1px solid var(--line);
    padding: 8px max(12px, env(safe-area-inset-right, 0px)) calc(8px + env(safe-area-inset-bottom, 0px)) max(12px, env(safe-area-inset-left, 0px));
  }
  .nav__item { flex: 1 1 0; flex-direction: column; gap: 2px; padding: 6px 4px; min-height: 52px; font-size: 13px; text-align: center; justify-content: center; }
  .nav__label { flex: none; }
  .nav__item .count-pill { position: absolute; transform: translate(22px, -14px); min-width: 22px; padding: 0 6px; font-size: 12px; }
  .nav__item { position: relative; }
}

/* ---------- State blocks: empty, error, not in plan, not connected ---------- */

.state { display: flex; flex-wrap: wrap; gap: 20px 28px; align-items: center; padding: clamp(24px, 4vw, 40px); background: var(--surface); border-radius: var(--r-panel); }
.state__text { flex: 1 1 260px; display: flex; flex-direction: column; gap: 12px; align-items: flex-start; }
.state__text p { max-width: 36em; }
.state--bare { background: transparent; padding: 0; }
.tess--sm { width: 88px; }

/* Loading: a skeleton of the final layout, shown after 150 ms. The shimmer ends by itself. */
.skeleton { display: flex; flex-direction: column; gap: 14px; }
.skeleton__bar { height: 16px; border-radius: 8px; background: var(--surface-hover); }
.skeleton__bar--title { height: 30px; width: 55%; border-radius: 10px; }
.skeleton__bar--short { width: 35%; }
.skeleton__bar--mid { width: 70%; }
.skeleton__block { height: 88px; border-radius: var(--r-card); background: var(--surface); }
@media (prefers-reduced-motion: no-preference) {
  @keyframes skeleton-pulse { 50% { opacity: .55; } }
  .skeleton__bar, .skeleton__block { animation: skeleton-pulse 1.4s ease-in-out 3; }
}

/* ---------- Toasts: one live region, floating, so it carries the one shadow ---------- */

portal-toasts {
  position: fixed; z-index: 60; right: max(20px, env(safe-area-inset-right, 0px));
  bottom: calc(max(20px, env(safe-area-inset-bottom, 0px)) + var(--bottombar-h));
  display: flex; flex-direction: column; gap: 10px; align-items: flex-end;
  width: min(420px, calc(100vw - 24px)); pointer-events: none;
}
.toast {
  pointer-events: auto; display: flex; gap: 10px; align-items: flex-start; width: 100%;
  padding: 12px 8px 12px 16px; border-radius: var(--r-card);
  background: var(--inverse); color: var(--on-inverse); border: 1px solid var(--inverse-line);
  box-shadow: var(--shadow-float);
}
.toast > .icon { margin-top: 12px; color: var(--accent); }
.toast--error > .icon { color: #FF8A80; }
.toast__text { flex: 1 1 auto; min-width: 0; padding-block: 10px; font-size: 16px; line-height: 1.4; }
.toast .icon-btn { color: var(--on-inverse); }
.toast :focus-visible { outline-color: var(--on-inverse); }
@media (hover: hover) and (pointer: fine) { .toast .icon-btn:hover { background: rgb(255 255 255 / .14); } }
@media (max-width: 639px) { portal-toasts { right: 12px; } }
@media (prefers-reduced-motion: no-preference) {
  .toast { transition: opacity 200ms var(--ease-out), transform 200ms var(--ease-out); }
  @starting-style { .toast { opacity: 0; transform: translateY(8px); } }
}

/* ---------- Dialog ---------- */

.dialog {
  width: min(480px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); overflow: auto;
  padding: clamp(24px, 4vw, 36px); border: 1px solid var(--line); border-radius: var(--r-panel);
  background: var(--bg); color: var(--ink); box-shadow: var(--shadow-float);
}
.dialog::backdrop { background: rgb(11 16 38 / .55); }
.dialog__actions { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }

/* ---------- Definition rows and tables ---------- */

.facts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0; }
.facts > div { display: grid; grid-template-columns: minmax(120px, 220px) minmax(0, 1fr); gap: 4px 24px; padding: 14px 0; border-top: 1px solid var(--line); }
.facts > div:first-child { border-top: 0; }
.facts dt { color: var(--muted); font-size: var(--t-label); padding-top: 2px; }
.facts dd { font-weight: 500; overflow-wrap: anywhere; }
@media (max-width: 639px) { .facts > div { grid-template-columns: minmax(0, 1fr); } }

.table { width: 100%; border-collapse: collapse; font-size: 16px; }
.table th, .table td { text-align: left; vertical-align: top; padding: 12px 14px 12px 0; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; }
.table thead th { font-family: var(--font-head); font-weight: 600; font-size: 15px; letter-spacing: -0.01em; border-bottom: 2px solid var(--ink); white-space: nowrap; }
.table tbody th { font-weight: 500; }
.table td.num, .table th.num { text-align: right; padding-right: 0; }
/* Narrow screens: each row becomes a labelled stack, so nothing scrolls sideways. */
@media (max-width: 899px) {
  .table--stack thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table--stack, .table--stack tbody, .table--stack tr, .table--stack td, .table--stack th { display: block; }
  .table--stack tr { padding: 14px 0; border-top: 2px solid var(--ink); }
  .table--stack td, .table--stack tbody th { display: grid; grid-template-columns: minmax(96px, 34%) minmax(0, 1fr); gap: 12px; padding: 4px 0; border: 0; }
  .table--stack td::before, .table--stack tbody th::before { content: attr(data-label); color: var(--muted); font-size: var(--t-label); font-weight: 400; }
}

/* ---------- Tess, still. Decorative: she says nothing here because no assistant is connected. ---------- */

.tess { margin: 0; width: 120px; flex: none; }
.tess svg { width: 100%; height: auto; overflow: visible; }

/* ---------- Keyboard shortcut list ---------- */

.keys { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 10px 20px; align-items: baseline; }
kbd {
  display: inline-grid; place-items: center; min-width: 30px; padding: 2px 8px;
  font-family: var(--font-body); font-size: var(--t-label); font-weight: 600;
  border: 1.5px solid var(--ink); border-radius: 8px; background: var(--bg); color: var(--ink);
}
