/* MH² brand – portal-wide palette (#2C5169 + black/white; matches CRM Stitch direction) */
:root {
  --mh2-primary: #2c5169;
  --mh2-primary-light: #3d6a86;
  --mh2-primary-dark: #234a61;
  --mh2-accent: #5a7a91;
  --mh2-bg: #f9f9f9;
  --mh2-surface: #ffffff;
  --mh2-text: #000000;
  --mh2-text-muted: #5f5f5f;
  --mh2-muted: #6b7280;
  --mh2-border: #e2e2e2;
  --mh2-sidebar-bg: #ffffff;
  --mh2-sidebar-border: #e2e2e2;
  --mh2-error: #b91c1c;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
  --font: "DM Sans", system-ui, sans-serif;
  --sidebar-width: 240px;
}

/* Record Meeting — live video grid */
.rm-meeting-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.5rem;
}
.rm-video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem;
  margin-top: 0.75rem;
}
.rm-video-tile {
  background: var(--mh2-bg);
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius);
  padding: 0.5rem;
}
.rm-video-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--mh2-text-muted);
  margin-bottom: 0.35rem;
}
.rm-video-host {
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.rm-artifacts-list {
  margin: 0.35rem 0 0.75rem;
  padding-left: 1.25rem;
  font-size: 0.9rem;
  color: var(--mh2-text-muted);
}
.rm-artifacts-list li {
  margin: 0.2rem 0;
}
.rm-workflow-card {
  border: 1px solid var(--mh2-border);
}
.rm-workflow-card--locked {
  opacity: 0.72;
}
.rm-workflow-card--active {
  border-color: var(--mh2-primary);
  box-shadow: 0 0 0 1px rgba(44, 81, 105, 0.12);
  opacity: 1;
}
.rm-workflow-card--complete .rm-step-num {
  background: var(--mh2-primary);
  color: #fff;
}
.rm-step-header {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
}
.rm-step-num {
  flex-shrink: 0;
  width: 1.75rem;
  height: 1.75rem;
  border-radius: 999px;
  background: var(--mh2-border);
  color: var(--mh2-text);
  font-size: 0.85rem;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-top: 0.1rem;
}
.rm-step-title {
  font-size: 1rem !important;
  margin: 0 0 0.15rem;
}
.rm-step-sub {
  margin: 0;
  font-size: 0.88rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 16px;
  color: var(--mh2-text);
  background: var(--mh2-bg);
  -webkit-font-smoothing: antialiased;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.view {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.hidden {
  display: none !important;
}

.view.hidden {
  display: none;
}

/* Login */
#login-view {
  background: var(--mh2-bg);
}

.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--mh2-surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px;
  border: 1px solid var(--mh2-border);
}

.login-logo {
  max-width: 160px;
  height: auto;
  margin-bottom: 16px;
  display: block;
}

.login-header h1 {
  margin: 0 0 8px 0;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--mh2-primary-dark);
}

.login-header p {
  margin: 0 0 28px 0;
  color: var(--mh2-primary);
  font-size: 0.95rem;
}

.login-form label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--mh2-text);
  margin-bottom: 6px;
}

.login-form input {
  width: 100%;
  padding: 12px 14px;
  font: inherit;
  font-size: 1rem;
  border: 1px solid var(--mh2-border);
  border-radius: 8px;
  margin-bottom: 18px;
  background: var(--mh2-surface);
  color: var(--mh2-text);
}

.login-form input:focus {
  outline: none;
  border-color: var(--mh2-primary-light);
  box-shadow: 0 0 0 3px rgba(44, 81, 105, 0.2);
}

.login-form .btn {
  width: 100%;
  padding: 12px;
  margin-top: 8px;
}

.error {
  color: var(--mh2-error);
  font-size: 0.875rem;
  margin: 0 0 12px 0;
}

.error.hidden {
  display: none;
}

.btn {
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  transition: background 0.2s, color 0.2s;
}

.btn-primary {
  background: var(--mh2-primary);
  color: white;
}

.btn-primary:hover {
  background: var(--mh2-primary-dark);
}

.login-google-required {
  margin-bottom: 16px;
  font-size: 0.9rem;
  color: var(--mh2-muted);
}

.login-google-wrap {
  margin-top: 20px;
  text-align: center;
}
.login-divider {
  display: block;
  margin: 14px 0 12px;
  font-size: 0.875rem;
  color: var(--mh2-muted);
}
.btn-google {
  display: inline-block;
  width: 100%;
  padding: 12px;
  text-align: center;
  font-size: 1rem;
  color: #1f2937;
  background: #fff;
  border: 1px solid var(--mh2-border);
  border-radius: 8px;
  text-decoration: none;
  box-sizing: border-box;
}
.btn-google:hover {
  background: #f9fafb;
  border-color: #9ca3af;
}

.btn-ghost {
  background: transparent;
  color: var(--mh2-primary);
}

.btn-ghost:hover {
  background: var(--mh2-border);
  color: var(--mh2-primary-dark);
}

/* Portal shell – left sidebar + content; only main area scrolls */
.portal-shell {
  display: flex;
  flex-direction: row;
  align-items: stretch;
  justify-content: flex-start;
  min-height: 100vh;
  max-height: 100vh;
  overflow: hidden;
  padding: 0 !important;
  background: var(--mh2-bg);
}

.sidebar {
  width: var(--sidebar-width);
  flex-shrink: 0;
  min-height: 100vh;
  max-height: 100vh;
  background: var(--mh2-sidebar-bg);
  border-right: 1px solid var(--mh2-sidebar-border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 20px 16px;
  border-bottom: 1px solid var(--mh2-border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

.sidebar-brand {
  font-weight: 600;
  font-size: 1rem;
  color: var(--mh2-text);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.sidebar-nav .nav-link,
.sidebar-nav .nav-link-footer,
.nav-link-footer {
  display: block;
  padding: 10px 16px;
  margin: 2px 8px;
  border-radius: var(--radius-sm);
  color: var(--mh2-text);
  text-decoration: none;
  font-family: var(--font);
  font-size: 0.9375rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}

.sidebar-nav .nav-link:hover,
.nav-link-footer:hover {
  background: var(--mh2-bg);
  color: var(--mh2-primary-dark);
}

.sidebar-nav .nav-link.active,
.nav-link-footer.active {
  background: rgba(44, 81, 105, 0.1);
  color: var(--mh2-primary-dark);
}

.nav-group { margin: 4px 0; }

.nav-group-header {
  display: flex;
  align-items: center;
  margin: 2px 8px 0;
  border-radius: var(--radius-sm);
  min-height: 40px;
}

.nav-group-header .nav-link { flex: 1; margin: 0; min-width: 0; }

.nav-group-toggle {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  padding: 0;
  margin: 0 4px 0 0;
  border: none;
  background: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
  color: var(--mh2-text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-group-toggle:hover { color: var(--mh2-text); background: var(--mh2-bg); }

.nav-group-arrow {
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
}

.nav-group.collapsed .nav-group-arrow { transform: rotate(-90deg); }

.nav-sublist {
  list-style: none;
  margin: 0;
  padding: 4px 0 4px 8px;
  border-left: 1px solid var(--mh2-border);
  margin-left: 20px;
}

.nav-group.collapsed .nav-sublist { display: none; }

.nav-sublink {
  display: block;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  color: var(--mh2-text);
  text-decoration: none;
  font-size: 0.875rem;
}

.nav-sublink:hover { background: var(--mh2-bg); color: var(--mh2-primary-dark); }

.nav-sublink.active {
  background: rgba(44, 81, 105, 0.1);
  color: var(--mh2-primary-dark);
  font-weight: 500;
}

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--mh2-border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-username {
  font-size: 0.875rem;
  color: var(--mh2-text-muted);
  margin: 0;
}

.btn-sidebar { width: 100%; justify-content: center; }

.portal-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow: auto;
  background: var(--mh2-bg);
  max-height: 100vh;
}

.page-content {
  flex: 1;
  padding: 24px 32px;
  overflow: auto;
  min-height: 0;
}

/* CRM detail: fill main column height and scroll inside #crm-detail-stack (see #page-crm rules). */
.page-content:has(#page-crm.crm-stitch.active) {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.page { display: none; }
.page.active { display: block; }

.page-title {
  margin: 0 0 20px 0;
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--mh2-text);
}

/* Cards */
.card {
  background: var(--mh2-surface);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  border: 1px solid var(--mh2-border);
  box-shadow: var(--shadow);
}

.card h2, .card h3 {
  margin: 0 0 16px 0;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--mh2-primary-dark);
}

.welcome-card h1 {
  margin: 0 0 8px 0;
  font-size: 1.5rem;
  color: var(--mh2-primary-dark);
}

.tagline {
  color: var(--mh2-primary);
  margin: 0 0 16px 0;
}

.cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card .stat-label {
  margin: 0 0 4px 0;
  font-size: 0.9rem;
  color: var(--mh2-primary);
}

.stat-card .stat-value {
  margin: 0;
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--mh2-primary-dark);
}

.charts-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 24px;
  margin-bottom: 24px;
}

.chart-card {
  min-height: 280px;
}

.chart-card canvas {
  max-height: 240px;
}

/* Dashboard */
.dashboard-top-row {
  grid-template-columns: 1fr 1fr;
  align-items: stretch;
}

.dashboard-revenue-card {
  text-align: center;
}

.dashboard-revenue-card .dashboard-box-title,
.dashboard-patients-card .dashboard-box-title {
  margin: 0 0 16px 0;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--mh2-primary-dark);
}

.dashboard-patients-card .dashboard-box-title {
  text-align: center;
}

.dashboard-revenue-sub {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.dashboard-sub-box {
  padding: 12px;
  background: var(--mh2-bg, #f8fafc);
  border-radius: var(--radius);
  border: 1px solid var(--mh2-border);
  text-align: center;
}

.dashboard-sub-box .dashboard-sub-title {
  margin: 0 0 8px 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--mh2-primary);
}

.dashboard-stat-value {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--mh2-primary-dark);
}

.dashboard-patients-tables {
  display: grid;
  grid-template-columns: minmax(min-content, 1fr) minmax(min-content, 1fr);
  gap: 24px;
  overflow-x: auto;
  min-width: 0;
}

.dashboard-table-title {
  margin: 0 0 12px 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--mh2-primary-dark);
  text-align: center;
}

.dashboard-patient-table-wrap {
  min-width: 0;
}

.dashboard-count-table { margin: 0; white-space: nowrap; }
.dashboard-count-table td { padding: 6px 12px 6px 0; }
.dashboard-count-label { font-weight: 600; }
.dashboard-count-indent { padding-left: 20px !important; }
.dashboard-count-indent-nested { padding-left: 40px !important; }

/* Keep Revenue and Patients cards same height */
.dashboard-revenue-card,
.dashboard-patients-card {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.dashboard-revenue-card .dashboard-revenue-sub,
.dashboard-patients-card .dashboard-patients-tables {
  flex: 1;
  min-height: 0;
}

.task-reporting-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-bottom: 24px;
}

.task-reporting-summary .data-table {
  margin: 0;
}

/* Fixed height + scroll for the top 3 summary tables; Total stays at bottom */
.task-reporting-table-wrap {
  height: 260px;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.task-reporting-summary-table {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.task-reporting-summary-table thead {
  flex-shrink: 0;
  display: block;
}

.task-reporting-summary-table thead tr {
  display: table;
  width: 100%;
  table-layout: fixed;
}

.task-reporting-summary-table tbody {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  display: block;
  scrollbar-width: thin;
  scrollbar-color: transparent transparent;
}

.task-reporting-table-wrap:hover .task-reporting-summary-table tbody {
  scrollbar-color: rgba(0, 0, 0, 0.25) transparent;
}

.task-reporting-summary-table tbody::-webkit-scrollbar {
  width: 8px;
}

.task-reporting-summary-table tbody::-webkit-scrollbar-track {
  background: transparent;
}

.task-reporting-summary-table tbody::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 4px;
}

.task-reporting-table-wrap:hover .task-reporting-summary-table tbody::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.25);
}

.task-reporting-table-wrap:hover .task-reporting-summary-table tbody::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.4);
}

.task-reporting-summary-table tbody tr {
  display: table;
  width: 100%;
  table-layout: fixed;
}

.task-reporting-summary-table tfoot {
  flex-shrink: 0;
  display: block;
}

.task-reporting-summary-table tfoot tr {
  display: table;
  width: 100%;
  table-layout: fixed;
}

.task-reporting-summary-table th:first-child,
.task-reporting-summary-table td:first-child {
  width: 65%;
}

.task-reporting-summary-table th.num,
.task-reporting-summary-table td.num {
  width: 35%;
}

.report-total-row {
  font-weight: 600;
  border-top: 1px solid var(--mh2-border);
}

.task-reporting-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
  margin-bottom: 16px;
}

.task-reporting-filters label {
  font-size: 0.875rem;
  font-weight: 500;
  margin: 0;
  color: var(--mh2-text);
}

.task-reporting-filters select {
  min-width: 140px;
  padding: 8px 12px;
  font: inherit;
  font-size: 0.9rem;
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  background: var(--mh2-surface);
  color: var(--mh2-text);
}

/* Home page: News/Updates and Wins cards */
.home-two-col {
  align-items: start;
}

.home-list-card {
  min-height: 200px;
}

.home-list-card h3 {
  margin: 0 0 14px 0;
}

.home-bullet-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.home-bullet-list li {
  position: relative;
  padding: 6px 0 6px 18px;
  font-size: 0.9375rem;
  line-height: 1.4;
  color: var(--mh2-text);
  border-bottom: 1px solid var(--mh2-border);
}

.home-bullet-list li:last-child {
  border-bottom: none;
}

.home-bullet-list li::before {
  content: "";
  position: absolute;
  left: 0;
  top: 12px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mh2-primary);
}

.home-wins-list li::before {
  background: var(--mh2-primary-light);
}

.meta {
  margin: 0 0 12px 0;
  font-size: 0.875rem;
  color: var(--mh2-primary);
}

.tables-list {
  list-style: none;
  margin: 0 0 24px 0;
  padding: 0;
}

.tables-list li {
  padding: 10px 12px;
  border-radius: 8px;
  font-family: ui-monospace, monospace;
  font-size: 0.9rem;
  border: 1px solid var(--mh2-border);
  margin-bottom: 8px;
  background: var(--mh2-bg);
}

