:root {
  --ink: #17212b;
  --muted: #65727f;
  --line: #dfe7e5;
  --panel: #ffffff;
  --wash: #f6f9f7;
  --teal: #196f73;
  --teal-soft: #d7eeeb;
  --coral: #d9675a;
  --coral-soft: #f9ded8;
  --sage: #7ca982;
  --gold: #c58a25;
  --navy: #243b53;
  --plum: #79516f;
  --shadow: 0 18px 45px rgba(28, 46, 61, 0.12);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--wash);
  color: var(--ink);
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: #edf5f2;
}

.auth-layout {
  width: min(1180px, 100%);
  min-height: min(760px, calc(100vh - 48px));
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.auth-art {
  position: relative;
  min-height: 560px;
  background: #12212a;
  color: white;
  display: grid;
  align-content: space-between;
  padding: 28px;
  overflow: hidden;
}

.auth-art img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.88;
}

.auth-art::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(0deg, rgba(18, 33, 42, 0.88), rgba(18, 33, 42, 0.08), rgba(18, 33, 42, 0.68));
}

.auth-brand,
.auth-copy {
  position: relative;
  z-index: 1;
}

.auth-copy h2 {
  max-width: 600px;
  margin: 6px 0 0;
  font-size: 2.15rem;
  line-height: 1.08;
}

.auth-panel {
  padding: 28px;
  display: grid;
  align-content: center;
  gap: 22px;
}

.auth-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  padding: 6px;
  border-radius: 8px;
  background: var(--wash);
  border: 1px solid var(--line);
}

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

.auth-tabs button.active {
  background: var(--panel);
  color: var(--ink);
  box-shadow: 0 8px 18px rgba(28, 46, 61, 0.08);
}

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

.auth-form h2 {
  margin: 0;
  font-size: 1.55rem;
}

.auth-form label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 800;
}

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

.form-grid label {
  display: grid;
  gap: 7px;
}

.toggle-row,
.checkbox-row {
  align-items: start;
  color: var(--ink);
  display: grid;
  font-size: 0.9rem;
  font-weight: 800;
  gap: 8px;
  grid-template-columns: auto 1fr;
  line-height: 1.35;
}

.toggle-row input,
.checkbox-row input {
  margin-top: 3px;
  width: auto;
}

.demo-credentials,
.auth-status,
.auth-help,
.section-copy {
  color: var(--muted);
  line-height: 1.45;
}

.demo-credentials {
  display: grid;
  gap: 8px;
  background: var(--wash);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
}

.demo-credentials p,
.auth-status,
.auth-help,
.section-copy {
  margin: 0;
}

.request-link {
  width: 100%;
}

.inline-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

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

.sidebar {
  display: none;
  background: #12212a;
  color: #f8fbfa;
  padding: 24px;
  flex-direction: column;
  gap: 24px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand,
.nav-item,
.panel-head,
.topbar,
.family-toolbar {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--teal), var(--coral));
  font-weight: 800;
  color: white;
}

.facility-heading {
  align-items: center;
  display: flex;
  gap: 14px;
}

.facility-header-logo {
  width: 120px;
  height: 64px;
  border-radius: 8px;
  object-fit: contain;
  background: white;
  border: 1px solid var(--line);
  padding: 6px;
}

.brand-mark.facility-header-logo {
  width: 64px;
  height: 64px;
  background: linear-gradient(135deg, var(--teal), var(--coral));
  border: 0;
  padding: 0;
}

.brand h1,
.brand p,
.account-card h2,
.account-card p {
  margin: 0;
}

.brand h1 {
  font-size: 1.25rem;
}

.brand p,
.account-card,
.sidebar .eyebrow {
  color: rgba(248, 251, 250, 0.72);
}

.nav-stack {
  display: grid;
  gap: 8px;
}

