/* =====================================================================
   Client Portal -- clients / calendar / session notes dashboard.

   Clinician screen (body.mode-clinician): cool-mist page, white cards with
   a 1px line and a soft shadow, navy ink, flat controls, and ONE action
   colour (orange, --sx-primary). Blue is data only; colour elsewhere appears
   only where it means something (IEP status chips, the "Saved" chip).
   Every value comes from the --sx-* tokens in UnifiedAppShell.css. The
   reference layout is the #portal screen of tools/design-preview.

   Layout: three columns (clients | calendar + note | snapshot + goals) on
   wide screens, two columns with the right column full width below on
   medium screens, one column on phones.
   ===================================================================== */

:root {
  --cp-danger: #b42318;
  --cp-danger-line: #f0b9b0;
  --cp-danger-tint: #fff4f2;
}

/* ----------------------------- Page shell ------------------------------ */
/* The clinician page has no outer card or vignette: the top bar and the
   cards sit directly on the cool-mist background. */
body.page-notes.mode-clinician::before,
body.page-notes.mode-clinician::after {
  display: none;
}

body.page-notes.mode-clinician .main-content {
  padding: 0;
}

body.page-notes .notes-shell {
  display: block;
  max-width: none;
  margin: 0;
  padding: 0;
  overflow: visible;
}

body.page-notes .notes-shell::before,
body.page-notes .notes-shell::after {
  display: none;
}

.calendar-notes-app {
  display: block;
  min-height: 0;
  color: var(--sx-ink);
  font-family: var(--sx-font-body);
  font-size: 15px;
  line-height: 1.5;
}

body.page-notes .calendar-notes-main {
  padding: 0;
  display: block;
}

.calendar-notes-app h1,
.calendar-notes-app h2,
.calendar-notes-app h3,
.cn-modal-title,
.cn-snapshot-title {
  font-family: var(--sx-font-display);
  color: var(--sx-ink);
  letter-spacing: -0.01em;
}

.calendar-notes-app button,
.cn-overlay button,
.cn-snapshot-overlay button {
  font-family: inherit;
}

:where(.calendar-notes-app, .cn-overlay, .cn-snapshot-overlay) :focus-visible {
  outline: 3px solid var(--sx-focus);
  outline-offset: 2px;
}

/* ------------------------------- Top bar -------------------------------- */
.cp-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 32px;
  background: var(--sx-surface);
  border-bottom: 1px solid var(--sx-line);
}

.cp-title {
  margin: 0;
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
}

.cp-date {
  margin: 2px 0 0;
  color: var(--sx-ink-3);
  font-size: 13.5px;
}

.cp-topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.cp-search {
  position: relative;
}

.cp-search svg {
  position: absolute;
  left: 12px;
  top: 50%;
  width: 18px;
  height: 18px;
  transform: translateY(-50%);
  color: var(--sx-ink-3);
  pointer-events: none;
}

.cp-search .cn-input {
  width: 240px;
  min-height: 40px;
  padding: 8px 12px 8px 38px;
}

.cp-icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------- Dashboard grid ------------------------------ */
.notes-layout {
  display: grid;
  grid-template-columns: clamp(268px, 21vw, 300px) minmax(0, 1fr) clamp(300px, 24vw, 340px);
  gap: 20px;
  align-items: start;
  width: 100%;
  max-width: 1760px;
  margin: 0 auto;
  padding: 28px 32px 56px;
  box-sizing: border-box;
}

.notes-layout:has(.client-panel.is-collapsed) {
  grid-template-columns: 64px minmax(0, 1fr) clamp(300px, 24vw, 340px);
}

.client-panel {
  grid-column: 1;
}

.calendar-notes-column {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

.cp-side {
  grid-column: 3;
  display: grid;
  gap: 20px;
  min-width: 0;
}

/* --------------------------- Shared card look ---------------------------- */
.client-panel,
.calendar-container,
.notes-container,
.cp-card {
  background: var(--sx-surface);
  border: 1px solid var(--sx-line);
  border-radius: var(--sx-radius);
  box-shadow: var(--sx-shadow);
  color: var(--sx-ink);
  box-sizing: border-box;
  min-width: 0;
}

.cp-card-h,
.client-panel-head,
.notes-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.cp-card-h h3,
.client-panel-title,
#notesTitle {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  line-height: 1.25;
}

.cp-card-h {
  padding: 18px 20px 0;
}

.cp-card-b {
  padding: 16px 20px 20px;
}

/* Status chips: colour only where it means something. */
.cp-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--sx-t-blue);
  color: var(--sx-t-blue-ink);
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
  white-space: nowrap;
}

