:root {
  --bg: #F8F7F4;
  --text: #1F2933;
  --primary: #3D5A6C;
  --primary-dark: #2F4756;
  --border: #D9D5CE;
  --card: #FFFFFF;
  --muted: #4B5563;
  --open-bg: #EDE6DC;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.4;
}
.screen { display: none; min-height: 100vh; }
.screen.active { display: block; }
.pad { padding: 24px 20px 40px; max-width: 480px; margin-left: auto; margin-right: auto; }
#home .pad {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
}
.pad-bottom { padding-bottom: calc(120px + env(safe-area-inset-bottom, 0px)); }
.pad-bottom-tall { padding-bottom: calc(168px + env(safe-area-inset-bottom, 0px)); }
@media (max-width: 560px) {
  .row-2-phone { flex-direction: column; gap: 0; }
  .row-2-phone .field { width: 100%; }
}

.header { margin-bottom: 28px; padding-top: 8px; }
.header h1 { font-size: 1.75rem; font-weight: 650; letter-spacing: -0.02em; }
.header h2 { font-size: 1.4rem; font-weight: 650; letter-spacing: -0.02em; }
.header p { margin-top: 4px; color: var(--muted); font-size: 1rem; }
.primary-btn, .secondary-btn {
  display: block; width: 100%; text-align: center; text-decoration: none;
  border-radius: 14px; font-weight: 600; cursor: pointer;
}
.primary-btn {
  background: var(--primary); color: #fff; border: none;
  padding: 22px 20px; font-size: 1.25rem; margin-bottom: 16px;
}
#about-buy-wrap { margin-top: 16px; }
#about-buy { margin-bottom: 8px; }
#about-code-wrap { margin: 0; }
#about-code {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  min-width: 44px;
  padding: 10px 4px;
  box-sizing: border-box;
}
.buy-prompt {
  margin: 16px 2px 8px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.4;
}
.buy-help {
  margin: 0 2px 16px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}
.buy-help-tap { white-space: nowrap; }
.plain-help {
  margin: 8px 2px 16px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.45;
}
#unlock-buy-wrap { margin-top: 8px; }
#unlock-buy { margin-bottom: 8px; }

.secondary-btn {
  background: var(--card); color: var(--text);
  border: 1.5px solid var(--border);
  padding: 18px 20px; font-size: 1.1rem; margin-bottom: 12px;
}
.home-bottom {
  margin-top: auto;
  padding-top: 36px;
}
.home-backup {
  margin-top: 0;
  padding-top: 0;
}
.home-backup-row {
  display: flex;
  gap: 10px;
  align-items: stretch;
}
.quiet-btn {
  flex: 1;
  display: block;
  width: auto;
  text-align: center;
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 8px;
  font-size: 0.85rem;
  font-weight: 500;
  margin-bottom: 0;
  cursor: pointer;
}
.quiet-btn:active {
  color: var(--primary);
}
.start-over-wrap {
  margin: 10px 0 0;
  text-align: center;
}
.start-over-link {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 400;
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
}
.start-over-link:active {
  color: var(--primary);
}

#home .footer-note {
  margin-top: 20px;
}
.footer-note {
  margin-top: 40px; text-align: center; font-size: 0.95rem;
  color: var(--muted); line-height: 1.5;
}
.packet-wrap {
  padding: 16px 16px 120px;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}
