:root {
  color-scheme: light;
  --bg: #ecfeff;
  --bg-2: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --line: #dbe7ee;
  --line-strong: #c7d7df;
  --text: #12313f;
  --muted: #617483;
  --muted-2: #8aa0ad;
  --primary: #0891b2;
  --primary-strong: #007c96;
  --primary-soft: #cffafe;
  --green: #059669;
  --green-soft: #dcfce7;
  --blue: #1d7ed8;
  --blue-soft: #dbeafe;
  --amber: #d97706;
  --amber-soft: #ffedd5;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --slate: #64748b;
  --slate-soft: #e2e8f0;
  --nav: #073547;
  --nav-deep: #06293b;
  --shadow: 0 18px 45px rgba(15, 61, 75, 0.12);
  --shadow-soft: 0 10px 24px rgba(15, 61, 75, 0.08);
  --radius: 8px;
  --font: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --sidebar-width: 108px;
  --schedule-header-height: 74px;
  --time-slot-height: 26px;
  --hour-height: 104px;
  --timeline-height: 1144px;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, rgba(236, 254, 255, 0.95), rgba(248, 250, 252, 0.98) 42%),
    radial-gradient(circle at 45% 0%, rgba(34, 211, 238, 0.18), transparent 34%);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: 0;
}

button,
input,
select {
  font: inherit;
}

button,
select {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(8, 145, 178, 0.28);
  outline-offset: 2px;
}

.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;
}

.skip-link {
  position: fixed;
  top: 12px;
  left: 120px;
  z-index: 20;
  transform: translateY(-140%);
  border-radius: 6px;
  background: var(--nav);
  color: white;
  padding: 10px 14px;
  text-decoration: none;
}

.skip-link:focus {
  transform: translateY(0);
}

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

.sidebar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  height: 100vh;
  flex-direction: column;
  align-items: center;
  background: linear-gradient(180deg, var(--nav), var(--nav-deep));
  color: rgba(255, 255, 255, 0.86);
  box-shadow: 8px 0 30px rgba(6, 41, 59, 0.2);
}

.brand-mark {
  display: grid;
  width: 100%;
  height: 72px;
  place-items: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  color: #67e8f9;
}

.brand-mark svg {
  width: 44px;
  height: 44px;
  filter: drop-shadow(0 10px 18px rgba(34, 211, 238, 0.25));
}

.nav-list {
  display: flex;
  width: 100%;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px 12px;
}

.nav-item,
.collapse-button {
  position: relative;
  display: grid;
  width: 100%;
  min-height: 58px;
  place-items: center;
  gap: 3px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: inherit;
  transition:
    background-color 180ms ease,
    color 180ms ease;
}

.nav-item:hover,
.collapse-button:hover {
  background: rgba(255, 255, 255, 0.08);
}

.nav-item.is-active {
  background: linear-gradient(180deg, #11b7c8, #0793a9);
  color: white;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3), 0 12px 22px rgba(8, 145, 178, 0.28);
}

.nav-item span,
.collapse-button span {
  max-width: 100%;
  min-width: 0;
  overflow: hidden;
  font-size: 10.5px;
  font-weight: 600;
  line-height: 1.12;
  text-align: center;
  text-overflow: clip;
  white-space: nowrap;
}

.nav-badge {
  position: absolute;
  top: 8px;
  right: 10px;
  display: grid;
  min-width: 18px;
  height: 18px;
  place-items: center;
  border-radius: 999px;
  background: #22d3ee;
  color: #073547;
  font-size: 10px;
}

.icon,
.nav-item svg,
.collapse-button svg,
.icon-button svg,
.clinic-switch svg,
.primary-button svg,
.secondary-button svg,
.quick-card svg {
  width: 22px;
  height: 22px;
}

.collapse-button {
  margin: 0 8px 10px;
}

.workspace {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: grid;
  grid-template-columns: 230px 270px minmax(260px, 1fr) auto;
  gap: 12px;
  align-items: center;
  min-height: 72px;
  padding: 10px 22px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(18px);
}

.product-title {
  display: grid;
  gap: 1px;
}

.product-title strong {
  font-size: 17px;
}

.product-title span,
.title-block span,
.summary-heading span {
  color: var(--muted);
  font-size: 12px;
}

.clinic-switch,
.global-search,
.secondary-button,
.primary-button,
.segmented,
.filter-row select,
.date-nav button,
.month-switch button,
.icon-button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  color: var(--text);
  transition:
    border-color 180ms ease,
    background-color 180ms ease,
    box-shadow 180ms ease,
    color 180ms ease;
}

.clinic-switch {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 12px;
  font-weight: 650;
  white-space: nowrap;
}

.clinic-switch .chevron {
  width: 16px;
  height: 16px;
}

.global-search {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
}

.global-search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--text);
}

.global-search input::placeholder {
  color: #8ba0ad;
}

kbd {
  border-radius: 5px;
  background: #f1f5f9;
  color: var(--muted);
  padding: 2px 7px;
  font-size: 12px;
}

.top-actions,
.toolbar-actions,
.date-nav,
.month-switch,
.chips,
.legend-row,
.detail-actions {
  display: flex;
  align-items: center;
}