.cp-chip--green { background: var(--sx-t-green); color: var(--sx-t-green-ink); }
.cp-chip--amber { background: var(--sx-t-amber); color: var(--sx-t-amber-ink); }
.cp-chip--orange { background: var(--sx-t-orange); color: var(--sx-t-orange-ink); }
.cp-chip--grey { background: #eef1f7; color: var(--sx-ink-2); }

/* ------------------------------ Buttons -------------------------------- */
/* Flat: no gradient, no glow, no lift. Hover is a slightly darker fill. */
.cn-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 42px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--sx-radius-sm);
  background: var(--sx-primary);
  color: #fff;
  font-family: var(--sx-font-display);
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
  white-space: nowrap;
  cursor: pointer;
  box-sizing: border-box;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.cn-btn:hover:not(:disabled) {
  background: var(--sx-primary-hover);
}

.cn-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.cn-btn--primary {
  background: var(--sx-primary);
  color: #fff;
}

.cn-btn--ghost {
  background: var(--sx-surface);
  border-color: var(--sx-line-strong);
  color: var(--sx-ink);
}

.cn-btn--ghost:hover:not(:disabled) {
  background: var(--sx-surface-2);
}

.cn-btn--danger {
  background: var(--sx-surface);
  border-color: var(--cp-danger-line);
  color: var(--cp-danger);
}

.cn-btn--danger:hover:not(:disabled) {
  background: var(--cp-danger-tint);
}

/* Quiet text-style action (e.g. "Edit" in a card header). */
.cn-btn--quiet {
  background: transparent;
  border-color: transparent;
  color: var(--sx-primary-ink);
}

.cn-btn--quiet:hover:not(:disabled) {
  background: var(--sx-primary-tint);
}

.cn-btn--compact {
  min-height: 34px;
  padding: 6px 12px;
  font-size: 13px;
}

.cn-btn--block {
  display: flex;
  width: 100%;
}

.cp-btn-icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ------------------------- Clients card -------------------------------- */
.client-panel {
  padding: 18px 20px 20px;
}

.client-panel-head {
  margin-bottom: 12px;
}

.client-panel-title {
  margin-right: auto;
}

.client-panel-toggle {
  flex: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--sx-line-strong);
  border-radius: 9px;
  background: var(--sx-surface);
  color: var(--sx-ink-2);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.12s ease;
}

.client-panel-toggle:hover {
  background: var(--sx-surface-2);
}

.client-panel-body {
  display: block;
}

/* Collapsed state: a narrow strip that only carries the expand button. */
.client-panel.is-collapsed {
  padding: 12px 10px;
}

.client-panel.is-collapsed .client-panel-head {
  justify-content: center;
  margin-bottom: 0;
}

.client-panel.is-collapsed .client-panel-title,
.client-panel.is-collapsed #clientCount,
.client-panel.is-collapsed .client-panel-body {
  display: none;
}

#clientList {
  list-style: none;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
  width: 100%;
  max-height: min(62vh, 620px);
  margin: 0 0 16px;
  padding: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

#clientList li[hidden] {
  display: none !important;
}

/* Client row: avatar, name + one-line summary, quiet delete action. */
#clientList li.client-unfiled-member,
#clientList li.client-folder-member {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px;
  border: 0;
  border-radius: var(--sx-radius-sm);
  background: transparent;
  color: var(--sx-ink);
  cursor: pointer;
  transition: background-color 0.12s ease;
}

#clientList li.client-unfiled-member:hover,
#clientList li.client-folder-member:hover {
  background: var(--sx-surface-2);
}

#clientList li.client-unfiled-member.active,
#clientList li.client-folder-member.active {
  background: var(--sx-primary-tint);
}

.client-avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--sx-t-blue);
  color: var(--sx-t-blue-ink);
  font-family: var(--sx-font-display);
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
}

.client-row-text {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-width: 0;
}

#clientList li span[data-client-id] {
  display: block;
  max-width: 100%;
  overflow: hidden;
  color: var(--sx-ink);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
}

.client-row-sub {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 2px 8px;
  min-width: 0;
  color: var(--sx-ink-3);
  font-size: 12.5px;
  line-height: 1.4;
}

.client-row-sub-text {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.client-row-sub .cp-chip {
  padding: 1px 8px;
  font-size: 11px;
}

/* Always available to keyboard and touch users; shown on hover otherwise so
   the list stays quiet. */
#clientList li .client-row-delete-btn {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--sx-ink-3);
  font-size: 0.85rem;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease, background-color 0.12s ease, color 0.12s ease;
}

#clientList li:hover .client-row-delete-btn,
#clientList li:focus-within .client-row-delete-btn,
#clientList li.active .client-row-delete-btn {
  opacity: 1;
}

