:root {
  --bg: #f2eee6;
  --bg-accent: #ddd4c5;
  --panel: rgba(255, 252, 247, 0.9);
  --panel-strong: #fffdf8;
  --line: rgba(92, 72, 48, 0.14);
  --text: #2e2a26;
  --muted: #6f665d;
  --primary: #21504f;
  --primary-soft: #dcebea;
  --secondary: #c9b18e;
  --secondary-strong: #8a6542;
  --danger: #9a3f31;
  --shadow: 0 24px 60px rgba(74, 54, 31, 0.12);
  --radius-xl: 28px;
  --radius-lg: 22px;
  --radius-md: 16px;
}

* {
  box-sizing: border-box;
}

img {
  max-width: 100%;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top left, rgba(33, 80, 79, 0.12), transparent 32%),
    radial-gradient(circle at right center, rgba(201, 177, 142, 0.18), transparent 26%),
    linear-gradient(180deg, #f8f4ed 0%, var(--bg) 55%, #ebe3d8 100%);
  min-height: 100vh;
}

body.login-screen .app-shell.centered-layout {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}

body.login-screen {
  overflow: hidden;
}

body.login-screen .app-shell.centered-layout .panel-layout {
  width: 100%;
  max-width: 520px;
  min-height: auto;
}

body.login-screen .app-shell.centered-layout .auth-card {
  width: 100%;
  margin: 0 auto;
}

a {
  color: inherit;
}

