:root {
  --blue-900: #0284C7;
  --blue-800: #0EA5E9;
  --blue-050: #E5F4FC;
  --gold-500: #0D9488;
  --gold-600: #0F766E;
  --teal-050: #E1F6F3;
  --bg: #F3F6FA;
  --surface: #FFFFFF;
  --border: #E2E8F0;
  --text: #1B2A3C;
  --text-dim: #64748B;
  --danger: #EF4444;
  --danger-bg: #FEE2E2;
  --success: #10B981;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15,23,42,0.04), 0 4px 16px rgba(15,23,42,0.06);
  --focus-ring: 0 0 0 3px rgba(2,132,199,0.18);

  --sidebar-bg: #0B2544;
  --sidebar-bg-2: #123A66;
  --sidebar-text: rgba(255,255,255,0.62);
  --sidebar-text-active: #FFFFFF;
  --sidebar-active-bg: #0284C7;

  --sidebar-w: 250px;
  --sidebar-w-collapsed: 76px;

  --icon-purple-bg: #E0E7FF; --icon-purple: #6366F1;
  --icon-green-bg: #D1FAE5;  --icon-green: #10B981;
  --icon-blue-bg: #CCFBF1;   --icon-blue: #0D9488;
  --icon-red-bg: #FEE2E2;    --icon-red: #EF4444;
}

* { box-sizing: border-box; }

/* Important fix: any element with the "hidden" attribute must actually disappear
   regardless of its display rules (e.g. .modal-overlay or .placeholder which use flex).
   Without this rule, those elements stayed visible even when JS set hidden on them. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', sans-serif;
}

/* Thin, subtle scrollbars everywhere instead of the browser's bulky default */
* { scrollbar-width: thin; scrollbar-color: #C7D0E0 transparent; }
*::-webkit-scrollbar { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: #C7D0E0; border-radius: 8px; }
*::-webkit-scrollbar-thumb:hover { background: #A6B3CC; }

h1, h2, h3 {
  font-family: 'Inter', sans-serif;
}

input[type="checkbox"], input[type="radio"] { accent-color: var(--blue-900); }

@media (prefers-reduced-motion: reduce) {
  .modal-overlay, .modal-overlay .modal, .toast { animation: none !important; }
}

/* ===== App shell: dark sidebar + main content ===== */
.app-shell {
  display: flex;
  height: 100vh;
}

.app-sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
  display: flex;
  flex-direction: column;
  padding: 22px 16px;
  transition: width 0.18s ease, min-width 0.18s ease;
  position: relative;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px;
  margin-bottom: 28px;
  position: relative;
}
.sidebar-logo-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--sidebar-active-bg);
  color: white;
  font-weight: 900;
  font-size: 19px;
  font-family: 'Inter', sans-serif;
  flex-shrink: 0;
}
.sidebar-logo-text { display: flex; flex-direction: column; line-height: 1.25; }
.sidebar-logo-text strong { color: white; font-size: 15.5px; letter-spacing: 0.5px; }
.sidebar-logo-text span { color: var(--sidebar-text); font-size: 10px; letter-spacing: 2px; }

.sidebar-collapse-btn {
  margin-left: auto;
  width: 26px;
  height: 26px;
  border-radius: 7px;
  border: none;
  background: rgba(255,255,255,0.08);
  color: var(--sidebar-text);
  cursor: pointer;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
  flex-shrink: 0;
}
.sidebar-collapse-btn:hover { background: rgba(255,255,255,0.16); color: white; }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
  overflow-y: auto;
  overflow-x: visible;
}
.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  padding: 11px 12px;
  border-radius: 9px;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
  position: relative;
}
.sidebar-nav-item .nav-icon { font-size: 16px; width: 18px; text-align: center; flex-shrink: 0; }
.sidebar-nav-item:hover { background: rgba(255,255,255,0.06); color: white; }
.sidebar-nav-item.active { background: var(--sidebar-active-bg); color: white; font-weight: 600; }

.sidebar-footer {
  border-top: 1px solid rgba(255,255,255,0.08);
  padding-top: 14px;
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sidebar-user, .sidebar-clinic {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
}
.sidebar-user-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--sidebar-active-bg);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700;
  flex-shrink: 0;
}
.sidebar-user-info, .sidebar-clinic-info { display: flex; flex-direction: column; line-height: 1.3; min-width: 0; }
.sidebar-user-info strong, .sidebar-clinic-info strong { color: white; font-size: 13px; }
.sidebar-user-info span, .sidebar-clinic-info span { color: var(--sidebar-text); font-size: 11px; }
.sidebar-clinic { background: rgba(255,255,255,0.05); border-radius: 10px; }
.sidebar-clinic-icon { font-size: 16px; }

/* Phase 7: expandable sidebar group ("Clinical" today — Medical Records +
   Prescriptions). The header toggles open/closed; children are ordinary
   .sidebar-nav-item buttons (see js/nav.js) so all existing click-routing
   and permission-visibility logic works on them unchanged. */
.sidebar-nav-group { display: flex; flex-direction: column; gap: 3px; }
.sidebar-nav-group-header {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--sidebar-text);
  padding: 11px 12px;
  border-radius: 9px;
  font-family: 'Inter', sans-serif;
  font-weight: 500;
  font-size: 14px;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-nav-group-header:hover { background: rgba(255,255,255,0.06); color: white; }
.sidebar-nav-group.has-active-child > .sidebar-nav-group-header { color: white; font-weight: 600; }
.sidebar-nav-group-label { flex: 1; }
.sidebar-nav-group-caret { font-size: 11px; transition: transform 0.15s ease; flex-shrink: 0; }
.sidebar-nav-group-header[aria-expanded="false"] .sidebar-nav-group-caret { transform: rotate(-90deg); }
.sidebar-nav-group-items { display: flex; flex-direction: column; gap: 3px; }
.sidebar-nav-subitem { padding-left: 34px; }