#clientList li .client-row-delete-btn:hover,
#clientList li .client-row-delete-btn:focus-visible {
  background: var(--cp-danger-tint);
  color: var(--cp-danger);
}

@media (hover: none) {
  #clientList li .client-row-delete-btn {
    opacity: 1;
  }
}

/* Folder headers: small-caps group labels (still click-to-collapse). */
#clientList li.client-folder-group {
  position: relative;
  margin: 12px 0 4px;
  padding: 4px 26px 4px 10px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--sx-ink-3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  line-height: 1.4;
  text-transform: uppercase;
  cursor: pointer;
}

#clientList li.client-folder-group.is-first-folder {
  margin-top: 16px;
}

#clientList li.client-folder-group:hover {
  background: var(--sx-surface-2);
  color: var(--sx-ink-2);
}

#clientList li.client-folder-group::after {
  content: '\25BE';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.8rem;
  transition: transform 0.12s ease;
}

#clientList li.client-folder-group.is-collapsed::after {
  transform: translateY(-50%) rotate(-90deg);
}

#clientList li.client-list-empty {
  padding: 14px 10px;
  color: var(--sx-ink-3);
  font-size: 13.5px;
  text-align: center;
}

.client-panel-actions {
  display: grid;
  gap: 8px;
}

.edit-client-btn {
  display: block;
  width: 100%;
  margin: 0;
  padding: 6px 12px;
  min-height: 34px;
  border: 1px solid var(--sx-line-strong);
  border-radius: var(--sx-radius-sm);
  background: var(--sx-surface);
  color: var(--sx-ink);
  font-family: var(--sx-font-display);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color 0.12s ease;
}

.edit-client-btn:hover {
  background: var(--sx-surface-2);
}

.edit-client-btn.active-edit {
  background: var(--sx-primary-tint);
  border-color: var(--sx-primary);
  color: var(--sx-primary-ink);
}

/* -------------------- Archived clients panel --------------------- */
.archived-clients-panel {
  margin: 12px 0 0;
  padding: 12px;
  border-radius: var(--sx-radius-sm);
  border: 1px solid var(--sx-line);
  background: var(--sx-surface-2);
}

.archived-clients-panel[hidden] {
  display: none !important;
}

.archived-clients-head,
.cn-folder-client-group,
.cn-field-label--inline {
  color: var(--sx-ink-3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  line-height: 1.4;
  text-transform: uppercase;
}

.archived-clients-head {
  margin-bottom: 8px;
  padding: 0 2px;
}

.archived-client-list {
  display: grid;
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
}

.archived-client-row,
.cn-folder-client-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 11px;
  border-radius: var(--sx-radius-sm);
  border: 1px solid var(--sx-line);
  background: var(--sx-surface);
}

.archived-client-name,
.cn-folder-client-name {
  min-width: 0;
  color: var(--sx-ink);
  font-size: 0.88rem;
  font-weight: 600;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.cn-btn.archived-client-restore-btn {
  flex: none;
  min-height: 30px;
  padding: 4px 12px;
  font-size: 12.5px;
}

.archived-clients-empty {
  padding: 8px 4px;
  color: var(--sx-ink-3);
  font-size: 0.85rem;
}

.cn-modal-sub--target {
  margin-top: -8px;
  color: var(--sx-ink);
  font-weight: 700;
  word-break: break-word;
}

.cn-folder-client-list {
  display: grid;
  gap: 8px;
  max-height: 230px;
  overflow: auto;
  padding: 12px;
  border-radius: var(--sx-radius-sm);
  border: 1px solid var(--sx-line);
  background: var(--sx-surface-2);
}

.cn-folder-client-group {
  margin-top: 4px;
  padding: 2px 4px;
}

.cn-folder-client-group:first-child {
  margin-top: 0;
}

.cn-folder-client-item.is-archived {
  background: var(--sx-surface-2);
}

.cn-folder-client-item.is-archived .cn-folder-client-name {
  color: var(--sx-ink-2);
}

.cn-folder-client-item input,
.cn-switch-row input,
.th-word-row input,
.th-activity input,
.th-picture-toggle input {
  accent-color: var(--sx-primary);
}

.cn-folder-client-meta {
  color: var(--sx-ink-3);
  font-size: 0.78rem;
  font-weight: 600;
  line-height: 1.4;
}

/* --------------------------- Calendar card ---------------------------- */
.calendar-container {
  width: 100%;
  padding: 18px 20px 20px;
}

.calendar-selector {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.calendar-month-label {
  font-family: var(--sx-font-display);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--sx-ink);
}

.calendar-nav-group {
  display: flex;
  gap: 6px;
}

.calendar-nav-btn {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--sx-line-strong);
  border-radius: 9px;
  background: var(--sx-surface);
  color: var(--sx-ink-2);
  cursor: pointer;
  transition: background-color 0.12s ease;
}