.top-actions {
  justify-content: end;
  gap: 8px;
}

.icon-button {
  position: relative;
  display: inline-grid;
  width: 44px;
  place-items: center;
  padding: 0;
  color: #4e6575;
}

.icon-button:hover,
.clinic-switch:hover,
.global-search:focus-within,
.secondary-button:hover,
.filter-row select:hover,
.date-nav button:hover,
.month-switch button:hover {
  border-color: #a6d7e4;
  box-shadow: 0 8px 20px rgba(8, 145, 178, 0.08);
}

.has-badge b {
  position: absolute;
  top: -4px;
  right: -4px;
  display: grid;
  min-width: 18px;
  height: 18px;
  place-items: center;
  border-radius: 999px;
  background: #ef4444;
  color: white;
  font-size: 10px;
}

.profile-button {
  display: grid;
  grid-template-columns: 38px auto;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  border: 0;
  background: transparent;
  color: var(--text);
  text-align: left;
}

.profile-button span {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: 50%;
  background: #bdf4f6;
  color: var(--primary-strong);
  font-weight: 750;
}

.profile-button strong {
  max-width: 125px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-layout {
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 12px;
  padding: 12px;
}

.date-panel,
.schedule-panel,
.detail-panel {
  min-width: 0;
}

.date-panel {
  display: grid;
  align-content: start;
  gap: 12px;
}

.date-card,
.summary-card,
.quick-card,
.schedule-panel,
.detail-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow-soft);
}

.date-card,
.summary-card,
.quick-card {
  padding: 16px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(20px, 2vw, 28px);
  font-weight: 720;
}

h2 {
  font-size: 17px;
}

.date-nav {
  gap: 7px;
}

.date-nav button,
.month-switch button {
  display: grid;
  min-width: 38px;
  place-items: center;
  padding: 0 10px;
}

.date-nav svg,
.month-switch svg {
  width: 18px;
  height: 18px;
}

.month-switch {
  justify-content: space-between;
  margin-top: 18px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
  margin-top: 14px;
}

.calendar-weekday {
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  text-align: center;
}

.calendar-day {
  position: relative;
  display: grid;
  min-width: 0;
  height: 38px;
  place-items: center;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-weight: 650;
}

.calendar-day:hover {
  background: #eefcff;
}

.calendar-day.is-muted {
  color: #a6b6c0;
}

.calendar-day.is-today span {
  color: var(--primary-strong);
}

.calendar-day.is-selected {
  background: var(--primary);
  color: white;
  box-shadow: 0 10px 20px rgba(8, 145, 178, 0.24);
}

.calendar-day.is-selected span {
  color: white;
}

.calendar-day i {
  position: absolute;
  bottom: 5px;
  width: min(22px, var(--load));
  height: 3px;
  border-radius: 999px;
  background: currentColor;
  opacity: 0.22;
}

.summary-card {
  display: grid;
  gap: 14px;
}

.summary-heading {
  display: grid;
  gap: 3px;
}

.summary-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
}

.summary-row:last-child {
  border-bottom: 0;
}

.summary-row.is-total {
  color: var(--text);
}

.summary-row span {
  display: inline-flex;
  align-items: center;
  gap: 9px;
}

.summary-row strong {
  color: var(--text);
  font-size: 17px;
}

.summary-icon {
  width: 22px;
  height: 22px;
  padding: 4px;
  border-radius: 6px;
  background: #eefcff;
  color: var(--primary);
}

.load-card {
  display: grid;
  gap: 8px;
  margin-top: 6px;
}

.load-card-top {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
}

.progress {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: #d8e7ed;
}

.progress i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--green), #10b4c4);
}

.load-card small {
  color: var(--muted);
}

.quick-card button {
  display: flex;
  width: 100%;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  border: 1px solid #18a9bc;
  border-radius: var(--radius);
  background: #f3feff;
  color: var(--primary-strong);
  padding: 0 16px;
  font-weight: 760;
}

.quick-card button:hover {
  background: var(--primary);
  color: white;
}

.schedule-panel {
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto;
  overflow: hidden;
}

.schedule-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.title-block {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
}

.title-block > div {
  min-width: 0;
}

.title-block h1 {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar-actions {
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 88px);
  overflow: hidden;
  padding: 2px;
}

.segmented button {
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 720;
}

.segmented button.is-active {
  background: var(--primary);
  color: white;
  box-shadow: 0 8px 18px rgba(8, 145, 178, 0.18);
}

.secondary-button,
.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 0 14px;
  font-weight: 720;
}

.primary-button {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
  box-shadow: 0 10px 24px rgba(8, 145, 178, 0.2);
}

.primary-button:hover {
  background: var(--primary-strong);
}

.week-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(80px, 1fr));
  gap: 8px;
  padding: 10px 18px 0;
}

.week-day {
  display: grid;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  padding: 8px;
  text-align: left;
}

.week-day span,
.week-day small {
  color: var(--muted);
  font-size: 11px;
}

.week-day strong {
  font-size: 18px;
}

.week-day.is-selected {
  border-color: var(--primary);
  background: #ecfeff;
}

