/* kit/tools-feedback: the Tools button, its menu and tip, the report form, the lists, Admin -> Feedback, the page-copy viewer,
   the toast and the new-version bar. Every class starts tk-, so nothing here can collide with the app's own.
   Colours are tokens: map them to the app's own on :root (see the README). Dark mode follows the system unless the app sets
   data-theme="light" / "dark" on <html>. No inline styles are needed by any script here: this works under a strict CSP. */
:root {
  --tk-bg: #fff; --tk-fg: #1b1f1d; --tk-muted: #5f6762; --tk-surface: #fff; --tk-surface-2: #f1f3f1; --tk-line: #d9dedb;
  --tk-accent: #1f6f4a; --tk-accent-fg: #fff; --tk-accent-soft: #e3f1e9; --tk-danger: #d23b3b; --tk-ok: #1f7a3d; --tk-warn: #b36b00;
  --tk-bar: #1b1f1d; --tk-bar-fg: #fff; --tk-sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --tk-fab-bottom: 18px;               /* the app's own bottom tab bar? set --tk-fab-bottom-phone: 84px (KAS: 84px on phones) */
  --tk-fab-bottom-phone: var(--tk-fab-bottom);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --tk-bg: #131614; --tk-fg: #e8ece9; --tk-muted: #9aa49e; --tk-surface: #1c201e; --tk-surface-2: #262b28; --tk-line: #353b37;
    --tk-accent: #5bc08a; --tk-accent-fg: #0b1a12; --tk-accent-soft: #1d3326; --tk-danger: #ef6a6a; --tk-ok: #5bc08a; --tk-warn: #e0a24a;
    --tk-bar: #e8ece9; --tk-bar-fg: #131614;
  }
}
:root[data-theme="dark"] {
  --tk-bg: #131614; --tk-fg: #e8ece9; --tk-muted: #9aa49e; --tk-surface: #1c201e; --tk-surface-2: #262b28; --tk-line: #353b37;
  --tk-accent: #5bc08a; --tk-accent-fg: #0b1a12; --tk-accent-soft: #1d3326; --tk-danger: #ef6a6a; --tk-ok: #5bc08a; --tk-warn: #e0a24a;
  --tk-bar: #e8ece9; --tk-bar-fg: #131614;
}

/* Every control in a window is a full finger's width on a phone (the render audit's tap-target check; Card Discounts, 2 Nov 2026). */
@media (max-width: 640px), (pointer: coarse) {
  .tk-sheet .tk-btn, .tk-sheet .tk-seg button, .tk-sheet select, .tk-sheet input[type="text"] { min-height: 44px; box-sizing: border-box; }
}

/* ---- the button: bottom right, above everything except windows; lifts over fixed controls; gone while the keyboard is up ---- */
.tk-fab { position: fixed; right: 18px; bottom: calc(var(--tk-fab-bottom) + env(safe-area-inset-bottom) + var(--tk-lift, 0px)); z-index: 66;
  width: 52px; height: 52px; padding: 0; border: 0; border-radius: 50%; display: grid; place-items: center; cursor: pointer;
  background: var(--tk-bar); color: var(--tk-bar-fg); box-shadow: 0 6px 20px rgba(0,0,0,.25), 0 0 0 1px rgba(255,255,255,.12) inset; }
