:root {
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #15233b;
  background: #f3f7fb;
  font-synthesis: none;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; overflow-x: hidden; background: #f3f7fb; }
button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 252px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 22px 16px;
  background: #122536;
  color: #fff;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.brand {
  display: flex; flex-direction: column; align-items: flex-start; gap: 9px;
  padding: 3px 6px 24px;
}
.brand-logo {
  display: block; width: 100%; max-width: 208px; height: auto;
  border: 1px solid rgba(255,255,255,.16); border-radius: 6px;
  background: #fff; box-shadow: 0 6px 18px rgba(4,17,28,.16);
}
.brand-product { padding-inline: 3px; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 14px; }
.brand span { margin-top: 3px; color: #9db1c1; font-size: 11px; }

.side-heading {
  min-height: 30px; padding: 0 8px; color: #8199aa; font-size: 10px;
  font-weight: 800; text-transform: uppercase; display: flex; align-items: center; justify-content: space-between;
}
.clinics-heading { margin-top: 16px; }
.icon-button {
  width: 30px; height: 30px; border: 0; border-radius: 5px;
  background: transparent; color: inherit; font-size: 19px;
}
.icon-button:hover { background: rgba(255,255,255,.08); }

.portfolio-link, .clinic-item {
  width: 100%; min-height: 50px; border: 0; border-radius: 7px;
  background: transparent; color: #dbe6ed;
}
.portfolio-link {
  padding: 8px 10px; display: flex; gap: 10px; align-items: center; text-align: left;
}
.portfolio-link:hover, .portfolio-link.active, .clinic-item:hover, .clinic-item.active { background: #203a4a; }
.portfolio-link.active, .clinic-item.active { box-shadow: inset 3px 0 #76c9ec; }
.portfolio-link span { display: block; font-size: 13px; }
.portfolio-link small, .clinic-select small { display: block; margin-top: 2px; color: #89a2b3; font-size: 10px; }
.nav-icon {
  width: 28px; height: 28px; flex: 0 0 auto; display: grid !important; place-items: center;
  border-radius: 6px; background: #2d4a5b; color: #9edcf5; font-weight: 800;
}

.clinic-selector { position: relative; flex: 0 0 auto; }
.clinic-selector-button {
  width: 100%; min-height: 52px; padding: 7px 9px; border: 1px solid #365264; border-radius: 7px;
  background: #172f40; color: #dbe6ed; display: flex; align-items: center; gap: 10px; text-align: left;
}
.clinic-selector-button:hover, .clinic-selector-button[aria-expanded="true"] { background: #203a4a; border-color: #54788e; }
.clinic-selector-button:focus-visible { outline: 2px solid #76c9ec; outline-offset: 2px; }
.clinic-selector-button:disabled { cursor: default; opacity: .65; }
.clinic-selector-copy { min-width: 0; flex: 1; }
.clinic-selector-copy strong, .clinic-selector-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.clinic-selector-copy strong { font-size: 12px; }
.clinic-selector-copy small { margin-top: 2px; color: #89a2b3; font-size: 10px; font-weight: 500; }
.clinic-selector-chevron { color: #89a2b3; font-size: 18px; line-height: 1; transition: transform .16s ease; }
.clinic-selector-button[aria-expanded="true"] .clinic-selector-chevron { transform: rotate(180deg); }
.clinic-list {
  position: fixed;
  z-index: 30;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-gutter: stable;
  display: grid;
  gap: 4px;
  padding: 6px;
  border: 1px solid #365264;
  border-radius: 8px;
  background: #122536;
  box-shadow: 0 16px 34px rgba(4, 17, 28, .36);
}
.clinic-list[hidden] { display: none; }
.clinic-list::-webkit-scrollbar { width: 6px; }
.clinic-list::-webkit-scrollbar-thumb { border-radius: 999px; background: #315064; }
.clinic-list::-webkit-scrollbar-track { background: transparent; }
.clinic-item { padding: 0; display: flex; align-items: center; }
.clinic-select {
  min-width: 0; flex: 1; min-height: 50px; padding: 8px 7px 8px 11px;
  border: 0; background: transparent; color: inherit; text-align: left;
  display: flex; align-items: center; justify-content: space-between;
}
.clinic-select span { min-width: 0; display: block; overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.connection-dot { width: 7px; height: 7px; flex: 0 0 auto; border-radius: 50%; background: #607888; }
.connection-dot.connected { background: #44d69b; box-shadow: 0 0 0 3px rgba(68,214,155,.1); }
.clinic-edit {
  width: 32px; height: 32px; margin-right: 4px; border: 0; border-radius: 5px;
  background: transparent; color: #88a0b0; font-weight: 800;
}
.clinic-edit:hover { background: rgba(255,255,255,.08); color: #fff; }
.privacy-note { flex: 0 0 auto; margin-top: 10px; padding: 14px 8px 4px; border-top: 1px solid #294250; }
.privacy-note strong, .privacy-note span { display: block; }
.privacy-note strong { font-size: 11px; }
.privacy-note span { margin-top: 5px; color: #829bab; font-size: 10px; line-height: 1.5; }
.sidebar-admin { flex: 0 0 auto; margin-top: 10px; padding-top: 14px; border-top: 1px solid #294250; }
.settings-link {
  width: 100%; min-height: 50px; padding: 8px 10px; border: 0; border-radius: 7px;
  background: transparent; color: #dbe6ed; display: flex; align-items: center;
  gap: 10px; text-align: left;
}
.settings-link:hover, .settings-link.active { background: #203a4a; }
.settings-link span { display: block; font-size: 13px; }
.settings-link small { display: block; margin-top: 2px; color: #89a2b3; font-size: 10px; }
.settings-icon { font-size: 15px !important; }
.sidebar-admin + .privacy-note { margin-top: 10px; }

main { min-width: 0; padding: 26px 32px 44px; }
.topbar, .control-bar, .dashboard { width: min(1440px, 100%); margin-inline: auto; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.eyebrow { margin: 0 0 5px; color: #6f8192; font-size: 10px; font-weight: 850; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 27px; letter-spacing: 0; }
h2 { margin-bottom: 0; font-size: 16px; letter-spacing: 0; }
.title-row { display: flex; align-items: center; gap: 10px; }
.clinic-badge {
  padding: 4px 7px; border: 1px solid #cbdbe5; border-radius: 4px;
  background: #fff; color: #4e6879; font-size: 10px; font-weight: 750;
}
.header-actions {
  display: flex;
  align-items: flex-end;
  flex-direction: column;
  gap: 6px;
}
.header-main-actions { display: flex; gap: 9px; }
.user-menu { display: flex; align-items: center; gap: 9px; }
.user-menu span { color: #617686; font-size: 11px; font-weight: 700; }
.primary-button, .secondary-button {
  min-height: 40px; padding: 0 15px; border-radius: 6px; font-weight: 750;
}
.primary-button { border: 1px solid #2585b5; background: #2585b5; color: #fff; }
.primary-button:hover { background: #1c709a; }
.primary-button:disabled { cursor: not-allowed; border-color: #aebdca; background: #aebdca; }
.secondary-button { border: 1px solid #d4e0e8; background: #fff; color: #334b5c; }
.sync-status-badge {
  min-height: 19px;
  padding: 3px 8px;
  border: 1px solid #d9e6ee;
  border-radius: 999px;
  background: #fff;
  color: #647887;
  font-size: 10px;
  font-weight: 750;
}
.sync-status-badge.ok { border-color: #bfe9d6; background: #ecfbf4; color: #237658; }
.sync-status-badge.syncing { border-color: #b9ddf2; background: #edf8fd; color: #236d92; }
.sync-status-badge.warning { border-color: #f2d7a7; background: #fff8eb; color: #94601f; }
.sync-status-badge.error { border-color: #efc4c4; background: #fff1f1; color: #963a3a; }
.sync-status-badge.muted { border-color: #d9e6ee; background: #f7fafc; color: #7b8d9a; }

.control-bar {
  min-height: 74px; margin-bottom: 16px; padding: 13px 16px;
  border: 1px solid #dfe8ef; border-radius: 8px; background: #fff;
  box-shadow: 0 4px 18px rgba(34,78,105,.05);
  display: flex; align-items: flex-end; flex-wrap: wrap; gap: 14px 18px;
}
.segmented { padding: 3px; border: 1px solid #dbe6ed; border-radius: 6px; background: #f5f8fa; display: flex; }
.segmented button {
  min-width: 66px; height: 31px; border: 0; border-radius: 4px;
  background: transparent; color: #607585; font-size: 11px; font-weight: 700;
}
.segmented button.active { background: #fff; color: #176f9b; box-shadow: 0 1px 4px rgba(33,78,105,.12); }
.period-inputs { display: flex; flex: 0 1 auto; min-width: 0; align-items: flex-end; gap: 9px; }
.period-inputs label { display: block; flex: 0 1 150px; width: 150px; min-width: 0; max-width: 150px; }
.period-inputs input {
  --period-control-height: 38px;
  display: block; min-width: 0; max-width: 100%; min-inline-size: 0;
  height: var(--period-control-height); line-height: var(--period-control-height);
  -webkit-appearance: none; appearance: none; text-align: center;
}
.period-inputs input::-webkit-date-and-time-value {
  display: flex; height: 100%; min-height: 0; margin: 0; padding: 0;
  align-items: center; justify-content: center; line-height: normal; text-align: center;
}
.period-inputs input::-webkit-datetime-edit { padding: 0; text-align: center; }
.control-bar > .segmented { flex: 0 0 auto; }
label span { display: block; margin-bottom: 5px; color: #607382; font-size: 10px; font-weight: 750; }
input, select {
  width: 100%; height: 38px; padding: 0 10px; border: 1px solid #cedce5;
  border-radius: 5px; background: #fff; color: #16283a;
}
input:focus, select:focus { outline: 2px solid #b6def0; border-color: #55a9ce; }
.period-summary { flex: 0 1 220px; min-width: 0; margin-left: auto; text-align: right; overflow-wrap: anywhere; }
.period-summary span, .period-summary strong { display: block; }
.period-summary span { color: #8494a1; font-size: 10px; }
.period-summary strong { margin-top: 4px; font-size: 12px; }

@media (min-width: 901px) {
  .control-bar > .segmented { align-self: flex-end; }
}

@media (min-width: 1000px) and (orientation: landscape) {
  .control-bar { flex-wrap: nowrap; }
  .period-inputs { flex-shrink: 0; }
}

.status-banner {
  margin-bottom: 14px; padding: 10px 13px; border: 1px solid #c9e4f0;
  border-radius: 6px; background: #edf8fc; color: #28647f; font-size: 12px;
}
.status-banner.error { border-color: #edc4c4; background: #fff1f1; color: #963a3a; }
.dashboard.report-loading .metrics,
.dashboard.report-loading .sortable-dashboard {
  opacity: 0.55;
  transition: opacity 120ms ease;
}

.metrics { display: grid; gap: 12px; margin-bottom: 14px; }
.overview-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.revenue-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.supplier-expense-metric { border-top: 3px solid #efb85d; padding-top: 15px; }
.project-switch-link { display: inline-flex; align-items: center; text-decoration: none; }
.activity-metrics,
.expense-metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: min(1010px, 100%);
}
.expense-metrics {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  width: min(760px, 100%);
}
.metric, .panel, .detail-strip {
  border: 1px solid #dfe8ef; border-radius: 8px; background: #fff;
  box-shadow: 0 5px 20px rgba(35,76,101,.045);
}
.metric {
  min-height: 125px; padding: 17px;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.metric.primary-metric { border-top: 3px solid #53b6de; padding-top: 15px; }
.metric span, .metric small { display: block; }
.metric span { color: #647887; font-size: 10px; font-weight: 750; }
.metric strong {
  display: block; margin: 11px 0 8px; font-size: 23px; font-weight: 750;
  white-space: nowrap; transition: color .18s ease, font-weight .18s ease;
}
.metric small { color: #8a9aa6; font-size: 9px; line-height: 1.4; }
.metric small.warning-text { color: #a4631c; font-weight: 650; }
.metric-action {
  appearance: none;
  background: none;
  border: 0;
  color: #0878ad;
  cursor: pointer;
  font: inherit;
  font-size: 9px;
  font-weight: 700;
  margin-top: 6px;
  padding: 0;
  text-align: left;
}
.metric-action:hover { text-decoration: underline; }
.metric-action:disabled { cursor: wait; opacity: .65; text-decoration: none; }

.login-page {
  min-height: 100vh;
  background: #eef5f9;
  display: grid;
  place-items: center;
}
.login-shell { width: min(420px, calc(100% - 32px)); padding: 24px 0; }
.login-panel {
  padding: 30px;
  border: 1px solid #d9e5ec;
  border-radius: 8px;
  background: #fff;
  box-shadow: 0 20px 50px rgba(37, 77, 101, .12);
}
.login-brand { align-items: center; padding: 0 0 28px; color: #16283a; }
.login-brand .brand-logo {
  width: min(240px, 100%); max-width: 240px; border-color: #e2eaf0;
  box-shadow: none;
}
.login-brand .brand-product { text-align: center; }
.login-heading h1 { font-size: 28px; }
.login-heading > p:last-child {
  color: #718492;
  font-size: 13px;
  line-height: 1.6;
}
.login-form { display: grid; gap: 16px; margin-top: 24px; }
.login-form .primary-button { width: 100%; margin-top: 4px; }

.panel {
  min-width: 0; max-width: 100%; min-height: 290px; padding: 18px;
  transition: border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.trend-panel { min-height: 270px; }
.panel-heading { display: flex; align-items: start; justify-content: space-between; gap: 16px; margin-bottom: 18px; }
.panel-note { color: #8999a5; font-size: 10px; }
.panel-description { margin: -10px 0 18px; line-height: 1.45; }
.sortable-dashboard {
  display: grid;
  min-width: 0; max-width: 100%;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.full-width-module { grid-column: 1 / -1; }
.drag-handle { cursor: grab; user-select: none; }
.drag-handle:active { cursor: grabbing; }
.drag-icon {
  width: 28px; height: 28px; flex: 0 0 auto; display: grid; place-items: center;
  border: 1px solid #dce7ed; border-radius: 5px; color: #7b909d;
  background: #f8fafc; font-size: 11px; font-weight: 850;
}
.panel-tools { display: flex; align-items: center; gap: 10px; }
.panel.dragging {
  opacity: .45;
  outline: 2px dashed #58b5dc;
  outline-offset: 2px;
}

.trend-chart {
  min-width: 0; max-width: 100%;
  height: 190px; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(74px, 1fr);
  gap: 6px; overflow-x: auto; padding-top: 4px;
}
.trend-column { min-width: 74px; display: grid; grid-template-rows: 23px 1fr 22px; gap: 4px; text-align: center; }
.trend-value { overflow: hidden; color: #5e7180; font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }
.trend-track { min-height: 120px; display: flex; align-items: end; justify-content: center; border-bottom: 1px solid #e5edf2; }
.trend-bar { width: min(28px, 68%); min-height: 2px; border-radius: 3px 3px 0 0; background: #56b8df; }
.trend-bar.empty { background: #e7eef3; }
.trend-label { color: #718391; font-size: 9px; white-space: nowrap; }

#dailyTrendChart { height: 220px; box-sizing: border-box; grid-auto-columns: minmax(110px, 1fr); grid-template-rows: minmax(0, 1fr); overflow-y: hidden; padding: 8px 6px 10px; }
#dailyTrendChart .trend-column { min-width: 110px; min-height: 0; grid-template-rows: 28px minmax(0, 1fr) 22px; border-radius: 8px; outline-offset: -2px; }
#dailyTrendChart .trend-track { min-height: 0; }
#dailyTrendChart .trend-value { color: #24435c; font-size: 13px; font-weight: 750; overflow: visible; font-variant-numeric: tabular-nums; transition: transform .16s ease, color .16s ease; }
#dailyTrendChart .trend-bar { width: 34px; border-radius: 5px 5px 0 0; transition: transform .16s ease, box-shadow .16s ease; transform-origin: bottom center; }
#dailyTrendChart .trend-column:is(:hover, :focus) .trend-value { color: #006c9b; font-weight: 900; transform: scale(1.08); }
#dailyTrendChart .trend-column:is(:hover, :focus) .trend-bar:not(.empty) { transform: scaleX(1.18); background: #079acb; box-shadow: 0 0 0 2px #b7e8f7, 0 4px 12px #0788b329; }
#dailyTrendChart .trend-column:focus { outline: 2px solid #9ad7ed; }
#dailyTrendChart .trend-label { font-size: 11px; }
@media (max-width: 700px) {
  #dailyTrendChart { grid-auto-columns: minmax(104px, 1fr); }
  #dailyTrendChart .trend-column { min-width: 104px; }
  #dailyTrendChart .trend-value { font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  #dailyTrendChart .trend-value, #dailyTrendChart .trend-bar { transition: none; }
}

.bar-chart { display: grid; gap: 13px; }
.scrollable-chart {
  max-height: 431px;
  overflow-y: auto;
  padding-right: 6px;
  scrollbar-gutter: stable;
}
.scrollable-chart::-webkit-scrollbar { width: 8px; }
.scrollable-chart::-webkit-scrollbar-track { background: #edf3f7; border-radius: 999px; }
.scrollable-chart::-webkit-scrollbar-thumb { background: #b8cbd8; border-radius: 999px; }
.scrollable-chart::-webkit-scrollbar-thumb:hover { background: #8fb1c4; }
.mobile-scroll-area { scrollbar-gutter: stable; }
.bar-row { min-height: 24px; display: grid; grid-template-columns: minmax(90px, 145px) minmax(100px, 1fr) 90px; align-items: center; gap: 10px; }
.bar-label {
  min-width: 0; display: flex; align-items: center; gap: 8px;
  color: #405463; font-size: 11px; white-space: nowrap;
}
.bar-rank {
  width: 20px; flex: 0 0 20px; color: #718391;
  font-size: 10px; font-weight: 800; text-align: center;
  font-variant-numeric: tabular-nums;
}
.bar-label-text { min-width: 0; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.bar-track { height: 8px; overflow: hidden; border-radius: 3px; background: #edf2f5; }
.bar-fill { height: 100%; min-width: 2px; border-radius: 3px; }
.bar-fill.zero { min-width: 0; }
.bar-fill.blue { background: #4baed5; }
.bar-fill.indigo { background: #6689d5; }
.bar-fill.cyan { background: #57c3bd; }
.bar-fill.activity-blue { background: #83bfe3; }
.bar-value { color: #203546; font-size: 11px; font-weight: 750; text-align: right; }
.bar-value small {
  display: block;
  margin-top: 2px;
  color: #718391;
  font-size: 9px;
  font-weight: 650;
}
.chart-empty { padding: 62px 0; color: #93a1ab; font-size: 11px; text-align: center; }

.doctor-activity-chart { display: grid; gap: 13px; }
.doctor-activity-header,
.doctor-activity-row {
  display: grid;
  grid-template-columns: 20px minmax(100px, 145px) minmax(90px, 1fr) 52px 60px;
  align-items: center;
  gap: 10px;
}
.doctor-activity-header {
  min-height: 18px;
  color: #718391;
  font-size: 9px;
  font-weight: 800;
  text-align: right;
  text-transform: uppercase;
}
.doctor-activity-header span:first-child { grid-column: 4; }
.doctor-activity-header span:last-child { grid-column: 5; }
.doctor-activity-row { min-height: 24px; color: #405463; font-size: 11px; }
.doctor-activity-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.doctor-activity-row strong {
  color: #203546;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.activity-sort {
  display: flex;
  overflow: hidden;
  border: 1px solid #d5e3eb;
  border-radius: 5px;
  background: #f5f9fb;
}
.activity-sort button {
  min-height: 28px;
  padding: 0 10px;
  border: 0;
  border-right: 1px solid #d5e3eb;
  background: transparent;
  color: #647987;
  font: inherit;
  font-size: 9px;
  font-weight: 800;
  cursor: pointer;
}
.activity-sort button:last-child { border-right: 0; }
.activity-sort button.active {
  background: #dff3fb;
  color: #176c91;
}
.activity-sort button:focus-visible {
  position: relative;
  z-index: 1;
  outline: 2px solid #47add7;
  outline-offset: -2px;
}
.clinic-activity-chart { display: grid; gap: 13px; }
.clinic-activity-header,
.clinic-activity-row {
  display: grid;
  grid-template-columns: 20px minmax(125px, 165px) minmax(80px, 1fr) 52px 60px;
  align-items: center;
  gap: 10px;
}
.clinic-activity-header {
  min-height: 18px;
  color: #718391;
  font-size: 9px;
  font-weight: 800;
  text-align: right;
  text-transform: uppercase;
}
.clinic-activity-header span:first-child { grid-column: 4; }
.clinic-activity-header span:last-child { grid-column: 5; }
.clinic-activity-row { min-height: 36px; color: #405463; font-size: 11px; }
.clinic-activity-name { min-width: 0; }
.clinic-activity-name strong,
.clinic-activity-name small { display: block; }
.clinic-activity-name strong {
  overflow: hidden;
  color: #405463;
  font-size: 11px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.clinic-activity-name small {
  margin-top: 3px;
  color: #8194a1;
  font-size: 8px;
  line-height: 1.25;
}
.clinic-activity-row > strong {
  color: #203546;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  text-align: right;
}
.clinic-activity-row.not-synced .clinic-activity-name strong,
.clinic-activity-row.not-synced > strong { color: #8b9aa4; }
.clinic-activity-row.not-synced .clinic-activity-name small { color: #b36b62; }
.clinic-new-patient-row.not-synced .bar-label,
.clinic-new-patient-row.not-synced .bar-value { color: #8b9aa4; }
.clinic-new-patient-row.not-synced .bar-value small { color: #b36b62; }

@media (min-width: 701px) {
  .metric:hover, .panel:hover {
    border-color: #a9d7ea;
    box-shadow: 0 12px 30px rgba(35, 105, 139, .12);
    transform: translateY(-2px);
  }
  .metric:hover strong {
    color: #0c2943;
    font-weight: 850;
  }
  .panel:hover .bar-value,
  .panel:hover .activity-row strong {
    color: #0c2943;
    font-weight: 850;
  }
}

@media (prefers-reduced-motion: reduce) {
  .metric, .panel { transition: none; }
  .metric:hover, .panel:hover { transform: none; }
}

.activity-chart { display: grid; gap: 20px; padding-top: 16px; }
.activity-row { display: grid; grid-template-columns: 110px 1fr 54px; align-items: center; gap: 12px; }
.activity-row span { color: #526877; font-size: 11px; }
.activity-row strong { font-size: 13px; text-align: right; }
.activity-track { height: 22px; border-radius: 4px; background: #edf3f6; overflow: hidden; }
.activity-track i { display: block; height: 100%; border-radius: 4px; background: #82cbe8; }

.status-list, .insight-list { display: grid; gap: 10px; }
.status-row {
  min-height: 48px; padding: 10px 0; display: grid;
  grid-template-columns: 10px minmax(0, 1fr) auto; align-items: center; gap: 11px;
  border-bottom: 1px solid #edf2f5;
}
.status-row:last-child { border-bottom: 0; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #95a5b0; }
.status-row.ok .status-dot { background: #35bf87; box-shadow: 0 0 0 4px rgba(53,191,135,.1); }
.status-row.warning .status-dot { background: #e6a23c; box-shadow: 0 0 0 4px rgba(230,162,60,.12); }
.status-row.muted .status-dot { background: #b5c4ce; }
.status-row strong, .status-row small { display: block; }
.status-row strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.status-row small { margin-top: 2px; color: #7e8f9b; font-size: 10px; }
.status-row b { color: #102840; font-size: 12px; }
.insight-row {
  padding: 12px; border: 1px solid #e2edf3; border-radius: 7px; background: #f8fbfd;
}
.insight-row strong, .insight-row span { display: block; }
.insight-row strong { font-size: 12px; }
.insight-row span { margin-top: 4px; color: #6f8190; font-size: 11px; line-height: 1.45; }
.insight-row.ok { border-color: #d4efe4; background: #f3fbf8; }
.insight-row.warning { border-color: #f0ddbc; background: #fff9ee; }

.detail-strip {
  margin-top: 14px; padding: 15px 18px; display: grid; grid-template-columns: repeat(4, 1fr);
}
.detail-strip div + div { border-left: 1px solid #e6edf2; padding-left: 18px; }
.detail-strip span, .detail-strip strong { display: block; }
.detail-strip span { color: #7b8c98; font-size: 9px; text-transform: uppercase; font-weight: 750; }
.detail-strip strong { margin-top: 5px; font-size: 14px; }

.settings-view { width: min(1440px, 100%); margin: 0 auto; }
.doctor-management-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.doctor-directory-row { grid-template-columns: minmax(180px, 1.2fr) minmax(120px, 1fr) 90px 78px; }
.doctor-directory-row code { overflow-wrap: anywhere; }
.doctor-unlinked { margin-top: 16px; padding: 16px; }
.doctor-unlinked summary { cursor: pointer; font-weight: 700; }
.doctor-unlinked p { color: #506675; font-size: 12px; }
.doctor-unlinked-row { display: flex; gap: 16px; flex-wrap: wrap; padding: 8px 0; font-size: 12px; }
@media (max-width: 700px) {
  .settings-header:has(#addDoctor) { flex-wrap: wrap; }
  .settings-table-header.doctor-directory-row { display: none; }
  .settings-clinic-row.doctor-directory-row { grid-template-columns: minmax(0, 1fr) 78px; }
  .doctor-directory-row > code { grid-column: 1; }
  .doctor-directory-row > .api-status { grid-column: 1; justify-self: start; }
  .doctor-directory-row > button { grid-column: 2; grid-row: 1; }
}
.dashboard.report-loading .metric strong {
  visibility: hidden;
}
.dashboard.report-loading .metric::after {
  content: "Loading…";
  color: var(--muted);
  font-size: 12px;
}
.user-management-header { margin-top: 18px; }
.settings-header {
  padding: 22px; border: 1px solid #dfe8ef; border-radius: 8px; background: #fff;
  box-shadow: 0 5px 20px rgba(35,76,101,.045);
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
}
.settings-header h2 { font-size: 20px; }
.settings-header p:last-child { max-width: 620px; margin: 7px 0 0; color: #748693; font-size: 11px; }
.settings-summary {
  margin: 14px 0; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px;
}
.settings-summary article {
  min-height: 92px; padding: 17px; border: 1px solid #dfe8ef; border-radius: 8px;
  background: #fff; box-shadow: 0 5px 20px rgba(35,76,101,.04);
}
.settings-summary span, .settings-summary strong { display: block; }
.settings-summary span { color: #718491; font-size: 10px; font-weight: 750; }
.settings-summary strong { margin-top: 9px; font-size: 22px; }
.settings-panel {
  overflow: hidden; border: 1px solid #dfe8ef; border-radius: 8px; background: #fff;
  box-shadow: 0 5px 20px rgba(35,76,101,.045);
}
.settings-table-header, .settings-clinic-row {
  display: grid; grid-template-columns: minmax(210px, 1.4fr) minmax(150px, 1fr) 100px 150px 78px;
  align-items: center; gap: 16px;
}
#settingsView .settings-table-header:not(.user-table-header), #settingsClinicList .settings-clinic-row { grid-template-columns: minmax(180px, 1.4fr) minmax(130px, 1fr) 100px 140px 110px; }
.clinic-settings-actions { display: flex; flex-direction: column; align-items: stretch; gap: 5px; }
#clinicInfoForm textarea { width: 100%; padding: 10px 12px; border: 1px solid #d3dfe7; border-radius: 6px; font: inherit; resize: vertical; }
.user-table-header, .settings-user-row {
  display: grid; grid-template-columns: minmax(100px, .7fr) 105px minmax(140px, 1fr) minmax(130px, .8fr) 120px minmax(230px, 1.3fr);
  align-items: center; gap: 10px;
}
.settings-table-header {
  min-height: 42px; padding: 0 18px; background: #f7fafc; color: #758895;
  border-bottom: 1px solid #e4ecf1; font-size: 9px; font-weight: 800; text-transform: uppercase;
}
.settings-clinic-row { min-height: 72px; padding: 10px 18px; border-bottom: 1px solid #edf2f5; }
.settings-user-row {
  min-height: 58px; padding: 10px 18px; border-bottom: 1px solid #edf2f5;
}
.settings-clinic-row:last-child { border-bottom: 0; }
.settings-user-row:last-child { border-bottom: 0; }
.settings-clinic-row code { color: #466274; font-size: 11px; }
.settings-clinic-row > span, .settings-user-row > span { color: #506675; font-size: 11px; }
.settings-user-row strong { font-size: 12px; }
.settings-user-row.disabled-user { background: #fafcfd; }
.settings-user-row.disabled-user > strong { color: #80909a; }
.user-status-cell, .user-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.api-status.disabled { background: #f1f3f5; color: #687983; }
.danger-button {
  min-height: 32px; padding: 0 11px; border: 1px solid #f0c8c4; border-radius: 6px;
  background: #fff5f4; color: #b53026; font-weight: 750; cursor: pointer;
}
.danger-button:disabled { opacity: .45; cursor: not-allowed; }
.settings-clinic-name { min-width: 0; display: flex; align-items: center; gap: 11px; }
.settings-clinic-name > span:last-child { min-width: 0; }
.settings-clinic-name strong, .settings-clinic-name small { display: block; }
.settings-clinic-name strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.settings-clinic-name small { margin-top: 3px; color: #8798a3; font-size: 9px; }
.clinic-avatar {
  width: 34px; height: 34px; flex: 0 0 auto; display: grid; place-items: center;
  border-radius: 7px; background: #e6f4fa; color: #257ca5; font-size: 13px; font-weight: 850;
}
.api-status {
  width: fit-content; padding: 5px 7px; border-radius: 4px; font-size: 9px !important; font-weight: 750;
}
.api-status.saved { background: #e7f7f0; color: #27775a; }
.api-status.missing { background: #fff0dc; color: #98601d; }
.settings-edit { min-height: 32px; padding: 0 11px; font-size: 10px; }
.settings-empty { padding: 22px; color: #718491; font-size: 12px; }

dialog {
  width: min(500px, calc(100vw - 28px)); padding: 0; border: 0; border-radius: 8px;
  box-shadow: 0 24px 80px rgba(14,36,51,.3);
}
dialog::backdrop { background: rgba(14,31,43,.48); }
dialog form { padding: 22px; }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; margin-bottom: 20px; }
dialog label { display: block; margin-bottom: 15px; }
dialog small { display: block; margin-top: 5px; color: #84939e; font-size: 10px; }
.credential-status {
  width: fit-content; margin: -5px 0 15px; padding: 4px 7px;
  border-radius: 4px; font-size: 10px; font-weight: 750;
}
.credential-status.saved { background: #e8f8f1; color: #267657; }
.credential-status.missing { background: #fff1df; color: #94601f; }
.checkbox-field { display: flex !important; align-items: center; gap: 9px; }
.checkbox-field.hidden { display: none !important; }
.checkbox-field input { width: 16px; height: 16px; margin: 0; }
.checkbox-field span { margin: 0; }
.clinic-access-options {
  margin: 0 0 15px; padding: 12px; border: 1px solid #dfe8ef;
  border-radius: 6px; background: #f8fbfd;
}
.clinic-access-options > span {
  display: block; margin-bottom: 9px; color: #607382; font-size: 10px; font-weight: 750;
}
.clinic-access-options label { margin-bottom: 8px; }
.clinic-access-options .project-sub-permission {
  margin-left: 25px;
  color: var(--muted);
  font-size: 13px;
}
.clinic-access-options .project-sub-permission:has(input:disabled) {
  opacity: 0.55;
}
.date-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.dialog-note { color: #6f818f; font-size: 11px; line-height: 1.55; }
.csv-import-section {
  margin-top: 16px; padding: 14px; border: 1px solid #dce8ef;
  border-radius: 7px; background: #f7fbfd;
}
.csv-import-section strong, .csv-import-section span { display: block; }
.csv-import-section strong { color: #203546; font-size: 12px; }
.csv-import-section > div span { margin-top: 4px; color: #738794; font-size: 10px; line-height: 1.45; }
.csv-import-section .file-field { margin: 13px 0 10px; }
.queue-completeness { display: flex; align-items: flex-start; gap: 8px; }
.queue-completeness input { width: 16px; min-width: 16px; height: 16px; margin: 2px 0 0; }
.queue-completeness span { font-size: 11px; line-height: 1.5; }
#historyDialog { max-height: calc(100dvh - 24px); overflow-y: auto; }
.csv-import-section input[type="file"] {
  width: 100%; margin-top: 6px; padding: 8px; border: 1px solid #cfdee7;
  border-radius: 5px; background: #fff; color: #405463; font-size: 10px;
}
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.form-error { padding: 9px 11px; border-radius: 5px; background: #fff0f0; color: #963a3a; font-size: 11px; }
.sync-dialog { width: min(680px, calc(100vw - 28px)); }
.sync-scope {
  margin: 18px 0; display: grid; grid-template-columns: 1fr 1fr;
  overflow: hidden; border: 1px solid #d7e4ec; border-radius: 6px;
}
.sync-scope label {
  min-height: 48px; margin: 0; padding: 0 16px; display: flex;
  align-items: center; gap: 10px; cursor: pointer;
}
.sync-scope label + label { border-left: 1px solid #d7e4ec; }
.sync-scope input, .sync-clinic-option input, .sync-select-all input {
  width: 16px; height: 16px; flex: 0 0 auto; margin: 0;
}
.sync-scope span, .sync-select-all span { margin: 0; color: #405463; font-size: 11px; }
.sync-list-heading {
  min-height: 30px; display: flex; align-items: center;
  justify-content: space-between; gap: 16px;
  color: #6f8192; font-size: 10px; font-weight: 800; text-transform: uppercase;
}
.sync-select-all { margin: 0 !important; display: flex !important; align-items: center; gap: 8px; cursor: pointer; }
.sync-select-all span { text-transform: none; }
.sync-clinic-list {
  max-height: 300px; overflow-y: auto; border: 1px solid #dfe8ef;
  border-radius: 6px; scrollbar-gutter: stable;
}
.sync-clinic-option {
  min-height: 48px; margin: 0 !important; padding: 0 14px;
  display: grid !important; grid-template-columns: 16px minmax(0, 1fr) auto;
  align-items: center; gap: 12px; cursor: pointer; border-bottom: 1px solid #edf2f5;
}
.sync-clinic-option:last-child { border-bottom: 0; }
.sync-clinic-option:hover { background: #f7fbfd; }
.sync-clinic-name { margin: 0; overflow: hidden; color: #203546; font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.sync-clinic-status { margin: 0; display: flex; align-items: center; gap: 6px; color: #718491; font-size: 10px; }
.sync-clinic-status i { width: 7px; height: 7px; border-radius: 50%; background: #35bf87; }
.sync-dialog-footer { margin-top: 18px; display: flex; align-items: center; justify-content: space-between; gap: 18px; }
.sync-dialog-footer > strong { color: #405463; font-size: 11px; }
.sync-dialog-footer .dialog-actions { margin-top: 0; }

@media (min-width: 701px) and (max-width: 1200px) {
  .topbar { flex-wrap: wrap; align-items: flex-start; }
  .header-actions { min-width: 0; max-width: 100%; }
  .header-main-actions { flex-wrap: wrap; justify-content: flex-end; }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 210px minmax(0, 1fr); }
  main { padding: 22px 18px 36px; }
  .control-bar { align-items: flex-end; }
  .period-summary { flex-basis: 100%; margin-left: 0; text-align: left; }
  .sortable-dashboard { grid-template-columns: minmax(0, 1fr); }
  .full-width-module { grid-column: auto; }
}

@media (min-width: 701px) and (max-width: 1100px) and (orientation: portrait) {
  .control-bar { --period-single-width: 260px; display: grid; grid-template-columns: minmax(0, 1fr); align-items: start; gap: 16px; }
  .control-bar > .segmented { justify-self: start; width: min(var(--period-single-width), 100%); }
  .control-bar > .segmented button { flex: 1; min-width: 0; }
  .period-inputs { display: grid; width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
  .period-inputs label { display: flex; flex-direction: column; gap: 6px; width: 100%; max-width: none; }
  .period-inputs label span { margin: 0; }
  .period-inputs #dayField, .period-inputs #monthField { grid-column: 1 / -1; max-width: var(--period-single-width); }
  .period-inputs input {
    box-sizing: border-box; width: 100%; inline-size: 100%; max-inline-size: 100%; min-inline-size: 0;
    --period-control-height: 44px;
    height: 44px; padding: 0 12px;
  }
  .period-summary { margin: 0; text-align: left; }
}

@media (max-width: 700px) {
  .app-shell { display: block; width: 100%; max-width: 100vw; overflow-x: hidden; }
  .sidebar { position: static; width: 100%; height: auto; padding: 13px; overflow: visible; }
  .brand { padding-bottom: 14px; }
  .privacy-note { display: none; }
  .sidebar-admin { margin-top: 14px; }
  .clinic-list { grid-template-columns: 1fr; }
  main { width: 100%; max-width: 100vw; overflow-x: hidden; padding: 18px 13px 30px; }
  .topbar, .control-bar, .dashboard, .settings-view {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  .topbar { align-items: start; }
  .header-actions { align-items: flex-start; flex-direction: column; }
  .header-main-actions { flex-wrap: wrap; }
  .control-bar { display: block; }
  .period-inputs { margin-top: 12px; }
  .period-summary { margin-top: 12px; text-align: left; }
  .overview-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .revenue-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sales-metrics .primary-metric { grid-column: 1 / -1; }
  .activity-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); width: 100%; }
  .expense-metrics { grid-template-columns: repeat(3, minmax(0, 1fr)); width: 100%; }
  .metric { min-height: 104px; padding: 14px; }
  .metric strong { margin: 9px 0 6px; font-size: 21px; }
  .metric small { font-size: 9px; }
  .panel { min-width: 0; max-width: 100%; overflow: hidden; min-height: auto; padding: 16px; }
  .panel-heading { margin-bottom: 14px; }
  .sortable-dashboard { min-width: 0; max-width: 100%; gap: 12px; }
  .trend-panel { min-height: auto; }
  .trend-chart {
    width: 100%;
    max-width: 100%;
    height: 168px;
    grid-auto-columns: 72px;
    overflow-x: auto;
  }
  .trend-column { min-width: 72px; }
  .bar-chart { gap: 11px; }
  .scrollable-chart,
  #paymentModeChart,
  #treatmentChart,
  #revenueChart,
  #clinicChart,
  #dataStatusList {
    max-height: 318px;
    overflow-y: auto;
    padding-right: 4px;
    scrollbar-gutter: stable;
  }
  .bar-row {
    min-width: 0;
    min-height: 38px;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 5px 10px;
  }
  .doctor-activity-chart { gap: 11px; }
  .doctor-activity-header,
  .doctor-activity-row {
    grid-template-columns: 18px minmax(0, 1fr) 50px 58px;
    gap: 5px 8px;
  }
  .doctor-activity-header span:first-child { grid-column: 3; }
  .doctor-activity-header span:last-child { grid-column: 4; }
  .doctor-activity-row { min-height: 38px; }
  .doctor-activity-row .bar-track {
    grid-column: 1 / -1;
    grid-row: 2;
  }
  #clinicActivityPanel .panel-heading { flex-wrap: wrap; }
  .clinic-activity-chart { gap: 11px; }
  .clinic-activity-header,
  .clinic-activity-row {
    grid-template-columns: 18px minmax(0, 1fr) 50px 58px;
    gap: 5px 8px;
  }
  .clinic-activity-header span:first-child { grid-column: 3; }
  .clinic-activity-header span:last-child { grid-column: 4; }
  .clinic-activity-row { min-height: 48px; }
  .clinic-activity-row .bar-track {
    grid-column: 1 / -1;
    grid-row: 2;
  }
  .bar-label { min-width: 0; grid-column: 1; grid-row: 1; }
  .bar-value { grid-column: 2; grid-row: 1; font-size: 10px; }
  .bar-value small { font-size: 8px; }
  .bar-track { grid-column: 1 / -1; grid-row: 2; }
  .drag-icon { display: none; }
  .drag-handle { cursor: default; }
  .detail-strip { grid-template-columns: repeat(2, 1fr); gap: 16px 0; }
  .detail-strip div:nth-child(3) { border-left: 0; padding-left: 0; }
  .settings-table-header { display: none; }
  #settingsClinicList .settings-clinic-row, .settings-clinic-row {
    grid-template-columns: minmax(0, 1fr) auto; gap: 8px 12px; padding: 14px;
  }
  .settings-user-row {
    grid-template-columns: minmax(0, 1fr) auto; gap: 7px 12px; padding: 14px;
  }
  .settings-user-row > strong,
  .settings-user-row > span { grid-column: 1; }
  .settings-user-row .user-actions { grid-column: 1 / -1; grid-row: auto; }
  .settings-clinic-row code, .settings-clinic-row > span { grid-column: 1; margin-left: 45px; }
  .settings-clinic-row .settings-edit { grid-column: 2; grid-row: 1; }
  .clinic-settings-actions { grid-column: 2; grid-row: 1 / span 3; align-self: start; }
}

@media (max-width: 460px) {
  .topbar { display: block; }
  .header-actions { margin-top: 15px; }
  .header-main-actions { flex-wrap: wrap; }
  .segmented button { min-width: 58px; }
  .activity-sort button { min-height: 30px; padding: 0 8px; }
  .period-inputs { display: block; }
  .period-inputs label + label { margin-top: 9px; }
  .overview-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .revenue-metrics article:first-child { grid-column: 1 / -1; }
  .activity-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .expense-metrics { grid-template-columns: 1fr; }
  .metric { min-height: 96px; padding: 12px; }
  .activity-metrics .metric strong { font-size: 19px; }
  .activity-metrics .metric small { font-size: 8px; }
  .bar-row { grid-template-columns: minmax(0, 1fr) auto; }
  .bar-label { font-size: 10px; }
  .bar-rank { width: 18px; flex-basis: 18px; font-size: 9px; }
  .trend-chart { grid-auto-columns: 70px; }
  .trend-column { min-width: 70px; }
  .date-pair { grid-template-columns: 1fr; }
  .settings-header { align-items: stretch; flex-direction: column; }
  .settings-summary { grid-template-columns: 1fr; }
  .sync-scope { grid-template-columns: 1fr; }
  .sync-scope label + label { border-top: 1px solid #d7e4ec; border-left: 0; }
  .sync-dialog-footer { align-items: stretch; flex-direction: column; }
  .sync-dialog-footer .dialog-actions { width: 100%; }
  .sync-dialog-footer .dialog-actions button { flex: 1; }
}

/* Patient profile summaries share the existing dashboard scope and layout. */
.patient-profile-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.patient-profile-card { min-width: 0; padding: 20px; border: 1px solid var(--border, #dce6ef); border-radius: 12px; }
.patient-profile-card h3 { margin: 0 0 8px; font-size: 17px; }
.patient-profile-card > .panel-note { margin: 0 0 20px; line-height: 1.5; }
.profile-gender { display: flex; flex-wrap: wrap; align-items: center; gap: 20px; padding-top: 8px; }
.period-lock-panel { padding: 20px; margin-top: 24px; }
.period-lock-panel p, .period-lock-panel li { line-height: 1.6; overflow-wrap: anywhere; }
.period-lock-actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; margin: 16px 0; }
.period-lock-actions label { display: grid; gap: 8px; }
.period-lock-actions input { padding: 10px; border: 1px solid #cbd5e1; border-radius: 8px; max-width: 100%; }
@media (max-width: 600px) { .period-lock-actions > * { width: 100%; min-width: 0; } }
.profile-donut { width: 136px; height: 136px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0; }
.profile-donut > div { width: 98px; height: 98px; border-radius: 50%; background: white; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; }
.profile-donut strong { font-size: 27px; }
.profile-donut span, .profile-legend { font-size: 12px; }
.profile-legend > div { display: flex; align-items: center; gap: 8px; margin: 14px 0; }
.profile-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.profile-bar-row { display: grid; grid-template-columns: 68px minmax(20px, 1fr) 90px; gap: 10px; align-items: center; margin: 16px 0; font-size: 12px; }
.profile-bar-row strong { text-align: right; white-space: nowrap; font-size: 12px; }
.profile-bar-track { height: 10px; background: #edf3f7; border-radius: 5px; overflow: hidden; }
.profile-bar-track > div { height: 100%; background: #128c9e; border-radius: inherit; }
.profile-bar-track > .profile-bar-unknown { background: #cbd5e1; }
.patient-profile-card > .profile-tag-note { margin-top: 22px; margin-bottom: 0; }
@media (max-width: 1200px) { .patient-profile-card { padding: 14px; } .profile-bar-row { grid-template-columns: 58px minmax(12px, 1fr) 80px; gap: 6px; } }
@media (max-width: 1000px) { .patient-profile-grid { grid-template-columns: 1fr; } }
