:root {
  color-scheme: light;
  --ink: #17201c;
  --ink-strong: #091311;
  --muted: #5d6b67;
  --subtle: #7a8783;
  --canvas: #f6f8f7;
  --surface: #ffffff;
  --surface-soft: #eef4f2;
  --surface-raised: #f9fbfa;
  --surface-active: #e4f6f2;
  --line: #d9e2de;
  --line-strong: #a9bab4;
  --brand: #0f766e;
  --brand-dark: #0a4f49;
  --brand-hover: #0b615a;
  --brand-soft: #dff4f0;
  --blue: #1f5f99;
  --green: #2f7d55;
  --orange: #c76d2a;
  --purple: #6757a8;
  --danger: #b42318;
  --danger-soft: #fff1ef;
  --warning-soft: #fff4e5;
  --success-soft: #e8f5ee;
  --info-soft: #e9f2fb;
  --focus: #0f766e;
  --radius: 8px;
  --radius-sm: 4px;
  --shell-width: 1600px;
  --control: 42px;
  --background: var(--canvas);
  --foreground: var(--ink);
  --card: var(--surface);
  --card-foreground: var(--ink);
  --primary: var(--brand);
  --primary-foreground: #ffffff;
  --secondary: var(--surface-soft);
  --secondary-foreground: var(--ink);
  --accent: var(--brand-soft);
  --accent-foreground: var(--brand-dark);
  --destructive: var(--danger);
  --destructive-foreground: #ffffff;
  --border: var(--line);
  --input: var(--line);
  --ring: var(--brand);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--canvas);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--canvas);
  font-family: "IBM Plex Sans", Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: 0.01em;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body:not(.is-logged-in) {
  overflow: hidden;
}

body:not(.is-logged-in) .app-shell {
  display: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
.button-link {
  display: inline-flex;
  min-height: var(--control);
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  color: var(--ink);
  background: var(--surface);
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color 150ms ease,
    border-color 150ms ease,
    color 150ms ease,
    transform 150ms ease;
}

button:hover,
.button-link:hover {
  border-color: var(--line-strong);
  background: var(--surface-raised);
}

button:active,
.button-link:active {
  transform: translateY(1px);
}

button:focus-visible,
.button-link:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

button svg,
.button-link svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

input,
select,
textarea {
  color: var(--ink);
}

[hidden] {
  display: none !important;
}

::selection {
  color: #ffffff;
  background: var(--brand);
}

.primary-action {
  border-color: var(--brand);
  color: #ffffff;
  background: var(--brand);
  font-weight: 700;
}

.primary-action:hover {
  border-color: var(--brand-hover);
  color: #ffffff;
  background: var(--brand-hover);
}

.danger-action {
  border-color: #f2b8b0;
  color: var(--danger);
  background: var(--danger-soft);
}

.danger-action:hover {
  border-color: var(--danger);
  color: #ffffff;
  background: var(--danger);
}

.secondary-action {
  border-color: #b9d9d4;
  color: var(--brand-dark);
  background: #effaf8;
  font-weight: 700;
}

.secondary-action:hover {
  border-color: var(--brand);
  color: var(--brand-dark);
  background: var(--brand-soft);
}

.text-button {
  min-height: auto;
  border: 0;
  border-radius: 0;
  padding: 0;
  color: var(--brand-dark);
  background: transparent;
  font-size: 13px;
  font-weight: 800;
}

.text-button:hover {
  color: var(--brand-hover);
  background: transparent;
  text-decoration: underline;
}

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

h1,
h2,
h3,
strong {
  color: var(--ink-strong);
}

h1 {
  margin-bottom: 0;
  font-size: 32px;
  font-weight: 500;
  line-height: 1.18;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
  font-weight: 650;
  line-height: 1.3;
}

h3 {
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 650;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brand-dark);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

small,
.brand span,
.patient-card span,
.timeline span,
.material-grid span,
.empty-state,
.form-note {
  color: var(--muted);
}

.empty-state,
.form-note {
  margin: 0;
  line-height: 1.55;
}

/* Login */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  overflow-y: auto;
  padding: 24px;
  background:
    linear-gradient(90deg, rgba(15, 118, 110, 0.08) 0 1px, transparent 1px 100%) 0 0 / 48px 48px,
    linear-gradient(0deg, rgba(15, 118, 110, 0.06) 0 1px, transparent 1px 100%) 0 0 / 48px 48px,
    #f3f7f6;
}