.calendar-nav-btn:hover {
  background: var(--sx-surface-2);
}

.calendar-nav-btn svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.calendar-table {
  width: calc(100% + 12px);
  border-collapse: separate;
  border-spacing: 6px;
  table-layout: fixed;
  margin: 0 -6px;
}

.calendar-table th {
  padding: 4px 0;
  color: var(--sx-ink-3);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.06em;
}

.calendar-table td {
  padding: 0;
  text-align: center;
}

.calendar-day-box {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 1.15;
  box-sizing: border-box;
  border: 1px solid var(--sx-line);
  border-radius: var(--sx-radius-sm);
  background: var(--sx-surface);
  color: var(--sx-ink);
  font-size: 14px;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.calendar-day-box:hover {
  background: var(--sx-surface-2);
  border-color: var(--sx-line-strong);
}

/* A small dot marks a day that has a note. */
.calendar-day-box.has-note::after {
  content: '';
  position: absolute;
  bottom: 7px;
  left: 50%;
  width: 5px;
  height: 5px;
  margin-left: -2.5px;
  border-radius: 50%;
  background: var(--sx-primary);
}

/* Today = solid orange. */
.calendar-day-box.is-today {
  border-color: var(--sx-primary);
  background: var(--sx-primary);
  color: #fff;
  font-weight: 700;
}

.calendar-day-box.is-today:hover {
  background: var(--sx-primary-hover);
  border-color: var(--sx-primary-hover);
}

.calendar-day-box.is-today.has-note::after {
  background: #fff;
}

/* Selected day: tinted fill and an orange edge. */
.calendar-day-box.is-selected:not(.is-today) {
  border: 2px solid var(--sx-primary);
  background: var(--sx-primary-tint);
  color: var(--sx-ink);
  font-weight: 700;
}

.calendar-day-box.is-selected.is-today {
  box-shadow: 0 0 0 2px var(--sx-surface), 0 0 0 4px var(--sx-primary);
}

.calendar-empty {
  padding: 36px 16px;
  text-align: center;
  color: var(--sx-ink-3);
  font-size: 0.95rem;
}

/* --------------------------- Session note card ---------------------------- */
.notes-container {
  display: flex;
  flex-direction: column;
  width: 100%;
  padding: 18px 20px 20px;
}

.notes-header-row {
  margin-bottom: 14px;
}

#notesTitle .cp-note-for {
  margin-left: 8px;
  color: var(--sx-ink-3);
  font-size: 13.5px;
  font-weight: 500;
}

/* "Saved" chip: visible when the note is stored, amber while typing. */
.notes-autosave {
  display: none;
  flex: none;
  background: var(--sx-t-green);
  color: var(--sx-t-green-ink);
}

.notes-autosave.is-visible {
  display: inline-flex;
}

.notes-autosave.is-saving {
  background: var(--sx-t-amber);
  color: var(--sx-t-amber-ink);
}

.notes-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.notes-tool-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 6px 12px;
  border: 1px solid var(--sx-line-strong);
  border-radius: var(--sx-radius-sm);
  background: var(--sx-surface);
  color: var(--sx-ink);
  font-family: var(--sx-font-display);
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  transition: background-color 0.12s ease;
}

.notes-tool-btn svg {
  width: 16px;
  height: 16px;
  flex: none;
}

.notes-tool-btn .notes-tool-caret {
  width: 13px;
  height: 13px;
  margin-left: -2px;
  opacity: 0.7;
}

.notes-tool-btn:hover:not(:disabled) {
  background: var(--sx-surface-2);
}

.notes-tool-btn[aria-expanded="true"] {
  background: var(--sx-surface-2);
}

.notes-tool-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.notes-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.notes-tool-btn--icon {
  padding: 6px 9px;
  color: var(--sx-ink-2);
}

.notes-tool-wrap {
  position: relative;
}

.notes-macro-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 40;
  width: 340px;
  max-width: min(360px, 80vw);
  max-height: 340px;
  overflow-y: auto;
  padding: 6px;
  border-radius: var(--sx-radius-sm);
  background: var(--sx-surface);
  border: 1px solid var(--sx-line);
  box-shadow: 0 12px 32px rgba(11, 27, 70, 0.16);
}

.notes-macro-menu[hidden] {
  display: none;
}