/* Data tables (e.g. Patients page) */
.data-table-card {
  min-height: 200px;
}

.table-loading {
  margin: 0;
  font-size: 0.9rem;
  color: var(--mh2-primary);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.data-table th,
.data-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--mh2-border);
}

.data-table th {
  font-weight: 600;
  color: var(--mh2-primary-dark);
  background: rgba(44, 81, 105, 0.06);
}

.data-table tbody tr:hover {
  background: rgba(44, 81, 105, 0.04);
}

.data-table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.utilization-table-card-header {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
}
.utilization-table-card-header .muted {
  margin: 0;
  margin-right: auto;
}
.utilization-table-wrapper .utilization-scroll {
  overflow-x: auto;
  max-width: 100%;
}
.utilization-table-wrapper #utilization-table tr.utilization-total-row th,
.utilization-table-wrapper #utilization-table tr.utilization-total-row td {
  font-weight: 600;
  border-top: 2px solid var(--mh2-primary-dark);
}
.utilization-table-wrapper #utilization-table tr.utilization-pct-row th {
  font-weight: 500;
}
.utilization-table-wrapper #utilization-table {
  min-width: 600px;
}
/* Provider column only: no wrap, width fits names, solid background when sticky (use class so row 2 first cell isn't mistaken) */
.utilization-table-wrapper #utilization-table th.col-provider,
.utilization-table-wrapper #utilization-table td.col-provider {
  position: sticky;
  left: 0;
  background: var(--mh2-surface);
  z-index: 1;
  box-shadow: 2px 0 4px rgba(0,0,0,0.04);
  white-space: nowrap;
  width: 1%;
}
.utilization-table-wrapper #utilization-table thead th.col-provider {
  background: var(--mh2-surface);
}
.utilization-table-wrapper #utilization-table th[rowspan] {
  vertical-align: middle;
}
/* Center all data columns (to the right of Provider) */
.utilization-table-wrapper #utilization-table td:not(.col-provider),
.utilization-table-wrapper #utilization-table th:not(.col-provider) {
  text-align: center;
}
.utilization-table-wrapper #utilization-table td:not(.col-provider).num,
.utilization-table-wrapper #utilization-table th:not(.col-provider).num {
  text-align: center;
}
/* Vertical divider to the LEFT of each new week (right of Utilization % = 5th, 10th, 15th column in data rows) */
.utilization-table-wrapper #utilization-table tr:first-child th:nth-child(n+2):not(:last-child) {
  border-right: 2px solid var(--mh2-border);
}
/* Row 2: 5 cells per week; border after 5th (Utilization %) = columns 5, 10, 15 */
.utilization-table-wrapper #utilization-table tr:nth-child(2) th:nth-child(5n) {
  border-right: 2px solid var(--mh2-border);
}
/* Body: 1 Provider + 5 per week; border after Utilization % = columns 6, 11, 16 */
.utilization-table-wrapper #utilization-table tbody td:nth-child(5n+6) {
  border-right: 2px solid var(--mh2-border);
}

.utilization-ave-blocks {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}
.utilization-ave-block {
  display: flex;
  flex-direction: column;
  padding: 0.75rem 1rem;
  background: var(--mh2-surface);
  border: 1px solid var(--mh2-border);
  border-radius: 6px;
  min-width: 180px;
}
.utilization-ave-label {
  font-size: 0.85rem;
  color: var(--mh2-text-secondary);
  margin-bottom: 0.25rem;
}
.utilization-ave-value {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--mh2-primary-dark);
}

.utilization-capacity-spacer {
  height: 2rem;
  margin-top: 1.5rem;
}
.capacity-table-wrapper #capacity-table th.col-provider,
.capacity-table-wrapper #capacity-table td.col-provider {
  position: sticky;
  left: 0;
  background: var(--mh2-surface);
  z-index: 1;
  box-shadow: 2px 0 4px rgba(0,0,0,0.04);
  white-space: nowrap;
  width: 1%;
}
.capacity-table-wrapper #capacity-table thead th.col-provider {
  background: var(--mh2-surface);
}
.capacity-table-wrapper #capacity-table thead th,
#capacity-by-type-table thead th {
  white-space: nowrap;
}
#capacity-by-type-table td {
  text-align: center;
}
.capacity-table-wrapper #capacity-table td:not(.col-provider),
.capacity-table-wrapper #capacity-table th:not(.col-provider) {
  text-align: center;
}
.capacity-spacer-row .capacity-spacer-cell {
  height: 2rem;
  background: var(--mh2-bg);
  border: none;
  vertical-align: middle;
}
.capacity-table-wrapper #capacity-table tr.capacity-by-type th {
  font-weight: 600;
  color: var(--mh2-primary-dark);
}
.capacity-table-wrapper #capacity-table td.capacity-negative {
  color: var(--mh2-error);
}
#capacity-by-type-table td.capacity-negative {
  color: var(--mh2-error);
}

/* Conflicts: overlapping appointments tables */
.conflicts-table-card {
  margin-bottom: 1.5rem;
}
.conflicts-table-card:last-child {
  margin-bottom: 0;
}
.conflicts-table-heading {
  margin: 0 0 0.75rem 0;
  font-size: 1.1rem;
  color: var(--mh2-primary-dark);
}
.conflicts-scroll {
  overflow: auto;
  max-width: 100%;
  max-height: 320px;
}
.conflicts-table {
  min-width: 480px;
  width: 100%;
}
.conflicts-table td {
  vertical-align: top;
}
.conflicts-table thead th {
  position: sticky;
  top: 0;
  background: var(--mh2-surface);
  z-index: 1;
  box-shadow: 0 1px 0 var(--mh2-border);
}

/* AI Tool: context include controls + scrollable result */
.ai-tool-include {
  margin: 1rem 0;
  padding: 0.75rem 1rem;
  border: 1px solid var(--mh2-border);
  border-radius: 6px;
  background: var(--mh2-bg);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
}
.ai-tool-include-legend {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--mh2-text-secondary);
  margin-bottom: 0.25rem;
  width: 100%;
}
.ai-tool-include-option {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  color: var(--mh2-text-secondary);
}
.ai-tool-include-option input[type="checkbox"] {
  width: 1rem;
  height: 1rem;
}
.ai-tool-work-product {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  border: 1px solid var(--mh2-border);
  border-radius: 6px;
  background: var(--mh2-bg);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
}
.ai-tool-prompt-details {
  margin-top: 0.75rem;
  margin-bottom: 0.75rem;
}
.ai-tool-prompt-summary {
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--mh2-primary);
}
.ai-tool-prompt-input {
  margin-top: 0.5rem;
  resize: vertical;
}
.ai-tool-chat-input {
  margin-top: 0.5rem;
  margin-bottom: 0.75rem;
  resize: vertical;
}
.ai-tool-result {
  max-height: 320px;
  max-width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.75rem 1rem;
  background: #0b1020;
  color: #e4e7f5;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.9rem;
  white-space: pre-wrap;
  word-wrap: break-word;
}

/* AI Chat page */
.page-ai-chat .ai-chat-layout {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
  align-items: stretch;
}
.ai-chat-card {
  display: flex;
  flex-direction: column;
}
.ai-chat-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
}
.ai-chat-transcript {
  flex: 1;
  min-height: 200px;
  max-height: 400px;
  border: 1px solid var(--mh2-border);
  border-radius: 6px;
  padding: 0.75rem 1rem;
  overflow-y: auto;
  background: var(--mh2-surface);
}
.ai-chat-message {
  margin-bottom: 0.5rem;
  max-width: 100%;
}
.ai-chat-message-user {
  text-align: right;
}
.ai-chat-message-user .ai-chat-bubble {
  background: var(--mh2-primary);
  color: #fff;
  margin-left: auto;
}
.ai-chat-message-ai .ai-chat-bubble {
  background: #0b1020;
  color: #e4e7f5;
  margin-right: auto;
}
.ai-chat-bubble {
  display: inline-block;
  padding: 0.5rem 0.75rem;
  border-radius: 10px;
  white-space: pre-wrap;
  word-wrap: break-word;
  max-width: 100%;
}
.ai-chat-input-row {
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
}
.ai-chat-input {
  flex: 1;
  resize: vertical;
}
.ai-chat-send-btn {
  white-space: nowrap;
}

/* Patient Details page: center table values; diagnosis table left-aligned; encounters subtables side by side */
.patient-details-tables .data-table th,
.patient-details-tables .data-table td {
  text-align: center;
}
.patient-details-tables .patient-details-diagnosis-table th,
.patient-details-tables .patient-details-diagnosis-table td {
  text-align: left;
}
.patient-details-encounters-title {
  text-align: center;
}

/* Encounters section: two independent tables side by side (no Dashboard coupling) */
.pd-encounters-row {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 2rem;
  align-items: stretch;
}
.pd-encounters-block {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.pd-encounters-subtitle {
  margin: 0 0 0.5rem 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--mh2-primary-dark);
}
.pd-encounters-users-scroll {
  max-height: 320px;
}
/* Left table: vertical summary – compact, metric left, count right */
.pd-encounters-summary-table {
  width: max-content;
}
.pd-encounters-summary-table th,
.pd-encounters-summary-table td {
  text-align: left;
}
.pd-encounters-summary-table th:last-child,
.pd-encounters-summary-table td:last-child {
  padding-left: 1.25rem;
  width: 1%;
  white-space: nowrap;
  text-align: right;
}
/* Right table: unsigned by user – compact, user left, count right */
.pd-encounters-users-table {
  width: max-content;
}
.pd-encounters-users-table th:first-child,
.pd-encounters-users-table td:first-child {
  text-align: left;
}
.pd-encounters-users-table th:last-child,
.pd-encounters-users-table td:last-child {
  padding-left: 1.25rem;
  width: 1%;
  white-space: nowrap;
  text-align: right;
}

.conflicts-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.75rem;
}

.sales-forecast-top-actions {
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* Sales prototype: program × month table */
.sales-detail-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.sales-detail-filter label {
  font-weight: 500;
}
.sales-detail-filter select {
  min-width: 160px;
  padding: 6px 10px;
  font-size: 0.95rem;
}
.sales-detail-filter input {
  min-width: 140px;
  padding: 6px 10px;
  font-size: 0.95rem;
}

.sales-forecast-detail-filter {
  flex-wrap: wrap;
}

#sales-forecast-detail-export-btn {
  margin-left: auto;
}

.table-sort-btn {
  all: unset;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}
.table-sort-btn:focus-visible {
  outline: 2px solid rgba(31, 99, 187, 0.45);
  outline-offset: 2px;
  border-radius: 6px;
}
.table-sort-indicator {
  font-size: 0.8em;
  opacity: 0.75;
}
.sales-table-wrap {
  margin-top: 12px;
  max-height: 420px;
}

/* Admin page: layout + panels */
.admin-layout {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.admin-intro-card {
  border-left: 4px solid var(--mh2-primary);
}

.admin-intro-title {
  margin: 0 0 0.5rem 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--mh2-primary-dark);
}

.admin-meta-list {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.75rem 1.5rem;
  margin: 1rem 0 0 0;
}

.admin-meta-item {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.admin-meta-item dt {
  font-size: 0.8rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--mh2-text-secondary);
}

.admin-meta-item dd {
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  padding: 0.1rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  line-height: 1.4;
  white-space: nowrap;
}

.pill-soft {
  background: rgba(31, 99, 187, 0.07);
  color: var(--mh2-primary-dark);
  border: 1px solid rgba(31, 99, 187, 0.16);
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1.5rem;
}

@media (min-width: 960px) {
  .admin-grid {
    grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr);
    align-items: flex-start;
  }
}

.admin-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.admin-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.25rem;
}

.admin-panel-title {
  margin: 0 0 0.25rem 0;
}

.admin-panel-body {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.admin-table-wrap {
  max-height: 260px;
  overflow: auto;
  border-radius: 6px;
  border: 1px solid var(--mh2-border-subtle);
  background: var(--mh2-surface-soft);
  padding: 0.5rem;
}

.admin-table-wrap table {
  margin: 0;
}

.admin-form {
  margin-top: 0.5rem;
}

.admin-fieldset {
  border: 1px solid var(--mh2-border-subtle);
  border-radius: 8px;
  padding: 0.75rem 0.9rem 0.9rem;
}

.admin-fieldset-legend {
  padding: 0 0.4rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--mh2-text-secondary);
}

