/* =============================================================================================
   Owner app design system (WP11). Mobile-first; no web fonts; no external resources.
   Used by /login and every /app/*.html page. JS side: /assets/app/lib/kit.js.

   TOKENS  (light in :root, dark in the prefers-color-scheme block; never hard-code colours)
     surfaces  --c-bg --c-surface --c-surface-2 --c-border (decorative) --c-border-strong (inputs)
     text      --c-text --c-muted --c-link
     action    --c-primary --c-primary-hover --c-on-primary --c-danger --c-on-danger --c-focus
     status    --c-{info,success,warning,danger,neutral}-{bg,fg}
     spacing   --s-1 (4px) ... --s-7 (48px)   radius --r-1 --r-2 --r-pill   --shadow
   A unit test checks every text/background token pair for WCAG AA contrast in both themes.

   COMPONENTS
     layout    .app .app-main .page-head .stack .cluster .grid .muted .small .num .visually-hidden
     shell     .skip-link .app-header(.is-open) .brand .nav-toggle .app-nav .app-banner(--demo) .loading
     buttons   .btn + --primary | --secondary | --danger | --ghost, size --small, width --block;
               aria-disabled="true" / [disabled] look disabled; a.btn works the same
     forms     .field > label + input|select|textarea + .hint + .field-error; .check (checkbox
               or radio row); .form-error (form-level); .input--code; fieldset/legend
     content   .card .card__title .card--accent; .notice.notice--{info,success,warning,danger};
               .chip.chip--{neutral,info,success,warning,danger,example,from-text};
               .tag--example (amber "Example - set your own"), .tag--from-text (green);
               .table-wrap > .table (th scope=col; td.num right-aligned); .empty (empty state);
               .stats (number strip); .steps (wizard progress); .tips > .tip (dismissible tip);
               .checklist; .dialog (<dialog>); .toasts > .toast.toast--{success,info,warning,error}
   ============================================================================================= */

:root {
  color-scheme: light dark;

  --c-bg: #f5f6f8;
  --c-surface: #ffffff;
  --c-surface-2: #eef1f5;
  --c-border: #dde1e7;
  --c-border-strong: #6b7280;
  --c-text: #111827;
  --c-muted: #4b5563;
  --c-link: #1d4ed8;
  --c-primary: #1d4ed8;
  --c-primary-hover: #1e40af;
  --c-on-primary: #ffffff;
  --c-danger: #b42318;
  --c-on-danger: #ffffff;
  --c-focus: #1d4ed8;

  --c-info-bg: #e8f0fe;
  --c-info-fg: #1e3a8a;
  --c-success-bg: #e6f5ea;
  --c-success-fg: #14532d;
  --c-warning-bg: #fff3d1;
  --c-warning-fg: #7a4100;
  --c-danger-bg: #fdecea;
  --c-danger-fg: #9b1c13;
  --c-neutral-bg: #eceff3;
  --c-neutral-fg: #374151;

  --s-1: 0.25rem;
  --s-2: 0.5rem;
  --s-3: 0.75rem;
  --s-4: 1rem;
  --s-5: 1.5rem;
  --s-6: 2rem;
  --s-7: 3rem;
  --r-1: 6px;
  --r-2: 10px;
  --r-pill: 999px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 10%);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --tap: 44px;
  --max: 72rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --c-bg: #0e151d;
    --c-surface: #16202b;
    --c-surface-2: #1e2a37;
    --c-border: #2b3948;
    --c-border-strong: #8593a3;
    --c-text: #e6edf3;
    --c-muted: #a9b6c4;
    --c-link: #8db3ff;
    --c-primary: #8db3ff;
    --c-primary-hover: #adc8ff;
    --c-on-primary: #0b1220;
    --c-danger: #ff9488;
    --c-on-danger: #1f0705;
    --c-focus: #adc8ff;

    --c-info-bg: #15294a;
    --c-info-fg: #b9d0ff;
    --c-success-bg: #11301e;
    --c-success-fg: #94e5ad;
    --c-warning-bg: #3a2905;
    --c-warning-fg: #ffd88a;
    --c-danger-bg: #3d1513;
    --c-danger-fg: #ffb3aa;
    --c-neutral-bg: #253241;
    --c-neutral-fg: #d5dee8;

    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

/* ---- Base --------------------------------------------------------------------------------- */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--c-bg);
  color: var(--c-text);
  font: 1rem/1.5 var(--font);
  overflow-wrap: anywhere;
}

