/* Tokens, buttons, top bar, chips, tabs, tables, cards, modal, token box, banner, bell, toast and
   skeleton are copied from the Pulse UI (Pulse repository, main at b5432a8, app/static/styles.css),
   with the changes listed in docs/design/s3-web-brief.md §4: no money/bar tokens, three text
   tokens darkened to reach 4.5:1, a system font stack, no inline styles (the CSP forbids them). */
:root {
  /* Light theme is sand and cream, not white: easier on the eyes over a working day. */
  --bg: #efe7d9;
  --surface: #faf5ec;
  --surface-2: #f3ecdf;
  --surface-3: #e9e0d0;
  --ink: #231e17;
  --ink-2: #5a5146;
  --ink-3: #6a6054;
  --line: #e4d9c6;
  --line-2: #d6c9b3;
  --accent: #4f46e5;
  --accent-ink: #ffffff;
  --accent-soft: #e9e5f6;
  --accent-text: #4338ca;
  --good: #11713f;
  --good-soft: #e0eedb;
  --mid: #8a4e05;
  --mid-soft: #f6e6c8;
  --bad: #b8291e;
  --bad-soft: #f6ddd5;
  --c-green: #1d6b2c; --c-coral: #a8402c; --c-violet: #6b3fa0;
  --c-slate: #3b4660; --c-red: #b0241b; --c-orange: #9a4a0b;
  --shadow: 0 1px 2px rgba(60, 44, 20, .05), 0 1px 3px rgba(60, 44, 20, .07);
  --shadow-lg: 0 12px 32px rgba(60, 44, 20, .16);
  --radius: 14px;
  --radius-sm: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0d13; --surface: #141823; --surface-2: #1a1f2c; --surface-3: #222838;
    --ink: #eef1f6; --ink-2: #b2bacb; --ink-3: #9aa3b5; --line: #252b3a; --line-2: #313849;
    --accent: #7c74ff; --accent-ink: #0b0d13; --accent-soft: #24214d; --accent-text: #aaa5ff;
    --good: #4fd08f; --good-soft: #10301f; --mid: #f2b04b; --mid-soft: #35270d;
    --bad: #ff7b6e; --bad-soft: #3a1714;
    --c-green: #6fd27c; --c-coral: #ff9a85; --c-violet: #c7a6f0;
    --c-slate: #a9b4d0; --c-red: #ff8a80; --c-orange: #ffaa66;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 16px 40px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0d13; --surface: #141823; --surface-2: #1a1f2c; --surface-3: #222838;
  --ink: #eef1f6; --ink-2: #b2bacb; --ink-3: #9aa3b5; --line: #252b3a; --line-2: #313849;
  --accent: #7c74ff; --accent-ink: #0b0d13; --accent-soft: #24214d; --accent-text: #aaa5ff;
  --good: #4fd08f; --good-soft: #10301f; --mid: #f2b04b; --mid-soft: #35270d;
  --bad: #ff7b6e; --bad-soft: #3a1714;
  --c-green: #6fd27c; --c-coral: #ff9a85; --c-violet: #c7a6f0;
  --c-slate: #a9b4d0; --c-red: #ff8a80; --c-orange: #ffaa66;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3); --shadow-lg: 0 16px 40px rgba(0, 0, 0, .5);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-text); }
.hidden, [hidden] { display: none !important; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { overflow-wrap: anywhere; }

/* -- boot / login ------------------------ */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner {
  width: 28px; height: 28px; border-radius: 50%;
  border: 3px solid var(--line-2); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line);
  border-radius: 20px; padding: 32px 28px 28px; box-shadow: var(--shadow-lg);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: -.01em; }
.brand-mark { width: 34px; height: 34px; border-radius: 10px; background: var(--accent); display: grid; place-items: center; flex: none; }
.brand-mark svg { width: 22px; height: 22px; }
.login-card h1 { font-size: 22px; margin: 26px 0 4px; letter-spacing: -.02em; }
.login-card p.sub { color: var(--ink-2); margin: 0 0 22px; }
.login-card .note { margin: 4px 0 14px; color: var(--ink-2); }
.login-card .alt { display: inline-block; padding: 10px 0; }
.field { display: grid; gap: 6px; margin-bottom: 14px; }
.field > span { font-size: 12.5px; font-weight: 600; color: var(--ink-2); }
.input, select.input {
  width: 100%; height: 42px; padding: 0 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-2); background: var(--surface); outline: none;
  font-size: 16px; transition: border-color .15s, box-shadow .15s;
}
.input::placeholder { color: var(--ink-3); opacity: 1; }
.input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.form-error { color: var(--bad); font-size: 13px; min-height: 18px; margin: 2px 0 10px; }

