:root {
  --bg: #f5f1ea;
  --panel: #fffdf9;
  --line: #d9cec0;
  --ink: #1d2b2b;
  --muted: #4f5a56;
  --accent: #116466;
  --accent-soft: #d8f0ed;
  --warn: #a85f2e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", sans-serif;
  font-size: 1.0625rem;
  background:
    radial-gradient(circle at top right, rgba(17, 100, 102, 0.14), transparent 24%),
    linear-gradient(180deg, #fbf9f4, var(--bg));
  color: var(--ink);
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1.5rem 2rem;
  border-bottom: 1px solid var(--line);
}

.eyebrow {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.82rem;
  color: var(--accent);
}

.subtitle {
  margin: 0.4rem 0 0;
  color: var(--muted);
}

.shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: calc(100vh - 90px);
}

aside {
  border-right: 1px solid var(--line);
  padding: 1rem;
  background: rgba(255, 253, 249, 0.78);
}

aside nav {
  display: grid;
  gap: 0.5rem;
}

/* Accessibility (50+ users): slightly larger nav text and guaranteed 44px
   touch targets for every nav button. */
aside nav button {
  font-size: 1.05rem;
  min-height: 44px;
  text-align: left;
}

aside button,
.inline-actions button,
button {
  padding: 0.72rem 0.95rem;
  min-height: 44px;
  border-radius: 12px;
  border: 0;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font: inherit;
}

aside button.secondary,
button.secondary {
  background: var(--accent-soft);
  color: var(--accent);
}

aside nav button.active {
  background: var(--accent);
  color: #ffffff;
  font-weight: 700;
  box-shadow: inset 5px 0 0 rgba(0, 0, 0, 0.38);
  outline: 2px solid rgba(0, 0, 0, 0.25);
  outline-offset: -2px;
}

/* Strengthen the "you are here" nav marker on small phones (360–414px) so the
   active section is unmistakable in the stacked mobile nav. CSS-only. */
@media (max-width: 480px) {
  aside nav button.active {
    box-shadow: inset 6px 0 0 rgba(255, 255, 255, 0.9);
  }
}

/* Quick View disclaimer callout: more visible than a plain field hint. */
.quickview-disclaimer {
  margin: 0 0 0.75rem;
  padding: 0.7rem 0.9rem;
  border-radius: 12px;
  background: var(--accent-soft);
  border-left: 4px solid var(--accent);
  color: #1f2937;
  font-size: 0.9rem;
  font-weight: 600;
}

.field-label {
  margin: 0.4rem 0 0;
  font-weight: 600;
}

.otp-mode-banner {
  margin: 0 0 0.75rem;
  padding: 0.6rem 0.8rem;
  border-radius: 12px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  font-weight: 600;
}

.internal-pilot-banner {
  margin: 0;
  padding: 0.7rem 1rem;
  background: #7a3b00;
  color: #fff;
  font-weight: 600;
  text-align: center;
  border-bottom: 2px solid #ffb454;
}

.contact-primary {
  border: 1.5px solid var(--accent);
  background: var(--accent-soft);
}

main {
  padding: 1rem;
  display: grid;
  gap: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 1rem;
  box-shadow: 0 10px 25px rgba(29, 43, 43, 0.06);
}

.section-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1rem;
}

.stack {
  display: grid;
  gap: 0.65rem;
}

input,
select,
textarea {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 0.72rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  font: inherit;
}

/* iOS Safari: an unstyled empty type="time" control can render as a large
   blank grey block with invisible text. Normalize its appearance so the value
   (or a standard empty state) is visible, keep a practical touch target, and
   left-align like the other inputs. */
input[type="time"] {
  -webkit-appearance: none;
  appearance: none;
  background-color: #fff;
  color: inherit;
  min-height: 44px;
  text-align: left;
}
input[type="time"]::-webkit-date-and-time-value {
  text-align: left;
}

textarea {
  min-height: 88px;
}

.result,
.cards {
  display: grid;
  gap: 0.75rem;
}