.form-row-inline {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.form-row-inline .form-field {
  flex: 1 1 220px;
}

.field-help {
  margin-top: 0.25rem;
  font-size: 0.8rem;
  color: var(--mh2-text-secondary);
}

.admin-actions {
  margin-top: 0.75rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
}
.sales-table-wrap-single {
  overflow: auto;
}
.sales-table-wrap-single .sales-program-table {
  min-width: 400px;
}
/* Sticky header and first column with solid backgrounds (no transparent) so content does not show through */
#sales-table thead th,
#sales-detail-table thead th {
  font-weight: 600;
  color: var(--mh2-primary-dark);
  background: var(--mh2-surface);
  position: sticky;
  top: 0;
  z-index: 2;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.06);
}
#sales-table th:first-child,
#sales-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--mh2-surface);
  width: 14rem;
  min-width: 14rem;
  max-width: 14rem;
  box-sizing: border-box;
  border-right: 2px solid var(--mh2-border);
}
#sales-table thead th:first-child {
  z-index: 3;
}
/* Detail table: wider first column for long names (e.g. "Deposit - Advanced Assessment") */
#sales-detail-table th:first-child,
#sales-detail-table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  background: var(--mh2-surface);
  width: 22rem;
  min-width: 22rem;
  max-width: 22rem;
  box-sizing: border-box;
  border-right: 2px solid var(--mh2-border);
}
#sales-detail-table thead th:first-child {
  z-index: 3;
}
.sales-program-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}
.sales-program-table th,
.sales-program-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--mh2-border);
}
.sales-program-table th.num,
.sales-program-table td.num {
  text-align: center;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.sales-program-table th:first-child,
.sales-program-table td:first-child {
  text-align: left;
}
.sales-program-table th:nth-child(2),
.sales-program-table td:nth-child(2) {
  white-space: nowrap;
  min-width: 9rem;
}
.sales-program-table td:first-child:not(.sales-section-label) {
  white-space: nowrap;
  min-width: 9rem;
}
.sales-program-table .sales-total-row td {
  border-top: 1px solid var(--mh2-border);
  padding-top: 12px;
}
.sales-program-table tr.sales-section-divider td {
  border-top-width: 3px;
  border-top-color: var(--mh2-primary, #2c5169);
}
.sales-program-table .sales-balance-row td {
  border-top: 2px solid var(--mh2-primary);
  padding-top: 12px;
}
.sales-program-table td.sales-subrow {
  padding-left: 28px;
}
.sales-program-table td.sales-subrow-nested {
  padding-left: 48px;
}
.sales-program-table td.sales-section-label {
  font-size: 1.15em;
  font-weight: 600;
  color: var(--mh2-primary, #2c5169);
  text-align: center;
  vertical-align: middle;
  width: 1%;
  white-space: nowrap;
  padding-left: 8px;
  padding-right: 12px;
  border-right: 1px solid var(--mh2-border, #e0e0e0);
}
/* Treatment wizard (single-page) */
.treatment-one-page .treatment-section {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--mh2-border);
}

.treatment-one-page .treatment-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

/* Treatment page – card-based layout */
.page-treatment .page-tagline.treatment-tagline {
  margin: -4px 0 20px 0;
  color: var(--mh2-text-muted);
  font-size: 0.95rem;
}

.page-treatment .treatment-form {
  max-width: 720px;
}

.page-treatment .treatment-form-layout {
  width: 100%;
}

.treatment-form-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.treatment-card {
  background: var(--mh2-surface);
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.treatment-card-header {
  padding: 14px 18px;
  background: rgba(44, 81, 105, 0.05);
  border-bottom: 1px solid var(--mh2-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.treatment-card-summary {
  list-style: none;
  cursor: pointer;
  user-select: none;
}

.treatment-card-summary::-webkit-details-marker {
  display: none;
}

.treatment-card-summary::after {
  content: "";
  display: inline-block;
  width: 0;
  height: 0;
  margin-left: 8px;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--mh2-text-muted);
  vertical-align: middle;
  transition: transform 0.2s ease;
}

details[open] .treatment-card-summary::after {
  transform: rotate(180deg);
}

.treatment-card-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--mh2-primary-dark);
}

.treatment-card-badge {
  font-size: 0.8rem;
  color: var(--mh2-text-muted);
  font-weight: 400;
}

.treatment-card-body {
  padding: 18px;
}

.treatment-top-row {
  display: grid;
  grid-template-columns: minmax(0, auto) minmax(260px, 1fr);
  gap: 16px;
  align-items: stretch;
}

@media (max-width: 720px) {
  .treatment-top-row {
    grid-template-columns: 1fr;
  }
}

.treatment-card-patient .treatment-card-body,
.treatment-card-plan-period .treatment-card-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.treatment-plan-period-dates {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
}

.treatment-plan-period-dates > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.treatment-sublabel {
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--mh2-text-muted);
}

.treatment-input {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  font-size: 1rem;
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  background: var(--mh2-surface);
  color: var(--mh2-text);
}

.treatment-input:focus {
  outline: none;
  border-color: var(--mh2-primary-light);
  box-shadow: 0 0 0 2px rgba(44, 81, 105, 0.15);
}

.treatment-date {
  width: 100%;
  max-width: 160px;
}

.treatment-label {
  display: block;
  font-weight: 500;
  color: var(--mh2-text);
  margin-bottom: 4px;
}

.treatment-options {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
}

.treatment-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  color: var(--mh2-text);
  cursor: pointer;
}

.treatment-option input {
  margin: 0;
  flex-shrink: 0;
}

.treatment-subsection {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--mh2-border);
}

.treatment-subsection-title {
  margin: 0 0 10px 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--mh2-text-muted);
}

/* Metabolic & lifestyle: 4 rows with header column */
.treatment-metabolic-grid {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.treatment-metabolic-row {
  display: grid;
  grid-template-columns: 100px 1fr;
  gap: 16px 20px;
  align-items: start;
  min-height: 2.5rem;
}

.treatment-metabolic-row + .treatment-metabolic-row {
  border-top: 1px solid var(--mh2-border);
  padding-top: 10px;
  margin-top: 6px;
}

.treatment-metabolic-header {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--mh2-primary-dark);
  padding-top: 2px;
}

.treatment-metabolic-options {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
}

.treatment-card-justification .treatment-card-header {
  flex-wrap: wrap;
}

.treatment-char-count {
  font-size: 0.8rem;
  color: var(--mh2-text-muted);
  font-weight: 400;
}

.treatment-textarea {
  width: 100%;
  min-height: 120px;
  padding: 12px 14px;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.5;
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  background: var(--mh2-surface);
  color: var(--mh2-text);
  resize: vertical;
}

.treatment-textarea:focus {
  outline: none;
  border-color: var(--mh2-primary-light);
  box-shadow: 0 0 0 2px rgba(44, 81, 105, 0.15);
}

.treatment-actions {
  padding: 8px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.treatment-submit {
  align-self: flex-start;
}

/* View Treatment Plans page */
.page-treatment-plans .page-tagline.treatment-plans-tagline {
  margin: -4px 0 20px 0;
  color: var(--mh2-text-muted);
  font-size: 0.95rem;
}

.treatment-plans-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 960px;
}

.treatment-plans-segmented {
  margin: 0 0 0.75rem;
}

.tp-contrib-due-banner {
  margin: 0;
  padding: 0.4rem 0.75rem;
  font-size: 0.84rem;
  font-weight: 600;
  line-height: 1.35;
  color: #92400e;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 8px;
  max-width: 28rem;
}

.tp-action-status {
  margin: 0.65rem 0 0;
  padding: 0.5rem 0.75rem;
  font-size: 0.88rem;
  border-radius: 8px;
  background: #eff6ff;
  color: #1e40af;
  border: 1px solid #93c5fd;
}

.tp-action-status.tp-action-status-success {
  background: #ecfdf5;
  color: #065f46;
  border-color: #6ee7b7;
}

.tp-action-status.tp-action-status-error {
  background: #fef2f2;
  color: #991b1b;
  border-color: #fca5a5;
}

.tp-contribution-row.tp-contrib-locked {
  opacity: 0.55;
}

.tp-contribution-row.tp-contrib-locked input[type="checkbox"] {
  cursor: not-allowed;
}