.notes-macro-group {
  padding: 9px 10px 4px;
  color: var(--sx-ink-3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.notes-macro-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 11px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--sx-ink);
  font-family: inherit;
  font-size: 0.88rem;
  line-height: 1.4;
  cursor: pointer;
  transition: background-color 0.12s ease;
}

.notes-macro-item:hover {
  background: var(--sx-surface-2);
}

#notesArea {
  flex: 1 1 auto;
  width: 100%;
  min-height: 260px;
  padding: 12px 14px;
  border: 1px solid var(--sx-line-strong);
  border-radius: var(--sx-radius-sm);
  background: var(--sx-surface);
  color: var(--sx-ink);
  font-family: var(--sx-font-body);
  font-size: 15px;
  line-height: 1.6;
  resize: vertical;
  box-sizing: border-box;
}

#notesArea::placeholder {
  color: #6b7898;
}

#notesArea:focus {
  outline: 3px solid var(--sx-focus);
  outline-offset: 0;
  border-color: var(--sx-royal);
}

#notesArea:disabled {
  background: var(--sx-surface-2);
  cursor: not-allowed;
}

.notes-container::before {
  display: none;
}

/* ----------------- Right column: snapshot + goals ----------------- */
.cp-snap {
  display: grid;
  gap: 10px;
  margin: 0 0 14px;
  font-size: 13.5px;
}

.cp-snap-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding-bottom: 9px;
  border-bottom: 1px solid var(--sx-line);
}

.cp-snap-row:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.cp-snap-label {
  flex: none;
  color: var(--sx-ink-3);
}

.cp-snap-value {
  min-width: 0;
  color: var(--sx-ink);
  font-weight: 600;
  text-align: right;
  overflow-wrap: anywhere;
}

.cp-snap-value.is-empty {
  color: var(--sx-ink-3);
  font-weight: 400;
}

.cp-side-empty {
  margin: 0 0 14px;
  color: var(--sx-ink-3);
  font-size: 13.5px;
}

.cp-side-empty--flush {
  margin-bottom: 0;
}

.cp-snap-value .cp-chip {
  margin-left: 8px;
  vertical-align: 1px;
}

/* Dormant per-row edit actions (Rename / Delete) sit under the row. */
#clientList li:has(.client-row-actions) {
  flex-wrap: wrap;
}

.client-row-actions {
  display: flex;
  flex: 1 0 100%;
  gap: 8px;
  padding: 2px 0 2px 48px;
}

.cp-goal-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cp-goal-item {
  position: relative;
  padding-left: 14px;
  font-size: 13.5px;
  font-weight: 600;
  line-height: 1.45;
  overflow-wrap: anywhere;
}

.cp-goal-item::before {
  content: '';
  position: absolute;
  left: 0;
  top: 0.55em;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--sx-blue-500);
}

.cp-goal-more {
  margin: 12px 0 0;
  color: var(--sx-ink-3);
  font-size: 12.5px;
}

/* --------------------------- Forms / shared modal parts ------------------ */
.cn-field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.cn-switch-row {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-top: 10px;
  color: var(--sx-ink-2);
  font-weight: 600;
}

.cn-check-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px 12px;
  margin-top: 4px;
}

.cn-photo-preview,
.cn-snapshot-photo {
  width: 92px;
  height: 92px;
  border-radius: var(--sx-radius-sm);
  border: 1px solid var(--sx-line);
  object-fit: cover;
  background: var(--sx-surface-2);
}

.cn-snapshot-photo {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--sx-ink-3);
  font-size: 0.8rem;
  overflow: hidden;
}

.cn-snapshot-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.cn-wizard-step[hidden] {
  display: none !important;
}

/* ---------------------- Snapshot (read-only) modal ---------------------- */
.cn-snapshot-overlay {
  position: fixed;
  inset: 0;
  z-index: 4000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 22px;
  background: rgba(7, 23, 81, 0.55);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.cn-snapshot-modal {
  width: min(760px, 100%);
  max-height: calc(100dvh - 44px);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
  border-radius: var(--sx-radius);
  border: 1px solid var(--sx-line);
  background: var(--sx-surface);
  box-shadow: 0 24px 60px rgba(7, 23, 81, 0.28);
  color: var(--sx-ink);
  box-sizing: border-box;
}

.cn-snapshot-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.cn-snapshot-title-wrap {
  min-width: 0;
}

.cn-snapshot-title {
  margin: 0 0 4px;
  font-size: clamp(1.15rem, 2vw, 1.4rem);
}

.cn-snapshot-subtitle {
  color: var(--sx-ink-3);
  font-size: 0.92rem;
}

.cn-snapshot-scroll {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.cn-snapshot-row {
  border: 1px solid var(--sx-line);
  border-radius: var(--sx-radius-sm);
  padding: 12px 14px;
  background: var(--sx-surface-2);
}

.cn-snapshot-row-label,
.cn-snapshot-field-label {
  margin-bottom: 4px;
  color: var(--sx-ink-3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.cn-snapshot-row-value {
  color: var(--sx-ink);
  line-height: 1.45;
}

.cn-snapshot-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--sx-line);
  border-radius: var(--sx-radius);
  background: var(--sx-surface);
}

.cn-snapshot-card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--sx-line);
}

