:root {
  --paper: #FAF6EE;
  --paper-warm: #F5EFE2;
  --surface: #FFFFFF;
  --ink: #2A2520;
  --ink-soft: #4A4138;
  --muted: #7A7268;
  --line: #E8E0D2;
  --ok: #6B8E5A;
  --attention: #C8923A;
  --attention-bg: #FBF3DF;
  --shadow: 0 2px 12px rgba(60, 45, 25, 0.06);
  --radius: 14px;
  --radius-sm: 8px;
  --serif: 'Fraunces', 'Iowan Old Style', 'Palatino', Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

body {
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
}

h1, h2, h3 {
  font-family: var(--serif);
  font-weight: 500;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0;
}

h1 { font-size: 1.75rem; line-height: 1.2; }
h2 { font-size: 1.25rem; line-height: 1.3; margin-bottom: 0.75rem; }
h3 { font-size: 1.05rem; line-height: 1.35; }

p { margin: 0 0 0.75rem; }
p:last-child { margin-bottom: 0; }

a {
  color: var(--ok);
  text-decoration: underline;
  text-decoration-color: rgba(107, 142, 90, 0.4);
  text-underline-offset: 2px;
}
a:hover { text-decoration-color: var(--ok); }

button {
  font: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------- Loading ---------- */

.loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: var(--paper);
  z-index: 100;
}
.loading-leaf {
  font-size: 2rem;
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 0.4; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.1); }
}

/* ---------- Lock screen ---------- */

.lock-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
  background: linear-gradient(180deg, var(--paper) 0%, var(--paper-warm) 100%);
}

.lock-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
  text-align: center;
}

.lock-leaf {
  font-size: 2.5rem;
  margin-bottom: 1rem;
}

.lock-card h1 {
  margin-bottom: 0.5rem;
}

.lock-card p {
  color: var(--muted);
  margin-bottom: 1.5rem;
}

#lock-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#lock-form input {
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  font-size: 1rem;
  text-align: center;
}
#lock-form input:focus {
  outline: 2px solid var(--ok);
  outline-offset: 1px;
  border-color: transparent;
}

#lock-form button[type="submit"] {
  padding: 0.85rem 1rem;
  background: var(--ok);
  color: white;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: background 0.15s ease;
}
#lock-form button[type="submit"]:hover { background: #5d7e4f; }
#lock-form button[type="submit"]:disabled {
  opacity: 0.5;
  cursor: wait;
}

.lock-error {
  margin-top: 1rem;
  color: #B44A3D;
  font-size: 0.95rem;
}

.lock-lang {
  margin-top: 1.5rem;
  color: var(--muted);
  font-size: 0.9rem;
}
.lock-lang button {
  color: var(--muted);
  text-decoration: underline;
  text-decoration-color: transparent;
  min-width: 44px;
  min-height: 36px;
  padding: 0.5rem 0.75rem;
  transition: color 0.15s ease;
}
.lock-lang button.active {
  color: var(--ink);
  text-decoration-color: var(--ink);
}

/* ---------- App layout ---------- */

.app {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem 1rem 4rem;
}

.app-header {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 1rem;
  padding: 1.5rem 0.5rem 1.5rem;
}

.patient {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.85rem;
}

.patient-photo {
  width: 144px;
  height: 144px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--paper-warm);
  flex-shrink: 0;
  box-shadow: 0 4px 24px rgba(60, 45, 25, 0.12);
}

.patient-info h1 {
  font-size: 1.75rem;
  letter-spacing: -0.015em;
}
.patient-info p {
  color: var(--muted);
  font-size: 0.95rem;
  margin: 0.25rem 0 0;
}

.lang-toggle {
  position: absolute;
  top: 0.5rem;
  right: 0.5rem;
  display: flex;
  align-items: center;
  gap: 0.2rem;
  color: var(--muted);
  font-size: 0.85rem;
  background: var(--surface);
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  box-shadow: var(--shadow);
}
.lang-toggle button {
  color: var(--muted);
  min-width: 44px;
  min-height: 36px;
  padding: 0.4rem 0.55rem;
  border-radius: 6px;
  transition: color 0.15s ease, background 0.15s ease;
}
.lang-toggle button.active {
  color: var(--ink);
  background: var(--paper-warm);
}