.back {
  display: inline-block; margin-bottom: 12px; color: var(--primary);
  text-decoration: none; font-weight: 500; font-size: 0.95rem;
  background: none; border: none; cursor: pointer; padding: 0;
}
.packet {
  background: var(--card); border-radius: 16px; padding: 22px 20px;
  border: 1px solid var(--border); max-width: 480px; margin: 0 auto;
}
.packet-header { border-bottom: 1px solid var(--border); padding-bottom: 14px; margin-bottom: 18px; }
.packet-header h2 { font-size: 1.15rem; font-weight: 650; margin-bottom: 2px; }
.subtitle { font-size: 0.85rem; color: var(--muted); }
.section { margin-bottom: 18px; }
.section-title {
  font-size: 0.875rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted); margin-bottom: 6px;
}
.patient-line { font-size: 1.2rem; font-weight: 600; }
.patient-meta { color: var(--muted); font-size: 0.95rem; margin-top: 2px; }
ul { list-style: none; }
ul li { padding: 3px 0 3px 14px; position: relative; }
ul li::before { content: "•"; position: absolute; left: 0; color: var(--primary); }
.open-items {
  background: var(--open-bg); border-radius: 10px;
  padding: 12px 14px; margin-bottom: 18px;
}
.open-items .section-title {
  color: #3F3428;
  margin-bottom: 8px;
  font-weight: 800;
}
.open-items li::before { color: #8B7355; }
.mr-card.open-card .mr-card-head h3 {
  color: #3F3428;
  font-weight: 800;
}
.prepared {
  margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--border);
  font-size: 0.9rem; color: var(--muted);
}
.action-bar {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--bg); border-top: 1px solid var(--border);
  padding: 14px 16px 28px; display: flex; gap: 10px;
  max-width: 480px; margin: 0 auto;
}
.action-bar button {
  flex: 1; border: none; border-radius: 12px;
  padding: 16px 8px; font-size: 1rem; font-weight: 600; cursor: pointer;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-secondary { background: #fff; color: var(--text); border: 1.5px solid var(--border); }
.toast {
  display: none; position: fixed; bottom: 96px; left: 16px; right: 16px;
  background: var(--text); color: #fff; text-align: center;
  padding: 12px; border-radius: 10px; font-size: 0.95rem; z-index: 20;
}
.field { margin-bottom: 18px; }
.field label {
  display: block; font-size: 0.9rem; font-weight: 600;
  margin-bottom: 6px; color: var(--text);
}
.field .hint { font-weight: 400; color: var(--muted); font-size: 0.85rem; }
.field .field-help { margin: 6px 0 0; color: var(--muted); font-size: 0.9rem; line-height: 1.4; }
.field input, .field textarea {
  width: 100%; border: 1.5px solid var(--border); border-radius: 12px;
  padding: 14px 14px; font-size: 1.05rem; font-family: inherit;
  background: var(--card); color: var(--text);
}
.field textarea { min-height: 88px; resize: vertical; }
.field input:focus, .field textarea:focus {
  outline: none; border-color: var(--primary);
}
.attach-btn {
  width: 100%; border: 1.5px dashed var(--border); border-radius: 12px;
  padding: 18px; background: var(--card); color: var(--primary);
  font-size: 1.05rem; font-weight: 600; cursor: pointer;
}
.row-2 { display: flex; gap: 12px; }
.row-2 .field { flex: 1; }
.prompt-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 18px; margin-bottom: 14px;
}
.prompt-card h3 { font-size: 1.05rem; font-weight: 650; margin-bottom: 8px; }
.prompt-card p { color: var(--muted); font-size: 0.95rem; margin-bottom: 14px; }
.prompt-actions { display: flex; gap: 8px; }
.prompt-actions button {
  flex: 1; border-radius: 10px; padding: 12px 8px;
  font-size: 0.95rem; font-weight: 600; cursor: pointer; border: none;
}
.success-banner {
  background: #E8F0EC; color: #2F5D4A; border-radius: 12px;
  padding: 14px 16px; margin-bottom: 20px; font-weight: 550;
}
.storage-banner {
  background: var(--open-bg); color: #3F3428;
  border-radius: 12px; padding: 14px 16px; margin-bottom: 20px;
  font-size: 0.95rem; line-height: 1.45;
}


/* Welcome (first-time) */
.welcome-how {
  margin-bottom: 24px;
}
#welcome .header h1 {
  font-size: 1.85rem;
  line-height: 1.25;
  letter-spacing: -0.02em;
}
#welcome .primary-btn,
#welcome .secondary-btn {
  margin-bottom: 12px;
}

/* Example mode banner — sticky, senior-readable */
.example-banner {
  position: sticky;
  top: 0;
  z-index: 40;
  background: #F3E8D8;
  color: #3F3428;
  border: 1.5px solid #D4C4A8;
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 16px;
  font-size: 1.05rem;
  line-height: 1.45;
  box-shadow: 0 2px 8px rgba(31, 41, 51, 0.08);
}
.example-banner p {
  margin: 0 0 12px;
}
.example-banner-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.example-banner-actions .primary-btn,
.example-banner-actions .secondary-btn {
  margin: 0;
  width: 100%;
}
.packet-wrap > .example-banner {
  margin: 12px 0 8px;
}