.cn-snapshot-card-badge {
  padding: 2px 9px;
  border-radius: 999px;
  background: #eef1f7;
  color: var(--sx-ink-2);
  font-size: 11.5px;
  font-weight: 600;
}

.cn-snapshot-card-head h4 {
  margin: 0;
  color: var(--sx-ink);
  font-family: var(--sx-font-display);
  font-size: 1rem;
  font-weight: 700;
}

.cn-snapshot-card-body {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.cn-snapshot-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 11px 13px;
  border-radius: var(--sx-radius-sm);
  border: 1px solid var(--sx-line);
  background: var(--sx-surface-2);
}

.cn-snapshot-field.is-full-width {
  grid-column: 1 / -1;
}

.cn-snapshot-field-label {
  margin-bottom: 0;
}

.cn-snapshot-field-val {
  color: var(--sx-ink);
  font-size: 0.92rem;
  line-height: 1.6;
}

.cn-clinical-list {
  margin: 4px 0 0;
  padding-left: 18px;
  list-style-type: disc;
}

.cn-clinical-list li {
  margin-bottom: 4px;
  line-height: 1.5;
}

.cn-clinical-list li:last-child {
  margin-bottom: 0;
}

.cn-snapshot-empty {
  grid-column: 1 / -1;
  padding: 18px;
  border: 1px dashed var(--sx-line-strong);
  border-radius: var(--sx-radius-sm);
  background: var(--sx-surface-2);
  color: var(--sx-ink-2);
  text-align: center;
}

/* ------------------------------ Overlays ------------------------------- */
.cn-overlay {
  position: fixed;
  inset: 0;
  z-index: 3500; /* above the phone sidebar drawer (3000) and its scrim (2900) */
  display: none;
  align-items: center;
  justify-content: center;
  padding: 22px;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: rgba(7, 23, 81, 0.55);
}

/* With the sidebar docked (tablet + desktop) centre the modal in the visible content area */
@media (min-width: 701px) {
  .cn-overlay {
    left: var(--sidebar-width, 140px);
    width: calc(100vw - var(--sidebar-width, 140px));
  }

  .cn-modal {
    max-width: calc(100vw - var(--sidebar-width, 140px) - 32px);
    margin: 0 auto;
  }
}

/* iPad / phone: 16px inputs stop Safari's focus zoom that shifts the modal sideways */
@media (max-width: 1024px) {
  .cn-modal {
    width: min(540px, calc(100vw - 24px));
  }

  .cn-input,
  .cn-textarea,
  .cn-select,
  select.cn-input {
    font-size: 16px !important;
    scroll-margin-top: 24px;
  }
}

.cn-overlay.is-open {
  display: flex;
}

.cn-modal {
  width: min(540px, calc(100vw - 24px));
  max-height: calc(100dvh - 28px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 28px 28px 24px;
  border-radius: var(--sx-radius);
  background: var(--sx-surface);
  border: 1px solid var(--sx-line);
  box-shadow: 0 24px 60px rgba(7, 23, 81, 0.28);
  color: var(--sx-ink);
  box-sizing: border-box;
}

.cn-modal--sm {
  width: min(380px, 100%);
  text-align: center;
}

.cn-modal--folder {
  width: min(560px, 100%);
  text-align: left;
}

.cn-modal--wide {
  width: min(680px, 100%);
}

.cn-modal-title {
  margin: 0 0 4px;
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.25;
}

.cn-modal-title--danger {
  color: var(--cp-danger);
}

.cn-modal-sub {
  margin: 0 0 16px;
  color: var(--sx-ink-2);
  font-size: 0.9rem;
  line-height: 1.55;
}

.cn-field-label {
  display: block;
  margin: 12px 0 4px;
  color: var(--sx-ink-2);
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.4;
}

.cn-field-label--inline {
  margin: 0;
}

.cn-input,
.cn-textarea {
  width: 100%;
  min-height: 42px;
  padding: 10px 12px;
  border: 1px solid var(--sx-line-strong);
  border-radius: var(--sx-radius-sm);
  background: var(--sx-surface);
  color: var(--sx-ink);
  font-family: inherit;
  font-size: 0.95rem;
  box-sizing: border-box;
  transition: border-color 0.12s ease;
}

select.cn-input {
  appearance: none;
  padding-right: 40px;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--sx-ink-2) 50%),
    linear-gradient(135deg, var(--sx-ink-2) 50%, transparent 50%);
  background-position:
    calc(100% - 19px) calc(50% - 2px),
    calc(100% - 13px) calc(50% - 2px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

select.cn-input[multiple] {
  padding-right: 12px;
  background-image: none;
}

.cn-input option {
  color: var(--sx-ink);
  background: var(--sx-surface);
}

.cn-textarea {
  resize: vertical;
  line-height: 1.5;
}

.cn-input::placeholder,
.cn-textarea::placeholder {
  color: #6b7898;
}

.cn-input:focus,
.cn-textarea:focus {
  outline: 3px solid var(--sx-focus);
  outline-offset: 0;
  border-color: var(--sx-royal);
}

.cn-error {
  margin-top: 10px;
  color: var(--cp-danger);
  font-size: 0.88rem;
}

.cn-modal-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin-top: 18px;
}