.filter-row {
  display: grid;
  grid-template-columns: 160px 160px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 12px 18px 16px;
  border-bottom: 1px solid var(--line);
}

.filter-row select {
  width: 100%;
  padding: 0 12px;
  color: var(--muted);
  font-weight: 650;
}

.chips {
  flex-wrap: wrap;
  gap: 7px;
}

.chip {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--muted);
  padding: 0 11px;
  font-size: 13px;
  font-weight: 720;
}

.chip.is-active {
  border-color: #99e5ef;
  background: #effdff;
  color: var(--primary-strong);
}

.chip-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

.chip-green.is-active {
  border-color: #bbf7d0;
  background: var(--green-soft);
  color: var(--green);
}

.chip-blue.is-active {
  border-color: #bfdbfe;
  background: var(--blue-soft);
  color: var(--blue);
}

.chip-amber.is-active {
  border-color: #fed7aa;
  background: var(--amber-soft);
  color: var(--amber);
}

.chip-red.is-active {
  border-color: #fecaca;
  background: var(--red-soft);
  color: var(--red);
}

.chip-slate.is-active {
  border-color: #cbd5e1;
  background: var(--slate-soft);
  color: var(--slate);
}

.schedule-content {
  min-height: 0;
  overflow: auto;
  background:
    linear-gradient(#eef7fa 1px, transparent 1px) 0 0 / 100% var(--hour-height),
    white;
}

.schedule-board {
  position: relative;
  display: grid;
  grid-template-columns: 58px repeat(var(--doctor-count), minmax(200px, 1fr));
  grid-template-rows: var(--schedule-header-height) var(--timeline-height);
  min-width: calc(58px + var(--doctor-count) * 200px);
}

.schedule-head,
.doctor-head {
  position: sticky;
  top: 0;
  z-index: 3;
  height: var(--schedule-header-height);
  min-height: var(--schedule-header-height);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.98);
}