.tp-dx-readonly {
  flex: 1;
  min-width: 10rem;
  padding: 0.35rem 0.5rem;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--mh2-text, #0f172a);
  background: var(--mh2-surface-muted, #f8fafc);
  border: 1px solid var(--mh2-border-subtle, #e2e8f0);
  border-radius: 6px;
}

.treatment-plans-inline-editor {
  max-width: 52rem;
}

.treatment-plans-inline-editor .tp-plan-card {
  margin-bottom: 1rem;
  padding: 0.9rem 1rem 1rem;
}

.treatment-plans-inline-editor .tp-plan-card-title {
  margin: 0 0 0.35rem;
  font-size: 0.98rem;
  font-weight: 600;
  color: var(--mh2-text, #0f172a);
  letter-spacing: -0.01em;
}

.treatment-plans-inline-editor .tp-plan-card-lead {
  margin: 0 0 0.75rem;
  font-size: 0.82rem;
  line-height: 1.45;
  color: var(--mh2-text-muted, #64748b);
  max-width: 44rem;
}

.treatment-plans-inline-editor .tp-plan-subsection-title {
  margin: 0 0 0.3rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--mh2-text, #0f172a);
}

.treatment-plans-inline-editor .tp-plan-subsection-title-spaced {
  margin-top: 1.15rem;
}

.treatment-plans-inline-editor .tp-plan-subsection-lead {
  margin: 0 0 0.5rem;
  font-size: 0.8rem;
  line-height: 1.4;
  color: var(--mh2-text-muted, #64748b);
}

.treatment-plans-inline-editor .tp-plan-card-active {
  border-left: 3px solid var(--mh2-primary, #2c5169);
}

.treatment-plans-inline-editor .tp-plan-card-maintenance {
  border-left: 3px solid var(--mh2-primary-light, #3d6a86);
  background: var(--mh2-surface-muted, #f8fafc);
}

.treatment-plans-inline-editor .tp-care-team-card-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.65rem;
  margin-bottom: 0.15rem;
}

.treatment-plans-patient-card {
  max-width: 52rem;
}

.treatment-plan-bg-scroll-wrap {
  max-height: 15rem;
  overflow-y: auto;
  overflow-x: hidden;
  border: 1px solid var(--mh2-border-subtle, #e2e8f0);
  border-radius: 6px;
  background: var(--mh2-surface-muted, #f8fafc);
  padding: 0.5rem 0.65rem;
}

.treatment-plan-bg-scroll-wrap .treatment-plan-modal-cerbo {
  margin: 0;
  padding: 0;
  border: none;
  background: transparent;
}

#treatment-plan-iv-picker .crm-modal-backdrop {
  background: rgba(15, 23, 42, 0.48);
}

.treatment-plan-iv-picker-shell.crm-modal-content {
  overflow: hidden;
  max-width: 84rem;
  width: min(84rem, calc(100vw - 2rem));
}

.treatment-plan-iv-picker-shell {
  display: flex;
  flex-direction: column;
  max-height: min(90vh, 52rem);
  overflow: hidden;
  gap: 0.65rem;
  padding: 1.1rem 1.15rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--mh2-border-subtle, #e2e8f0);
  box-shadow:
    0 25px 50px -12px rgba(15, 23, 42, 0.18),
    0 0 0 1px rgba(15, 23, 42, 0.04);
  background: var(--mh2-surface, #fff);
}

.treatment-plan-iv-picker-header {
  flex-shrink: 0;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid var(--mh2-border-subtle, #e8ecf0);
}

.treatment-plan-iv-picker-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.treatment-plan-iv-picker-title {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.25;
  color: var(--mh2-text, #0f172a);
}

.treatment-plan-iv-picker-subtitle {
  margin: 0.5rem 0 0;
  font-size: 0.84rem;
  line-height: 1.45;
}

.treatment-plan-iv-picker-close {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  margin: -0.2rem -0.25rem 0 0;
  padding: 0;
  border: none;
  border-radius: 8px;
  font-size: 1.35rem;
  line-height: 1;
  color: var(--mh2-text-muted, #64748b);
  background: transparent;
  cursor: pointer;
  transition: color 0.12s ease, background 0.12s ease;
}

.treatment-plan-iv-picker-close:hover {
  color: var(--mh2-text, #0f172a);
  background: var(--mh2-surface-muted, #f1f5f9);
}

.treatment-plan-iv-picker-close:focus-visible {
  outline: 2px solid var(--mh2-primary, #2563eb);
  outline-offset: 2px;
}

.treatment-plan-iv-picker-footer {
  flex-shrink: 0;
  margin-top: 0.35rem;
  padding-top: 0.65rem;
  border-top: 1px solid var(--mh2-border-subtle, #e8ecf0);
  background: var(--mh2-surface, #fff);
}

.treatment-plan-iv-picker-error {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
}

.treatment-plan-iv-picker-freetext-label {
  display: block;
  font-size: 0.82rem;
  margin: 0.5rem 0 0.25rem;
}

.treatment-plan-iv-picker-freetext {
  margin-top: 0;
}

.treatment-plan-iv-picker-actions {
  margin-top: 0.85rem;
  justify-content: flex-end;
  gap: 0.5rem;
}

.treatment-plan-iv-picker-body-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.35rem 0.75rem 0.5rem 0.25rem;
  background: var(--mh2-surface-muted, #f8fafc);
  border-radius: 8px;
  border: 1px solid var(--mh2-border-subtle, #e2e8f0);
}

.tp-iv-modal-section {
  margin-bottom: 1.25rem;
  padding: 1rem 1rem 1.05rem;
  border-radius: 10px;
  border: 1px solid var(--mh2-border-subtle, #e2e8f0);
  background: var(--mh2-surface, #fff);
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.tp-iv-modal-section:last-child {
  margin-bottom: 0;
}

.tp-iv-section-title {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--mh2-text, #0f172a);
}

.tp-iv-section-lead {
  margin: 0 0 0.85rem;
  font-size: 0.8rem;
  line-height: 1.45;
}

.tp-iv-section-note {
  margin: 0 0 0.75rem;
  font-size: 0.8rem;
  line-height: 1.45;
}

.tp-iv-med-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.tp-iv-grid-med {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(10.5rem, 14rem) auto;
  gap: 0.65rem 1rem;
  align-items: center;
}

@media (max-width: 640px) {
  .tp-iv-grid-med {
    grid-template-columns: 1fr;
  }
}

.tp-iv-med-maintain {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.15;
  color: var(--mh2-text, #0f172a);
  white-space: nowrap;
  cursor: pointer;
}

.tp-iv-med-maintain input[type="checkbox"] {
  margin: 0;
  width: 0.95rem;
  height: 0.95rem;
  flex-shrink: 0;
}

.tp-iv-med-maintain input[type="checkbox"]:checked ~ .tp-iv-med-maintain-text {
  color: var(--mh2-text, #0f172a);
  font-weight: 600;
}

.tp-iv-med-label {
  font-size: 0.82rem;
  line-height: 1.35;
  color: var(--mh2-text, #0f172a);
  word-break: break-word;
}

.tp-iv-grid-med select.tp-iv-med-action,
.tp-iv-grid-med select.tp-iv-med-custom-action {
  width: 100%;
  min-height: 2.25rem;
  font-size: 0.82rem;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--mh2-border-subtle, #e2e8f0);
  border-radius: 8px;
  background: var(--mh2-surface, #fff);
  color: var(--mh2-text, #0f172a);
}

.tp-iv-grid-med select.tp-iv-med-action:focus,
.tp-iv-grid-med select.tp-iv-med-custom-action:focus {
  outline: none;
  border-color: var(--mh2-primary, #2563eb);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.12);
}

.tp-iv-med-custom.tp-iv-grid-med {
  padding-top: 0.35rem;
  margin-top: 0.15rem;
  border-top: 1px dashed var(--mh2-border-subtle, #e2e8f0);
}

.tp-iv-check-stack {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.tp-iv-check-row {
  display: grid;
  grid-template-columns: minmax(0, max-content) minmax(0, 1fr);
  gap: 0.5rem 0.65rem;
  align-items: center;
}

.tp-iv-check-row .tp-iv-check-tile {
  white-space: nowrap;
}

.tp-iv-check-row .tp-iv-pick-detail {
  margin: 0;
  width: 100%;
  min-width: 0;
}

.tp-iv-check-row .tp-iv-pick-detail:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  background: var(--mh2-surface-muted, #f1f5f9);
}

.tp-iv-check-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr));
  gap: 0.5rem 1rem;
}

.tp-iv-check-grid-2 {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem 1rem;
}

@media (max-width: 420px) {
  .tp-iv-check-grid,
  .tp-iv-check-grid-2 {
    grid-template-columns: 1fr;
  }
}

.tp-iv-check-tile {
  display: grid;
  grid-template-columns: 0.95rem minmax(0, 1fr);
  align-items: center;
  column-gap: 1rem;
  margin: 0;
  padding: 0.5rem 0.75rem;
  min-height: 2rem;
  border-radius: 8px;
  border: 1px solid var(--mh2-border-subtle, #e8ecf0);
  background: var(--mh2-surface-muted, #f8fafc);
  cursor: pointer;
  font-size: 0.82rem;
  line-height: 1.25;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.tp-iv-check-tile:hover {
  border-color: var(--mh2-border, #cbd5e1);
  background: var(--mh2-surface, #fff);
}

.tp-iv-check-tile input[type="checkbox"] {
  margin: 0;
  width: 0.95rem;
  height: 0.95rem;
  justify-self: start;
  align-self: center;
  flex-shrink: 0;
}

.tp-iv-check-tile-text {
  min-width: 0;
  align-self: center;
  padding-left: 0.15rem;
}

.treatment-plans-inline-actions {
  margin-top: 1rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--mh2-border-subtle, #e2e8f0);
}

.tp-plan-toolbar-left,
.tp-plan-toolbar-right {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

@media (max-width: 720px) {
  .treatment-plans-inline-actions.crm-modal-actions-split {
    flex-direction: column;
    align-items: stretch;
  }

  .tp-plan-toolbar-left,
  .tp-plan-toolbar-right {
    justify-content: flex-start;
  }
}

.tp-intervention-details {
  border: 1px solid var(--mh2-border-subtle, #e2e8f0);
  border-radius: 8px;
  padding: 0.4rem 0.65rem;
  margin-bottom: 0.5rem;
  background: var(--mh2-surface, #fff);
}

.tp-intervention-details[open] {
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
}

.tp-intervention-summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
  line-height: 1.35;
  list-style: none;
}

.tp-intervention-summary::-webkit-details-marker {
  display: none;
}

.tp-intervention-summary::before {
  content: "▸";
  display: inline-block;
  width: 1rem;
  font-size: 0.75rem;
  color: var(--mh2-text-muted, #64748b);
  transform: rotate(0deg);
  transition: transform 0.15s ease;
}

.tp-intervention-details[open] .tp-intervention-summary::before {
  transform: rotate(90deg);
}

.tp-intervention-hint-list li {
  margin-bottom: 0.2rem;
}

.tp-iv-assign-card {
  padding: 0.4rem 0.55rem;
  margin-bottom: 0.35rem;
  background: var(--mh2-surface, #fff);
  border: 1px solid var(--mh2-border-subtle, #e2e8f0);
}

.tp-iv-assign-grid {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  min-width: 0;
}

.tp-iv-assign-text {
  flex: 1 1 auto;
  min-width: 0;
  font-size: 0.86rem;
  line-height: 1.3;
  color: var(--mh2-text, #0f172a);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tp-iv-assign-controls {
  display: flex;
  flex-direction: row;
  flex: 0 0 auto;
  flex-wrap: nowrap;
  gap: 0.35rem;
  align-items: center;
  justify-content: flex-end;
}

.tp-iv-goal-assign {
  position: relative;
  flex: 0 0 auto;
  width: 7.5rem;
  max-width: 7.5rem;
}

.tp-iv-assign-goals-trigger {
  display: block;
  width: 100%;
  padding: 0.25rem 0.4rem;
  font-size: 0.78rem;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tp-iv-assign-controls .tp-iv-assign-remove {
  flex: 0 0 auto;
  white-space: nowrap;
  padding: 0.25rem 0.45rem;
  font-size: 0.78rem;
}

.tp-iv-assign-goals-popover {
  position: absolute;
  top: calc(100% + 0.25rem);
  right: 0;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  min-width: 15rem;
  max-width: min(22rem, 92vw);
  padding: 0.45rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--mh2-border, #cbd5e1);
  background: var(--mh2-surface, #fff);
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

.tp-iv-assign-goals-popover.hidden {
  display: none;
}

.tp-iv-assign-goals-checklist {
  max-height: 11rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.tp-iv-assign-goal-option {
  display: grid;
  grid-template-columns: 0.95rem minmax(0, 1fr);
  align-items: start;
  column-gap: 0.45rem;
  margin: 0;
  padding: 0.3rem 0.35rem;
  border-radius: 6px;
  font-size: 0.8rem;
  line-height: 1.3;
  cursor: pointer;
}

.tp-iv-assign-goal-option:hover {
  background: var(--mh2-surface-muted, #f1f5f9);
}

.tp-iv-assign-goal-option input[type="checkbox"] {
  margin: 0.15rem 0 0;
}

.tp-iv-assign-goals-empty {
  margin: 0;
  font-size: 0.8rem;
}

.tp-iv-assign-goals-done {
  align-self: flex-end;
  margin-top: 0.1rem;
}

#treatment-plan-iv-picker {
  z-index: 110;
}

/* Width set again after generic .crm-modal-content (max-width: 480px) below. */
.treatment-plan-outcomes-modal-shell.crm-modal-content {
  display: flex;
  flex-direction: column;
}

.treatment-plan-outcomes-modal-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.treatment-plan-outcomes-modal-close {
  flex: 0 0 auto;
  border: none;
  background: transparent;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--mh2-text-muted, #666);
  padding: 0.15rem 0.35rem;
}

.treatment-plan-outcomes-modal-body {
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  padding-right: 0.15rem;
}

.tp-outcomes-iv-table .tp-outcomes-iv-text,
.tp-outcomes-pb-table .tp-outcomes-pb-text,
.tp-outcomes-goal-table .tp-outcomes-goal-text {
  max-width: 36rem;
  word-break: break-word;
}

.tp-outcomes-subsection-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 0.75rem;
  margin: 0.95rem 0 0.3rem;
}

.tp-outcomes-subsection-head:first-of-type {
  margin-top: 0.7rem;
}

.tp-outcomes-subsection-title {
  font-size: 0.86rem;
  margin: 0;
  flex-shrink: 0;
}

.tp-outcomes-subsection-hint {
  font-size: 0.8rem;
  margin: 0;
  flex: 1 1 14rem;
  line-height: 1.35;
}

.tp-outcomes-pb-table select.tp-outcomes-pb-trajectory {
  width: 100%;
  max-width: 16rem;
}

.tp-outcomes-goal-table select.tp-outcomes-goal-achieved {
  width: 100%;
  min-width: 4.5rem;
  max-width: 7.5rem;
}

.tp-outcomes-plan-notes-section {
  border-top: 1px solid var(--mh2-border, #e5e5e5);
  padding-top: 0.25rem;
}

.tp-outcomes-plan-notes-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  max-height: 14rem;
  overflow-y: auto;
  margin-bottom: 0.65rem;
}

.tp-outcomes-plan-note {
  margin: 0;
  padding: 0.55rem 0.7rem;
  border-radius: 0.35rem;
  background: var(--mh2-bg, #f7f7f7);
  border: 1px solid var(--mh2-border, #e5e5e5);
}

.tp-outcomes-plan-note-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.75rem;
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  color: var(--mh2-text-muted, #666);
}

.tp-outcomes-plan-note-meta time {
  font-weight: 600;
}

.tp-outcomes-plan-note-by::before {
  content: "·";
  margin-right: 0.35rem;
}

.tp-outcomes-plan-note-text {
  margin: 0;
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-wrap;
}

.tp-outcomes-plan-notes-compose {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  align-items: flex-start;
}

.tp-outcomes-plan-note-input {
  width: 100%;
  min-height: 4.5rem;
  resize: vertical;
}

.tp-outcomes-iv-table select.tp-outcomes-iv-score {
  width: 100%;
  min-width: 4.5rem;
}

.treatment-plans-outcomes-table .btn-sm {
  padding: 0.25rem 0.65rem;
  font-size: 0.82rem;
}

.tp-iv-pick-block {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.35rem 0 0.5rem;
}

.tp-iv-pick-label {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  font-size: 0.84rem;
  line-height: 1.35;
  cursor: pointer;
}

.tp-iv-pick-label input {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.tp-iv-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.15rem;
  max-width: 100%;
  padding: 0.2rem 0.35rem 0.2rem 0.5rem;
  border: 1px solid var(--mh2-border-subtle, #e2e8f0);
  border-radius: 6px;
  background: var(--mh2-surface, #fff);
  font-size: 0.8rem;
  line-height: 1.3;
}

.tp-iv-chip-text {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.tp-iv-chip-remove {
  padding: 0 0.25rem !important;
  min-height: auto !important;
  line-height: 1.2;
}

.treatment-plans-filter-form {
  display: block;
}

.treatment-plans-filter-row {
  display: flex;
  flex-wrap: wrap;
  gap: 16px 24px;
  align-items: flex-end;
}

.treatment-plans-filter-field {
  flex: 0 1 200px;
  min-width: 0;
}

.treatment-plans-filter-field .treatment-input {
  max-width: 100%;
}

.treatment-plans-filter-actions {
  flex: 0 0 auto;
}

.treatment-plans-results-card .treatment-card-body {
  overflow-x: auto;
}

.treatment-plans-results .data-table {
  width: 100%;
  min-width: 640px;
}

#treatment-plans-results .treatment-plans-data-table th,
#treatment-plans-results .treatment-plans-data-table td {
  text-align: center;
  vertical-align: middle;
}

.treatment-plans-results .muted {
  margin: 0;
}

.treatment-plan-modal-cerbo {
  margin: 0 0 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--mh2-border-subtle, #e2e8f0);
  border-radius: 6px;
  background: var(--mh2-surface-muted, #f8fafc);
  font-size: 0.84rem;
  line-height: 1.45;
}

.treatment-plan-modal-cerbo .treatment-plan-cerbo-section-title {
  margin: 0 0 0.35rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--mh2-text, #0f172a);
}

.treatment-plan-modal-cerbo .treatment-plan-cerbo-section-title:not(:first-child) {
  margin-top: 0.65rem;
}

.treatment-plan-modal-cerbo ul {
  margin: 0;
  padding-left: 1.1rem;
}

.treatment-plan-modal-cerbo li {
  margin-bottom: 0.3rem;
}

.treatment-plan-modal-cerbo .treatment-plan-cerbo-rx-line {
  margin: 0 0 0.35rem;
}

/* Mobile page (Provider → Mobile) */
.page-mobile .page-tagline.mobile-tagline {
  margin: -4px 0 20px 0;
  color: var(--mh2-text-muted);
  font-size: 0.95rem;
}

.mobile-page-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
  max-width: 720px;
}

.mobile-card .treatment-card-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mobile-card-desc {
  margin: 0;
  font-size: 0.9rem;
}

.mobile-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mobile-form .treatment-textarea {
  min-height: 60px;
}

.mobile-btn {
  align-self: flex-start;
}

.mobile-form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.mobile-overview {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.9rem;
}

.mobile-overview-section-title {
  font-weight: 600;
  margin: 0 0 4px 0;
  color: var(--mh2-primary-dark);
}

.mobile-overview-list {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

.mobile-overview-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
  border-bottom: 1px solid rgba(15, 23, 42, 0.06);
}

.mobile-overview-list li:last-child {
  border-bottom: none;
}

.mobile-overview-remove-btn {
  font-size: 0.8rem;
  padding: 4px 8px;
  border-radius: 999px;
  border: none;
  background: rgba(185, 28, 28, 0.04);
  color: var(--mh2-error);
  cursor: pointer;
}

.mobile-overview-remove-btn:hover {
  background: rgba(185, 28, 28, 0.12);
}

.mobile-option-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.mobile-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
}

.mobile-option input[type="checkbox"] {
  width: 16px;
  height: 16px;
}

.mobile-task-rows {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mobile-task-row {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid rgba(15, 23, 42, 0.08);
  background: var(--mh2-surface);
}

/* Mobile page: label + dropdown row (like Tasks view dropdown) */
.mobile-select-row {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 14px;
}

.mobile-select-label {
  flex: 0 0 120px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--mh2-primary-dark);
  padding-top: 8px;
}

.mobile-select {
  flex: 1;
  min-width: 180px;
  min-height: 120px;
  padding: 8px 10px;
  border: 1px solid var(--mh2-border);
  border-radius: 6px;
  background: var(--mh2-surface);
  font: inherit;
  font-size: 0.9rem;
  color: var(--mh2-text);
}

.mobile-select:focus {
  outline: none;
  border-color: var(--mh2-primary-light);
}

.wizard-card h1 {
  margin: 0 0 8px 0;
  font-size: 1.5rem;
  color: var(--mh2-primary-dark);
}

.wizard-desc {
  margin: 0 0 24px 0;
  color: var(--mh2-primary);
  font-size: 0.95rem;
}

.wizard-step {
  margin-bottom: 20px;
}

.wizard-step label {
  display: block;
  font-weight: 500;
  margin-bottom: 8px;
  color: var(--mh2-text);
}

.wizard-row {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}

.wizard-row input[type="text"] {
  flex: 1;
  min-width: 200px;
  padding: 12px 14px;
  font: inherit;
  font-size: 1rem;
  border: 1px solid var(--mh2-border);
  border-radius: 8px;
  background: var(--mh2-surface);
  color: var(--mh2-text);
}

.wizard-row input:focus {
  outline: none;
  border-color: var(--mh2-primary-light);
}

.wizard-actions {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.wizard-questions {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.wizard-q {
  padding: 16px;
  border: 1px solid var(--mh2-border);
  border-radius: 8px;
  background: rgba(44, 81, 105, 0.03);
}

.wizard-q > label {
  display: block;
  margin-bottom: 10px;
  font-weight: 500;
  color: var(--mh2-primary-dark);
}

.wizard-options {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}

.wizard-radio {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 400;
  cursor: pointer;
}

.wizard-radio input {
  margin: 0;
}

.treatment-details-table {
  margin: 12px 0;
}

.treatment-recommendation {
  padding: 16px;
  border-radius: 8px;
  background: rgba(44, 81, 105, 0.06);
  border: 1px solid var(--mh2-border);
  margin-bottom: 16px;
}

.treatment-recommendation ul {
  margin: 8px 0 0 0;
  padding-left: 24px;
}

/* News page */
.news-intro-card h1 {
  margin: 0 0 8px 0;
  font-size: 1.5rem;
  color: var(--mh2-primary-dark);
}

.news-intro-card .tagline {
  margin: 0 0 16px 0;
}

.news-feed-card h2,
.news-sources-card h2 {
  margin: 0 0 12px 0;
  font-size: 1.15rem;
  color: var(--mh2-primary-dark);
}

.news-placeholder {
  margin: 0;
  color: var(--mh2-primary);
  font-size: 0.95rem;
}

.news-feed-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.news-feed-list li {
  padding: 14px 0;
  border-bottom: 1px solid var(--mh2-border);
}

.news-feed-list li:last-child {
  border-bottom: none;
}

.news-feed-list a {
  color: var(--mh2-primary);
  font-weight: 500;
  text-decoration: none;
}

.news-feed-list a:hover {
  text-decoration: underline;
}

.news-feed-list .news-item-meta {
  font-size: 0.875rem;
  color: var(--mh2-text-muted);
  margin-top: 4px;
  display: block;
}

.news-item-snippet {
  font-size: 0.9rem;
  color: var(--mh2-text);
  margin: 6px 0 4px 0;
  line-height: 1.4;
}

.news-summarize-btn {
  margin-top: 8px;
  font-size: 0.875rem;
}

.news-findings {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--mh2-bg-subtle, #f5f5f5);
  border-radius: 6px;
  font-size: 0.9rem;
}

.news-findings-title {
  margin: 0 0 6px 0;
  font-weight: 600;
  color: var(--mh2-primary-dark);
}

.news-findings-list {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--mh2-text);
  line-height: 1.45;
}

.news-findings-list li {
  padding: 2px 0;
  border-bottom: none;
}

.news-diagnostic-row {
  margin: 0 0 8px 0;
  font-size: 0.9rem;
}
.news-vertex-status {
  margin-left: 8px;
  font-size: 0.85rem;
  color: var(--mh2-text-muted);
}
.news-vertex-status.error {
  color: var(--mh2-danger, #c00);
}

.news-meta,
#news-feed-meta {
  margin: 12px 0 0 0;
  font-size: 0.85rem;
  color: var(--mh2-text-muted);
}

.news-sources-list {
  margin: 12px 0;
  padding-left: 24px;
}

.news-sources-list li {
  margin-bottom: 8px;
}

.news-sources-note {
  margin: 16px 0 0 0;
  font-size: 0.9rem;
  color: var(--mh2-primary);
}

.news-subhead {
  margin: 20px 0 10px 0;
  font-size: 1.05rem;
  color: var(--mh2-primary-dark);
}

.news-category-label {
  margin: 14px 0 6px 0;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--mh2-primary);
}

.news-sources-card .news-sources-list a {
  color: var(--mh2-primary);
  font-weight: 500;
  text-decoration: none;
}

.news-sources-card .news-sources-list a:hover {
  text-decoration: underline;
}

.news-sources-card code {
  font-size: 0.85rem;
  background: rgba(44, 81, 105, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
}

/* Task board (Trello-like) */
.task-board {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  overflow-x: auto;
  padding-bottom: 16px;
  min-height: 400px;
}

.task-column {
  flex: 0 0 280px;
  min-width: 280px;
  background: var(--mh2-surface);
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 180px);
}

.task-column-header {
  padding: 12px 14px;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--mh2-text);
  border-bottom: 1px solid var(--mh2-border);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}

.task-column-header-title {
  flex: 1;
  min-width: 0;
  cursor: pointer;
  border-radius: var(--radius-sm);
  padding: 2px 4px;
  margin: -2px -4px;
}

.task-column-header-title:hover {
  background: rgba(44, 81, 105, 0.06);
}

.task-list-name-input {
  flex: 1;
  font: inherit;
  font-weight: 600;
  font-size: 0.95rem;
  padding: 4px 6px;
  border: 1px solid var(--mh2-primary-light);
  border-radius: var(--radius-sm);
  background: var(--mh2-surface);
  color: var(--mh2-text);
  min-width: 0;
}

.task-list-delete-btn {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  padding: 0;
  border: none;
  background: transparent;
  color: var(--mh2-text-muted);
  font-size: 1.2rem;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--radius-sm);
}

.task-list-delete-btn:hover {
  color: var(--mh2-error);
  background: rgba(185, 28, 28, 0.08);
}

.task-column-add-list {
  min-width: 200px;
  justify-content: center;
  align-items: flex-start;
  padding-top: 12px;
}

.task-column-add-list .task-add-list-btn {
  color: var(--mh2-text-muted);
  font-weight: 500;
}

.task-column-add-list .task-add-list-btn:hover {
  color: var(--mh2-primary);
  background: rgba(44, 81, 105, 0.06);
}

.task-card-drop-before {
  border-top: 3px solid var(--mh2-primary);
  margin-top: -3px;
}

.task-page-header {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.task-page-header .page-title {
  margin: 0;
}

.task-page-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.task-view-dropdown-wrap {
  display: inline-flex;
  align-items: center;
}

.task-view-select {
  min-width: 140px;
  padding: 6px 10px;
  border: 1px solid var(--mh2-border);
  border-radius: 6px;
  background: var(--mh2-bg);
  font: inherit;
  color: var(--mh2-text);
}

.task-card-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 4px;
}

.task-card-top .task-card-title {
  flex: 1;
  min-width: 0;
  margin: 0 0 4px 0;
}

.task-card-mark-complete {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1.5px solid var(--mh2-border);
  border-radius: 50%;
  background: transparent;
  color: var(--mh2-text-muted);
  font-size: 0.9rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}

.task-card-mark-complete:hover:not(.complete) {
  border-color: var(--mh2-primary-light);
  color: var(--mh2-primary-light);
}

.task-card[data-status="complete"] .task-card-mark-complete,
.task-card-mark-complete.complete {
  border-color: var(--mh2-primary);
  background: var(--mh2-primary);
  color: white;
  font-size: 1rem;
  font-weight: 600;
}


.task-column-cards {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  min-height: 60px;
}

.task-card {
  background: var(--mh2-bg);
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: grab;
  transition: box-shadow 0.15s;
}

.task-card:hover {
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.task-card.dragging {
  opacity: 0.6;
  cursor: grabbing;
}

.task-card-title {
  font-weight: 500;
  font-size: 0.9375rem;
  color: var(--mh2-text);
  margin: 0 0 4px 0;
}

.task-card-meta {
  font-size: 0.8rem;
  color: var(--mh2-text-muted);
  margin: 0;
}

.task-column-add {
  padding: 8px 14px;
  border-top: 1px solid var(--mh2-border);
  flex-shrink: 0;
}

.task-column-add .btn {
  width: 100%;
  justify-content: center;
  color: var(--mh2-text-muted);
  font-weight: 500;
}

.task-column-add .btn:hover {
  color: var(--mh2-primary);
  background: rgba(44, 81, 105, 0.06);
}

.task-column.drop-target {
  background: rgba(44, 81, 105, 0.04);
  border-color: var(--mh2-primary-light);
}

/* Task modals */
.task-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.task-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
}

.task-modal-content {
  position: relative;
  width: 100%;
  max-width: 420px;
  margin: 0;
}

.task-modal-content.task-modal-edit-wrapper {
  max-width: 640px;
}

.task-modal-content label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin: 12px 0 4px 0;
  color: var(--mh2-text);
}

.task-modal-content input[type="text"],
.task-modal-content input[type="date"],
.task-modal-content select,
.task-modal-content textarea {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  font-size: 0.9375rem;
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  background: var(--mh2-surface);
  color: var(--mh2-text);
}

.task-modal-content textarea {
  resize: vertical;
  min-height: 60px;
}

.task-modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  flex-wrap: wrap;
}

.task-modal-actions .btn:last-of-type {
  margin-left: auto;
}

.task-delete-btn {
  color: var(--mh2-error);
}

.task-delete-btn:hover {
  background: rgba(185, 28, 28, 0.08);
  color: var(--mh2-error);
}

.task-modal-edit-body {
  display: flex;
  align-items: stretch;
  gap: 0;
  margin-top: 12px;
}

.task-modal-edit-main {
  flex: 1;
  min-width: 0;
}

.task-modal-edit-comments {
  border-left: 1px solid var(--mh2-border);
  margin-left: 20px;
  padding-left: 20px;
  min-width: 220px;
  max-width: 280px;
  display: flex;
  flex-direction: column;
}

.task-modal-comments-title {
  font-size: 0.875rem;
  font-weight: 600;
  margin: 0 0 10px 0;
  color: var(--mh2-text);
}

.task-modal-comments-list {
  overflow-y: auto;
  max-height: 240px;
  flex: 1;
  min-height: 80px;
}

.task-comment {
  margin-bottom: 10px;
  font-size: 0.8rem;
}

.task-comment:last-child {
  margin-bottom: 0;
}

.task-comment-meta {
  color: var(--mh2-text-muted);
  font-size: 0.7rem;
  display: block;
}

.task-comment-body {
  margin: 2px 0 0 0;
  word-break: break-word;
  color: var(--mh2-text);
}

.task-modal-add-comment {
  display: flex;
  gap: 8px;
  margin-top: 12px;
  flex-shrink: 0;
}

.task-modal-add-comment .task-comment-input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-family: inherit;
}

.task-modal-add-comment .task-comment-input:focus {
  outline: none;
  border-color: var(--mh2-primary-light);
}

.task-modal-add-comment .task-comment-submit {
  flex-shrink: 0;
  padding: 8px 12px;
  font-size: 0.875rem;
}

/* News page */
.news-intro-card h1 {
  margin: 0 0 8px 0;
  font-size: 1.5rem;
  color: var(--mh2-primary-dark);
}

.news-intro-card .tagline {
  margin: 0 0 16px 0;
}

.news-feed-card h2,
.news-sources-card h2 {
  margin: 0 0 12px 0;
  font-size: 1.15rem;
  color: var(--mh2-primary-dark);
}

.news-placeholder {
  margin: 0;
  color: var(--mh2-primary);
  font-size: 0.95rem;
}

.news-feed-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.news-feed-list li {
  padding: 14px 0;
  border-bottom: 1px solid var(--mh2-border);
}

.news-feed-list li:last-child {
  border-bottom: none;
}

.news-feed-list a {
  color: var(--mh2-primary);
  font-weight: 500;
  text-decoration: none;
}

.news-feed-list a:hover {
  text-decoration: underline;
}

.news-feed-list .news-item-meta {
  font-size: 0.875rem;
  color: var(--mh2-text-muted);
  margin-top: 4px;
  display: block;
}

.news-item-snippet {
  font-size: 0.9rem;
  color: var(--mh2-text);
  margin: 6px 0 4px 0;
  line-height: 1.4;
}

.news-summarize-btn {
  margin-top: 8px;
  font-size: 0.875rem;
}

.news-findings {
  margin-top: 10px;
  padding: 10px 12px;
  background: var(--mh2-bg-subtle, #f5f5f5);
  border-radius: 6px;
  font-size: 0.9rem;
}

.news-findings-title {
  margin: 0 0 6px 0;
  font-weight: 600;
  color: var(--mh2-primary-dark);
}

.news-findings-list {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--mh2-text);
  line-height: 1.45;
}

.news-findings-list li {
  padding: 2px 0;
  border-bottom: none;
}

#news-feed-meta {
  margin: 12px 0 0 0;
  font-size: 0.85rem;
  color: var(--mh2-text-muted);
}

.news-sources-list {
  margin: 12px 0;
  padding-left: 24px;
}

.news-sources-list li {
  margin-bottom: 8px;
}

.news-sources-note {
  margin: 16px 0 0 0;
  font-size: 0.9rem;
  color: var(--mh2-primary);
}

.news-subhead {
  margin: 20px 0 10px 0;
  font-size: 1.05rem;
  color: var(--mh2-primary-dark);
}

.news-category-label {
  margin: 14px 0 6px 0;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--mh2-primary);
}

.news-sources-card .news-sources-list a {
  color: var(--mh2-primary);
  font-weight: 500;
  text-decoration: none;
}

.news-sources-card .news-sources-list a:hover {
  text-decoration: underline;
}

.news-sources-card code {
  font-size: 0.85rem;
  background: rgba(44, 81, 105, 0.1);
  padding: 2px 6px;
  border-radius: 4px;
}

/* CRM — full-width canvas; brand tokens align with :root */
#page-crm.crm-stitch {
  --crm-brand: var(--mh2-primary);
  --crm-brand-dark: var(--mh2-primary-dark);
  --crm-brand-dim: rgba(44, 81, 105, 0.12);
  --crm-canvas: #f9f9f9;
  --crm-surface: #ffffff;
  --crm-text: #000000;
  --crm-text-muted: #5f5f5f;
  --crm-border: #e2e2e2;
  --crm-border-light: #eeeeee;
  background: var(--crm-canvas);
  margin: -24px -32px 0;
  padding: 24px 32px 32px;
  min-height: calc(100% + 24px);
}

#page-crm.crm-stitch .page-title {
  color: var(--crm-text);
  letter-spacing: -0.02em;
  margin-bottom: 0;
}

#page-crm.crm-stitch .muted {
  color: var(--crm-text-muted);
}

#page-crm.crm-stitch .btn-primary {
  background: var(--crm-brand);
  color: #fff;
}

#page-crm.crm-stitch .btn-primary:hover {
  background: var(--crm-brand-dark);
}

#page-crm.crm-stitch .btn-ghost {
  color: var(--crm-brand);
}

#page-crm.crm-stitch .btn-ghost:hover {
  background: var(--crm-brand-dim);
  color: var(--crm-brand-dark);
}

#page-crm.crm-stitch .btn-sm.btn-primary {
  background: var(--crm-brand);
}

#page-crm.crm-stitch .card {
  background: var(--crm-surface);
  border: 1px solid var(--crm-border);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

#page-crm.crm-stitch .data-table {
  border-collapse: collapse;
}

#page-crm.crm-stitch .data-table thead th {
  background: #f3f3f3;
  color: var(--crm-text);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--crm-border);
}

#page-crm.crm-stitch .data-table tbody td {
  border-bottom: 1px solid var(--crm-border-light);
  color: var(--crm-text);
}

#page-crm.crm-stitch .crm-search-input {
  border: 1px solid var(--crm-border);
  background: var(--crm-surface);
  color: var(--crm-text);
}

#page-crm.crm-stitch .crm-search-input:focus {
  outline: none;
  border-color: var(--crm-brand);
  box-shadow: 0 0 0 2px var(--crm-brand-dim);
}

#page-crm.crm-stitch .crm-search-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

#page-crm.crm-stitch .crm-search-row .crm-search-input {
  flex: 1 1 12rem;
  min-width: 0;
  max-width: none;
}

#page-crm.crm-stitch .crm-list-filter-btn {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 2.25rem;
  min-height: 2.25rem;
  padding: 0.35rem 0.5rem;
  color: var(--crm-text-muted);
  border: 1px solid var(--crm-border);
  border-radius: 6px;
  background: var(--crm-surface);
}

#page-crm.crm-stitch .crm-list-filter-btn:hover {
  color: var(--crm-text);
  border-color: var(--crm-brand);
  background: var(--crm-surface);
}

#page-crm.crm-stitch .crm-list-filter-btn--active {
  color: var(--crm-brand);
  border-color: var(--crm-brand);
  background: color-mix(in srgb, var(--crm-brand) 12%, var(--crm-surface));
}

#page-crm.crm-stitch .crm-list-filter-btn-icon {
  display: block;
  opacity: 0.9;
}

.crm-list-filter-modal-content {
  max-width: 26rem;
  width: min(100%, 26rem);
}

.crm-list-filter-modal-body {
  max-height: min(70vh, 32rem);
  overflow-y: auto;
}

.crm-list-filter-tags-field {
  margin-top: 0.5rem;
}

.crm-list-filter-tags-label {
  display: block;
  font-size: 0.875rem;
  color: var(--mh2-text-muted);
  margin-bottom: 0.35rem;
}

.crm-list-filter-tags-box {
  max-height: 14rem;
  overflow: auto;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--mh2-border);
  border-radius: 6px;
  background: var(--mh2-surface);
  font-size: 0.875rem;
}

.crm-list-filter-tag-cat {
  margin-bottom: 0.2rem;
}

.crm-list-filter-tag-cat:last-child {
  margin-bottom: 0;
}

.crm-list-filter-tag-cat-name {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--mh2-text-muted);
  margin-bottom: 0.1rem;
}

.crm-list-filter-tag-cat-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.crm-list-filter-tag-item {
  display: flex;
  align-items: flex-start;
  gap: 0.3rem;
  line-height: 1.35;
  cursor: pointer;
  margin: 0;
  padding: 0;
}

.crm-list-filter-tag-item input {
  margin-top: 0.2rem;
  flex-shrink: 0;
}

.crm-modal-actions-left {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#page-crm.crm-stitch .crm-list-tags-td {
  min-width: 6rem;
  max-width: 16rem;
}

#page-crm.crm-stitch .crm-list-tag-cell-inner {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem 0.35rem;
  align-items: center;
}

#page-crm.crm-stitch .crm-list-tags-td .crm-tag-chip {
  max-width: 100%;
}

#page-crm.crm-stitch .crm-detail-box {
  background: var(--crm-surface);
  border: 1px solid var(--crm-border);
}

#page-crm.crm-stitch .crm-detail-box-title {
  color: var(--crm-text-muted);
}

#page-crm.crm-stitch .crm-detail-textarea {
  border-color: var(--crm-border);
  background: var(--crm-surface);
  color: var(--crm-text);
}

#page-crm.crm-stitch .crm-detail-textarea:focus {
  outline: none;
  border-color: var(--crm-brand);
  box-shadow: 0 0 0 2px var(--crm-brand-dim);
}

#page-crm.crm-stitch .crm-task-detail-form .crm-detail-input,
#page-crm.crm-stitch .crm-task-detail-form select,
#page-crm.crm-stitch .crm-task-detail-form input[type="date"] {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--crm-border);
  border-radius: 6px;
  padding: 0.5rem 0.65rem;
  background: var(--crm-surface);
  color: var(--crm-text);
}

#page-crm.crm-stitch .crm-task-detail-form label {
  display: block;
  margin-top: 0.75rem;
  margin-bottom: 0.25rem;
  font-size: 0.875rem;
  color: var(--crm-text-muted);
}

#page-crm.crm-stitch .crm-task-detail-form .crm-detail-box-title {
  margin-top: 0;
}

#page-crm.crm-stitch .crm-task-detail-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

#page-crm.crm-stitch .crm-task-detail-readonly .crm-activity-detail-meta {
  margin-bottom: 0.75rem;
  line-height: 1.45;
}

#page-crm.crm-stitch .crm-task-detail-readonly .crm-activity-detail-body {
  margin-top: 0;
  white-space: pre-wrap;
}

#page-crm.crm-stitch .crm-task-readonly-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-top: 1rem;
}

#page-crm.crm-stitch .crm-task-no-desc {
  margin: 0.35rem 0 0 0;
}

#page-crm.crm-stitch .crm-modal-content input,
#page-crm.crm-stitch .crm-modal-content textarea,
#page-crm.crm-stitch .crm-modal-content select {
  border-color: var(--crm-border);
}

@media (max-width: 640px) {
  #page-crm.crm-stitch {
    margin: -16px -16px 0;
    padding: 16px 16px 24px;
  }
}