.cn-modal-actions--tight {
  margin-top: 12px;
  justify-content: flex-start;
  flex-wrap: wrap;
}

.cn-folder-panel {
  margin-top: 14px;
  padding: 16px;
  border-radius: var(--sx-radius);
  border: 1px solid var(--sx-line);
  background: var(--sx-surface);
}

.cn-folder-panel--list {
  background: var(--sx-surface-2);
}

.cn-folder-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.cn-switch-row--panel {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: var(--sx-radius-sm);
  border: 1px solid var(--sx-line);
  background: var(--sx-surface-2);
}

/* ----------------------- Take-Home Builder ----------------------- */
/* The builder overlay uses the same clinician chrome as every other modal:
   white card, navy text, orange primary, flat chips. */
.th-meta {
  display: flex;
  gap: 12px;
  margin: 4px 0 10px;
}

.th-meta-item {
  flex: 1 1 0;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--sx-line);
  border-radius: var(--sx-radius-sm);
  background: var(--sx-surface-2);
}

.th-meta-label {
  display: block;
  margin-bottom: 2px;
  color: var(--sx-ink-3);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.th-meta-value {
  color: var(--sx-ink);
  font-size: 0.96rem;
  font-weight: 600;
  word-break: break-word;
}

.th-templates {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 4px 0 16px;
}

.th-template-btn {
  padding: 7px 12px;
  border-radius: var(--sx-radius-sm);
  border: 1px solid var(--sx-line-strong);
  background: var(--sx-surface);
  color: var(--sx-ink);
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.th-template-btn:hover {
  background: var(--sx-surface-2);
}

.th-template-btn.is-active {
  background: var(--sx-primary-tint);
  border-color: var(--sx-primary);
  color: var(--sx-primary-ink);
}

.th-activities {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 4px;
}

.th-activity {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 10px 12px;
  border: 1px solid var(--sx-line);
  border-radius: var(--sx-radius-sm);
  background: var(--sx-surface);
  color: var(--sx-ink-2);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.12s ease, border-color 0.12s ease;
}

.th-activity:hover {
  background: var(--sx-surface-2);
  border-color: var(--sx-line-strong);
  color: var(--sx-ink);
}

.th-activity input {
  width: 17px;
  height: 17px;
  flex: none;
  cursor: pointer;
}

.th-activity:has(input:checked) {
  background: var(--sx-primary-tint);
  border-color: var(--sx-primary);
  color: var(--sx-ink);
}

.th-articulation-builder {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--sx-line);
  border-radius: var(--sx-radius-sm);
  background: var(--sx-surface-2);
}

.th-articulation-head,
.th-word-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.th-help {
  margin-top: 3px;
  color: var(--sx-ink-3);
  font-size: 0.82rem;
  line-height: 1.4;
}

.th-word-controls {
  margin-top: 10px;
}

.th-word-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(176px, 1fr));
  gap: 8px;
  max-height: 220px;
  overflow-y: auto;
  margin-top: 10px;
  padding-right: 4px;
}

.th-word-row {
  display: grid;
  grid-template-columns: auto 52px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  padding: 8px 9px;
  border: 1px solid var(--sx-line);
  border-radius: var(--sx-radius-sm);
  color: var(--sx-ink);
  background: var(--sx-surface);
  font-size: 0.9rem;
}

.th-word-row > span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.th-word-picture {
  width: 52px;
  height: 52px;
  border-radius: 7px;
  background: var(--sx-surface);
  object-fit: contain;
}

.th-word-picture[hidden] {
  display: block;
  visibility: hidden;
}