/* -- buttons ------------------------ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 14px; border-radius: var(--radius-sm); border: 1px solid var(--line-2);
  background: var(--surface); cursor: pointer; font-weight: 600; font-size: 13.5px; white-space: nowrap;
  text-decoration: none; color: var(--ink);
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.06); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: var(--bad); }
.btn.regl { color: var(--bad); background: var(--bad-soft); border-color: transparent; }
.btn.block { width: 100%; height: 44px; }
.btn.sm { height: 32px; padding: 0 10px; font-size: 13px; }
.icon-btn { width: 38px; padding: 0; }
.btn svg, .icon { width: 16px; height: 16px; flex: none; }

/* -- top bar ------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(12px); -webkit-backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--line);
}
.topbar-in { padding: 10px 24px; display: flex; align-items: center; gap: 10px; min-height: 62px; }
.brand-link { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font-weight: 800; font-size: 17px; letter-spacing: -.01em; flex: none; border-radius: 12px; }
.spacer { flex: 1; }
.topbar-in > * { flex: none; }
.topbar-in > .spacer { flex: 1 1 0; }
.top-nav { display: flex; align-items: center; gap: 4px; flex: none; }
.top-nav .sep { width: 1px; height: 22px; background: var(--line-2); margin: 0 6px; }
.btn.nav { border-color: var(--line-2); }
.btn.nav[aria-current="page"] { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.topbar-in > .user-name { flex: 0 1 auto; min-width: 0; max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); font-weight: 600; }
.menu-btn { display: none; }
.topbar-menu { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 24px 12px; }
.topbar-menu .btn { flex: 0 0 auto; }
.chip {
  display: inline-flex; align-items: center; gap: 5px; height: 24px; padding: 0 9px; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent-text); font-size: 12px; font-weight: 600; white-space: nowrap;
}
.chip.neutral { background: var(--surface-2); color: var(--ink-2); }
.chip.good { background: var(--good-soft); color: var(--good); }
.chip.mid { background: var(--mid-soft); color: var(--mid); }
.chip.bad { background: var(--bad); color: var(--surface); }
.sync-pill {
  display: inline-flex; align-items: center; gap: 8px; height: 36px; padding: 0 12px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: 13px; color: var(--ink-2);
  white-space: nowrap; flex: none;
}
.sync-pill b { color: var(--ink); font-weight: 600; }
.sync-pill .short { display: none; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); flex: none; }
.dot.stale { background: var(--mid); }
.dot.err { background: var(--bad); }
.search { position: relative; flex: 1 1 220px; min-width: 120px; max-width: 340px; }
.topbar-in > .search { flex: 1 1 220px; }
.search .input { height: 36px; padding-left: 34px; font-size: 14px; width: 100%; }
.search svg { position: absolute; left: 11px; top: 10px; color: var(--ink-3); pointer-events: none; }
.bell { position: relative; flex: none; }
.bell-count { position: absolute; top: -5px; right: -5px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px;
  background: var(--bad); color: var(--surface); font-size: 11.5px; font-weight: 700; line-height: 19px; text-align: center;
  box-shadow: 0 0 0 2px var(--surface); }

/* -- layout ------------------------ */
.page { padding: 22px 24px 60px; }
.container { max-width: 1168px; margin: 0 auto; }
/* the script page and the lesson list: one centred column (title included) capped for line length */
.col { max-width: 780px; margin-inline: auto; }
/* the history table: seven columns, one line per event where the screen allows */
.container.wide { max-width: 1600px; }
.section { margin-top: 18px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
.note { color: var(--ink-3); font-size: 12.5px; }
.page h1 { font-size: 24px; letter-spacing: -.02em; margin: 0 0 14px; }
.page h2 { font-size: 17px; margin: 22px 0 10px; }
.back-row { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.back-row h1 { margin: 0; font-size: 22px; }
.back-btn { font-size: 20px; width: 44px; height: 44px; flex: none; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.banner {
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 14px; border-radius: 12px;
  background: var(--mid-soft); color: var(--mid); font-size: 13px; margin-top: 14px;
}
.banner.err { background: var(--bad-soft); color: var(--bad); }
.banner .btn { margin-left: auto; flex: none; }
.skeleton { background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; border-radius: 8px; color: transparent !important; }
@keyframes shimmer { to { background-position: -200% 0; } }
.sk-line { height: 18px; margin-bottom: 10px; }
.sk-card { height: 84px; margin-bottom: 10px; border-radius: var(--radius); }
.empty { padding: 40px 16px; text-align: center; color: var(--ink-3); }
.empty b { display: block; color: var(--ink-2); font-size: 15px; margin-bottom: 4px; }
.dim { color: var(--ink-3); }

/* -- tabs ------------------------ */
.tabs { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; max-width: 100%; }
.tabs button { min-height: 36px; padding: 0 16px; border: 0; border-radius: 9px; background: transparent; cursor: pointer; font-weight: 600; color: var(--ink-2); white-space: nowrap; }
.tabs button.on { background: var(--surface-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }
.tabs .n { color: var(--ink-3); font-weight: 600; margin-left: 4px; }
.tabs { margin: 4px 0 14px; }

/* -- shops and scripts ------------------------ */
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.tile, .row-card {
  display: block; padding: 14px 16px; text-decoration: none; color: var(--ink); min-width: 0;
  min-height: 44px; text-align: left; width: 100%; overflow-wrap: anywhere; font: inherit;
}
.row-card .meta { display: block; margin: 0; }
.tile:hover, .row-card:hover { background: var(--surface-2); }
.tile h3, .row-card h3 { margin: 0 0 4px; font-size: 15.5px; letter-spacing: -.01em; }
.tile .meta, .row-card .meta { color: var(--ink-2); font-size: 13px; }
.list { display: grid; gap: 8px; }
.row-card .line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px; color: var(--ink-2); font-size: 13px; }
.row-card .shop { color: var(--ink-3); }
.res-head { display: flex; align-items: center; gap: 8px; margin: 18px 0 10px; }
.res-head h2 { margin: 0; }

/* -- script page ------------------------ */
.script-box { padding: 14px 16px; }
.script-box .facts { display: flex; flex-wrap: wrap; gap: 4px 16px; color: var(--ink-2); margin-bottom: 10px; }
.script-box .facts b { color: var(--ink); }
.script-box .btns { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.important {
  background: var(--mid-soft); border-left: 4px solid var(--mid); border-radius: var(--radius);
  padding: 14px 16px; margin-top: 14px;
}
.important h2 { margin: 0 0 8px; font-size: 16px; color: var(--mid); }
.acc { border: 1px solid var(--line); background: var(--surface); border-radius: var(--radius); margin-top: 8px; }
.acc, .xs-head, .gallery, .important, .res-head, .footnotes, .videos { scroll-margin-top: 150px; }
.acc > summary {
  display: flex; align-items: center; gap: 10px; min-height: 44px; padding: 8px 14px; cursor: pointer;
  list-style: none; font-weight: 700; font-size: 15px; border-radius: var(--radius);
}
.acc > summary::-webkit-details-marker { display: none; }
.acc > summary .t { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.acc .chev { color: var(--ink-3); transition: transform .2s; }
.acc[open] > summary .chev { transform: rotate(90deg); }
.acc .acc-body { padding: 2px 16px 14px; }
.xs-head { display: flex; align-items: center; gap: 12px; margin: 22px 0 8px; }
.xs-head h2 { margin: 0; flex: 1; }
.xs-row { --n: 2; display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 2px 0 10px; }
@media (min-width: 600px) { .xs-row { --n: 3; } }
@media (min-width: 900px) { .xs-row { --n: 4; } }
/* the card width divides the row exactly, so a snapped row never shows a half-cut card */
.xs-row .xs-item { flex: 0 0 calc((100% - 12px * (var(--n) - 1)) / var(--n)); display: flex; min-width: 0; scroll-snap-align: start; }
.xs-row .xs-card { flex: 1 1 auto; }
.xs-card {
  flex: 0 0 200px; scroll-snap-align: start; min-width: 0; text-align: left; padding: 10px; cursor: pointer;
  display: grid; gap: 6px; align-content: start; min-height: 44px;
}
.xs-card .pic { aspect-ratio: 4 / 3; border-radius: 8px; background: var(--surface-3); overflow: hidden; display: grid; place-items: center; color: var(--ink-3); font-size: 12px; }
.xs-card img, .xs-pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
.xs-card .nm { font-weight: 600; overflow-wrap: anywhere; }
.xs-card .pr { color: var(--ink-2); font-size: 13px; }
.xs-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.xs-grid .xs-card { flex: none; }
.xs-pic { max-width: 320px; border-radius: 10px; overflow: hidden; margin-bottom: 12px; }
.videos { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btn.vid { height: auto; min-height: 44px; padding: 4px 12px 4px 4px; }
.btn.vid img { width: 64px; height: 40px; object-fit: cover; border-radius: 6px; }
.btn.vid:not(:has(img)) { padding: 0 14px; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 10px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; overflow-wrap: anywhere; }

/* -- photo gallery (S2): a row of square thumbnails and a modal; a missing file is a tile with words -- */
.gallery h2 { margin: 18px 0 6px; }
.gallery .gal-none { margin: 0; color: var(--ink-2); }
/* the S3 .xs-row pattern: --n square thumbnails divide the row exactly, so a snapped row never
   shows a half-cut tile (or half a word of a «not copied yet» tile); --n steps with the width of
   the content column so a tile is never below 82 px (the longest word of the tile text needs about
   72 px) on a phone and 96 px or more above it */
.gal-row { --n: 3; display: flex; gap: 8px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 2px 0 10px; }
.gal-item { flex: 0 0 calc((100% - 8px * (var(--n) - 1)) / var(--n)); min-width: 0; scroll-snap-align: start; }
.gal-thumb {
  display: grid; place-items: center; width: 100%; aspect-ratio: 1; padding: 0; overflow: hidden; cursor: pointer;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm); background: var(--surface-3);
}
.gal-thumb { position: relative; }
/* a ring that does not depend on the photo: surface, accent, surface bands over the picture, so an
   accent-coloured photo cannot hide it; the transparent outline keeps the ring in forced-colours mode */
.gal-thumb:focus-visible { outline: 2px solid transparent; outline-offset: -3px; }
.gal-thumb:focus-visible::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit; pointer-events: none;
  box-shadow: inset 0 0 0 2px var(--surface), inset 0 0 0 4px var(--accent), inset 0 0 0 6px var(--surface);
}
.gal-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.miss { display: block; padding: 4px; color: var(--ink-3); font-size: 11px; line-height: 1.25; text-align: center; overflow-wrap: normal; }
@media (min-width: 384px) { .gal-row { --n: 4; } }
@media (min-width: 474px) { .gal-row { --n: 5; } }
@media (min-width: 564px) { .gal-row { --n: 6; } }
@media (min-width: 654px) { .gal-row { --n: 7; } }
@media (min-width: 744px) { .gal-row { --n: 8; } }
@media (min-width: 761px) { .gal-row { --n: 6; } }
@media (min-width: 768px) { .gal-row { --n: 7; } }
/* the dialog's own height limit drives the body here (not 75vh), and the picture leaves room for a
   footer that wraps to two rows. The stage has one height for every photo (and the footer one height
   whether the original link shows or not), so the ‹ › buttons stay where they were and a second click
   on the same spot turns the next photo instead of landing on the backdrop */
dialog.photo-dlg .modal-body { padding: 12px; display: grid; place-items: center; max-height: none; }
.ph-stage { width: 100%; height: max(160px, calc(100dvh - 300px)); display: flex; align-items: center; justify-content: center; touch-action: pan-y pinch-zoom; }
.ph-stage img { display: block; max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.ph-stage .miss { width: min(100%, 360px); height: min(100%, 270px); display: grid; place-items: center; font-size: 14px; border-radius: 10px; background: var(--surface-3); }
.photo-dlg .modal-foot { justify-content: space-between; align-items: center; }
.ph-nav-group { display: inline-flex; align-items: center; gap: 8px; }
.ph-nav { width: 44px; padding: 0; font-size: 20px; }
.ph-orig.off { visibility: hidden; }
.ph-count { min-width: 64px; text-align: center; font-weight: 600; white-space: nowrap; }

/* -- copy status (S2): three stat cards, then the unmatched lists as accordions -- */
.status-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; margin-top: 12px; }
.stat-card { padding: 14px 16px; }
.stat-card h2 { margin: 0 0 8px; font-size: 16px; }
.stat-card .kv { grid-template-columns: minmax(0, 1fr) auto; margin: 0; }
.stat-card .kv dd { text-align: right; font-weight: 600; }
.page h2.st-h { margin: 22px 0 4px; }
.acc > summary .chip { flex: none; }
.acc-body .table-scroll { margin-top: 8px; }

/* -- author HTML (sanitized at import) ------------------------ */
.rich { overflow-wrap: anywhere; line-height: 1.55; }
.rich > :first-child { margin-top: 0; }
.rich > :last-child { margin-bottom: 0; }
.rich p { margin: 0 0 .7em; }
.rich ul, .rich ol { padding-left: 22px; margin: 0 0 .7em; }
.rich img { max-width: 100%; height: auto; border-radius: 8px; cursor: zoom-in; }
.rich ins { text-decoration: underline; }
.rich .c-green { color: var(--c-green); } .rich .c-coral { color: var(--c-coral); }
.rich .c-violet { color: var(--c-violet); } .rich .c-slate { color: var(--c-slate); }
.rich .c-red { color: var(--c-red); } .rich .c-orange { color: var(--c-orange); }
.rich .c-grey { color: inherit; }
.rich .align-center { text-align: center; } .rich .align-right { text-align: right; }
.rich .align-justify { text-align: justify; }
.reg-item + .reg-item { margin-top: 18px; }
.reg-item h3 { margin: 0 0 6px; font-size: 15px; }

/* -- dialogs and drawers (native <dialog>, so the page behind is inert) -------------- */
dialog.modal {
  width: calc(100% - 32px); max-width: 640px; max-height: calc(100dvh - 32px); padding: 0; margin: auto;
  background: var(--surface); color: var(--ink); border-radius: 18px; box-shadow: var(--shadow-lg);
  border: 1px solid var(--line); overflow: hidden;
}
dialog.modal[open] { display: flex; flex-direction: column; }
dialog.modal.wide { max-width: 870px; }
dialog.modal::backdrop { background: rgba(9, 12, 20, .5); }
dialog.drawer {
  margin: 0 0 0 auto; width: min(560px, 92vw); max-width: none; height: 100dvh; max-height: 100dvh;
  border-radius: 0; border-width: 0 0 0 1px;
}
.modal-head { display: flex; align-items: center; gap: 10px; padding: 12px 12px 12px 18px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; flex: 1; min-width: 0; }
.modal-head h2:focus { outline: none; }
.close-btn { min-width: 44px; height: 44px; }
.modal-body { padding: 18px; overflow-y: auto; max-height: 75vh; min-height: 0; flex: 1 1 auto; }
.drawer .modal-body { max-height: none; }
/* a dialog sentence quotes names: a name longer than the line (one run without spaces) breaks
   instead of widening the dialog past a phone screen; ordinary words stay whole */
.modal-body > p { overflow-wrap: anywhere; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 14px 18px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.modal-foot .btn { min-height: 44px; }
.modal .note-box { margin: 12px 0 0; color: var(--ink-2); font-size: 13px; }
.token-box { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; padding: 14px; border: 1px solid var(--line-2); border-radius: 12px; background: var(--surface-2); }
.token-box code { flex: 1 1 250px; min-width: 0; overflow-wrap: anywhere; font: 600 19px/1.6 ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace; user-select: all; }
.alert-item { padding: 12px 0; border-bottom: 1px solid var(--line); display: grid; gap: 4px; }
.alert-item:last-child { border-bottom: 0; }
.alert-item .when { color: var(--ink-3); font-size: 12.5px; }

/* -- admin ------------------------ */
.admin-grid { display: grid; gap: 12px; }
.store-card { padding: 16px; display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: start; }
.store-card h3 { margin: 0; font-size: 16px; }
.store-card .head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.meta { display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--ink-2); font-size: 13px; margin-top: 6px; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; max-width: 330px; }
.err-text { color: var(--bad); font-size: 13px; margin-top: 6px; }
.ok-text { color: var(--good); font-size: 13px; margin-top: 6px; }
.tools { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 8px; }
.tools .search { flex: 1 1 220px; }
/* compact filters (controls as tall as a .btn): the history table keeps ten rows on a 900 px screen */
.filters { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: flex-end; margin-bottom: 12px; }
.filters .field { margin: 0; min-width: 176px; flex: 1 1 176px; max-width: 240px; gap: 4px; }
.filters .input { height: 38px; }
.filters input[type="date"] { padding: 0 8px; }
/* a select cannot wrap its value: these take the width of their longest option. The user select
   holds free-text names (up to 60 characters): its box stops at 320 px and its chosen name ends
   with «…»; the open list shows every name whole */
.filters .field.sel { flex: 1 1 auto; max-width: none; grid-template-columns: minmax(0, 1fr); }
.filters .field.sel-user { max-width: 320px; }
.filters .sel-user select { text-overflow: ellipsis; }
.filters .field.check-field { flex: 0 0 auto; align-self: flex-end; min-height: 44px; display: flex; align-items: center; }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; min-height: 44px; }
.check input { width: 20px; height: 20px; accent-color: var(--accent); }
.table-scroll { overflow-x: auto; border-radius: var(--radius); }
table.data { width: 100%; border-collapse: separate; border-spacing: 0; background: var(--surface); }
table.data th, table.data td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--line); overflow-wrap: break-word; }
/* a long run without spaces (admin.js cell()) breaks anywhere; words never break */
table.data .brk { overflow-wrap: anywhere; }
table.data thead th {
  font-size: 11.5px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--ink-3);
  background: var(--surface-2); position: sticky; top: 0;
}
table.data td.nw { white-space: nowrap; }
/* wherever the table (not the cards) is shown, the browser summary (at most ~35 characters) and
   the headers keep one line and «Причина», «Користувач» and «Хто виконав» take the wrapping; the
   fixed event labels keep one line from 1366 px */