.login-screen.hidden {
  display: none;
}

.login-card {
  display: grid;
  gap: 22px;
  width: min(468px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 22px 70px rgba(24, 54, 49, 0.14);
}

.login-brand {
  display: grid;
  justify-items: center;
  gap: 14px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.login-logo {
  display: block;
  width: min(292px, 100%);
  height: auto;
}

.login-copy {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.6;
}

.auth-panel {
  display: grid;
  gap: 20px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface);
}

.auth-tabs button {
  min-height: 44px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
}

.auth-tabs button + button {
  border-left: 1px solid var(--line);
}

.auth-tabs button.active {
  color: #ffffff;
  background: var(--brand-dark);
}

.login-form,
.stack-form {
  display: grid;
  gap: 12px;
}

.login-form label,
.stack-form label,
.compact-form label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.login-form input,
.stack-form input,
.stack-form select,
.stack-form textarea,
.compact-form input,
.compact-form select,
.compact-form textarea {
  width: 100%;
  min-height: var(--control);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--ink);
  background: var(--surface-raised);
}

.login-form input:focus,
.stack-form input:focus,
.stack-form select:focus,
.stack-form textarea:focus,
.compact-form input:focus,
.compact-form select:focus,
.compact-form textarea:focus {
  border-color: var(--brand);
  background: #ffffff;
}

textarea {
  min-height: 116px;
  resize: vertical;
}

.auth-divider {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 10px;
  align-items: center;
  color: var(--subtle);
  font-size: 13px;
}

.auth-divider::before,
.auth-divider::after {
  content: "";
  height: 1px;
  background: var(--line);
}

.google-button {
  width: 100%;
  font-weight: 750;
}

.google-button span {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border-radius: 50%;
  color: #ffffff;
  background: #1f5f99;
  font-weight: 800;
}

.password-label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

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

.sidebar {
  position: sticky;
  top: 0;
  display: flex;
  height: 100vh;
  flex-direction: column;
  gap: 24px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--surface);
  padding: 20px 16px;
}

.brand {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  width: 100%;
  gap: 12px;
  align-items: center;
  padding: 4px;
}

.brand-logo,
.portrait {
  display: grid;
  width: 52px;
  height: 52px;
  place-items: center;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.brand-logo {
  display: block;
  object-fit: contain;
  padding: 4px;
}

.brand strong,
.brand span {
  display: block;
  overflow-wrap: anywhere;
}

.brand > div {
  min-width: 0;
}

.brand strong {
  font-size: 18px;
  line-height: 1.15;
}

.brand span {
  margin-top: 3px;
  font-size: 12px;
  line-height: 1.35;
}

.nav {
  display: grid;
  gap: 4px;
}

.nav-item {
  justify-content: flex-start;
  width: 100%;
  min-height: 44px;
  border-color: transparent;
  border-radius: var(--radius-sm);
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  font-weight: 650;
}

.nav-item:hover {
  border-color: transparent;
  color: var(--ink);
  background: var(--surface-soft);
}

.nav-item.active {
  color: var(--brand-dark);
  background: var(--brand-soft);
}

.nav-item.active .icon {
  color: #ffffff;
  background: var(--brand);
}

.nav-item[aria-current="page"] {
  font-weight: 800;
}

.icon {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  flex: 0 0 auto;
  border-radius: var(--radius-sm);
  color: var(--brand-dark);
  background: #f0f6f4;
}

.icon svg {
  width: 17px;
  height: 17px;
  stroke-width: 2;
}

.owner-panel {
  margin-top: auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-raised);
}