/* ===== Page header: breadcrumb above the title, only shown when relevant
   (e.g. "Clinical / Medical Records", "Administration / People & Access") ===== */
.main-topbar-titles { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.page-breadcrumb { font-size: 12px; color: var(--text-dim); font-weight: 600; text-transform: uppercase; letter-spacing: 0.02em; }

/* ===== Administration page: section labels grouping the settings tabs
   (Clinic / Clinical Setup / People & Access / Finance / System) — pure
   visual dividers inside #adminTabs, no click behavior of their own. ===== */
.settings-nav-group-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
  padding: 14px 16px 4px;
}
.settings-nav-group-label:first-child { padding-top: 4px; }

/* ===== Sidebar collapsed (icon rail) state ===== */
.app-sidebar.sidebar-collapsed {
  width: var(--sidebar-w-collapsed);
  min-width: var(--sidebar-w-collapsed);
}
.sidebar-collapsed .sidebar-logo { justify-content: center; gap: 0; }
.sidebar-collapsed .sidebar-logo-text { display: none; }
.sidebar-collapsed .sidebar-collapse-btn {
  margin-left: 0;
  position: absolute;
  right: -22px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--sidebar-active-bg);
  color: white;
  box-shadow: var(--shadow);
}
.sidebar-collapsed .sidebar-collapse-btn:hover { background: var(--blue-800); }
.sidebar-collapsed .sidebar-nav-item {
  justify-content: center;
  gap: 0;
  font-size: 0;
  padding: 11px 0;
}
/* Phase 7: collapsed (icon-rail) sidebar — the Clinical group header becomes
   a plain icon like every other item (its own hover tooltip still works via
   the existing initSidebarTooltips, since that targets any
   .sidebar-nav-item[data-title], see js/nav.js — the group header isn't
   one, so it gets no tooltip and no click-driven collapse of its own),
   and its children are always shown so both stay reachable by icon alone. */
.sidebar-collapsed .sidebar-nav-group-header {
  justify-content: center;
  gap: 0;
  font-size: 0;
  padding: 11px 0;
  cursor: default;
}
.sidebar-collapsed .sidebar-nav-group-caret,
.sidebar-collapsed .sidebar-nav-group-label { display: none; }
.sidebar-collapsed .sidebar-nav-group-items { display: flex !important; }
.sidebar-collapsed .sidebar-nav-subitem { padding-left: 0; }
/* Collapsed-sidebar hover tooltip: a single element positioned via JS
   (js/nav.js initSidebarTooltips) rather than CSS ::after, because the
   scrollable .sidebar-nav (overflow-y:auto) would otherwise clip a
   tooltip positioned relative to a nav item — per the CSS overflow spec,
   overflow-x:visible has no effect once overflow-y is not visible. */
.sidebar-hover-tooltip {
  position: fixed;
  background: var(--sidebar-bg-2);
  color: white;
  font-size: 12.5px;
  font-weight: 600;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
  z-index: 9999;
  box-shadow: var(--shadow);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
}
.sidebar-hover-tooltip.visible { opacity: 1; }
.sidebar-collapsed .sidebar-footer { align-items: center; }
.sidebar-collapsed .sidebar-user { justify-content: center; }
.sidebar-collapsed .sidebar-user-info { display: none; }
.sidebar-collapsed .sidebar-user #logoutBtn { margin-right: 0 !important; }
.sidebar-collapsed .sidebar-clinic { justify-content: center; padding: 6px; }
.sidebar-collapsed .sidebar-clinic-info { display: none; }

/* ===== Main content area ===== */
.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.main-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.main-topbar h2 { margin: 0; font-size: 19px; color: var(--text); }

@media (max-width: 900px) {
  .app-shell { flex-direction: column; height: auto; min-height: 100vh; }
  .app-sidebar { width: 100% !important; min-width: 0; flex-direction: row; flex-wrap: wrap; padding: 12px; }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; overflow: visible; }
  .sidebar-footer { display: none; }
  .sidebar-collapse-btn { display: none; }
  .app-main { height: auto; }
  /* Phase 7: on narrow widths the sidebar is already a wrapped row of
     buttons, not a vertical rail — the Clinical group's expand/collapse
     toggle doesn't make sense in that layout, so its two children are
     always shown as plain flat items, same idea as the icon-rail case. */
  .sidebar-nav-group { flex-direction: row; flex-wrap: wrap; }
  .sidebar-nav-group-header { width: auto; }
  .sidebar-nav-group-items { flex-direction: row; flex-wrap: wrap; display: flex !important; }
  .sidebar-nav-subitem { padding-left: 12px; }
  .main-topbar { flex-wrap: wrap; gap: 8px; }
}

/* ===== Calendar view toggle (Day / Week / Month / Year) ===== */
.calendar-view-toggle {
  display: flex;
  gap: 4px;
  margin-bottom: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  width: fit-content;
}
.cal-toggle-btn {
  background: transparent;
  border: none;
  padding: 8px 20px;
  border-radius: 7px;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.cal-toggle-btn:hover { color: var(--text); }
.cal-toggle-btn.active { background: var(--blue-900); color: white; }

.calendar-view-panel { display: none; }
.calendar-view-panel.active { display: block; }

/* ===== Week view ===== */
.week-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 10px;
}
.week-day-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  min-height: 240px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.week-day-card.is-today { border-color: var(--blue-800); }
.week-day-header { text-align: center; padding-bottom: 8px; border-bottom: 1px solid var(--border); }
.week-day-header .dow { font-size: 11px; color: var(--text-dim); font-weight: 700; text-transform: uppercase; }
.week-day-header .dom { font-size: 19px; font-weight: 800; color: var(--text); }
.week-day-appts { display: flex; flex-direction: column; gap: 6px; overflow-y: auto; flex: 1; }
.week-appt-item {
  background: var(--blue-050);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 11.5px;
  cursor: pointer;
  line-height: 1.4;
}
.week-appt-item strong { display: block; font-size: 12px; color: var(--text); }
.week-appt-item:hover { background: var(--icon-blue-bg); }
.week-day-empty { font-size: 11.5px; color: var(--text-dim); text-align: center; margin-top: 12px; }