button,
input,
textarea {
  font: inherit;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  padding: 14px 16px;
  color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

input:focus,
textarea:focus {
  outline: none;
  border-color: rgba(33, 80, 79, 0.4);
  box-shadow: 0 0 0 4px rgba(33, 80, 79, 0.08);
}

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

.app-shell,
.detail-page {
  width: min(100% - 32px, 1440px);
  margin: 0 auto;
  padding: 28px 0 40px;
}

.app-shell {
  display: grid;
  grid-template-columns: 1.02fr 1.28fr;
  gap: 24px;
  align-items: start;
}

.app-shell.centered-layout {
  grid-template-columns: 1fr;
  max-width: none;
}

.app-shell.centered-layout .panel-layout {
  width: 100%;
}

.app-shell.centered-layout .dashboard,
.app-shell.centered-layout .auth-card,
.app-shell.centered-layout .search-card,
.app-shell.centered-layout .dashboard-hero,
.app-shell.centered-layout .stats-grid {
  width: 100%;
}

.welcome-panel {
  position: sticky;
  top: 28px;
  padding: 36px;
  min-height: calc(100vh - 56px);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(150deg, rgba(33, 80, 79, 0.96), rgba(47, 91, 90, 0.92)),
    linear-gradient(180deg, #21504f, #123536);
  color: #f7f2ea;
  box-shadow: var(--shadow);
}

.welcome-copy {
  color: var(--muted);
  line-height: 1.7;
}

.welcome-panel .welcome-copy {
  color: rgba(247, 242, 234, 0.84);
}

.welcome-card,
.panel-card {
  border-radius: var(--radius-lg);
  background: var(--panel);
  border: 1px solid rgba(255, 255, 255, 0.22);
  box-shadow: var(--shadow);
  backdrop-filter: blur(14px);
}

.welcome-card {
  margin-top: 28px;
  padding: 22px;
  color: #1f1d1a;
}

.feature-list,
.plan-list {
  margin: 14px 0 0;
  padding-left: 18px;
}

.feature-list li,
.plan-list li {
  margin-bottom: 8px;
}

.eyebrow {
  margin: 0 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.78rem;
  color: var(--secondary);
  font-weight: 700;
}

.panel-layout,
.dashboard,
.detail-content {
  display: grid;
  gap: 18px;
}

.auth-card,
.dashboard-hero,
.search-card,
.detail-header,
.detail-form-card {
  padding: 28px;
}

.auth-card {
  background: #fff;
}

.section-heading h2,
.section-heading h3,
.detail-title-row h1,
.patient-card h3 {
  margin: 0;
}

.login-brand {
  margin: 0 0 18px;
  text-align: center;
  color: #1f1d1a;
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  font-weight: 800;
}

.login-brand-logo {
  display: block;
  width: min(100%, 320px);
  max-width: 320px;
  height: auto;
  margin: 0 auto 18px;
  object-fit: contain;
}

.section-heading.compact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.search-card-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: nowrap;
}

.stack-form,
.detail-form {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 8px;
  font-weight: 600;
}

.helper-text {
  color: var(--muted);
  margin-bottom: 0;
}

.error-text {
  color: var(--danger);
  font-weight: 700;
  margin-bottom: 0;
}

.hidden {
  display: none !important;
}

.btn {
  border: 0;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 999px;
  padding: 12px 18px;
  font-weight: 800;
  transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.btn:hover,
.icon-btn:hover {
  transform: translateY(-1px);
}

.btn-primary {
  color: #f5f0ea;
  background: linear-gradient(135deg, #21504f, #346b68);
  box-shadow: 0 18px 30px rgba(33, 80, 79, 0.2);
}

.btn-secondary {
  color: var(--secondary-strong);
  background: rgba(201, 177, 142, 0.22);
  border: 1px solid rgba(138, 101, 66, 0.18);
}

.btn-danger {
  color: #fff;
  background: linear-gradient(135deg, #b43d31, #8f2c22);
  box-shadow: 0 16px 28px rgba(154, 63, 49, 0.2);
}

#logoutBtn {
  color: #fff !important;
  background: linear-gradient(135deg, #b43d31, #8f2c22) !important;
  box-shadow: 0 16px 28px rgba(154, 63, 49, 0.2) !important;
}

.dashboard-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  position: relative;
  z-index: 20;
  overflow: visible;
}

.welcome-brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.welcome-brand-logo {
  width: 58px;
  height: 58px;
  object-fit: contain;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.74);
  padding: 4px;
  flex: 0 0 58px;
}

.hero-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
  position: relative;
  z-index: 21;
}

.page-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.mobile-page-nav-toggle {
  display: none;
  width: 44px;
  height: 44px;
  min-width: 44px;
  border: 0;
  border-radius: 14px;
  cursor: pointer;
  color: #fff;
  font-size: 1.2rem;
  background: linear-gradient(135deg, #21504f, #346b68);
  box-shadow: 0 12px 22px rgba(33, 80, 79, 0.22);
}

.page-nav-btn {
  border: 0;
  cursor: pointer;
  padding: 10px 14px;
  border-radius: 999px;
  color: var(--secondary-strong);
  background: rgba(201, 177, 142, 0.16);
  position: relative;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.page-nav-btn.active {
  color: #f5f0ea;
  background: linear-gradient(135deg, #21504f, #346b68);
}

.detail-header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.project-frame-card {
  padding: 0;
  overflow: hidden;
  min-height: calc(100vh - 180px);
}

.project-frame-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 20px 20px 0;
}

.project-frame {
  display: block;
  width: 100%;
  min-height: calc(100vh - 180px);
  border: 0;
  background: #fff;
}

.detail-photo-trigger {
  width: 72px;
  height: 72px;
  min-width: 72px;
  min-height: 72px;
  flex: 0 0 72px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: pointer;
  border-radius: 50%;
  overflow: hidden;
}

#detailHeaderPhoto,
.detail-photo-trigger .detail-header-avatar,
.detail-photo-trigger img.detail-header-avatar {
  width: 100% !important;
  height: 100% !important;
  min-width: 100% !important;
  min-height: 100% !important;
  max-width: 100% !important;
  max-height: 100% !important;
  object-fit: cover;
  display: block;
}

.patient-detail-header .detail-photo-trigger .detail-header-avatar,
.patient-detail-header .detail-photo-trigger img.detail-header-avatar {
  border-radius: 24px !important;
}

.add-patient-btn {
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
  flex: 0 0 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  text-decoration: none;
  color: #f5f0ea;
  background: linear-gradient(135deg, #21504f, #346b68);
  box-shadow: 0 12px 24px rgba(33, 80, 79, 0.22);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.add-patient-btn:hover {
  transform: translateY(-1px);
}

.add-patient-btn span {
  line-height: 1;
  font-size: 1.55rem;
  font-weight: 500;
}

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

.search-toolbar {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.sort-menu {
  position: relative;
  justify-self: start;
}

.sort-menu-trigger {
  min-width: 180px;
  justify-content: space-between;
}

.sort-menu-trigger::after {
  content: "▾";
  font-size: 0.9rem;
}

.sort-menu-popup {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  z-index: 20;
  min-width: 180px;
  display: grid;
  gap: 6px;
  padding: 8px;
  border-radius: 16px;
  background: var(--panel-strong);
  border: 1px solid var(--line);
  box-shadow: 0 18px 34px rgba(74, 54, 31, 0.14);
}

.sort-menu-item {
  border: 0;
  cursor: pointer;
  text-align: left;
  padding: 12px 14px;
  border-radius: 12px;
  color: var(--secondary-strong);
  background: rgba(201, 177, 142, 0.16);
}

.sort-menu-item.active {
  color: #f5f0ea;
  background: linear-gradient(135deg, #21504f, #346b68);
}

.results-pill,
.status-badge,
.room-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  font-weight: 700;
}

.results-pill {
  min-height: 40px;
  padding: 0 14px;
  color: var(--primary);
  background: var(--primary-soft);
  white-space: nowrap;
}

.patient-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.patient-card {
  padding: 20px;
  border-radius: var(--radius-md);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(247, 242, 234, 0.92));
  border: 1px solid var(--line);
  box-shadow: 0 16px 32px rgba(74, 54, 31, 0.08);
  display: grid;
  gap: 14px;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  position: relative;
}

.patient-alert-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  color: #fff;
  background: linear-gradient(135deg, #b43d31, #8f2c22);
  font-size: 0.78rem;
  font-weight: 800;
  box-shadow: 0 10px 18px rgba(154, 63, 49, 0.18);
}

.patient-card-missing-data {
  border-color: rgba(180, 61, 49, 0.82);
  box-shadow: 0 0 0 2px rgba(180, 61, 49, 0.14), 0 16px 32px rgba(74, 54, 31, 0.08);
}

.patient-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 18px 34px rgba(74, 54, 31, 0.12);
}

.patient-card:focus-visible {
  outline: 3px solid rgba(33, 80, 79, 0.24);
  outline-offset: 2px;
}

.patient-card-top,
.patient-footer,
.detail-title-row,
.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.detail-header-main {
  display: flex;
  align-items: center;
  gap: 16px;
}

.patient-card-heading {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
  flex: 1 1 auto;
}

.patient-card-heading > div {
  min-width: 0;
  display: grid;
  gap: 6px;
  align-content: start;
}

.patient-avatar,
.patient-avatar-fallback,
.detail-header-avatar {
  object-fit: cover;
  background: rgba(33, 80, 79, 0.12);
  overflow: hidden;
}

.patient-avatar,
.patient-avatar-fallback {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  flex-shrink: 0;
}

.patient-avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-weight: 800;
  border: 1px solid rgba(33, 80, 79, 0.14);
}

.patient-avatar {
  background: rgba(255, 255, 255, 0.88);
  display: block;
}

.detail-header-avatar {
  width: 72px;
  height: 72px;
  min-width: 72px;
  max-width: 72px;
  min-height: 72px;
  max-height: 72px;
  display: block;
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 14px 26px rgba(74, 54, 31, 0.12);
}

.patient-detail-header .detail-header-avatar,
.patient-detail-header img.detail-header-avatar {
  width: 124px !important;
  height: 156px !important;
  min-width: 124px !important;
  max-width: 124px !important;
  min-height: 156px !important;
  max-height: 156px !important;
  border-radius: 24px !important;
}

.patient-detail-header .detail-photo-trigger {
  width: 124px;
  height: 156px;
  min-width: 124px;
  min-height: 156px;
  border-radius: 24px;
}

.detail-header-avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-size: 1.5rem;
  font-weight: 800;
  border: 1px solid rgba(33, 80, 79, 0.14);
}

.status-badge {
  min-height: 32px;
  padding: 0 12px;
  margin-bottom: 10px;
  color: var(--primary);
  background: var(--primary-soft);
  align-self: start;
  justify-self: start;
  max-width: 100%;
  white-space: normal;
  text-align: center;
}

.room-badge {
  min-width: 68px;
  min-height: 42px;
  padding: 0 14px;
  color: #fff;
  background: linear-gradient(135deg, #b89167, #8a6542);
  flex: 0 0 auto;
  align-self: start;
}

.patient-card-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 12px;
}

.patient-card h3 {
  min-width: 0;
  line-height: 1.28;
  overflow-wrap: break-word;
  word-break: normal;
  hyphens: none;
  text-wrap: balance;
}

.patient-card h3.patient-name-long {
  font-size: 1.08rem;
}

.patient-card h3.patient-name-very-long {
  font-size: 0.98rem;
  line-height: 1.24;
}

.patient-meta,
.patient-diagnosis {
  margin: 0;
  color: var(--muted);
}

.patient-archive-duration {
  margin: 0;
  color: #8e8a84;
  font-size: 0.84rem;
  line-height: 1.35;
}

.patient-meta {
  font-size: 0.94rem;
  line-height: 1.4;
}

.patient-diagnosis {
  font-size: 0.92rem;
  line-height: 1.45;
}

.patient-footer {
  align-items: end;
}

.empty-state {
  margin: 0;
  padding: 18px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.7);
  color: var(--muted);
}

.detail-header {
  margin-bottom: 18px;
}

.back-link {
  text-decoration: none;
  color: var(--primary);
  font-weight: 700;
}

.icon-btn {
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.5rem;
  color: #fff;
  background: linear-gradient(135deg, #21504f, #346b68);
  box-shadow: 0 18px 28px rgba(33, 80, 79, 0.24);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.icon-btn-danger {
  background: linear-gradient(135deg, #b43d31, #8f2c22);
  box-shadow: 0 18px 28px rgba(154, 63, 49, 0.24);
}

.icon-btn-muted {
  background: linear-gradient(135deg, #8f96a3, #6f7785);
  box-shadow: 0 18px 28px rgba(111, 119, 133, 0.24);
}

.icon-link-btn {
  min-height: 52px;
  padding: 0 18px;
  border-radius: 999px;
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  color: #fff;
  font-weight: 700;
  background: linear-gradient(135deg, #21504f, #346b68);
  box-shadow: 0 18px 28px rgba(33, 80, 79, 0.24);
}

.icon-link-btn-muted {
  background: linear-gradient(135deg, #8f96a3, #6f7785);
  box-shadow: 0 18px 28px rgba(111, 119, 133, 0.24);
}

.header-count-badge {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.74rem;
  font-weight: 800;
  color: #111;
  background: #84e26d;
  box-shadow: 0 8px 16px rgba(55, 130, 41, 0.22);
}

.nav-unread-badge {
  min-width: 20px;
  height: 20px;
  top: -8px;
  right: -8px;
  font-size: 0.68rem;
  background: #84e26d;
  color: #111;
}

.detail-card {
  padding: 24px;
}

.detail-list {
  display: grid;
  gap: 12px;
}

.detail-list > div:not(.detail-row):not(.detail-row-form) {
  display: grid;
  gap: 4px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.detail-row,
.detail-row-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.detail-row-content {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.detail-row-content strong,
.detail-row-content p,
.detail-inline-list li {
  white-space: pre-line;
}

.detail-row > .mini-edit-btn {
  justify-self: end;
  align-self: start;
}

.detail-row-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.detail-name-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.detail-name-edit-btn {
  width: 34px;
  height: 34px;
  min-width: 34px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.mini-edit-btn {
  border: 0;
  cursor: pointer;
  border-radius: 12px;
  padding: 9px 12px;
  color: var(--secondary-strong);
  background: rgba(201, 177, 142, 0.16);
  flex-shrink: 0;
}

.mini-edit-btn-save {
  color: #f5f0ea;
  background: linear-gradient(135deg, #21504f, #346b68);
}

.detail-inline-list {
  margin: 0;
  padding-left: 18px;
}

.prescribed-medications-editor-card,
.prescribed-medications-static-list {
  display: grid;
  gap: 10px;
}

.prescribed-medications-editor-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 700;
}

.prescribed-medications-rows {
  display: grid;
  gap: 10px;
}

.prescribed-medication-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 160px 40px;
  gap: 10px;
  align-items: start;
}

.prescribed-medication-row .file-action-btn {
  margin-top: 4px;
  width: 40px;
  height: 40px;
  min-width: 40px;
  justify-self: end;
}

.prescribed-medication-name {
  min-width: 0;
  min-height: 72px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
}

.prescribed-medications-static-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(108, 89, 64, 0.08);
}

.prescribed-medications-static-item span {
  color: var(--muted);
}

.prescribed-medication-expired {
  border-color: rgba(180, 61, 49, 0.28);
  background: rgba(180, 61, 49, 0.08);
}

.detail-list span {
  display: block;
  color: var(--muted);
  margin-bottom: 4px;
}

.detail-form textarea[name="carePlan"] {
  min-height: 110px;
}

.patient-files-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.file-category-add-btn {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.3rem;
  background: linear-gradient(135deg, #21504f, #3f7d78);
  box-shadow: 0 10px 18px rgba(33, 80, 79, 0.18);
}

.patient-files-list {
  display: grid;
  gap: 14px;
}

.category-note-box {
  display: grid;
  gap: 10px;
  margin-bottom: 14px;
  padding: 16px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(108, 89, 64, 0.08);
}

.category-note-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.category-note-label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}

.category-note-display {
  white-space: pre-line;
  line-height: 1.55;
  color: var(--text);
  min-height: 24px;
}

.patient-file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 18px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(247, 241, 232, 0.92));
  border: 1px solid rgba(108, 89, 64, 0.1);
  box-shadow: 0 18px 32px rgba(94, 69, 43, 0.08);
  color: var(--text);
  text-decoration: none;
}

.patient-file-link {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  color: var(--text);
  text-decoration: none;
}

.patient-file-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 14px;
}

.patient-file-copy {
  min-width: 0;
  flex: 1 1 auto;
}

.patient-file-thumb {
  width: 56px;
  height: 56px;
  min-width: 56px;
  border-radius: 18px;
  object-fit: cover;
  box-shadow: 0 10px 18px rgba(76, 59, 43, 0.14);
}

.patient-file-thumb-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  font-size: 0.74rem;
  font-weight: 800;
  background: rgba(201, 177, 142, 0.18);
}

.patient-file-item strong,
.patient-file-item p {
  margin: 0;
}

.patient-file-item strong {
  display: block;
  font-size: 1rem;
  line-height: 1.35;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.patient-file-item p {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.4;
  margin-top: 4px;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.patient-file-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.file-action-btn {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  color: #8a6542;
  background: linear-gradient(180deg, rgba(201, 177, 142, 0.24), rgba(201, 177, 142, 0.12));
  box-shadow: 0 8px 16px rgba(94, 69, 43, 0.12);
}

.file-action-btn-danger {
  color: #fff;
  background: linear-gradient(135deg, #b43d31, #8f2c22);
}

.patient-file-open {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--primary);
  background: rgba(33, 80, 79, 0.1);
}

.floating-add-btn {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 68px;
  height: 68px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 2rem;
  background: linear-gradient(135deg, #21504f, #3f7d78);
  box-shadow: 0 22px 34px rgba(33, 80, 79, 0.3);
  z-index: 40;
}

.preview-modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.preview-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 23, 18, 0.7);
  backdrop-filter: blur(4px);
}

.preview-modal-card {
  position: relative;
  z-index: 1;
  width: min(92vw, 900px);
  max-height: 88vh;
  padding: 14px;
  border-radius: 28px;
  background: rgba(255, 250, 245, 0.96);
  box-shadow: 0 26px 60px rgba(17, 16, 14, 0.28);
}

.preview-modal-image {
  display: block;
  width: 100%;
  max-height: calc(88vh - 28px);
  border-radius: 20px;
  object-fit: contain;
  background: #f5f1eb;
}

.orders-link-card {
  cursor: pointer;
}

.visit-reports-list {
  margin-top: 18px;
}

.visit-report-card {
  cursor: pointer;
}

.orders-link-card-body {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.orders-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.orders-list-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.68);
  border: 1px solid rgba(108, 89, 64, 0.1);
}

.orders-list-open {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  font-weight: 700;
}

.orders-list-open small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 500;
}

.orders-link-arrow {
  width: 46px;
  height: 46px;
  min-width: 46px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 1.25rem;
  background: linear-gradient(135deg, #21504f, #3f7d78);
  box-shadow: 0 12px 22px rgba(33, 80, 79, 0.18);
}

.orders-layout {
  display: flex;
  justify-content: center;
}

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

.orders-paste-input {
  width: 100%;
  min-height: 180px;
  resize: vertical;
  border-radius: 20px;
  border: 1px solid rgba(108, 89, 64, 0.14);
  background: rgba(255, 255, 255, 0.88);
  padding: 16px 18px;
  font: inherit;
  line-height: 1.55;
  color: var(--text);
}

.orders-sheet {
  width: min(100%, 1220px);
  padding: 0;
  overflow: hidden;
}

.orders-summary {
  padding: 28px 30px 20px;
  border-bottom: 2px solid rgba(37, 29, 19, 0.18);
}

.orders-summary p {
  margin: 0 0 8px;
  font-size: clamp(1rem, 1.6vw, 1.12rem);
  line-height: 1.45;
}

.orders-table-wrap {
  overflow-x: auto;
}

.orders-table {
  width: 100%;
  border-collapse: collapse;
  background: rgba(255, 255, 255, 0.92);
}

.orders-table th,
.orders-table td {
  border: 2px solid rgba(37, 29, 19, 0.22);
  padding: 10px 12px;
  vertical-align: top;
}

.orders-table th {
  font-size: 1rem;
  text-align: center;
  background: rgba(248, 243, 236, 0.96);
}

.orders-table td textarea {
  width: 100%;
  min-height: 68px;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
  resize: vertical;
  font: inherit;
}

.orders-table-actions {
  width: 58px;
  text-align: center;
}

.orders-print-logo-wrap {
  display: none;
  justify-content: center;
  margin-bottom: 18px;
}

.orders-print-logo {
  display: block;
  width: min(220px, 100%);
  max-width: 220px;
  height: auto;
  object-fit: contain;
}

@media print {
  .detail-header,
  .floating-add-btn,
  .orders-table-actions,
  .file-action-btn,
  .btn,
  .icon-link-btn,
  .back-link {
    display: none !important;
  }

  .orders-page,
  .detail-page {
    width: 100%;
    max-width: none;
    padding: 0;
    background: #fff;
  }

  .orders-sheet,
  .panel-card {
    box-shadow: none !important;
    border: 0 !important;
    background: #fff !important;
  }

  .orders-print-logo-wrap {
    display: flex;
    margin-bottom: 22px;
  }

  .orders-print-logo {
    max-width: 240px;
  }

  .orders-table th,
  .orders-table td {
    border-color: #000 !important;
  }
}

.preview-close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  font-size: 1.4rem;
  background: linear-gradient(135deg, #b43d31, #8f2c22);
  box-shadow: 0 12px 22px rgba(143, 44, 34, 0.3);
}

.visit-detail-meta-actions {
  align-items: flex-start;
}

.visit-detail-meta {
  display: grid;
  gap: 4px;
  min-width: 0;
  margin-right: 6px;
  color: var(--muted);
  font-size: 0.9rem;
}

.visit-summary {
  display: grid;
  gap: 4px;
}

.visit-table textarea {
  min-height: 96px;
  white-space: pre-wrap;
  overflow-wrap: break-word;
}

.visit-table .visit-patient-name-input {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.visit-table th:nth-child(1),
.visit-table td:nth-child(1) {
  width: 24%;
}

.visit-table th:nth-child(2),
.visit-table td:nth-child(2),
.visit-table th:nth-child(3),
.visit-table td:nth-child(3) {
  width: 34%;
}

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

  .welcome-panel {
    position: static;
    min-height: auto;
  }

  .stats-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

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

@media (max-width: 640px) {
  .app-shell,
  .detail-page {
    width: min(100% - 20px, 1440px);
    padding: 10px 0 24px;
  }

  .welcome-panel,
  .auth-card,
  .dashboard-hero,
  .search-card,
  .detail-header,
  .detail-form-card,
  .detail-card {
    padding: 20px;
  }

  .dashboard-hero,
  .search-card-actions,
  .detail-header-actions,
  .patient-footer,
  .hero-actions,
  .form-actions,
  .section-heading.compact {
    flex-direction: column;
    align-items: flex-start;
  }

  .btn,
  .icon-btn {
    width: 100%;
  }

  .icon-btn {
    border-radius: 18px;
    height: 48px;
  }

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

  .search-card-actions {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    width: 100%;
  }

  .hero-actions {
    display: grid;
    grid-template-columns: auto auto;
    align-items: start;
    justify-content: end;
    width: auto;
    margin-left: 0;
    position: relative;
    gap: 8px;
  }

  .dashboard-hero {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: start;
  }

  .mobile-page-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .welcome-brand-logo {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
    border-radius: 12px;
  }

  .welcome-brand-row {
    gap: 10px;
  }

  #logoutBtn {
    grid-column: 2;
    grid-row: 1;
    justify-self: end;
    width: auto;
    min-width: 74px;
    padding: 9px 12px;
    font-size: 0.84rem;
  }

  .page-nav {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    z-index: 999;
    width: min(220px, calc(100vw - 40px));
    padding: 10px;
    border-radius: 18px;
    background: var(--panel-strong);
    border: 1px solid var(--line);
    box-shadow: 0 18px 34px rgba(74, 54, 31, 0.16);
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    flex-wrap: nowrap;
  }

  .page-nav.page-nav-mobile-open {
    display: flex;
  }

  .page-nav-btn {
    width: 100%;
    justify-content: center;
    text-align: center;
  }

  .add-patient-btn {
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    flex-basis: 40px;
  }

  .add-patient-btn span {
    font-size: 1.35rem;
  }

  .sort-menu {
    width: 100%;
  }

  .sort-menu-trigger,
  .sort-menu-popup {
    width: 100%;
    min-width: 0;
  }

  .sort-menu-popup {
    top: calc(100% + 6px);
    left: 0;
  }

  .patient-card {
    padding: 12px;
    gap: 8px;
    min-width: 0;
  }

  .patient-card-top {
    align-items: flex-start;
    gap: 8px;
  }

  .patient-card-heading {
    flex-direction: row;
    align-items: flex-start;
    gap: 8px;
    min-width: 0;
  }

  .patient-card-heading > div {
    min-width: 0;
  }

  .patient-card h3 {
    font-size: 0.95rem;
    line-height: 1.2;
    word-break: normal;
    overflow-wrap: break-word;
    text-wrap: balance;
  }

  .patient-card h3.patient-name-long {
    font-size: 0.88rem;
  }

  .patient-card h3.patient-name-very-long {
    font-size: 0.82rem;
    line-height: 1.18;
  }

  .login-brand-logo {
    width: min(100%, 240px);
    max-width: 240px;
    margin-bottom: 14px;
  }

  .patient-card-heading .status-badge {
    margin-top: 6px;
    margin-bottom: 0;
  }

  .patient-meta,
  .patient-diagnosis,
  .patient-footer {
    font-size: 0.78rem;
    line-height: 1.35;
  }

  .patient-footer {
    align-items: flex-start;
  }

  .patient-avatar,
  .patient-avatar-fallback,
  .detail-header-avatar {
    width: 40px;
    height: 40px;
    min-width: 40px;
    max-width: 40px;
    min-height: 40px;
    max-height: 40px;
  }

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

  .detail-header-main {
    flex-direction: row;
    align-items: center;
    gap: 14px;
  }

  .detail-header-main > div:last-child {
    min-width: 0;
  }

  .detail-header-main h1 {
    font-size: 1.08rem;
    line-height: 1.2;
  }

  .detail-header-avatar,
  img.detail-header-avatar {
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    max-width: 48px !important;
    min-height: 48px !important;
    max-height: 48px !important;
    inline-size: 48px !important;
    block-size: 48px !important;
    flex: 0 0 48px;
  }

  .patient-detail-header .detail-header-avatar,
  .patient-detail-header img.detail-header-avatar {
    width: 48px !important;
    height: 48px !important;
    min-width: 48px !important;
    max-width: 48px !important;
    min-height: 48px !important;
    max-height: 48px !important;
    border-radius: 50% !important;
  }

  .detail-photo-trigger {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    flex-basis: 48px;
  }

  .patient-detail-header .detail-photo-trigger {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
    border-radius: 50%;
  }

  .detail-header-actions {
    width: auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;
  }

  .detail-header-actions .icon-btn {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: 999px;
    padding: 0;
    font-size: 1rem;
  }

  .icon-link-btn {
    min-height: 40px;
    padding: 0 12px;
    font-size: 0.84rem;
  }

  .detail-grid {
    gap: 14px;
  }

  .detail-card {
    padding: 16px;
  }

  .detail-list > div:not(.detail-row):not(.detail-row-form) {
    grid-template-columns: minmax(92px, 40%) minmax(0, 1fr);
    align-items: start;
    gap: 8px;
  }

  .detail-row,
  .detail-row-form {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .detail-row-content {
    width: 100%;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding-bottom: 0;
    border-bottom: 0;
  }

  .detail-row-content strong,
  .detail-row-content p,
  .detail-row-content li,
  .detail-row-content textarea,
  .detail-row-content input {
    width: 100%;
    max-width: 100%;
    white-space: normal;
    word-break: normal !important;
    overflow-wrap: break-word !important;
    hyphens: none;
    min-width: 0;
  }

  .detail-row-actions {
    justify-content: flex-end;
    flex-wrap: wrap;
    width: 100%;
  }

  .detail-row > .mini-edit-btn {
    align-self: flex-end;
    justify-self: auto;
    margin-top: 2px;
  }

  .detail-row-content span,
  .detail-row-content strong,
  .detail-row-content p,
  .detail-row-content li,
  .detail-inline-list {
    display: block;
    width: 100%;
    max-width: 100%;
    word-break: normal !important;
    overflow-wrap: break-word !important;
    hyphens: none;
    text-wrap: pretty;
    min-width: 0;
  }

.detail-row-content strong,
.detail-row-content p,
.detail-row-content li {
  font-size: 0.94rem;
  line-height: 1.55;
}

  .detail-row-content strong,
  .detail-row-content p,
  .detail-inline-list,
  .detail-inline-list li,
  .detail-row-content textarea,
  .detail-row-content input {
    inline-size: 100%;
  }

.detail-row-content strong {
  font-size: 0.98rem;
  white-space: pre-line;
  word-break: normal !important;
  overflow-wrap: break-word !important;
  text-wrap: pretty;
}

.detail-row-content p,
.detail-inline-list li {
  white-space: pre-line;
}

  .mini-edit-btn {
    width: 30px;
    height: 30px;
    min-width: 30px;
    padding: 0;
    border-radius: 999px;
    font-size: 0.82rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .detail-row-actions .mini-edit-btn {
    width: auto;
    height: auto;
    min-width: 74px;
    padding: 8px 12px;
    border-radius: 999px;
  }

  .detail-list span {
    margin-bottom: 0;
    font-size: 0.8rem;
  }

  .detail-list strong {
    font-size: 0.98rem;
    line-height: 1.55;
    word-break: normal;
    overflow-wrap: break-word;
  }

  .patient-file-item {
    padding: 14px;
    align-items: stretch;
    border-radius: 20px;
  }

  .orders-link-card-body {
    align-items: flex-start;
  }

  .orders-list-item {
    padding: 10px 12px;
  }

  .orders-summary {
    padding: 18px 18px 14px;
  }

  .visit-detail-meta-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .visit-detail-meta {
    width: 100%;
    margin-right: 0;
  }

  .orders-table th,
  .orders-table td {
    min-width: 132px;
    padding: 9px 10px;
  }

  .orders-table-actions {
    min-width: 52px !important;
  }

  .category-note-box {
    padding: 14px;
  }

  .patient-file-link {
    align-items: flex-start;
    gap: 10px;
  }

  .patient-file-main {
    gap: 10px;
    align-items: flex-start;
  }

  .patient-file-thumb {
    width: 48px;
    height: 48px;
    min-width: 48px;
    border-radius: 14px;
  }

  .patient-file-actions {
    margin-top: 2px;
    gap: 6px;
    align-self: flex-start;
  }

  .file-category-add-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    font-size: 1.15rem;
  }

  .file-action-btn,
  .patient-file-open {
    width: 30px;
    height: 30px;
    min-width: 30px;
  }

  .floating-add-btn {
    right: 16px;
    bottom: 16px;
    width: 56px;
    height: 56px;
    font-size: 1.8rem;
  }

  .preview-modal {
    padding: 14px;
  }

  .preview-modal-card {
    width: 100%;
    padding: 10px;
    border-radius: 20px;
  }

  .preview-modal-image {
    border-radius: 14px;
  }

  .preview-close-btn {
    top: 10px;
    right: 10px;
    width: 36px;
    height: 36px;
    font-size: 1.2rem;
  }
}

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

  .patient-card {
    padding: 10px;
    gap: 7px;
  }

  .patient-card-top {
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    column-gap: 8px;
    row-gap: 6px;
    align-items: start;
  }

  .patient-card-heading {
    display: contents;
  }

  .patient-card .patient-avatar {
    grid-column: 1;
    grid-row: 1 / span 2;
  }

  .patient-card-heading > div {
    grid-column: 2;
    grid-row: 1;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px 8px;
    min-width: 0;
  }

  .patient-card h3 {
    font-size: 0.88rem;
    width: 100%;
    white-space: normal;
    word-break: normal;
    overflow-wrap: break-word;
    line-height: 1.25;
  }

  .patient-card h3.patient-name-long {
    font-size: 0.82rem;
  }

  .patient-card h3.patient-name-very-long {
    font-size: 0.76rem;
    line-height: 1.2;
  }

  .room-badge,
  .status-badge {
    min-width: 0;
    padding: 0 8px;
    font-size: 0.72rem;
  }

  .patient-card-heading .status-badge {
    margin-top: 0;
    order: 2;
  }

  .room-badge {
    grid-column: 2;
    grid-row: 2;
    align-self: start;
    justify-self: start;
    order: 3;
  }

  .patient-meta,
  .patient-diagnosis,
  .patient-footer {
    font-size: 0.72rem;
  }

  .sort-menu-trigger {
    min-width: 0;
    width: 100%;
    padding: 12px 14px;
  }

  .sort-menu-popup {
    width: 100%;
    min-width: 0;
  }

  .add-patient-btn {
    width: 38px;
    height: 38px;
    min-width: 38px;
    min-height: 38px;
    flex-basis: 38px;
  }

  .add-patient-btn span {
    font-size: 1.2rem;
  }

  #logoutBtn {
    justify-self: end;
    min-width: 68px;
    padding: 8px 11px;
    font-size: 0.78rem;
  }

  .detail-photo-trigger {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    flex-basis: 44px;
  }
}
.user-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(247, 242, 234, 0.92));
  border: 1px solid rgba(92, 72, 48, 0.14);
  box-shadow: 0 16px 32px rgba(74, 54, 31, 0.08);
}

.user-actions {
  display: flex;
  gap: 10px;
}

.backup-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
  margin-bottom: 18px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
}

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