.nav-item {
  gap: 12px;
  border: 0;
  width: 100%;
  min-height: 48px;
  color: rgba(248, 251, 250, 0.8);
  background: transparent;
  border-radius: 8px;
  padding: 10px 12px;
  text-align: left;
}

.nav-item span:first-child {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, 0.08);
  font-size: 0.78rem;
  font-weight: 800;
}

.nav-item small {
  display: inline-grid;
  place-items: center;
  min-width: 22px;
  height: 22px;
  margin-left: 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  color: white;
  font-size: 0.74rem;
  font-weight: 900;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.account-card {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 16px;
  display: grid;
  gap: 12px;
}

.account-card h2 {
  color: white;
  font-size: 1rem;
}

.account-details {
  display: grid;
  gap: 2px;
}

.account-details strong {
  color: white;
}

.account-details span {
  color: rgba(248, 251, 250, 0.68);
  font-size: 0.84rem;
}

.account-card .ghost {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.18);
  color: white;
}

.workspace {
  padding: 24px;
  min-width: 0;
}

.topbar {
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 20px;
}

.topbar h2,
.family-toolbar h2,
.panel h3,
.resident-detail h3,
.security-layout h2 {
  margin: 0;
}

.topbar h2,
.family-toolbar h2,
.security-layout h2 {
  font-size: 1.8rem;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.session-chip {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 8px 12px;
  color: var(--muted);
  font-weight: 800;
}

.primary,
.ghost,
.icon-button {
  border: 1px solid transparent;
  border-radius: 8px;
  min-height: 40px;
  padding: 10px 14px;
  font-weight: 700;
}

.primary {
  background: var(--teal);
  color: white;
  box-shadow: 0 10px 20px rgba(25, 111, 115, 0.18);
}

.primary:hover {
  background: #115d60;
}

.message-alert-button {
  align-items: center;
  display: inline-flex;
  gap: 8px;
  justify-content: center;
  position: relative;
}

.message-alert-button.has-unread {
  box-shadow: 0 0 0 3px rgba(217, 103, 90, 0.18), 0 10px 20px rgba(25, 111, 115, 0.18);
}

.notification-badge {
  min-width: 22px;
  height: 22px;
  border-radius: 999px;
  background: #d9675a;
  color: white;
  display: inline-grid;
  font-size: 0.74rem;
  font-weight: 900;
  line-height: 1;
  place-items: center;
  padding: 0 6px;
}

.ghost {
  background: var(--panel);
  border-color: var(--line);
  color: var(--ink);
}

a.ghost,
a.primary {
  align-items: center;
  display: inline-flex;
  justify-content: center;
  text-decoration: none;
}

.ghost[aria-pressed="true"],
.ghost.active {
  background: #17212b;
  color: white;
}

.full {
  width: 100%;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.hero-panel {
  min-height: 220px;
  border-radius: 8px;
  overflow: hidden;
  position: relative;
  display: grid;
  align-items: end;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  background: #20303d;
}

.hero-panel img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hero-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(18, 33, 42, 0.82), rgba(18, 33, 42, 0.24), rgba(18, 33, 42, 0.04));
}

.hero-copy {
  position: relative;
  z-index: 1;
  max-width: 760px;
  color: white;
  padding: 28px;
}

.hero-copy h3 {
  margin: 4px 0 0;
  font-size: 2.2rem;
  line-height: 1.08;
  max-width: 720px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0;
  font-weight: 800;
}

.staff-grid,
.family-grid,
.security-layout,
.settings-layout,
.requests-layout,
.controls-grid {
  display: grid;
  gap: 16px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(28, 46, 61, 0.06);
}

.staff-grid {
  grid-template-columns: minmax(320px, 1fr);
  align-items: start;
}

#messagesView.view.active {
  display: grid;
  gap: 20px;
  grid-template-columns: minmax(460px, 1.15fr) minmax(320px, 0.85fr);
  align-items: start;
}

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