/* Master Record */
.mr-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 14px; padding: 16px 18px; margin-bottom: 12px;
}
.mr-card-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px;
}
.mr-card-head h3 {
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--muted);
}
.edit-link {
  background: none; border: none; color: var(--primary);
  font-size: 0.9rem; font-weight: 600; cursor: pointer;
}
.mr-card.open-card { background: var(--open-bg); border-color: #E0D5C5; }

/* Setup */
.choice {
  display: block; width: 100%; text-align: left;
  background: var(--card); border: 1.5px solid var(--border);
  border-radius: 14px; padding: 18px 18px; margin-bottom: 12px;
  cursor: pointer; font-size: 1.05rem; font-weight: 600; color: var(--text);
}
.choice:hover, .choice.selected { border-color: var(--primary); }
.choice small {
  display: block; font-weight: 400; color: var(--muted);
  font-size: 0.9rem; margin-top: 4px;
}
.radio-row {
  display: flex; gap: 12px; margin-bottom: 18px;
}
.radio-row label {
  flex: 1; background: var(--card); border: 1.5px solid var(--border);
  border-radius: 12px; padding: 14px; text-align: center;
  font-weight: 600; cursor: pointer;
}
.radio-row input { display: none; }
.radio-row input:checked + span,
.radio-row label:has(input:checked),
.radio-row label.selected {
  border-color: var(--primary);
  background: #EAF0F3;
}

.freq-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 8px;
}
.freq-grid label {
  flex: 1 1 calc(50% - 8px);
  min-width: 140px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 14px 10px;
  text-align: center;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  color: var(--text);
}
.freq-grid input { display: none; }
.freq-grid label:has(input:checked),
.freq-grid label.selected {
  border-color: var(--primary);
  background: #EAF0F3;
}
.clear-btn {
  display: block;
  width: auto;
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 600;
  padding: 8px 4px 4px;
  cursor: pointer;
  text-align: left;
}

/* QR modal */
.modal-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(31, 41, 51, 0.45);
  z-index: 50;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--card);
  border-radius: 18px;
  padding: 28px 24px 22px;
  max-width: 340px;
  width: 100%;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,0.18);
}
.modal h3 {
  font-size: 1.15rem;
  font-weight: 650;
  margin-bottom: 6px;
}
.modal .modal-sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 20px;
}
.modal .qr-frame {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 16px;
}
.modal .qr-frame img {
  width: 200px;
  height: 200px;
  display: block;
  margin: 0 auto;
}
.modal .modal-note {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 18px;
  line-height: 1.45;
}
.modal .btn-primary {
  margin-bottom: 0;
  padding: 16px 20px;
  font-size: 1.05rem;
}


.backup-help {
  margin: 8px 0 0;
  padding: 14px 16px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}
.backup-help em { font-style: italic; }
.backup-help strong { font-weight: 700; }
.privacy-link {
  color: var(--primary);
  text-decoration: underline;
  font-size: inherit;
}
.privacy-link:hover { color: var(--primary-dark); }
.privacy-body {
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.55;
}
.privacy-page .mr-card { margin-bottom: 14px; }
.packet-footer { margin-top: 18px; margin-bottom: 8px; }
.toast {
  line-height: 1.4;
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
  white-space: normal;
}

@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  html, body { background: #fff !important; color: #000; }
  .screen { display: none !important; }
  #packet.screen.active,
  #packet { display: block !important; background: #fff !important; }
  .action-bar, .back, .toast, .modal-overlay, .storage-banner, .example-banner,
  .packet-footer, .home-bottom, #home, #master, #add, #prompts,
  #welcome, #setup-who, #setup-form, #setup-quick, #meds-edit, #patient-edit,
  #insurance-edit, #pharmacy-edit, #list-edit { display: none !important; }
  .packet-wrap { padding: 0 !important; margin: 0 !important; }
  .packet {
    border: none !important;
    border-radius: 0 !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 12px 16px !important;
    box-shadow: none !important;
    background: #fff !important;
  }
  .open-items { background: #f3eee6 !important; }
}


/* Working list edit (pharmacy + shared list screens) */
.working-list { list-style: none; }
.working-list li::before { content: none; }
.working-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  position: relative;
}
.working-item:last-child { border-bottom: none; }
.working-item > span {
  flex: 1;
  padding-left: 0;
  font-size: 1.05rem;
  line-height: 1.35;
}
.remove-item {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 2px;
}

.how-title {
  font-size: 1.05rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text);
}
/* Custom numbers — Safari iOS clips native outside list markers */
.how-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: how-step;
}
.how-list li {
  counter-increment: how-step;
  position: relative;
  padding: 8px 2px 8px 2.35rem;
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.45;
  color: var(--text);
}
.how-list li::before {
  content: counter(how-step) ".";
  position: absolute;
  left: 0;
  top: 8px;
  width: 1.85rem;
  text-align: right;
  font-weight: 650;
  color: var(--text);
  font-variant-numeric: tabular-nums;
}


/* Visit file pick + Master files */
.file-picked {
  margin-top: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
}
.file-picked span {
  flex: 1;
  font-size: 0.95rem;
  color: var(--text);
  word-break: break-word;
}
.files-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.file-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.file-row:last-child { border-bottom: none; }
.file-thumb {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #fff;
  cursor: pointer;
  flex-shrink: 0;
}
.file-link {
  color: var(--primary);
  font-weight: 600;
  font-size: 1.05rem;
  text-decoration: underline;
  word-break: break-word;
  background: none;
  border: none;
  padding: 0;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}