.card {
  padding: 0.85rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  display: grid;
  gap: 0.25rem;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.quick-actions .quick-action {
  width: auto;
  flex: 1 1 auto;
  min-width: 160px;
  font-weight: 600;
}

.card-today {
  padding: 0.85rem;
  border-radius: 14px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  display: grid;
  gap: 0.25rem;
}

.card-today strong {
  color: var(--accent);
}

.contact-actions {
  margin-top: 0.35rem;
}

.call-now {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 0.9rem;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
}

.call-now:hover {
  filter: brightness(0.95);
}

.kv {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 0.5rem;
}

.token {
  font-family: Consolas, monospace;
  word-break: break-all;
  color: var(--warn);
}

.hidden {
  display: none;
}

button.link {
  background: none;
  border: none;
  color: var(--accent, #1d4ed8);
  padding: 0;
  min-height: 0;
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  width: auto;
}

.record-actions {
  margin-top: 0.4rem;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

button.link.danger {
  color: var(--danger, #b00020);
}

.viewer-actions {
  margin: 0.75rem 0;
}

.danger-button {
  background: var(--danger, #b00020);
  color: #fff;
  border: none;
}

.viewer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}

.viewer-overlay.hidden {
  display: none;
}

/* Secure-default guard: the Home Screen helper must never occupy layout or
   become visible pre-login through any later, more specific display rule. */
#a2hs-card.hidden,
#a2hs-collapsed.hidden,
#a2hs-guide.hidden {
  display: none !important;
}

.viewer-dialog {
  background: #fff;
  border-radius: 14px;
  width: min(900px, 100%);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.viewer-body {
  padding: 1rem;
  overflow: auto;
  display: grid;
  gap: 0.75rem;
}

.viewer-body img,
.viewer-body iframe {
  max-width: 100%;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
}

.viewer-body iframe {
  height: 70vh;
}

.viewer-meta {
  display: grid;
  gap: 0.25rem;
  margin-bottom: 0.85rem;
}

.viewer-meta p {
  margin: 0;
}

.upload-notes-label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

/* Notes are optional, secondary metadata — keep them visually compact so the
   upload action and the records search stay the dominant elements. */
textarea.notes-compact {
  min-height: 80px;
}

.viewer-file {
  display: grid;
  gap: 0.4rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.75rem;
}

.viewer-file-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.dup-dialog {
  width: min(440px, 100%);
}

.dup-body {
  padding: 1rem;
}

.dup-body p {
  margin: 0;
  line-height: 1.5;
}

.dup-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
  padding: 0.85rem 1rem;
  border-top: 1px solid var(--line);
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

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

  aside {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

.timeline-day {
  margin-bottom: 1.25rem;
}

.timeline-day h3 {
  margin: 0 0 0.25rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.25rem;
}

/* Accessibility (50+ users): headings explicitly larger than body text. */
.panel h2 {
  font-size: 1.35rem;
}

.panel h3 {
  font-size: 1.15rem;
}

/* "Sắp ra mắt" badge for future-scope placeholders (Family, Community). */
.coming-soon-badge {
  display: inline-block;
  vertical-align: middle;
  margin-left: 0.4rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--accent-soft);
  color: var(--accent);
  border: 1px solid var(--accent);
  white-space: nowrap;
}

/* Family Connect informational card (Gia đình & SOS) — read-only placeholder. */
.family-placeholder-card {
  margin-top: 1rem;
  padding: 0.85rem;
  border-radius: 14px;
  border: 1px dashed var(--line);
  background: #fff;
}

.family-placeholder-card p {
  margin: 0.35rem 0 0;
}

.timeline-facility {
  margin: 0.5rem 0 0.75rem;
}

.timeline-facility h4 {
  margin: 0 0 0.4rem;
  opacity: 0.85;
}

/* Patient-saved external appointment reminder note on the timeline. */
.timeline-appointment-note {
  padding: 0.6rem 0.85rem;
  border-radius: 14px;
  border: 1px dashed var(--line);
  background: #fff;
  margin: 0.5rem 0 0.75rem;
}

/* "Did you book?" nudge after opening an external booking channel. */
.booking-prompt {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 60;
  max-width: 480px;
  margin: 0 auto;
  padding: 1rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.18);
}

.booking-prompt p {
  margin: 0.5rem 0 0.75rem;
}

.booking-prompt-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.booking-prompt-actions button {
  width: auto;
}

.home-greeting strong {
  font-size: 1.15rem;
}

.app-footer {
  grid-column: 1 / -1;
  border-top: 1px solid var(--line);
  padding: 1rem 1.5rem;
  text-align: center;
  color: var(--muted, #6b7280);
  font-size: 0.85rem;
}

.app-footer p {
  margin: 0.15rem 0;
}

.upload-inputs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

.file-input {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  cursor: pointer;
}

.file-input input[type="file"] {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.file-input .file-button {
  display: inline-block;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--line);
  border-radius: 0.5rem;
  background: var(--surface, #f3f4f6);
  font-size: 0.9rem;
  white-space: nowrap;
}

.file-input .file-name {
  color: var(--muted, #6b7280);
  font-size: 0.9rem;
  word-break: break-all;
}

.app-footer .footer-logo {
  display: block;
  margin: 0 auto 0.6rem;
  height: 56px;
  width: auto;
  border-radius: 8px;
}

.field-hint {
  margin: -0.2rem 0 0.2rem;
  color: var(--muted, #6b7280);
  font-size: 0.85rem;
  line-height: 1.35;
}

.auth-value-intro {
  margin: 0 0 0.6rem;
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--text, #1f2933);
  line-height: 1.4;
}

/* "Mở nhanh từ màn hình chính" helper card */
.a2hs-card {
  margin: 0 0 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--accent-soft, #d8f0ed);
  border-radius: 12px;
  background: var(--accent-soft, #d8f0ed);
}
.a2hs-title {
  margin: 0 0 0.3rem;
  font-weight: 700;
  color: var(--accent, #116466);
}
.a2hs-text {
  margin: 0 0 0.6rem;
  font-size: 0.95rem;
  line-height: 1.45;
}
.a2hs-instructions {
  margin: 0 0 0.6rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--accent, #116466);
}
.a2hs-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.a2hs-card button,
.a2hs-collapsed button {
  min-height: 44px;
}
.a2hs-guide {
  margin: 0 0 0.6rem;
  padding: 0.7rem 0.8rem;
  border: 1px solid var(--accent, #116466);
  border-radius: 10px;
  background: #fff;
}
.a2hs-guide:focus {
  outline: 3px solid var(--accent, #116466);
  outline-offset: 2px;
}
.a2hs-guide .a2hs-actions {
  margin-top: 0.2rem;
}
.a2hs-guide-note {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  font-weight: 600;
}
.a2hs-steps {
  margin: 0 0 0.6rem;
  padding-left: 1.2rem;
  font-size: 0.95rem;
  line-height: 1.5;
}
.a2hs-steps li {
  margin-bottom: 0.3rem;
}
.a2hs-share-icon {
  vertical-align: -0.35em;
  margin: 0 0.15rem;
  color: var(--accent, #116466);
}
.a2hs-step-warning {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.88rem;
  font-weight: 600;
  color: #8a4b08;
}
.app-share-clarify {
  margin: 0.3rem 0 0.5rem;
  font-size: 0.88rem;
  color: #555;
}
.a2hs-confirm {
  margin: 0 0 0.4rem;
  font-size: 0.9rem;
  color: var(--accent, #116466);
  font-weight: 600;
  line-height: 1.45;
}
.a2hs-copy-result {
  margin: 0.5rem 0 0;
  font-size: 0.9rem;
  color: var(--accent, #116466);
  word-break: break-all;
}

/* Collapsed recovery entry after "Để sau" */
.a2hs-collapsed {
  margin: 0 0 1rem;
  padding: 0.6rem 0.9rem;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
  flex-wrap: wrap;
}
.a2hs-collapsed-title {
  margin: 0;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--accent, #116466);
}
.a2hs-collapsed-text {
  margin: 0.15rem 0 0;
  font-size: 0.85rem;
  color: var(--muted, #4f5a56);
}

/* "Chia sẻ ứng dụng này với người thân" card (public app link only) */
.app-share-card {
  margin-top: 1.2rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line, #e2e8f0);
  border-radius: 12px;
  background: #fff;
}
.app-share-text {
  margin: 0 0 0.35rem;
  font-size: 0.95rem;
  line-height: 1.45;
}
.app-share-safety {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  color: var(--muted, #4f5a56);
  line-height: 1.4;
}

.time-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.1rem 0 0.4rem;
}

.time-chips:empty {
  display: none;
}

.time-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.5rem 0.25rem 0.65rem;
  border-radius: 999px;
  background: var(--accent-soft, #e0f2fe);
  color: var(--accent-strong, #075985);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}

.time-chip button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  padding: 0;
  border: none;
  border-radius: 999px;
  background: rgba(7, 89, 133, 0.15);
  color: inherit;
  font-size: 0.95rem;
  line-height: 1;
  cursor: pointer;
}

.time-chip button:hover {
  background: rgba(7, 89, 133, 0.3);
}

.record-search {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin: 0 0 0.5rem;
  flex-wrap: wrap;
}

/* The records search is the primary way patients find documents — give it
   clear visual weight (accent border, roomier padding, slightly larger text). */
.record-search input[type="search"] {
  flex: 1 1 240px;
  min-width: 0;
  padding: 0.85rem 1rem;
  font-size: 1.05rem;
  border: 2px solid var(--accent);
  border-radius: 12px;
  background: var(--panel);
}

.record-search input[type="search"]:focus {
  outline: 2px solid var(--accent-soft);
  outline-offset: 1px;
}

#patient-record-search-count {
  margin: 0 0 0.6rem;
  color: var(--muted, #6b7280);
  font-size: 0.85rem;
}

.provider-directory {
  margin-top: 1.25rem;
  display: grid;
  gap: 0.75rem;
}

.provider-directory-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.provider-directory-filters input,
.provider-directory-filters select {
  flex: 1 1 200px;
}

.provider-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

a.provider-link-button {
  display: inline-block;
  text-decoration: none;
  text-align: center;
}

.provider-directory-empty,
.provider-directory-hint {
  margin: 0.25rem 0;
  color: #555;
  font-size: 0.95rem;
}

.provider-directory-hint {
  font-style: italic;
}

.external-reminder-warning {
  background: #fff7ed;
  border: 1px solid #fed7aa;
  color: #9a3412;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.85rem;
  margin: 0.5rem 0;
}

.status-badge {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
}

.status-active {
  background: #e0f2fe;
  color: #075985;
}

.status-cancelled {
  background: #fee2e2;
  color: #991b1b;
}

.status-done {
  background: #dcfce7;
  color: #166534;
}

.external-reminder-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.sos-warning {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  color: #92400e;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-weight: 600;
}

.sos-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0.75rem 0;
}

.sos-contact-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.status-backup {
  background: #ede9fe;
  color: #5b21b6;
}

.status-inactive {
  background: #e5e7eb;
  color: #4b5563;
}

/* Public SOS page */
.sos-public {
  max-width: 520px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

.sos-public-header {
  text-align: center;
  margin-bottom: 1rem;
}

.sos-public-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1.25rem;
}

.sos-patient-name {
  font-weight: 700;
  font-size: 1.1rem;
  margin-bottom: 1rem;
}

.sos-contacts {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.sos-contact-card {
  border: 1px solid #e2e8f0;
  border-radius: 10px;
  padding: 1rem;
}

.sos-contact-name {
  font-weight: 700;
  font-size: 1.05rem;
}

.sos-contact-badge {
  display: inline-block;
  margin-left: 0.5rem;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  background: #e0f2fe;
  color: #075985;
}

.sos-contact-badge.sos-backup {
  background: #ede9fe;
  color: #5b21b6;
}

.sos-contact-relationship,
.sos-contact-note {
  color: #475569;
  margin-top: 0.35rem;
}

.sos-usecase {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 12px;
  padding: 1rem 1.25rem;
  margin-bottom: 1rem;
}

.sos-usecase-title {
  font-weight: 700;
  margin: 0 0 0.5rem;
}

.sos-usecase ul {
  margin: 0;
  padding-left: 1.25rem;
}

.sos-usecase li {
  margin: 0.2rem 0;
}

.sos-usecase-note {
  margin: 0.6rem 0 0;
  font-weight: 600;
  color: #b91c1c;
}

.sos-patient-label {
  font-size: 0.9rem;
  color: #475569;
  font-weight: 600;
}

.sos-patient-value {
  font-size: 1.25rem;
  font-weight: 700;
}

.sos-contact-priority-label {
  font-size: 0.9rem;
  color: #475569;
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.sos-call-button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.15rem;
  width: 100%;
  margin-top: 0.9rem;
  padding: 1rem 1.1rem;
  background: #dc2626;
  color: #ffffff;
  border-radius: 12px;
  font-weight: 800;
  text-decoration: none;
  text-align: center;
  box-shadow: 0 4px 12px rgba(220, 38, 38, 0.3);
}

.sos-call-label {
  font-size: 1.15rem;
  letter-spacing: 0.04em;
}

.sos-call-number {
  font-size: 1.5rem;
  letter-spacing: 0.03em;
}

.sos-manage-name {
  font-size: 1.05rem;
  letter-spacing: 0.02em;
}

.sos-manage-priority {
  color: #475569;
  font-weight: 600;
}

.sos-manage-status-off {
  color: #94a3b8;
  font-weight: 600;
}

.sos-disabled-toggle {
  margin-top: 0.6rem;
  align-self: flex-start;
}

.sos-disabled-section {
  margin-top: 0.6rem;
  padding-top: 0.6rem;
  border-top: 1px dashed #cbd5e1;
}

.sos-disabled-section h3 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  color: #64748b;
}

.sos-link-details {
  margin-top: 0.6rem;
  font-size: 0.85rem;
  color: #475569;
  word-break: break-all;
}

.sos-link-details summary {
  cursor: pointer;
  color: #2563eb;
}

.sos-status-message {
  margin-top: 1rem;
  color: #475569;
}

.record-date-choice {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin: 0.25rem 0 0.5rem;
}

.record-date-option {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.95rem;
  color: #334155;
  cursor: pointer;
}

.record-date-option input {
  width: auto;
  margin: 0;
}

.dob-group {
  display: flex;
  gap: 0.5rem;
  margin: 0.25rem 0 0.5rem;
}

.dob-select {
  flex: 1 1 0;
  min-width: 0;
}

/* Batch upload review queue */
.batch-body {
  gap: 1rem;
}
.batch-apply {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 0.5rem 0.75rem;
  background: #f8fafc;
}
.batch-apply summary {
  cursor: pointer;
  font-weight: 600;
}
.batch-apply-grid {
  display: grid;
  gap: 0.6rem;
  margin-top: 0.6rem;
}
.batch-apply-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.batch-apply-row select,
.batch-apply-row input {
  flex: 1 1 180px;
  min-width: 0;
}
.batch-queue {
  display: grid;
  gap: 0.75rem;
}
.batch-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.75rem;
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 0.75rem;
  align-items: start;
}
.batch-card.is-saved {
  border-color: #16a34a;
  background: #f0fdf4;
}
.batch-card.is-error {
  border-color: var(--danger, #b00020);
  background: #fef2f2;
}
.batch-card .batch-thumb {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  border: 1px solid var(--line);
  object-fit: cover;
  background: #fff;
}
.batch-thumb-badge {
  width: 64px;
  height: 64px;
  border-radius: 8px;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 700;
  color: #475569;
  background: #f1f5f9;
}
.batch-fields {
  display: grid;
  gap: 0.45rem;
  min-width: 0;
}
.batch-card-head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: baseline;
}
.batch-filename {
  font-weight: 600;
  word-break: break-word;
}
.batch-fields select,
.batch-fields input {
  width: 100%;
}
.batch-date-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}
.batch-date-row select {
  flex: 1 1 140px;
}
.batch-status {
  font-size: 0.85rem;
}
.batch-status.is-saved { color: #16a34a; }
.batch-status.is-error { color: var(--danger, #b00020); }
.batch-dup-note {
  font-size: 0.85rem;
  color: #b45309;
}
.batch-remove {
  align-self: start;
}

/* Batch image preview (zoom) overlay */
.batch-thumb-btn {
  padding: 0;
  border: none;
  background: none;
  cursor: pointer;
  line-height: 0;
  border-radius: 8px;
}
.batch-thumb-btn:focus-visible {
  outline: 2px solid var(--accent, #2563eb);
  outline-offset: 2px;
}
.batch-zoom {
  align-self: start;
  font-size: 0.85rem;
}
.batch-preview-dialog {
  max-width: 920px;
  width: min(96vw, 920px);
  display: flex;
  flex-direction: column;
}
.batch-preview-name {
  word-break: break-word;
  margin-right: 0.5rem;
}
.batch-preview-body {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.batch-preview-stage {
  width: 100%;
  max-height: 75vh;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-overflow-scrolling: touch;
}
/* When zoomed past fit, anchor to the top-left so scrolling can reach every edge
   (flex centering clips the overflowing start of the image otherwise). */
.batch-preview-stage.is-zoomed {
  align-items: flex-start;
  justify-content: flex-start;
}
/* The frame takes up the rotated+scaled footprint (sized in JS) so the stage can
   scroll/pan; the image is centered inside it and transformed via rotate()/scale(). */
.batch-preview-frame {
  position: relative;
  flex: 0 0 auto;
  margin: auto;
}
.viewer-body .batch-preview-image {
  position: absolute;
  top: 50%;
  left: 50%;
  max-width: none;
  max-height: none;
  transform-origin: center center;
  border-radius: 8px;
  background: #fff;
}
.batch-preview-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border-bottom: 1px solid var(--line);
}
.batch-preview-zoom-level {
  font-size: 0.9rem;
  color: #475569;
  min-width: 2.5ch;
  text-align: center;
}
/* Zoom + rotate viewer for saved-record image attachments (inline in the record
   viewer). Mirrors the batch preview behavior but is self-contained per image. */
.img-viewer {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.img-viewer-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}
.img-viewer-zoom-level {
  font-size: 0.9rem;
  color: #475569;
  min-width: 2.5ch;
  text-align: center;
}
.img-viewer-stage {
  width: 100%;
  max-height: 70vh;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 10px;
  -webkit-overflow-scrolling: touch;
}
.img-viewer-stage.is-zoomed {
  align-items: flex-start;
  justify-content: flex-start;
}
.img-viewer-frame {
  position: relative;
  flex: 0 0 auto;
  margin: auto;
}
/* Class selector beats the generic `.viewer-body img { width:100% }` rule, and JS
   sets the explicit size inline. Reset the inherited border/max constraints. */
.viewer-body .img-viewer-image {
  position: absolute;
  top: 50%;
  left: 50%;
  width: auto;
  max-width: none;
  max-height: none;
  border: 0;
  border-radius: 6px;
  transform-origin: center center;
  background: #fff;
}
.batch-date-selects {
  display: flex;
  flex: 1 1 100%;
  gap: 0.4rem;
}
.batch-date-selects select {
  flex: 1 1 0;
  min-width: 0;
}
.batch-preview-badge {
  width: 140px;
  height: 180px;
  border-radius: 12px;
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  font-weight: 700;
  color: #475569;
  background: #f1f5f9;
}
.batch-preview-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--line);
}
.batch-preview-count {
  font-size: 0.9rem;
  color: #475569;
  min-width: 3ch;
  text-align: center;
}

/* --- Patient access log (TF-6 trust timeline) --- */
.access-log {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}
.access-log-day {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.access-log-day-label {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: #475569;
  border-bottom: 1px solid var(--line);
  padding-bottom: 0.35rem;
}
.access-log-day-items {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.access-log-card {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-left: 4px solid #94a3b8;
  border-radius: 12px;
  background: #ffffff;
}
.access-log-card.severity-normal {
  border-left-color: #16a34a;
}
.access-log-card.severity-warning {
  border-left-color: #d97706;
  background: #fffbeb;
}
.access-log-card.severity-denied {
  border-left-color: #dc2626;
  background: #fef2f2;
}
.access-log-icon {
  font-size: 1.25rem;
  line-height: 1.6;
  flex: 0 0 auto;
}
.access-log-body {
  flex: 1 1 auto;
  min-width: 0;
}
.access-log-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}
.access-log-headline {
  margin: 0;
  font-weight: 600;
  color: #0f172a;
}
.access-log-detail {
  margin: 0.3rem 0 0;
  font-size: 0.9rem;
  color: #475569;
}
.access-log-time {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: 0.85rem;
  color: #64748b;
}
.access-log-badge {
  flex: 0 0 auto;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  white-space: nowrap;
  color: #475569;
  background: #f1f5f9;
}
.access-log-badge.severity-normal {
  color: #166534;
  background: #dcfce7;
}
.access-log-badge.severity-warning {
  color: #92400e;
  background: #fef3c7;
}
.access-log-badge.severity-denied {
  color: #991b1b;
  background: #fee2e2;
}

.analytics-note {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  background: #eff6ff;
  color: #1e3a8a;
  font-size: 0.9rem;
  line-height: 1.4;
}
.emergency-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: #b91c1c;
  letter-spacing: 0.02em;
}
.emergency-fallback-label {
  display: inline-block;
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: #92400e;
  background: #fef3c7;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
}
.analytics-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: #0f172a;
}
.analytics-section-title {
  margin: 1.5rem 0 0.75rem;
  font-size: 1rem;
  font-weight: 700;
  color: #1e293b;
  border-bottom: 1px solid #e2e8f0;
  padding-bottom: 0.35rem;
}
.analytics-section-title:first-child {
  margin-top: 0;
}

/* --- "Chuẩn bị đi khám" (visit preparation package) --------------------- */
.visit-prep-block {
  margin-top: 1.25rem;
  padding: 1.25rem;
  border: 1px solid #e2e8f0;
  border-radius: 14px;
  background: #f8fafc;
}
.visit-prep-block h3 {
  margin: 0 0 0.35rem;
  font-size: 1.05rem;
}
.visit-prep-block textarea {
  width: 100%;
  min-height: 88px;
  box-sizing: border-box;
}
.visit-prep-reminder {
  background: #fffbeb;
  border: 1px solid #fde68a;
  color: #92400e;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  font-size: 0.9rem;
  line-height: 1.5;
  font-weight: 600;
}
.visit-prep-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.75rem;
}
.visit-prep-preview {
  margin-top: 1.5rem;
}
.visit-prep-preview:not(.is-ready) {
  display: none;
}
.visit-prep-doc {
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 1.25rem;
  background: #ffffff;
}
.visit-prep-doc-head {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  border-bottom: 2px solid #0f172a;
  padding-bottom: 0.6rem;
  margin-bottom: 0.9rem;
}
.visit-prep-doc-head strong {
  font-size: 1.25rem;
  color: #0f172a;
}
.visit-prep-doc-note {
  font-size: 0.85rem;
  color: #475569;
  font-style: italic;
  margin-bottom: 0.75rem;
  line-height: 1.5;
}
.visit-prep-doc-reminder {
  font-size: 0.85rem;
  color: #92400e;
  font-weight: 600;
  margin-bottom: 0.9rem;
  line-height: 1.5;
}
.visit-prep-doc-safety {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px dashed #94a3b8;
  font-size: 0.85rem;
  color: #b45309;
  line-height: 1.5;
}

@media print {
  body.printing-visit-prep * {
    visibility: hidden;
  }
  body.printing-visit-prep #visit-prep-preview,
  body.printing-visit-prep #visit-prep-preview * {
    visibility: visible;
  }
  body.printing-visit-prep #visit-prep-preview {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    margin: 0;
    padding: 0;
  }
  body.printing-visit-prep .visit-prep-doc {
    border: none;
    border-radius: 0;
    padding: 0;
  }
  body.printing-visit-prep #visit-prep-preview .cards {
    display: block;
  }
  body.printing-visit-prep #visit-prep-preview .card {
    border: 1px solid #cbd5e1;
    break-inside: avoid;
    page-break-inside: avoid;
    margin-bottom: 0.6rem;
  }
  @page {
    size: A4;
    margin: 16mm;
  }
}

/* --- V1 UX patch: profile summary mode, reminder actions, access-log filters --- */
.form-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

#patient-profile-view .cards {
  margin-bottom: 12px;
}

.access-log-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 12px;
}

.access-log-controls input[type="search"] {
  width: 100%;
  box-sizing: border-box;
}

.access-log-filter-chips {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.filter-chip {
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid #cbd5e1;
  background: #fff;
  color: #334155;
  font-size: 0.85rem;
  cursor: pointer;
}

.filter-chip.chip-active {
  background: #0f766e;
  border-color: #0f766e;
  color: #fff;
}

#access-log-more {
  margin-top: 8px;
}

/* Pre-login emergency contact card (OWNER APPROVED): 115 + emergency phone
   number only — never a name, relationship or any other personal data. */
.emergency-precard {
  margin: 0 0 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid #f5c6cb;
  border-radius: 12px;
  background: #fdf2f3;
}
.emergency-precard-title {
  margin: 0 0 0.3rem;
  font-weight: 700;
  font-size: 1.125rem;
  color: #a4262c;
}
.emergency-precard-actions {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
}
.emergency-precard-call {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  padding: 0.6rem 1.1rem;
  border-radius: 10px;
  border: 1px solid #a4262c;
  background: #ffffff;
  color: #a4262c;
  font-size: 1.0625rem;
  font-weight: 700;
  text-decoration: none;
}
.emergency-precard-call-115 {
  background: #a4262c;
  color: #ffffff;
}