.admin-tool-card {
  position: relative;
  overflow: hidden;
  padding: 22px;
  margin-bottom: 0;
  border-radius: 24px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(247, 242, 234, 0.92));
  box-shadow: 0 18px 34px rgba(74, 54, 31, 0.08);
}

.admin-tool-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: linear-gradient(180deg, #21504f, #346b68);
}

.notification-admin-card::before {
  background: linear-gradient(180deg, #21504f, #346b68);
}

.backup-admin-card::before {
  background: linear-gradient(180deg, #8a6542, #c9b18e);
}

.summary-filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin-top: 18px;
}

.summary-filter-bar label {
  min-width: 180px;
  flex: 0 1 220px;
}

.summary-select-card {
  padding: 14px 16px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(247, 242, 234, 0.92));
  border: 1px solid rgba(92, 72, 48, 0.12);
  box-shadow: 0 12px 24px rgba(74, 54, 31, 0.06);
}

.summary-select-card select {
  margin-top: 4px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  padding: 12px 42px 12px 14px;
  color: var(--text);
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--secondary-strong) 50%),
    linear-gradient(135deg, var(--secondary-strong) 50%, transparent 50%);
  background-position:
    calc(100% - 18px) calc(50% - 3px),
    calc(100% - 12px) calc(50% - 3px);
  background-size: 6px 6px, 6px 6px;
  background-repeat: no-repeat;
}