/* ===== Year view ===== */
.year-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.year-month-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s ease;
}
.year-month-card:hover { border-color: var(--blue-800); }
.year-month-title { text-align: center; font-weight: 700; font-size: 13px; margin-bottom: 8px; color: var(--text); }
.year-mini-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.year-mini-cell {
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; color: var(--text-dim);
  border-radius: 3px;
}
.year-mini-cell.has-appts { background: var(--blue-050); color: var(--blue-900); font-weight: 800; }
.year-mini-cell.other-month { visibility: hidden; }
.year-mini-cell.is-today { box-shadow: inset 0 0 0 1.5px var(--blue-800); }

@media (max-width: 900px) {
  .week-grid { grid-template-columns: repeat(7, minmax(110px, 1fr)); overflow-x: auto; }
  .year-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Auth screens (login / forced password change) ===== */
.auth-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}
.auth-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 32px;
  width: 100%;
  max-width: 380px;
}
.auth-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; justify-content: center; }
.auth-logo-mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--blue-900);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-weight: 900; font-size: 18px;
}
.auth-logo strong { font-size: 14px; letter-spacing: 1px; color: var(--text); }
.auth-card h2 { text-align: center; margin: 0 0 4px; font-size: 20px; }
.auth-card > .hint { text-align: center; margin: 0 0 20px; }

/* ===== Permission matrix (Security Roles editor) ===== */
.permission-module-row {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 8px;
}
.permission-module-row .module-name { font-weight: 700; font-size: 13.5px; color: var(--text); margin-bottom: 8px; }
.permission-actions { display: flex; flex-wrap: wrap; gap: 6px 16px; }
.permission-actions label {
  display: flex; align-items: center; gap: 5px;
  font-size: 12.5px; font-weight: 600; color: var(--text-dim);
  cursor: pointer;
}
.permission-actions input[type="checkbox"] { width: 14px; height: 14px; cursor: pointer; }
.permission-select-all {
  font-size: 11.5px;
  color: var(--blue-800);
  cursor: pointer;
  text-decoration: underline;
  margin-inline-start: 8px;
}

/* ===== Buttons ===== */
.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: transform 0.08s ease, background 0.15s ease, box-shadow 0.15s ease;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--blue-900); color: white; box-shadow: 0 1px 2px rgba(2,132,199,0.25); }
.btn-primary:hover { background: var(--blue-800); box-shadow: 0 2px 8px rgba(2,132,199,0.32); }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text);
}
.btn-outline:hover { border-color: var(--blue-800); color: var(--blue-800); }

.btn-danger-outline {
  background: transparent;
  border: 1.5px solid var(--danger-bg);
  color: var(--danger);
}
.btn-danger-outline:hover { background: var(--danger-bg); }

/* ===== Views container ===== */
.views-container { flex: 1; min-height: 0; display: flex; }
.app-view { display: none; flex: 1; min-height: 0; min-width: 0; }
.app-view.active-view { display: flex; }

.full-view {
  flex: 1;
  padding: 24px 32px;
  overflow-y: auto;
}

/* ===== Layout ===== */
.layout {
  display: flex;
  flex: 1;
  min-height: 0;
  width: 100%;
}

.sidebar {
  width: 320px;
  min-width: 320px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.search-box { padding: 16px; border-bottom: 1px solid var(--border); }
.search-box input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  background: var(--bg);
}
.search-box input:focus { outline: none; border-color: var(--blue-800); box-shadow: var(--focus-ring); }

.patient-count {
  padding: 10px 16px;
  font-size: 12px;
  color: var(--text-dim);
  font-weight: 600;
}

.patient-list {
  list-style: none;
  margin: 0;
  padding: 0 8px 16px;
  overflow-y: auto;
  flex: 1;
}

.patient-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 4px;
}
.patient-card:hover { background: var(--blue-050); }
.patient-card.active { background: var(--blue-050); box-shadow: inset 3px 0 0 var(--blue-900); }

.avatar-sm, .avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}
.avatar-sm { width: 40px; height: 40px; font-size: 15px; }
.avatar { width: 64px; height: 64px; font-size: 24px; }

.patient-card-info { min-width: 0; }
.patient-card-info strong {
  display: block;
  font-size: 14.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.patient-card-info span { font-size: 12.5px; color: var(--text-dim); }

.empty-state {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-dim);
}
.empty-state p { margin-bottom: 12px; font-size: 14px; }

/* ===== Main area ===== */
.main {
  flex: 1;
  overflow-y: auto;
  padding: 32px;
}

.placeholder {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  text-align: center;
}
.placeholder-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.6; }
.placeholder h2 { font-size: 18px; margin: 0 0 6px; color: var(--text); }
.placeholder p { margin: 0; font-size: 14px; }

/* ===== Patient / Doctor detail view — vertical folder-tabs beside content ===== */
.patient-view {
  max-width: 1040px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
  align-items: start;
}

.patient-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 18px;
  margin-bottom: 4px;
}
.patient-header-info { flex: 1; min-width: 0; }
.patient-header-info h2 { margin: 0 0 4px; font-size: 22px; }
.patient-meta { color: var(--text-dim); font-size: 13.5px; }
.patient-header-actions { display: flex; gap: 8px; }

