/* Data pages: views, toolbar, filters, tables, patient sheet. */

/* ---------- Utilities ---------- */
.muted { color: var(--muted); }
.small { font-size: 12px; }
.bad-ink { color: var(--bad-ink); }
.warn-ink { color: var(--warn-ink); }
.r { text-align: right; }
.clip { display: inline-block; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.two { display: grid; line-height: 1.25; }
.two small { font-size: 12px; }
.avatar.sm { width: 28px; height: 28px; font-size: 11px; }
.swatch { display: inline-block; width: 12px; height: 12px; border-radius: 4px; border: 1px solid var(--swatch-border); flex: none; }
.phase-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; flex: none; }
.sync-pill { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); animation: pulse 1s var(--ease) infinite; }

/* ---------- Views (tabs with counts) ---------- */
.views { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin: -4px 0 14px; padding-bottom: 2px; border-bottom: 1px solid var(--border); }
.views::-webkit-scrollbar { display: none; }
.view-tab {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border: 0; background: transparent; cursor: pointer;
  color: var(--muted); font-weight: 600; font-size: 13.5px; white-space: nowrap; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.view-tab:hover { color: var(--text); }
.view-tab[aria-selected="true"] { color: var(--brand-ink); border-bottom-color: var(--accent); }
.view-tab .count { font-size: 11.5px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border); color: var(--muted); min-width: 22px; text-align: center; }
.view-tab[aria-selected="true"] .count { background: var(--brand-tint); border-color: transparent; color: var(--brand-ink); }
.view-tab .count:empty { display: none; }