.summary-chart-card {
  display: grid;
  gap: 14px;
  margin-top: 18px;
  padding: 20px;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  min-width: 0;
  overflow: hidden;
}

.summary-chart-head h4 {
  margin: 0;
}

.summary-chart-wrap {
  width: 100%;
  min-width: 0;
}

.summary-chart-scroll {
  overflow-x: auto;
  padding-bottom: 6px;
  -webkit-overflow-scrolling: touch;
}

.summary-chart-svg {
  width: 100%;
  min-width: 720px;
  height: 220px;
  display: block;
}

.summary-chart-axis {
  stroke: rgba(92, 72, 48, 0.24);
  stroke-width: 2;
}

.summary-chart-bar {
  fill: rgba(201, 177, 142, 0.42);
}

.summary-chart-bar.is-active {
  fill: #21504f;
}

.summary-chart-value {
  fill: var(--text);
  font-size: 12px;
  font-weight: 700;
}

.summary-chart-label {
  fill: var(--muted);
  font-size: 10px;
}

.summary-metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  margin-top: 18px;
}

.summary-metric-card {
  display: grid;
  gap: 8px;
  padding: 20px;
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(247, 242, 234, 0.92));
  border: 1px solid rgba(92, 72, 48, 0.14);
  box-shadow: 0 16px 32px rgba(74, 54, 31, 0.08);
}