/* Any full-view that contains a folder-tabs bar (Reports, Admin Settings) gets the
   same two-column treatment — everything else in that view spans the full width
   above the tabs, then the tabs sit in their own left column beside the content. */
.full-view:has(> .folder-tabs) {
  display: grid;
  grid-template-columns: 220px 1fr;
  gap: 24px;
  align-items: start;
}
.full-view:has(> .folder-tabs) > *:not(.folder-tabs):not(.folder-content) {
  grid-column: 1 / -1;
}

/* Folder-tab style navigation, echoing a physical paper medical file — now a
   vertical list sitting beside its content instead of a horizontal bar on top. */
.folder-tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  align-self: start;
}
.tab {
  background: transparent;
  border: none;
  padding: 11px 16px;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  font-size: 13.5px;
  color: var(--text-dim);
  cursor: pointer;
  border-radius: 8px;
  text-align: left;
  transition: background 0.15s ease, color 0.15s ease;
}
.tab.active {
  background: var(--blue-900);
  color: white;
}
.tab:not(.active):hover { background: var(--blue-050); color: var(--text); }

.folder-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  min-height: 280px;
  min-width: 0;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ===== Phase 10.1A: Communication sub-navigation (scroll/layout fix) =====
   #commSubNav reuses the .folder-tabs + .tab markup for visual consistency
   with #adminTabs, but it plays a different structural role: #adminTabs is
   a sidebar column that sits BESIDE independently-scrolling content inside
   the .full-view:has(> .folder-tabs) two-column grid above — that pairing
   is what makes .folder-tabs' base position:sticky;top:0 safe there (the
   sidebar has its own column; nothing scrolls over it). #commSubNav is
   nested one level deeper (inside .folder-content, inside one .tab-panel)
   and sits ABOVE its own stacked .comm-sub-panel content in the SAME
   single column, so it never qualifies for that grid rule — but it still
   inherited .folder-tabs' sticky/vertical-list rules regardless. The
   result: as the shared .full-view scrollport scrolled, #commSubNav stuck
   to the top of it (like #adminTabs correctly does) while the Communication
   content beneath it kept scrolling upward underneath a sticky box that has
   no background of its own — producing the reported overlap (e.g. the
   "Send Triggers" section header sliding up behind the stuck sub-nav).
   Normal document flow is correct here — there is no reason for a page's
   own in-column sub-tab bar to stay fixed while its own section scrolls —
   so this override returns #commSubNav to static flow and lays its 5
   buttons out as a horizontal bar, matching the same "horizontal tab strip
   under a bottom border" treatment .folder-tabs itself already uses at
   narrow widths (see the max-width:860px block below), just applied here
   unconditionally since #commSubNav never has an adjacent content column
   to sit beside at any width. */
#commSubNav {
  position: static;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 6px;
  border-bottom: 2px solid var(--border);
  padding-bottom: 0;
}
#commSubNav .tab {
  border-radius: 8px 8px 0 0;
  position: relative;
  top: 2px;
}

@media (max-width: 860px) {
  .patient-view,
  .full-view:has(> .folder-tabs) {
    display: block;
  }
  .full-view:has(> .folder-tabs) > *:not(.folder-tabs):not(.folder-content) {
    grid-column: auto;
  }
  .patient-header { margin-bottom: 24px; }
  .folder-tabs {
    flex-direction: row;
    flex-wrap: wrap;
    position: static;
    border-bottom: 2px solid var(--blue-900);
    margin-bottom: 0;
  }
  .tab { border-radius: 8px 8px 0 0; position: relative; top: 2px; }
  .folder-content { border-radius: 0 0 var(--radius) var(--radius); border-top: none; }
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 18px;
}
.info-item { }
.info-item .label { font-size: 12px; color: var(--text-dim); margin-bottom: 4px; font-weight: 600; }
.info-item .value { font-size: 15px; }
.info-item.full { grid-column: 1 / -1; }
.info-item .value.empty { color: var(--text-dim); font-style: italic; }

.attachments-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.hint { font-size: 12.5px; color: var(--text-dim); }
.file-label { cursor: pointer; }

.attachments-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.attachment-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.attachment-icon { font-size: 22px; }
.attachment-info { flex: 1; min-width: 0; }
.attachment-info strong { display: block; font-size: 14px; }
.attachment-info span { font-size: 12px; color: var(--text-dim); }
.attachment-actions { display: flex; gap: 6px; }
.attachment-actions a, .attachment-actions button {
  font-family: 'Inter', sans-serif;
  font-size: 12.5px;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
  color: var(--text);
  text-decoration: none;
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(11,37,68,0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: modalOverlayFadeIn 0.15s ease;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(11,37,68,0.28);
  animation: modalPopIn 0.18s cubic-bezier(0.2, 0.8, 0.3, 1);
}
@keyframes modalOverlayFadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modalPopIn {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
}
.modal-header h3 { margin: 0; font-size: 17px; }
.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--text-dim);
  line-height: 1;
}
.modal-body { padding: 20px 22px; }

.form-row { margin-bottom: 14px; display: flex; flex-direction: column; gap: 6px; }
.form-row label { font-size: 13px; font-weight: 600; color: var(--text-dim); }
.form-row input, .form-row select, .form-row textarea {
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-family: 'Inter', sans-serif;
  font-size: 14px;
  background: var(--bg);
  resize: vertical;
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
  outline: none;
  border-color: var(--blue-800);
  box-shadow: var(--focus-ring);
}
.two-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.two-cols > div { display: flex; flex-direction: column; gap: 6px; }
.two-cols label { font-size: 13px; font-weight: 600; color: var(--text-dim); }

