:root {
  --bg: #f7f5f1;
  --surface: #ffffff;
  --surface-2: #f1eee8;
  --ink: #1f2a2e;
  --ink-2: #56656b;
  --ink-3: #8a979c;
  --line: #e4dfd6;
  --accent: #0f766e;
  --accent-ink: #ffffff;
  --accent-soft: #dff1ee;
  --warm: #c2410c;
  --warm-soft: #fdeadf;
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --star: #e0a100;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 42, 46, .06), 0 6px 20px rgba(31, 42, 46, .06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12181a; --surface: #1a2225; --surface-2: #222c30; --ink: #e8eef0; --ink-2: #a9b6bb; --ink-3: #74838a;
    --line: #2c383c; --accent: #2bb3a5; --accent-ink: #062a27; --accent-soft: #143633; --warm: #f08a4b; --warm-soft: #3a2418;
    --danger: #f2766b; --danger-soft: #3b1d1a; --shadow: 0 1px 2px rgba(0,0,0,.3), 0 6px 20px rgba(0,0,0,.25);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: inherit; }
img, video { display: block; max-width: 100%; }
h1, h2, h3 { line-height: 1.2; margin: 0; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: baseline; gap: 8px; text-decoration: none; font-weight: 700; font-size: 17px; }
.brand small { font-weight: 500; color: var(--ink-3); font-size: 13px; }
main { max-width: 1120px; margin: 0 auto; padding: 24px 24px 80px; }

/* ---------- controls ---------- */
button, .btn { font: inherit; font-weight: 600; border: 1px solid transparent; border-radius: 10px; padding: 9px 16px; cursor: pointer;
  background: var(--accent); color: var(--accent-ink); text-decoration: none; display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
button:hover, .btn:hover { filter: brightness(1.06); }
button.ghost, .btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
button.ghost:hover { background: var(--surface-2); filter: none; }
button.danger { background: transparent; color: var(--danger); border-color: var(--danger-soft); }
button.danger:hover { background: var(--danger-soft); }
button.small, .btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 80px; }
label { display: grid; gap: 5px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--ink-3); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-2); }
.chip.accent { background: var(--accent-soft); color: var(--accent); }
.chip.warm { background: var(--warm-soft); color: var(--warm); }
.chip.danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- home ---------- */
.page-head { display: flex; align-items: end; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 28px; }
.page-head .search { max-width: 280px; }
.filters { display: flex; gap: 6px; margin-bottom: 18px; flex-wrap: wrap; }
.filters button { background: transparent; color: var(--ink-2); border-color: var(--line); padding: 5px 12px; font-size: 13px; }
.filters button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 18px; }
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; text-decoration: none; display: flex; flex-direction: column;
  transition: transform .15s ease; }
.card:hover { transform: translateY(-2px); }
.card .cover { aspect-ratio: 4/3; background: var(--surface-2) center/cover; display: grid; place-items: center; font-size: 44px; position: relative; }
.card .cover .day { position: absolute; left: 10px; bottom: 10px; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; }
.card .body { padding: 12px 14px 14px; display: grid; gap: 4px; }
.card h3 { font-size: 17px; }
.card .meta { font-size: 13px; color: var(--ink-2); }
.empty { text-align: center; padding: 70px 20px; color: var(--ink-2); background: var(--surface); border-radius: var(--radius); border: 1px dashed var(--line); }
.empty .big { font-size: 48px; }
.empty h2 { margin: 10px 0 6px; color: var(--ink); }