.summary-metric-card h4,
.summary-metric-card strong {
  margin: 0;
}

.summary-metric-card strong {
  font-size: clamp(1.45rem, 2vw, 2rem);
  line-height: 1.1;
}

.admin-tool-card .section-heading.compact {
  align-items: start;
}

.admin-tool-card .section-heading h3 {
  margin-bottom: 6px;
}

.admin-tool-card .panel-copy {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.backup-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.backup-upload-form {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  flex: 1 1 320px;
}

.backup-upload-form input[type="file"] {
  max-width: 100%;
}

.backup-file-picker {
  position: relative;
  min-height: 48px;
  padding: 12px 16px;
  border-radius: 16px;
  border: 1px dashed rgba(138, 101, 66, 0.36);
  background: rgba(255, 255, 255, 0.82);
  color: var(--secondary-strong);
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  flex: 1 1 220px;
  cursor: pointer;
}

.backup-file-picker input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.backup-download-btn {
  min-width: 132px;
}

#notificationForm,
#backupUploadForm {
  align-items: stretch;
}

#notificationForm label,
.backup-file-picker {
  background: rgba(255, 255, 255, 0.62);
}

#notificationForm label {
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(108, 89, 64, 0.12);
}

#notificationMessageBox,
#backupMessage {
  padding: 12px 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(108, 89, 64, 0.1);
}

