/* TheraGrid - the pages: grids, chips, forms, dialogs.
   app.css holds the shell and the palette; this holds everything inside it.
   Extra tokens are defined here so the two sheets stay independent. */

:root {
  --stripe:#FBFCFD;
  --ind:#2F6FB5;      /* individual  */
  --grp:#7A4FA8;      /* group       */
  --rs:#0E7FB8;       /* rescheduled - sky blue, the clinic's own reading */
  --rs-bg:#E3F3FB;
  --pkg:#0F6E58;
  --pkg-bg:#E4F2EE;
  --cancel:#C0392B;
  --snum-bg:#E6EBF1;
  --snum-ink:#243747;
  --shadow:0 10px 34px rgba(16,24,32,.18);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --stripe:#141A20;
    --ind:#5A9BE0; --grp:#B084E0; --rs:#5FBCEA; --rs-bg:#0F2A38;
    --pkg:#4BB98D; --pkg-bg:#12291F;
    --cancel:#E8705F;
    --snum-bg:#222C36; --snum-ink:#D6DEE7;
    --shadow:0 10px 34px rgba(0,0,0,.55);
  }
}

:root[data-theme="dark"] {
  --stripe:#141A20;
  --ind:#5A9BE0; --grp:#B084E0; --rs:#5FBCEA; --rs-bg:#0F2A38;
  --pkg:#4BB98D; --pkg-bg:#12291F;
  --cancel:#E8705F;
  --snum-bg:#222C36; --snum-ink:#D6DEE7;
  --shadow:0 10px 34px rgba(0,0,0,.55);
}

/* ---------------------------------------------------------------- bars --- */

.toolbar, .filterbar {
  display:flex; flex-wrap:wrap; gap:9px; align-items:center;
  background:var(--surface); border:1px solid var(--line);
  border-radius:var(--radius); padding:9px 11px;
}
.filterbar { margin-top:9px; }
.grow { flex:1; }
.seg { display:flex; gap:4px; }
.seg .btn { padding:7px 12px; }
.seg .btn[aria-pressed="true"] {
  background:var(--accent); border-color:var(--accent); color:var(--accent-ink);
}
.range {
  font-family:"IBM Plex Mono", ui-monospace, monospace; font-size:13px;
  font-weight:500; white-space:nowrap; padding:0 4px;
}
.dateinput, .search {
  border:1px solid var(--line); background:var(--ground); color:var(--ink);
  border-radius:8px; padding:7px 10px; font:inherit; font-size:13px; min-height:36px;
}
.search { min-width:180px; }
.dateinput { font-family:"IBM Plex Mono", ui-monospace, monospace; font-size:12px; }

.filterbar label {
  font-size:10px; font-family:"IBM Plex Mono", ui-monospace, monospace;
  letter-spacing:.11em; text-transform:uppercase; color:var(--faint);
}
.filterbar .sep { width:1px; align-self:stretch; background:var(--line); margin:0 3px; }
.pills { display:flex; flex-wrap:wrap; gap:5px; }
.pill-btn {
  appearance:none; cursor:pointer; font:inherit; font-size:12px;
  display:inline-flex; align-items:center; gap:6px;
  border:1px solid var(--line); background:var(--ground); color:var(--ink);
  border-radius:999px; padding:4px 11px;
}
.pill-btn:hover { border-color:var(--accent); }
.pill-btn[aria-pressed="true"] {
  border-color:var(--accent); background:var(--accent-bg); font-weight:500;
}
.pill-btn .dot { width:9px; height:9px; border-radius:50%; flex:none; }

/* ---------------------------------------------------------------- grid --- */

.gridwrap {
  margin-top:10px; background:var(--surface);
  border:1px solid var(--line); border-radius:var(--radius);
  /* Scrolls in BOTH directions, which is also what makes the sticky header and
     time column work: a sticky cell is positioned against its nearest scroll
     container, and overflow-x alone already makes this one. Offsetting the
     header to clear the page nav pinned it 52px below the grid's own top
     instead - an empty band across the table, with the first slot label hidden
     underneath it. */
  overflow:auto; max-height:calc(100vh - 230px);
}
table.cal { border-collapse:collapse; width:100%; }
table.cal th, table.cal td {
  border-right:1px solid var(--line-soft); vertical-align:top; padding:0;
}
/* Slot rows are tall, so the divider has to be findable without counting cards. */
table.cal tbody tr > td { border-bottom:3px solid var(--line); }
table.cal tbody tr:nth-child(even) > td { background:var(--stripe); }

table.cal thead th {
  position:sticky; top:0; z-index:5;
  background:var(--sunken); font-size:12px; font-weight:600; padding:8px 10px;
  text-align:left; border-bottom:1px solid var(--line); white-space:nowrap;
}
table.cal thead th.today { color:var(--accent); box-shadow:inset 0 -2px 0 var(--accent); }
table.cal thead th .wd {
  display:block; font-family:"IBM Plex Mono", ui-monospace, monospace;
  font-size:10px; letter-spacing:.09em; text-transform:uppercase;
  color:var(--faint); font-weight:500;
}
.shutlabel {
  display:block; font-size:10px; font-weight:500; color:var(--bad);
  text-transform:none; letter-spacing:0;
}

td.slotcell, th.slotcell {
  background:var(--sunken); padding:8px 10px; white-space:nowrap; width:1%;
  font-family:"IBM Plex Mono", ui-monospace, monospace; font-size:13px;
  position:sticky; left:0; z-index:4;
}
/* The corner belongs on top of both, or the row it crosses paints over it. */
table.cal thead th.slotcell { z-index:6; }
td.daycell { padding:5px; min-width:172px; }
td.daycell.today { background:var(--accent-bg); }
td.shut, th.shut { background:repeating-linear-gradient(45deg,
  transparent, transparent 7px, var(--line-soft) 7px, var(--line-soft) 14px); }