.time-head {
  grid-column: 1;
  grid-row: 1;
  left: 0;
  z-index: 4;
  display: grid;
  place-items: center;
  gap: 3px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.time-head svg {
  width: 18px;
  height: 18px;
}

.doctor-head {
  grid-row: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-content: center;
  padding: 11px 14px 10px;
  border-left: 1px solid var(--line);
}

.doctor-head strong,
.doctor-head span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.doctor-head strong {
  font-size: 14px;
}

.doctor-head span {
  color: var(--muted);
  font-size: 12px;
}

.doctor-head small {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.mini-icon,
.tiny-icon {
  width: 14px;
  height: 14px;
}

.load-line {
  grid-column: 1 / -1;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: #d9e6ec;
}

.load-line b {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--doctor-color);
}

.time-axis {
  grid-column: 1;
  grid-row: 2;
  position: sticky;
  left: 0;
  z-index: 2;
  height: var(--timeline-height);
  min-height: var(--timeline-height);
  border-right: 1px solid var(--line);
  background:
    linear-gradient(#edf4f7 1px, transparent 1px) 0 0 / 100% var(--hour-height),
    rgba(255, 255, 255, 0.96);
}

.time-row {
  position: absolute;
  right: 0;
  left: 0;
  display: flex;
  align-items: start;
  justify-content: center;
  color: #516a7a;
  padding-top: 7px;
  font-weight: 670;
  line-height: 1;
}

.doctor-column {
  grid-row: 2;
  display: grid;
  grid-template-rows: repeat(44, var(--time-slot-height));
  align-content: stretch;
  gap: 0;
  height: var(--timeline-height);
  min-height: var(--timeline-height);
  border-left: 1px solid var(--line);
  padding: 0 10px;
  background: linear-gradient(#eef7fa 1px, transparent 1px) 0 0 / 100% var(--hour-height);
}

.appointment {
  position: relative;
  display: grid;
  grid-column: 1;
  grid-row: var(--row-start) / span var(--row-span);
  gap: 3px;
  min-height: 0;
  align-content: start;
  margin: 5px 0;
  border: 1px solid var(--line);
  border-left: 3px solid currentColor;
  border-radius: 7px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.94), rgba(248, 250, 252, 0.9));
  color: var(--primary);
  padding: 7px 9px;
  box-shadow: 0 5px 14px rgba(15, 61, 75, 0.05);
  overflow: hidden;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background-color 160ms ease;
}

.appointment:hover,
.appointment.is-selected {
  border-color: currentColor;
  box-shadow: 0 12px 24px rgba(15, 61, 75, 0.1);
}

.appointment-green {
  color: var(--green);
}

.appointment-blue {
  color: var(--blue);
}

.appointment-amber {
  color: var(--amber);
}

.appointment-red {
  color: var(--red);
}

.appointment-slate {
  color: var(--slate);
}

.appointment-empty {
  color: #8aa0ad;
}

.appointment.is-available {
  min-height: 0;
  border-style: dashed;
  background: rgba(248, 250, 252, 0.76);
  color: #7a94a3;
  text-align: center;
}

.appointment-top {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px;
  align-items: baseline;
  min-width: 0;
}

.appointment time,
.appointment strong {
  color: var(--text);
  font-size: 13px;
  font-weight: 760;
  line-height: 1.18;
}

.appointment strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.appointment p {
  min-width: 0;
  overflow: hidden;
  color: #355366;
  font-size: 12px;
  line-height: 1.18;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.appointment footer {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
  overflow: hidden;
}

.appointment footer span:first-child {
  margin-right: auto;
  color: #536b7b;
  font-size: 11px;
}

.appointment footer b,
.status-pill {
  flex: 0 0 auto;
  border-radius: 5px;
  background: currentColor;
  color: white;
  padding: 2px 6px;
  font-size: 10px;
  line-height: 1.4;
}

.appointment-green footer b {
  background: var(--green-soft);
  color: var(--green);
}

.appointment-blue footer b {
  background: var(--blue-soft);
  color: var(--blue);
}

.appointment-amber footer b {
  background: var(--amber-soft);
  color: var(--amber);
}

.appointment-red footer b {
  background: var(--red-soft);
  color: var(--red);
}

.appointment-slate footer b {
  background: var(--slate-soft);
  color: var(--slate);
}

.pay-mark,
.alert-mark {
  display: inline-grid;
  flex: 0 0 auto;
  place-items: center;
  color: #315568;
}

.appointment.is-compact {
  gap: 2px;
  padding: 6px 8px;
}

.appointment.is-compact p {
  display: none;
}

.appointment.is-compact footer span:first-child {
  font-size: 10px;
}

.appointment.is-compact footer b {
  padding: 1px 5px;
}

.duration-mark {
  flex: 0 0 auto;
  border-radius: 5px;
  background: #eef7fa;
  color: #496474;
  padding: 1px 5px;
  font-size: 10px;
  font-weight: 760;
  line-height: 1.4;
}

.appointment.is-micro {
  display: flex;
  min-height: 0;
  align-items: center;
  gap: 5px;
  margin: 2px 0;
  padding: 2px 7px;
}

.appointment.is-micro .appointment-top {
  display: flex;
  min-width: 0;
  flex: 1;
  gap: 6px;
}

.appointment.is-micro time,
.appointment.is-micro strong {
  font-size: 12px;
  line-height: 1;
}

.appointment.is-micro p,
.appointment.is-micro footer {
  display: none;
}

.appointment.is-extended {
  align-content: start;
  padding-top: 10px;
}

.alert-mark {
  color: var(--red);
}

.current-time-line {
  position: absolute;
  right: 0;
  left: 0;
  z-index: 5;
  height: 1px;
  background: #ef4444;
  pointer-events: none;
}

.current-time-line span {
  position: sticky;
  left: 0;
  display: inline-grid;
  min-width: 50px;
  height: 28px;
  place-items: center;
  transform: translateY(-50%);
  border-radius: 999px;
  background: #ef4444;
  color: white;
  font-size: 12px;
  font-weight: 760;
}

.empty-column {
  display: grid;
  min-height: 160px;
  place-items: center;
  border: 1px dashed var(--line-strong);
  border-radius: 7px;
  color: var(--muted);
  padding: 18px;
  text-align: center;
}

.legend-row {
  flex-wrap: wrap;
  gap: 18px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 12px;
}

.legend-row span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 3px;
}

.legend-dot.green {
  background: var(--green);
}

.legend-dot.blue {
  background: var(--blue);
}

.legend-dot.amber {
  background: var(--amber);
}

.legend-dot.red {
  background: var(--red);
}

.legend-dot.slate {
  background: var(--slate);
}

.legend-line {
  width: 24px;
  height: 2px;
  background: #ef4444;
}

.detail-panel {
  position: fixed;
  top: 96px;
  right: 16px;
  z-index: 24;
  display: grid;
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100vh - 120px);
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  padding: 0;
  opacity: 0;
  pointer-events: none;
  transform: translateX(calc(100% + 28px));
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.detail-panel.is-open {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0);
}

.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.detail-head span {
  display: block;
  color: var(--primary-strong);
  font-size: 26px;
  font-weight: 780;
  line-height: 1;
}

.detail-head small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.detail-head button {
  display: grid;
  width: 38px;
  height: 38px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--muted);
}

.detail-head button:hover {
  border-color: #a6d7e4;
  color: var(--primary-strong);
}

.detail-body {
  min-height: 0;
  overflow: auto;
  padding: 16px;
}

.detail-panel h3 {
  margin-top: 12px;
  font-size: 20px;
}

.detail-panel p {
  margin-top: 4px;
  color: var(--muted);
}

.detail-panel dl {
  display: grid;
  gap: 10px;
  margin: 16px 0 0;
}

.detail-panel dl div {
  display: grid;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 10px;
}

.detail-panel dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 740;
  text-transform: uppercase;
}

.detail-panel dd {
  margin: 0;
  font-weight: 680;
}

.detail-patient-card {
  display: grid;
  gap: 4px;
  margin-top: 14px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--primary);
  border-radius: 7px;
  background: #f8feff;
  padding: 10px;
}

.detail-patient-card span,
.detail-patient-card small {
  color: var(--muted);
  font-size: 12px;
}

.detail-patient-card strong {
  color: var(--text);
}

.detail-actions {
  gap: 8px;
  border-top: 1px solid var(--line);
  padding: 12px 16px 16px;
}