.notification-modal-card {
  width: min(460px, calc(100vw - 28px));
}

.notification-modal-content {
  display: grid;
  gap: 14px;
}

.notification-modal-content h3,
.notification-modal-text {
  margin: 0;
}

.notification-modal-text {
  white-space: pre-line;
  line-height: 1.6;
}

.log-toolbar {
  margin-top: 0;
}

.log-quick-filters {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

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

.log-results-pill {
  margin-top: 18px;
}

.log-online-users-wrap {
  display: grid;
  gap: 10px;
  margin-top: 18px;
}

.log-online-users {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.log-online-user-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 14px;
  border-radius: 14px;
  color: #183b2e;
  background: linear-gradient(180deg, rgba(112, 214, 153, 0.92), rgba(76, 191, 126, 0.9));
  border: 1px solid rgba(24, 59, 46, 0.12);
  font-weight: 800;
  box-shadow: 0 10px 18px rgba(76, 191, 126, 0.12);
}

.log-list {
  display: grid;
  gap: 12px;
  margin-top: 18px;
}

.log-pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-top: 18px;
}

.log-page-pill {
  min-width: 120px;
}

.log-item {
  padding: 18px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.95), rgba(247, 242, 234, 0.92));
  border: 1px solid rgba(92, 72, 48, 0.14);
  box-shadow: 0 16px 32px rgba(74, 54, 31, 0.08);
  display: grid;
  gap: 10px;
}