.tk-fab[hidden] { display: none !important; }
.tk-fab svg { width: 24px; height: 24px; }
.tk-fab:focus-visible { outline: 3px solid var(--tk-accent); outline-offset: 3px; }
@media (max-width: 640px) { .tk-fab { bottom: calc(var(--tk-fab-bottom-phone) + env(safe-area-inset-bottom) + var(--tk-lift, 0px)); } }
.tk-badge { position: absolute; top: -3px; right: -3px; min-width: 20px; height: 20px; padding: 0 5px; box-sizing: border-box; border-radius: 10px;
  background: var(--tk-danger); color: #fff; font: 700 11.5px/16px var(--tk-sans); font-style: normal; text-align: center; border: 2px solid var(--tk-bg); }
html.tk-kb .tk-fab, html.kb-open .tk-fab { display: none !important; }
/* While the app has a window, sheet or (on phones) a menu sheet open, the Tools button stays available but moves to the
   top right, onto the dimmed strip above the window, where it covers no button or text (owner, 6 Nov 2026: "It should be
   visible on all screens but should avoid being placed on buttons / text"). Earlier it was hidden there, and before that it
   sat over a window's Save button. In the top bar, left of the account button (--tk-fab-right-raised, 72px). Above the window
   (64), below the Tools window (70). The sign-in sheet still hides it. */
/* Family Health, owner, live #30, 6 Nov 2026: "Why is the tools button up there?? It should be over the menu where I'm used
   to seeing it". So it stays where it always is, bottom right, and is drawn above a window, sheet or open menu (69: above the
   window's 64, below the Tools window's 70). */
html:has(#dialog:not([hidden])) .tk-fab, html:has(.sheet) .tk-fab, html:has(details.menu[open]) .tk-fab { z-index: 69; }
html:has(.acc-back) .tk-fab { display: none !important; }
/* While typing in a Tools window the page behind showed between the window and the keyboard, health details included
   (Family Health, owner, 6 Nov 2026). With the keyboard up, the backdrop is solid. */
html.tk-kb .tk-wrap, html.kb-open .tk-wrap { background: var(--tk-surface, #111); }
/* The first-visit tip waits while a window is open: it would point at the button's usual place, not where it is then. */
html:has(#dialog:not([hidden])) :is(.tk-tip-spot, .tk-tip-arrow, .tk-tip-bubble), html:has(.sheet) :is(.tk-tip-spot, .tk-tip-arrow, .tk-tip-bubble) { display: none !important; }
/* Room at the end of the page so the button never covers the last content (owner, App Playbook 4.12). */
html.tk-has-fab body::after { content: ""; display: block; height: 76px; }

/* ---- sheets: a bottom sheet on a phone, a window on a computer; the menu is a pop-over beside the button there ---- */
@keyframes tkUp { from { transform: translateY(100%); } to { transform: none; } }
@keyframes tkFade { from { opacity: 0; } to { opacity: 1; } }
.tk-wrap { position: fixed; left: 0; right: 0; top: var(--tk-vv-top, 0px); height: var(--tk-vv-h, 100%); z-index: 70; background: rgba(0,0,0,.4);
  display: flex; align-items: flex-end; justify-content: center; animation: tkFade .15s ease-out; }
.tk-sheet { position: relative; box-sizing: border-box; width: 100%; max-height: min(88dvh, 100%); overflow-y: auto; overscroll-behavior: contain; background: var(--tk-surface); color: var(--tk-fg);
  border-radius: 20px 20px 0 0; padding: 12px 18px calc(22px + env(safe-area-inset-bottom)); font: 15px/1.45 var(--tk-sans); animation: tkUp .22s ease-out; }
.tk-sheet:focus { outline: none; }
.tk-bigwrap .tk-sheet { min-height: 60dvh; }
/* Typing on a phone (Card Discounts report #4, 12 Nov 2026: "the screen behind it is visible" while the keyboard is up): the keyboard
   leaves only a small part of the screen, and a bottom sheet in it left a dimmed strip of the page showing above. While the keyboard
   is up the sheet takes the whole visible part, so only the form shows. */
html.tk-kb .tk-wrap, html.kb-open .tk-wrap { background: var(--tk-surface); animation: none; }
html.tk-kb .tk-sheet, html.kb-open .tk-sheet { height: 100%; max-height: 100%; min-height: 0; border-radius: 0; animation: none; }
@media (min-width: 641px) {
  .tk-wrap { align-items: center; }
  .tk-sheet { width: min(560px, calc(100vw - 32px)); border-radius: 16px; padding-bottom: 22px; box-shadow: 0 20px 60px rgba(0,0,0,.35); animation: tkFade .15s ease-out; }
  .tk-bigwrap .tk-sheet { width: min(860px, calc(100vw - 32px)); max-height: 90dvh; }
  .tk-menuwrap { background: transparent; align-items: flex-end; justify-content: flex-end; }
  .tk-menu { width: 320px; margin: 0 18px calc(var(--tk-fab-bottom) + 64px + var(--tk-lift, 0px)) 0; max-height: min(70vh, 620px); box-shadow: 0 10px 40px rgba(0,0,0,.3); border: 1px solid var(--tk-line); }
}
html:has(.tk-wrap), html:has(.tk-tip-spot) { overflow: hidden; }       /* the page stays still behind a layer laid over it */
.tk-x { position: sticky; top: 0; float: right; z-index: 4; display: flex; align-items: center; justify-content: center; width: 44px; height: 44px; margin: -6px -8px -38px auto; padding: 0;
  border: 0; border-radius: 50%; cursor: pointer; color: var(--tk-fg); background: radial-gradient(circle, var(--tk-surface-2) 16.5px, transparent 17px); }
.tk-x svg { width: 20px; height: 20px; }
.tk-grip { width: 40px; height: 5px; border-radius: 3px; background: var(--tk-line); margin: 0 auto 8px; }
@media (min-width: 641px) { .tk-grip { display: none; } }
.tk-h2 { margin: 0 44px 10px 0; font: 650 19px/1.25 var(--tk-sans); }
.tk-h { margin: 8px 10px 4px; font: 600 13px var(--tk-sans); color: var(--tk-muted); }
.tk-sheet hr { border: 0; border-top: 1px solid var(--tk-line); margin: 6px 4px; }
.tk-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 10px; border: 0; border-radius: 10px; background: none; color: var(--tk-fg); text-align: left; cursor: pointer; font: inherit; }
.tk-item:hover, .tk-item:focus-visible { background: var(--tk-accent-soft); outline: none; }
.tk-item b { display: block; font-size: 14.5px; font-weight: 600; } .tk-item small { display: block; font-size: 12.5px; color: var(--tk-muted); margin-top: 1px; }
.tk-ic { width: 32px; height: 32px; flex: none; display: grid; place-items: center; border-radius: 50%; background: var(--tk-accent-soft); color: var(--tk-accent); font-size: 15px; }
.tk-count { display: inline-block; min-width: 20px; height: 20px; padding: 0 6px; box-sizing: border-box; border-radius: 10px; vertical-align: 1px; background: var(--tk-danger); color: #fff; font: 700 11.5px/20px var(--tk-sans); font-style: normal; text-align: center; }

/* ---- the one-time tip: a coach mark ---- */
@keyframes tkPulse { from { transform: scale(1); opacity: .9; } to { transform: scale(1.35); opacity: 0; } }
.tk-tip-spot { position: fixed; z-index: 67; border-radius: 50%; pointer-events: none; box-shadow: 0 0 0 9999px rgba(8,12,10,.68); outline: 3px solid #fff; animation: tkFade .25s ease-out; }
.tk-tip-spot::after { content: ""; position: absolute; inset: -3px; border-radius: 50%; border: 3px solid #fff; animation: tkPulse 1.6s ease-out .3s infinite; }
.tk-tip-arrow { position: fixed; z-index: 68; width: 90px; height: 80px; color: #fff; pointer-events: none; animation: tkFade .25s ease-out; filter: drop-shadow(0 1px 3px rgba(0,0,0,.5)); }
.tk-tip-arrow svg { display: block; }
.tk-tip-bubble { position: fixed; z-index: 68; width: 320px; box-sizing: border-box; padding: 16px 16px 14px; background: var(--tk-surface); color: var(--tk-fg); border-radius: 18px;
  box-shadow: 0 12px 40px rgba(0,0,0,.4); font: 15px/1.4 var(--tk-sans); animation: tkFade .25s ease-out; }
.tk-tip-bubble h2 { display: flex; align-items: center; gap: 10px; margin: 0 0 8px; font: 650 17px/1.25 var(--tk-sans); }
.tk-tip-mini { flex: none; width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; background: var(--tk-bar); color: var(--tk-bar-fg); }
.tk-tip-mini svg { width: 16px; height: 16px; }
.tk-tip-lead { margin: 0 0 6px; font-size: 14px; color: var(--tk-muted); } .tk-tip-foot { margin: 0 0 12px; font-size: 13px; color: var(--tk-muted); }
.tk-tip-list { margin: 0 0 10px; padding: 0 0 0 18px; font-size: 14.5px; } .tk-tip-list li { margin: 3px 0; }
.tk-tip-acts { display: flex; align-items: center; justify-content: space-between; gap: 12px; } .tk-tip-try { font-size: 13.5px; font-weight: 600; }
html.tk-kb .tk-tip-bubble, html.tk-kb .tk-tip-spot, html.tk-kb .tk-tip-arrow, html.kb-open .tk-tip-bubble, html.kb-open .tk-tip-spot, html.kb-open .tk-tip-arrow { display: none; }
@media (prefers-reduced-motion: reduce) { .tk-wrap, .tk-sheet, .tk-tip-bubble, .tk-tip-spot, .tk-tip-arrow { animation: none; } .tk-tip-spot::after { animation: none; display: none; } }

/* ---- buttons, segments, fields ---- */
.tk-btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 8px 16px; border: 1px solid var(--tk-line); border-radius: 10px;
  background: var(--tk-surface); color: var(--tk-fg); font: 600 14.5px var(--tk-sans); cursor: pointer; text-decoration: none; }
.tk-btn:disabled { opacity: .55; cursor: default; } .tk-btn[hidden] { display: none; }
.tk-btn.tk-primary { background: var(--tk-accent); border-color: var(--tk-accent); color: var(--tk-accent-fg); }
.tk-btn.tk-sm { min-height: 32px; padding: 4px 10px; font-size: 13px; }
.tk-btn svg { width: 18px; height: 18px; }
.tk-seg { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 10px; }
.tk-seg button { padding: 7px 12px; border: 1px solid var(--tk-line); border-radius: 18px; background: var(--tk-surface); color: var(--tk-fg); font: 14px var(--tk-sans); cursor: pointer; }
.tk-seg button[aria-pressed="true"], .tk-seg button[aria-selected="true"] { background: var(--tk-accent); border-color: var(--tk-accent); color: var(--tk-accent-fg); }
.tk-sheet textarea, .tk-sheet input[type="text"], .tk-sheet select, .tk-sec textarea, .tk-sec input[type="text"], .tk-sec select, .tk-fields textarea, .tk-fields select {
  width: 100%; box-sizing: border-box; padding: 9px 10px; border: 1px solid var(--tk-line); border-radius: 10px; background: var(--tk-bg); color: var(--tk-fg); font: 15px/1.4 var(--tk-sans); }
/* iPhone Safari zooms into a text box under 16px and stays zoomed (owner's rule, 18 Oct 2026). Never fix it with maximum-scale=1. */
@media (pointer: coarse) {
  input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), textarea, select, [contenteditable="true"] { font-size: max(16px, 1em) !important; }   /* !important: this module's own .tk-sheet textarea rules are more specific */
}
.tk-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; } .tk-sp { flex: 1; }
.tk-hint, .tk-muted { color: var(--tk-muted); font-size: 13px; } .tk-hint { margin: 6px 0 0; text-align: right; } .tk-block { display: block; }
.tk-check { display: flex; align-items: flex-start; gap: 8px; margin: 6px 0; font-size: 14px; } .tk-check input { margin-top: 3px; }
.tk-sent { margin: 10px 0 0; font-size: 13.5px; } .tk-sent summary { cursor: pointer; color: var(--tk-muted); }
.tk-pics { display: flex; flex-wrap: wrap; gap: 10px; } .tk-pics:not(:empty) { margin: 10px 0 4px; }
.tk-pic { position: relative; width: 76px; height: 76px; flex: none; }
.tk-pic img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; border: 1px solid var(--tk-line); display: block; box-sizing: border-box; }
.tk-pic button { position: absolute; top: -8px; right: -8px; width: 28px; height: 28px; padding: 0; border-radius: 50%; display: grid; place-items: center; border: 1px solid var(--tk-line); background: var(--tk-surface); color: var(--tk-fg); cursor: pointer; }
.tk-pic button svg { width: 14px; height: 14px; }

/* ---- lists ---- */
.tk-fb { border: 1px solid var(--tk-line); border-radius: 10px; padding: 10px 12px; margin: 8px 0; background: var(--tk-surface); }
.tk-fb.tk-news { border-color: var(--tk-accent); }
.tk-fb-top { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 2px; }
.tk-fb-body { margin: 6px 0; overflow-wrap: anywhere; } .tk-fb-acts { margin-top: 6px; }
.tk-reply { background: var(--tk-accent-soft); padding: 8px 10px; border-radius: 8px; margin: 8px 0 4px; }
.tk-chip { display: inline-block; padding: 1px 8px; border-radius: 10px; background: var(--tk-surface-2); font-size: 12px; font-weight: 600; }
.tk-chip.ok { color: var(--tk-ok); } .tk-chip.warn { color: var(--tk-warn); }
.tk-shots { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; } .tk-shots img { max-width: 160px; max-height: 120px; border: 1px solid var(--tk-line); border-radius: 6px; display: block; }
.tk-rel { border-bottom: 1px solid var(--tk-line); padding: 6px 0 10px; } .tk-rel h3 { margin: 0 0 2px; font-size: 16px; }

/* ---- Admin -> Feedback ---- */
.tk-sec { margin: 0 0 22px; } .tk-sec h3 { margin: 0 0 8px; font-size: 17px; }
.tk-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; }
.tk-stat { border: 1px solid var(--tk-line); border-radius: 10px; padding: 10px; background: var(--tk-surface); } .tk-stat b { display: block; font-size: 1.6em; } .tk-stat span { font-size: 13px; color: var(--tk-muted); }
.tk-stat.warn { border-color: var(--tk-danger); } .tk-stat.warn b { color: var(--tk-danger); }
.tk-adm { border-bottom: 1px solid var(--tk-line); padding: 8px 0; } .tk-adm summary { cursor: pointer; list-style: none; padding: 4px 0; } .tk-adm summary::-webkit-details-marker { display: none; }
.tk-sum { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; } .tk-sum::before { content: "▸"; color: var(--tk-muted); width: 1em; } .tk-adm[open] .tk-sum::before { content: "▾"; }
.tk-detail { padding: 8px 0 4px 12px; }
.tk-fields { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-end; margin: 10px 0; } .tk-fields label { font-size: 13.5px; } .tk-fields select { width: auto; } .tk-wide { flex: 1 1 100%; }
.tk-hist { line-height: 1.6; }
.tk-rec { margin: 10px 0; } .tk-rec > summary { cursor: pointer; }
.tk-rec-body { margin: 8px 0; padding: 10px 12px; border: 1px solid var(--tk-line); border-radius: 10px; background: var(--tk-surface); font-size: 13px; }
.tk-rec-row { display: grid; grid-template-columns: 112px minmax(0, 1fr); gap: 2px 10px; padding: 3px 0; overflow-wrap: anywhere; } .tk-rec-row > span:first-child { color: var(--tk-muted); }
@media (max-width: 640px) { .tk-rec-row { grid-template-columns: minmax(0, 1fr); } .tk-rec-row + .tk-rec-row { border-top: 1px solid var(--tk-line); padding-top: 6px; margin-top: 3px; } }
.tk-rec code { font-size: 12px; overflow-wrap: anywhere; }
.tk-rel-pick { max-height: 220px; overflow-y: auto; border: 1px solid var(--tk-line); border-radius: 8px; padding: 6px 10px; margin: 8px 0; }
.tk-table { overflow-x: auto; } .tk-table table { border-collapse: collapse; width: 100%; font-size: 14px; } .tk-table th, .tk-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--tk-line); }

/* ---- "Open as they saw it" ---- */
.tk-pc-wrap { position: fixed; inset: 0; z-index: 90; background: rgba(8,10,9,.92); display: flex; flex-direction: column; font: 15px/1.4 var(--tk-sans); }
.tk-pc-bar { display: flex; align-items: flex-start; gap: 12px; padding: 10px 14px; background: var(--tk-surface); color: var(--tk-fg); border-bottom: 1px solid var(--tk-line); }
.tk-pc-what { flex: 1; min-width: 0; display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px; } .tk-pc-note { flex-basis: 100%; }
.tk-pc-x { flex: none; width: 40px; height: 40px; padding: 0; border-radius: 50%; display: grid; place-items: center; background: transparent; border: 0; color: var(--tk-fg); cursor: pointer; } .tk-pc-x svg { width: 20px; height: 20px; }
.tk-pc-stage { flex: 1; min-height: 0; display: grid; place-items: center; overflow: hidden; padding: 8px; }
.tk-pc-box { position: relative; overflow: hidden; border-radius: 6px; box-shadow: 0 0 0 1px rgba(255,255,255,.25), 0 10px 40px rgba(0,0,0,.5); background: #fff; }
.tk-pc-frame { position: absolute; left: 0; top: 0; border: 0; transform-origin: 0 0; background: #fff; }

/* ---- the toast and the new-version bar ---- */
.tk-toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom)); left: 50%; transform: translateX(-50%); z-index: 95; width: max-content; max-width: calc(100vw - 32px); box-sizing: border-box;
  padding: 10px 16px; border-radius: 8px; background: var(--tk-fg); color: var(--tk-bg); font: 14px var(--tk-sans); }