/* CRM shell: column layout so list/detail stacks can shrink and scroll internally. */
#page-crm.crm-stitch.active {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  width: 100%;
}

#crm-content:not(.hidden) {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  max-width: 100%;
  display: flex;
  flex-direction: column;
}

/* Detail viewport: fluid width, mostly vertical scroll; inner content may scroll horizontally if needed. */
#crm-detail-stack {
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  max-width: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

#crm-detail-stack > .crm-detail-shell {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.crm-page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.record-audit-page-header {
  align-items: flex-start;
  gap: 1rem;
}

.record-audit-intro {
  max-width: 52rem;
  margin: 0.35rem 0 0;
}

.record-audit-subheading {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 0;
}

.record-audit-sortable-th {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.record-audit-sortable-th:hover {
  color: var(--mh2-accent, #2563eb);
}

.record-audit-sort-ind {
  font-size: 0.75em;
  opacity: 0.85;
  margin-left: 0.2em;
}

.case-loads-sortable-th {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.case-loads-sortable-th:hover {
  color: var(--mh2-accent, #2563eb);
}

.case-loads-filters {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.75rem;
}

.case-loads-subtitle {
  margin-top: 1rem;
  margin-bottom: 0.4rem;
  font-size: 1.2rem;
}

.case-loads-filters label {
  font-size: 0.9rem;
  color: var(--mh2-text);
}

.case-loads-filters select {
  min-width: 11rem;
  max-width: 14rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--mh2-border);
  border-radius: 6px;
  background: var(--mh2-surface);
}

.case-loads-table-card {
  min-height: 0;
}

.case-loads-scroll {
  max-height: clamp(260px, 52vh, 620px);
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#case-loads-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--mh2-surface);
  color: var(--mh2-primary-dark);
  box-shadow: 0 1px 0 var(--mh2-border);
}

#case-loads-summary-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--mh2-surface);
  color: var(--mh2-primary-dark);
  box-shadow: 0 1px 0 var(--mh2-border);
}

#page-case-loads #case-loads-content > h2.case-loads-subtitle:first-of-type {
  margin-top: 0;
}

.case-loads-matrix-intro {
  margin: 0 0 0.75rem 0;
  font-size: 0.9rem;
  max-width: 60rem;
}

.case-loads-matrix-scroll {
  max-height: min(48vh, 28rem);
}

#case-loads-matrix-table {
  min-width: max(100%, 52rem);
}