h1, h2, h3 { line-height: 1.25; margin: 0 0 var(--s-3); }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }
p { margin: 0 0 var(--s-3); }
p:last-child { margin-bottom: 0; }

a { color: var(--c-link); text-underline-offset: 0.15em; }
a:hover { text-decoration-thickness: 2px; }

:focus-visible { outline: 3px solid var(--c-focus); outline-offset: 2px; }
[tabindex="-1"]:focus:not(:focus-visible) { outline: none; }

code, pre, kbd { font-family: var(--font-mono); font-size: 0.9em; }
pre { white-space: pre-wrap; background: var(--c-surface-2); padding: var(--s-3); border-radius: var(--r-1); overflow-x: auto; }

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap;
}

.muted { color: var(--c-muted); }
.small { font-size: 0.875rem; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- Layout ------------------------------------------------------------------------------- */

.app-main {
  max-width: var(--max);
  margin: 0 auto;
  padding: var(--s-4);
}
.app-main:focus { outline: none; }

.stack > * + * { margin-top: var(--s-4); }
.stack > :empty { display: none; }
.cluster { display: flex; flex-wrap: wrap; gap: var(--s-2); align-items: center; }
.grid { display: grid; gap: var(--s-4); grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }

.page-head {
  display: flex; flex-wrap: wrap; gap: var(--s-3);
  align-items: center; justify-content: space-between;
  margin-bottom: var(--s-4);
}
.page-head h1 { margin: 0; }

.loading { color: var(--c-muted); padding: var(--s-6) 0; text-align: center; }

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

.skip-link {
  position: absolute; left: var(--s-2); top: -100px; z-index: 100;
  background: var(--c-surface); color: var(--c-link);
  padding: var(--s-2) var(--s-3); border-radius: var(--r-1); box-shadow: var(--shadow);
}
.skip-link:focus { top: var(--s-2); }

.app-header {
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}
.app-header__bar {
  max-width: var(--max); margin: 0 auto;
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2) var(--s-3);
  padding: var(--s-2) var(--s-4);
  min-height: 3.5rem;
}
.brand { font-weight: 700; font-size: 1.1rem; color: var(--c-text); text-decoration: none; }
.brand:hover { text-decoration: underline; }
.app-header__business { color: var(--c-muted); font-size: 0.9rem; }
.app-header__badge { display: none; }
.nav-toggle { margin-left: auto; }

.app-nav { display: none; border-top: 1px solid var(--c-border); }
.app-header.is-open .app-nav, .app-header--minimal .app-nav { display: block; }
.app-header--minimal .app-nav { border-top: 0; }
.app-nav__list {
  list-style: none; margin: 0 auto; padding: var(--s-2) var(--s-4);
  max-width: var(--max);
  display: flex; flex-direction: column; gap: var(--s-1);
}
.app-nav__link {
  display: flex; align-items: center; min-height: var(--tap);
  padding: 0 var(--s-3); border-radius: var(--r-1);
  color: var(--c-text); text-decoration: none;
  background: none; border: 0; font: inherit; cursor: pointer; width: 100%; text-align: left;
}
.app-nav__link:hover { background: var(--c-surface-2); }
.app-nav__signout { color: var(--c-link); }
.app-nav__link[aria-current="page"] { background: var(--c-info-bg); color: var(--c-info-fg); font-weight: 600; }
.app-header--minimal .app-nav__list { flex-direction: row; justify-content: flex-end; padding-top: 0; }
.app-header--minimal .app-nav__link { width: auto; }

.app-banner { max-width: var(--max); margin: var(--s-3) auto 0; padding: 0 var(--s-4); }
/* The read-only demo (lib/demo.js): always shown, the sign-up link on its own line */
.app-banner--demo .notice__action { display: inline-block; margin-top: var(--s-1); }

