/* SHARED_CRM_2026_11_05 (from VITCH_MAKEOVER_2026_10_17): theme layer, loaded after app.css. Light and dark follow the
   existing tokens; every colour below is a token. No !important. */
:root {
  --accent-strong: var(--brand-accent-strong, color-mix(in srgb, var(--brand-accent) 60%, #000));
  --accent-strong-hover: color-mix(in srgb, var(--accent-strong) 85%, #000);
  --r-sm: 8px; --r-md: 12px; --r-lg: 16px; --r-pill: 999px;
  --sh-sm: 0 1px 2px rgba(16, 24, 40, .05);
  --sh-md: 0 4px 14px rgba(16, 24, 40, .07);
  --sh-lg: 0 12px 32px rgba(16, 24, 40, .12);
  --side-w: 252px;
  --focus: 0 0 0 3px color-mix(in srgb, var(--brand-accent) 45%, transparent);
  --t-base: 0.9375rem; --t-sm: 0.8125rem; --t-xs: 0.75rem;
  --bg: #f6f7f9; --surface: #ffffff; --surface-hover: #f1f3f6; --border: #e3e7ec; --border-soft: #edf0f4;
  --text: #141a22; --text-muted: #535d6b; --text-faint: #8a93a0;
  --wm-size: 13px;
}
:root[data-theme="dark"] {
  --bg: #0f1318; --surface: #171c23; --surface-hover: #1f252e; --border: #2a313b; --border-soft: #21272f;
  --text: #eef1f4; --text-muted: #aab2bd; --text-faint: #7d8692;
  --sh-sm: 0 1px 2px rgba(0,0,0,.4); --sh-md: 0 4px 14px rgba(0,0,0,.45); --sh-lg: 0 12px 32px rgba(0,0,0,.5);
}
html { scroll-behavior: smooth; }
@media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } *, *::before, *::after { transition-duration: .01ms; animation-duration: .01ms; } }
body { background: var(--bg); color: var(--text); font-size: var(--t-base); line-height: 1.5; }

/* ---------- shell: sidebar + top bar ---------- */
.app-side {
  position: fixed; inset: 0 auto 0 0; width: var(--side-w); z-index: 40;
  display: flex; flex-direction: column; gap: 6px; padding: 14px 12px 12px;
  background: var(--brand-primary); color: color-mix(in srgb, #fff 82%, var(--brand-primary));
  overflow-y: auto; box-shadow: inset -1px 0 0 rgba(255,255,255,.06);
}
.app-side .brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 14px; color: #fff; text-decoration: none; }
.app-side .brand-name { font-family: var(--font-display); font-weight: 700; font-size: 1.05rem; color: #fff; letter-spacing: -.01em; }
.app-side .brand-mark { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: rgba(255,255,255,.1); color: #fff; font-weight: 800; font-size: .8rem; border: 1px solid rgba(255,255,255,.14); }
.side-search { display: flex; align-items: center; gap: 8px; margin: 0 4px 8px; padding: 0 10px; height: 38px; border-radius: 10px; background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.1); color: rgba(255,255,255,.75); }
.side-search:focus-within { background: rgba(255,255,255,.12); border-color: var(--brand-accent); }
.app-side .side-search input[type="search"][name="q"] { flex: 1; min-width: 0; background: transparent; border: 0; border-radius: 0; min-height: 0; padding: 0; box-shadow: none; color: #fff; font: inherit; font-size: .85rem; outline: none; }
.app-side .side-search input[type="search"][name="q"]:focus { box-shadow: none; border: 0; }
.side-search input::placeholder { color: rgba(255,255,255,.55); }
.side-nav { display: flex; flex-direction: column; gap: 10px; flex: 1; }
.side-group-title { font-size: .66rem; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: rgba(255,255,255,.45); padding: 8px 12px 4px; }
.side-nav a, .side-logout {
  display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 0 12px; margin: 1px 0;
  border-radius: 10px; color: rgba(255,255,255,.82); text-decoration: none; font-size: .9rem; font-weight: 500;
  border: 0; background: none; width: 100%; text-align: left; cursor: pointer; font-family: inherit;
  transition: background .15s ease, color .15s ease;
}
.side-nav a:hover, .side-logout:hover { background: rgba(255,255,255,.08); color: #fff; }
.side-nav a[aria-current="page"] { background: rgba(255,255,255,.14); color: #fff; font-weight: 600; box-shadow: inset 3px 0 0 var(--brand-accent); }
.side-ico { display: inline-flex; width: 18px; height: 18px; opacity: .85; flex: none; }
.side-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid rgba(255,255,255,.1); display: flex; flex-direction: column; gap: 6px; }
.side-foot .acting-pill { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border-radius: 10px; background: rgba(255,255,255,.06); color: #fff; text-decoration: none; font-size: .85rem; }
.side-foot .acting-pill .meta { margin-left: auto; color: var(--brand-accent-soft); font-size: .72rem; }
.side-foot-row { display: flex; align-items: center; gap: 6px; }
.side-foot-row .theme-toggle { width: 40px; height: 40px; border-radius: 10px; border: 1px solid rgba(255,255,255,.12); background: rgba(255,255,255,.06); color: #fff; display: grid; place-items: center; cursor: pointer; }
.side-foot-row form { flex: 1; }
.app-topbar { display: none; }
.side-backdrop { display: none; }
main, main.wide { margin-left: var(--side-w); max-width: none; width: auto; padding: 24px 28px 48px; min-height: 100vh; box-sizing: border-box; }
body.embed main, body.embed main.wide { margin-left: 0; padding: 12px; }
.app-topbar-plain { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; background: var(--brand-primary); }
.app-topbar-plain .brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
.app-topbar-plain + main, .app-topbar-plain ~ main { margin-left: 0; }
.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }
@media (max-width: 1024px) {
  main, main.wide { margin-left: 0; padding: 16px 16px 40px; }
  .app-topbar { display: flex; align-items: center; gap: 12px; position: sticky; top: 0; z-index: 35; padding: 10px 14px; background: var(--brand-primary); color: #fff; }
  .app-topbar .brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; }
  .app-topbar .brand-name { color: #fff; font-family: var(--font-display); font-weight: 700; }
  .nav-toggle-btn { order: 0; width: 44px; height: 44px; margin: 0; border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; cursor: pointer; background: rgba(255,255,255,.08); border: 0; }
  .nav-toggle-btn::before, .nav-toggle-btn::after { content: none; display: none; }
  .nav-toggle-btn span { display: block; width: 18px; height: 2px; background: #fff; border-radius: 2px; }
  .app-topbar .brand { order: 1; margin: 0; }
  .app-topbar .brand-name { display: inline; font-size: 1rem; }
  .app-side { transform: translateX(-100%); transition: transform .25s ease; box-shadow: none; }
  .nav-toggle:checked ~ .app-side { transform: translateX(0); box-shadow: var(--sh-lg); }
  .side-backdrop { display: block; position: fixed; inset: 0; z-index: 36; background: rgba(0,0,0,.4); opacity: 0; pointer-events: none; transition: opacity .2s ease; }
  .nav-toggle:checked ~ .side-backdrop { opacity: 1; pointer-events: auto; }
  .side-brand { display: none; }
}

/* ---------- type ---------- */
h1, h2 { font-family: var(--font-display); letter-spacing: -.01em; }
h1 { font-size: 1.5rem; margin: 0 0 12px; }
h2 { font-size: 1.25rem; margin: 0 0 8px; }
h3 { font-size: 1rem; font-weight: 700; margin: 0 0 6px; }
.meta { color: var(--text-muted); font-size: var(--t-sm); }

/* ---------- surfaces ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: 20px 22px; box-shadow: var(--sh-sm); margin-bottom: 16px; }
.card .card { box-shadow: none; }
.t-wrap { border: 1px solid var(--border); border-radius: var(--r-md); overflow: auto; background: var(--surface); }
table { font-size: var(--t-sm); }
thead th { position: sticky; top: 0; background: var(--surface-hover); color: var(--text-muted); font-size: .7rem; letter-spacing: .08em; text-transform: uppercase; font-weight: 700; padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tbody tr:hover > td { background: var(--surface-hover); }
tbody tr:last-child > td { border-bottom: 0; }

/* ---------- buttons: one hierarchy ---------- */
.btn, .focus-btn, .ck-btn, .bo-btn, .pii-btn, .ib-pill, .view-chip, .cal-chip, .cs-f button {
  font-family: inherit; cursor: pointer; transition: background .15s ease, color .15s ease, border-color .15s ease, box-shadow .15s ease;
}
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-size: var(--t-sm); font-weight: 600; box-shadow: none; text-decoration: none; }
.btn:hover { transform: none; box-shadow: none; background: var(--surface-hover); border-color: color-mix(in srgb, var(--border) 60%, var(--text-faint)); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--brand-primary); border-color: var(--brand-primary); color: #fff; }
.btn-primary:hover { background: var(--brand-primary-soft); border-color: var(--brand-primary-soft); }
.btn-accent { background: var(--brand-accent); border-color: var(--brand-accent); color: var(--text-on-accent); }
.btn-accent:hover { background: var(--brand-accent-soft); border-color: var(--brand-accent-soft); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-hover); border-color: transparent; color: var(--text); }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-danger, .btn-red { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-sm { min-height: 34px; padding: 0 12px; font-size: var(--t-xs); border-radius: 8px; }
.btn-xs { min-height: 30px; padding: 0 10px; font-size: var(--t-xs); border-radius: 8px; }
.btn-icon { min-width: 40px; padding: 0; }
.btn:focus-visible, button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: none; box-shadow: var(--focus); }
.focus-btn { border-radius: 10px; font-weight: 600; min-height: 42px; }
.ck-btn, .bo-btn { border-radius: 8px; }
.pii-btn { border-radius: var(--r-pill); font-size: .7rem; letter-spacing: .06em; padding: 3px 10px; }

/* ---------- forms ---------- */
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea {
  font-family: inherit; font-size: var(--t-sm); color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 12px; min-height: 40px; box-sizing: border-box;
  transition: border-color .15s ease, box-shadow .15s ease;
}
textarea { min-height: 80px; line-height: 1.45; }
input:focus, select:focus, textarea:focus { border-color: var(--brand-accent); outline: none; box-shadow: var(--focus); }
input::placeholder, textarea::placeholder { color: var(--text-faint); }
.field label, .label, .cs-f > span:first-child, .cal-new-form label > span { font-size: .7rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); }
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--brand-primary); }
.bl-select-trigger { border-radius: 10px; min-height: 40px; border: 1px solid var(--border); background: var(--surface); }
.bl-select-trigger:focus-visible { box-shadow: var(--focus); }
.bl-select-menu { border-radius: 12px; box-shadow: var(--sh-lg); border: 1px solid var(--border); }
.bl-opt { border-radius: 8px; }
.bl-opt:hover, .bl-opt.is-selected { background: var(--surface-hover); }

/* ---------- badges, chips, pills ---------- */
.badge, .ib-tag, .tpl-chip { display: inline-flex; align-items: center; gap: 4px; border-radius: var(--r-pill); padding: 2px 9px; font-size: .7rem; font-weight: 600; letter-spacing: .02em; }
.badge { background: var(--surface-hover); color: var(--text-muted); border: 1px solid var(--border); }
.view-chip, .cal-chip, .ib-pill, .filter-chip { border-radius: var(--r-pill); border: 1px solid var(--border); background: var(--surface); color: var(--text-muted); font-size: var(--t-xs); font-weight: 600; padding: 6px 12px; min-height: 32px; }
.view-chip.active, .cal-chip.active, .cal-chip[aria-current], .ib-pill.on { background: var(--brand-primary); border-color: var(--brand-primary); color: #fff; }

/* ---------- KPI tiles ---------- */
.kpi-strip { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); padding: 14px 16px; box-shadow: var(--sh-sm); }
.kpi-label { font-size: .68rem; letter-spacing: .08em; text-transform: uppercase; color: var(--text-muted); font-weight: 700; }
.kpi-value { font-family: var(--font-display); font-size: 1.5rem; font-weight: 800; margin-top: 4px; color: var(--text); letter-spacing: -.02em; }
.mgr-kpi { border-radius: var(--r-md); border: 1px solid var(--border); background: var(--surface); }

/* ---------- My Day ---------- */
.focus-card, .cockpit-focus { border-radius: var(--r-lg); border: 1px solid var(--border); box-shadow: var(--sh-md); }
.cockpit-error-banner { border-radius: 10px; padding: 10px 14px; font-size: var(--t-sm); margin-bottom: 12px; }
.focus-book, .focus-snooze { border-radius: var(--r-md); border: 1px solid var(--border); }
.focus-book-summary, .focus-snooze-summary { min-height: 44px; }

/* ---------- calendar ---------- */
.cal-toolbar-card { padding: 14px 18px; }
.cal-title { font-family: var(--font-display); font-size: 1.1rem; }
.cal-cell { border-radius: 8px; }
.cal-cell.today .cal-cell-day { background: var(--brand-accent); color: var(--text-on-accent); border-radius: var(--r-pill); }
.cal-cell.focus { outline: 2px solid var(--brand-primary); outline-offset: -2px; }
.cal-side { border-radius: var(--r-lg); border: 1px solid var(--border); background: var(--surface); box-shadow: var(--sh-sm); }
.cal-side-row { border-radius: var(--r-md); border: 1px solid var(--border-soft); border-left: 4px solid var(--row-color, var(--brand-accent)); padding: 10px 12px; margin-bottom: 10px; }
.cal-new summary { border-radius: 10px; }
.cal-pill { border-radius: 6px; font-size: .72rem; }

/* ---------- inbox ---------- */
.ib-list, .ib-pane { border-radius: var(--r-lg); border: 1px solid var(--border); box-shadow: var(--sh-sm); }
.ib-item.on { background: color-mix(in srgb, var(--brand-primary) 9%, var(--surface)); box-shadow: inset 3px 0 0 var(--brand-accent); }
.ib-av { background: color-mix(in srgb, var(--brand-primary) 14%, var(--surface)); color: var(--brand-primary); }
.ib-send { background: var(--brand-primary); }
.ib-form textarea { border-radius: 21px; }

/* ---------- patient page ---------- */
.funnel-action { border-radius: var(--r-md); border: 1px solid var(--border); }
.funnel-action[data-state="done"] { border-color: color-mix(in srgb, var(--ok) 35%, var(--border)); }
.booking-mini { border-radius: var(--r-md); }
.booking-mini-row { border-radius: 10px; }
.edit-row input, .edit-row select { min-height: 40px; }
.chat-box { border-radius: var(--r-md); }

/* ---------- clinic setup / admin ---------- */
.settings-section h3 { font-size: 1.05rem; }
.cs-doc { border-radius: var(--r-md); }
.scope-matrix th, .scope-matrix td { padding: 8px 10px; }
.inline-form { gap: 10px; }

/* ---------- screen protection: subtle, still traceable ---------- */
.wm-tile { color: rgba(0, 0, 0, .035); }
html[data-theme="dark"] .wm-tile { color: rgba(255, 255, 255, .04); }
#snooze-perm { font-size: .78rem; border-radius: var(--r-pill); }
#snooze-toasts > div { border-radius: var(--r-md); }

/* ---------- misc ---------- */
.skip-link:focus { box-shadow: var(--focus); }
summary { cursor: pointer; }
details > summary::-webkit-details-marker { color: var(--text-faint); }
hr { border: 0; border-top: 1px solid var(--border); }
code { background: var(--surface-hover); border-radius: 6px; padding: 1px 6px; font-size: .8em; }
.breadcrumb, .crumbs { font-size: var(--t-sm); color: var(--text-muted); }

/* ---------- pass 2: measured fixes (contrast, tap size, phone tables, overlays) ---------- */
.side-group-title { color: rgba(255,255,255,.72); }
.side-foot .acting-pill .meta { color: rgba(255,255,255,.85); }
.skip-link { background: var(--brand-primary); color: #fff; }
.btn-accent, .btn-accent:hover { background: color-mix(in srgb, var(--brand-accent) 82%, #000); border-color: transparent; color: #fff; }
.btn-accent:hover { background: color-mix(in srgb, var(--brand-accent) 70%, #000); }
.pii-cap, .pii-cap.is-warn { color: var(--text-muted); }
.bl-select-label.is-placeholder { color: var(--text-muted); }
.cal-cell.out .cal-cell-day, .cal-cell.out { color: var(--text-muted); }
.chat-time, .ib-time, .faint, .text-faint { color: var(--text-muted); }
.view-chip.active, .lib-chip.active, .filter-chip.active, .cal-chip.active, a.active.chip { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }
.pii-btn { min-height: 28px; padding: 4px 12px; }
.filter-chip summary, details.filter summary, summary.filter-summary, .filters summary { min-height: 36px; display: inline-flex; align-items: center; }
.recent-pill, .today-log-lead, .today-log-open { min-height: 36px; display: inline-flex; align-items: center; }
.th-sort { display: inline-flex; align-items: center; min-height: 28px; }
td a, .meta a { display: inline-block; min-height: 24px; line-height: 24px; }
main { overflow-x: hidden; }
.card > table, .card > .t-wrap, .mgr-table, .scope-matrix { max-width: 100%; }
.scope-matrix { font-size: .78rem; }
.scope-matrix th, .scope-matrix td { padding: 6px 6px; }
.lib-controls { flex-wrap: wrap; }
.lib-controls select, .lib-controls input { max-width: 100%; }
#snooze-perm { position: static; display: inline-flex; align-items: center; gap: 8px; margin: 0 0 12px; max-width: 100%; box-sizing: border-box; font-size: .8rem; padding: 8px 14px; border-radius: var(--r-pill); }
@media (max-width: 1024px) {
  .card { padding: 14px 14px; border-radius: var(--r-md); }
  .card:has(> table), .card:has(> .t-wrap) { overflow-x: auto; }
  .card > table, .card > .t-wrap table { min-width: 560px; }
  .mgr-table, .table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  main table tr.row-link td:nth-child(n+6), main table thead th:nth-child(n+6) { display: none; }
  main table tr.row-link td { padding: 12px 10px; }
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .cockpit-strip, .today-strip { grid-template-columns: repeat(2, 1fr); }
  .recent-strip, .today-recent { display: flex; overflow-x: auto; gap: 8px; padding-bottom: 6px; -webkit-overflow-scrolling: touch; }
  .recent-strip > *, .today-recent > * { flex: none; }
  .focus-card .chat-box, .focus-conv, .cockpit-focus .chat-box, .focus-card details[open] .chat-box { min-height: 44vh; max-height: 60vh; }
  .focus-btn { min-height: 48px; font-size: 1rem; }
  .cal-toolbar { flex-wrap: wrap; gap: 8px; }
  .cal-layout { grid-template-columns: 1fr; }
  .filter-panel { max-width: calc(100vw - 32px); left: 0; right: auto; }
  h1 { font-size: 1.3rem; }
}

/* ---------- pass 3 ---------- */
.btn-accent, summary.btn-accent, a.btn-accent { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.btn-accent:hover, summary.btn-accent:hover, a.btn-accent:hover { background: var(--accent-strong-hover); border-color: var(--accent-strong-hover); color: #fff; }
.btn-sm.btn-accent, .btn-xs.btn-accent { color: #fff; }
main a.active, .view-chip-row a.active, .cal-chip-row a.active { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }
.funnel-step.current { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }
.funnel-step-state { color: var(--text); font-weight: 700; }
.pii-field .pii-cap, .pii-cap, .pii-cap.is-warn { color: var(--text-muted); font-weight: 600; }
.cal-side-empty { color: var(--text-muted); }
.cal-cell.today .cal-cell-day { background: var(--brand-primary); color: #fff; }
.rt-edit, .rt-edit a { color: var(--text); }
.ib-thread .chat-time { color: #4f5864; }
code { color: var(--text); }
.card b, .card strong { color: inherit; }
.ad-thumb-skeleton .ad-skel-label { display: none; }
summary { min-height: 40px; display: flex; align-items: center; gap: 8px; }
summary.btn { display: inline-flex; }
a.meta, .meta a, .tpl-rules a, .ib-sub a { display: inline-block; min-height: 24px; line-height: 24px; }
.ib-back { min-width: 40px; min-height: 40px; display: inline-flex; align-items: center; justify-content: center; }
.focus-chat, .focus-card .chat-box { min-height: 180px; max-height: 360px; }
.snooze-perm-bar { display: flex; align-items: center; gap: 8px; margin: 0 0 14px; padding: 10px 14px; border-radius: var(--r-md); background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: .85rem; cursor: pointer; box-shadow: var(--sh-sm); max-width: 100%; box-sizing: border-box; }
.recent-strip-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.lib-controls .ctrl { min-width: 0; max-width: 100%; }
.lib-controls .ctrl select { width: 100%; }
.inline-form { flex-wrap: wrap; }
.inline-form textarea { width: 100%; }
@media (max-width: 1024px) {
  .recent-strip-pills { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 6px; }
  .recent-strip-pills > * { flex: none; }
  .focus-chat, .focus-card .chat-box { min-height: 42vh; max-height: 58vh; }
  .funnel-steps, .funnel-stepper, .stage-bar { flex-wrap: wrap; gap: 6px; }
  .funnel-step { flex: 0 1 auto; }
}

/* ---------- pass 4 ---------- */
:root { --warn: #7a5414; }
.view-chip.active, .view-chip-row a.active, .tabs a.active, .tabs a[aria-current="true"], .next-chip-row > a.active, main a.active[href] { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }
.funnel-step-state { background: var(--surface-hover); color: var(--text); border: 1px solid var(--border); }
.funnel-step-state[data-state="next"], .funnel-step-state[data-state="next_step"], .funnel-step-state[data-state="NEXT"] { background: #e9d9ad; color: #16211c; border-color: #d9c48a; }
.funnel-step-state[data-state="done"], .funnel-step-state[data-state="DONE"] { background: var(--ok-bg); color: var(--ok); border-color: transparent; }
.ib-pane .ib-thread .chat-time { color: #4f5864; }
td a { min-width: 24px; }
.ib-note a, p a, .lib-empty a, .tpl-rules a, .cal-side-empty a { display: inline-block; min-height: 24px; line-height: 24px; }
.inline-form { display: flex; flex-wrap: wrap; align-items: center; }
.lib-controls { display: flex; flex-wrap: wrap; max-width: 100%; gap: 10px; }
@media (max-width: 1024px) {
  .funnel { display: flex; flex-wrap: wrap; gap: 6px; }
  .lib-controls .ctrl { flex: 1 1 100%; }
  .cal-chip-group { max-height: 120px; overflow-y: auto; }
}

/* ---------- pass 5 ---------- */
.th-sort-active, a.th-sort.th-sort-active { color: var(--brand-primary); }
.breadcrumb a, .crumbs a, nav[aria-label="Breadcrumb"] a { display: inline-flex; align-items: center; min-height: 28px; }
main a:not([class]), main .meta a, main a.meta, main small a, main p a { display: inline-block; min-height: 24px; line-height: 24px; }
@media (max-width: 1024px) {
  .cal-chip-group { display: flex; flex-wrap: nowrap; overflow-x: auto; max-height: none; gap: 6px; padding-bottom: 6px; -webkit-overflow-scrolling: touch; }
  .cal-chip-group > * { flex: none; }
}

/* ---------- pass 6: every control has a visible boundary (3:1 against its surroundings) ---------- */
:root { --border-strong: #8e97a3; --fill-soft: #f3f5f8; }
:root[data-theme="dark"] { --border-strong: #5d6672; --fill-soft: #1c222a; }
.btn:not(.btn-accent):not(.btn-primary):not(.btn-ok):not(.btn-danger):not(.btn-red):not(.btn-warn):not(.active):not(.on):not(.selected) { border: 1px solid var(--border-strong); background: var(--surface); }
.btn:not(.btn-accent):not(.btn-primary):not(.btn-ok):not(.btn-danger):not(.btn-red):not(.btn-warn):not(.active):not(.on):not(.selected):hover { background: var(--fill-soft); border-color: var(--text-muted); }
.btn-accent, a.btn-accent, summary.btn-accent, .btn.btn-accent { background: var(--accent-strong); color: #fff; border-color: transparent; }
.btn-primary, .btn.btn-primary { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }
.btn-ghost { border: 1px solid var(--border-strong); background: transparent; color: var(--text); }
.btn-ghost:hover { background: var(--fill-soft); border-color: var(--text-muted); }
.btn-primary, .btn-primary:hover { border-color: var(--brand-primary); }
.btn-accent, .btn-accent:hover, .btn-ok, .btn-danger, .btn-red { border-color: transparent; }
.view-chip, .cal-chip, .ib-pill, .filter-chip, .next-chip, .recent-pill, details.filter-chip, details.filter-chip summary, .tabs a, .lib-chip { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
.view-chip:hover, .cal-chip:hover, .ib-pill:hover, .recent-pill:hover, .tabs a:hover { background: var(--fill-soft); }
.pii-btn, .platform-field-reveal, .agent-pick-btn, .bl-select-trigger { border: 1px solid var(--border-strong); background: var(--surface); }
.pii-btn:hover, .platform-field-reveal:hover { background: var(--fill-soft); }
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select, textarea { border-color: var(--border-strong); }
.app-side .side-search input[type="search"][name="q"] { border: 0; }
main a:not([class]):not(:has(img)) { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: color-mix(in srgb, currentColor 45%, transparent); }
.ib-form textarea { border: 1px solid var(--border-strong); box-shadow: none; }
.t-wrap, .card { border-color: var(--border); }

/* ---------- pass 7 ---------- */
.ib-pills .ib-pill, .ib-list .ib-pill { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
.ib-pills .ib-pill.on { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }
.pii-field .pii-btn, span .pii-btn, button.pii-btn[data-pii-reveal], button.pii-btn[data-pii-copy] { border: 1px solid var(--border-strong); background: var(--surface); color: var(--text); }
.focus-btn.focus-btn-reveal, .focus-btn.focus-btn-copy, .focus-touch-btns .focus-btn, .focus-btn:not(.focus-btn-wa):not(.focus-btn-call) { border: 1px solid var(--border-strong); }
.focus-btn.focus-btn-wa, a.focus-btn-wa, .ck-btn-wa { background: #0d7f58; color: #fff; border-color: #0d7f58; }
.focus-btn.focus-btn-call, .ck-btn-call { background: var(--brand-primary); color: #fff; }
.next-chip, .next-chip-row > a { border: 1px solid var(--border-strong); }
.app-topbar-plain .theme-toggle, .app-topbar .theme-toggle { border: 1px solid rgba(255,255,255,.55); color: #fff; }
.pagination .btn-primary, span.btn.btn-primary { background: var(--brand-primary); color: #fff; }

/* ---------- pass 8 ---------- */
.btn-ghost.active, .btn-ghost[aria-current="true"], .btn-ghost[aria-current="page"], a.btn.btn-ghost.active { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }
.ib-back { border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); }

/* ---------- pass 9 ---------- */
.btn-ghost.btn-primary, a.btn.btn-ghost.active, .btn-ghost.btn-primary, .btn-ghost.on, .btn-ghost.selected, .btn-ghost[data-active="1"] { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }
.ib-head .ib-back, button.ib-back { border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); color: var(--text); }
.btn-ghost[style*="background"], .btn[style*="background:var(--brand-primary)"], .btn[style*="background: var(--brand-primary)"] { color: #fff; border-color: var(--brand-primary); }

/* pass 10: counts inside filled chips, the gold Mark paid button, small My Day links, phone tables */
a.active .meta, .chip.active .meta, [aria-current="true"] .meta, .btn-primary .meta, .btn-accent .meta { color: inherit; opacity: .9; }
.focus-btn.focus-btn-payment { background: var(--accent-strong); border-color: var(--accent-strong); color: #fff; }
.focus-btn.focus-btn-payment:hover { background: var(--accent-strong-hover); }
a.focus-open-full, a.focus-phone { display: inline-flex; align-items: center; min-height: 28px; padding: 2px 6px; margin: -2px -6px; border-radius: 8px; color: var(--text-soft); }
a.focus-open-full:hover, a.focus-phone:hover { background: var(--fill-soft); color: var(--text); }
@media (max-width: 1024px) {
  .card > table, .card > .table, main table.table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .card > table thead, .card > .table thead, main table.table thead { display: table-header-group; }
  .card > table tbody, .card > .table tbody, main table.table tbody { display: table-row-group; }
}

/* pass 11: phone inbox chat header: the status pill takes its own line, the title keeps room */
@media (max-width: 1024px) {
  .ib-head { row-gap: 6px; }
  .ib-head .ib-hinfo { flex: 1 1 160px; min-width: 160px; }
  .ib-head .ib-status { flex: 0 0 auto; margin-left: 0; }
}

/* THEME_CONTRAST_2026_10_29: light + dark colour fixes from the contrast audit (WCAG AA:
   4.5:1 for text, 3:1 for large text). Dark rules use :root[data-theme="dark"] so they win
   over the page-level <style> blocks of the inbox, templates and calendar. */

/* ---------- both themes ---------- */
.focus-btn-qualify-submit { background: #15803d; }
.focus-btn-qualify-submit:hover { background: #166534; }
.focus-btn-book-submit { background: #1d4ed8; }
.focus-btn-book-submit:hover { background: #1e40af; }
.focus-btn-snooze-submit { background: #6d28d9; }
.focus-btn-snooze-submit:hover { background: #5b21b6; }
.cal-wk-head.today .cal-wk-head-day { color: #fff; }
.cal-wk-time { color: var(--text-muted); }
.cascade-status.is-active { color: #7a5a1c; }
.av-badge.off { color: #475569; }
.av-badge.free { color: #166534; }
.av-badge.full { color: #991b1b; }

/* ---------- dark theme ---------- */
:root[data-theme="dark"] .btn-ok { background: #1f7a47; color: #fff; }
:root[data-theme="dark"] .btn-danger,
:root[data-theme="dark"] .btn-red { background: #b42318; color: #fff; }
:root[data-theme="dark"] .th-sort-active { color: var(--text); }
:root[data-theme="dark"] .ownership-label { color: #5eead4; }
:root[data-theme="dark"] .tr-warn .tr-k { color: #fca5a5; }
:root[data-theme="dark"] .ad-funnel .t-num,
:root[data-theme="dark"] .ad-funnel .t-num b { color: #e2c27d; }
:root[data-theme="dark"] .cascade-status.is-active { color: #e2c27d; }
:root[data-theme="dark"] a[style*="b45309"] { color: #fbbf24 !important; }
:root[data-theme="dark"] td.num[style*="198754"],
:root[data-theme="dark"] td[style*="#198754"] { color: #86efac !important; }

/* calendar availability */
:root[data-theme="dark"] .av-badge.free { background: rgba(34,197,94,.18); color: #86efac; }
:root[data-theme="dark"] .av-badge.off { background: rgba(148,163,184,.22); color: #cbd5e1; }
:root[data-theme="dark"] .av-badge.full { background: rgba(239,68,68,.20); color: #fca5a5; }

/* My Day conversation + any chat box: theme surface, not navy */
:root[data-theme="dark"] .chat-box { background: var(--bg); }
:root[data-theme="dark"] .chat-in { background: #1f252e; color: var(--text); }
:root[data-theme="dark"] .chat-out { background: #1d3a2c; color: #e3f3e8; }
:root[data-theme="dark"] .chat-time { color: #9fa9b6; }

/* Inbox */
:root[data-theme="dark"] .ib-av { background: rgba(111,206,141,.14); color: #cfe3d8; }
:root[data-theme="dark"] .ib-tag { background: rgba(255,255,255,.07); color: var(--text-muted); }
:root[data-theme="dark"] .ib-tag.open { background: rgba(111,206,141,.16); color: #86efac; }
:root[data-theme="dark"] .ib-tag.need { background: #2f6b52; color: #fff; }
:root[data-theme="dark"] .ib-status { color: var(--text-muted); }
:root[data-theme="dark"] .ib-status.open { color: #86efac; }
:root[data-theme="dark"] .ib-thread { background-color: #11161c;
  background-image: radial-gradient(rgba(255,255,255,.04) 1px, transparent 1px); }
:root[data-theme="dark"] .ib-day span { background: #1f252e; color: var(--text-muted); }
:root[data-theme="dark"] .ib-thread .chat-msg { color: var(--text); box-shadow: 0 1px .5px rgba(0,0,0,.4); }
:root[data-theme="dark"] .ib-thread .chat-in { background: #1f252e; }
:root[data-theme="dark"] .ib-thread .chat-out { background: #1d3a2c; color: #e3f3e8; }
:root[data-theme="dark"] .ib-thread .chat-time { color: #9fa9b6; }
:root[data-theme="dark"] .ib-thread .chat-msg a { color: #7cc4ef; }
:root[data-theme="dark"] .ib-failed { color: #fca5a5 !important; }
:root[data-theme="dark"] .ib-comp { background: var(--surface); }
:root[data-theme="dark"] .ib-form textarea { background: var(--bg); color: var(--text); box-shadow: 0 0 0 1px var(--border); }
:root[data-theme="dark"] .ib-form-off textarea { background: var(--surface-hover); }
:root[data-theme="dark"] .ib-send { background: #2f6b52; }
:root[data-theme="dark"] .ib-note { color: var(--text-muted); }
:root[data-theme="dark"] .ib-closed { background: #3a2a10; border-color: #6b5420; color: #f5deb0; }
:root[data-theme="dark"] .ib-tpl select, :root[data-theme="dark"] .ib-tpl input,
:root[data-theme="dark"] .ib-tpl .pv { background: var(--bg); color: var(--text); border-color: var(--border); }
:root[data-theme="dark"] .ib-empty { color: var(--text-muted); }
:root[data-theme="dark"] .ib-err { color: #fca5a5; }

/* Templates + flash messages */
:root[data-theme="dark"] .tpl-chip { background: var(--surface-hover); border-color: var(--border); color: var(--text-muted); }
:root[data-theme="dark"] .tpl-chip-on { background: rgba(111,206,141,.16); border-color: rgba(111,206,141,.4); color: #86efac; }
:root[data-theme="dark"] .tpl-chip-bad { background: rgba(239,68,68,.16); border-color: rgba(239,68,68,.4); color: #fca5a5; }
:root[data-theme="dark"] .reply-flash.ok, :root[data-theme="dark"] .ds-flash.ok { background: rgba(111,206,141,.16); color: #86efac; }
:root[data-theme="dark"] .reply-flash.err, :root[data-theme="dark"] .ds-flash.err { background: rgba(239,68,68,.16); color: #fca5a5; }

/* Admin lead switch */
:root[data-theme="dark"] .ls-state.on { color: #86efac; }
:root[data-theme="dark"] .ls-state.off { color: #fca5a5; }
:root[data-theme="dark"] .ls-switch { background: #475569; }
:root[data-theme="dark"] .ls-switch.on { background: #2f8a5b; }
/* THEME_CONTRAST_2026_10_29 (b): rules that page-level styles were overriding */
.focus-snooze-grid .focus-btn.focus-btn-qualify-submit { background: #15803d; color: #fff; }
.focus-snooze-grid .focus-btn.focus-btn-qualify-submit:hover { background: #166534; }
.cal-wk-head.today .cal-wk-head-day { background: var(--accent-strong); color: #fff; }
:root .av-badge.off { color: #475569; }
:root .av-badge.free { color: #166534; }
:root .av-badge.full { color: #991b1b; }
:root[data-theme="dark"] .av-badge.off { color: #cbd5e1; }
:root[data-theme="dark"] .av-badge.free { color: #86efac; }
:root[data-theme="dark"] .av-badge.full { color: #fca5a5; }

/* DAY_STATS_DARK_2026_10_29: My Day "All clear" day counts were white chips with near-white text in dark mode */
html[data-theme="dark"] .cockpit-day-stats span { background: rgba(255,255,255,.08); color: #e6ece8; border: 1px solid rgba(255,255,255,.12); }
html[data-theme="dark"] .cockpit-day-stats span b { color: #ffffff; }

/* SHARED_CRM_2026_11_05: Inbox empty-state hint measured 3.6:1 in light; muted text passes (the Inbox page's own style block sets #6b7280) */
:root .ib-empty { color: var(--text-muted); }