.panel-head {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

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

.resident-panel-actions input {
  min-width: 220px;
}

.resident-roster-card {
  display: grid;
  gap: 4px;
}

.panel-note {
  color: var(--muted);
  margin: 0;
  max-width: 560px;
}

.resident-directory-list {
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
}

.inbox-panel,
.shared-documents-panel {
  display: grid;
  gap: 14px;
}

.inbox-panel {
  background: linear-gradient(180deg, #ffffff 0%, #f6fbfa 100%);
  border-color: rgba(25, 111, 115, 0.3);
  box-shadow: inset 5px 0 0 var(--teal), 0 16px 34px rgba(28, 46, 61, 0.08);
}

.shared-documents-panel {
  background: linear-gradient(180deg, #fffefd 0%, #fff9f2 100%);
  border-color: rgba(197, 138, 37, 0.32);
  box-shadow: inset 5px 0 0 var(--gold), 0 16px 34px rgba(28, 46, 61, 0.08);
}

.inbox-panel > .panel-head,
.shared-documents-panel > .panel-head {
  border-radius: 8px;
  margin: 0 0 4px;
  padding: 14px;
}

.inbox-panel > .panel-head {
  background: #eaf6f4;
  border: 1px solid rgba(25, 111, 115, 0.18);
}

.shared-documents-panel > .panel-head {
  background: #fff0d8;
  border: 1px solid rgba(197, 138, 37, 0.24);
}

.inbox-panel > .panel-head .eyebrow,
.inbox-panel > .panel-head h3 {
  color: var(--teal);
}

.shared-documents-panel > .panel-head .eyebrow,
.shared-documents-panel > .panel-head h3 {
  color: #7d5416;
}

.shared-document-form {
  background: rgba(255, 255, 255, 0.76);
  border: 1px solid rgba(197, 138, 37, 0.18);
  border-radius: 8px;
  padding: 14px;
}

.add-resident-panel {
  display: grid;
  gap: 12px;
}

.add-resident-form {
  display: grid;
  gap: 12px;
}

.inline-access-panel {
  background: #f6faf9;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  margin-top: 4px;
  padding: 16px;
}

.inline-access-panel h4 {
  margin: 0;
}

.shared-document-form,
.shared-document-list {
  display: grid;
  gap: 10px;
}

.inbox-filter-bar {
  align-items: end;
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: 8px;
  grid-template-columns: minmax(220px, 320px) 1fr;
  margin: -2px 0 14px;
  padding-bottom: 14px;
}

.section-pill {
  background: #e7f1f0;
  border-radius: 999px;
  color: var(--teal);
  font-size: 0.72rem;
  font-weight: 800;
  padding: 4px 8px;
}

.shared-upload-label {
  justify-self: start;
}

.selected-file-summary {
  color: var(--muted);
  font-weight: 800;
}

.selected-file-row {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
}

.selected-file-row .ghost {
  width: auto;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
  color: var(--ink);
  padding: 10px 12px;
}

textarea {
  resize: vertical;
}

.resident-list,
.thread-list,
.audit-list,
.message-window {
  display: grid;
  gap: 10px;
}

.resident-card,
.thread-card,
.audit-item,
.chart-doc,
.message-bubble {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.resident-card {
  min-height: 78px;
  padding: 12px;
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.resident-card.active {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(25, 111, 115, 0.13);
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 900;
}

.avatar.teal {
  background: var(--teal);
}

.avatar.coral {
  background: var(--coral);
}

.avatar.plum {
  background: var(--plum);
}

.avatar.navy {
  background: var(--navy);
}

.resident-card strong,
.thread-card strong,
.resident-hero strong {
  display: block;
}

.resident-card small,
.thread-card small,
.resident-hero small,
.audit-item small,
.message-bubble small {
  color: var(--muted);
}

.pill {
  border-radius: 999px;
  padding: 4px 8px;
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
}

.pill.good {
  background: #dff0df;
  color: #2f6b37;
}

.pill.warn {
  background: #f9e9c8;
  color: #855700;
}

.pill.urgent {
  background: #ffe1dc;
  color: #9b3027;
}

.danger-text {
  color: #9b3027;
}

.danger-button {
  background: #9b3027;
  border: 1px solid #9b3027;
  border-radius: 8px;
  color: #fff;
  cursor: pointer;
  font-weight: 800;
  padding: 11px 14px;
}

.danger-button:hover {
  background: #7f261f;
}

.danger-button:disabled {
  background: #e5c2bd;
  border-color: #e5c2bd;
  cursor: not-allowed;
}

.resident-hero {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
}

.resident-hero .avatar {
  width: 64px;
  height: 64px;
  font-size: 1.2rem;
}

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

.resident-profile-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}

.resident-focus-grid {
  align-items: start;
  display: grid;
  gap: 16px;
  grid-template-columns: minmax(320px, 0.92fr) minmax(360px, 1.08fr);
  margin-bottom: 18px;
}

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

.detail-box {
  background: var(--wash);
  border-radius: 8px;
  padding: 12px;
}

.detail-box span {
  display: block;
  color: var(--muted);
  font-size: 0.78rem;
  margin-bottom: 4px;
}

.detail-box strong {
  font-size: 1rem;
}

.profile-section {
  border: 2px solid var(--line);
  border-radius: 8px;
  background: white;
  display: grid;
  gap: 12px;
  margin-bottom: 16px;
  padding: 16px;
  box-shadow: 0 12px 28px rgba(28, 46, 61, 0.07);
}

.resident-focus-grid .profile-section {
  margin-bottom: 0;
  min-height: 100%;
}

.resident-family-section {
  border-color: rgba(25, 111, 115, 0.32);
  box-shadow: inset 5px 0 0 var(--teal), 0 12px 28px rgba(28, 46, 61, 0.07);
}

.resident-message-section {
  border-color: rgba(25, 111, 115, 0.22);
  box-shadow: inset 5px 0 0 var(--teal), 0 12px 28px rgba(28, 46, 61, 0.07);
}

.resident-family-section > .panel-head,
.resident-message-section > .panel-head {
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.resident-family-section > .panel-head .eyebrow {
  color: var(--teal);
}

.resident-message-section > .panel-head .eyebrow {
  color: var(--teal);
}

.resident-family-section > .panel-head .pill {
  background: var(--teal-soft);
  color: var(--teal);
}

.resident-message-section > .panel-head .pill {
  background: var(--teal-soft);
  color: var(--teal);
}

.profile-contact-list,
.profile-contact-editor,
.resident-message-list {
  display: grid;
  gap: 10px;
}

.profile-contact-card,
.profile-contact-edit,
.resident-message-card,
.pending-profile-note {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 10px;
  padding: 12px;
}

.profile-contact-card,
.profile-contact-edit {
  background: #f8fcfb;
  border-color: #cfe3df;
}

.profile-contact-card.pending {
  background: #fffaf0;
}

.pending-profile-note {
  background: white;
}

.resident-message-card {
  align-items: start;
  background: #fffaf7;
  border-color: #f0d4c8;
  grid-template-columns: 1fr auto;
}

.resident-message-card > div,
.resident-message-card p {
  grid-column: 1 / -1;
}

.resident-message-card p {
  color: var(--ink);
  line-height: 1.45;
  margin: 0;
}

.resident-message-card button {
  grid-column: 2;
  justify-self: end;
}

.contact-card-head {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.profile-contact-card dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.profile-contact-card dt {
  color: var(--muted);
  font-size: 0.76rem;
}

.profile-contact-card dd {
  margin: 0;
  font-weight: 800;
}

.profile-contact-card p,
.pending-profile-note small {
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
}

.contact-actions {
  display: flex;
  justify-content: flex-end;
}

.profile-alert-options {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  padding-top: 10px;
}

.profile-form-section {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 10px;
  margin-top: 6px;
  padding-top: 12px;
}

.profile-form-section h4 {
  margin: 0;
}

.chart-section-grid,
.family-document-list {
  display: grid;
  gap: 12px;
}

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

.family-document-list {
  grid-template-columns: repeat(4, minmax(220px, 1fr));
}

.shared-family-section {
  grid-column: 1 / -1;
}

.chart-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--wash);
  display: grid;
  gap: 10px;
  padding: 12px;
}

.chart-section-head,
.chart-doc {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.chart-section h4,
.chart-section small,
.chart-doc strong,
.chart-doc small {
  display: block;
}

.chart-section h4 {
  margin: 0;
  font-size: 0.98rem;
}

.chart-section small,
.chart-doc small {
  color: var(--muted);
}

.chart-doc-list {
  display: grid;
  gap: 8px;
}

.chart-doc {
  background: white;
  padding: 10px;
}

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

.upload-label {
  cursor: pointer;
  overflow: hidden;
  position: relative;
}

.upload-label input {
  cursor: pointer;
  inset: 0;
  opacity: 0;
  position: absolute;
}

.empty-state.compact {
  padding: 10px;
}

.inbox-title,
.inbox-actions,
.thread-labels {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.inbox-actions {
  justify-content: flex-end;
}

.inbox-actions select {
  width: auto;
  min-width: 130px;
}

.inbox-unread-badge,
.unread-pill,
.viewed-pill {
  border-radius: 999px;
  display: inline-grid;
  font-size: 0.72rem;
  font-weight: 900;
  min-height: 22px;
  place-items: center;
}

.inbox-unread-badge {
  background: var(--coral-soft);
  color: #9b3027;
  padding: 3px 9px;
}

.unread-pill {
  background: #fff0d6;
  color: #855700;
  padding: 3px 8px;
}

.viewed-pill {
  background: #edf4f1;
  color: var(--muted);
  padding: 3px 8px;
}

.thread-card {
  padding: 12px;
  display: grid;
  gap: 8px;
}

.inbox-panel.attention {
  border-color: rgba(217, 103, 90, 0.65);
  box-shadow: 0 0 0 4px rgba(217, 103, 90, 0.12), var(--shadow);
}

.thread-card.unread {
  border-color: rgba(217, 103, 90, 0.55);
  box-shadow: inset 4px 0 0 var(--coral);
}

.thread-card button {
  justify-self: start;
}

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

.stacked-form,
.dialog-form,
.message-form {
  display: grid;
  gap: 10px;
}

.stacked-form label,
.dialog-form label,
.family-toolbar label {
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 700;
}

.family-toolbar {
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.testing-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid #e9c778;
  background: #fff7df;
  color: #6f4b00;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 16px;
}

.testing-banner span,
.dialog-note {
  color: var(--muted);
  line-height: 1.45;
}

.family-toolbar label {
  min-width: min(320px, 100%);
}

.family-grid {
  grid-template-columns: minmax(380px, 1.25fr) minmax(300px, 0.75fr);
  align-items: start;
}

.family-summary {
  grid-column: 1 / -1;
}

.family-message,
.family-documents {
  grid-column: 1 / -1;
}

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

.family-summary-banner {
  border-radius: 8px;
  background: linear-gradient(135deg, var(--teal-soft), #f6ead8);
  padding: 16px;
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 12px;
  align-items: center;
}

.text-alert-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 11px;
  padding: 14px;
}

.text-alert-card h4 {
  font-size: 1.05rem;
  margin: 0;
}

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

.text-alert-card .ghost {
  justify-self: start;
}

.family-contact-card {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 12px;
  padding: 14px;
}

.family-contact-card h4 {
  font-size: 1.05rem;
  margin: 0;
}

.family-contact-card p {
  color: var(--muted);
  line-height: 1.45;
  margin: 0;
}

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

.family-access-details {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.family-access-details summary {
  align-items: center;
  cursor: pointer;
  display: flex;
  gap: 12px;
  justify-content: space-between;
  list-style: none;
  padding: 14px;
}

.family-access-details summary::-webkit-details-marker {
  display: none;
}

.family-access-details summary::after {
  content: "+";
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--teal);
  display: grid;
  font-weight: 900;
  height: 28px;
  place-items: center;
  width: 28px;
}

.family-access-details[open] summary::after {
  content: "-";
}

.family-access-details summary span {
  color: var(--ink);
  font-weight: 900;
}

.family-access-details summary small {
  color: var(--muted);
}

.family-access-detail-grid {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  padding: 14px;
}

.password-prompt-card {
  align-items: center;
  background: #fff7e7;
  border: 1px solid #f0d49b;
  border-radius: 8px;
  display: grid;
  gap: 12px;
  grid-template-columns: 1fr auto;
  padding: 14px;
}

.password-prompt-card.quiet {
  background: #f6faf9;
  border-color: var(--line);
}

.password-prompt-card h4 {
  font-size: 1.05rem;
  margin: 0;
}

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

.contact-summary-list {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin: 0;
}

.contact-summary-list dt {
  color: var(--muted);
  font-size: 0.76rem;
}

.contact-summary-list dd {
  font-weight: 800;
  margin: 0;
  overflow-wrap: anywhere;
}

.audit-item p,
.message-bubble p,
.controls-grid p {
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.message-bubble .message-text {
  color: var(--ink);
  font-size: 1rem;
  line-height: 1.5;
  margin-top: 8px;
}

.message-window {
  max-height: 390px;
  overflow: auto;
  padding-right: 4px;
}

.compact-message-window {
  max-height: 260px;
}

.full-message-window {
  max-height: 62vh;
}

.message-bubble {
  padding: 12px;
  max-width: 88%;
}

.message-header {
  align-items: baseline;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
}

.message-author {
  color: var(--teal);
  font-weight: 800;
}

.message-author.inline {
  margin-right: 6px;
}

.message-detail {
  color: var(--muted);
}

.message-bubble.family {
  justify-self: end;
  background: #eff7f6;
  border-color: #beddd9;
}

.message-bubble.staff {
  justify-self: start;
}

.security-layout {
  grid-template-columns: 1.3fr 0.8fr;
  align-items: start;
}

.settings-layout {
  grid-template-columns: minmax(360px, 0.9fr) minmax(320px, 1.1fr);
  align-items: start;
}

.requests-layout {
  grid-template-columns: minmax(360px, 1.1fr) minmax(320px, 0.9fr);
  align-items: start;
}

.wide {
  grid-column: 1 / -1;
}

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

.controls-grid > div {
  background: var(--wash);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.controls-grid h3 {
  margin: 0;
  font-size: 1rem;
}

.audit-item {
  padding: 12px;
}

.field-map {
  display: grid;
  gap: 10px;
}

.settings-form,
.section-editor-list,
.section-summary-list {
  display: grid;
  gap: 10px;
}

.inline-form-row,
.section-editor-row {
  align-items: center;
  display: grid;
  gap: 8px;
}

.inline-form-row {
  grid-template-columns: minmax(0, 1fr) auto;
}

.logo-preview-card {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--wash);
  display: grid;
  gap: 12px;
  grid-template-columns: auto 1fr;
  padding: 12px;
}

.logo-preview-card strong,
.logo-preview-card small {
  display: block;
}

.logo-preview-card small {
  color: var(--muted);
  margin-top: 3px;
}

.logo-preview-mark {
  overflow: hidden;
}

.logo-preview-mark.has-image {
  background: white;
  border: 1px solid var(--line);
}

.logo-preview-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.logo-upload-label {
  justify-self: start;
}

.section-editor-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--wash);
  grid-template-columns: minmax(0, 1fr) auto auto;
  padding: 10px;
}

.section-summary-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--wash);
}

.section-summary-card {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
}

.section-summary-card small {
  color: var(--muted);
  font-weight: 800;
}

.sort-control {
  align-items: center;
  color: var(--muted);
  display: flex;
  font-size: 0.78rem;
  font-weight: 900;
  gap: 8px;
  justify-content: flex-end;
}

.sort-control select {
  min-width: 150px;
  width: auto;
}

.request-list,
.approved-list {
  display: grid;
  gap: 10px;
}

.request-card,
.approved-card,
.empty-state {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
  padding: 12px;
}

.request-card {
  display: grid;
  gap: 10px;
}

.approved-card {
  align-items: center;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.approved-card > div {
  display: grid;
  gap: 4px;
}

.request-card dl {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 0;
}

.request-card dt,
.approved-card small,
.empty-state,
.auth-status {
  color: var(--muted);
}

.request-card dd {
  margin: 0;
  font-weight: 800;
}

.request-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.field-map div {
  border: 1px solid var(--line);
  background: var(--wash);
  border-radius: 8px;
  padding: 12px;
}

.field-map span {
  display: block;
  color: var(--muted);
  font-size: 0.8rem;
}

.field-map strong {
  display: block;
  margin-top: 4px;
}

dialog {
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: var(--shadow);
  width: min(560px, calc(100vw - 32px));
}

#threadDialog,
#documentPreviewDialog,
#residentProfileDialog {
  width: min(680px, calc(100vw - 32px));
}

#documentPreviewDialog {
  width: min(920px, calc(100vw - 32px));
}

#residentProfileDialog {
  width: min(820px, calc(100vw - 32px));
}

dialog::backdrop {
  background: rgba(18, 33, 42, 0.5);
}

.dialog-form {
  padding: 18px;
}

.thread-reader {
  width: min(680px, calc(100vw - 32px));
}

.thread-reader-window {
  max-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--wash);
  padding: 10px;
}