.th-word-star {
  border: none;
  background: transparent;
  color: var(--sx-ink-3);
  font-size: 1.05rem;
  cursor: pointer;
}

.th-word-star.is-starred {
  color: var(--sx-primary);
}

.th-selected-block {
  margin-top: 12px;
}

.th-selected-words {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  min-height: 30px;
}

.th-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px 4px 11px;
  border-radius: 999px;
  background: var(--sx-t-blue);
  border: 1px solid transparent;
  color: var(--sx-t-blue-ink);
  font-size: 0.82rem;
  font-weight: 600;
}

.th-chip.is-starred {
  background: var(--sx-primary-tint);
  border-color: var(--sx-primary);
  color: var(--sx-primary-ink);
}

.th-chip-remove {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: rgba(11, 27, 70, 0.1);
  color: inherit;
  font-size: 0.8rem;
  line-height: 1;
  cursor: pointer;
}

.th-chip-remove:hover {
  background: rgba(11, 27, 70, 0.2);
}

.th-picture-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  color: var(--sx-ink-2);
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}

.th-picture-toggle input {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

@media (max-width: 520px) {
  .th-activities {
    grid-template-columns: 1fr;
  }
  .th-meta {
    flex-direction: column;
  }
}

/* --------------------------- Responsive -------------------------------- */
/* Medium screens: clients + calendar/note, with the client details spread
   across the full width below. */
@media (max-width: 1359px) {
  .notes-layout,
  .notes-layout:has(.client-panel.is-collapsed) {
    grid-template-columns: clamp(240px, 28vw, 300px) minmax(0, 1fr);
  }
  .notes-layout:has(.client-panel.is-collapsed) {
    grid-template-columns: 64px minmax(0, 1fr);
  }
  .cp-side {
    grid-column: 1 / -1;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }
  .cp-side > .cn-btn {
    grid-column: 1 / -1;
  }
}

/* Phone (the sidebar is replaced by the floating menu button): leave room
   for that button beside the title; the search row wraps below and starts
   back at the page edge. */
@media (max-width: 700px) {
  .cp-topbar {
    flex-wrap: wrap;
    padding: 14px 16px 14px 76px;
    min-height: 76px;
  }
  .cp-topbar-title {
    flex: 1 1 auto;
    min-width: 0;
  }
  .cp-topbar-actions {
    flex: 1 1 100%;
    margin-left: -60px;
  }
}

/* Stack the page into one column whenever the space beside the sidebar is
   too narrow for side-by-side panels. The tablet rail (701-1024px) takes
   140px, so an iPad in portrait (768-834px) leaves only 628-694px. */
@media (max-width: 900px) {
  .cp-search {
    flex: 1 1 auto;
    min-width: 0;
  }
  .cp-search .cn-input {
    width: 100%;
  }
  .notes-layout,
  .notes-layout:has(.client-panel.is-collapsed) {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 16px 16px 40px;
  }
  .client-panel,
  .calendar-notes-column,
  .cp-side {
    grid-column: 1;
  }
  .cp-side {
    grid-template-columns: 1fr;
  }
  #clientList {
    max-height: 320px;
  }
  .client-panel.is-collapsed {
    padding: 10px 14px;
  }
  .client-panel.is-collapsed .client-panel-head {
    justify-content: flex-start;
  }
  .client-panel.is-collapsed .client-panel-title {
    display: block;
  }
  .calendar-container,
  .notes-container {
    padding: 16px;
  }
  .notes-container {
    min-height: 0;
  }
  #notesArea {
    min-height: 220px;
  }

  .cn-overlay {
    align-items: flex-start;
    /* clear the fixed hamburger button that stays above the overlay on phones */
    padding: calc(66px + env(safe-area-inset-top, 0px)) 8px calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .cn-modal {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 76px);
    padding: 18px 14px 14px;
  }

  .cn-modal-actions {
    position: sticky;
    bottom: 0;
    padding-top: 10px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0), #fff 35%);
  }

  .cn-field-grid {
    grid-template-columns: 1fr;
  }

  .cn-snapshot-overlay {
    align-items: flex-start;
    padding: 10px 8px calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .cn-snapshot-modal {
    width: calc(100vw - 16px);
    max-height: calc(100dvh - 20px);
    padding: 16px 14px 12px;
  }

  .cn-snapshot-head {
    flex-direction: column;
  }

  .cn-snapshot-scroll {
    gap: 10px;
  }

  .cn-check-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 980px) {
  .cn-snapshot-head {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  .calendar-notes-app *,
  .cn-overlay *,
  .cn-snapshot-overlay * {
    transition: none !important;
    animation: none !important;
  }
}