@media (min-width: 48rem) {
  .app-main { padding: var(--s-5) var(--s-5) var(--s-7); }
  .app-header__badge { display: inline-flex; }
  .nav-toggle { display: none; }
  .app-header__bar { padding-bottom: 0; }
  .app-nav, .app-header.is-open .app-nav { display: block; border-top: 0; }
  .app-nav__list { flex-direction: row; flex-wrap: wrap; padding: var(--s-1) var(--s-4) var(--s-2); }
  .app-nav__link { width: auto; }
  .app-nav__list > li:last-child { margin-left: auto; }
  .app-header--minimal .app-nav__list > li:last-child { margin-left: 0; }
  h1 { font-size: 1.75rem; }
}

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

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s-2);
  min-height: var(--tap); padding: 0 var(--s-4);
  border: 1px solid transparent; border-radius: var(--r-1);
  font: inherit; font-weight: 600; line-height: 1.2; text-align: center; text-decoration: none;
  cursor: pointer; white-space: normal;
  background: var(--c-surface); color: var(--c-text); border-color: var(--c-border-strong);
}
.btn:hover { background: var(--c-surface-2); }
.btn--primary { background: var(--c-primary); color: var(--c-on-primary); border-color: var(--c-primary); }
.btn--primary:hover { background: var(--c-primary-hover); border-color: var(--c-primary-hover); }
.btn--secondary { background: var(--c-surface); color: var(--c-text); border-color: var(--c-border-strong); }
.btn--danger { background: var(--c-danger); color: var(--c-on-danger); border-color: var(--c-danger); }
.btn--danger:hover { filter: brightness(0.92); background: var(--c-danger); }
.btn--ghost { background: transparent; color: var(--c-link); border-color: transparent; }
.btn--ghost:hover { background: var(--c-surface-2); }
.btn--small { min-height: 36px; padding: 0 var(--s-3); font-size: 0.9rem; }
.btn--block { display: flex; width: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.6; cursor: not-allowed; }
@media (pointer: coarse) { .btn--small { min-height: var(--tap); } }

/* ---- Forms -------------------------------------------------------------------------------- */

.field { display: flex; flex-direction: column; gap: var(--s-1); }
.field > label, legend { font-weight: 600; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend { padding: 0; margin-bottom: var(--s-2); }

input:not([type="checkbox"], [type="radio"]), select, textarea {
  width: 100%; min-height: var(--tap);
  padding: var(--s-2) var(--s-3);
  font: inherit; color: var(--c-text);
  background: var(--c-surface);
  border: 1px solid var(--c-border-strong); border-radius: var(--r-1);
}
textarea { min-height: 7rem; resize: vertical; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; }
input[aria-invalid="true"], select[aria-invalid="true"], textarea[aria-invalid="true"] {
  border-color: var(--c-danger-fg); border-width: 2px;
}
input[type="checkbox"], input[type="radio"] { width: 1.25rem; height: 1.25rem; margin: 0.15rem 0 0; accent-color: var(--c-primary); flex: none; }

.check { display: flex; gap: var(--s-2); align-items: flex-start; min-height: var(--tap); padding: var(--s-2) 0; }
.check label { font-weight: 400; }

.hint { margin: 0; color: var(--c-muted); font-size: 0.9rem; }
.field-error { margin: 0; color: var(--c-danger-fg); font-size: 0.9rem; font-weight: 600; }
.form-error {
  margin: 0; padding: var(--s-3); border-radius: var(--r-1);
  background: var(--c-danger-bg); color: var(--c-danger-fg); font-weight: 600;
}

.input--code {
  font-family: var(--font-mono); font-size: 1.5rem !important;
  letter-spacing: 0.3em; text-align: center;
}

/* ---- Cards, notices, chips, tags ---------------------------------------------------------- */

.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border); border-radius: var(--r-2);
  padding: var(--s-4); box-shadow: var(--shadow);
}
.card > * + * { margin-top: var(--s-3); }
.card__title { margin: 0; }
.card--accent { border-left: 4px solid var(--c-primary); }
@media (min-width: 48rem) { .card { padding: var(--s-5); } }

.notice {
  margin: 0; padding: var(--s-3) var(--s-4);
  border-radius: var(--r-1); border-left: 4px solid currentColor;
  background: var(--c-info-bg); color: var(--c-info-fg);
}
.notice--info { background: var(--c-info-bg); color: var(--c-info-fg); }
.notice--success { background: var(--c-success-bg); color: var(--c-success-fg); }
.notice--warning { background: var(--c-warning-bg); color: var(--c-warning-fg); }
.notice--danger { background: var(--c-danger-bg); color: var(--c-danger-fg); }
.notice__title { font-weight: 700; margin-bottom: var(--s-1); }
.notice__text { margin: 0; }
.notice__action { color: inherit; font-weight: 600; }
.notice a { color: inherit; }