.detail-actions button {
  min-height: 38px;
  flex: 1;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--text);
  font-weight: 720;
}

.status-green {
  background: var(--green-soft);
  color: var(--green);
}

.status-blue {
  background: var(--blue-soft);
  color: var(--blue);
}

.status-amber {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-red {
  background: var(--red-soft);
  color: var(--red);
}

.status-slate {
  background: var(--slate-soft);
  color: var(--slate);
}

.main-layout.is-patient-view {
  grid-template-columns: minmax(0, 1fr);
}

.main-layout.is-patient-view > .date-panel,
.main-layout.is-patient-view > .schedule-panel,
.main-layout.is-patient-view > .detail-panel {
  display: none;
}

.patient-card-view {
  grid-column: 1 / -1;
  width: 100%;
  min-width: 0;
}

.patient-card-view[hidden] {
  display: none;
}

.patient-page {
  display: grid;
  width: 100%;
  gap: 12px;
  min-width: 0;
}

.patient-sticky-region {
  position: sticky;
  top: 72px;
  z-index: 7;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  min-width: 0;
  gap: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(18px);
}

.patient-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  width: 100%;
  min-width: 0;
  gap: 14px;
  padding: 16px 18px;
}

.patient-breadcrumb,
.patient-meta-line,
.patient-contact-strip,
.patient-badges,
.patient-actions,
.history-filter-row,
.media-filter-row,
.plan-action-grid {
  display: flex;
  align-items: center;
}

.patient-breadcrumb {
  flex-wrap: wrap;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.patient-breadcrumb i {
  color: var(--muted-2);
  font-style: normal;
}

.patient-back-button,
.patient-actions button,
.patient-tabs button,
.history-filter-row button,
.media-filter-row button,
.plan-list-item,
.plan-action-grid button,
.patient-empty-inline button,
.inline-empty button,
.media-overlay-card header button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  color: var(--text);
  transition:
    border-color 180ms ease,
    background-color 180ms ease,
    box-shadow 180ms ease,
    color 180ms ease;
}

.patient-back-button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 34px;
  padding: 0 10px;
  color: var(--primary-strong);
  font-weight: 760;
}

.patient-back-button:hover,
.patient-actions button:hover,
.patient-tabs button:hover,
.history-filter-row button:hover,
.media-filter-row button:hover,
.plan-list-item:hover,
.plan-action-grid button:hover,
.patient-empty-inline button:hover,
.inline-empty button:hover,
.media-card:hover,
.media-overlay-card header button:hover {
  border-color: #9bddea;
  box-shadow: 0 8px 18px rgba(8, 145, 178, 0.09);
}

.patient-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  width: 100%;
  min-width: 0;
  gap: 18px;
  align-items: center;
}

.patient-identity {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 13px;
  align-items: center;
  min-width: 0;
}

.patient-avatar {
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(180deg, #bdf4f6, #dcfce7);
  color: var(--primary-strong);
  font-size: 18px;
  font-weight: 820;
}

.patient-kicker {
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 780;
}

.patient-identity h1 {
  margin-top: 2px;
  overflow-wrap: anywhere;
}

.patient-meta-line {
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.patient-meta-line span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.patient-meta-line span + span::before {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--muted-2);
  content: "";
}

.patient-actions {
  flex-wrap: wrap;
  justify-content: end;
  gap: 8px;
  min-width: 0;
}

.patient-actions button,
.plan-action-grid button {
  display: inline-flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  font-size: 13px;
  font-weight: 760;
}

.patient-header-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  width: 100%;
  min-width: 0;
  gap: 12px;
  align-items: start;
}

.patient-contact-strip {
  flex-wrap: wrap;
  gap: 8px;
}

.patient-contact-strip span {
  display: inline-flex;
  min-height: 34px;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8feff;
  color: #315568;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 720;
}

.patient-badges {
  flex-wrap: wrap;
  justify-content: end;
  gap: 7px;
}

.patient-badge {
  display: inline-flex;
  min-height: 32px;
  align-items: center;
  border-radius: 7px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 780;
}

.badge-green {
  background: var(--green-soft);
  color: var(--green);
}

.badge-red {
  background: var(--red-soft);
  color: var(--red);
}

.badge-amber {
  background: var(--amber-soft);
  color: var(--amber);
}

.badge-blue {
  background: var(--blue-soft);
  color: var(--blue);
}

.patient-tabs-wrap {
  min-width: 0;
  overflow: hidden;
  border-top: 1px solid var(--line);
}

.patient-tabs {
  display: flex;
  width: 100%;
  min-width: 0;
  overflow-x: auto;
  padding: 0 14px;
  scrollbar-width: thin;
}

.patient-tabs button {
  position: relative;
  min-width: max-content;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 16px;
  font-weight: 780;
  box-shadow: none;
}

.patient-tabs button::after {
  position: absolute;
  right: 12px;
  bottom: 0;
  left: 12px;
  height: 3px;
  border-radius: 999px 999px 0 0;
  background: transparent;
  content: "";
}

.patient-tabs button.is-active {
  color: var(--primary-strong);
}

.patient-tabs button.is-active::after {
  background: var(--primary);
}

.patient-tab-panel {
  min-width: 0;
}