.log-item-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.log-item h3 {
  margin: 0;
}

.messages-page-card {
  display: grid;
  gap: 18px;
  padding-bottom: 120px;
}

.messages-compose-form {
  display: grid;
  gap: 12px;
}

.messages-compose-form textarea {
  width: 100%;
  min-height: 120px;
  resize: vertical;
}

.messages-compose-docked {
  position: sticky;
  bottom: 16px;
  z-index: 30;
  width: min(760px, calc(100% - 32px));
  margin: 0 auto;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  padding: 14px;
  border-radius: 24px;
  background: rgba(255, 252, 247, 0.96);
  border: 1px solid rgba(108, 89, 64, 0.12);
  box-shadow: 0 18px 34px rgba(74, 54, 31, 0.12);
}

.messages-compose-docked textarea {
  min-height: 72px;
  margin: 0;
}

.messages-form-status {
  width: min(760px, calc(100% - 32px));
  margin: 6px auto 0;
  text-align: center;
}

.messages-list {
  display: grid;
  gap: 14px;
  align-content: start;
}

.message-item {
  display: grid;
  gap: 8px;
  width: min(72%, 560px);
  padding: 12px 14px;
  border-radius: 18px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(247, 242, 234, 0.92));
  border: 1px solid rgba(108, 89, 64, 0.12);
  box-shadow: 0 16px 30px rgba(74, 54, 31, 0.08);
}