#case-loads-matrix-table thead th {
  background: var(--mh2-surface);
  color: var(--mh2-primary-dark);
  box-shadow: 0 1px 0 var(--mh2-border);
  font-size: 0.88rem;
  padding: 0.45rem 0.4rem;
}

/* Month columns scroll horizontally; keep z-index low so the frozen "Provider" column (higher z-index) stays on top. */
#case-loads-matrix-table thead tr:first-child th.matrix-month-h {
  position: sticky;
  top: 0;
  z-index: 1;
  vertical-align: bottom;
  text-align: center;
}

#case-loads-matrix-table thead tr:nth-child(2) th.matrix-sub-h {
  position: sticky;
  top: 2.4rem;
  z-index: 1;
  font-size: 0.75rem;
  font-weight: 500;
  line-height: 1.2;
  padding: 0.35rem 0.35rem;
}

/* Frozen first column: must stack above all horizontally scrolling month headers and body cells. */
#case-loads-matrix-table thead th.matrix-corner,
#case-loads-matrix-table thead th.matrix-provider-h {
  position: sticky;
  left: 0;
  z-index: 12;
  text-align: left;
  background: var(--mh2-surface);
  box-shadow: 2px 0 0 var(--mh2-border), 0 1px 0 var(--mh2-border);
  /* Strong edge so month headers do not show through on horizontal pan */
  background-clip: border-box;
}

#case-loads-matrix-table thead th.matrix-provider-h,
#case-loads-matrix-table thead th.matrix-corner {
  top: 0;
  width: 13rem;
  min-width: 13rem;
  max-width: 13rem;
  vertical-align: bottom;
  white-space: nowrap;
}

#case-loads-matrix-table tbody th.matrix-provider-col {
  position: sticky;
  left: 0;
  z-index: 5;
  text-align: left;
  font-weight: 500;
  width: 13rem;
  min-width: 13rem;
  max-width: 13rem;
  background: var(--mh2-surface);
  /* Below thead corner (12) but above scrolling tds (auto/0) */
  box-shadow: 2px 0 0 var(--mh2-border), 2px 0 4px rgba(0, 0, 0, 0.06);
  white-space: nowrap;
}

/* Scrolling data cells: stay under frozen provider column */
#case-loads-matrix-table tbody td {
  position: relative;
  z-index: 0;
}

#case-loads-matrix-table tbody tr:hover th.matrix-provider-col,
#case-loads-matrix-table tbody tr:hover td {
  background: rgba(44, 81, 105, 0.04);
}

#case-loads-matrix-table #case-loads-matrix-tbody th.matrix-provider-col {
  background: var(--mh2-surface);
}

#case-loads-matrix-table tbody tr:hover th.matrix-provider-col {
  background: rgba(44, 81, 105, 0.06);
}

#case-loads-matrix-table .matrix-sub-h {
  min-width: 4.5rem;
}

#case-loads-matrix-table td.num {
  min-width: 3.5rem;
}

#case-loads-matrix-table th.matrix-month-sep,
#case-loads-matrix-table td.matrix-month-sep {
  border-left: 2px solid var(--mh2-border);
}

/* Record Audit: fixed viewport-relative height, vertical (and horizontal) scroll */
.record-audit-table-card {
  min-height: 0;
}

.record-audit-table-scroll {
  max-height: clamp(220px, 36vh, 380px);
  overflow-y: auto;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

#record-audit-table thead th,
#record-audit-detail-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--mh2-surface);
  color: var(--mh2-primary-dark);
  box-shadow: 0 1px 0 var(--mh2-border);
}

.crm-header-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.crm-segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: max-content;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
  padding: 0.25rem 0;
  min-height: 2.6rem;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
}

.crm-segment-btn {
  flex: 0 0 auto;
  padding: 0.55rem 1.25rem;
  border: 1px solid var(--mh2-border);
  background: var(--mh2-surface);
  border-radius: 999px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  color: var(--mh2-text);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.crm-segment-btn:hover {
  background: var(--mh2-bg);
}

.crm-segment-btn.active {
  background: var(--mh2-primary);
  color: #fff;
  border-color: var(--mh2-primary);
}

#page-crm.crm-stitch .crm-segment-btn {
  border-color: var(--crm-border);
  background: var(--crm-surface);
  color: var(--crm-text);
}

#page-crm.crm-stitch .crm-segment-btn:hover {
  background: #f3f3f3;
}

#page-crm.crm-stitch .crm-segment-btn.active {
  background: var(--crm-brand);
  border-color: var(--crm-brand);
  color: #fff;
}

#page-crm.crm-stitch #crm-contacts-table tbody tr:hover,
#page-crm.crm-stitch #crm-organizations-table tbody tr.crm-clickable-row:hover {
  background: rgba(44, 81, 105, 0.06);
}

.crm-view-panel.hidden {
  display: none;
}

.crm-panel-empty {
  margin: 0.75rem 0 0 0;
  padding: 0 0.25rem;
}

.crm-action-status {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: center;
  font-size: 0.85rem;
}

.crm-action-status label {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  font-weight: 400;
}