.document-preview-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.document-preview-stage {
  height: min(72vh, 720px);
  min-height: 420px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef4f2;
  display: grid;
  place-items: center;
  overflow: auto;
  padding: 16px;
}

.document-preview-content {
  --preview-rotation: 0deg;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  transform: rotate(var(--preview-rotation));
  transform-origin: center;
  transition: transform 160ms ease;
}

.document-preview-stage.fit-page {
  overflow: hidden;
}

.document-preview-stage.rotated {
  overflow: auto;
}

.document-preview-stage.fit-width {
  align-items: start;
  overflow: auto;
}

.document-preview-stage img,
.document-preview-stage iframe {
  border: 0;
  border-radius: 8px;
  background: white;
  box-shadow: 0 8px 22px rgba(28, 46, 61, 0.12);
}

.document-preview-stage.fit-page img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.document-preview-stage.fit-width img {
  width: 100%;
  height: auto;
  max-width: 100%;
}

.document-preview-stage iframe {
  width: 100%;
  height: 100%;
  min-height: 640px;
}

.document-preview-stage.fit-width iframe {
  min-height: 86vh;
}

.dialog-note {
  margin: -4px 0 4px;
}

.recipient-mode {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 8px;
  margin: 0;
  padding: 12px;
}

.recipient-mode legend {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  padding: 0 6px;
}