.patient-overview-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stats-layout {
  display: grid;
  grid-template-areas:
    "kpis kpis kpis"
    "chart chart bars"
    "chart chart summary";
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  align-items: start;
}

.patient-panel,
.stats-kpi {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow-soft);
}

.patient-panel {
  padding: 16px;
}

.patient-alert-panel {
  border-color: #fecaca;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(254, 242, 242, 0.86));
}

.patient-section-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.patient-section-head span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.patient-section-icon {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 7px;
  background: #eefcff;
  color: var(--primary);
  padding: 7px;
}

.patient-definition-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.patient-definition-grid.compact {
  grid-template-columns: 1fr;
}

.patient-definition-grid div {
  display: grid;
  gap: 3px;
  min-width: 0;
  border-bottom: 1px solid var(--line);
  padding-bottom: 9px;
}

.patient-definition-grid dt {
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
}

.patient-definition-grid dd {
  min-width: 0;
  margin: 0;
  color: var(--text);
  font-weight: 700;
  overflow-wrap: anywhere;
}

.alert-list,
.consent-list,
.plan-list,
.plan-stage-list,
.procedure-list,
.category-bars {
  display: grid;
  gap: 9px;
}

.alert-item {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 9px;
  align-items: start;
  min-height: 42px;
  border-radius: 7px;
  background: white;
  padding: 10px;
}

.alert-item b {
  border-radius: 5px;
  padding: 4px 6px;
  font-size: 11px;
  text-align: center;
}

.alert-item span {
  font-weight: 730;
  overflow-wrap: anywhere;
}

.alert-high b {
  background: var(--red-soft);
  color: var(--red);
}

.alert-medium b {
  background: var(--amber-soft);
  color: var(--amber);
}

.alert-low b {
  background: var(--blue-soft);
  color: var(--blue);
}

.consent-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 42px;
  border-bottom: 1px solid var(--line);
}

.consent-row span {
  font-weight: 700;
}

.consent-row b {
  flex: 0 0 auto;
  border-radius: 5px;
  padding: 4px 7px;
  font-size: 11px;
}

.consent-row .is-signed {
  background: var(--green-soft);
  color: var(--green);
}

.consent-row .is-missing {
  background: var(--amber-soft);
  color: var(--amber);
}

.next-event-card,
.clinical-note,
.clinical-goal,
.patient-empty-inline,
.inline-empty {
  border-radius: 7px;
  background: #f8feff;
  padding: 12px;
}

.next-event-card {
  display: grid;
  gap: 6px;
}

.next-event-card span,
.clinical-note,
.clinical-goal {
  color: var(--muted);
}

.finance-tiles,
.stats-kpi-grid {
  display: grid;
  gap: 10px;
}

.finance-tiles {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-bottom: 12px;
}

.finance-tile {
  display: grid;
  gap: 4px;
  border-radius: 7px;
  background: #eefcff;
  padding: 10px;
}

.finance-tile span,
.stats-kpi small {
  color: var(--muted);
  font-size: 12px;
}

.finance-tile strong {
  color: var(--primary-strong);
  font-size: 17px;
}

.history-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr);
  gap: 12px;
}

.history-media-panel {
  grid-column: 1 / -1;
}

.history-filter-row,
.media-filter-row {
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 14px;
}

.history-filter-row button,
.media-filter-row button {
  min-height: 34px;
  padding: 0 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 740;
}

.history-filter-row button.is-active,
.media-filter-row button.is-active {
  border-color: #99e5ef;
  background: #effdff;
  color: var(--primary-strong);
}

.timeline-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.timeline-event {
  display: grid;
  grid-template-columns: 112px minmax(0, 1fr);
  gap: 12px;
  min-width: 0;
}

.timeline-event > time {
  color: var(--primary-strong);
  font-size: 13px;
  font-weight: 790;
}

.timeline-event article {
  min-width: 0;
  border-left: 3px solid var(--primary);
  border-radius: 7px;
  background: #f8feff;
  padding: 12px;
}