/* --------------------------------------------------------------- chips --- */

ul.sessions { list-style:none; margin:0; padding:0; display:flex; flex-direction:column; gap:5px; }
.sess {
  border:1px solid var(--line); border-left:8px solid var(--kidcolour, var(--line));
  border-radius:7px; background:var(--raised); padding:4px 7px; cursor:pointer;
}
.sess:hover { border-color:var(--accent); border-left-color:var(--kidcolour, var(--accent)); }
.sess.dim { opacity:.3; filter:saturate(.35); }
.sess.st-cancelled .sess-name { text-decoration:line-through; }
.sess-top { display:flex; align-items:center; gap:5px; flex-wrap:wrap; }
.sess-name { font-size:12.5px; font-weight:600; }
.sess-meta {
  font-family:"IBM Plex Mono", ui-monospace, monospace; font-size:10px;
  color:var(--muted); margin-top:2px;
}
.sess-note { font-size:11px; color:var(--wait); margin-top:3px; word-break:break-word; }

/* The session number is what staff read first, so it gets real weight. */
.snum {
  font-family:"IBM Plex Mono", ui-monospace, monospace; font-size:13px; font-weight:700;
  background:var(--snum-bg); color:var(--snum-ink); border-radius:5px;
  padding:0 6px; letter-spacing:-.02em;
}
.badge {
  font-size:9px; font-weight:700; letter-spacing:.04em; padding:1px 5px;
  border-radius:4px; border:1px solid var(--line); color:var(--muted);
}
/* Group and individual are read at a glance, so they get colour, not outline. */
.badge.g  { color:#fff; background:var(--grp); border-color:transparent; }
.badge.i  { color:#fff; background:var(--ind); border-color:transparent; }
.badge.rs { color:#fff; background:var(--rs);  border-color:transparent; }
.badge.cx { color:#fff; background:var(--cancel); border-color:transparent; }
.badge.ok { color:#fff; background:var(--ok); border-color:transparent; }
.badge.warn { color:#fff; background:var(--cancel); border-color:transparent; font-size:9px; }
.badge.pkgflag {
  background:var(--pkg-bg); color:var(--pkg); border-color:transparent;
  font-family:"IBM Plex Mono", ui-monospace, monospace;
}

.cellfoot { display:flex; gap:5px; margin-top:6px; }
.addbtn {
  flex:1; border:1px dashed var(--line); background:none; color:var(--accent);
  border-radius:7px; padding:4px; cursor:pointer; font-size:16px; line-height:1;
}
.addbtn:hover { border-color:var(--accent); background:var(--accent-bg); }
.notebtn {
  appearance:none; border:1px dashed var(--line); background:none; cursor:pointer;
  color:var(--muted); border-radius:7px; padding:4px 9px; font-size:13px; line-height:1;
}
.notebtn:hover, .notebtn.has {
  border-style:solid; border-color:var(--wait); color:var(--wait); background:var(--wait-bg);
}
.cellnote {
  background:var(--wait-bg); border-left:3px solid var(--wait); border-radius:6px;
  padding:4px 7px; margin-bottom:6px; font-size:11.5px; cursor:pointer;
  word-break:break-word;
}
.cellnote.done {
  background:var(--sunken); border-left-color:var(--faint);
  color:var(--faint); text-decoration:line-through;
}

/* ------------------------------------------------------------- summary --- */

tr.summary td {
  background:var(--sunken); padding:8px 10px; vertical-align:top;
  font-family:"IBM Plex Mono", ui-monospace, monospace; font-size:11px;
}
tr.summary .big {
  display:block; margin-bottom:5px; font-family:"IBM Plex Sans", system-ui, sans-serif;
  font-size:13px; font-weight:600;
}
.openrow { display:flex; align-items:center; gap:3px; flex-wrap:wrap; margin-bottom:3px; }
.openrow .slotlabel { color:var(--faint); width:38px; flex:none; font-size:10px; }
.tchip {
  font-size:9px; font-weight:700; color:#fff; padding:1px 5px; border-radius:4px;
  white-space:nowrap; letter-spacing:.03em;
}
.opencell .none { color:var(--faint); }

/* --------------------------------------------------------------- modal --- */

.modal {
  position:fixed; inset:0; z-index:100; background:rgba(12,16,20,.55);
  display:flex; align-items:flex-start; justify-content:center;
  padding:40px 16px; overflow:auto;
}
.modal-box {
  width:100%; max-width:540px; background:var(--surface);
  border:1px solid var(--line); border-radius:13px; box-shadow:var(--shadow);
}
.modal-box.wide { max-width:860px; }
.modal-head {
  display:flex; align-items:center; gap:12px; padding:14px 18px;
  border-bottom:1px solid var(--line);
}
.modal-head h3 { margin:0; font-size:16px; font-weight:600; flex:1; }
.modal-head .x {
  appearance:none; border:0; background:none; cursor:pointer;
  color:var(--muted); font-size:24px; line-height:1; padding:0 4px;
}
.modal-head .x:hover { color:var(--ink); }
.modal-body { padding:16px 18px 18px; }

/* --------------------------------------------------------------- forms --- */

.form2 { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.form1 { display:flex; flex-direction:column; gap:9px; }
.form2 .span2 { grid-column:1 / -1; }
.form2 label, .form1 label {
  display:block; font-size:12px; font-weight:500; color:var(--muted); margin-bottom:4px;
}
.form2 input, .form2 select, .form1 input, .form1 select, .form1 textarea {
  width:100%; border:1px solid var(--line); background:var(--ground); color:var(--ink);
  border-radius:8px; padding:8px 10px; font:inherit; font-size:14px;
}
.form2 input:focus, .form2 select:focus, .form1 textarea:focus {
  outline:2px solid var(--accent); outline-offset:-1px;
}
.form1 textarea { resize:vertical; font-family:inherit; }
.form1 label.check {
  display:flex; align-items:center; gap:7px; font-size:13px; color:var(--ink);
}
.form1 label.check input { width:auto; }
.actions { display:flex; gap:8px; align-items:center; margin-top:2px; }
.btn.danger { border-color:var(--bad); color:var(--bad); }
.btn.danger:hover { background:var(--bad-bg); }

/* --------------------------------------------------------------- toast --- */

.toast {
  position:fixed; left:50%; bottom:22px; transform:translate(-50%, 18px);
  z-index:200; padding:10px 16px; border-radius:9px; font-size:13px;
  background:var(--ink); color:var(--ground); box-shadow:var(--shadow);
  opacity:0; pointer-events:none; transition:opacity .16s, transform .16s;
}
.toast.show { opacity:1; transform:translate(-50%, 0); }
.toast.bad { background:var(--bad); color:#fff; }

/* -------------------------------------------------------------- mobile --- */

@media (max-width: 760px) {
  .toolbar, .filterbar { padding:8px; }
  .search { min-width:0; flex:1; }
  .range { width:100%; order:9; }
  td.daycell { min-width:150px; }
  .gridwrap { max-height:calc(100vh - 180px); }
  .form2 { grid-template-columns:1fr; }
  .modal { padding:14px 10px; }
}

/* A provisional booking: pencilled in, and deliberately allowed to sit on top
   of a real one. It has to look unlike a confirmed session at a glance, or
   staff will read the grid as more certain than it is. */
.badge.tent {
  color:#fff; background:var(--wait); border-color:transparent;
  font-size:10px; padding:0 5px;
}
.sess.tentative { border-style:dashed; background:transparent; }

/* ----------------------------------------------------------- conflicts --- */

/* Contradictions the spreadsheet allowed: a therapist in two places, an
   individual sharing a therapist with a group. They are not errors in
   TheraGrid, and they cannot be resolved by software - someone has to decide
   which booking is real. So they are loud, and they carry the cell text needed
   to find the row in the sheet. */

.conflictbar {
  margin-top:10px; border:1px solid var(--bad);
  background:var(--bad-bg); border-radius:var(--radius); overflow:hidden;
}
.conflictbar .chead {
  display:flex; align-items:center; gap:9px; width:100%;
  appearance:none; border:0; background:none; cursor:pointer;
  font:inherit; color:var(--bad); text-align:left; padding:10px 13px;
}
.conflictbar .chead .flag { font-size:15px; line-height:1; }
.conflictbar .chead .sub { color:var(--muted); font-weight:400; }
.conflictbar .chead .chev { margin-left:auto; transition:transform .15s; }
.conflictbar[data-open="true"] .chead .chev { transform:rotate(180deg); }

.conflictbar .clist { display:none; list-style:none; margin:0; padding:0 13px 12px; }
.conflictbar[data-open="true"] .clist { display:block; }
.conflictbar .clist li {
  padding:8px 0; border-top:1px solid var(--line); font-size:13px;
  display:flex; flex-wrap:wrap; gap:8px; align-items:baseline;
}
.conflictbar .clist .when {
  font-family:"IBM Plex Mono", ui-monospace, monospace; font-size:11px;
  color:var(--faint); min-width:82px;
}
.conflictbar .clist .why { color:var(--muted); flex:1 1 260px; }
.conflictbar .clist code, .clashchip code {
  font-family:"IBM Plex Mono", ui-monospace, monospace; font-size:11px;
  background:var(--sunken); color:var(--ink); padding:1px 6px; border-radius:4px;
  word-break:break-word;
}

/* The cell it belongs to, so it is findable from the grid and not only a list. */
td.daycell.hasclash { box-shadow:inset 0 0 0 2px var(--bad); }
.clashchip {
  border:1px dashed var(--bad); border-left:8px solid var(--bad);
  background:var(--bad-bg); border-radius:7px; padding:4px 7px; margin-bottom:6px;
  font-size:11.5px; color:var(--bad);
}
.clashchip b { font-size:12.5px; }
.clashchip .why { display:block; color:var(--muted); margin:2px 0 3px; }
.conflictbar .clist li[data-jump] { cursor:pointer; }
.conflictbar .clist li[data-jump]:hover { background:var(--surface); }

/* ------------------------------------------------------------- planning --- */

.toolbar b { font-size:14px; }
.toolbar .sub { color:var(--muted); font-size:12px; }

/* The weekly grid has no dates, so the columns are wider and calmer than the
   calendar's - there is less in each cell and more reason to read across. */
table.cal.plan td.daycell { min-width:190px; }
table.cal.plan thead th { text-transform:none; }

.openline { display:flex; flex-wrap:wrap; gap:3px; margin-top:6px; }
.openpill {
  color:#fff; font-size:9px; font-weight:700; letter-spacing:.04em;
  padding:1px 7px; border-radius:999px; white-space:nowrap;
}

/* ------------------------------------------------------------- packages --- */

table.rows { border-collapse:collapse; width:100%; font-size:13px; }
table.rows thead th {
  position:sticky; top:0; z-index:2; text-align:left; white-space:nowrap;
  background:var(--sunken); color:var(--faint); font-weight:600; font-size:11px;
  letter-spacing:.06em; text-transform:uppercase;
  padding:9px 12px; border-bottom:1px solid var(--line);
}
table.rows td { padding:10px 12px; border-bottom:1px solid var(--line-soft); vertical-align:middle; }
table.rows tbody tr { cursor:pointer; }
table.rows tbody tr:hover td { background:var(--raised); }
table.rows .num { text-align:right; font-family:"IBM Plex Mono", ui-monospace, monospace; }
table.rows .mono { font-family:"IBM Plex Mono", ui-monospace, monospace; font-size:12px; color:var(--muted); }
table.rows .dot {
  display:inline-block; width:9px; height:9px; border-radius:50%;
  margin-right:7px; vertical-align:-1px;
}

/* The bar carries the answer at a glance; the numbers are for confirming it. */
.progress { min-width:210px; }
.progress .bar {
  height:6px; border-radius:99px; background:var(--sunken); overflow:hidden; margin-bottom:4px;
}
.progress .bar i { display:block; height:100%; background:var(--accent); }
.progress .bar.near i { background:var(--wait); }
.progress .bar.over i { background:var(--bad); }
.progress .count {
  font-family:"IBM Plex Mono", ui-monospace, monospace; font-size:11px; color:var(--muted);
}
.progress .muted { font-size:11px; color:var(--faint); margin-left:8px; }

.panel.empty { text-align:center; padding:38px 22px; }
.panel.empty .lead { max-width:520px; margin:6px auto 0; }

/* --------------------------------------------------- policy and settings --- */

/* Where a package stands against what was agreed. "Not agreed" is deliberately
   quiet: nothing agreed is not the same as nothing allowed, and colouring it
   like a breach would put every family in the wrong over a rule nobody made. */
.standing {
  font-size:11px; font-weight:600; padding:2px 9px; border-radius:999px;
  background:var(--sunken); color:var(--muted);
}
.standing.within { background:var(--ok-bg); color:var(--ok); }
.standing.spent  { background:var(--wait-bg); color:var(--wait); }
.standing.over   { background:var(--bad-bg); color:var(--bad); }

.hint {
  font-size:12px; color:var(--muted); margin:0 0 7px; font-weight:400;
  max-width:62ch;
}
.checkrow { display:flex; flex-wrap:wrap; gap:6px 16px; }
.checkrow .check {
  display:flex; align-items:center; gap:6px; font-size:13px;
  color:var(--ink); font-weight:400; margin:0;
}
.checkrow .check input { width:auto; }

.form2 textarea {
  width:100%; border:1px solid var(--line); background:var(--ground); color:var(--ink);
  border-radius:8px; padding:8px 10px; font:inherit; font-size:14px;
  font-family:"IBM Plex Mono", ui-monospace, monospace; resize:vertical;
}
.form2 label.check { display:flex; align-items:center; gap:7px; color:var(--ink); }
.form2 label.check input { width:auto; }

/* A closure in the past is history, not something to act on. */
table.rows tr.past td { opacity:.5; }

/* ----------------------------------------------------------- slot editor --- */

/* The session times are the rows of the calendar, in the order of the clinic's
   day. A textarea could hold them but said none of that. */
.slotlist { display:flex; flex-direction:column; gap:6px; margin-bottom:9px; }
.slotrow { display:flex; align-items:center; gap:7px; }
.slotrow .ord {
  width:22px; flex:none; text-align:right; color:var(--faint);
  font-family:"IBM Plex Mono", ui-monospace, monospace; font-size:11px;
}
.slotrow input {
  flex:0 1 150px; font-family:"IBM Plex Mono", ui-monospace, monospace;
}
.iconbtn {
  appearance:none; cursor:pointer; flex:none;
  border:1px solid var(--line); background:var(--surface); color:var(--muted);
  border-radius:7px; width:30px; height:34px; font-size:11px; line-height:1;
}
.iconbtn:hover:not(:disabled) { border-color:var(--accent); color:var(--accent); }
.iconbtn:disabled { opacity:.3; cursor:default; }
.iconbtn.danger { font-size:16px; }
.iconbtn.danger:hover { border-color:var(--bad); color:var(--bad); background:var(--bad-bg); }

/* A second scrollbar above a wide grid. The real one is at the bottom of a
   table taller than the window, so reaching it means scrolling past what you
   were trying to look at. */
.topscroll {
  overflow-x:auto; overflow-y:hidden; height:12px; margin-top:10px;
  border:1px solid var(--line); border-bottom:0;
  border-radius:var(--radius) var(--radius) 0 0; background:var(--surface);
}
.topscroll > div { height:1px; }
.topscroll + .gridwrap { margin-top:0; border-top-left-radius:0; border-top-right-radius:0; }

/* ------------------------------------------------------------- messages --- */

/* A limitation stated plainly, rather than a button that quietly cannot work. */
.panel.notice { border-left:5px solid var(--wait); background:var(--wait-bg); }
.panel.notice h2 { color:var(--wait); }
.panel.notice .lead { color:var(--ink); margin-bottom:0; }

.tile.warn { border-left-color:var(--wait); }
.tile.warn .n { color:var(--wait); }

.btn.tiny { min-height:0; padding:3px 9px; font-size:12px; }

.msgtext {
  margin:0; padding:13px 15px; white-space:pre-wrap; word-break:break-word;
  background:var(--sunken); border-radius:var(--radius);
  font-family:inherit; font-size:13.5px; line-height:1.55;
}

.panel > .cards { margin-bottom:0; }
.cards + .panel { margin-top:16px; }

/* -------------------------------------------------------------- history --- */

.seenby { display:flex; flex-wrap:wrap; gap:6px; align-items:center; margin-top:14px; }
.seenby .lbl {
  font-size:10px; font-family:"IBM Plex Mono", ui-monospace, monospace;
  letter-spacing:.11em; text-transform:uppercase; color:var(--faint);
}
.seenby .tpill {
  color:#fff; font-size:11px; font-weight:600; padding:2px 10px; border-radius:999px;
}

/* The time it was booked for, with what actually ran underneath it. */
.ran { display:block; font-size:10px; color:var(--faint); }
.notecell { max-width:280px; color:var(--muted); font-size:12px; word-break:break-word; }
table.rows td .badge { margin-left:4px; }

/* ----------------------------------------------------------------- team --- */

.readonly {
  margin:0; padding:8px 10px; background:var(--sunken); border-radius:8px;
  font-size:13px; color:var(--muted);
}
.never { color:var(--faint); }
.muted { color:var(--faint); font-size:12px; }

/* Roles as cards, not a dropdown: what each one means is the decision, and a
   select hides it behind a click. */
.rolepick { display:grid; grid-template-columns:repeat(auto-fit,minmax(200px,1fr)); gap:8px; }
.rolecard {
  display:flex; gap:9px; align-items:flex-start; cursor:pointer;
  border:1px solid var(--line); border-radius:var(--radius); padding:10px 12px;
  background:var(--ground);
}
.rolecard:has(input:checked) { border-color:var(--accent); background:var(--accent-bg); }
.rolecard:has(input:disabled) { opacity:.55; cursor:default; }
.rolecard input { width:auto; margin-top:3px; flex:none; }
.rolecard b { display:block; font-size:13px; }
.rolecard em { display:block; font-style:normal; font-size:11.5px; color:var(--muted); margin-top:2px; }

.permgrid { display:grid; grid-template-columns:repeat(auto-fit,minmax(215px,1fr)); gap:14px; }
.permarea h4 {
  margin:0 0 6px; font-size:10px; letter-spacing:.11em; text-transform:uppercase;
  color:var(--faint); font-family:"IBM Plex Mono", ui-monospace, monospace; font-weight:600;
}
.check.perm {
  display:flex; align-items:center; gap:7px; font-size:12.5px; color:var(--ink);
  font-weight:400; margin:0 0 5px; cursor:pointer;
}
.check.perm input { width:auto; flex:none; }
.check.perm .ovr {
  font-style:normal; font-size:9px; letter-spacing:.06em; text-transform:uppercase;
  color:var(--wait); background:var(--wait-bg); padding:1px 5px; border-radius:4px;
}

.steps { margin:12px 0 0; padding-left:22px; font-size:13.5px; line-height:1.7; }
.steps li { margin-bottom:7px; }

/* The filter bar folds away on a phone, where it would otherwise push the grid
   off the bottom of the screen. On a desktop it costs one line, so it stays. */
.foldbtn { display:none; }

@media (max-width: 760px) {
  .foldbtn {
    display:block; width:100%; margin-top:9px; text-align:left;
    appearance:none; cursor:pointer; font:inherit; font-size:12.5px;
    border:1px solid var(--line); background:var(--surface); color:var(--muted);
    border-radius:var(--radius); padding:9px 12px;
  }
  .foldbtn::after { content:" ▾"; color:var(--faint); }
  .foldbtn[aria-expanded="true"]::after { content:" ▴"; }
  .filterbar { display:none; }
  .filterbar.open { display:flex; }
  .foldbtn + .filterbar.open { margin-top:6px; }
}

/* --------------------------------------------------- chips, fuller form --- */

/* The outcome is a word, right-aligned, because it is what the eye goes to
   after the name. A tick meaning "attended" is indistinguishable at a glance
   from a tick meaning "confirmed", and staff should not have to learn which. */
.outcome {
  font-size:8.5px; font-weight:700; letter-spacing:.07em; white-space:nowrap;
  padding:2px 6px; border-radius:4px; background:var(--sunken); color:var(--muted);
}
.outcome.attended  { background:var(--ok-bg); color:var(--ok); }
.outcome.cancelled { background:var(--bad-bg); color:var(--bad); }
.outcome.immediate { background:var(--bad); color:#fff; }
.outcome.scheduled { background:var(--accent-bg); color:var(--accent); }

.badge.code {
  background:var(--ind); color:#fff; border-color:transparent;
  font-family:"IBM Plex Mono", ui-monospace, monospace;
}

.sess-acts { display:flex; gap:10px; margin-top:5px; }
.linkbtn {
  appearance:none; border:0; background:none; padding:0; cursor:pointer;
  font:inherit; font-size:10.5px; color:var(--muted); text-decoration:underline;
  text-underline-offset:2px;
}
.linkbtn:hover { color:var(--accent); }
.sess-top .grow { flex:1; }

/* ---------------------------------------------------------- month view --- */

.monthhead {
  display:grid; grid-template-columns:repeat(7,1fr); gap:5px; padding:10px 10px 0;
  font-size:10px; font-family:"IBM Plex Mono", ui-monospace, monospace;
  letter-spacing:.09em; text-transform:uppercase; color:var(--faint);
}
.monthgrid { display:grid; grid-template-columns:repeat(7,1fr); gap:5px; padding:6px 10px 10px; }
.mday {
  appearance:none; cursor:pointer; text-align:left; font:inherit;
  background:var(--raised); border:1px solid var(--line); border-radius:8px;
  padding:8px 9px; min-height:80px; color:var(--ink);
  display:flex; flex-direction:column; gap:1px;
}
.mday:hover:not(:disabled) { border-color:var(--accent); }
.mday:disabled { cursor:default; }
.mday.blank { background:none; border:0; min-height:0; }
.mday.off { background:none; border-style:dashed; color:var(--faint); }
.mday.shut { background:var(--bad-bg); border-color:var(--bad); }
.mday.today { border-color:var(--accent); box-shadow:inset 0 0 0 1px var(--accent); }
.mday .n { font-family:"IBM Plex Mono", ui-monospace, monospace; font-weight:600; font-size:14px; }
.mday .s { font-size:10.5px; color:var(--muted); }
.mday .s.bad { color:var(--bad); }
.mday .s.dim { color:var(--faint); }

/* --------------------------------------------------------- availability --- */

table.rows.avail th { font-size:10px; }
.availcell { vertical-align:top; }
.freeslot {
  display:inline-block; margin:0 3px 3px 0; padding:1px 6px; border-radius:4px;
  background:var(--ok-bg); color:var(--ok); font-size:10px;
  font-family:"IBM Plex Mono", ui-monospace, monospace;
}
.availcell .none { color:var(--faint); font-size:11px; }

/* ------------------------------------------------------------ side panel --- */

/* Panels sit beside the grid rather than over it, because their whole job is to
   be read against it - who else is in this slot, what this child did last
   month. A dialog covering the cell you just clicked answers the question by
   hiding the thing you asked it about. */
.sidepanel {
  position:fixed; top:64px; bottom:16px; width:min(430px, 46vw); z-index:90;
  background:var(--surface); border:1px solid var(--line); border-radius:13px;
  box-shadow:var(--shadow); display:flex; flex-direction:column; overflow:hidden;
}
.sidepanel.left  { left:16px; }
.sidepanel.right { right:16px; }

.sidepanel .panel-head {
  display:flex; align-items:flex-start; gap:12px; padding:13px 16px;
  border-bottom:1px solid var(--line); flex:none;
}
.sidepanel .panel-head h3 { margin:0; font-size:15px; font-weight:600; }
.sidepanel .panel-head .sub { font-size:11.5px; color:var(--muted); }
.sidepanel .panel-head .x {
  appearance:none; border:0; background:none; cursor:pointer; margin-left:auto;
  color:var(--muted); font-size:22px; line-height:1; padding:0 3px;
}
.sidepanel .panel-head .x:hover { color:var(--ink); }
.sidepanel .panel-body { overflow-y:auto; padding:14px 16px 18px; flex:1; }

@media (max-width: 760px) {
  /* No room to sit beside anything; become a sheet from the bottom. */
  .sidepanel, .sidepanel.left, .sidepanel.right {
    left:8px; right:8px; width:auto; top:auto; height:72vh; bottom:8px;
  }
}

/* ------------------------------------------------- panels: availability --- */

.availlist { display:flex; flex-direction:column; gap:7px; margin-bottom:14px; }
.availrow { display:grid; grid-template-columns:1fr auto auto; gap:6px; align-items:center; }
.availrow .tpill {
  color:#fff; font-size:11px; font-weight:600; padding:3px 10px; border-radius:999px;
  justify-self:start;
}
.availrow select, .availrow input { font-size:12px; padding:5px 8px; min-height:0; }
.availrow .note { grid-column:1 / -1; }

/* ------------------------------------------------------ panels: history --- */

.histhead { display:flex; align-items:center; gap:6px; margin-bottom:12px; flex-wrap:wrap; }
.histhead .grow { flex:1; }
.histhead .sub { font-size:11.5px; color:var(--muted); }
.histtiles { display:grid; grid-template-columns:repeat(3,1fr); gap:6px; margin-bottom:14px; }
.htile {
  background:var(--raised); border:1px solid var(--line); border-radius:8px;
  padding:8px 10px; display:flex; flex-direction:column;
}
.htile.warn { border-color:var(--wait); }
.htile .n { font-size:19px; font-weight:600; line-height:1.1; }
.htile.warn .n { color:var(--wait); }
.htile .l {
  font-size:9px; letter-spacing:.09em; text-transform:uppercase; color:var(--faint);
  font-family:"IBM Plex Mono", ui-monospace, monospace; margin-top:2px;
}
table.rows.hist td { padding:5px 7px; font-size:12px; }
table.rows.hist .dim { color:var(--faint); }
.linkbtn.more { margin-top:9px; font-size:12px; }

/* ----------------------------------------------------- panels: planners --- */

.plannedkid { border-bottom:1px solid var(--line-soft); padding:11px 0; }
.plannedkid:last-child { border-bottom:0; }
.pk-head { display:flex; align-items:center; gap:5px; flex-wrap:wrap; margin-bottom:7px; }
.pk-head .grow { flex:1; }
.pk-head .tpill { color:#fff; font-size:10px; font-weight:600; padding:1px 8px; border-radius:999px; }

.planwhen { display:flex; flex-wrap:wrap; gap:5px; margin-bottom:14px; }
.whenpill {
  display:inline-flex; align-items:center; gap:5px; font-size:11px;
  background:var(--sunken); border-radius:999px; padding:3px 10px;
  font-family:"IBM Plex Mono", ui-monospace, monospace;
}
.whenpill i { width:8px; height:8px; border-radius:50%; }

.addform { display:flex; flex-wrap:wrap; gap:5px; align-items:center; }
.addform input, .addform select {
  border:1px solid var(--line); background:var(--ground); color:var(--ink);
  border-radius:7px; padding:5px 8px; font:inherit; font-size:12px; min-height:0;
}
.addform .n { width:56px; font-family:"IBM Plex Mono", ui-monospace, monospace; }
.addform .tm { width:88px; font-family:"IBM Plex Mono", ui-monospace, monospace; }
.addform .note { flex:1 1 130px; }
.addform .btn { min-height:0; padding:5px 13px; font-size:12px; }
.addform .err { flex:1 1 100%; margin:4px 0 0; }

/* Clicking a child fades everyone else. Colour on one chip among four hundred
   is something you have to hunt for; the absence of colour everywhere else is
   not. The faded ones stay legible on purpose - the shape of the day is still
   worth seeing behind the answer. */
.focusbar {
  display:flex; align-items:center; gap:9px; margin-top:10px;
  background:var(--accent-bg); border:1px solid var(--accent);
  border-radius:var(--radius); padding:8px 13px; font-size:13px;
}
.focusbar .sub { color:var(--muted); font-size:12px; }
.focusbar .grow { flex:1; }

/* ------------------------------------------------------- editable grid --- */

/* Fields live in the row rather than behind a dialog, because this page is used
   to go DOWN a column - who has no phone number, which of these are unpaid -
   and a dialog per row turns one pass into eighty open-edit-close cycles. */
table.rows.edit td { padding:5px 7px; vertical-align:middle; }
table.rows.edit tbody tr { cursor:default; }
table.rows.edit tbody tr:hover td { background:transparent; }
table.rows.edit input, table.rows.edit select {
  border:1px solid var(--line); background:var(--ground); color:var(--ink);
  border-radius:7px; padding:5px 7px; font:inherit; font-size:12px;
  min-height:0; width:100%; min-width:92px;
}
table.rows.edit input[type="checkbox"] { width:auto; min-width:0; }
table.rows.edit input:focus, table.rows.edit select:focus {
  outline:2px solid var(--accent); outline-offset:-1px;
}
table.rows.edit input:disabled, table.rows.edit select:disabled {
  opacity:.65; cursor:default;
}
table.rows.edit .kidcell { white-space:nowrap; }
table.rows.edit .mid { text-align:center; }
table.rows.edit .amt { min-width:80px; text-align:right;
  font-family:"IBM Plex Mono", ui-monospace, monospace; }
table.rows.edit .tiny { width:58px; min-width:0; margin-left:5px; }
table.rows.edit .lastcell { white-space:nowrap; }
table.rows.edit .progress { min-width:170px; }

/* A row with unsaved edits, so it is obvious what Save is about to write. */
table.rows.edit tr.touched td { background:var(--accent-bg); }
table.rows.edit tr.touched .kidcell { box-shadow:inset 3px 0 0 var(--accent); }

.count { font-size:11.5px; color:var(--faint); }
.unsaved {
  font-size:12px; color:var(--wait); background:var(--wait-bg);
  padding:4px 11px; border-radius:999px; font-weight:500;
}
.toolbar .check {
  display:flex; align-items:center; gap:7px; font-size:12.5px; color:var(--muted);
}
.toolbar .check input { width:auto; }

/* --------------------------------------------------------- history page --- */

.panel.corrections { padding-bottom:6px; }
.corr-head { display:flex; align-items:baseline; gap:12px; flex-wrap:wrap; margin-bottom:10px; }
.corr-head h2 {
  margin:0; font-size:11px; letter-spacing:.11em; text-transform:uppercase;
  color:var(--faint); font-family:"IBM Plex Mono", ui-monospace, monospace;
}
.corr-head .sub { font-size:12px; color:var(--muted); margin-left:auto; }

table.rows.corr td { vertical-align:middle; }
table.rows.corr td .sub { display:block; font-size:11.5px; color:var(--muted); font-weight:400; }
table.rows.corr input {
  width:62px; text-align:center; border:1px solid var(--line);
  background:var(--ground); color:var(--ink); border-radius:7px;
  padding:6px 4px; font:inherit; font-size:14px;
  font-family:"IBM Plex Mono", ui-monospace, monospace;
}
table.rows.corr input:focus { outline:2px solid var(--accent); outline-offset:-1px; }
/* The counted number under the corrected one: a box showing 9 on its own does
   not say whether that is what the sessions add up to or what somebody decided. */
table.rows.corr .of {
  display:block; font-size:10px; color:var(--faint); margin-top:3px;
  font-family:"IBM Plex Mono", ui-monospace, monospace;
}

.wholine {
  display:flex; align-items:center; gap:8px; flex-wrap:wrap;
  margin:18px 0 12px; font-size:16px;
}
.wholine > b { font-size:19px; font-weight:600; }
.wholine .tpill { color:#fff; font-size:11px; font-weight:600; padding:2px 10px; border-radius:999px; }
.wholine .facts {
  font-size:12.5px; color:var(--muted);
  font-family:"IBM Plex Mono", ui-monospace, monospace;
}
.wholine .facts b { color:var(--ink); font-weight:600; }

.histmonths { display:grid; grid-template-columns:repeat(auto-fit,minmax(290px,1fr)); gap:12px; }
.histmonth {
  background:var(--surface); border:1px solid var(--line);
  border-radius:var(--radius); padding:12px 14px 14px;
}
.hm-head { display:flex; align-items:baseline; gap:10px; margin-bottom:9px; }
.hm-head .sub { margin-left:auto; font-size:11.5px; color:var(--faint); }
.hm-week, .hm-grid { display:grid; grid-template-columns:repeat(7,1fr); gap:4px; }
.hm-week span {
  font-size:9px; letter-spacing:.08em; text-transform:uppercase; color:var(--faint);
  font-family:"IBM Plex Mono", ui-monospace, monospace; text-align:center; padding-bottom:3px;
}

/* A day the child was due. The colour is the outcome, so the pattern of a term
   is legible without reading a single date. */
.hd {
  position:relative;
  display:flex; flex-direction:column; align-items:center; justify-content:center;
  min-height:42px; border-radius:7px; border:2px solid transparent;
  font-family:"IBM Plex Mono", ui-monospace, monospace;
}

/* Who took the session, in her own colour, one stripe per session that day.
   Cover and swaps are the thing people scan a year for, and a name is too big
   to print ninety times - a colour is not. */
.hd .hflag {
  position:absolute; top:0; left:0; right:0; height:3px;
  display:flex; gap:1px; border-radius:5px 5px 0 0; overflow:hidden;
}
.hd .hflag b { flex:1; background:var(--faint); }

.hd .rstag {
  position:absolute; right:2px; bottom:1px;
  font-size:8px; font-weight:700; font-style:normal; text-decoration:none;
  letter-spacing:.3px; color:var(--rs);
}
.hd.multi em { font-size:9px; letter-spacing:-.3px; }
.hd i { font-style:normal; font-size:11px; color:var(--muted); }
.hd em { font-style:normal; font-size:10px; font-weight:700; }
.hd.blank { border:0; }
.hd.none i { color:var(--faint); opacity:.55; }
.hd.done { border-color:var(--ok); background:var(--ok-bg); }
.hd.done i, .hd.done em { color:var(--ok); }
.hd.cx   { border-color:var(--wait); background:var(--wait-bg); }
.hd.cx i, .hd.cx em { color:var(--wait); }
.hd.ic   { border-color:var(--bad); background:var(--bad-bg); }
.hd.ic i, .hd.ic em { color:var(--bad); }
.hd.rs   { border-color:var(--rs); background:var(--rs-bg); }
.hd.rs i, .hd.rs em, .hd.rs .rstag { color:var(--rs); }
.hd.tent { border-style:dashed; border-color:var(--muted); }
.hd.open { border-color:var(--line); background:var(--raised); }
.hd.open i, .hd.open em { color:var(--muted); }

/* ------------------------------------------- planner: one child in full --- */

/* The whole point of this panel is deciding what to write for each child, so
   each one carries their own record rather than a status tag. */
.pk-counts {
  display:flex; align-items:center; gap:10px; margin-bottom:8px;
  font-size:11px; color:var(--faint);
  font-family:"IBM Plex Mono", ui-monospace, monospace;
}
.pk-counts b { color:var(--ink); font-size:12.5px; font-weight:600; margin-right:-6px; }
.pk-counts .span {
  margin-left:auto; background:var(--sunken); color:var(--muted);
  padding:1px 8px; border-radius:4px;
}

table.rows.pk-sess { margin-bottom:7px; }
table.rows.pk-sess td { padding:3px 6px; font-size:11.5px; border-bottom:0; }
table.rows.pk-sess tr:hover td { background:var(--raised); }
table.rows.pk-sess .dim { color:var(--faint); }

.plannedkid .hint { margin:0 0 8px; }
.plannedkid .linkbtn.more { display:block; margin:0 0 9px; font-size:11.5px; }
.addform .ended { width:78px; }
/* The day this panel was opened from, among the child's usual days. */
.whenpill.on { background:var(--accent-bg); color:var(--accent); font-weight:600; }
.vs {
  font-size:11px; letter-spacing:.09em; text-transform:uppercase; color:var(--faint);
  font-family:"IBM Plex Mono", ui-monospace, monospace;
}

/* The comparison pickers read as one control rather than two stray dates. */
.toolbar .dateinput { min-width:142px; }
#calSwap { padding:7px 11px; font-size:14px; line-height:1; }

/* A therapist taken from the plan rather than recorded. It is a good guess and
   must not look like a fact. */
td.guessed { color:var(--muted); }
.guess {
  margin-left:4px; font-size:9px; font-weight:700; color:var(--wait);
  background:var(--wait-bg); padding:0 4px; border-radius:3px; vertical-align:1px;
}
.panel.notice.thin { padding:11px 14px; }
.panel.notice.thin .lead { margin:0; font-size:12.5px; }
/* A package naming a different therapy from its therapist's. Legitimate, but
   worth seeing - it is usually a typo. */
td.mismatch input { border-color:var(--wait); }

/* Who gets the daily message. Reception opens this to answer "is everybody
   on?", which is a counting question, so the count sits in the bar and not at
   the bottom of a list of ninety. */
.whobar {
  display:flex; align-items:center; gap:8px; flex-wrap:wrap;
  padding-bottom:10px; margin-bottom:10px; border-bottom:1px solid var(--line);
}
.whobar .whocount { font-family:"IBM Plex Mono", ui-monospace, monospace; font-size:15px; }

.whogrid {
  display:grid; gap:2px 14px;
  grid-template-columns:repeat(auto-fill, minmax(215px, 1fr));
}
.whoitem {
  display:flex; align-items:center; gap:7px;
  padding:3px 5px; border-radius:6px; cursor:pointer; min-width:0;
}
.whoitem:hover { background:var(--raised); }
.whoitem input { margin:0; flex:none; }
.whoitem .whodot { width:9px; height:9px; border-radius:2px; flex:none; }
.whoitem .whoname {
  flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap;
}
.whoitem .whoth { font-size:11px; flex:none; max-width:82px;
  overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

/* Left out, and saying so plainly - the tick alone is easy to miss in ninety. */
.whoitem.off .whoname { color:var(--muted); text-decoration:line-through; }
.whoitem.off .whodot { opacity:.3; }
.whoitem.off .whoth { opacity:.45; }

/* A heading between groups of panels, for a tab that holds two subjects -
   your own login, and everybody else's. */
.sechead {
  margin:18px 2px 8px; font-size:13px; font-weight:700;
  text-transform:uppercase; letter-spacing:.06em; color:var(--muted);
}
.sechead:first-child { margin-top:2px; }