.recipient-mode label,
.recipient-option {
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--wash);
  display: grid;
  gap: 10px;
  grid-template-columns: auto 1fr;
  padding: 10px;
}

.recipient-picker {
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  gap: 8px;
  max-height: 230px;
  overflow: auto;
  padding: 8px;
}

.recipient-picker.disabled {
  background: #fbfdfc;
}

.section-recipient-control {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
  padding: 10px;
}

.recipient-option {
  background: #fff;
}

.recipient-option.disabled {
  opacity: 0.56;
}

.recipient-option strong,
.recipient-option small {
  display: block;
}

.recipient-option strong {
  color: var(--ink);
}

.recipient-option small,
.recipient-summary {
  color: var(--muted);
}

.recipient-summary {
  font-size: 0.86rem;
  font-weight: 800;
  margin: -2px 0 2px;
}

.icon-button {
  width: 38px;
  height: 38px;
  padding: 0;
  background: var(--wash);
  border-color: var(--line);
}

menu {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 0;
  margin: 8px 0 0;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #17212b;
  color: white;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  max-width: min(420px, calc(100vw - 36px));
  z-index: 4;
}

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

.family-session .admin-only {
  display: none !important;
}

.family-session .admin-preview-only {
  display: none !important;
}

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

  .sidebar {
    position: static;
    height: auto;
    flex-direction: row;
    align-items: stretch;
    flex-wrap: wrap;
  }

  .brand {
    min-width: 240px;
  }

  .nav-stack {
    grid-template-columns: repeat(3, minmax(150px, 1fr));
    flex: 1;
  }

  .auth-layout,
  .staff-grid,
  .family-grid,
  .security-layout,
  .settings-layout,
  .requests-layout,
  #messagesView.view.active {
    grid-template-columns: 1fr 1fr;
  }

  .auth-layout {
    min-height: auto;
  }

  .auth-art {
    min-height: 360px;
  }

  .resident-detail,
  .wide {
    grid-column: 1 / -1;
  }

  .controls-grid,
  .resident-profile-grid,
  .family-document-list,
  .family-access-detail-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 980px) {
  #messagesView.view.active {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .auth-screen {
    padding: 0;
  }

  .auth-layout {
    min-height: 100vh;
    border-radius: 0;
  }

  .auth-art {
    min-height: 260px;
    padding: 20px;
  }

  .auth-copy h2 {
    font-size: 1.45rem;
  }

  .auth-panel {
    padding: 20px;
  }

  .workspace,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .family-toolbar,
  .testing-banner {
    align-items: stretch;
    flex-direction: column;
  }

  .facility-heading {
    align-items: flex-start;
  }

  .facility-header-logo {
    width: min(140px, 45vw);
  }

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

  .top-actions button {
    flex: 1;
  }

  .inbox-actions,
  .inbox-actions select,
  .inbox-actions button {
    width: 100%;
  }

  .document-preview-controls button {
    flex: 1;
  }

  .document-preview-stage {
    height: 65vh;
    min-height: 340px;
    padding: 8px;
  }

  .session-chip {
    width: 100%;
    justify-content: center;
  }

  .auth-layout,
  .form-grid,
  .nav-stack,
  .staff-grid,
  .family-grid,
  .security-layout,
  .settings-layout,
  .requests-layout,
  .resident-profile-grid,
  .resident-focus-grid,
  .chart-section-grid,
  .family-document-list,
  .family-access-detail-grid,
  .controls-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .resident-detail,
  .wide {
    grid-column: auto;
  }

  .hero-panel {
    min-height: 260px;
  }

  .hero-panel::after {
    background: linear-gradient(0deg, rgba(18, 33, 42, 0.86), rgba(18, 33, 42, 0.24));
  }

  .hero-copy {
    padding: 20px;
  }

  .hero-copy h3 {
    font-size: 1.35rem;
  }

  .topbar h2,
  .family-toolbar h2,
  .security-layout h2 {
    font-size: 1.45rem;
  }

  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .resident-hero {
    grid-template-columns: 64px 1fr;
  }

  .resident-hero-actions {
    grid-column: 1 / -1;
    width: 100%;
  }

  .resident-hero-actions button {
    flex: 1;
  }

  .resident-card {
    grid-template-columns: 44px 1fr;
  }

  .resident-card .pill {
    grid-column: 1 / -1;
    text-align: left;
  }
}