.file-note {
  display: block;
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 2px;
  font-weight: 400;
}
.modal-wide { max-width: 480px; }
.file-lightbox {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px;
  margin-bottom: 16px;
  max-height: 60vh;
  overflow: auto;
}
.file-lightbox img {
  display: block;
  max-width: 100%;
  height: auto;
  margin: 0 auto;
}


/* Doctor Packet file thumbs + ask line */
.pkt-thumbs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}
.pkt-thumb {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  flex-shrink: 0;
}
.pkt-ask-line {
  margin-top: 4px;
}

.working-item-actions {
  display: flex;
  gap: 10px;
  flex-shrink: 0;
  align-items: flex-start;
}

/* ---- Multi-person: Record open + Switch ---- */
.record-open {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin: 0 0 16px;
}
.record-open[hidden] { display: none; }
.record-open-line {
  margin: 0;
  font-size: 17px;
  color: var(--text);
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.record-open-switch {
  flex: 0 0 auto;
  min-height: 44px;
  padding: 8px 18px;
  font-size: 17px;
  font-weight: 600;
  color: var(--primary);
  background: var(--bg);
  border: 2px solid var(--primary);
  border-radius: 10px;
  cursor: pointer;
}
.record-open-switch:active { background: #e9edf0; }
.choice-erase-all {
  border-color: #b9897f;
  color: #7a2e22;
}
.choice-erase-all small { color: #7a2e22; }

/* ---- v16: Start over warning popup ---- */
:root { --danger: #9B2C2C; --danger-dark: #7F2323; --danger-bg: #FBF1F0; }
body.modal-open { overflow: hidden; }
.erase-modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  padding-top: calc(16px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
}
.erase-modal[hidden] { display: none; }
.erase-modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(31, 41, 51, 0.62);
}
.erase-modal-box {
  position: relative;
  width: 100%; max-width: 480px;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--card);
  border: 3px solid var(--danger);
  border-top-width: 10px;
  border-radius: 18px;
  padding: 22px 20px 20px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.28);
  color: var(--text);
}
.erase-modal-icon {
  width: 56px; height: 56px; line-height: 56px;
  margin: 0 auto 10px;
  border-radius: 50%;
  background: var(--danger-bg);
  color: var(--danger);
  font-size: 2rem; text-align: center;
}
.erase-modal-title {
  color: var(--danger);
  font-size: 1.5rem; font-weight: 700; line-height: 1.25;
  text-align: center; letter-spacing: -0.01em;
  margin-bottom: 14px;
  overflow-wrap: anywhere;
}
.erase-modal-body p {
  font-size: 1.15rem; line-height: 1.5;
  margin-bottom: 14px;
  overflow-wrap: anywhere;
}
.erase-modal-body p strong { color: var(--danger); }
.erase-modal-tip {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 1.05rem !important;
}
.erase-modal-actions {
  display: flex; flex-direction: column; gap: 12px;
  margin-top: 6px;
}
.erase-keep-btn, .erase-danger-btn {
  display: block; width: 100%;
  min-height: 56px;
  padding: 16px 18px;
  border-radius: 14px;
  font-size: 1.15rem; font-weight: 700; line-height: 1.3;
  text-align: center; cursor: pointer;
  overflow-wrap: anywhere;
}
.erase-keep-btn {
  background: var(--primary); color: #fff; border: 2px solid var(--primary);
}
.erase-keep-btn:active { background: var(--primary-dark); }
.erase-danger-btn {
  background: var(--danger); color: #fff; border: 2px solid var(--danger);
}
.erase-danger-btn:active { background: var(--danger-dark); }
.erase-keep-btn:focus-visible, .erase-danger-btn:focus-visible {
  outline: 3px solid #E0A100; outline-offset: 3px;
}

/* ---- v19: trial line, trial ended, unlock ---- */
.access-line {
  margin: 0 0 12px;
  text-align: center;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.4;
}
.link-btn {
  background: none;
  border: none;
  padding: 6px 4px;
  margin: 0;
  color: var(--primary);
  font-size: 1rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}
.access-line .link-btn { font-size: 0.95rem; padding: 4px 2px; }
.welcome-bought { margin: 4px 0 0; text-align: center; }
.access-card .privacy-body + .privacy-body { margin-top: 10px; }
.access-price { font-weight: 600; color: var(--primary); }
.access-notice { border-left: 4px solid var(--primary); }
.unlock-message { margin: 10px 2px 0; font-size: 1rem; line-height: 1.5; min-height: 1.5em; }
.unlock-message.is-ok { color: #2F6B3A; font-weight: 600; }
.unlock-message.is-problem { color: #8A4B12; }

/* v22 Shots: one plain line on the Doctor Packet */
[hidden] { display: none !important; }
.pkt-shot { margin: 4px 0 0; font-size: 1rem; line-height: 1.5; }