button.crm-action-related-link {
  display: inline;
  max-width: 100%;
  padding: 0;
  margin: 0;
  border: none;
  background: none;
  font: inherit;
  color: var(--crm-brand, var(--mh2-primary, #2c5169));
  text-decoration: underline;
  text-underline-offset: 0.12em;
  cursor: pointer;
  text-align: left;
}

button.crm-action-related-link:hover {
  color: var(--crm-brand-dark, #1a3344);
}

button.crm-action-related-link:focus-visible {
  outline: 2px solid var(--crm-brand, var(--mh2-primary, #2c5169));
  outline-offset: 2px;
}

.crm-intake-email-detail .crm-intake-email-subject {
  font-size: 1.05rem;
  font-weight: 600;
  margin: 0.5rem 0 0.25rem 0;
  color: var(--crm-text, inherit);
}

.crm-intake-body-plain {
  margin-top: 0.75rem;
  white-space: pre-wrap;
  max-height: none;
  overflow: visible;
  font-size: 0.95rem;
  line-height: 1.45;
}

.crm-intake-call-dl {
  margin: 0;
}

.crm-intake-call-dl-row {
  display: grid;
  grid-template-columns: 8rem 1fr;
  gap: 0.35rem 1rem;
  margin-bottom: 0.5rem;
  font-size: 0.95rem;
}

.crm-intake-call-dl-row dt {
  margin: 0;
  color: var(--crm-text-muted, #666);
  font-weight: 500;
}

.crm-intake-call-dl-row dd {
  margin: 0;
}

.crm-detail-shell {
  margin-top: 0.25rem;
}

/* Fluid rhythm + layout queries: width is the detail card, not the viewport (avoids reflow while horizontally scrolling). */
/* ~20% larger banner type line than base; name remains larger than meta/type. */
#crm-contact-detail,
#crm-org-detail {
  container-type: inline-size;
  container-name: crm-detail-shell;
  --crm-banner-column-gap: clamp(0.5rem, 0.28rem + 1.15vw, 1.125rem);
  --crm-banner-row-gap: clamp(0.2rem, 0.1rem + 0.55vw, 0.45rem);
  --crm-banner-edge-gap: clamp(0.45rem, 0.28rem + 0.95vw, 0.95rem);
  --crm-banner-block-pad: clamp(0.2rem, 0.1rem + 0.45vw, 0.42rem);
  --crm-banner-icon-gap: clamp(0.22rem, 0.16rem + 0.35vw, 0.4rem);
  --crm-banner-name-size: clamp(1.26rem, 1.104rem + 0.48vw, 1.536rem);
  --crm-banner-type-size: clamp(0.936rem, 0.864rem + 0.3vw, 1.05rem);
  --crm-banner-meta-size: clamp(0.984rem, 0.912rem + 0.264vw, 1.08rem);
  --crm-banner-strip-margin: clamp(0.3rem, 0.15rem + 0.55vw, 0.5rem);
}

#crm-contact-detail {
  --crm-detail-fixed-width: 980px;
}

@supports (width: 1cqi) {
  #crm-contact-detail,
  #crm-org-detail {
    --crm-banner-column-gap: clamp(0.5rem, 0.3rem + 2.8cqi, 1.125rem);
    --crm-banner-row-gap: clamp(0.2rem, 0.1rem + 1.1cqi, 0.45rem);
    --crm-banner-edge-gap: clamp(0.45rem, 0.28rem + 2.2cqi, 0.95rem);
    --crm-banner-block-pad: clamp(0.2rem, 0.1rem + 0.85cqi, 0.42rem);
    --crm-banner-icon-gap: clamp(0.22rem, 0.16rem + 0.65cqi, 0.4rem);
    --crm-banner-name-size: clamp(1.26rem, 1.104rem + 1.08cqi, 1.536rem);
    --crm-banner-type-size: clamp(0.936rem, 0.864rem + 0.54cqi, 1.05rem);
    --crm-banner-meta-size: clamp(0.984rem, 0.912rem + 0.48cqi, 1.08rem);
    --crm-banner-strip-margin: clamp(0.3rem, 0.12rem + 1cqi, 0.5rem);
  }
}

.crm-detail-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.75rem 1rem;
  margin-bottom: 0.2rem;
}

.crm-contact-detail-top {
  align-items: center;
  flex-wrap: nowrap;
  gap: var(--crm-banner-edge-gap, 0.75rem);
  padding: var(--crm-banner-block-pad, 0.35rem) 0 0.8rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid color-mix(in srgb, var(--mh2-border) 78%, transparent);
}

.crm-org-detail-top {
  align-items: center;
  flex-wrap: nowrap;
  gap: var(--crm-banner-edge-gap, 0.75rem);
  padding: var(--crm-banner-block-pad, 0.35rem) 0 0.8rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid color-mix(in srgb, var(--mh2-border) 78%, transparent);
}

/*
 * Contact banner: centered name row; below — type · email · phone in three equal columns.
 */
.crm-contact-banner-spread {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-start;
  gap: var(--crm-banner-column-gap, 1rem);
}

#crm-contact-detail .crm-contact-detail-top {
  flex-wrap: nowrap;
}

.crm-contact-banner-stack {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
}

.crm-contact-banner-name-row {
  margin: 0;
  font: inherit;
  font-weight: 700;
  color: var(--mh2-primary);
  text-align: center;
  width: 100%;
}

.crm-contact-banner-name-row .crm-detail-title-main {
  display: block;
  font-size: var(--crm-banner-name-size, 1.25rem);
  font-weight: 700;
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-contact-banner-meta-line {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-width: 0;
  font-size: var(--crm-banner-meta-size, 0.88rem);
  color: var(--mh2-text);
}

.crm-contact-banner-meta-segment {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: var(--crm-banner-icon-gap, 0.35rem);
  min-width: 0;
  flex: 1 1 0;
  text-align: center;
}

.crm-contact-banner-meta-segment:first-child .crm-contact-banner-value {
  color: var(--mh2-text-muted);
  font-weight: 500;
  font-size: var(--crm-banner-type-size, 0.84rem);
}

.crm-contact-banner-meta-segment:first-child .crm-contact-banner-value::before {
  content: "Contact Type: ";
}

.crm-contact-banner-meta-dot {
  flex: 0 0 auto;
  color: var(--mh2-text-muted);
  font-weight: 500;
  font-size: 1.1em;
  line-height: 1;
  padding: 0 0.15rem;
  user-select: none;
}

.crm-org-banner-spread {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-start;
  gap: var(--crm-banner-column-gap, 1rem);
}

.crm-org-banner-stack {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.45rem;
}

.crm-org-banner-name-row {
  margin: 0;
  font: inherit;
  font-weight: 700;
  color: var(--mh2-primary);
  text-align: center;
  width: 100%;
  font-size: var(--crm-banner-name-size, 1.25rem);
  line-height: 1.2;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-org-banner-meta-line {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  min-width: 0;
  font-size: var(--crm-banner-meta-size, 0.88rem);
  color: var(--mh2-text);
}

.crm-org-banner-meta-segment {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: var(--crm-banner-icon-gap, 0.35rem);
  min-width: 0;
  flex: 1 1 0;
  text-align: center;
}

.crm-org-banner-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-org-banner-meta-dot {
  flex: 0 0 auto;
  color: var(--mh2-text-muted);
  font-weight: 500;
  font-size: 1.1em;
  line-height: 1;
  padding: 0 0.15rem;
  user-select: none;
}

.crm-org-banner-icon {
  width: 1rem;
  text-align: center;
  color: var(--mh2-text-muted);
  flex: 0 0 1rem;
}


.crm-detail-title {
  margin: 0;
  flex: 0 1 auto;
  min-width: 0;
  color: var(--mh2-primary);
}

.crm-detail-title-main {
  display: inline;
  font-size: 1.25rem;
  font-weight: 700;
  line-height: 1.15;
}

.crm-detail-title-sub {
  display: inline;
  margin-left: 0.55rem;
  font-size: 0.84rem;
  font-weight: 500;
  line-height: 1.2;
  color: var(--mh2-text-muted);
}

.crm-detail-meta {
  margin: 0 0 1rem 0;
  font-size: 0.9rem;
}

.crm-detail-layout {
  display: grid;
  grid-template-columns: minmax(240px, 300px) minmax(0, 1fr);
  gap: 1.25rem;
  align-items: stretch;
  min-height: 706px;
}

.crm-detail-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-width: 0;
  min-height: 0;
  height: 100%;
}

.crm-detail-main {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  height: 100%;
}

.crm-sticky-block,
.crm-misc-block {
  flex: 1 1 0;
  min-height: 0;
}

.crm-tags-block {
  flex: 0.5 1 0;
  min-height: 0;
}

.crm-primary-dl {
  margin: 0 0 0.75rem 0;
  font-size: 0.95rem;
}

.crm-primary-dl-row {
  display: grid;
  grid-template-columns: 6.5rem 1fr;
  gap: 0.35rem 0.75rem;
  margin-bottom: 0.5rem;
}

.crm-primary-dl-row dt {
  margin: 0;
  color: var(--mh2-text-muted);
  font-weight: 500;
  font-size: 0.8rem;
}

.crm-primary-dl-row dd {
  margin: 0;
  word-break: break-word;
}

#crm-org-primary-edit {
  font-size: 0.72rem;
  line-height: 1;
  padding: 0.28rem 0.5rem;
  min-height: 1.25rem;
  margin-left: auto;
  flex-shrink: 0;
  align-self: center;
}

#crm-contact-primary-edit {
  font-size: 0.72rem;
  line-height: 1;
  padding: 0.28rem 0.5rem;
  min-height: 1.25rem;
  margin-left: auto;
  flex-shrink: 0;
  align-self: center;
}

#crm-contact-detail-back {
  background: var(--mh2-border);
}

#crm-org-detail-back {
  background: var(--mh2-border);
}

.crm-detail-box-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.6rem;
}

.crm-detail-box-header .crm-detail-box-title {
  margin: 0;
}

.crm-sticky-block {
  display: flex;
  flex-direction: column;
}

.crm-sticky-textarea {
  flex: 1 1 auto;
  min-height: 140px;
  width: 100%;
  resize: none;
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  background: var(--mh2-bg);
  color: var(--mh2-text);
  padding: 0.75rem;
  font: inherit;
  line-height: 1.45;
}

.crm-sticky-textarea.is-readonly {
  background: transparent;
  border-color: transparent;
  padding: 0;
  resize: none;
}

.crm-detail-banner {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1rem;
  margin-bottom: 0;
}

.crm-detail-banner-main {
  min-width: 0;
  flex: 1;
}

.crm-contact-banner-row {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.88rem;
  min-height: 1.05rem;
  max-width: 240px;
}

.crm-contact-banner-spread .crm-contact-banner-row {
  max-width: none;
}

.crm-contact-banner-icon {
  width: 1rem;
  text-align: center;
  color: var(--mh2-text-muted);
  flex: 0 0 1rem;
}

.crm-contact-banner-value {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Toolbar meta line: single-row ellipsis per segment (Option C). */
.crm-contact-banner-meta-line .crm-contact-banner-value {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Match misc-panel Edit sizing (see .crm-misc-readonly > .btn). */
#crm-contact-sticky-save,
#crm-org-sticky-save {
  font-size: 0.72rem;
  line-height: 1;
  padding: 0.28rem 0.5rem;
  min-height: 1.25rem;
}

.crm-detail-banner-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.75rem 1rem;
}

.crm-detail-banner-item dt {
  margin: 0 0 0.15rem 0;
  color: var(--mh2-text-muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.crm-detail-banner-item dd {
  margin: 0;
  font-size: 0.95rem;
  line-height: 1.3;
  word-break: break-word;
}

/* Org detail primary banner only: stack when the detail card is narrow (contact banner never wraps — see #crm-contact-detail rules). */
@container crm-detail-shell (max-width: 1100px) {
  .crm-detail-banner {
    flex-direction: column;
    align-items: stretch;
  }

  .crm-detail-banner-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.crm-misc-readonly {
  position: static;
}

.crm-misc-readonly > .btn.btn-primary.btn-sm {
  position: static;
  font-size: 0.72rem;
  line-height: 1;
  padding: 0.28rem 0.5rem;
  min-height: 1.25rem;
}

.crm-misc-block {
  position: relative;
  padding-top: 2.25rem;
}

.crm-misc-block .crm-detail-box-title {
  margin-right: 5.5rem;
}

#crm-contact-patient-misc-edit,
#crm-contact-referrer-misc-edit,
#crm-org-misc-edit {
  position: absolute;
  top: 0.7rem;
  right: 0.75rem;
  z-index: 2;
}

.crm-activity-detail-inner {
  position: relative;
}

.crm-task-detail-readonly .crm-activity-detail-meta,
.crm-task-detail-readonly .crm-activity-detail-body,
.crm-task-detail-readonly .crm-task-no-desc {
  padding-right: 0;
}

.crm-misc-placeholder {
  font-size: 0.9rem;
  line-height: 1.45;
}

.crm-misc-copy {
  margin: 0;
}

.crm-tags-placeholder {
  margin: 0;
  font-size: 0.9rem;
  line-height: 1.45;
}

.crm-tags-block {
  position: relative;
  padding-top: 2.25rem;
}

.crm-tags-block .crm-detail-box-title {
  margin-right: 5.5rem;
}

.crm-tags-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-bottom: 0.55rem;
  max-height: 108px;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 0.2rem;
}

.crm-tag-chip {
  display: inline-flex;
  align-items: center;
  max-width: 100%;
  padding: 0.12rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--mh2-border);
  background: var(--mh2-surface);
  font-size: 0.78rem;
  line-height: 1.2;
  color: var(--mh2-text);
}

.crm-tag-chip-overflow {
  background: color-mix(in srgb, var(--mh2-surface) 88%, var(--mh2-border));
  color: var(--mh2-text-muted);
}

.crm-tags-actions {
  display: block;
}

.crm-tags-manage-edit {
  position: absolute;
  top: 0.7rem;
  right: 0.75rem;
  z-index: 2;
  font-size: 0.72rem;
  line-height: 1;
  padding: 0.28rem 0.5rem;
  min-height: 1.25rem;
}

.crm-tags-inline-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.5rem;
  align-items: center;
}

.crm-tags-inline-row-3 {
  grid-template-columns: minmax(120px, 0.7fr) minmax(0, 1fr) auto;
}

.crm-tags-inline-actions {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.crm-tags-inline-row > select.crm-detail-input,
.crm-tags-inline-row > input.crm-detail-input {
  width: 100%;
}

.crm-tags-assignment-list {
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  background: var(--mh2-surface);
  padding: 0.7rem 0.95rem 0.7rem 1.15rem;
  height: 320px;
  max-height: min(45vh, 420px);
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
}

.crm-tags-category-block {
  margin-bottom: 0.7rem;
}

.crm-tags-category-block:last-child {
  margin-bottom: 0;
}

.crm-tags-category-title {
  margin: 0 0 0.35rem 0;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--mh2-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.crm-tags-checkbox-list {
  display: grid;
  gap: 0;
}

.crm-tags-checkbox-row {
  display: grid;
  grid-template-columns: 0.95rem minmax(0, 1fr);
  align-items: center;
  column-gap: 1rem;
  min-width: 0;
  margin: 0 !important;
  padding: 0;
  min-height: 1.4rem;
  line-height: 1.15;
}

.crm-tags-checkbox-row input[type="checkbox"] {
  margin: 0;
  width: 0.95rem;
  height: 0.95rem;
  justify-self: start;
  align-self: center;
}

.crm-tags-checkbox-row span {
  padding-left: 0.2rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.crm-modal-content.crm-tags-modal-content {
  width: min(980px, calc(100vw - 2rem));
  max-width: 980px;
}

.crm-tags-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.4rem;
}

.crm-tags-modal-header h2 {
  margin: 0;
}

.crm-tags-modal-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 1rem;
  align-items: start;
}

.crm-tags-modal-section {
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  background: var(--mh2-bg);
  padding: 0.8rem;
}

.crm-tags-modal-section-title {
  margin: 0 0 0.7rem 0;
  font-size: 0.92rem;
}

.crm-tags-modal-subtitle {
  margin: 1.1rem 0 0.5rem 0;
  padding-top: 0.9rem;
  border-top: 1px solid var(--mh2-border);
  font-size: 0.92rem;
  color: var(--mh2-primary-dark);
  font-weight: 600;
}

.crm-tags-assign-actions {
  margin-top: 0.75rem;
  display: flex;
  justify-content: flex-end;
}

.crm-misc-readonly {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  color: var(--mh2-text);
}

.crm-misc-readonly .crm-primary-dl {
  margin: 0;
}

.crm-misc-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  font-size: 0.9rem;
}