.timeline-event header {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.timeline-event h3 {
  margin-top: 2px;
  font-size: 16px;
}

.timeline-event header b {
  flex: 0 0 auto;
  align-self: start;
  border-radius: 5px;
  background: var(--primary-soft);
  color: var(--primary-strong);
  padding: 4px 7px;
  font-size: 11px;
}

.timeline-event p {
  margin-top: 8px;
  color: var(--text);
  font-weight: 680;
}

.timeline-event small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.timeline-media {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 9px;
  color: var(--primary-strong);
  font-size: 12px;
  font-weight: 760;
}

.timeline-media.muted {
  color: var(--muted);
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 10px;
}

.media-card {
  display: grid;
  min-width: 0;
  min-height: 232px;
  align-content: start;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  padding: 8px;
  text-align: left;
  transition:
    border-color 180ms ease,
    box-shadow 180ms ease;
}

.media-card img {
  width: 100%;
  aspect-ratio: 16 / 10;
  border-radius: 6px;
  object-fit: cover;
}

.media-card span {
  color: var(--primary-strong);
  font-size: 11px;
  font-weight: 780;
  text-transform: uppercase;
}

.media-card strong {
  min-width: 0;
  color: var(--text);
  overflow-wrap: anywhere;
}

.media-card small {
  color: var(--muted);
}

.plans-layout {
  display: grid;
  grid-template-columns: minmax(220px, 0.65fr) minmax(0, 1.35fr) minmax(280px, 0.7fr);
  gap: 12px;
  align-items: start;
}

.plan-list-item {
  display: grid;
  gap: 6px;
  min-height: 96px;
  align-content: center;
  padding: 12px;
  text-align: left;
}

.plan-list-item.is-active {
  border-color: var(--primary);
  background: #effdff;
}

.plan-list-item span {
  color: var(--muted);
  font-size: 12px;
}

.plan-list-item strong {
  overflow-wrap: anywhere;
}

.plan-stage {
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #f8feff;
  padding: 12px;
}

.plan-stage header,
.procedure-row,
.plan-progress-block div:first-child,
.category-bar div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.plan-stage header {
  margin-bottom: 10px;
}

.plan-stage header b {
  border-radius: 5px;
  background: var(--blue-soft);
  color: var(--blue);
  padding: 4px 7px;
  font-size: 11px;
}

.procedure-row {
  min-height: 42px;
  border-top: 1px solid var(--line);
  padding-top: 8px;
}

.procedure-row span {
  min-width: 0;
  flex: 1;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.procedure-row b,
.procedure-row small,
.procedure-row strong {
  flex: 0 0 auto;
}

.procedure-row b,
.procedure-row small {
  color: var(--muted);
}

.plan-progress-block {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.plan-progress-block span {
  color: var(--muted);
  font-weight: 700;
}

.plan-progress-block strong {
  color: var(--primary-strong);
  font-size: 20px;
}

.plan-action-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 14px;
}

.stats-kpi-grid {
  grid-area: kpis;
  grid-column: 1 / -1;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stats-kpi {
  display: grid;
  gap: 6px;
  padding: 14px;
}

.stats-kpi span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 760;
}

.stats-kpi strong {
  color: var(--text);
  font-size: 24px;
  line-height: 1.1;
}

.stats-chart-panel {
  grid-area: chart;
}

.stats-bars-panel {
  grid-area: bars;
}

.stats-summary-panel {
  grid-area: summary;
}

.line-chart-wrap {
  display: grid;
  gap: 10px;
}

.line-chart-wrap svg {
  width: 100%;
  height: auto;
  overflow: visible;
}

.line-chart-wrap line {
  stroke: #cbdce4;
  stroke-width: 1.2;
}

.line-chart-wrap polyline {
  fill: none;
  stroke: var(--primary);
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 4;
}

.line-chart-wrap circle {
  fill: white;
  stroke: var(--primary);
  stroke-width: 3;
}

.line-chart-wrap text {
  fill: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.chart-legend i {
  width: 24px;
  height: 3px;
  border-radius: 999px;
  background: var(--primary);
}

.category-bar {
  display: grid;
  gap: 6px;
}

.category-bar div span {
  font-weight: 730;
}

.category-bar div strong {
  color: var(--primary-strong);
}

.category-bar i {
  display: block;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--green), var(--primary));
}

.patient-empty-state,
.patient-empty-inline,
.inline-empty {
  display: grid;
  justify-items: start;
  gap: 10px;
}

.patient-empty-state {
  min-height: 460px;
  align-content: center;
  justify-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  padding: 24px;
  text-align: center;
}

.patient-empty-state p,
.patient-empty-inline span,
.inline-empty span {
  color: var(--muted);
}

.patient-empty-svg {
  width: 44px;
  height: 44px;
  color: var(--amber);
}

.patient-empty-inline button,
.inline-empty button {
  min-height: 36px;
  padding: 0 10px;
  color: var(--primary-strong);
  font-weight: 740;
}

.media-overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(7, 53, 71, 0.38);
  padding: 18px;
  backdrop-filter: blur(5px);
}

.media-overlay-card {
  display: grid;
  width: min(820px, 100%);
  max-height: min(760px, calc(100vh - 36px));
  overflow: auto;
  border-radius: 10px;
  background: white;
  box-shadow: var(--shadow);
}

.media-overlay-card header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  padding: 16px;
}

.media-overlay-card header span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.media-overlay-card header button {
  display: grid;
  width: 44px;
  place-items: center;
  padding: 0;
}

.media-overlay-card > img {
  width: 100%;
  max-height: 470px;
  object-fit: cover;
}

.media-overlay-card .patient-definition-grid {
  padding: 16px;
}

.appointment-dialog {
  width: min(460px, calc(100vw - 28px));
  border: 0;
  border-radius: 10px;
  padding: 0;
  color: var(--text);
  box-shadow: var(--shadow);
}

.appointment-dialog::backdrop {
  background: rgba(7, 53, 71, 0.32);
  backdrop-filter: blur(4px);
}

.dialog-card {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.dialog-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.dialog-head span,
.dialog-card label span {
  color: var(--muted);
  font-size: 12px;
}

.dialog-head button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
}

.dialog-head svg {
  width: 18px;
  height: 18px;
}