/* ---------- Cards ---------- */

.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}

/* ---------- Timeline ---------- */

.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}

.timeline-event {
  position: relative;
  padding-left: 1.5rem;
  padding-bottom: 1.25rem;
  border-left: 2px solid var(--line);
  margin-left: 0.5rem;
}
.timeline-event:last-child { padding-bottom: 0; }
.timeline-event::before {
  content: '';
  position: absolute;
  left: -7px;
  top: 0.4rem;
  width: 12px;
  height: 12px;
  background: var(--ok);
  border-radius: 50%;
  border: 2px solid var(--surface);
}
.timeline-event.attention::before { background: var(--attention); }

.timeline-event time {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.15rem;
  letter-spacing: 0.01em;
}
.timeline-event h3 {
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  color: var(--ink);
}
.timeline-event p {
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.timeline-bullets {
  list-style: none;
  margin: 0.25rem 0 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}
.timeline-bullets li {
  position: relative;
  padding-left: 1rem;
  color: var(--ink-soft);
  font-size: 0.93rem;
  line-height: 1.4;
}
.timeline-bullets li::before {
  content: '';
  position: absolute;
  left: 0.1rem;
  top: 0.55em;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ok);
}
.timeline-event.attention .timeline-bullets li::before {
  background: var(--attention);
}

.timeline-photo {
  width: 100%;
  max-width: 280px;
  margin-top: 0.75rem;
  border-radius: var(--radius-sm);
  display: block;
  background: var(--paper-warm);
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

/* ---------- Tabs ---------- */

.tabs {
  display: flex;
  gap: 0.25rem;
  margin-bottom: 1rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  padding: 0.25rem;
  background: var(--paper-warm);
  border-radius: var(--radius);
}
.tabs::-webkit-scrollbar { display: none; }

.tabs button {
  flex: 1;
  padding: 0.65rem 1rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.95rem;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease;
}
.tabs button.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(60, 45, 25, 0.06);
}

/* ---------- Problems ---------- */

.problem {
  padding: 0.85rem 1rem;
  background: var(--paper);
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
  border-left: 3px solid var(--ok);
}
.problem.attention {
  background: var(--attention-bg);
  border-left-color: var(--attention);
}
.problem h3 {
  font-family: var(--sans);
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}
.problem p {
  color: var(--ink-soft);
  font-size: 0.95rem;
}
.problem:last-child { margin-bottom: 0; }

/* ---------- Vitals ---------- */

.vitals-group { margin-bottom: 1rem; }
.vitals-group:last-child { margin-bottom: 0; }
.vitals-group time {
  display: block;
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 0.5rem;
}
.vitals-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
}
.vital {
  padding: 0.65rem 0.85rem;
  background: var(--paper);
  border-radius: var(--radius-sm);
}
.vital-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.15rem;
}
.vital-value {
  font-family: var(--serif);
  font-size: 1.15rem;
  color: var(--ink);
}

/* ---------- Photos ---------- */

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.5rem;
}
.photo-grid figure {
  margin: 0;
}
.photo-grid img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: var(--radius-sm);
  background: var(--paper-warm);
  display: block;
}
.photo-grid figcaption {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.25rem;
  line-height: 1.3;
}

/* ---------- Hospital ---------- */

.hospital-info dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 0.5rem 1rem;
  margin: 0;
}
.hospital-info dt {
  color: var(--muted);
  font-size: 0.9rem;
}
.hospital-info dd {
  margin: 0;
  color: var(--ink);
}

/* ---------- Messages ---------- */

.messages-section h2 {
  font-family: var(--serif);
}
.messages-intro {
  color: var(--muted);
  margin-bottom: 1rem;
}