.form-row.three-cols { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.form-row.three-cols > div { display: flex; flex-direction: column; gap: 6px; }
.form-row.three-cols label { font-size: 12.5px; font-weight: 600; color: var(--text-dim); }
.form-row.three-cols .span-2 { grid-column: span 2; }

.form-section-header {
  background: transparent;
  color: var(--blue-900);
  font-family: 'Inter', sans-serif;
  font-weight: 800;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 0 0 8px;
  margin: 26px 0 14px;
  border-bottom: 2px solid var(--blue-050);
}
.form-section-header:first-child { margin-top: 0; }

.checkbox-field { display: flex; align-items: center; }
.checkbox-field label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
}
.checkbox-field input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

.form-errors { color: var(--danger); font-size: 13px; margin-bottom: 10px; }
.form-errors:empty { display: none; }

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding-top: 8px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--blue-900);
  color: white;
  padding: 12px 22px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: var(--shadow);
  z-index: 200;
  animation: toastSlideUp 0.2s ease;
}
.toast.error { background: var(--danger); }
@keyframes toastSlideUp {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ===== Dashboard: stat cards, charts, cards grid ===== */
.stat-cards-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 18px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.stat-icon {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.stat-icon.icon-purple { background: var(--icon-purple-bg); }
.stat-icon.icon-green { background: var(--icon-green-bg); }
.stat-icon.icon-blue { background: var(--icon-blue-bg); }
.stat-icon.icon-red { background: var(--icon-red-bg); }
.stat-value { font-size: 22px; font-weight: 800; font-family: 'Inter', sans-serif; color: var(--text); line-height: 1.2; }
.stat-label { font-size: 12.5px; color: var(--text-dim); margin-top: 2px; }

.dashboard-grid-2col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
.dashboard-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  min-height: 260px;
}
.dashboard-card h3 { margin: 0 0 14px; font-size: 15px; color: var(--text); }
.dashboard-card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.dashboard-card-header h3 { margin: 0; }
.dashboard-card > *:last-child { flex: 1; }

/* Center the "no data yet" message instead of leaving it stranded at the
   top with a big empty gap underneath — this is what made near-empty
   dashboard cards feel unbalanced. */
.notif-list:has(> p.hint),
.donut-row:has(> p.hint),
.alerts-list:has(> p.hint),
.bar-chart:has(> p.hint) {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

/* Simple bar chart (no external library) */
.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  min-height: 160px;
  padding-top: 10px;
}
.bar-chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar-chart-bar { width: 100%; max-width: 34px; background: var(--blue-900); border-radius: 6px 6px 0 0; min-height: 4px; transition: height 0.3s ease; }
.bar-chart-label { font-size: 11px; color: var(--text-dim); }

/* Donut charts via conic-gradient (no external library) */
.donut-row { display: flex; align-items: center; gap: 24px; }
.donut-chart {
  width: 110px; height: 110px;
  border-radius: 50%;
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800; color: var(--text);
  position: relative;
}
.donut-chart::after {
  content: '';
  position: absolute;
  width: 66px; height: 66px;
  border-radius: 50%;
  background: var(--surface);
}
.donut-chart span { position: relative; z-index: 1; }
.donut-legend { display: flex; flex-direction: column; gap: 8px; }
.donut-legend-item { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.donut-legend-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }

.alerts-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.alerts-list li {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13.5px;
}
.alerts-list .alert-icon { font-size: 16px; }

@media (max-width: 900px) {
  .stat-cards-row { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid-2col { grid-template-columns: 1fr; }
}

/* ===== Patients page stat cards ===== */
.patients-view-wrapper {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  min-width: 0;
  padding: 20px 24px 0;
}
.patients-stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 18px;
}
.patients-view-wrapper .layout {
  flex: 1;
  min-height: 0;
  margin: 0 -24px;
  border-top: 1px solid var(--border);
}

@media (max-width: 900px) {
  .patients-stats-row { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Calendar and notifications panel on the home screen ===== */
.home-dashboard {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-top: 28px;
  align-items: start;
}
.home-calendar-card, .home-notifications-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.calendar-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.calendar-nav-group { display: flex; align-items: center; gap: 6px; }
.calendar-nav-group select {
  padding: 7px 10px;
  border-radius: 7px;
  border: 1.5px solid var(--border);
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  background: var(--bg);
}

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-dim);
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  max-width: 640px;
  margin: 0 auto;
  margin-bottom: 6px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  max-width: 640px;
  margin: 0 auto;
}
.day-cell {
  aspect-ratio: 1;
  max-width: 84px;
  max-height: 84px;
  margin: 0 auto;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  gap: 3px;
  padding: 6px 2px;
  border-radius: 8px;
  border: 1.5px solid transparent;
  cursor: pointer;
  font-size: 13px;
  font-family: 'Inter', sans-serif;
  color: var(--text);
  background: transparent;
}
.day-cell:hover { background: var(--blue-050); }
.day-cell.other-month { opacity: 0.32; }
.day-cell.is-today { border-color: var(--blue-800); font-weight: 700; }
.day-badge {
  background: var(--gold-500);
  color: white;
  border-radius: 10px;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  line-height: 1.5;
}

.home-notifications-card h3 { margin: 0 0 4px; font-size: 15.5px; color: var(--blue-900); }
.notif-date { font-size: 12.5px; color: var(--text-dim); margin-bottom: 14px; font-weight: 600; }
.notif-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.notif-item {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.notif-item:hover { border-color: var(--blue-800); background: var(--blue-050); }
.notif-item-time { font-size: 12px; font-weight: 700; color: var(--gold-600); }
.notif-item-patient { font-size: 14px; font-weight: 700; }
.notif-item-doctor { font-size: 12px; color: var(--text-dim); }

@media (max-width: 900px) {
  .home-dashboard { grid-template-columns: 1fr; }
}

/* ===== Home screen (dashboard) ===== */
.home-view { width: 100%; }
.home-hero { text-align: left; margin-bottom: 24px; }
.home-hero h2 { font-size: 24px; margin: 0 0 4px; color: var(--text); }
.home-hero p { color: var(--text-dim); margin: 0; font-size: 14px; }

.home-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 18px;
}
.home-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 28px 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  font-family: 'Inter', sans-serif;
  transition: transform 0.12s ease, border-color 0.15s ease;
}
.home-card:hover { transform: translateY(-3px); border-color: var(--blue-800); }
.home-card:active { transform: translateY(0); }
.home-card-icon { font-size: 34px; }
.home-card-title { font-size: 15.5px; font-weight: 700; color: var(--text); }
.home-card-count { font-size: 12.5px; color: var(--gold-600); font-weight: 700; }

