/* JTA Receipts — Receipt Digitisation & Management — mobile-first */
:root {
  --brand: #176554; --brand-dark: #0f4a3d; --brand-soft: #e5f2ee;
  --ink: #1f2937; --muted: #6b7280; --paper: #f3f1eb; --card: #fff; --line: #e5e7eb;
  --ok: #166534; --ok-soft: #dcfce7; --warn: #b45309; --warn-soft: #fef3c7;
  --bad: #b4463d; --bad-soft: #fee2e2; --info: #1d4ed8; --info-soft: #dbeafe;
  --radius: 14px; --shadow: 0 1px 3px rgba(15,55,45,.10), 0 4px 14px rgba(15,55,45,.06);
}
* { box-sizing: border-box; }
/* An author `display` rule beats the UA stylesheet's [hidden] rule — make hidden win. */
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--paper); color: var(--ink); min-height: 100vh;
}
body.auth-pending .auth-screen, body.auth-pending .shell { visibility: hidden; }
h1 { font-size: 1.3rem; margin: 4px 0 2px; }
h2 { font-size: 1.1rem; }
h3 { font-size: .95rem; margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.bad { color: var(--bad); }
.ok { color: var(--ok); }
button { font: inherit; cursor: pointer; }
input, select, textarea {
  font: inherit; width: 100%; padding: 10px 12px; border: 1px solid var(--line);
  border-radius: 10px; background: #fff; color: var(--ink);
}
label { display: block; font-weight: 600; font-size: .92rem; margin: 12px 0 0; }
label > input, label > select, label > textarea { margin-top: 5px; font-weight: 400; }
.stack > * + * { margin-top: 2px; }

.primary { background: var(--brand); color: #fff; border: 0; border-radius: 10px; padding: 12px 18px; font-weight: 600; width: 100%; }
.primary:disabled { background: #9db5ae; cursor: not-allowed; }
.ghost { background: var(--brand-soft); color: var(--brand-dark); border: 0; border-radius: 10px; padding: 10px 14px; font-weight: 600; }
.ghost.warn { background: var(--warn-soft); color: var(--warn); }
.ghost.danger { background: var(--bad-soft); color: var(--bad); }
.link { background: none; border: 0; color: var(--brand-dark); text-decoration: underline; text-underline-offset: 3px; padding: 6px 2px; }

/* auth / demo entry */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px;
  background: radial-gradient(900px 460px at 15% -10%, #d9ece6 0, transparent 60%), var(--paper); }
.auth-card { background: var(--card); border-radius: 20px; box-shadow: var(--shadow); max-width: 440px; width: 100%; padding: 26px; }
.brand { display: flex; align-items: center; gap: 12px; }
.brand-mark { background: var(--brand); color: #fff; font-weight: 800; border-radius: 12px; padding: 10px 12px; }
.brand-copy strong { display: block; }
.brand-copy small { color: var(--muted); }
.ethos { color: var(--brand-dark); font-style: italic; font-size: .9rem; margin: 10px 0 14px; }
.msg { min-height: 1.2em; font-size: .9rem; margin: 10px 0 0; }
.msg.bad { color: var(--bad); }
.row-links { display: flex; justify-content: space-between; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.demo-note { background: var(--info-soft); color: var(--info); border-radius: 10px; padding: 10px 12px; font-size: .85rem; margin-top: 14px; }
.persona-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.persona { background: var(--brand-soft); border: 2px solid transparent; border-radius: 12px; padding: 14px 10px; text-align: center; font-weight: 600; color: var(--brand-dark); }
.persona small { display: block; font-weight: 400; color: var(--muted); margin-top: 3px; }

/* shell */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 12px 16px; background: var(--brand-dark); color: #eaf4f0; }
.topbar-left { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.topbar .link { color: #cfe5de; }
.topbar .brand-mark { padding: 6px 9px; font-size: .9rem; }
.topbar-title { font-weight: 700; }
.topbar-title small { display: block; font-weight: 400; font-size: .72rem; color: #a9c9bf; }
.sync { font-size: .78rem; color: #a9c9bf; }

.tabs { display: flex; gap: 4px; padding: 8px 12px; background: var(--card); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { background: none; border: 0; padding: 9px 14px; border-radius: 999px; font-weight: 600; color: var(--muted); white-space: nowrap; }
.tab.is-active { background: var(--brand-soft); color: var(--brand-dark); }

.main { padding: 14px 16px 80px; max-width: 980px; width: 100%; margin: 0 auto; }
.who { font-size: .95rem; margin-bottom: 6px; display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 6px; }

.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: .75rem; font-weight: 600; background: #eef1f0; color: #3b423f; white-space: nowrap; }
.chip.ok { background: var(--ok-soft); color: var(--ok); }
.chip.warn { background: var(--warn-soft); color: var(--warn); }
.chip.bad { background: var(--bad-soft); color: var(--bad); }
.chip.info { background: var(--info-soft); color: var(--info); }
.chip.brand { background: var(--brand-soft); color: var(--brand-dark); }

/* cards & lists */
.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-top: 10px;
  animation: cardIn .8s cubic-bezier(.16,.8,.24,1) both; }
/* Deliberately long (.8s) and includes a brief brand-coloured glow, not just a
   fade — real pages fetch data before painting, so by the time a user looks
   back at the screen the entrance is often already over; a longer, more
   visually distinct entrance stays noticeable even after that delay. */
@keyframes cardIn {
  0%   { opacity: 0; transform: translateY(22px) scale(.96); box-shadow: 0 0 0 2px rgba(23,101,84,.55), 0 8px 20px rgba(23,101,84,.25); }
  55%  { opacity: 1; transform: translateY(0) scale(1.005); }
  100% { opacity: 1; transform: none; box-shadow: var(--shadow); }
}
/* Stagger the first several cards on a page so the entrance reads as a visible
   cascade rather than everything appearing (or fading) at once. */
#view-body > .card:nth-of-type(1), #view-body .dash-2col:nth-of-type(1) .card { animation-delay: .05s; }
#view-body > .card:nth-of-type(2), #view-body .dash-2col:nth-of-type(2) .card { animation-delay: .15s; }
#view-body > .card:nth-of-type(3), #view-body .dash-2col:nth-of-type(3) .card { animation-delay: .25s; }
#view-body > .card:nth-of-type(4) { animation-delay: .35s; }
#view-body > .card:nth-of-type(5) { animation-delay: .45s; }
@media (prefers-reduced-motion: reduce) { .card { animation: none; box-shadow: var(--shadow); } }

/* Skeleton loading placeholder — swap in for "Loading…"/"Checking…" text while
   a card's real content is still being fetched. */
.skeleton-line { height: 12px; border-radius: 6px; margin: 8px 0; background: linear-gradient(90deg, #e6e3da 25%, #f1efe7 37%, #e6e3da 63%); background-size: 400% 100%; animation: skeletonShimmer 1.4s ease infinite; }
.skeleton-line.w60 { width: 60%; } .skeleton-line.w80 { width: 80%; } .skeleton-line.w40 { width: 40%; }
@keyframes skeletonShimmer { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }
@media (prefers-reduced-motion: reduce) { .skeleton-line { animation: none; } }
.card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.rows { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.row-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px 14px; display: flex; align-items: center; gap: 12px; }
.row-card.is-muted { opacity: .62; }
.row-main { flex: 1; background: none; border: 0; text-align: left; padding: 0; display: block; min-width: 0; cursor: pointer; }
.row-name { display: block; font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.row-meta { display: block; font-size: .8rem; color: var(--muted); margin-top: 2px; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.thumb { width: 46px; height: 58px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); background: #fff; flex: none; }
.btn-pair { display: flex; gap: 6px; flex-wrap: wrap; }

/* stat tiles */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; margin-top: 10px; }
.stat { background: var(--card); border-radius: 12px; box-shadow: var(--shadow); padding: 12px 14px; }
.stat b { display: block; font-size: 1.35rem; }
.stat span { font-size: .78rem; color: var(--muted); }
.stat.accent { background: var(--brand); color: #fff; }
.stat.accent span { color: #cfe5de; }
.progress { background: #e6e3da; border-radius: 999px; height: 12px; overflow: hidden; margin-top: 8px; }
.progress > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width .4s; }

/* month grid */
.month-grid { display: grid; grid-template-columns: auto repeat(12, 1fr); gap: 3px; margin-top: 10px; overflow-x: auto; font-size: .72rem; }
.mg-cell { min-width: 26px; height: 26px; border-radius: 6px; display: flex; align-items: center; justify-content: center; background: #eceae2; color: var(--muted); }
.mg-cell.s-none { background: #eceae2; }
.mg-cell.s-sorting { background: var(--warn-soft); color: var(--warn); }
.mg-cell.s-scanning { background: #fde68a; color: #92400e; }
.mg-cell.s-indexing { background: var(--info-soft); color: var(--info); }
.mg-cell.s-check { background: #e9d5ff; color: #6b21a8; }
.mg-cell.s-complete { background: var(--ok-soft); color: var(--ok); }
.mg-cell.s-archived { background: var(--brand); color: #fff; }
.mg-label { padding-right: 6px; display: flex; align-items: center; font-weight: 600; color: var(--ink); }
.legend { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 8px; font-size: .75rem; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 4px; vertical-align: -1px; }

/* filters */
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; align-items: center; }
.filters select, .filters input { width: auto; min-width: 110px; padding: 8px 10px; }
.filters input[type="search"] { flex: 1; min-width: 150px; }

/* sheets */
.sheet { border: 0; border-radius: 18px 18px 0 0; padding: 0; width: 100%; max-width: 560px;
  margin: auto auto 0; background: var(--card); box-shadow: var(--shadow); }
.sheet::backdrop { background: rgba(15,55,45,.45); }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px;
  padding: 16px 18px 8px; border-bottom: 1px solid var(--line); }
.sheet-head h2 { margin: 0; font-size: 1.05rem; }
.sheet-body { padding: 6px 18px 16px; max-height: 66vh; overflow-y: auto; }
.sheet-foot { display: flex; gap: 8px; padding: 12px 18px 18px; border-top: 1px solid var(--line); }
.sheet-foot .primary { width: auto; flex: 1; }
.sheet.wide { max-width: 960px; }
@media (min-width: 640px) { .sheet { border-radius: 18px; margin: auto; } }

.notice { background: var(--brand-soft); color: var(--brand-dark); border-radius: 10px; padding: 10px 12px; font-size: .88rem; margin: 12px 0 0; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.bad { background: var(--bad-soft); color: var(--bad); }
.notice.info { background: var(--info-soft); color: var(--info); }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; margin: 10px 0 0; }
.check input { width: 20px; height: 20px; flex: none; margin-top: 1px; }

/* indexing split view */
.split { display: grid; grid-template-columns: 1fr; gap: 14px; }
@media (min-width: 760px) { .split { grid-template-columns: minmax(0, 5fr) minmax(0, 6fr); align-items: start; }
  .split-img { position: sticky; top: 0; } }
.split-img { background: var(--paper); border-radius: 12px; padding: 10px; text-align: center; }
.split-img img, .split-img embed { max-width: 100%; max-height: 46vh; border-radius: 8px; background: #fff; box-shadow: var(--shadow); }
.img-tools { display: flex; gap: 6px; justify-content: center; margin-top: 8px; flex-wrap: wrap; }
.img-tools .ghost { padding: 7px 10px; font-size: .85rem; }

/* field with availability flag */
.field-flag { display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 6px; align-items: end; }
.field-flag select.flag { width: auto; max-width: 130px; padding: 8px; font-size: .8rem; color: var(--muted); }
.field-flag.is-unavailable input, .field-flag.is-unavailable select.val { opacity: .45; }
/* OCR progress + raw text */
.ocr-progress { display: flex; align-items: center; gap: 10px; background: var(--info-soft); color: var(--info);
  border-radius: 10px; padding: 10px 12px; margin-top: 12px; font-weight: 600; font-size: .9rem; }
.ocr-progress .spin { width: 16px; height: 16px; border: 2px solid var(--info); border-right-color: transparent;
  border-radius: 50%; animation: ocrspin .7s linear infinite; flex: none; }
@keyframes ocrspin { to { transform: rotate(360deg); } }
.ocr-text { white-space: pre-wrap; background: #26312d; color: #d7e9e3; border-radius: 10px; padding: 12px 14px;
  font-size: .8rem; line-height: 1.5; margin-top: 8px; max-height: 40vh; overflow: auto; font-family: "Courier New", monospace; }

/* per-field AI confidence badges */
.conf-badge { display: inline-block; font-size: .68rem; font-weight: 700; padding: 1px 7px; border-radius: 999px;
  margin-left: 6px; vertical-align: middle; }
.conf-badge.c-high { background: var(--ok-soft); color: var(--ok); }
.conf-badge.c-medium { background: var(--warn-soft); color: var(--warn); }
.conf-badge.c-low { background: var(--bad-soft); color: var(--bad); }
.field-flag.low-conf input, .field-flag.low-conf select.val { border-color: var(--bad); background: #fff6f5; }

.suggest { background: var(--info-soft); border-radius: 10px; padding: 10px 12px; margin-top: 12px; font-size: .86rem; }
.suggest b { color: var(--info); }
.suggest .btn-pair { margin-top: 8px; }

/* enhance dialog */
.enhance-stage { background: #26312d; border-radius: 12px; padding: 10px; text-align: center; position: relative; }
.enhance-stage canvas { max-width: 100%; max-height: 46vh; border-radius: 6px; background: #fff; touch-action: none; }
.enhance-controls { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.enhance-controls label { margin: 0; flex: 1; min-width: 150px; }
.enhance-controls input[type="range"] { padding: 0; }

/* pills */
.pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.pill { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 7px 13px; font-weight: 600; font-size: .85rem; color: var(--muted); }
.pill.is-on { background: var(--brand); border-color: var(--brand); color: #fff; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: .86rem; }
.tbl th { text-align: left; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl-wrap { overflow-x: auto; }
.tbl td.r, .tbl th.r { text-align: right; font-variant-numeric: tabular-nums; }

.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--brand-dark); color: #fff; padding: 11px 18px; border-radius: 999px;
  box-shadow: var(--shadow); z-index: 99; max-width: 92vw; text-align: center; }

.empty { text-align: center; color: var(--muted); padding: 26px 10px; }
.empty .big { font-size: 2rem; display: block; margin-bottom: 6px; }

.demo-banner { background: #fde68a; color: #78350f; text-align: center; font-size: .8rem; padding: 5px 10px; font-weight: 600; }

.section-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.section-head h2 { margin: 0; }
.back { margin-top: 10px; display: inline-block; }

.qr-note { font-size: .72rem; color: var(--muted); word-break: break-all; }

/* standard page header */
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; }
.page-head h1 { font-size: 1.5rem; margin: 0; }
.page-head p { margin: 2px 0 0; }

/* greeting ring on white greeting */
.greeting .ring { background: conic-gradient(#fff calc(var(--p) * 1%), rgba(255,255,255,.28) 0); width: 66px; height: 66px; }
.greeting .ring > b { background: var(--brand-dark); color: #fff; width: 48px; height: 48px; font-size: .85rem; }

/* help centre */
.help-cat { margin-top: 10px; }
.help-q { border-top: 1px solid var(--line); padding: 8px 0 2px; }
.help-q:first-child { border-top: 0; }
.help-q > summary { cursor: pointer; font-weight: 600; color: var(--brand-dark); }
.help-q > p { margin: 8px 0 6px; color: var(--ink); font-size: .92rem; line-height: 1.5; }

/* spending by category */
.cat-bars { display: flex; flex-direction: column; gap: 7px; margin-top: 10px; }
.cat-row { display: grid; grid-template-columns: minmax(90px, 30%) 1fr auto; gap: 10px; align-items: center; font-size: .86rem; }
.cat-name { color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cat-bar { background: #e6e3da; border-radius: 999px; height: 10px; overflow: hidden; }
.cat-bar > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; }
.cat-val { font-weight: 700; color: var(--brand-dark); white-space: nowrap; }

/* month-end control centre */
.me-steps { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.me-step { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px; background: var(--paper); }
.me-step[data-go] { cursor: pointer; }
.me-step.is-open { background: var(--warn-soft); }
.me-ic { font-size: 1.05rem; flex: none; }
.me-label { flex: 1; font-weight: 600; font-size: .9rem; }

/* till & petty cash */
.till-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 560px) { .till-grid { grid-template-columns: 1fr; } }
.till-calc { margin-top: 14px; }
.till-calc td { padding: 7px 8px; }
.till-calc td.r { text-align: right; font-variant-numeric: tabular-nums; }
.till-expected td { border-top: 2px solid var(--line); font-size: 1.05rem; }
.till-variance { display: flex; flex-direction: column; justify-content: flex-end; padding: 6px 12px;
  background: var(--paper); border-radius: 12px; }
.till-variance b { font-size: 1.15rem; }
.till-variance.bad { background: var(--bad-soft); }
.till-variance.bad b { color: var(--bad); }

/* floating Ask-AI button */
.fab-ai { position: fixed; right: 18px; bottom: 20px; z-index: 44; background: var(--brand); color: #fff;
  border: 0; border-radius: 999px; padding: 12px 18px; font-weight: 700; font-size: .92rem;
  box-shadow: 0 4px 16px rgba(15,55,45,.28); }
.fab-ai:hover { background: var(--brand-dark); }
@media (max-width: 860px) { .fab-ai { bottom: 70px; right: 14px; padding: 11px 15px; } }

/* contextual help icon */
.help-i { display: inline-flex; align-items: center; justify-content: center; width: 16px; height: 16px;
  border-radius: 50%; background: var(--brand-soft); color: var(--brand-dark); font-size: .68rem; font-weight: 700;
  cursor: help; vertical-align: middle; font-style: normal; }

/* interactive walkthrough overlay */
.wt-overlay { position: fixed; inset: 0; z-index: 80; background: rgba(15,55,45,.55);
  display: flex; align-items: center; justify-content: center; padding: 20px; }
.wt-card { background: var(--card); border-radius: 18px; box-shadow: var(--shadow); max-width: 440px; width: 100%; padding: 22px; }
.wt-step { font-size: .74rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--brand); }
.wt-card h2 { margin: 6px 0 8px; font-size: 1.25rem; }
.wt-card p { margin: 0; line-height: 1.55; color: var(--ink); }
.wt-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 18px; gap: 10px; }

/* dashboard 2-column widget grid */
.dash-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 10px; }
@media (max-width: 720px) { .dash-2col { grid-template-columns: 1fr; } }

/* message board */
.msg-item { border-top: 1px solid var(--line); padding: 10px 0; }
.msg-item:first-of-type { border-top: 0; }
.msg-top { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
.msg-item b { display: block; }
.msg-body { margin: 4px 0 6px; font-size: .9rem; color: var(--ink); line-height: 1.45; }
.msg-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.msg-actions .ghost { padding: 6px 12px; font-size: .82rem; }

/* home pulse */
.pulse { display: flex; flex-direction: column; gap: 9px; margin-top: 8px; }
.pulse-row { display: grid; grid-template-columns: minmax(96px, 38%) 1fr auto; gap: 10px; align-items: center; font-size: .85rem; }
.pulse-row[data-go] { cursor: pointer; }
.pulse-track { background: #e6e3da; border-radius: 999px; height: 9px; overflow: hidden; }
.pulse-track > i { display: block; height: 100%; background: var(--brand); border-radius: 999px; transition: width .5s; }
.pulse-val { font-weight: 700; color: var(--brand-dark); white-space: nowrap; }

/* today's tasks */
.tasklist { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.taskrow { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 10px; background: var(--paper); }
.taskrow[data-go] { cursor: pointer; }
.taskrow.is-done { opacity: .6; }
.tickbox { width: 20px; height: 20px; border-radius: 6px; border: 2px solid var(--brand); display: flex;
  align-items: center; justify-content: center; color: var(--brand); font-size: .8rem; font-weight: 800; flex: none; }
.taskrow.is-done .tickbox { background: var(--ok); border-color: var(--ok); color: #fff; }
.tasktxt { flex: 1; font-size: .88rem; }

/* recent activity */
.act-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--card);
  border-radius: 10px; box-shadow: var(--shadow); padding: 9px 12px; font-size: .88rem; }

/* Ask JTA Receipts AI */
.ai-card { border-top: 4px solid var(--brand); }
.ai-ask { display: flex; gap: 8px; margin-top: 10px; }
.ai-ask input { flex: 1; }
.ai-answer { margin-top: 12px; background: var(--brand-soft); border-radius: 12px; padding: 12px 14px;
  font-size: .92rem; line-height: 1.5; color: var(--ink); white-space: normal; }
.ai-card .pills { margin-top: 8px; }
.ai-card .pill { cursor: pointer; font-weight: 500; font-size: .8rem; }

/* =================== v3: app shell (header + sidebar) ==================== */
:root { --appbar-h: 56px; --side-w: 246px; --side-cw: 64px; }
.shell { min-height: 100vh; display: flex; flex-direction: column; background: var(--paper); }

.appbar { position: sticky; top: 0; z-index: 40; height: var(--appbar-h); display: flex; align-items: center;
  justify-content: space-between; gap: 12px; padding: 0 14px; background: var(--card);
  border-bottom: 1px solid var(--line); box-shadow: 0 1px 2px rgba(15,55,45,.05); }
.appbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.appbar .brand-mark { padding: 6px 9px; font-size: .9rem; }
.appbar-title { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
.appbar-title strong { font-size: .95rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }
.appbar-title small { color: var(--muted); font-size: .72rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar-centre { flex: 1; display: flex; justify-content: center; }
.appbar-right { display: flex; align-items: center; gap: 6px; }
.icon-btn { background: none; border: 0; font-size: 1.15rem; padding: 8px; border-radius: 10px; line-height: 1; }
.icon-btn:hover { background: var(--brand-soft); }
/* menu button is always available: collapses the sidebar on desktop,
   opens the drawer on mobile */
.nav-toggle { display: block; }

.home-badge { font-weight: 700; font-size: .82rem; padding: 5px 14px; border-radius: 999px;
  background: var(--brand-soft); color: var(--brand-dark); white-space: nowrap; }

.user-menu { position: relative; }
.user-btn { display: flex; align-items: center; gap: 8px; background: none; border: 0; padding: 4px 6px; border-radius: 10px; }
.user-btn:hover { background: var(--brand-soft); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand); color: #fff; font-weight: 700;
  display: flex; align-items: center; justify-content: center; font-size: .8rem; flex: none; }
.user-copy { display: flex; flex-direction: column; line-height: 1.1; text-align: left; }
.user-copy b { font-size: .85rem; }
.user-copy small { color: var(--muted); font-size: .72rem; }
.caret { color: var(--muted); font-size: .7rem; }
.user-drop { position: absolute; right: 0; top: calc(100% + 6px); background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow); padding: 6px; min-width: 170px; z-index: 60; }
.drop-item { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 9px 12px;
  border-radius: 8px; font-weight: 600; font-size: .9rem; }
.drop-item:hover { background: var(--brand-soft); }

.layout { flex: 1; display: flex; align-items: stretch; min-height: 0; }
.sidebar { width: var(--side-w); flex: none; background: var(--card); border-right: 1px solid var(--line);
  position: sticky; top: var(--appbar-h); height: calc(100vh - var(--appbar-h)); overflow-y: auto;
  display: flex; flex-direction: column; }
.side-nav { flex: 1; padding: 10px 10px 4px; }
.side-group { margin-bottom: 6px; }
.side-label { font-size: .66rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--muted); padding: 10px 12px 4px; }
.side-item { display: flex; align-items: center; gap: 11px; width: 100%; text-align: left; background: none;
  border: 0; padding: 9px 12px; border-radius: 10px; font-weight: 600; font-size: .9rem; color: var(--ink); }
.side-item .si { font-size: 1.05rem; width: 20px; text-align: center; flex: none; }
.side-item:hover { background: var(--brand-soft); }
.side-item.is-on { background: var(--brand); color: #fff; }
.side-item .badge-n { margin-left: auto; background: var(--bad); color: #fff; border-radius: 999px;
  font-size: .68rem; font-weight: 700; padding: 0 7px; min-width: 18px; text-align: center; }
.side-item.is-on .badge-n { background: rgba(255,255,255,.3); }
.side-collapse { background: none; border: 0; border-top: 1px solid var(--line); padding: 12px;
  color: var(--muted); font-weight: 600; font-size: .82rem; text-align: left; }

.content { flex: 1; min-width: 0; padding: 16px 22px 96px; max-width: 1120px; width: 100%; margin: 0 auto; }
.crumb-row { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; flex-wrap: wrap; }
.back-btn { font-weight: 600; }
.crumbs { font-size: .82rem; color: var(--muted); }
.crumbs b { color: var(--ink); }

.bottombar { display: none; }

/* collapsed sidebar (desktop) */
body[data-side="collapsed"] .sidebar { width: var(--side-cw); }
body[data-side="collapsed"] .side-item .txt,
body[data-side="collapsed"] .side-label,
body[data-side="collapsed"] .side-collapse { display: none; }
body[data-side="collapsed"] .side-item { justify-content: center; }
body[data-side="collapsed"] .side-item .si { width: auto; }
body[data-side="collapsed"] .side-item .badge-n { position: absolute; margin: -14px 0 0 14px; }

/* greeting card */
.greeting { border-radius: 16px; padding: 18px 20px; color: #fff; background: linear-gradient(120deg, var(--brand), var(--brand-dark));
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 16px; }
.greeting-copy { flex: 1; min-width: 0; }
.greeting h1 { font-size: 1.4rem; margin: 0 0 4px; }
.greeting p { margin: 0; color: rgba(255,255,255,.9); font-size: .95rem; }
.greeting .g-meta { font-size: .78rem; color: rgba(255,255,255,.75); margin-top: 6px; }
.greeting .g-ring { flex: none; }
.greeting .g-alert { margin-top: 8px; background: rgba(255,255,255,.16); border-radius: 10px; padding: 7px 11px; font-size: .84rem; display: inline-block; }
.g-illus { font-size: 2.6rem; flex: none; }

@media (max-width: 860px) {
  /* Two-row mobile header: row 1 = hamburger + brand + title + user menu;
     row 2 = home badge (own line) so nothing needs truncating or hiding. */
  .appbar { flex-wrap: wrap; height: auto; min-height: var(--appbar-h); padding: 8px 14px; row-gap: 6px; }
  .appbar-left { order: 0; }
  .appbar-right { order: 1; gap: 2px; }
  .appbar-centre { order: 2; flex: none; width: 100%; max-width: 100%; justify-content: flex-start; overflow: hidden; }
  .appbar-title { display: flex; }
  .appbar-title strong { max-width: 46vw; }
  .home-badge { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; }
  .icon-btn { padding: 7px; font-size: 1.05rem; }
  .nav-toggle { display: block; }
  .user-copy { display: none; }
  .sidebar { position: fixed; left: 0; top: var(--appbar-h); z-index: 55; width: 82vw; max-width: 300px;
    transform: translateX(-100%); transition: transform .22s ease; box-shadow: var(--shadow); }
  body[data-drawer="open"] .sidebar { transform: none; }
  body[data-side="collapsed"] .sidebar { width: 82vw; }
  body[data-side="collapsed"] .side-item .txt, body[data-side="collapsed"] .side-label { display: flex; }
  .scrim { position: fixed; inset: var(--appbar-h) 0 0 0; background: rgba(15,55,45,.4); z-index: 50; }
  .content { padding: 14px 14px 96px; }
  .bottombar { display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 45; background: var(--card);
    border-top: 1px solid var(--line); padding: 4px 4px env(safe-area-inset-bottom); }
  .bb-item { flex: 1; background: none; border: 0; display: flex; flex-direction: column; align-items: center;
    gap: 2px; padding: 7px 0; font-size: .68rem; font-weight: 600; color: var(--muted); }
  .bb-item span { font-size: 1.2rem; }
  .bb-item.is-on { color: var(--brand); }
  .bb-item.bb-scan { position: relative; }
  .bb-item.bb-scan span { display: flex; align-items: center; justify-content: center; width: 52px; height: 52px;
    margin-top: -22px; border-radius: 50%; background: var(--brand); color: #fff; font-size: 1.5rem;
    box-shadow: 0 4px 12px rgba(0,0,0,.22); }
  .bb-item.bb-scan { color: var(--brand); }
  .side-collapse { display: none; }
}

/* ================= v2: home workspaces & colour identity ================= */
/* Neutral background everywhere; the workspace colour is an ACCENT applied
   through the brand variables, so every button/chip/topbar re-tints itself. */
body[data-ws="JH"]    { --brand: #176554; --brand-dark: #0f4a3d; --brand-soft: #e5f2ee; }
body[data-ws="HH"]    { --brand: #c2570f; --brand-dark: #9a3412; --brand-soft: #fdeadd; }
body[data-ws="HO"]    { --brand: #3f3d94; --brand-dark: #312e81; --brand-soft: #e7e6f7; }
body[data-ws="ALL"]   { --brand: #0f766e; --brand-dark: #115e59; --brand-soft: #d9f2ef; }
body[data-ws="HIST"]  { --brand: #1d4ed8; --brand-dark: #1e3a8a; --brand-soft: #dbeafe; }
body[data-ws="ADMIN"] { --brand: #1e293b; --brand-dark: #0f172a; --brand-soft: #e2e8f0; }
body[data-ws] .shell { border-left: 6px solid var(--brand); min-height: 100vh; }

.ws-switch { display: flex; gap: 4px; flex-wrap: wrap; }
.ws-tab { border: 0; border-radius: 999px; padding: 6px 12px; font-weight: 700; font-size: .8rem;
  background: rgba(255,255,255,.14); color: #fff; opacity: .75; }
.ws-tab.is-on { opacity: 1; background: #fff; }
.ws-tab.is-on[data-ws="JH"]    { color: #176554; }
.ws-tab.is-on[data-ws="HH"]    { color: #c2570f; }
.ws-tab.is-on[data-ws="HO"]    { color: #312e81; }
.ws-tab.is-on[data-ws="ALL"]   { color: #0f766e; }
.ws-tab.is-on[data-ws="HIST"]  { color: #1d4ed8; }
.ws-tab.is-on[data-ws="ADMIN"] { color: #0f172a; }

/* historic scanner — big option cards */
.big-options { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-top: 12px; }
.big-option { background: var(--card); border: 2px solid var(--brand-soft); border-radius: 16px; padding: 22px 16px;
  text-align: center; cursor: pointer; box-shadow: var(--shadow); }
.big-option:active { background: var(--brand-soft); }
.big-option .bi { font-size: 2.2rem; display: block; }
.big-option b { display: block; margin-top: 8px; color: var(--brand-dark); }
.big-option small { display: block; color: var(--muted); margin-top: 4px; font-weight: 400; }
.big-option input { display: none; }

/* chain-of-custody disclosure */
details.custody { margin-top: 10px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; background: #fbfbf9; }
details.custody > summary { cursor: pointer; font-weight: 600; color: var(--brand-dark); }
details.custody p { margin: 8px 0 2px; }
.ws-badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .72rem;
  font-weight: 700; background: var(--brand-soft); color: var(--brand-dark); }

/* home dashboard */
.primary-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
@media (max-width: 480px) { .primary-actions { grid-template-columns: 1fr; } }
.quick-primary { display: flex; align-items: center; justify-content: center; gap: 8px; text-align: center;
  background: var(--brand); color: #fff; border: 0; border-radius: 14px; padding: 18px 10px;
  font-weight: 700; font-size: 1.02rem; cursor: pointer; box-shadow: var(--shadow); }
.quick-primary:active { background: var(--brand-dark); }
.quick-primary input { display: none; }
.mer-row { display: flex; justify-content: space-between; align-items: baseline; }
.mer-row b { font-size: 1.2rem; color: var(--brand-dark); }

.quick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; margin-top: 10px; }
.quick { display: flex; flex-direction: column; align-items: center; gap: 6px; text-align: center;
  background: var(--card); border: 2px solid var(--brand-soft); border-radius: 14px;
  padding: 16px 10px; font-weight: 700; color: var(--brand-dark); cursor: pointer; }
.quick:active { background: var(--brand-soft); }
.quick .qi { font-size: 1.6rem; }
.quick input { display: none; }

.ring-wrap { display: flex; align-items: center; gap: 14px; }
.ring { --p: 0; width: 74px; height: 74px; border-radius: 50%; flex: none;
  background: conic-gradient(var(--brand) calc(var(--p) * 1%), #e6e3da 0);
  display: flex; align-items: center; justify-content: center; }
.ring > b { background: var(--card); width: 54px; height: 54px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center; font-size: .9rem; }
.ring.is-complete { animation: ringPop .5s ease; }
.ring.is-complete > b { color: var(--ok); }
@keyframes ringPop { 0% { transform: scale(.9); } 55% { transform: scale(1.06); } 100% { transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .ring.is-complete { animation: none; } }

.attn { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.attn li { display: flex; align-items: center; gap: 10px; background: var(--card);
  border-radius: 10px; box-shadow: var(--shadow); padding: 10px 12px; }
.attn li b { margin-left: auto; }
.attn button { background: none; border: 0; display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left; padding: 0; font: inherit; }

/* All Homes command centre */
.cc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
@media (max-width: 640px) { .cc-grid { grid-template-columns: 1fr; } }
.cc-home { border-top: 5px solid var(--hc, var(--brand)); }
.compare { display: flex; gap: 4px; align-items: flex-end; height: 90px; margin-top: 10px; }
.compare .bar { flex: 1; border-radius: 6px 6px 0 0; background: var(--hc); min-height: 4px; position: relative; }
.compare .bar span { position: absolute; top: -20px; left: 0; right: 0; text-align: center; font-size: .72rem; font-weight: 700; }
.compare .bar small { position: absolute; bottom: -20px; left: 0; right: 0; text-align: center; font-size: .7rem; color: var(--muted); }

/* Reports charts (charts.js) */
.viz-wrap { width: 100%; }
.viz-line { width: 100%; height: auto; display: block; }
.viz-grid { stroke: var(--line); stroke-width: 1; }
.viz-axis { fill: var(--muted); font-size: 9px; }
.viz-dot { cursor: pointer; }
.viz-legend { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 8px; }
.viz-legend-item { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; color: var(--ink); }
.viz-legend-item i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }
.viz-donut-row { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; margin-top: 8px; }
.viz-donut-total { font-size: 15px; font-weight: 700; fill: var(--ink); }
.viz-donut-seg { cursor: pointer; }
.viz-legend-list { list-style: none; margin: 0; padding: 0; flex: 1; min-width: 160px; }
.viz-legend-list li { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: .84rem; border-top: 1px solid var(--line); }
.viz-legend-list li:first-child { border-top: 0; }
.viz-legend-list i { width: 10px; height: 10px; border-radius: 50%; flex: none; }
.viz-legend-list span:first-of-type { flex: 1; color: var(--ink); }
.viz-legend-list b { color: var(--brand-dark); }
.viz-tip { position: fixed; z-index: 999; background: #1f2937; color: #fff; font-size: .78rem; line-height: 1.35;
  padding: 6px 10px; border-radius: 8px; pointer-events: none; box-shadow: var(--shadow); max-width: 220px; }
.viz-status-row { padding: 4px 2px; }
.viz-status-bar { display: flex; height: 14px; border-radius: 999px; overflow: hidden; background: #e6e3da; }
.viz-status-bar i { display: block; height: 100%; }

/* global search */
#search-input { margin-top: 4px; font-size: 1rem; }
.search-results { margin-top: 12px; max-height: 50vh; overflow-y: auto; }