.tk-toast a { margin-left: 6px; color: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; white-space: nowrap; cursor: pointer; }
@media (max-width: 640px) { .tk-toast { bottom: calc(84px + env(safe-area-inset-bottom)); } }
.tk-new-version { position: sticky; top: 0; z-index: 40; text-align: center; padding: 8px 12px; font: 14px var(--tk-sans); background: #f4c542; color: #222; }
.tk-new-version button { margin-left: 8px; padding: 4px 12px; border: 0; border-radius: 8px; background: #222; color: #fff; font: 600 14px var(--tk-sans); cursor: pointer; }
/* The keyboard is up on a phone: the window fills the visible area (Family Health live #68). */
.tk-wrap.tk-kb { top: 0 !important; bottom: 0; height: auto !important; align-items: flex-start; background: var(--tk-surface, #111); }
.tk-wrap.tk-kb .tk-sheet { max-height: var(--tk-sheet-h, 100%); height: var(--tk-sheet-h, 100%); margin-top: var(--tk-sheet-top, 0px); border-radius: 0; animation: none; }
/* Steps aside while the page scrolls down (tools.js), back on the first scroll up. */
.tk-fab { transition: transform .2s ease, opacity .2s ease; }
html.tk-fab-away .tk-fab { transform: translateY(160%); opacity: 0; pointer-events: none; }
/* Family Health: sharing the records behind a report stands out from the small print (owner, 8 Nov 2026) */
.tk-check.tk-share { display: flex; align-items: flex-start; gap: 10px; margin: 10px 0; padding: 10px 12px; border: 1px solid var(--line, #d0d5dd); border-radius: 12px; background: var(--surface-2, rgba(127,127,127,.08)); line-height: 1.35; }
.tk-check.tk-share input { margin-top: 3px; flex: none; width: 20px; height: 20px; }