/* ---------- Toolbar & filter chips ---------- */
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.toolbar-spacer { flex: 1; }
.search-box {
  display: flex; align-items: center; gap: 8px; height: 36px; padding: 0 10px; min-width: min(340px, 100%); flex: 0 1 340px;
  border: 1px solid var(--border-strong); border-radius: var(--r-ctl); background: var(--card); color: var(--muted);
}
.search-box:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-tint-strong); }
.search-box svg { width: 16px; height: 16px; flex: none; }
.search-box input { border: 0; outline: 0; background: transparent; flex: 1; min-width: 0; height: 100%; color: var(--text); }
.select-sm { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.select-sm select, .filter-pop select { height: 32px; border: 1px solid var(--border-strong); border-radius: var(--r-ctl); background: var(--card); padding: 0 8px; font-size: 13px; color: var(--text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chips:empty { display: none; }
.fchip { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 4px 0 11px; border-radius: 99px; background: var(--brand-tint); color: var(--brand-ink); font-size: 12.5px; font-weight: 600; }
.fchip button { width: 22px; height: 22px; border: 0; border-radius: 50%; background: transparent; color: inherit; cursor: pointer; display: grid; place-items: center; }
.fchip button:hover { background: var(--brand-tint-strong); }
.fchip svg { width: 12px; height: 12px; }
.filter-pop { width: 330px; padding: 12px; display: grid; gap: 10px; }
.fp-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.fp-row select { flex: 1; }
.fp-row .input { height: 34px; flex: 1; min-width: 0; }
.fp-opts { display: grid; gap: 4px; max-height: 220px; overflow-y: auto; width: 100%; }
.fp-opts label { display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 4px 2px; cursor: pointer; }
.fp-actions { display: flex; justify-content: flex-end; gap: 6px; }

/* ---------- Table ---------- */
.table-card { overflow: hidden; }
.table-wrap { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th {
  position: sticky; top: 0; z-index: 1; background: var(--surface); text-align: left; font-size: 11.5px; font-weight: 700;
  letter-spacing: .04em; text-transform: uppercase; color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap;
}
.tbl td { padding: 0 12px; height: var(--row-h); border-bottom: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
.tbl tbody tr { cursor: pointer; transition: background .12s; }
.tbl tbody tr:hover { background: var(--brand-tint); }
.tbl tbody tr:focus-visible { outline: 2px solid var(--brand); outline-offset: -2px; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl.is-loading tbody { opacity: .55; }
.cell-patient { display: flex; align-items: center; gap: 10px; min-width: 220px; height: var(--row-h); }
.cell-patient .who { display: grid; min-width: 0; line-height: 1.25; }
.cell-patient b { font-weight: 600; display: flex; align-items: center; gap: 6px; }
.cell-patient small { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; max-width: 240px; }
:root[data-density="compact"] .cell-patient small { display: none; }
.star { color: var(--accent); font-size: 14px; }
.flag { font: 700 10px/16px var(--font-body); padding: 0 5px; border-radius: 4px; background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.flag-bad { background: var(--bad-tint); color: var(--bad-ink); border-color: transparent; }
.flag-warn { background: var(--warn-tint); color: var(--warn-ink); border-color: transparent; }
.journey-cell { display: inline-flex; align-items: center; gap: 7px; }
.journey-cell small { font-size: 11.5px; }
.label-cell { display: inline-flex; align-items: center; gap: 7px; }
.note-cell { max-width: 200px; color: var(--muted); }
.supply { display: inline-flex; align-items: center; gap: 8px; }
.supply .bar { width: 56px; height: 6px; border-radius: 99px; background: var(--surface); border: 1px solid var(--border); overflow: hidden; }
.supply .bar i { display: block; height: 100%; border-radius: 99px; }
.bar-good i { background: var(--good); }
.bar-warn i { background: var(--warn); }
.bar-bad i { background: var(--bad); }
.supply b { font-weight: 600; font-size: 12.5px; }
.est { font-size: 10.5px; font-weight: 700; color: var(--warn-ink); background: var(--warn-tint); border-radius: 4px; padding: 0 4px; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 12px 2px; }
.pager .muted { margin-right: auto; font-size: 12.5px; }

/* ---------- Patient sheet ---------- */
body.sheet-open { overflow: hidden; }
.sheet-scrim { background: var(--scrim-strong); }
.sheet {
  position: fixed; z-index: 82; top: 3vh; left: 50%; transform: translateX(-50%); width: min(1100px, calc(100vw - 32px)); max-height: 94vh;
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow-3); border: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden; animation: palIn .18s var(--ease);
}
.sheet-head { position: relative; display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.sheet-nav { display: flex; gap: 2px; }
.sheet-nav .icon-btn { width: 30px; height: 30px; font-size: 20px; line-height: 1; }
.sheet-nav .icon-btn:disabled { opacity: .3; cursor: default; }
.sheet-title { min-width: 0; flex: 1; }
.sheet-title .t1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sheet-title h2 { font-size: 19px; }
.sheet-title .t2 { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 3px; font-size: 12.5px; color: var(--muted); }
.sheet-title .t2 span { display: inline-flex; align-items: center; gap: 5px; }
.sheet-title .t2 svg { width: 13px; height: 13px; }
.sheet-actions { display: flex; align-items: center; gap: 6px; }
.sheet-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); border-bottom: 1px solid var(--border); }
.sheet-stats .stat { padding: 12px 20px; border-right: 1px solid var(--border); display: grid; gap: 4px; }
.sheet-stats .stat:last-child { border-right: 0; }
.sheet-stats small { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.sheet-stats b { font: 700 18px/1.2 var(--font-head); }
.sheet-stats .stat > div { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.jband { display: flex; gap: 18px; align-items: flex-end; flex-wrap: wrap; padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--surface); }
.jphase { display: grid; gap: 6px; }
.jp-label { font-size: 11px; font-weight: 800; letter-spacing: .07em; text-transform: uppercase; color: var(--ph); }
.jp-dots { display: flex; align-items: center; }
.jdot { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--ph); background: var(--card); flex: none; }
.jdot.done { background: var(--ph); }
.jdot.now { background: var(--ph); box-shadow: 0 0 0 4px color-mix(in srgb, var(--ph) 25%, transparent); animation: nowPulse 1.6s var(--ease) infinite; }
.jdot.now.stuck { border-color: var(--bad); background: var(--bad); box-shadow: 0 0 0 4px var(--bad-tint); }
.jdot.ahead { opacity: .45; }
@keyframes nowPulse { 50% { box-shadow: 0 0 0 7px color-mix(in srgb, var(--ph) 10%, transparent); } }
.jline { width: 18px; height: 2px; background: color-mix(in srgb, var(--ph) 40%, transparent); }
.jcap { flex: 1 1 260px; display: flex; flex-wrap: wrap; gap: 4px 14px; justify-content: flex-end; font-size: 12.5px; align-items: center; }
.sheet-tabs { display: flex; gap: 2px; padding: 0 14px; border-bottom: 1px solid var(--border); overflow-x: auto; scrollbar-width: none; }
.sheet-tabs button {
  height: 40px; padding: 0 12px; border: 0; background: transparent; font-weight: 600; font-size: 13px; color: var(--muted);
  cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap;
}
.sheet-tabs button[aria-selected="true"] { color: var(--brand-ink); border-bottom-color: var(--accent); }
.sheet-body { padding: 18px 20px 24px; overflow-y: auto; flex: 1; }
.sheet-grid { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 16px; }
.sheet-grid .col { display: grid; gap: 16px; align-content: start; }
.sec { border: 1px solid var(--border); border-radius: var(--r-card); padding: 14px 16px; display: grid; gap: 8px; align-content: start; margin-bottom: 14px; }
.sheet-grid .sec { margin-bottom: 0; }
.sec h3 { font-size: 13px; display: flex; align-items: center; gap: 8px; }
.kv { display: grid; grid-template-columns: 140px minmax(0, 1fr); gap: 12px; font-size: 13px; padding: 2px 0; }
.kv span { color: var(--muted); }
.kv b { font-weight: 500; overflow-wrap: anywhere; }
.note-text { white-space: pre-wrap; font-size: 13.5px; }
.note-item { padding: 8px 0; border-bottom: 1px dashed var(--border); }
.note-item:last-child { border-bottom: 0; }
.note-item p { font-size: 13px; }
.row-line { display: flex; gap: 12px; align-items: center; justify-content: space-between; flex-wrap: wrap; font-size: 13px; padding: 6px 0; border-bottom: 1px dashed var(--border); }
.row-line:last-child { border-bottom: 0; }
.timeline { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.timeline li { display: grid; grid-template-columns: 12px auto 1fr; gap: 10px; align-items: center; font-size: 13px; }
.timeline small { justify-self: end; }
.tl-dot { width: 10px; height: 10px; border-radius: 50%; }
.tbl.mini { font-size: 12.5px; }
.tbl.mini th { position: static; padding: 8px; }
.tbl.mini td { height: 38px; padding: 0 8px; }
.tbl.mini tbody tr { cursor: default; }
.tbl.mini tbody tr:hover { background: transparent; }
.wchart { width: 100%; height: auto; }
.wchart .draw { stroke-dasharray: 1200; stroke-dashoffset: 1200; animation: draw .8s var(--ease) forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }

@media (max-width: 899px) {
  .toolbar .select-sm, .toolbar [data-cols], .toolbar [data-toggle-density] { display: none; }
  .search-box { flex: 1 1 100%; }
  /* Tables become cards on phones. */
  .tbl:not(.mini) thead { display: none; }
  .tbl:not(.mini), .tbl:not(.mini) tbody { display: block; width: 100%; }
  .tbl:not(.mini) tr { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .tbl:not(.mini) td { display: block; height: auto; padding: 0; border: 0; white-space: normal; }
  .tbl:not(.mini) td.c-patient, .tbl:not(.mini) td.c-contact { grid-column: 1 / -1; height: auto; min-width: 0; }
  .tbl:not(.mini) td.c-patient .cell-patient, .tbl:not(.mini) td.c-contact .cell-patient { height: auto; min-width: 0; }
  .tbl:not(.mini) .c-note, .tbl:not(.mini) .c-label, .tbl:not(.mini) .c-lastRx, .tbl:not(.mini) .c-lifetime { display: none; }
  .sheet { top: 0; left: 0; transform: none; width: 100vw; max-height: none; height: 100dvh; border-radius: 0; }
  .sheet-head { flex-wrap: wrap; padding: 12px 14px; padding-top: calc(12px + env(safe-area-inset-top, 0px)); }
  .sheet-actions { width: 100%; }
  .sheet-actions [data-close] { position: absolute; top: calc(10px + env(safe-area-inset-top, 0px)); right: 10px; }
  .sheet-stats { grid-template-columns: 1fr 1fr; }
  .sheet-stats .stat { border-bottom: 1px solid var(--border); }
  .sheet-grid { grid-template-columns: minmax(0, 1fr); }
  .kv { grid-template-columns: 110px minmax(0, 1fr); }
}

/* Row actions and the team note editor. */
.col-act { width: 44px; text-align: right; }
.row-more { opacity: 0; transition: opacity .12s; width: 30px; height: 30px; }
.tbl tbody tr:hover .row-more, .row-more:focus-visible { opacity: 1; }
@media (hover: none) { .row-more { opacity: 1; } }
.note-edit { display: grid; gap: 8px; }
.note-edit textarea { height: auto; min-height: 90px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.note-bar { display: flex; align-items: center; gap: 10px; }
.note-bar small:first-child { flex: 1; }

/* Sheet sections keep their size; only the body scrolls. */
.sheet-head, .sheet-stats, .jband, .sheet-tabs { flex: none; }
/* Journey band: one slim segmented bar per track. */
.jtracks { display: grid; gap: 10px; padding: 14px 20px; border-bottom: 1px solid var(--border); background: var(--surface); flex: none; }
.jt-row { display: grid; grid-template-columns: 92px minmax(0, 1fr) minmax(150px, auto); gap: 14px; align-items: center; }
.jt-name { font-size: 12px; font-weight: 700; color: var(--muted); }
.jt-bar { display: flex; gap: 3px; height: 8px; }
.jt-bar i { flex: 1; border-radius: 99px; background: var(--border); }
.jt-bar i.on { background: var(--ph); }
.jt-bar i.now { background: var(--ph); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ph) 25%, transparent); }
.jt-cap { font-size: 12.5px; display: flex; gap: 6px; align-items: center; justify-content: flex-end; white-space: nowrap; }
.jt-foot { font-size: 12px; color: var(--muted); text-align: right; }
@media (max-width: 899px) { .jt-row { grid-template-columns: minmax(0, 1fr); gap: 4px; } .jt-cap { justify-content: flex-start; } }

/* Journey rail (replaces the segmented bar). */
.jt-rail { position: relative; height: 4px; border-radius: 99px; background: var(--border); margin: 0 7px; }
.jt-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 99px; background: var(--brand); }
.jt-dot { position: absolute; top: 50%; width: 14px; height: 14px; border-radius: 50%; background: var(--card); border: 3px solid var(--brand); transform: translate(-50%, -50%); box-shadow: 0 0 0 4px var(--brand-tint); }
.jt-dot.is-closed { background: var(--brand); box-shadow: none; }

/* Sortable column headers. */
.tbl th .th-sort { display: inline-flex; align-items: center; gap: 4px; border: 0; background: transparent; padding: 0; font: inherit; color: inherit; letter-spacing: inherit; text-transform: inherit; cursor: pointer; }
.tbl th .th-sort .arrow { font-size: 11px; opacity: .35; }
.tbl th .th-sort:hover { color: var(--text); }
.tbl th .th-sort:hover .arrow { opacity: .8; }
.tbl th .th-sort.is-on { color: var(--brand-ink); }
.tbl th .th-sort.is-on .arrow { opacity: 1; }

/* ---------- Customizable tables ---------- */
.tbl-sk { display: grid; gap: 12px; padding: 18px 16px; }
@media (min-width: 900px) {
  /* Toolbar and tabs stay on screen while the page scrolls; the table scrolls inside itself
     so its header row can stick too. */
  .table-top { position: sticky; top: var(--topbar-h); z-index: 15; background: var(--surface); padding-top: 6px; margin-top: -6px; }
  .table-wrap.tw-fit { overflow: auto; overscroll-behavior: contain; }
  .tbl-x thead th { z-index: 3; }
  .tbl-x th[draggable="true"] { cursor: grab; }
  .tbl-x th .th-in { display: inline-flex; align-items: center; gap: 4px; }
  .tbl-x .is-pinned { position: sticky; z-index: 2; background: var(--card); }
  .tbl-x thead th.is-pinned { z-index: 4; background: var(--surface); }
  .tbl-x .pin-edge { box-shadow: inset -1px 0 0 var(--border), 8px 0 10px -8px var(--pin-shadow); }
  .tbl-x tbody tr:hover td.is-pinned { background: linear-gradient(var(--brand-tint), var(--brand-tint)), var(--card); }
  .tbl-x th.is-dragging { opacity: .45; }
  .tbl-x th.drop-before { box-shadow: inset 3px 0 0 var(--brand); }
  .tbl-x th.drop-after { box-shadow: inset -3px 0 0 var(--brand); }
}
.col-resize { position: absolute; top: 0; right: -5px; width: 10px; height: 100%; cursor: col-resize; z-index: 5; touch-action: none; }
.col-resize::after { content: ""; position: absolute; left: 4px; top: 25%; height: 50%; width: 2px; border-radius: 2px; background: var(--border-strong); opacity: 0; transition: opacity .12s; }
.tbl-x th:hover .col-resize::after, body.is-col-resizing .col-resize::after { opacity: 1; }
body.is-col-resizing { cursor: col-resize; user-select: none; -webkit-user-select: none; }

.col-panel {
  position: fixed; z-index: 95; width: min(360px, calc(100vw - 16px)); max-height: min(72vh, 560px); overflow-y: auto;
  padding: 12px; background: var(--card); border: 1px solid var(--border); border-radius: var(--r-card); box-shadow: var(--shadow-2);
  animation: pop .18s var(--ease);
}
.cp-head { display: grid; gap: 2px; margin-bottom: 8px; }
.cp-head b { font-size: 14px; }
.cp-head small { color: var(--muted); font-size: 12px; }
.cp-grip-inline svg { width: 12px; height: 12px; vertical-align: -2px; }
.cp-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.cp-list li { display: flex; align-items: center; gap: 4px; padding: 2px 4px; border-radius: 8px; border: 1px solid transparent; background: var(--card); }
.cp-list li:hover { background: var(--surface); }
.cp-list li.is-off label { color: var(--muted); }
.cp-list li.is-dragging { opacity: .45; }
.cp-list li.drop-before { box-shadow: inset 0 3px 0 var(--brand); }
.cp-list li.drop-after { box-shadow: inset 0 -3px 0 var(--brand); }
.cp-list label { flex: 1; display: flex; align-items: center; gap: 8px; min-height: 34px; font-size: 13.5px; cursor: pointer; }
.cp-list .icon-btn { width: 28px; height: 28px; }
.cp-list .icon-btn svg { width: 15px; height: 15px; }
.cp-list .icon-btn:disabled { opacity: .3; cursor: default; }
.cp-grip { display: inline-flex; color: var(--faint); cursor: grab; padding: 4px 2px; }
.cp-grip svg { width: 14px; height: 14px; }
.cp-pin.is-on { color: var(--brand-ink); background: var(--brand-tint); }
.cp-tip { margin: 10px 2px 0; }
.cp-foot { display: flex; gap: 6px; align-items: center; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
@media (max-width: 899px) {
  .tbl:not(.mini) tr { position: relative; }
  .tbl:not(.mini) td.col-act { position: absolute; top: 10px; right: 8px; width: auto; }
  .tbl:not(.mini) td.c-patient, .tbl:not(.mini) td.c-contact { padding-right: 36px; }
}

/* GHL tasks card in the patient panel (read-only) */
.gtasks { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: 260px; overflow-y: auto; }
.gtasks li { display: grid; grid-template-columns: 18px minmax(0, 1fr) auto; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--border); font-size: 13px; }
.gtasks li:last-child { border-bottom: 0; }
.gtasks li > div { display: grid; gap: 1px; min-width: 0; }
.gtasks b { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gtasks small { font-size: 11.5px; }
.gtasks .pill { font-size: 10.5px; padding: 1px 7px; }
.gtasks li.is-done b { font-weight: 500; color: var(--muted); }
.gt-mark { width: 16px; height: 16px; border-radius: 50%; border: 1.5px solid var(--border-strong); display: grid; place-items: center; font-size: 10px; color: var(--good-ink); }
.gtasks li.is-done .gt-mark { border-color: var(--good); background: var(--good-tint); }
.gt-over { color: var(--warn-ink); }