.chip, .tag--example, .tag--from-text {
  display: inline-flex; align-items: center; gap: var(--s-1);
  padding: 0.1rem 0.6rem; border-radius: var(--r-pill);
  font-size: 0.8rem; font-weight: 600; line-height: 1.5; white-space: nowrap;
  background: var(--c-neutral-bg); color: var(--c-neutral-fg);
}
.chip--info { background: var(--c-info-bg); color: var(--c-info-fg); }
.chip--success { background: var(--c-success-bg); color: var(--c-success-fg); }
.chip--warning, .chip--example, .tag--example { background: var(--c-warning-bg); color: var(--c-warning-fg); }
.chip--danger { background: var(--c-danger-bg); color: var(--c-danger-fg); }
.chip--from-text, .tag--from-text { background: var(--c-success-bg); color: var(--c-success-fg); white-space: normal; }

/* ---- Tables ------------------------------------------------------------------------------- */

.table-wrap { overflow-x: auto; border: 1px solid var(--c-border); border-radius: var(--r-1); }
.table { width: 100%; border-collapse: collapse; background: var(--c-surface); }
.table caption { text-align: left; font-weight: 600; padding: var(--s-2) var(--s-3); }
.table th, .table td { padding: var(--s-2) var(--s-3); text-align: left; vertical-align: top; border-bottom: 1px solid var(--c-border); }
.table th { font-size: 0.85rem; color: var(--c-muted); background: var(--c-surface-2); white-space: nowrap; }
.table tbody tr:last-child td { border-bottom: 0; }
.table .num { text-align: right; }

/* Narrow screens: each row becomes a small card, labelled from data-label. */
@media (max-width: 40rem) {
  .table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { border-bottom: 1px solid var(--c-border); padding: var(--s-2) 0; }
  .table tbody tr:last-child { border-bottom: 0; }
  .table td { border: 0; padding: var(--s-1) var(--s-3); display: grid; grid-template-columns: 9rem 1fr; gap: var(--s-2); }
  .table td::before { content: attr(data-label); color: var(--c-muted); font-size: 0.85rem; }
  .table .num { text-align: left; }
}

/* ---- Empty states, stats, steps ----------------------------------------------------------- */

.empty {
  text-align: center; padding: var(--s-6) var(--s-4);
  background: var(--c-surface); border: 1px dashed var(--c-border-strong); border-radius: var(--r-2);
}
.empty > * + * { margin-top: var(--s-3); }
.empty .cluster { justify-content: center; }
.empty__title { margin: 0; }
.empty__help { font-size: 0.9rem; }
.empty__text { color: var(--c-muted); max-width: 36rem; margin-left: auto; margin-right: auto; }

.stats__title { font-size: 1rem; color: var(--c-muted); font-weight: 600; margin-bottom: var(--s-2); }
.stats__list { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s-2); margin: 0; }
.stats__item { background: var(--c-surface); border: 1px solid var(--c-border); border-radius: var(--r-1); padding: var(--s-3); }
.stats__item dt { color: var(--c-muted); font-size: 0.85rem; }
.stats__item dd { margin: 0; font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }
@media (min-width: 48rem) { .stats__list { grid-template-columns: repeat(4, 1fr); } }

.steps { margin-bottom: var(--s-4); }
.steps__text { font-weight: 600; margin-bottom: var(--s-2); }
.steps__list { list-style: none; margin: 0; padding: 0; display: flex; gap: 4px; }
.steps__item { flex: 1; height: 6px; border-radius: var(--r-pill); background: var(--c-surface-2); border: 1px solid var(--c-border-strong); }
.steps__item--done { background: var(--c-primary); border-color: var(--c-primary); }
.steps__item--current { background: var(--c-primary); border-color: var(--c-primary); opacity: 0.55; }
.steps__label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* ---- Tips, checklist ---------------------------------------------------------------------- */

.tips:empty { display: none; }
.tips > * + * { margin-top: var(--s-2); }
.tip {
  display: block; color: var(--c-text); font-size: 1rem;
  background: var(--c-info-bg); border: 1px solid var(--c-border); border-left: 4px solid var(--c-info-fg);
  border-radius: var(--r-1); padding: var(--s-3) var(--s-4);
}
.tip__title { font-weight: 700; color: var(--c-info-fg); margin-bottom: var(--s-1); }
.tip__text { margin-bottom: var(--s-2); color: var(--c-info-fg); }
.tip__actions { display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: center; }
.tip__actions a { color: var(--c-info-fg); font-weight: 600; }
.tip .btn--ghost { color: var(--c-info-fg); }