@media (max-width: 720px) {
  .home-cards { grid-template-columns: repeat(2, 1fr); }
}

/* ===== Search box (wide, standalone) ===== */
.search-box.wide { padding: 0 0 18px; border-bottom: none; max-width: 420px; }

/* ===== Data tables (appointments / records / prescriptions) ===== */
.date-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}
.date-nav input[type="date"] {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  font-family: 'Inter', sans-serif;
  background: var(--surface);
}
.date-nav input[type="date"]:focus { outline: none; border-color: var(--blue-800); box-shadow: var(--focus-ring); }
.date-nav select {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  background: var(--surface);
  color: var(--text);
}
.date-nav select:focus { outline: none; border-color: var(--blue-800); box-shadow: var(--focus-ring); }
.date-nav > .btn { align-self: flex-end; }
.date-label { color: var(--text-dim); font-size: 13.5px; font-weight: 600; }

/* Quick-search box injected above searchable tables (see js/nav.js initTableQuickSearch) */
.table-quick-search {
  position: relative;
  margin-bottom: 10px;
  max-width: 320px;
}
.table-quick-search::before {
  content: '🔍';
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12.5px;
  opacity: 0.5;
  pointer-events: none;
}
.table-quick-search input {
  width: 100%;
  padding: 9px 12px 9px 34px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  background: var(--surface);
}
.table-quick-search input:focus {
  outline: none;
  border-color: var(--blue-800);
  box-shadow: var(--focus-ring);
}
.table-quick-search-empty-row td {
  text-align: center !important;
  color: var(--text-dim);
  padding: 24px 16px !important;
  font-style: italic;
  position: static !important;
}

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: auto;
  max-height: 74vh;
  position: relative;
}
.data-table { width: 100%; min-width: 640px; border-collapse: collapse; }
.data-table th {
  background: var(--blue-050);
  color: var(--blue-900);
  font-size: 12.5px;
  font-weight: 700;
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 2;
}
.data-table td {
  padding: 12px 16px;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table th:first-child, .data-table td:first-child {
  position: sticky;
  left: 0;
}
.data-table th:first-child { background: var(--blue-050); z-index: 3; }
.data-table td:first-child { background: var(--surface); z-index: 1; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #F7FAFD; }
.data-table tbody tr:hover td:first-child { background: #F7FAFD; }
.data-table .cell-link { cursor: pointer; color: var(--blue-800); font-weight: 600; }
.data-table .cell-link:hover { text-decoration: underline; }
.data-table .row-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.data-table .row-actions button {
  font-family: 'Inter', sans-serif;
  font-size: 12px;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  cursor: pointer;
}
.data-table .row-actions button:hover { border-color: var(--blue-800); color: var(--blue-800); }
.data-table .row-actions button.danger { border-color: var(--danger); color: var(--danger); }
.data-table .row-actions button.danger:hover { border-color: var(--danger); color: var(--danger); background: var(--danger-bg); }

/* Status badges */
.badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
}
.badge-scheduled { background: #E4EEF7; color: #1F6FB2; }
.badge-completed { background: #E7F3EB; color: var(--success); }
.badge-cancelled { background: var(--danger-bg); color: var(--danger); }
.badge-no_show { background: #F1EAE0; color: var(--gold-600); }
.badge-paid { background: #E7F3EB; color: var(--success); }
.badge-partial { background: #E4EEF7; color: #1F6FB2; }
.badge-unpaid { background: #F1EAE0; color: var(--gold-600); }

/* Phase 9: Visit Type badges — deliberately distinct from the status-badge
   palette above (blue/green/red/gold) so Visit Type and Status never read
   as the same kind of information at a glance. */
.badge-visit-new_consultation { background: var(--border); color: var(--text-dim); }
.badge-visit-follow-up { background: var(--icon-purple-bg); color: var(--icon-purple); }

/* Phase 9: banner shown inside the appointment modal when it's in
   "Book Follow-up" mode, naming the original appointment it follows up on. */
.follow-up-banner {
  background: var(--icon-purple-bg);
  color: var(--icon-purple);
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 600;
}

/* Phase 7.3: Support ticket status/priority badges — used by both the
   tenant Support Center (public/js/support.js) and the Platform Admin
   Support page (public/js/platform.js), so the color language stays the
   same on both sides of one conversation. */
.badge-status-open { background: var(--blue-050); color: var(--blue-900); }
.badge-status-in_progress { background: var(--teal-050); color: var(--gold-600); }
.badge-status-waiting_on_clinic { background: #F1EAE0; color: var(--gold-600); }
.badge-status-resolved { background: #E7F3EB; color: var(--success); }
.badge-status-closed { background: var(--border); color: var(--text-dim); }

.badge-priority-low { background: var(--border); color: var(--text-dim); }
.badge-priority-normal { background: var(--blue-050); color: var(--blue-900); }
.badge-priority-high { background: #F1EAE0; color: var(--gold-600); }
.badge-priority-urgent { background: var(--danger-bg); color: var(--danger); }

/* Phase 10: Notification Delivery status badges — the same small, clear
   five-value status model as db/notificationDeliveriesStore.js (pending,
   processing, sent, failed, skipped), reusing the existing badge color
   language (green=success, red=failure, gold=in-flight/attention,
   grey=inert) instead of inventing a new palette. */
.badge-sent { background: #E7F3EB; color: var(--success); }
.badge-failed { background: var(--danger-bg); color: var(--danger); }
.badge-skipped { background: var(--border); color: var(--text-dim); }
.badge-pending, .badge-processing { background: #F1EAE0; color: var(--gold-600); }

/* Phase 5.1: per-tenant module override rows (Create Tenant modal + Tenant
   Details "Modules" section). Each row is a plan-state label, an explicit
   tri-state control, and a plainly-worded effective-state badge — three
   distinct states (Inherited / Override-Enabled / Override-Disabled), never
   an ambiguous single on/off toggle. */
.module-override-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.module-override-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
}
.module-override-row.not-implemented { opacity: .6; }
.module-override-name { font-weight: 600; }
.module-override-name .hint { font-weight: 400; }
.module-plan-state { font-size: 11px; color: var(--text-dim); white-space: nowrap; }
.module-override-row select { padding: 5px 8px; font-size: 12.5px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); }
.module-effective-badge { white-space: nowrap; }
.module-effective-badge.badge-on { background: #E7F3EB; color: var(--success); }
.module-effective-badge.badge-off { background: var(--danger-bg); color: var(--danger); }
@media (max-width: 640px) {
  .module-override-row { grid-template-columns: 1fr; }
}

/* ===== Panel toolbar (search/filter bars above tables: Users, Invoices, Credit
   Notes, Activity Log, and any other admin/list toolbar) ===== */
.panel-toolbar {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}
.panel-toolbar input[type="text"],
.panel-toolbar input[type="search"],
.panel-toolbar input[type="date"],
.panel-toolbar select {
  padding: 9px 12px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  color: var(--text);
}
.panel-toolbar input[type="text"]:focus,
.panel-toolbar input[type="search"]:focus,
.panel-toolbar input[type="date"]:focus,
.panel-toolbar select:focus {
  outline: none;
  border-color: var(--blue-800);
  box-shadow: var(--focus-ring);
}
.panel-toolbar .btn,
.panel-toolbar .btn-sm { white-space: nowrap; }

/* A single label+control column inside a .panel-toolbar (e.g. Reports filters),
   replacing raw "<label>X</label><br><input>" layouts. */
.filter-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.filter-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}
.btn-sm { padding: 7px 14px; font-size: 13px; }

/* Condensed record/prescription lists inside a patient's file or a doctor's profile */
.record-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.record-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.record-item:hover { border-color: var(--blue-800); }
.record-item-main strong { display: block; font-size: 14px; }
.record-item-main span { font-size: 12.5px; color: var(--text-dim); }
.record-item-date { font-size: 12.5px; color: var(--text-dim); white-space: nowrap; }

/* ===== Phase 7.3: Support Ticket Center ===== */

/* Ticket list items reuse .patient-card (same .sidebar/.patient-list shell
   as Patients) but add a right-aligned status badge slot instead of an
   avatar+phone-number line. */
.ticket-card { justify-content: space-between; }
.ticket-card-badges { flex-shrink: 0; }

/* Ticket detail panel — deliberately its own class rather than reusing
   .patient-view, since that class carries a 220px-tabs + content grid
   meant for folder-tab detail pages, which a single-column ticket
   conversation doesn't need. */
.ticket-detail-view {
  max-width: 820px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.ticket-detail-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 8px;
}
.ticket-detail-header h2 { margin: 0 0 4px; font-size: 20px; }
.ticket-detail-badges { display: flex; gap: 8px; flex-shrink: 0; white-space: nowrap; }
.ticket-description {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 14px;
  white-space: pre-wrap;
  margin: 0 0 8px;
}

.ticket-conversation {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  padding: 4px 2px;
  margin-bottom: 12px;
}
.ticket-message {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
}
/* Tenant messages align left in the tenant app (they're "you"); platform
   staff replies align right and are tinted blue, so the two sides of the
   conversation are visually distinguishable at a glance on both ends. */
.ticket-message-tenant { align-self: flex-start; }
.ticket-message-platform { align-self: flex-end; background: var(--blue-050); border-color: var(--blue-050); }
.ticket-message-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.ticket-message-head strong { color: var(--text); font-size: 12.5px; }
.ticket-message-body { font-size: 14px; white-space: pre-wrap; }

/* Platform Admin side (public/platform.html's ticket modal) reuses this same
   conversation styling for its "Notes" thread, so a platform-authored
   reply looks the same shade of blue on both sides of the conversation. */
.ticket-notes { display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow-y: auto; margin-bottom: 10px; }
.ticket-note {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13.5px;
}
.ticket-note-tenant { background: var(--bg); }
.ticket-note-platform { background: var(--blue-050); border-color: var(--blue-050); }

/* ===== Repeatable rows (locations/schedule/medications forms) ===== */
.repeatable-rows { display: flex; flex-direction: column; gap: 10px; margin-bottom: 10px; }
.repeatable-row {
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  position: relative;
}
.repeatable-row input, .repeatable-row select {
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
}
.repeatable-row .remove-row-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  color: var(--danger);
  font-size: 16px;
  cursor: pointer;
  line-height: 1;
}
.locations-row { grid-template-columns: 1fr 1fr; }
.schedule-row { grid-template-columns: 1fr 1fr 1fr 1fr; }
.medication-row { grid-template-columns: 1.5fr 1fr 1fr 1fr; }
.social-link-row { grid-template-columns: 1fr 2fr; }
.room-row { grid-template-columns: 1fr 1fr; }
.currency-row { grid-template-columns: 1fr 1fr 1fr; }
.invoice-line-item-row { grid-template-columns: 2fr 1fr 1fr 1fr 1fr; }
.discount-rule-row { display:flex; align-items:center; gap:12px; padding:8px 0; border-bottom:1px solid var(--border); }
.discount-rule-row .role-name { flex:1; font-weight:600; font-size:13.5px; }
.discount-rule-row input {
  width: 90px;
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
  background: var(--surface);
}
.discount-rule-row input:focus { outline: none; border-color: var(--blue-800); box-shadow: var(--focus-ring); }

.insurance-row-block { display: flex; flex-direction: column; gap: 10px; }
.insurance-row-block .ins-company {
  padding: 8px 10px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 13.5px;
}
.ins-fees-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.ins-fees-grid label { font-size: 11.5px; font-weight: 600; color: var(--text-dim); display: block; margin-bottom: 4px; }
.ins-fees-grid input {
  width: 100%;
  padding: 7px 8px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
}

.checkbox-list {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 18px;
  padding: 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  margin-bottom: 6px;
}
.checkbox-list label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.checkbox-list input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; }

.section-subtitle {
  font-size: 14px;
  font-weight: 700;
  margin: 18px 0 10px;
  color: var(--blue-900);
}

.form-row.four-cols { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.form-row.four-cols label { font-size: 12.5px; font-weight: 600; color: var(--text-dim); }

.modal-wide { max-width: 720px; }
.modal-xl { max-width: 940px; }

/* Phase 5.1: Tenant Details view (Platform Portal) */
.tenant-details-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; margin-bottom: 18px; }
.tenant-details-section { margin-bottom: 18px; }
.tenant-details-section h4 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-dim); }
.tenant-details-field { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0; border-bottom: 1px dashed var(--border); font-size: 13.5px; }
.tenant-details-field span:first-child { color: var(--text-dim); }
.tenant-details-field span:last-child { font-weight: 600; text-align: right; }
.tenant-details-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 18px; }
@media (max-width: 700px) {
  .tenant-details-grid { grid-template-columns: 1fr; }
}

/* ===== Finance cards (doctor account) ===== */
.finance-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.finance-card {
  background: var(--blue-050);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
}
.finance-card .value { font-size: 22px; font-weight: 900; color: var(--blue-900); font-family: 'Inter', sans-serif; }
.finance-card .label { font-size: 12px; color: var(--text-dim); margin-top: 4px; }

/* ===== Prescription print view ===== */
.rx-print-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  border-bottom: 2px solid var(--blue-900);
  padding-bottom: 14px;
  margin-bottom: 18px;
}
.rx-print-header h3 { margin: 0; color: var(--blue-900); }
.rx-print-header .doctor-specialty { color: var(--text-dim); font-size: 13px; }
.rx-print-meta { text-align: right; font-size: 13px; color: var(--text-dim); }
.rx-symbol { font-size: 28px; font-weight: 900; color: var(--gold-500); font-family: 'Inter', sans-serif; margin-right: 6px; }
.rx-med-list { list-style: none; margin: 0; padding: 0; }
.rx-med-list li {
  padding: 12px 0;
  border-bottom: 1px dashed var(--border);
}
.rx-med-list li:last-child { border-bottom: none; }
.rx-med-name { font-weight: 700; font-size: 15px; }
.rx-med-details { color: var(--text-dim); font-size: 13px; margin-top: 3px; }

.invoice-items { width: 100%; border-collapse: collapse; margin: 16px 0; }
.invoice-items th, .invoice-items td { text-align: left; padding: 8px 4px; border-bottom: 1px solid var(--border); font-size: 14px; }
.invoice-items th { color: var(--text-dim); font-size: 12px; font-weight: 700; }
.invoice-totals { margin-top: 10px; margin-left: auto; max-width: 280px; }
.invoice-totals-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.invoice-totals-row.grand-total { border-top: 2px solid var(--blue-900); font-weight: 800; font-size: 16px; margin-top: 6px; padding-top: 10px; }
.invoice-totals-row.balance-due { color: var(--danger); font-weight: 800; }

@media print {
  body * { visibility: hidden; }
  .printable-content, .printable-content * { visibility: visible; }
  .printable-content { position: absolute; top: 0; left: 0; width: 100%; }
  .no-print { display: none !important; }
}

@media (max-width: 720px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; min-width: 0; max-height: 40vh; border-right: none; border-bottom: 1px solid var(--border); }
  .info-grid, .two-cols, .form-row.three-cols, .form-row.four-cols,
  .locations-row, .schedule-row, .medication-row, .social-link-row, .room-row,
  .ins-fees-grid, .patients-stats-row, .finance-cards {
    grid-template-columns: 1fr;
  }
  .full-view { padding: 16px; }
  .patients-view-wrapper { padding: 14px 14px 0; }
  .patients-view-wrapper .layout { margin: 0 -14px; }
  .main-topbar { padding: 14px 16px; flex-wrap: wrap; gap: 10px; }
  .main-topbar h2 { font-size: 16px; }
  .modal-body { padding: 16px; }
  .form-section-header { font-size: 12px; padding: 0 0 6px; }
  .home-dashboard { grid-template-columns: 1fr; }
  .donut-row { flex-direction: column; align-items: flex-start; gap: 14px; }
  .table-wrap { max-height: 60vh; }
}

@media (max-width: 480px) {
  .stat-cards-row { grid-template-columns: 1fr; }
  .sidebar-logo-text strong { font-size: 13px; }
  .stat-value { font-size: 18px; }
  .btn { padding: 9px 14px; font-size: 13px; }
  .main-topbar .btn-primary { padding: 8px 12px; font-size: 12.5px; }
}