@media (min-width: 1000px) { table.data td.one, table.data thead th { white-space: nowrap; } }
/* 8 px cell sides until 1366 px: at 1000 px the one-line cells and headers then fit without a
   sideways scroll (measured on the render fixture: 12 px sides overflow by 33 px) */
@media (min-width: 1000px) and (max-width: 1365px) { table.data th, table.data td { padding-left: 8px; padding-right: 8px; } }
@media (min-width: 1366px) { table.data td.one-wide { white-space: nowrap; } }
table.data tr.alert td { background: var(--bad-soft); }
.footnotes { margin-top: 12px; display: grid; gap: 4px; }
.more { margin-top: 14px; text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; font-weight: 600; font-size: 13.5px;
  transition: opacity .2s, transform .2s; z-index: 200; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
::view-transition-old(root), ::view-transition-new(root) { animation: none; mix-blend-mode: normal; }

/* -- top bar folds into «Меню»: admin below 1280 px (it has four buttons and the bell), operator
   below 1100 px. Below 1100 px the freshness pill takes its short form, below 900 px the brand
   text and the user name go (measured: nothing overlaps or overflows at any width). ------------ */
@media (max-width: 1279px) {
  .t-admin .top-nav { display: none; }
  .t-admin .menu-btn { display: inline-flex; }
}
@media (max-width: 1099px) {
  .t-op .top-nav { display: none; }
  .t-op .menu-btn { display: inline-flex; }
  .sync-pill .long, .sync-pill .when { display: none; }
  .sync-pill .short { display: inline; }
  .sync-pill { padding: 0 10px; }
}
@media (max-width: 1439px) {   /* the admin bar carries four buttons and the bell: its pill is short below 1440 px */
  .t-admin .sync-pill .long, .t-admin .sync-pill .when { display: none; }
  .t-admin .sync-pill .short { display: inline; }
  .t-admin .sync-pill { padding: 0 10px; }
}
@media (max-width: 899px) { .brand-text, .topbar-in > .user-name { display: none; } }
@media (min-width: 1280px) { .t-admin .topbar-menu { display: none !important; } }
@media (min-width: 1100px) { .t-op .topbar-menu { display: none !important; } }
@media (min-width: 761px) { .topbar-menu .mi-exit { display: none; } }

/* -- small screens ------------------------ */
@media (max-width: 760px) {
  .topbar-in { padding: 8px 16px; gap: 8px; flex-wrap: wrap; }
  .topbar-menu { padding: 0 16px 12px; }
  .exit-btn { display: none; }
  /* same selector weight as .topbar-in > .search above, or its flex basis wins and the search
     stays on the first row after «Меню» */
  .search, .topbar-in > .search { order: 20; flex: 1 0 100%; max-width: none; }
  /* three tabs share one row at 390 px with four-digit counts */
  .tabs { display: flex; gap: 2px; }
  .tabs button { flex: 1 1 auto; padding: 0 8px; }
  .page { padding: 16px 16px 48px; }
  .page h1 { font-size: 21px; }
  .store-card { grid-template-columns: 1fr; }
  .actions { justify-content: flex-start; max-width: none; }
  .tile, .row-card { padding: 12px 14px; }
  .close-btn .lbl { display: none; }
  dialog.drawer { width: 100vw; max-width: 100vw; border-width: 0; }
  dialog.modal:not(.drawer) { width: calc(100% - 16px); max-height: calc(100dvh - 16px); }
  .modal-body { padding: 14px; }
  .filters .field { max-width: none; min-width: 0; flex: 1 1 calc(50% - 6px); }
  .filters .field.sel, .filters .field.sel-user { flex: 1 1 100%; max-width: none; }
}
/* -- the history table needs about 900 px for its seven columns with every word whole
   (measured on the render fixture: 894 px); below 1000 px each event is a card ---------- */
@media (max-width: 999px) {
  table.data, table.data tbody, table.data tr, table.data td { display: block; width: 100%; }
  table.data thead { display: none; }
  table.data tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; padding: 6px 0; }
  table.data tr.alert { background: var(--bad-soft); }
  table.data td { border: 0; padding: 3px 12px; display: grid; grid-template-columns: 96px 1fr; gap: 8px; }
  table.data td::before { content: attr(data-label); color: var(--ink-3); font-size: 12px; font-weight: 600; }
  table.data td.nw { white-space: normal; }
  table.data tr.alert td { background: transparent; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
.nw { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