.checklist__progress { color: var(--c-muted); }
.checklist__bar { width: 100%; height: 8px; accent-color: var(--c-primary); }
.checklist__list { list-style: none; margin: 0; padding: 0; }
.checklist__item { display: flex; gap: var(--s-3); padding: var(--s-3) 0; border-top: 1px solid var(--c-border); }
.checklist__mark {
  flex: none; width: 1.5rem; height: 1.5rem; margin-top: 0.1rem;
  border: 2px solid var(--c-border-strong); border-radius: 50%;
}
.checklist__item.is-done .checklist__mark { background: var(--c-success-fg); border-color: var(--c-success-fg); position: relative; }
.checklist__item.is-done .checklist__mark::after {
  content: ""; position: absolute; left: 0.42rem; top: 0.18rem; width: 0.35rem; height: 0.7rem;
  border: solid var(--c-surface); border-width: 0 2px 2px 0; transform: rotate(45deg);
}
.checklist__item.is-done .checklist__label { color: var(--c-muted); text-decoration: line-through; }
.checklist__item.is-next .checklist__mark { border-color: var(--c-primary); }
.checklist__label { font-weight: 600; }
.checklist__body > * + * { margin-top: var(--s-1); }
.checklist__hint { color: var(--c-muted); font-size: 0.9rem; margin: 0; }
.checklist__help { font-size: 0.9rem; }

/* ---- Dialog, toasts ----------------------------------------------------------------------- */

.dialog {
  width: min(28rem, calc(100% - 2rem));
  border: 1px solid var(--c-border); border-radius: var(--r-2);
  background: var(--c-surface); color: var(--c-text);
  padding: var(--s-5); box-shadow: 0 10px 30px rgb(0 0 0 / 25%);
}
.dialog__title { margin-bottom: var(--s-2); }
.dialog__text { color: var(--c-muted); }
.dialog::backdrop { background: rgb(0 0 0 / 50%); }
.dialog__actions { justify-content: flex-end; margin-top: var(--s-4); }

.toasts {
  position: fixed; z-index: 1000; left: var(--s-3); right: var(--s-3); bottom: var(--s-3);
  display: flex; flex-direction: column; gap: var(--s-2); pointer-events: none;
}
.toasts--alert { bottom: auto; top: var(--s-3); }
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: var(--s-2);
  padding: var(--s-3) var(--s-3) var(--s-3) var(--s-4);
  border-radius: var(--r-1); box-shadow: 0 6px 20px rgb(0 0 0 / 20%);
  background: var(--c-surface); color: var(--c-text); border: 1px solid var(--c-border); border-left: 4px solid var(--c-info-fg);
}
.toast--success { border-left-color: var(--c-success-fg); }
.toast--warning { background: var(--c-warning-bg); color: var(--c-warning-fg); border-left-color: var(--c-warning-fg); }
.toast--error { background: var(--c-danger-bg); color: var(--c-danger-fg); border-left-color: var(--c-danger-fg); font-weight: 600; }
.toast__text { flex: 1; margin: 0; padding-top: 0.35rem; }
.toast__close {
  flex: none; min-width: var(--tap); min-height: var(--tap); margin: calc(-1 * var(--s-2)) calc(-1 * var(--s-2)) calc(-1 * var(--s-2)) 0;
  background: none; border: 0; border-radius: var(--r-1); color: inherit; font-size: 1.4rem; line-height: 1; cursor: pointer;
}
.toast__close:hover { background: rgb(127 127 127 / 15%); }
@media (min-width: 48rem) {
  .toasts { left: auto; width: 24rem; }
}

/* ---- Sign-in page ------------------------------------------------------------------------- */

.auth { max-width: 26rem; margin: 0 auto; padding: var(--s-6) var(--s-4) var(--s-7); }
.auth:focus { outline: none; }
.auth > * + * { margin-top: var(--s-4); }
.auth__brand { text-align: center; margin: 0; }
.auth__brand .brand { font-size: 1.35rem; }
.auth__card .stack > * + * { margin-top: var(--s-3); }
.auth__help { text-align: center; }
/* "Try the demo" (lib/demo.js) */
.auth__demo { margin-top: var(--s-4); padding-top: var(--s-4); border-top: 1px solid var(--c-border); }
.auth__demo > * + * { margin-top: var(--s-2); }

/* ---- Motion, print ------------------------------------------------------------------------ */

@media (prefers-reduced-motion: no-preference) {
  .toast { animation: toast-in 160ms ease-out; }
  @keyframes toast-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
}

@media print {
  .app-header, .app-banner, .toasts, .skip-link, .nav-toggle { display: none !important; }
  body { background: #fff; color: #000; }
  .card { box-shadow: none; }
}