/* ---------- patient ---------- */
.back { display: inline-block; color: var(--ink-2); text-decoration: none; font-size: 14px; margin-bottom: 14px; }
.hero { display: grid; grid-template-columns: 200px 1fr; gap: 24px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.hero .avatar { width: 200px; aspect-ratio: 1; border-radius: 12px; background: var(--surface-2) center/cover; display: grid; place-items: center; font-size: 64px; }
.hero h1 { font-size: 30px; }
.facts { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 20px; margin: 14px 0; }
.facts div { font-size: 14px; }
.facts dt { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
.facts dd { margin: 0; font-weight: 500; }
.progress { margin-top: 6px; }
.progress .bar { height: 8px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress .bar i { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.progress .lbl { display: flex; justify-content: space-between; font-size: 12px; color: var(--ink-3); margin-top: 4px; }

.section-head { display: flex; align-items: center; gap: 10px; margin: 32px 0 14px; flex-wrap: wrap; }
.section-head h2 { font-size: 20px; }

.timeline { position: relative; padding-left: 28px; }
.timeline::before { content: ""; position: absolute; left: 9px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.tl-item { position: relative; margin-bottom: 18px; }
.tl-item::before { content: ""; position: absolute; left: -24px; top: 18px; width: 12px; height: 12px; border-radius: 50%; background: var(--accent); border: 3px solid var(--bg); }
.tl-item.concern::before { background: var(--danger); }
.tl-item.guide::before { background: var(--bg); border: 2px dashed var(--ink-3); width: 10px; height: 10px; left: -23px; top: 8px; }
.tl-item.guide { color: var(--ink-3); font-size: 13px; margin-bottom: 12px; padding-top: 2px; }
.tl-item.guide b { color: var(--ink-2); font-weight: 600; }
.tl-item.guide.done { text-decoration: line-through; opacity: .7; }
.tl-item.today { font-size: 12px; font-weight: 700; color: var(--warm); text-transform: uppercase; letter-spacing: .05em; }
.tl-item.today::before { background: var(--warm); }
.entry { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px 16px; }
.entry.concern { box-shadow: inset 3px 0 0 var(--danger), var(--shadow); }
.entry header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.entry .when { font-weight: 700; }
.entry .date { color: var(--ink-3); font-size: 13px; }
.entry h3 { font-size: 16px; margin-top: 6px; }
.entry p { margin: 6px 0 0; white-space: pre-wrap; color: var(--ink-2); }
.entry .actions { margin-left: auto; display: flex; gap: 4px; }
.entry .actions button { padding: 3px 8px; font-size: 12px; }
.media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 8px; margin-top: 12px; }
.thumb { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: var(--surface-2); cursor: zoom-in; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; }
.thumb .play { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 30px; text-shadow: 0 2px 8px rgba(0,0,0,.5); pointer-events: none; }
.thumb .star { position: absolute; top: 6px; right: 6px; width: 30px; height: 30px; border-radius: 50%; border: 0; padding: 0; justify-content: center;
  background: rgba(0,0,0,.45); color: #fff; font-size: 16px; }
.thumb .star.on { background: var(--star); }
.thumb .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 14px 8px 6px; font-size: 12px; color: #fff; background: linear-gradient(transparent, rgba(0,0,0,.7)); }

/* ---------- dialogs ---------- */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(620px, calc(100vw - 32px)); background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(15, 20, 22, .55); }
dialog form { padding: 22px; display: grid; gap: 14px; }
dialog h2 { font-size: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.drop { border: 2px dashed var(--line); border-radius: 12px; padding: 22px; text-align: center; color: var(--ink-2); cursor: pointer; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop input { display: none; }
.pending { display: grid; grid-template-columns: repeat(auto-fill, minmax(80px, 1fr)); gap: 6px; }
.pending .p { position: relative; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--surface-2); font-size: 11px; }
.pending .p img, .pending .p video { width: 100%; height: 100%; object-fit: cover; }
.pending .p .x { position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; padding: 0; justify-content: center; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; font-size: 12px; }
.pending .p .prog { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); width: 0; transition: width .2s; }
.dialog-actions { display: flex; gap: 8px; justify-content: flex-end; }

/* ---------- lightbox ---------- */
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(8, 10, 11, .94); display: grid; grid-template-rows: 1fr auto; color: #fff; }
.lightbox .stage { display: grid; place-items: center; min-height: 0; padding: 20px 60px; }
.lightbox .stage img, .lightbox .stage video { max-height: calc(100vh - 170px); max-width: 100%; border-radius: 8px; }
.lightbox .bar { padding: 14px 20px 20px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; max-width: 900px; width: 100%; margin: 0 auto; }
.lightbox .bar input { background: rgba(255,255,255,.08); border-color: rgba(255,255,255,.15); color: #fff; flex: 1; min-width: 200px; }
.lightbox .bar button.ghost { color: #fff; border-color: rgba(255,255,255,.2); }
.lightbox .nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(255,255,255,.1); color: #fff; border-radius: 50%; width: 44px; height: 44px; justify-content: center; padding: 0; font-size: 20px; }
.lightbox .nav.prev { left: 10px; } .lightbox .nav.next { right: 10px; }
.lightbox .close { position: absolute; top: 12px; right: 12px; background: rgba(255,255,255,.1); color: #fff; border-radius: 50%; width: 40px; height: 40px; padding: 0; justify-content: center; }

/* ---------- story ---------- */
.story-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 18px; }
.story { max-width: 820px; margin: 0 auto; font-family: var(--serif); }
.story .cover { position: relative; border-radius: 22px; overflow: hidden; min-height: 460px; background: #20302f center/cover; display: flex; align-items: flex-end; color: #fff; }
.story .cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0,0,0,0) 35%, rgba(0,0,0,.75)); }
.story .cover .txt { position: relative; z-index: 1; padding: 36px; }
.story .cover .kicker { font-family: var(--font); text-transform: uppercase; letter-spacing: .14em; font-size: 12px; font-weight: 700; opacity: .85; }
.story .cover h1 { font-size: 52px; margin: 8px 0; font-weight: 600; }
.story .cover p { font-size: 18px; margin: 0; opacity: .9; }
.story .intro { font-size: 20px; line-height: 1.6; margin: 36px 0 10px; color: var(--ink-2); text-align: center; }
.chapter { margin: 56px 0 0; }
.chapter > h2 { font-family: var(--font); font-size: 13px; letter-spacing: .14em; text-transform: uppercase; color: var(--accent); display: flex; align-items: center; gap: 12px; }
.chapter > h2::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.moment { margin-top: 26px; }
.moment h3 { font-size: 26px; font-weight: 600; margin-bottom: 4px; }
.moment .sub { font-family: var(--font); color: var(--ink-3); font-size: 13px; margin-bottom: 12px; }
.moment p { font-size: 18px; line-height: 1.65; margin: 10px 0; }
.moment .pics { display: grid; gap: 8px; grid-template-columns: repeat(2, 1fr); }
.moment .pics.n1 { grid-template-columns: 1fr; }
.moment .pics.n3 > :first-child { grid-column: 1 / -1; }
.moment figure { margin: 0; }
.moment figure img, .moment figure video { width: 100%; border-radius: 12px; max-height: 560px; object-fit: cover; background: var(--surface-2); }
.moment .pics.n1 figure img { object-fit: contain; }
.moment figcaption { font-family: var(--font); font-size: 13px; color: var(--ink-2); margin-top: 5px; }
.finale { text-align: center; margin: 70px 0 30px; padding: 40px 20px; border-radius: 22px; background: var(--accent-soft); }
.finale .big { font-size: 46px; }
.finale h2 { font-size: 32px; font-weight: 600; margin: 6px 0; }
.finale p { font-family: var(--font); color: var(--ink-2); margin: 0; }

/* slideshow */
.show { position: fixed; inset: 0; z-index: 60; background: #000; color: #fff; display: grid; place-items: center; overflow: hidden; }
.show .slide { position: absolute; inset: 0; display: grid; place-items: center; animation: fade .7s ease; }
.show .slide img, .show .slide video { max-width: 100%; max-height: 100%; object-fit: contain; }
.show .slide img.kb { animation: kenburns 6s ease-out forwards; }
.show .title-card { text-align: center; padding: 30px; font-family: var(--serif); }
.show .title-card h1 { font-size: clamp(36px, 7vw, 76px); font-weight: 600; margin: 10px 0; }
.show .title-card p { font-size: 20px; opacity: .8; margin: 0; font-family: var(--font); }
.show .caption { position: absolute; left: 0; right: 0; bottom: 0; padding: 60px 40px 34px; background: linear-gradient(transparent, rgba(0,0,0,.8)); font-family: var(--serif); }
.show .caption .d { font-family: var(--font); text-transform: uppercase; letter-spacing: .14em; font-size: 13px; font-weight: 700; color: #7ee0d4; }
.show .caption .t { font-size: clamp(22px, 3.4vw, 36px); margin-top: 4px; }
.show .controls { position: absolute; top: 14px; right: 14px; display: flex; gap: 8px; z-index: 2; }
.show .controls button { background: rgba(255,255,255,.14); color: #fff; }
.show .dots { position: absolute; top: 0; left: 0; right: 0; display: flex; gap: 3px; padding: 6px; z-index: 2; }
.show .dots i { flex: 1; height: 3px; background: rgba(255,255,255,.25); border-radius: 2px; }
.show .dots i.on { background: #fff; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes kenburns { from { transform: scale(1); } to { transform: scale(1.07); } }

#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 10px;
  font-weight: 600; opacity: 0; pointer-events: none; transition: .25s; z-index: 100; }
#toast.on { opacity: 1; transform: translateX(-50%); }

@media (max-width: 700px) {
  main { padding: 16px 16px 60px; }
  .topbar { padding: 10px 16px; }
  .hero { grid-template-columns: 1fr; }
  .hero .avatar { width: 100%; aspect-ratio: 16/10; }
  .form-grid { grid-template-columns: 1fr; }
  .story .cover { min-height: 340px; }
  .story .cover h1 { font-size: 36px; }
  .lightbox .stage { padding: 20px 10px; }
}
@media print {
  .topbar, .story-tools, .back, #toast { display: none !important; }
  body { background: #fff; color: #000; }
  main { padding: 0; max-width: none; }
  .moment, .story .cover { break-inside: avoid; }
  .moment video { display: none; }
}

/* ---------- weekly backup reminder ---------- */
.banner { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 0 0 18px; padding: 12px 14px;
  background: var(--warm-soft); color: var(--ink); border: 1px solid var(--warm); border-radius: var(--radius); }
.banner[hidden] { display: none; }
.warn-text { color: var(--warm); font-weight: 600; }

/* ---------- clinic logo over photos/videos in the story and slideshow ---------- */
.wm-wrap { position: relative; }
.wm-corner { position: absolute; display: flex; gap: 2%; width: 100%; pointer-events: none; z-index: 2; padding: 0 3%; box-sizing: border-box; }
.wm-corner.br, .wm-corner.tr { justify-content: flex-end; }
.wm-corner.bl, .wm-corner.tl { justify-content: flex-start; }
.wm-corner.br, .wm-corner.bl { bottom: 3%; align-items: flex-end; }
.wm-corner.tr, .wm-corner.tl { top: 3%; align-items: flex-start; }
.wm-corner.br, .wm-corner.tr { flex-direction: row-reverse; justify-content: flex-start; } /* logo 1 nearest the corner */
.wm-wrap { container-type: inline-size; }
/* every logo gets the same height, so two logos look the same size (very wide ones capped in width) */
.wm-corner .wm { height: 8cqw !important; width: auto !important; max-width: 24cqw; min-width: 0; opacity: .9;
  border-radius: 0 !important; background: none !important; object-fit: contain !important; }
.show > .wm-corner { top: 4%; bottom: auto; }
.show > .wm-corner .wm { height: min(7vw, 90px) !important; max-width: min(21vw, 270px); }
.hero .avatar { position: relative; cursor: pointer; overflow: hidden; }
.avatar-btn { position: absolute; left: 8px; right: 8px; bottom: 8px; font-size: 13px; font-weight: 600; text-align: center; padding: 6px 8px;
  border-radius: 8px; background: rgba(0,0,0,.55); color: #fff; opacity: 0; transition: opacity .15s; }
.hero .avatar:hover .avatar-btn, .hero .avatar:focus-within .avatar-btn { opacity: 1; }
.hero .avatar:not([style*="background-image"]) .avatar-btn { opacity: 1; }
@media (hover: none) { .avatar-btn { opacity: 1; } }