.message-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}
.message-form label {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.25rem;
}
.message-form input,
.message-form textarea {
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  font-size: 1rem;
  font-family: var(--sans);
  resize: vertical;
}
.message-form input:focus,
.message-form textarea:focus {
  outline: 2px solid var(--ok);
  outline-offset: 1px;
  border-color: transparent;
}
.message-form button[type="submit"] {
  align-self: flex-start;
  padding: 0.75rem 1.5rem;
  background: var(--ok);
  color: white;
  border-radius: var(--radius-sm);
  font-weight: 500;
  margin-top: 0.5rem;
  transition: background 0.15s ease;
}
.message-form button[type="submit"]:hover { background: #5d7e4f; }
.message-form button[type="submit"]:disabled {
  opacity: 0.5;
  cursor: wait;
}

.form-status {
  font-size: 0.9rem;
  color: var(--muted);
  margin: 0.25rem 0 0;
  min-height: 1.2em;
}
.form-status.error { color: #B44A3D; }
.form-status.success { color: var(--ok); }

.message-feed {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.message {
  padding: 0.85rem 1rem;
  background: var(--paper);
  border-radius: var(--radius-sm);
  border-left: 3px solid var(--paper-warm);
}
.message-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 0.85rem;
  margin-bottom: 0.35rem;
  gap: 0.5rem;
}
.message-author {
  font-weight: 500;
  color: var(--ink);
}
.message-date {
  color: var(--muted);
  font-size: 0.8rem;
  white-space: nowrap;
}
.message-body {
  color: var(--ink-soft);
  white-space: pre-wrap;
  word-wrap: break-word;
}

.message-feed-empty {
  color: var(--muted);
  font-style: italic;
  text-align: center;
  padding: 1rem;
}

/* ---------- Footer ---------- */

.app-footer {
  margin-top: 2rem;
  padding: 1rem 0.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}
.app-footer .disclaimer {
  font-size: 0.8rem;
  margin-top: 0.5rem;
  opacity: 0.8;
}

/* ---------- Responsive ---------- */

/* Small screens — most family will read on a phone */
@media (max-width: 480px) {
  body { font-size: 16px; }
  h1 { font-size: 1.5rem; }
  h2 { font-size: 1.15rem; }
  .app { padding: 0.75rem 0.75rem 3rem; }
  .app-header {
    padding: 1.25rem 0.5rem 1.25rem;
  }
  .patient-photo { width: 120px; height: 120px; }
  .patient-info h1 { font-size: 1.5rem; }
  .patient-info p { font-size: 0.9rem; }
  .lang-toggle {
    font-size: 0.78rem;
    top: 0.4rem;
    right: 0.4rem;
    padding: 0.2rem 0.4rem;
  }
  .card {
    padding: 1rem 1rem;
    margin-bottom: 0.75rem;
    border-radius: 12px;
  }
  .timeline-event {
    padding-left: 1.25rem;
    padding-bottom: 1rem;
  }
  .timeline-event h3 { font-size: 0.98rem; }
  .timeline-bullets li { font-size: 0.9rem; }
  .timeline-photo { max-width: 220px; }
  .tabs {
    margin: 0 -0.25rem 0.75rem;
    padding: 0.2rem;
  }
  .tabs button {
    padding: 0.55rem 0.75rem;
    font-size: 0.9rem;
  }
  .messages-section h2 { font-size: 1.2rem; }
  .messages-intro { font-size: 0.92rem; }
  .message-form input,
  .message-form textarea { font-size: 16px; } /* prevent iOS zoom on focus */
  .message {
    padding: 0.75rem 0.85rem;
  }
  .photo-grid {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.4rem;
  }
  .vitals-list {
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  }
}

/* Larger screens */
@media (min-width: 720px) {
  .app { padding: 2rem 1.5rem 4rem; }
  .app-header { padding: 2rem 0.5rem 2rem; }
  .patient-info h1 { font-size: 2rem; }
  .patient-photo { width: 168px; height: 168px; }
  .card { padding: 1.5rem 1.75rem; }
  body { font-size: 17px; }
  .timeline-photo { max-width: 320px; }
}

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