.message-item-own {
  margin-left: auto;
  background: linear-gradient(180deg, rgba(226, 242, 238, 0.98), rgba(211, 232, 226, 0.94));
  border-color: rgba(33, 80, 79, 0.18);
}

.message-item-other {
  margin-right: auto;
}

.message-item-top {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.message-item-meta {
  display: grid;
  gap: 4px;
}

.message-item-meta strong,
.message-item-meta span,
.message-item-text {
  margin: 0;
}

.message-item-meta span {
  color: var(--muted);
  font-size: 0.76rem;
}

.message-item-text {
  white-space: pre-line;
  line-height: 1.45;
  font-size: 0.94rem;
}

.global-message-fab {
  position: fixed;
  left: 18px;
  bottom: 18px;
  width: 62px;
  height: 62px;
  border: 0;
  border-radius: 50%;
  z-index: 90;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  background: linear-gradient(135deg, #21504f, #3f7d78);
  box-shadow: 0 16px 30px rgba(33, 80, 79, 0.26);
}

.global-message-fab-badge {
  position: absolute;
  top: -4px;
  right: -2px;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  background: linear-gradient(135deg, #b43d31, #8f2c22);
  font-size: 0.74rem;
  font-weight: 800;
  box-shadow: 0 10px 18px rgba(154, 63, 49, 0.24);
}

.global-message-widget {
  position: fixed;
  inset: 0;
  z-index: 120;
}

.global-message-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(30, 26, 20, 0.34);
  backdrop-filter: blur(2px);
}

.global-message-panel {
  position: absolute;
  left: 18px;
  bottom: 92px;
  width: min(420px, calc(100vw - 28px));
  max-height: min(78vh, 720px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 10px;
  padding: 14px;
  border-radius: 24px;
  background: rgba(255, 252, 247, 0.98);
  border: 1px solid rgba(108, 89, 64, 0.12);
  box-shadow: 0 24px 44px rgba(74, 54, 31, 0.18);
}

.global-message-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.global-message-header h3 {
  margin: 0;
}

.global-message-header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.global-message-header .preview-close-btn {
  position: static;
  box-shadow: none;
}

.global-message-list {
  min-height: 220px;
  max-height: 52vh;
  overflow-y: auto;
  display: grid;
  gap: 10px;
  padding-right: 4px;
}

.global-message-item {
  display: flex;
}

.global-message-item.own {
  justify-content: flex-end;
}

.global-message-bubble {
  width: min(88%, 320px);
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(108, 89, 64, 0.12);
}

.global-message-item.own .global-message-bubble {
  background: linear-gradient(180deg, rgba(226, 242, 238, 0.98), rgba(211, 232, 226, 0.94));
  border-color: rgba(33, 80, 79, 0.16);
}

.global-message-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.global-message-meta strong,
.global-message-meta span,
.global-message-bubble p {
  margin: 0;
}

.global-message-meta strong {
  font-size: 0.84rem;
}

.global-message-meta span {
  color: var(--muted);
  font-size: 0.72rem;
}

.global-message-bubble p {
  font-size: 0.92rem;
  line-height: 1.42;
  white-space: pre-line;
}

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

.global-message-check-btn {
  color: #21504f;
}

.global-message-checked-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 4px 10px;
  border-radius: 999px;
  color: #21504f;
  background: rgba(33, 80, 79, 0.12);
  font-size: 0.74rem;
  font-weight: 800;
}

.global-message-compose {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.global-message-compose textarea {
  min-height: 58px;
  margin: 0;
}

@media (max-width: 640px) {
  .backup-actions,
  .backup-upload-form {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .admin-tools-grid {
    grid-template-columns: 1fr;
  }

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

  .summary-filter-bar {
    flex-direction: column;
  }

  .summary-filter-bar label,
  .summary-select-card {
    min-width: 0;
    width: 100%;
  }

  .summary-chart-card {
    padding: 16px;
  }

  .summary-chart-svg {
    min-width: 560px;
    height: 200px;
  }

  .summary-chart-label {
    font-size: 9px;
  }

  .log-filter-grid {
    grid-template-columns: 1fr;
  }

  .log-quick-filters {
    width: 100%;
  }

  .project-frame-toolbar {
    padding: 16px 16px 0;
  }

  .log-item {
    padding: 14px;
  }

  .message-item {
    padding: 14px;
    width: min(92%, 100%);
  }

  .global-message-panel {
    left: 10px;
    right: 10px;
    bottom: 84px;
    width: auto;
    max-height: 76vh;
    padding: 12px;
  }

  .global-message-bubble {
    width: min(92%, 100%);
  }

  .global-message-compose {
    grid-template-columns: 1fr;
  }

  .prescribed-medication-row {
    grid-template-columns: 1fr;
  }

  .messages-compose-docked {
    width: calc(100% - 20px);
    bottom: 10px;
    grid-template-columns: 1fr;
  }

  .messages-form-status {
    width: calc(100% - 20px);
  }
}

@media (max-width: 520px) {
  .summary-metrics-grid {
    grid-template-columns: 1fr;
  }

  .summary-chart-card {
    padding: 14px;
  }

  .summary-chart-svg {
    min-width: 480px;
    height: 188px;
  }

  .summary-chart-value {
    font-size: 11px;
  }
}
