/* ============================================================
   Patient Handout Generator — styles
   Two audiences in one file:
   - SCREEN: the app chrome + a colour handout preview (teal accent)
   - PRINT (@media print): B&W-robust. Structure (borders, icons,
     weight, rules) carries the meaning, colour is only a bonus,
     because most clinic printers are black-and-white.
   ============================================================ */

:root {
  --accent:        #0F6E56;   /* clinic teal-green */
  --accent-dark:   #085041;
  --accent-tint:   #E1F5EE;
  --ink:           #14181F;
  --ink-2:         #39414c;
  --muted:         #656D78;
  --faint:         #98A1AC;
  --line:          #E1E4E8;
  --line-strong:   #C7CCD2;
  --ground:        #F4F6F8;
  --surface:       #FFFFFF;
  --danger:        #A32D2D;
  --danger-dark:   #791F1F;
  --danger-tint:   #FCEBEB;
  --radius:        10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--ground);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; }

/* ---------- app chrome ---------- */
.app { max-width: 720px; margin: 0 auto; padding: 24px 20px 48px; }

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 20px;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 11px;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.app-header h1 { font-size: 19px; font-weight: 600; margin: 0; line-height: 1.15; }
.tagline { font-size: 13px; color: var(--muted); margin: 2px 0 0; }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; padding: 5px 10px; border-radius: 20px; white-space: nowrap;
}
.pill-private { color: var(--accent-dark); background: var(--accent-tint); }

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 14px; padding: 20px; margin-bottom: 16px;
}

.step-label {
  font-size: 12px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase;
  color: var(--muted); margin: 0 0 10px;
}

.plan-input {
  width: 100%; min-height: 150px; resize: vertical;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 13px 15px; font-size: 14px; line-height: 1.6; color: var(--ink);
  background: #fff;
}
.plan-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }

.privacy-note, .responsibility-note {
  display: flex; align-items: flex-start; gap: 7px;
  font-size: 12.5px; color: var(--muted); margin: 10px 0 0; line-height: 1.5;
}
.privacy-note svg { color: var(--accent); flex-shrink: 0; margin-top: 1px; }
.responsibility-note svg { color: var(--muted); flex-shrink: 0; margin-top: 1px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  font-size: 14px; font-weight: 500; padding: 11px 16px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: #fff; color: var(--ink); cursor: pointer;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:hover { background: var(--ground); border-color: var(--muted); }
.btn:active { transform: scale(.985); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-ghost { border-color: var(--line); color: var(--muted); }
.btn-block { width: 100%; margin-top: 16px; padding: 13px; font-size: 15px; }
.btn[aria-pressed="true"] { background: var(--accent-tint); border-color: var(--accent); color: var(--accent-dark); }

.demo-hint { font-size: 12.5px; color: var(--muted); text-align: center; margin: 12px 0 0; }
.linklike {
  border: none; background: none; padding: 0; cursor: pointer;
  color: var(--accent-dark); font-weight: 500; font-size: inherit; text-decoration: underline;
}
.kbd-hint { font-size: 11.5px; color: var(--faint); text-align: center; margin: 6px 0 0; }
.kbd-hint kbd {
  font-family: inherit; font-size: 10.5px; padding: 1px 5px; border-radius: 4px;
  border: 1px solid var(--line-strong); background: var(--ground); color: var(--muted);
}

/* button loading spinner (used while generating) */
.spinner {
  display: inline-block; width: 14px; height: 14px; vertical-align: -2px; margin-right: 2px;
  border: 2px solid rgba(255,255,255,.45); border-top-color: #fff; border-radius: 50%;
  animation: spin .7s linear infinite;
}
.btn:not(.btn-primary) .spinner { border-color: var(--line-strong); border-top-color: var(--accent); }
@keyframes spin { to { transform: rotate(360deg); } }

/* gentle reveal when a new handout/result appears */
@keyframes fadeInUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.reveal-in { animation: fadeInUp .35s ease; }
@media (prefers-reduced-motion: reduce) { .reveal-in { animation: none; } }

/* result actions */
.result-head { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 14px; }
.result-tick { color: var(--accent); flex-shrink: 0; }
.result-title { font-size: 16px; font-weight: 600; margin: 0; }
.result-sub { font-size: 13px; color: var(--muted); margin: 2px 0 0; }
.action-row { display: flex; flex-wrap: wrap; gap: 9px; }
.responsibility-note { margin-top: 14px; padding: 10px 12px; background: #FAEEDA; color: #7a4d0c; border-radius: var(--radius); }
.responsibility-note svg { color: #7a4d0c; }

/* ============================================================
   THE HANDOUT — screen preview (colour)
   ============================================================ */
.sheet {
  max-width: 720px; margin: 0 auto 60px; background: #fff; color: var(--ink);
  border: 1px solid var(--line); border-radius: 6px;
  padding: 30px 34px; font-size: 13.5px; line-height: 1.5;
}

.h-top { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.h-logo { height: 52px; width: auto; }
.h-review {
  text-align: right; background: var(--accent-tint); border-radius: 9px;
  padding: 8px 13px; display: flex; flex-direction: column; line-height: 1.25;
}
.h-review-label { font-size: 11px; color: var(--accent-dark); }
.h-review-when  { font-size: 15px; font-weight: 600; color: var(--accent-dark); margin-top: 2px; }
.h-review-what  { font-size: 11px; color: var(--accent-dark); }

.h-titleblock { position: relative; border-bottom: 2px solid var(--accent); padding-bottom: 12px; padding-right: 32px; margin-bottom: 15px; }
.h-eyebrow { font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: var(--faint); margin: 0 0 2px; }
.h-title { font-size: 23px; font-weight: 600; margin: 0; line-height: 1.1; }
.h-meta { font-size: 12.5px; color: var(--muted); margin: 5px 0 0; }

.h-intro { font-size: 13px; color: var(--ink-2); margin: 0 0 16px; }

.h-section { margin-bottom: 16px; }
.h-h {
  display: flex; align-items: center; gap: 8px;
  font-size: 14px; font-weight: 600; margin: 0 0 8px;
  padding-bottom: 5px; border-bottom: 1px solid var(--line);
}
.h-ico { color: var(--accent); display: inline-flex; }

/* goals */
.goal-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.goal {
  background: var(--accent-tint); border: 1px solid transparent; border-radius: 8px;
  padding: 10px 12px;
}
.goal-n {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%; font-size: 11px; font-weight: 700;
  background: var(--accent); color: #fff; margin-bottom: 5px;
}
.goal-title { font-weight: 600; color: var(--accent-dark); margin: 0; line-height: 1.35; font-size: 12.5px; }
.goal-sub { color: var(--accent-dark); margin: 3px 0 0; line-height: 1.35; font-size: 11.5px; }

/* conditions */
.cond-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cond { border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; }
.cond-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 25px; height: 25px; border-radius: 50%; margin-bottom: 5px;
  background: var(--accent-tint); color: var(--accent-dark);
}
.cond-name { font-weight: 600; margin: 0; font-size: 13px; }
.cond-text { color: var(--ink-2); margin: 3px 0 0; line-height: 1.45; font-size: 12px; }

/* to-do */
.todo-wrap { border: 1px solid var(--line); border-radius: 8px; padding: 12px 14px; }
.todo-group + .todo-group { margin-top: 10px; }
.todo-group-label { font-size: 11px; letter-spacing: .3px; text-transform: uppercase; color: var(--faint); margin: 0 0 6px; }
.todo-item { display: flex; align-items: flex-start; gap: 9px; margin: 0 0 6px; font-size: 12.5px; line-height: 1.45; }
.todo-item:last-child { margin-bottom: 0; }
.todo-box { width: 14px; height: 14px; border: 1.6px solid var(--ink-2); border-radius: 3px; flex-shrink: 0; margin-top: 1px; }

/* medicines */
.med-table { width: 100%; border-collapse: collapse; font-size: 12px; table-layout: fixed; }
.med-table th {
  text-align: left; color: var(--muted); font-weight: 600; font-size: 11px;
  padding: 6px 8px 6px 0; border-bottom: 1.5px solid var(--line-strong);
}
.med-table th:nth-child(1) { width: 34%; }
.med-table th:nth-child(2) { width: 38%; }
.med-table td { padding: 7px 8px 7px 0; border-bottom: 1px solid var(--line); vertical-align: top; line-height: 1.4; }
.med-table td:first-child { font-weight: 600; }
.med-table td:not(:first-child) { color: var(--ink-2); }
.med-table tr:last-child td { border-bottom: none; }

/* red flag — heavy border so it survives B&W */
.h-redflag {
  border: 2px solid var(--danger); border-radius: 8px;
  background: var(--danger-tint); padding: 11px 14px; margin-bottom: 16px;
}
.rf-head { display: flex; align-items: center; gap: 7px; font-weight: 700; color: var(--danger-dark); margin: 0 0 4px; font-size: 13px; }
.rf-ico { display: inline-flex; }
.rf-body { color: var(--danger); margin: 0; line-height: 1.5; font-size: 12px; }

/* team + reading */
.h-two { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.h-mini-h { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; margin: 0 0 6px; }
.h-mini-h svg { color: var(--muted); }
.mini-list { list-style: none; margin: 0; padding: 0; font-size: 12px; color: var(--ink-2); }
.mini-list li { display: flex; align-items: center; gap: 6px; margin-bottom: 5px; line-height: 1.4; }
.mini-list .role { color: var(--muted); }
.team-icon { display: inline-flex; flex-shrink: 0; color: var(--accent-dark); }
.mini-list a { color: var(--accent-dark); text-decoration: none; font-weight: 500; }
.mini-list a:hover { text-decoration: underline; }
.mini-list .qr-note { color: var(--faint); }

.h-foot {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 12px;
  border-top: 1px solid var(--line); padding-top: 9px; margin-top: 4px;
  font-size: 10.5px; color: var(--muted); line-height: 1.35;
}
.h-credit { text-align: right; white-space: nowrap; }

/* per-section quick-edit icons — click to edit that box in place, nothing sent anywhere */
.edit-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 21px; height: 21px; margin-left: auto; flex-shrink: 0;
  border: 1px solid var(--line-strong); border-radius: 6px;
  background: #fff; color: var(--faint); cursor: pointer;
}
.edit-icon:hover { border-color: var(--accent); color: var(--accent-dark); }
.edit-icon.is-editing { background: var(--accent-tint); border-color: var(--accent); color: var(--accent-dark); }
.edit-icon-abs { position: absolute; top: 0; right: 0; margin-left: 0; }

[contenteditable="true"] {
  outline: 1px dashed var(--accent); outline-offset: 2px; border-radius: 3px;
  background: #fbfffe;
}

/* ---------- header right + install + iOS hint ---------- */
.header-right { display: flex; align-items: center; gap: 8px; position: relative; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.ios-hint {
  font-size: 12px; color: var(--muted); background: var(--surface);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 8px 12px; margin: 0 0 16px;
}

/* ---------- info button + panel ---------- */
.info-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 50%;
  border: 1px solid var(--line-strong); background: #fff; color: var(--muted);
  cursor: pointer; flex-shrink: 0;
}
.info-btn:hover { border-color: var(--accent); color: var(--accent-dark); background: var(--accent-tint); }
.info-panel {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 20;
  width: 260px; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 12px; padding: 14px 16px; box-shadow: 0 6px 20px rgba(20, 24, 31, 0.12);
}
.info-panel-title { font-size: 13.5px; font-weight: 600; margin: 0 0 5px; }
.info-panel-body { font-size: 12.5px; color: var(--ink-2); line-height: 1.5; margin: 0 0 10px; }
.info-panel-link { font-size: 12.5px; font-weight: 500; color: var(--accent-dark); text-decoration: none; }
.info-panel-link:hover { text-decoration: underline; }

/* ---------- privacy (de-identify) step ---------- */
.privacy-lead { font-size: 13px; color: var(--ink-2); margin: 0 0 12px; line-height: 1.5; }
.chips { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 12.5px; background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: 8px; padding: 6px 8px 6px 11px; color: var(--ink);
}
.chip-empty { color: var(--muted); border-style: dashed; }
.chip-x {
  border: none; background: none; cursor: pointer; color: var(--muted);
  font-size: 16px; line-height: 1; padding: 0 2px; border-radius: 4px;
}
.chip-x:hover { color: var(--danger); background: var(--danger-tint); }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 500; margin-bottom: 5px; }
.field-hint { font-weight: 400; color: var(--muted); }
.text-input {
  width: 100%; border: 1px solid var(--line-strong); border-radius: var(--radius);
  padding: 10px 13px; font-size: 14px; color: var(--ink); background: #fff;
}
.text-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }

.add-id-row { display: flex; gap: 8px; }
.add-id-row .text-input { flex: 1; }

.err-msg {
  margin: 12px 0 0; padding: 10px 12px; font-size: 13px;
  color: var(--danger-dark); background: var(--danger-tint);
  border: 1px solid var(--danger); border-radius: var(--radius);
}

.demo-note {
  display: flex; align-items: flex-start; gap: 7px;
  font-size: 12.5px; color: #7a4d0c; background: #FAEEDA;
  border-radius: var(--radius); padding: 10px 12px; margin: 12px 0 0; line-height: 1.5;
}
.demo-note svg { color: #7a4d0c; flex-shrink: 0; margin-top: 1px; }

/* ============================================================
   PRINT — A4, black-and-white robust
   ============================================================ */
@media print {
  @page { size: A4 portrait; margin: 12mm 14mm; }

  body { background: #fff; }
  .app { display: none !important; }          /* hide all app chrome */

  .sheet {
    max-width: none; margin: 0; border: none; border-radius: 0;
    padding: 0; font-size: 11pt; color: #000;
  }
  .sheet[hidden] { display: block !important; } /* always print the handout */

  /* never print the quick-edit affordances or their focus/edit outline */
  .edit-icon { display: none !important; }
  [contenteditable] { outline: none !important; background: none !important; }

  /* keep blocks from splitting awkwardly across pages */
  .h-section, .h-redflag, .h-two, .goal, .cond { break-inside: avoid; }
  h2, h3, h4 { break-after: avoid; }

  /* ---- structure over colour: darken lines, drop tints ----
     Only for the "Print" button (real clinic printers, usually B&W).
     "Save as PDF" adds body.keep-color first, which skips this block
     entirely so the teal design survives for emailing. */
  body:not(.keep-color) .h-titleblock { border-bottom: 2pt solid #000; }
  body:not(.keep-color) .h-h { border-bottom: 1pt solid #444; }
  body:not(.keep-color) .h-ico, body:not(.keep-color) .h-mini-h svg,
  body:not(.keep-color) .cond-icon svg, body:not(.keep-color) .team-icon svg { color: #000; }
  body:not(.keep-color) .cond-icon { background: #fff; border: 1pt solid #555; }
  body:not(.keep-color) .mini-list a { color: #000; text-decoration: underline; }

  body:not(.keep-color) .h-review { background: #fff; border: 1.5pt solid #000; }
  body:not(.keep-color) .h-review-label, body:not(.keep-color) .h-review-when, body:not(.keep-color) .h-review-what { color: #000; }

  body:not(.keep-color) .goal { background: #fff; border: 1pt solid #555; }
  body:not(.keep-color) .goal-n { background: #000; color: #fff; }
  body:not(.keep-color) .goal-title, body:not(.keep-color) .goal-sub { color: #000; }

  body:not(.keep-color) .cond, body:not(.keep-color) .todo-wrap { border: 1pt solid #666; }
  body:not(.keep-color) .cond-text, body:not(.keep-color) .todo-item, body:not(.keep-color) .mini-list,
  body:not(.keep-color) .med-table td:not(:first-child), body:not(.keep-color) .h-meta, body:not(.keep-color) .h-intro { color: #111; }
  body:not(.keep-color) .todo-box { border: 1.5pt solid #000; }

  body:not(.keep-color) .med-table th { color: #000; border-bottom: 1.5pt solid #000; }
  body:not(.keep-color) .med-table td { border-bottom: .75pt solid #999; }

  /* red flag reads as URGENT without red ink: heavy black border + grey fill */
  body:not(.keep-color) .h-redflag { background: #f0f0f0; border: 2.5pt solid #000; }
  body:not(.keep-color) .rf-head, body:not(.keep-color) .rf-body, body:not(.keep-color) .rf-ico { color: #000; }

  body:not(.keep-color) .h-foot { border-top: 1pt solid #666; color: #333; }
}