.owner-panel span {
  color: var(--orange);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.owner-panel p {
  margin: 10px 0 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.owner-panel button {
  width: 100%;
}

.workspace {
  min-width: 0;
  width: min(100%, var(--shell-width));
  padding: 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 22px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-chip {
  min-width: 210px;
  justify-content: flex-start;
  padding: 4px 10px 4px 6px;
  background: var(--card);
}

.user-chip:hover {
  background: var(--accent);
}

.user-chip-text {
  display: grid;
  min-width: 0;
  text-align: left;
}

.user-chip-text strong,
.user-chip-text span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-chip-text strong {
  font-size: 13px;
  line-height: 1.2;
}

.user-chip-text span {
  color: var(--muted);
  font-size: 12px;
}

.avatar {
  position: relative;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--accent-foreground);
  background: var(--accent);
  font-weight: 850;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.avatar-sm {
  width: 34px;
  height: 34px;
  font-size: 12px;
}

.avatar-lg {
  width: 96px;
  height: 96px;
  font-size: 28px;
}

.avatar-xl {
  width: 124px;
  height: 124px;
  font-size: 34px;
}

.search {
  display: flex;
  width: 320px;
  height: var(--control);
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  color: var(--subtle);
  background: var(--surface);
}

.search svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
}

.search:focus-within {
  border-color: var(--brand);
  box-shadow: inset 0 -2px 0 var(--brand);
}

.view {
  display: none;
}

.view.active {
  display: block;
}

/* Shared surfaces */
.summary-grid,
.material-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric,
.panel,
.profile-hero,
.material-grid article {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.metric {
  position: relative;
  min-height: 148px;
  overflow: hidden;
  padding: 18px;
}

.metric::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 4px;
  background: var(--brand);
}

.metric:nth-child(2)::before {
  background: var(--blue);
}

.metric:nth-child(3)::before {
  background: var(--green);
}

.metric:nth-child(4)::before {
  background: var(--purple);
}

.metric span,
.metric small {
  display: block;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.metric strong {
  display: block;
  margin: 14px 0 8px;
  font-size: 36px;
  font-weight: 500;
  line-height: 1;
}

.metric small {
  max-width: 210px;
  line-height: 1.45;
}

.dashboard-layout,
.section-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(340px, 0.65fr);
  gap: 16px;
  margin-top: 16px;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(240px, 0.78fr) minmax(360px, 1.25fr) minmax(320px, 0.88fr);
  gap: 16px;
  margin-top: 16px;
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 18px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-heading button {
  flex: 0 0 auto;
}

.patient-list,
.diary-feed,
.timeline,
.insight-list,
.status-list {
  display: grid;
  gap: 10px;
}

.patient-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  width: 100%;
  min-height: 76px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px;
  background: var(--surface-raised);
  text-align: left;
}

.patient-card:hover {
  border-color: var(--line-strong);
  background: #ffffff;
}

.patient-card.active {
  border-color: var(--brand);
  background: var(--surface-active);
  box-shadow: inset 3px 0 0 var(--brand);
}

.patient-card strong,
.patient-card span {
  display: block;
}

.patient-card span span {
  margin-top: 4px;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.4;
}

.tag,
.status,
.schedule-kind {
  display: inline-flex;
  min-height: 26px;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

.tag {
  align-self: start;
  color: var(--brand-dark);
  background: var(--brand-soft);
}

.tag.attention {
  color: #8a3f12;
  background: var(--warning-soft);
}

.tag.stable {
  color: #265f45;
  background: var(--success-soft);
}

.timeline div,
.diary-entry,
.schedule-item,
.insight-list p {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.timeline div:first-child,
.diary-entry:first-child,
.schedule-item:first-child,
.insight-list p:first-child {
  padding-top: 0;
}

.timeline div:last-child,
.diary-entry:last-child,
.schedule-item:last-child,
.insight-list p:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.timeline time {
  display: block;
  color: var(--blue);
  font-size: 13px;
  font-weight: 850;
}

.timeline strong,
.timeline span,
.schedule-item strong,
.schedule-item span,
.diary-entry strong,
.diary-entry span,
.material-grid strong,
.material-grid span {
  display: block;
}

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

.schedule-toolbar h2 {
  font-size: 22px;
  font-weight: 500;
}

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

.schedule-list {
  display: grid;
  gap: 0;
}

.schedule-item {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) minmax(190px, auto);
  gap: 14px;
  align-items: center;
}

.schedule-time {
  color: var(--brand-dark);
  font-size: 18px;
  font-weight: 850;
  font-variant-numeric: tabular-nums;
}

.schedule-item span {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.schedule-kind {
  color: #174a79;
  background: var(--info-soft);
}

.schedule-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.schedule-actions button {
  min-height: 34px;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 6px;
}

.entry-heading {
  display: grid;
  gap: 2px;
}

.diary-entry p {
  margin: 9px 0 0;
  color: var(--muted);
}

.diary-entry p strong {
  display: inline;
  margin-right: 4px;
}

.patient-record {
  min-height: 520px;
}

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

.record-header p {
  margin: 8px 0 0;
  color: var(--muted);
}

.record-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.record-box {
  min-height: 128px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface-raised);
}

.record-box p {
  margin: 8px 0 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.food-columns {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.food-columns > div {
  min-height: 170px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  background: #ffffff;
}

.food-columns ul {
  margin: 8px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

.food-columns li + li {
  margin-top: 5px;
}

.muted-item {
  color: var(--subtle);
}

.compact-form {
  display: grid;
  align-content: start;
  gap: 12px;
}

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

.goal-board article {
  display: flex;
  min-height: 190px;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--surface-raised);
}

.goal-board p {
  color: var(--muted);
  overflow-wrap: anywhere;
}

.goal-board small {
  display: block;
  margin: auto 0 14px;
  color: var(--muted);
}

.status {
  width: fit-content;
  margin-bottom: 14px;
}

.planned {
  color: #785314;
  background: #fff2cc;
}

.in-progress {
  color: #174a79;
  background: var(--info-soft);
}

.done {
  color: #245c40;
  background: var(--success-soft);
}

.chart {
  display: grid;
  height: 320px;
  grid-template-columns: repeat(6, minmax(28px, 1fr));
  align-items: end;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 22px;
  background:
    repeating-linear-gradient(to top, transparent 0 62px, rgba(217, 226, 222, 0.75) 63px),
    #ffffff;
}

.chart span {
  display: block;
  min-height: 8px;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  background: linear-gradient(180deg, #35a69d, var(--brand-dark));
}

.chart-labels {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 12px;
  padding: 8px 22px 0;
  color: var(--muted);
  font-size: 13px;
  text-align: center;
}

.profile-hero {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr);
  gap: 24px;
  align-items: center;
  padding: 24px;
}

.portrait {
  width: 120px;
  height: 120px;
  overflow: hidden;
}

.logo-portrait img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  padding: 8px;
}

.profile-hero h2 {
  margin-bottom: 10px;
  font-size: 30px;
  font-weight: 500;
}

.profile-hero p {
  max-width: 760px;
  color: var(--muted);
  line-height: 1.65;
}

.contact-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.material-panel {
  margin-top: 16px;
}

.material-grid article {
  min-height: 116px;
  padding: 16px;
  background: var(--surface-raised);
}

.material-grid span {
  margin-top: 6px;
  line-height: 1.45;
}

.user-profile-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.38fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.profile-summary-card {
  display: grid;
  gap: 18px;
  justify-items: start;
}

.profile-summary-card h2 {
  font-size: 24px;
  font-weight: 550;
}

.profile-summary-card p {
  margin: 6px 0 0;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.profile-summary-list {
  display: grid;
  width: 100%;
  gap: 5px;
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.profile-summary-list span,
.form-section-heading p {
  color: var(--muted);
}

.photo-upload {
  display: grid;
  grid-template-columns: 124px minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  background: var(--surface-raised);
}

.photo-upload input[type="file"] {
  color: transparent;
  padding: 8px;
}

.photo-upload input[type="file"]::file-selector-button {
  min-height: 34px;
  margin-right: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  color: var(--foreground);
  background: var(--card);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.photo-upload input[type="file"]::file-selector-button:hover {
  background: var(--accent);
}

.photo-upload .form-note {
  margin: 8px 0 12px;
}

.profile-form-grid,
.address-grid {
  display: grid;
  gap: 12px;
}

.profile-form-grid {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.address-grid {
  grid-template-columns: 150px minmax(260px, 1.4fr) 120px minmax(180px, 0.8fr);
}

.address-grid label:nth-child(5) {
  grid-column: span 2;
}

.form-section-heading {
  display: grid;
  gap: 4px;
  border-top: 1px solid var(--border);
  margin-top: 4px;
  padding-top: 16px;
}

.form-section-heading h3 {
  margin-bottom: 0;
}

.status-item {
  display: flex;
  min-height: 58px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  background: var(--surface-raised);
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 30;
  max-width: 380px;
  border: 1px solid #b9d9d4;
  border-radius: var(--radius);
  padding: 12px 14px;
  color: var(--brand-dark);
  background: #effaf8;
  box-shadow: 0 16px 40px rgba(22, 45, 42, 0.12);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1240px) {
  .summary-grid,
  .material-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split-layout {
    grid-template-columns: minmax(260px, 0.85fr) minmax(0, 1.15fr);
  }

  .split-layout .compact-form {
    grid-column: 1 / -1;
  }
}

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

  .sidebar {
    position: sticky;
    z-index: 5;
    height: auto;
    gap: 12px;
    max-width: 100vw;
    overflow: hidden;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px;
  }

  .brand {
    max-width: 100%;
  }

  .nav {
    display: flex;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    gap: 6px;
    overflow-x: auto;
    padding-bottom: 2px;
    scrollbar-width: thin;
  }

  .nav-item {
    width: auto;
    min-width: 122px;
    flex: 0 0 auto;
  }

  .owner-panel {
    display: none;
  }

  .workspace {
    width: 100%;
  }

  .dashboard-layout,
  .section-grid,
  .split-layout,
  .user-profile-layout {
    grid-template-columns: 1fr;
  }

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

  .address-grid label:nth-child(5) {
    grid-column: auto;
  }
}

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

  h1 {
    font-size: 27px;
  }

  h2 {
    font-size: 17px;
  }

  .login-screen {
    place-items: start center;
    padding: 12px;
    background: #f3f7f6;
  }

  .login-card {
    width: 100%;
    gap: 16px;
    padding: 18px;
    box-shadow: none;
  }

  .login-logo {
    width: min(224px, 76vw);
  }

  .sidebar {
    top: 0;
    padding: 10px;
  }

  .brand {
    grid-template-columns: 44px minmax(0, 1fr);
  }

  .brand-logo {
    width: 44px;
    height: 44px;
  }

  .brand strong {
    font-size: 16px;
  }

  .nav-item {
    min-width: 104px;
    min-height: 42px;
    padding: 0 9px;
    font-size: 13px;
  }

  .icon {
    width: 26px;
    height: 26px;
  }

  .nav {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    overflow: visible;
    gap: 6px;
  }

  .nav-item {
    width: 100%;
    min-width: 0;
    min-height: 62px;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    padding: 0 5px;
    font-size: 12px;
  }

  .nav-item .icon {
    width: 24px;
    height: 24px;
  }

  .icon svg {
    width: 15px;
    height: 15px;
  }

  .workspace {
    padding: 16px;
  }

  .topbar,
  .top-actions,
  .schedule-toolbar,
  .record-header {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
  }

  .search {
    width: 100%;
  }

  .top-actions > button,
  .calendar-actions > button {
    width: 100%;
  }

  .user-chip {
    min-width: 0;
  }

  .user-chip-text {
    justify-items: center;
    text-align: center;
  }

  .calendar-actions {
    width: 100%;
  }

  .summary-grid,
  .record-grid,
  .food-columns,
  .goal-board,
  .material-grid,
  .profile-hero,
  .profile-form-grid,
  .address-grid,
  .photo-upload {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: 126px;
  }

  .panel,
  .schedule-toolbar,
  .profile-hero {
    padding: 16px;
  }

  .panel-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .panel-heading button {
    width: 100%;
  }

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

  .tag {
    width: fit-content;
  }

  .patient-record {
    min-height: 0;
  }

  .schedule-item {
    grid-template-columns: 1fr;
    gap: 7px;
  }

  .schedule-actions {
    align-items: stretch;
    justify-content: flex-start;
    flex-direction: column;
  }

  .schedule-kind {
    width: fit-content;
  }

  .inline-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .inline-actions button,
  .inline-actions .button-link {
    width: 100%;
  }

  .profile-hero {
    justify-items: start;
  }

  .contact-row {
    align-items: stretch;
    flex-direction: column;
  }

  .contact-row > * {
    width: 100%;
  }

  .chart {
    height: 240px;
    gap: 8px;
    padding: 16px;
  }

  .chart-labels {
    gap: 8px;
    padding-inline: 16px;
  }

  .toast {
    right: 16px;
    bottom: 16px;
    left: 16px;
    max-width: none;
  }
}

@media (max-width: 420px) {
  .workspace {
    padding: 12px;
  }

  .auth-tabs {
    grid-template-columns: 1fr;
  }

  .auth-tabs button + button {
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .summary-grid {
    gap: 10px;
  }

  .metric strong {
    font-size: 32px;
  }
}