.dialog-card label {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

.dialog-card input,
.dialog-card select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 11px;
  color: var(--text);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.dialog-actions {
  display: flex;
  justify-content: end;
  gap: 8px;
  margin-top: 4px;
}

.dialog-actions button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: white;
  padding: 0 14px;
  font-weight: 730;
}

.dialog-actions button[type="submit"] {
  border-color: var(--primary);
  background: var(--primary);
  color: white;
}

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  border-radius: var(--radius);
  background: var(--nav);
  color: white;
  padding: 12px 16px;
  box-shadow: var(--shadow);
  font-weight: 700;
}

@media (max-width: 1700px) {
  .main-layout {
    grid-template-columns: 310px minmax(0, 1fr);
  }
}

@media (max-width: 1120px) {
  .topbar {
    grid-template-columns: 180px minmax(180px, 1fr) minmax(220px, 1.4fr);
  }

  .top-actions {
    grid-column: 1 / -1;
    justify-content: start;
  }

  .main-layout {
    grid-template-columns: 1fr;
  }

  .date-panel {
    grid-template-columns: minmax(280px, 0.9fr) minmax(280px, 1fr) minmax(220px, 0.7fr);
  }

  .patient-sticky-region {
    position: static;
  }

  .patient-overview-grid,
  .stats-layout {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .stats-layout {
    grid-template-areas:
      "kpis kpis"
      "chart chart"
      "bars summary";
  }

  .plans-layout,
  .history-layout {
    grid-template-columns: 1fr;
  }

  .history-media-panel {
    grid-column: auto;
  }

  .media-grid,
  .stats-kpi-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    width: 100%;
    max-width: 100vw;
    min-width: 0;
    height: auto;
    flex-direction: row;
    align-items: stretch;
    overflow-x: auto;
    contain: paint;
    padding-right: 8px;
  }

  .brand-mark {
    width: 68px;
    height: auto;
    min-height: 62px;
    flex: 0 0 auto;
    border-right: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: 0;
  }

  .brand-mark svg {
    width: 34px;
    height: 34px;
  }

  .nav-list {
    width: auto;
    max-width: calc(100vw - 68px);
    min-width: 0;
    flex: 1 1 auto;
    flex-direction: row;
    overflow-x: auto;
    contain: paint;
    padding: 8px;
  }

  .nav-item {
    width: 76px;
    min-height: 54px;
    flex: 0 0 auto;
  }

  .collapse-button {
    display: none;
  }

  .topbar {
    position: static;
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .main-layout {
    padding: 10px;
  }

  .date-panel {
    grid-template-columns: 1fr;
  }

  .schedule-toolbar,
  .filter-row {
    grid-template-columns: 1fr;
  }

  .schedule-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-actions {
    justify-content: stretch;
  }

  .segmented,
  .secondary-button,
  .primary-button {
    flex: 1;
  }

  .filter-row {
    display: grid;
  }

  .week-strip {
    grid-template-columns: repeat(7, minmax(72px, 1fr));
    overflow-x: auto;
  }

  .detail-panel {
    top: auto;
    right: 10px;
    bottom: 10px;
    left: 10px;
    width: auto;
    max-height: 70vh;
    transform: translateY(calc(100% + 24px));
  }

  .detail-panel.is-open {
    transform: translateY(0);
  }

  .patient-hero,
  .patient-header-grid {
    grid-template-columns: 1fr;
  }

  .patient-hero,
  .patient-header-grid,
  .patient-contact-strip,
  .patient-badges,
  .patient-actions {
    max-width: 100%;
  }

  .patient-actions,
  .patient-badges {
    justify-content: start;
  }

  .patient-actions {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .patient-actions button {
    width: 100%;
    white-space: normal;
  }

  .patient-actions button:last-child {
    grid-column: 1 / -1;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 14px;
  }

  .panel-title,
  .month-switch,
  .toolbar-actions,
  .legend-row {
    align-items: stretch;
  }

  .panel-title,
  .toolbar-actions {
    flex-direction: column;
  }

  .date-nav {
    width: 100%;
  }

  .date-nav button {
    flex: 1;
  }

  .title-block h1 {
    white-space: normal;
  }

  .segmented {
    grid-template-columns: 1fr 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .profile-button strong,
  kbd {
    display: none;
  }

  .patient-header {
    padding: 14px;
  }

  .patient-identity {
    grid-template-columns: 48px minmax(0, 1fr);
  }

  .patient-avatar {
    width: 48px;
    height: 48px;
  }

  .patient-tabs {
    padding: 0 8px;
  }

  .patient-tabs button {
    padding: 0 12px;
  }

  .patient-overview-grid,
  .stats-layout,
  .stats-kpi-grid,
  .media-grid,
  .finance-tiles,
  .patient-definition-grid,
  .plan-action-grid {
    grid-template-columns: 1fr;
  }

  .stats-layout {
    grid-template-areas:
      "kpis"
      "chart"
      "bars"
      "summary";
  }

  .timeline-event {
    grid-template-columns: 1fr;
  }

  .timeline-event > time {
    padding-left: 12px;
  }

  .timeline-event header,
  .procedure-row,
  .plan-stage header {
    align-items: start;
    flex-direction: column;
  }

  .media-card {
    min-height: 216px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