.crm-misc-form .crm-primary-dl-row {
  margin: 0;
}

.crm-misc-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  margin: 0;
}

.crm-misc-field > span {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--mh2-muted, #666);
}

.crm-misc-org-select {
  font-family: var(--font);
  max-height: 10rem;
}

.crm-org-tree-col {
  width: 2.25rem;
  padding-left: 0.35rem;
  padding-right: 0.35rem;
}

.crm-org-tree-cell {
  vertical-align: middle;
  text-align: center;
  width: 2.25rem;
}

.crm-org-tree-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.2rem;
  margin: 0;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: var(--radius-sm);
  color: var(--mh2-text-muted, #666);
}

.crm-org-tree-toggle:hover {
  color: var(--mh2-text);
  background: var(--mh2-bg);
}

.crm-org-tree-arrow {
  display: block;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid currentColor;
}

.crm-org-tree-toggle.collapsed .crm-org-tree-arrow {
  transform: rotate(-90deg);
}

.crm-org-tree-spacer {
  display: inline-block;
  width: 1.25rem;
}

tr.crm-org-child-row td:nth-child(2) {
  background: color-mix(in srgb, var(--mh2-surface) 92%, var(--mh2-border) 8%);
}

.crm-org-child-name {
  display: inline-block;
  padding-left: 1.75rem;
  border-left: 3px solid color-mix(in srgb, var(--mh2-accent, var(--mh2-border)) 55%, var(--mh2-border));
  margin-left: 0.35rem;
  color: color-mix(in srgb, var(--mh2-text) 88%, var(--mh2-muted, gray));
}

.crm-activity-panel {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  flex: 1 1 auto;
}

.crm-activity-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.crm-activity-tab {
  padding: 0.45rem 1rem;
  border: 1px solid var(--mh2-border);
  background: var(--mh2-surface);
  border-radius: 999px;
  font-family: var(--font);
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--mh2-text);
}

.crm-activity-tab:hover {
  background: var(--mh2-bg);
}

.crm-activity-tab.active {
  background: var(--mh2-primary);
  color: #fff;
  border-color: var(--mh2-primary);
}

.crm-activity-detail {
  padding: 1rem;
  flex: 0 0 60%;
  min-height: 0;
  overflow: auto;
  margin-bottom: 0;
}

.crm-activity-detail-inner {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.crm-activity-detail-meta {
  font-size: 0.85rem;
}

.crm-activity-detail-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
  line-height: 1.45;
}

.crm-activity-table-wrap {
  flex: 1 1 40%;
  min-height: 0;
  max-height: none;
  overflow: auto;
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  background: var(--mh2-surface);
}

.crm-activity-table {
  margin: 0;
  font-size: 0.9rem;
}

.crm-activity-table th,
.crm-activity-table td {
  white-space: nowrap;
  padding-top: 0.35rem;
  padding-bottom: 0.35rem;
  line-height: 1.2;
}

.crm-activity-table .btn.btn-sm {
  font-size: 0.72rem;
  line-height: 1;
  padding: 0.2rem 0.45rem;
  min-height: 1.15rem;
}

.crm-activity-row-selected td {
  background: rgba(44, 81, 105, 0.1);
}

.crm-activity-empty {
  padding: 0.75rem;
  margin: 0;
}

.crm-activity-task-footer {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.crm-activity-note-footer,
.crm-activity-task-footer {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: auto;
  flex-shrink: 0;
}

.crm-activity-hint {
  font-size: 0.8rem;
  margin: 0;
}

.crm-modal-actions-split {
  justify-content: space-between;
  align-items: center;
}

.crm-modal-actions-right {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.crm-activity-pre {
  margin: 0;
  font-size: 0.85rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.crm-detail-grid {
  display: grid;
  grid-template-columns: minmax(180px, 220px) minmax(260px, 1fr) minmax(180px, 220px);
  gap: 1rem;
  align-items: stretch;
  min-height: 360px;
}

@media (max-width: 1100px) {
  .crm-detail-grid {
    grid-template-columns: 1fr;
    min-height: 0;
  }
}

.crm-detail-col {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
}

.crm-detail-box {
  background: var(--mh2-bg);
  border-radius: var(--radius-sm);
  border: 1px solid var(--mh2-border);
  padding: 0.75rem 0.85rem;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.crm-detail-box-scroll {
  flex: 1;
  max-height: 220px;
  overflow-y: auto;
}

.crm-detail-notes-main {
  flex: 1;
  min-height: 320px;
}

.crm-detail-box-title {
  margin: 0 0 0.5rem 0;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--mh2-text-muted);
}

.crm-detail-subhead {
  margin: 1rem 0 0.5rem 0;
  font-size: 0.9rem;
  font-weight: 600;
}

.crm-detail-textarea {
  width: 100%;
  min-height: 0;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.95rem;
  resize: vertical;
  background: var(--mh2-surface);
}

.crm-detail-notes-field {
  min-height: 120px;
}

.crm-detail-notes-timeline {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 0.75rem;
}

.crm-add-note-form-inline {
  flex-direction: column;
  align-items: stretch;
}

.crm-add-note-form-inline textarea {
  width: 100%;
}

.crm-detail-db-list {
  font-size: 0.9rem;
  line-height: 1.45;
}

.crm-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.crm-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.crm-tab {
  padding: 0.5rem 1rem;
  border: 1px solid var(--mh2-border);
  background: var(--mh2-surface);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.9rem;
  cursor: pointer;
  color: var(--mh2-text);
}

.crm-tab:hover {
  background: var(--mh2-bg);
}

.crm-tab.active {
  background: var(--mh2-primary);
  color: #fff;
  border-color: var(--mh2-primary);
}

.crm-tab-panel {
  display: none;
}

.crm-tab-panel.active {
  display: block;
}

.crm-reporting-tables {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  align-items: start;
}

@media (max-width: 960px) {
  .crm-reporting-tables {
    grid-template-columns: 1fr;
  }
}

.crm-reporting-table-card {
  margin: 0;
  min-width: 0;
}

.crm-reporting-table-title {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--mh2-primary-dark, #234a61);
}

.crm-reporting-mini-table {
  width: 100%;
  font-size: 0.9rem;
}

.crm-table-scroll {
  max-height: min(50vh, 420px);
  overflow-y: auto;
  overflow-x: auto;
}

.crm-table-scroll .data-table thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: var(--mh2-bg, #f3f3f3);
  box-shadow: 0 1px 0 var(--mh2-border, rgba(0, 0, 0, 0.12));
}

#page-crm.crm-stitch .crm-table-scroll .data-table thead th {
  background: #f3f3f3;
  box-shadow: 0 1px 0 var(--crm-border);
}

.crm-table-scroll .data-table thead th.crm-sortable-th {
  cursor: pointer;
  user-select: none;
}

.crm-table-scroll .data-table thead th .crm-sort-indicator {
  font-size: 0.85em;
  font-weight: 700;
  margin-left: 0.2em;
  opacity: 0.85;
}

.crm-search-row {
  margin-bottom: 0.75rem;
}

.crm-search-row.crm-search-row-flex {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 0.75rem;
}

.crm-bulk-action-label {
  font-size: 0.9rem;
  color: var(--mh2-fg, inherit);
  margin: 0;
  white-space: nowrap;
}

.crm-bulk-action-select {
  min-width: 11rem;
  max-width: 16rem;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.95rem;
  background: var(--mh2-surface, #fff);
  color: var(--mh2-fg, inherit);
}

.crm-bulk-action-select:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.crm-table-select-th,
.crm-table-select-td {
  width: 2.5rem;
  text-align: center;
  vertical-align: middle;
  padding-left: 0.35rem;
  padding-right: 0.35rem;
}

.crm-table-select-th {
  line-height: 1;
}

.crm-list-row-checkbox,
.crm-list-select-all {
  width: 1.05rem;
  height: 1.05rem;
  cursor: pointer;
  vertical-align: middle;
}

.crm-search-input {
  width: 100%;
  max-width: 320px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 1rem;
}

.crm-pipeline-board {
  display: flex;
  gap: 1rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
}

.crm-pipeline-column {
  min-width: 260px;
  flex-shrink: 0;
  background: var(--mh2-bg);
  border-radius: var(--radius);
  padding: 0.75rem;
  border: 1px solid var(--mh2-border);
}

.crm-pipeline-stage-name {
  margin: 0 0 0.5rem 0;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--mh2-primary-dark);
}

.crm-pipeline-cards {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.crm-pipeline-card {
  padding: 0.6rem 0.75rem;
  cursor: default;
}

.crm-pipeline-card-title {
  margin: 0 0 0.25rem 0;
  font-weight: 500;
  font-size: 0.9rem;
}

.crm-pipeline-card-meta {
  margin: 0;
  font-size: 0.8rem;
  color: var(--mh2-text-muted);
}

.crm-report-summary {
  margin-bottom: 1rem;
}

.crm-leads-contacts-card {
  margin-top: 1rem;
}

.crm-report-filters-card {
  margin-top: 1rem;
}

.crm-report-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 1rem;
  align-items: flex-end;
}

.crm-report-filters label {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.crm-report-filters select,
.crm-report-filters input[type="text"] {
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.95rem;
  min-width: 120px;
}

.crm-report-contacts-card {
  margin-top: 1rem;
}

#crm-report-contacts-table tbody tr.crm-clickable-row {
  cursor: pointer;
}

#crm-report-contacts-table tbody tr.crm-clickable-row:hover {
  background: var(--mh2-bg);
}

.crm-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.crm-modal.hidden {
  display: none;
}

.crm-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
}

.crm-modal-content {
  position: relative;
  max-width: 480px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
}

.crm-modal-content.treatment-plan-outcomes-modal-shell {
  width: min(78rem, calc(100vw - 2rem));
  max-width: min(78rem, calc(100vw - 2rem));
  max-height: min(90vh, 56rem);
  overflow: hidden;
}

.crm-contact-modal-content.crm-contact-modal-content {
  max-width: 720px;
}

.crm-contact-form-row {
  display: flex;
  gap: 0;
  align-items: flex-start;
  margin-top: 0.5rem;
}

.crm-contact-form-left {
  flex: 1;
  min-width: 0;
  padding-right: 0;
}

.crm-contact-form-divider {
  width: 1px;
  min-width: 1px;
  align-self: stretch;
  background: var(--mh2-border);
  margin: 0 1.25rem;
}

.crm-contact-form-divider.hidden {
  display: none;
}

.crm-contact-form-patient-details {
  width: 260px;
  min-width: 260px;
  flex-shrink: 0;
  padding-left: 0;
  border-left: none;
}

.crm-contact-form-patient-details.hidden {
  display: none;
}

.crm-patient-details-title {
  margin: 0 0 0.75rem 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--mh2-primary-dark);
}

.crm-modal-content label {
  display: block;
  margin-top: 0.75rem;
  margin-bottom: 0.25rem;
  font-weight: 500;
  font-size: 0.9rem;
}

.crm-modal-content label .required {
  color: var(--mh2-error);
}

.crm-modal-content input,
.crm-modal-content textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 1rem;
}

.crm-modal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.25rem;
  justify-content: flex-end;
}

.crm-detail-content h3 {
  margin: 1rem 0 0.5rem 0;
  font-size: 1rem;
}

.crm-detail-section {
  margin-top: 1.25rem;
}

.crm-add-note-form {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  margin-top: 0.5rem;
}

.crm-add-note-form textarea {
  flex: 1;
  min-width: 0;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: 0.95rem;
}

.crm-note-item {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--mh2-border);
}

.crm-note-item:last-child {
  border-bottom: none;
}

.crm-note-meta {
  font-size: 0.8rem;
  color: var(--mh2-text-muted);
}

.crm-note-item p {
  margin: 0.25rem 0 0 0;
}

.crm-note-item .crm-note-delete {
  margin-top: 0.25rem;
}

#crm-contacts-table tbody tr,
#crm-organizations-table tbody tr.crm-clickable-row {
  cursor: pointer;
}

#crm-contacts-table tbody tr:hover,
#crm-organizations-table tbody tr.crm-clickable-row:hover {
  background: var(--mh2-bg);
}

#crm-leads-contacts-table tbody tr.crm-clickable-row {
  cursor: pointer;
}

#crm-leads-contacts-table tbody tr.crm-clickable-row:hover {
  background: var(--mh2-bg);
}

.crm-csv-field-ref {
  margin: 0 0 0.75rem 0;
  border: 1px solid var(--mh2-border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.65rem;
  background: var(--mh2-bg);
}

.crm-csv-field-ref summary {
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
}

.crm-csv-field-ref-intro {
  font-size: 0.85rem;
  margin: 0.4rem 0 0.5rem 0;
}

.crm-csv-field-ref-body {
  max-height: 12rem;
  overflow: auto;
  font-size: 0.88rem;
  line-height: 1.4;
  margin-top: 0.25rem;
}

.crm-csv-field-ref-line {
  margin: 0.35rem 0;
  word-wrap: break-word;
}

.crm-csv-field-ref-line code {
  font-size: 0.9em;
  padding: 0 0.2em;
}

.muted {
  color: var(--mh2-text-muted);
  font-size: 0.9rem;
}
