/* Dorpus Clinic — appointments, patients, consultation and clinic roles (clinic_app.js) */

.cl-panel {
  max-width: 1180px;
  padding: 20px 24px 48px;
}

.cl-muted { color: #667570; font-size: 0.85rem; }
.cl-subhead { margin: 10px 0 6px; font-size: 0.78rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em; color: #667570; }

.cl-btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.45rem 0.85rem;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease;
}
.cl-btn:disabled { opacity: 0.55; cursor: not-allowed; }
.cl-btn-primary { background: #0f6e5b; color: #fff; }
.cl-btn-primary:hover:not(:disabled) { background: #0c5b4b; }
.cl-btn-dark { background: #111; color: #fff; }
.cl-btn-dark:hover:not(:disabled) { background: #2a2a2a; }
.cl-btn-light { background: #fff; border-color: #d5ddda; color: #17312b; }
.cl-btn-light:hover:not(:disabled) { background: #f2f6f5; }
.cl-btn.danger { color: #b42318; }
.cl-btn[hidden] { display: none; }
.cl-icon-btn {
  border: 1px solid #d5ddda; background: #fff; border-radius: 8px; min-width: 32px; height: 32px;
  font: inherit; font-size: 0.95rem; cursor: pointer; color: #17312b;
}
.cl-icon-btn:hover { background: #f2f6f5; }
.cl-link { border: 0; background: none; padding: 0; font: inherit; font-weight: 700; color: inherit; cursor: pointer; text-align: left; }
.cl-link:hover { text-decoration: underline; }
.cl-select, .cl-panel select, .cl-modal-card select {
  border: 1px solid #d5ddda; border-radius: 10px; padding: 0.42rem 0.6rem; background: #fff; font: inherit; color: inherit;
}
.cl-select[hidden] { display: none; }

/* ---- toolbar ---- */
.cl-toolbar { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 14px; }
.cl-toolbar-end { display: flex; gap: 8px; margin-left: auto; align-items: center; }
.cl-seg { display: inline-flex; gap: 2px; padding: 3px; background: #eef2f1; border-radius: 12px; }
.cl-seg button { border: 0; background: transparent; border-radius: 9px; padding: 0.38rem 0.8rem; font: inherit; font-size: 0.86rem; font-weight: 600; color: #667570; cursor: pointer; }
.cl-seg button.active { background: #fff; color: #102a24; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1); }
.cl-datenav { display: flex; gap: 6px; align-items: center; }
#view-appointments .cl-toolbar > .cl-datenav { margin-left: auto; }
#view-appointments .cl-toolbar-end { justify-content: flex-end; }
.cl-datenav input[type="date"] { border: 1px solid #d5ddda; border-radius: 10px; padding: 0.36rem 0.55rem; font: inherit; }

/* ---- stats ---- */
.cl-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; margin-bottom: 18px; }
.cl-stats[hidden] { display: none; }
.cl-stat { border: 1px solid #e3e8e6; border-radius: 12px; padding: 10px 12px; background: #fff; display: flex; flex-direction: column; }
.cl-stat-value { font-size: 1.35rem; font-weight: 700; line-height: 1.2; }
.cl-stat-label { font-size: 0.78rem; color: #667570; font-weight: 600; }
.cl-stat.is-checked_in .cl-stat-value { color: #9a6700; }
.cl-stat.is-in_consultation .cl-stat-value { color: #1d4ed8; }
.cl-stat.is-completed .cl-stat-value { color: #0f6e5b; }
.cl-stat.is-no_show .cl-stat-value { color: #b42318; }
.cl-stat.is-money .cl-stat-value { font-size: 1.1rem; padding-top: 3px; }

/* ---- day groups and appointment rows ---- */
.cl-day { margin-bottom: 20px; }
.cl-day-head { display: flex; justify-content: space-between; align-items: baseline; padding: 0 2px 6px; border-bottom: 1px solid #e3e8e6; margin-bottom: 8px; }
.cl-day-head h3 { margin: 0; font-size: 1rem; }
.cl-day-name { font-weight: 700; }
.cl-day.is-today .cl-day-name { color: #0f6e5b; }
.cl-day-date { font-weight: 500; color: #667570; }
.cl-day-count { font-size: 0.82rem; color: #667570; }
.cl-appt-list { display: grid; gap: 8px; }

.cl-appt {
  display: grid;
  grid-template-columns: 64px minmax(0, 1fr) auto auto auto;
  gap: 14px;
  align-items: center;
  padding: 10px 12px;
  border: 1px solid #e3e8e6;
  border-left: 4px solid #cfd8d5;
  border-radius: 12px;
  background: #fff;
}
.cl-appt.is-checked_in { border-left-color: #d4a017; }
.cl-appt.is-in_consultation { border-left-color: #2563eb; background: #f7f9ff; }
.cl-appt.is-completed { border-left-color: #0f6e5b; }
.cl-appt.is-no_show, .cl-appt.is-cancelled { border-left-color: #e5a29b; opacity: 0.72; }
.cl-token { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 44px; border-radius: 10px; background: #f3f6f5; }
.cl-token-no { font-size: 1.15rem; font-weight: 800; color: #102a24; line-height: 1.1; }
.cl-token-time { font-size: 0.78rem; color: #667570; font-weight: 600; }
.cl-appt-main { min-width: 0; }
.cl-appt-name { display: flex; flex-wrap: wrap; gap: 8px; align-items: baseline; }
.cl-mrn { font-size: 0.78rem; color: #667570; font-weight: 600; }
.cl-allergy-dot { font-size: 0.7rem; font-weight: 700; color: #b42318; background: #fdecea; border-radius: 999px; padding: 0 7px; }
.cl-appt-meta { font-size: 0.85rem; color: #4d5b57; }
.cl-appt-reason { font-size: 0.85rem; color: #667570; font-style: italic; }
.cl-pill { display: inline-block; font-size: 0.74rem; font-weight: 700; border-radius: 999px; padding: 2px 9px; background: #eef2f1; color: #4d5b57; white-space: nowrap; }
.cl-pill.is-checked_in { background: #fff4d6; color: #8a5a00; }
.cl-pill.is-in_consultation { background: #e0e9ff; color: #1d4ed8; }
.cl-pill.is-completed { background: #dff3ea; color: #0b6b4f; }
.cl-pill.is-no_show, .cl-pill.is-cancelled { background: #fdecea; color: #b42318; }
.cl-fee-btn { border: 1px dashed #c9d3d0; background: #fff; border-radius: 8px; padding: 3px 8px; font: inherit; font-size: 0.8rem; font-weight: 600; color: #8a5a00; cursor: pointer; }
.cl-fee-btn.is-paid { border-style: solid; border-color: #b7e0cf; background: #f0faf5; color: #0b6b4f; }
.cl-appt-actions { display: flex; gap: 6px; align-items: center; justify-content: flex-end; }
.cl-wait { font-size: 0.82rem; color: #667570; font-weight: 600; }

.cl-more { position: relative; }
.cl-more > summary { list-style: none; cursor: pointer; border: 1px solid #d5ddda; border-radius: 8px; width: 32px; height: 32px; display: grid; place-items: center; font-weight: 800; color: #17312b; background: #fff; }
.cl-more > summary::-webkit-details-marker { display: none; }
.cl-menu { position: absolute; right: 0; top: calc(100% + 4px); z-index: 30; min-width: 190px; background: #fff; border: 1px solid #e3e8e6; border-radius: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.12); padding: 4px; display: grid; }
.cl-menu-item { border: 0; background: none; text-align: left; padding: 8px 10px; border-radius: 8px; font: inherit; font-size: 0.88rem; cursor: pointer; }
.cl-menu-item:hover { background: #f2f6f5; }
.cl-menu-item.danger { color: #b42318; }
.cl-menu-sep { height: 1px; background: #e3e8e6; margin: 4px 6px; }

.cl-empty { text-align: center; padding: 40px 16px; color: #667570; border: 1px dashed #d5ddda; border-radius: 14px; background: #fbfcfc; }
.cl-empty p { margin: 0 0 12px; }

/* ---- modal ---- */
.cl-modal-card { width: min(760px, 100%); }
.cl-modal-form { display: grid; gap: 8px; }
.cl-form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px 12px; }
.cl-form-grid .span-2 { grid-column: span 2; }
.cl-field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.cl-field > span { font-size: 0.8rem; font-weight: 600; color: #667570; }
.cl-field input, .cl-field select, .cl-field textarea,
.cl-who > input, .cl-rows input, .cl-rows select, .cl-rx-fields input, .cl-rx-fields select,
.cl-card textarea, .cl-staff-row input, .cl-staff-row select {
  border: 1px solid #d5ddda; border-radius: 10px; padding: 0.5rem 0.65rem; font: inherit; font-size: 0.92rem;
  background: #fff; color: inherit; min-width: 0; width: 100%;
}
.cl-field input:focus, .cl-field select:focus, .cl-field textarea:focus, .cl-rx-fields input:focus,
.cl-rx-fields select:focus, .cl-rows input:focus, .cl-card textarea:focus, .cl-who > input:focus {
  outline: 2px solid #9fd2c4; border-color: #0f6e5b;
}
.cl-panel input:disabled, .cl-panel textarea:disabled, .cl-panel select:disabled { background: #f7f9f8; color: #2b3a36; }
.cl-check { display: flex; gap: 8px; align-items: center; font-size: 0.9rem; }
.cl-check[hidden] { display: none; }
.cl-modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 10px; }
.cl-request-box { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; background: #e8f4f0; border-radius: 10px; font-size: 0.9rem; }
.cl-who { display: grid; gap: 8px; }
.cl-pick-results { display: grid; gap: 6px; }
.cl-pick { display: flex; gap: 10px; align-items: center; border: 1px solid #e3e8e6; background: #fff; border-radius: 10px; padding: 8px 10px; font: inherit; text-align: left; cursor: pointer; }
.cl-pick:hover { border-color: #0f6e5b; background: #f6fbf9; }
.cl-pick-use { margin-left: auto; font-weight: 700; color: #0f6e5b; font-size: 0.85rem; }
.cl-new-patient { border: 1px solid #e3e8e6; border-radius: 12px; padding: 2px 12px 12px; }
.cl-chip-patient { display: flex; gap: 12px; align-items: center; padding: 10px 12px; border: 1px solid #b7e0cf; background: #f6fbf9; border-radius: 12px; }
.cl-chip-patient > div { flex: 1; }

.cl-avatar { flex: none; width: 34px; height: 34px; border-radius: 50%; background: #0f6e5b; color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 0.82rem; }
.cl-avatar.lg { width: 46px; height: 46px; font-size: 1rem; }

/* ---- patients ---- */
.cl-patients { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 20px; align-items: start; }
.cl-pt-list { position: sticky; top: 0; display: flex; flex-direction: column; gap: 10px; max-height: calc(100vh - 140px); }
.cl-search { display: flex; gap: 8px; }
.cl-search input { flex: 1; min-width: 0; border: 1px solid #d5ddda; border-radius: 10px; padding: 0.5rem 0.7rem; font: inherit; }
.cl-pt-results { list-style: none; margin: 0; padding: 0; overflow: auto; display: grid; gap: 4px; }
.cl-pt-item { width: 100%; display: flex; gap: 10px; align-items: center; border: 1px solid transparent; background: none; border-radius: 10px; padding: 8px; font: inherit; text-align: left; cursor: pointer; }
.cl-pt-item:hover { background: #f2f6f5; }
.cl-pt-item.active { background: #e8f4f0; border-color: #b7e0cf; }
.cl-pt-text { display: flex; flex-direction: column; min-width: 0; }
.cl-pt-text strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cl-pt-none { padding: 12px 8px; }
.cl-pt-detail { min-width: 0; }
.cl-pt-head { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.cl-pt-title { flex: 1; min-width: 200px; }
.cl-pt-title h2, .cl-cx-title h2 { margin: 0; font-size: 1.35rem; font-family: inherit; }
.cl-pt-title p, .cl-cx-title p { margin: 2px 0 0; }
.cl-pt-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.cl-alert { background: #fdecea; color: #8f1c13; border: 1px solid #f5c2bd; border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; font-size: 0.9rem; }
.cl-ok { background: #f3f6f5; color: #4d5b57; border-radius: 10px; padding: 8px 12px; margin-bottom: 10px; font-size: 0.9rem; }
.cl-facts { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0 0 12px; font-size: 0.9rem; }
.cl-facts dt { color: #667570; font-weight: 600; }
.cl-facts dd { margin: 0; white-space: pre-line; }
.cl-section-title { margin: 18px 0 8px; font-size: 0.95rem; }
.cl-timeline { display: grid; gap: 8px; }
.cl-tl-item { display: grid; grid-template-columns: 150px minmax(0, 1fr) auto; gap: 12px; padding: 10px 12px; border: 1px solid #e3e8e6; border-radius: 12px; background: #fff; }
.cl-tl-date { display: flex; flex-direction: column; font-size: 0.88rem; }
.cl-tl-body p { margin: 0 0 3px; font-size: 0.9rem; }
.cl-tl-actions { display: flex; gap: 6px; align-items: flex-start; flex-wrap: wrap; justify-content: flex-end; }
.cl-tag { display: inline-block; font-size: 0.7rem; font-weight: 800; background: #eef2f1; color: #0f6e5b; border-radius: 5px; padding: 0 5px; }
.cl-mini-list { display: grid; gap: 4px; }
.cl-mini { display: grid; grid-template-columns: 190px minmax(0, 1fr) auto; gap: 10px; align-items: center; padding: 6px 10px; border-radius: 8px; background: #fafbfb; font-size: 0.88rem; }

/* ---- consultation ---- */
.cl-consult { max-width: 1240px; }
.cl-cx-head { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; position: sticky; top: -20px; z-index: 5; background: #fff; padding: 12px 0 10px; margin-bottom: 8px; border-bottom: 1px solid #e3e8e6; }
.cl-cx-title { flex: 1; min-width: 200px; }
.cl-cx-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cl-save-state { font-size: 0.8rem; color: #667570; margin-right: 4px; }
.cl-cx-grid { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 16px; align-items: start; }
.cl-cx-main { display: grid; gap: 12px; min-width: 0; }
.cl-cx-side { display: grid; gap: 12px; position: sticky; top: 72px; }
.cl-card { border: 1px solid #e3e8e6; border-radius: 14px; background: #fff; padding: 12px 14px; }
.cl-card-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; }
.cl-card-head h3 { margin: 0; font-size: 0.95rem; }
.cl-dx-suggest { color: #0f6e5b; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; }
.cl-dx-suggest:hover:not(:disabled) { background: #e8f4f0; }
.cl-dx-suggest:disabled { opacity: 0.55; cursor: wait; }
.cl-dx-wrap { position: relative; }
.cl-icd-menu {
  position: absolute; left: 0; right: 140px; top: calc(100% - 2px); z-index: 20;
  max-height: 220px; overflow: auto; background: #fff; border: 1px solid #d5ddda;
  border-radius: 10px; box-shadow: 0 8px 24px rgba(16, 42, 36, 0.12); padding: 4px;
}
.cl-icd-opt {
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 8px; width: 100%;
  text-align: left; border: 0; background: transparent; border-radius: 8px;
  padding: 6px 8px; font: inherit; cursor: pointer; color: inherit;
}
.cl-icd-opt:hover, .cl-icd-opt:focus { background: #e8f4f0; }
.cl-icd-opt strong { color: #0f6e5b; font-size: 0.82rem; white-space: nowrap; }
.cl-icd-opt span { font-size: 0.86rem; min-width: 0; }
.cl-stack { display: grid; gap: 10px; }
.cl-stack-sm p { margin: 0 0 4px; font-size: 0.9rem; }
.cl-card textarea { resize: vertical; }
.cl-vitals { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.cl-vital { display: flex; flex-direction: column; gap: 3px; }
.cl-vital > span { font-size: 0.75rem; font-weight: 600; color: #667570; }
.cl-vital-in { display: flex; align-items: center; border: 1px solid #d5ddda; border-radius: 10px; background: #fff; overflow: hidden; }
.cl-vital-in input { border: 0; padding: 0.45rem 0.5rem; width: 100%; min-width: 0; font: inherit; background: transparent; }
.cl-vital-in input:focus { outline: none; }
.cl-vital-in:focus-within { outline: 2px solid #9fd2c4; border-color: #0f6e5b; }
.cl-vital-in em { font-style: normal; font-size: 0.72rem; color: #667570; padding: 0 8px 0 0; white-space: nowrap; }
.cl-bmi strong { padding: 0.45rem 0; font-size: 1rem; }
.cl-rows { display: grid; gap: 6px; margin-bottom: 8px; }
.cl-row { display: grid; grid-template-columns: minmax(0, 2fr) minmax(0, 1fr) 32px; gap: 6px; align-items: center; }
.cl-dx-row { grid-template-columns: minmax(0, 1fr) 140px 32px; }
.cl-rx-list { display: grid; gap: 8px; margin-bottom: 8px; }
.cl-rx-row { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; gap: 8px; align-items: start; padding: 8px; border: 1px solid #edf1ef; border-radius: 12px; background: #fbfcfc; }
.cl-rx-no { font-weight: 800; color: #0f6e5b; padding-top: 8px; text-align: center; }
.cl-rx-fields { display: grid; grid-template-columns: 112px minmax(0, 2fr) minmax(0, 1fr) minmax(0, 1fr); gap: 6px; }
.cl-rx-fields > :nth-child(8) { grid-column: 2 / -1; }
.cl-rx-tools { display: flex; flex-direction: column; gap: 4px; }
.cl-warnings:empty { display: none; }
.cl-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.cl-chip { border: 1px solid #c9ddd6; background: #fff; color: #0f6e5b; border-radius: 999px; padding: 3px 10px; font: inherit; font-size: 0.8rem; font-weight: 600; cursor: pointer; }
.cl-chip:hover { background: #e8f4f0; }
.cl-fu { display: grid; grid-template-columns: 180px minmax(0, 1fr); gap: 10px; }
.cl-prev { display: grid; gap: 10px; max-height: 60vh; overflow: auto; }
.cl-prev-item { border-bottom: 1px solid #edf1ef; padding-bottom: 8px; }
.cl-prev-item:last-child { border-bottom: 0; }
.cl-prev-head { display: flex; justify-content: space-between; gap: 6px; font-size: 0.85rem; }
.cl-prev-item p { margin: 3px 0; font-size: 0.86rem; }
.cl-prev-rx { margin: 4px 0 6px; padding-left: 1.1em; font-size: 0.84rem; }
.cl-addendum { border-left: 3px solid #b7e0cf; padding: 2px 10px; margin-bottom: 8px; }
.cl-addendum p { margin: 2px 0 0; white-space: pre-line; }
.cl-drug .cl-note { background: #fff8e8; border-radius: 8px; padding: 6px 10px; font-size: 0.85rem; }
.cl-drug-sec { border-top: 1px solid #edf1ef; padding: 6px 0; }
.cl-drug-sec summary { font-weight: 700; cursor: pointer; }
.cl-drug-sec p { font-size: 0.86rem; white-space: pre-line; max-height: 260px; overflow: auto; }

/* ---- team: clinic roles ---- */
.cl-staff-list { display: grid; gap: 4px; }
.cl-staff-row { display: grid; grid-template-columns: minmax(150px, 1.2fr) 150px minmax(0, 1fr) minmax(0, 1fr) 120px auto; gap: 8px; align-items: center; padding: 8px 0; border-top: 1px solid #edf1ef; }
.cl-staff-who { display: flex; flex-direction: column; min-width: 0; }
.cl-staff-who span { overflow: hidden; text-overflow: ellipsis; }
.cl-staff-branches { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 4px 14px; align-items: center; margin: 0; font-size: 0.86rem; }
.cl-role-list { display: grid; gap: 2px; }
.cl-role-row { display: grid; grid-template-columns: minmax(170px, 0.9fr) minmax(0, 1.6fr) auto; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid #edf1ef; }
.cl-role-who { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.cl-role-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.cl-role-tags:empty { display: none; }
.cl-role-perms { margin: 0; font-size: 0.84rem; color: #3b4744; line-height: 1.45; }
.cl-role-actions { display: flex; gap: 6px; justify-content: flex-end; }
.cl-perm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; max-height: 52vh; overflow: auto; padding-right: 4px; }
.cl-perm-group { border: 1px solid #e3e9e7; border-radius: 10px; padding: 6px 10px 8px; margin: 0; display: grid; gap: 6px; }
.cl-perm-group legend { font-weight: 700; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: #0f6e5b; padding: 0 4px; }
.cl-perm { display: grid; grid-template-columns: auto 1fr; gap: 8px; align-items: start; cursor: pointer; }
.cl-perm input { margin-top: 3px; }
.cl-perm span { display: flex; flex-direction: column; font-size: 0.88rem; }
.cl-perm small { font-size: 0.78rem; }

/* ---- reception: request actions ---- */
.cl-req-actions { display: flex; gap: 6px; align-items: center; }

@media (max-width: 1100px) {
  .cl-cx-grid { grid-template-columns: 1fr; }
  .cl-cx-side { position: static; }
  .cl-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  .cl-panel { padding: 14px 12px 40px; }
  .cl-patients { grid-template-columns: 1fr; }
  .cl-pt-list { position: static; max-height: none; }
  .cl-pt-results { max-height: 40vh; }
  .cl-appt { grid-template-columns: 52px minmax(0, 1fr) auto; gap: 8px 10px; }
  .cl-appt .cl-pill { grid-column: 3; grid-row: 1; }
  .cl-appt .cl-fee { grid-column: 2; }
  .cl-appt .cl-fee:empty { display: none; }
  .cl-appt .cl-appt-actions { grid-column: 2 / -1; justify-content: flex-start; }
  .cl-vitals { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .cl-rx-fields { grid-template-columns: 1fr 1fr; }
  .cl-rx-fields > :nth-child(2) { grid-column: 1 / -1; order: -1; }
  .cl-rx-fields > :nth-child(8) { grid-column: 1 / -1; }
  .cl-form-grid { grid-template-columns: 1fr 1fr; }
  .cl-tl-item { grid-template-columns: 1fr; }
  .cl-tl-actions { justify-content: flex-start; }
  .cl-mini { grid-template-columns: 1fr auto; }
  .cl-mini > :nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
  .cl-staff-row { grid-template-columns: 1fr 1fr; }
  .cl-staff-who { grid-column: 1 / -1; }
  .cl-role-row { grid-template-columns: 1fr auto; }
  .cl-role-perms { grid-column: 1 / -1; grid-row: 2; }
  .cl-perm-grid { grid-template-columns: 1fr; }
  .cl-toolbar-end { margin-left: 0; width: 100%; }
  .cl-toolbar-end .cl-btn-primary { margin-left: auto; }
  .cl-fu { grid-template-columns: 1fr; }
  .cl-cx-head { top: -14px; }
}

@media (max-width: 520px) {
  .cl-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .cl-form-grid { grid-template-columns: 1fr; }
  .cl-form-grid .span-2 { grid-column: auto; }
  .cl-row, .cl-dx-row { grid-template-columns: minmax(0, 1fr) 32px; }
  .cl-row > :nth-child(2) { grid-column: 1; }
  .cl-icd-menu { right: 32px; }
}

/* ---- Clinic setup (details, branches, departments & rooms, lab tests) ---- */
.cs-header { margin: 0 0 14px; }
.cs-header h2 { margin: 0 0 4px; }
.cs-tabs { margin-top: 10px; flex-wrap: wrap; }
.cs-tabs[hidden], .cs-tabs button[hidden] { display: none; }
.cs-pane[hidden] { display: none; }
.wf-title { margin: 0; font-size: 1.05rem; }
.cs-pane.teach-panel { margin: 0; }
/* Clinic details: basics on the left, hours and doctors on the right (wide screens) */
#view-clinic #profile-form { max-width: none; }
.pf-cols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 0 28px; align-items: start; }
.pf-col { display: grid; gap: 14px; min-width: 0; }
.pf-col > .pf-block:first-child { margin-top: 0; }
@media (max-width: 1100px) { .pf-cols { grid-template-columns: minmax(0, 1fr); gap: 14px; } }
/* Branches: a grid of cards */
.cl-branch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; margin-top: 6px; }
.cl-branch-card { border: 1px solid #e3e9e7; border-radius: 12px; padding: 14px 16px; display: grid; gap: 6px; align-content: start; background: #fff; }
.cl-branch-card.is-off { opacity: 0.7; }
.cl-branch-card p { margin: 0; font-size: 0.88rem; }
.cl-branch-head { display: flex; align-items: baseline; gap: 8px; font-size: 1rem; }
.cl-branch-code { font-size: 0.75rem; font-weight: 700; letter-spacing: 0.06em; color: #0f6e5b; background: #e8f3ef; border-radius: 6px; padding: 1px 6px; }
.cl-branch-staff { color: #3b4744; }
.cl-branch-card .cl-role-actions { justify-content: flex-start; margin-top: 4px; }
#cs-team .page-card, #cs-team .cl-staff-card { max-width: none; }
.cl-staff-branches .cl-check { white-space: nowrap; gap: 6px; }
.cl-staff-row .cl-staff-branches input[type="checkbox"] { width: auto; flex: none; margin: 0; }

/* Consultation: foldable cards (accordion) */
.cl-fold > .cl-card-head { cursor: pointer; margin-bottom: 0; align-items: center; user-select: none; }
.cl-fold > .cl-card-head:focus-visible { outline: 2px solid #9fd2c4; border-radius: 8px; }
.cl-fold > .cl-card-head h3 { flex: 1 1 auto; }
.cl-fold-chev { flex: none; width: 0.55rem; height: 0.55rem; border-right: 2px solid #667570; border-bottom: 2px solid #667570;
  transform: rotate(45deg); margin: 0 4px 3px 6px; transition: transform 0.15s ease; }
.cl-fold.is-open > .cl-card-head { margin-bottom: 8px; }
.cl-fold.is-open .cl-fold-chev { transform: rotate(-135deg); margin-bottom: -3px; }
.cl-fold:not(.is-open) > :not(.cl-card-head) { display: none; }

/* Fields nothing else styles (report comments, worklist search boxes…) get the clinic look
   instead of the browser's black border. :where() keeps this weaker than any specific rule. */
:where(#cl-modal, .cl-panel) :where(textarea, select, input:not([type=checkbox]):not([type=radio]):not([type=file]):not([type=range]):not([type=color])) {
  border: 1px solid #d5ddda;
  border-radius: 10px;
  padding: 0.5rem 0.65rem;
  font: inherit;
  font-size: 0.92rem;
  background: #fff;
  color: inherit;
}
:where(#cl-modal, .cl-panel) :where(textarea) {
  width: 100%;
  resize: vertical;
}
:where(#cl-modal, .cl-panel) :where(textarea, select, input):focus {
  outline: 2px solid #9fd2c4;
  border-color: #0f6e5b;
}

/* Patient journey during a consultation: away at the lab / a facility, or back waiting */
.cl-pill.is-stage-away, .cl-pill.is-stage-results_pending { background: #f1e8ff; color: #6b21a8; }
.cl-pill.is-stage-results_ready { background: #fff4d6; color: #8a5a00; }
.cl-appt.is-stage-away, .cl-appt.is-stage-results_pending { border-left-color: #9333ea; background: #fbf8ff; }
.cl-appt.is-stage-results_ready { border-left-color: #d97706; background: #fffbf0; }
.cl-stat.is-away .cl-stat-value { color: #7e22ce; }

#med-root.cl-panel { max-width: 1100px; }
.med-note { margin: 0 0 14px; color: #3b4744; font-size: 0.9rem; line-height: 1.45; max-width: 46rem; }
.med-browse { display: grid; grid-template-columns: 232px minmax(0, 1fr); gap: 20px; align-items: start; }
.med-side {
  position: sticky; top: 0;
  border: 1px solid #e3e8e6; border-radius: 14px; background: #fff;
  padding: 12px; display: grid; gap: 14px; max-height: calc(100vh - 8rem); overflow: auto;
}
.med-side h3 { margin: 0 0 6px; font-size: 0.75rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: #667570; }
.med-side-head { display: flex; align-items: center; justify-content: space-between; }
.med-side-head h3 { margin: 0; }
.med-clear { border: 0; background: none; padding: 0; font: inherit; font-size: 0.82rem; font-weight: 700; color: #0f6e5b; cursor: pointer; }
.med-filter {
  display: flex; width: 100%; justify-content: space-between; gap: 8px; align-items: center;
  border: 0; background: transparent; border-radius: 8px; padding: 0.32rem 0.45rem;
  font: inherit; font-size: 0.86rem; text-align: left; cursor: pointer; color: inherit;
}
.med-filter:hover:not(:disabled) { background: #f2f6f5; }
.med-filter.is-on { background: #e8f3ef; color: #0f6e5b; font-weight: 700; }
.med-filter:disabled { opacity: 0.4; cursor: default; }
.med-count { color: #667570; font-size: 0.78rem; font-weight: 600; }
.med-filter.is-on .med-count { color: #0f6e5b; }
.med-letters { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.med-letter {
  border: 0; background: transparent; border-radius: 7px; height: 28px;
  font: inherit; font-size: 0.78rem; font-weight: 700; cursor: pointer; color: #17312b;
}
.med-letter:hover:not(:disabled) { background: #f2f6f5; }
.med-letter.is-on { background: #0f6e5b; color: #fff; }
.med-letter:disabled { opacity: 0.3; cursor: default; }
.med-search { width: 100%; margin-bottom: 14px; }
.med-more { margin-top: 12px; }
@media (max-width: 860px) {
  .med-browse { grid-template-columns: 1fr; }
  .med-side { position: static; max-height: none; }
}
.med-list { display: grid; gap: 8px; }
.med-hit {
  display: grid; gap: 2px; text-align: left; width: 100%;
  border: 1px solid #e3e8e6; border-radius: 12px; background: #fff;
  padding: 10px 12px; font: inherit; cursor: pointer; color: inherit;
}
.med-hit:hover { border-color: #0f6e5b; }
.med-hit strong { font-size: 0.98rem; }
.med-link { margin: 0 0 12px; }
.med-sections { display: flex; flex-direction: column; gap: 8px; }
.med-section.cl-card { margin: 0; padding: 0; }
.med-section > .cl-card-head { margin: 0; padding: 10px 14px; }
.med-section.cl-fold.is-open > .cl-card-head { margin-bottom: 0; }
.med-section p { margin: 0; padding: 0 14px 12px; line-height: 1.5; white-space: pre-wrap; }
.med-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 0 0 12px; }

.cl-dx-feedback { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 8px; }
.cl-dx-feedback button { font-size: 0.78rem; padding: 4px 8px; border-radius: 8px; border: 1px solid #d5ddda; background: #f7faf9; }
.cl-dx-feedback button:focus-visible { outline: 2px solid #1f6f5b; outline-offset: 2px; }
.cl-dx-feedback input { flex: 1 1 140px; min-width: 120px; font-size: 0.8rem; }
.cl-dx-feedback-status { flex: 1 0 100%; margin: 0; font-size: 0.78rem; color: #3d4f4a; }

.cl-dx-feedback-note { margin: 0 0 6px; font-size: 0.78rem; color: #5b6b66; flex: 1 0 100%; }
.cl-dx-urgent { font-size: 0.78rem; display: inline-flex; gap: 4px; align-items: center; }
