/* Care OS — mobile-first. Timeline rows are CSS grid; nothing overlaps (no absolute-positioned labels). */
:root {
  color-scheme: light dark;
  --bg: #f3f7f6; --surface: #ffffff; --ink: #14262b; --muted: #5b6d73; --line: #d6e2e3;
  --teal: #1f6b73; --teal-ink: #ffffff; --teal-soft: #e4f0f1;
  --alert: #c9252f; --alert-soft: #fff1f2; --ok: #2f7a63;
  --shadow: 0 1px 2px rgba(20,38,43,.06), 0 8px 24px rgba(20,38,43,.07);
  --radius: 16px; --tcol: 60px; --rail: 28px; --bar-h: 0px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1a1d; --surface: #15272b; --ink: #e9f2f3; --muted: #9bb0b5; --line: #2a4147;
    --teal: #6cc3cc; --teal-ink: #0d1a1d; --teal-soft: #1b3a40;
    --alert: #ff6f79; --alert-soft: #301b1f; --ok: #63c5a3; --shadow: none;
  }
}
@media (min-width: 480px) { :root { --tcol: 72px; } }

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
body {
  margin: 0; min-height: 100dvh; background: var(--bg); color: var(--ink);
  font-family: var(--font); line-height: 1.4; -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; border-radius: 8px; }

.screen {
  max-width: 640px; margin: 0 auto;
  padding: 0 max(12px, env(safe-area-inset-left)) calc(28px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-right));
}

/* ---------- Public (caregiver) view ---------- */
.bar {
  position: sticky; top: 0; z-index: 20;
  padding: calc(env(safe-area-inset-top) + 8px) 0 14px;
  background: linear-gradient(var(--bg) 72%, transparent);
}
.bar-card {
  display: flex; align-items: center; gap: 12px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px 6px 10px 14px; box-shadow: var(--shadow);
}
.live-dot { flex: none; width: 12px; height: 12px; border-radius: 50%; background: var(--alert); box-shadow: 0 0 0 5px color-mix(in srgb, var(--alert) 16%, transparent); animation: pulse 1.6s ease-in-out infinite; }
.bar.idle .live-dot { background: var(--ok); box-shadow: 0 0 0 5px color-mix(in srgb, var(--ok) 16%, transparent); animation: none; }
/* Current-time jump target: the live dot plus a readout of the clock, tappable
   to re-centre the timeline on whatever's happening now (or next). */
.bar-now { flex: none; display: flex; align-items: center; gap: 7px; cursor: pointer; }
.bar-time { font-size: 13px; font-weight: 800; color: var(--ink); white-space: nowrap; }
.bar-text { flex: 1; min-width: 0; }
.bar-patient { font-size: 12px; font-weight: 700; color: var(--muted); }
/* Next-Care-Event jump target: label + title together, tappable independently
   of the current-time dot so each status-bar element jumps to its own point
   on the timeline. */
.bar-next { cursor: pointer; }
.bar-label { font-size: 12px; font-weight: 700; color: var(--alert); margin-top: 1px; }
.bar.idle .bar-label { color: var(--ok); }
.bar-title { font-size: 17px; font-weight: 700; line-height: 1.25; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar.open .bar-title { white-space: normal; overflow: visible; }
.bar-chev { flex: none; width: 44px; height: 44px; display: grid; place-items: center; border: 0; background: transparent; color: var(--muted); border-radius: 12px; }
.bar-chev svg { transition: transform .2s; }
.bar.open .bar-chev svg { transform: rotate(180deg); }

.notice { margin: 0 0 12px; padding: 9px 12px; border-radius: 12px; background: var(--teal-soft); color: var(--ink); font-size: 13px; text-align: center; }
.hero { padding: 6px 4px 18px; text-align: center; }
.hero h1 { margin: 0 0 6px; font-size: clamp(26px, 7.5vw, 34px); line-height: 1.1; letter-spacing: -.02em; text-wrap: balance; overflow-wrap: anywhere; }
.hero p { margin: 0; color: var(--muted); font-size: 14px; }
.install-btn { margin-top: 12px; padding: 9px 16px; border-radius: 999px; border: 1px solid var(--teal); background: transparent; color: var(--teal); font-weight: 700; font-size: 14px; }

/* ---------- Timeline ---------- */
.timeline { list-style: none; margin: 0; padding: 0; }
.step { display: grid; grid-template-columns: var(--tcol) var(--rail) minmax(0, 1fr); scroll-margin-top: calc(var(--bar-h) + 16px); }
.time { padding-top: 14px; text-align: right; font-size: clamp(17px, 4.8vw, 20px); font-weight: 800; line-height: 24px; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.time small { display: block; margin-top: -3px; font-size: 13px; font-weight: 700; color: var(--muted); letter-spacing: 0; }
.rail { position: relative; }
.rail::before { content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 2px; margin-left: -1px; background: var(--line); }
.step:first-child .rail::before { top: 26px; }
.step:last-child .rail::before { bottom: auto; height: 26px; }
.step:only-child .rail::before { display: none; }
.dot { position: absolute; left: 50%; top: 18px; width: 16px; height: 16px; margin-left: -8px; border-radius: 50%; background: var(--surface); border: 3px solid var(--muted); z-index: 1; }
.body { padding-bottom: 12px; min-width: 0; }

.card {
  position: relative; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px 15px; transition: opacity .25s, background-color .25s;
}
.badge { display: none; margin: 0 0 6px; font-size: 12px; font-weight: 800; color: var(--alert); }
.taskNum { margin: 0 0 3px; font-size: 11.5px; font-weight: 800; letter-spacing: .04em; color: var(--muted); text-transform: uppercase; }
.step.now .taskNum, .step.next .taskNum { color: inherit; opacity: .75; }
.task { margin: 0; font-size: clamp(18px, 5vw, 20px); line-height: 1.3; font-weight: 600; letter-spacing: -.01em; overflow-wrap: anywhere; }

.meta { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 10px; margin-top: 12px; color: var(--teal); font-size: 13px; font-weight: 700; }
.chip { flex: none; padding: 4px 10px; border-radius: 999px; background: var(--teal-soft); }
.line { flex: 1 1 24px; min-width: 24px; height: 2px; background: currentColor; opacity: .5; position: relative; }
.line::after { content: ""; position: absolute; right: -1px; top: -4px; border-left: 7px solid currentColor; border-top: 5px solid transparent; border-bottom: 5px solid transparent; }
.ends { flex: none; color: var(--muted); font-weight: 600; }
.alarm-chip { background: color-mix(in srgb, var(--alert) 12%, transparent); color: var(--alert); }
.detail-toggle { margin-top: 10px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 999px; background: transparent; color: var(--teal); font-size: 12.5px; font-weight: 700; }
.detail-text { margin: 8px 0 0; padding: 10px 12px; background: var(--teal-soft); border-radius: 10px; font-size: 13px; color: var(--ink); line-height: 1.5; white-space: pre-wrap; }

.between { display: flex; justify-content: center; align-items: center; gap: 8px; padding: 10px 0 0; color: var(--muted); font-size: 13px; }
.between b { font-size: 16px; font-weight: 400; line-height: 1; }
.step:last-child .body { padding-bottom: 4px; }

/* states (public only) */
.step.done .card { opacity: .58; }
.step.done .time { color: var(--muted); }
.step.done .dot { background: var(--teal); border-color: var(--teal); }
.step.done .dot::after { content: ""; position: absolute; left: 2px; top: -1px; width: 4px; height: 8px; border: solid var(--teal-ink); border-width: 0 2px 2px 0; transform: rotate(45deg); }
.step.now .dot, .step.next .dot { background: var(--alert); border-color: var(--surface); box-shadow: 0 0 0 2px var(--alert), 0 0 0 7px color-mix(in srgb, var(--alert) 16%, transparent); animation: pulse 1.6s ease-in-out infinite; }
.step.now .card, .step.next .card { border: 2px solid var(--alert); background: var(--alert-soft); padding: 13px 15px 14px; box-shadow: 0 8px 26px color-mix(in srgb, var(--alert) 16%, transparent); }
.step.now .badge, .step.next .badge { display: block; }
.step.now .chip, .step.next .chip { background: color-mix(in srgb, var(--alert) 14%, transparent); color: var(--alert); }
.step.now .meta, .step.next .meta { color: var(--alert); }
.step.now .task, .step.next .task { font-weight: 750; }
/* when a task is in progress, the following one is only "up next" (quieter) */
.has-now .step.next .dot { background: var(--surface); border-color: var(--teal); box-shadow: none; animation: none; }
.has-now .step.next .card { border: 1px solid var(--teal); background: var(--surface); box-shadow: none; padding: 14px 16px 15px; }
.has-now .step.next .badge { color: var(--teal); }
.has-now .step.next .chip { background: var(--teal-soft); color: var(--teal); }
.has-now .step.next .meta { color: var(--teal); }
.has-now .step.next .task { font-weight: 600; }
.has-warn .card { border-style: dashed; }
.warn { margin: 8px 0 0; font-size: 12px; font-weight: 700; color: var(--alert); }

.jump { position: fixed; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 30; padding: 12px 20px; border-radius: 999px; border: 0; background: var(--ink); color: var(--bg); font-weight: 700; font-size: 15px; box-shadow: 0 8px 24px rgba(0,0,0,.25); }

.sk { height: 92px; margin: 0 0 14px 0; border-radius: var(--radius); background: var(--line); opacity: .5; animation: shimmer 1.4s ease-in-out infinite; }
.sk:nth-child(2) { animation-delay: .15s; } .sk:nth-child(3) { animation-delay: .3s; }
.empty { text-align: center; color: var(--muted); padding: 40px 12px; }
.empty h2 { color: var(--ink); margin: 0 0 6px; font-size: 20px; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }
@keyframes shimmer { 0%, 100% { opacity: .35; } 50% { opacity: .65; } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; scroll-behavior: auto !important; } }

/* ---------- Editor (family) ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); padding: calc(env(safe-area-inset-top) + 10px) 0 10px; }
.topbar .in { max-width: 1080px; margin: 0 auto; padding: 0 max(14px, env(safe-area-inset-left)); display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 18px; letter-spacing: -.02em; }
.brand img { width: 28px; height: 28px; border-radius: 8px; }
.topbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.session-info { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); }
.session-email { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.session-signout { background: none; border: none; padding: 2px 6px; font-size: 12px; color: var(--teal); cursor: pointer; border-radius: 6px; }
.session-signout:hover { background: var(--teal-soft); }
.pill { font-size: 12px; font-weight: 700; padding: 5px 10px; border-radius: 999px; background: var(--teal-soft); color: var(--teal); white-space: nowrap; }
.pill[data-kind="dirty"] { background: color-mix(in srgb, var(--alert) 14%, transparent); color: var(--alert); }

.editor { max-width: 1080px; margin: 0 auto; padding: 14px max(14px, env(safe-area-inset-left)) calc(110px + env(safe-area-inset-bottom)); }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin-bottom: 14px; background: var(--teal-soft); border-radius: 14px; }
.seg button { padding: 10px; border: 0; border-radius: 10px; background: transparent; font-weight: 700; color: var(--muted); }
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.subseg { display: flex; gap: 4px; padding: 3px; margin: 2px 0 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; }
.subseg button { flex: 1; padding: 8px 6px; border: 0; border-radius: 9px; background: transparent; font-weight: 700; font-size: 13px; color: var(--muted); }
.subseg button[aria-selected="true"] { background: var(--teal-soft); color: var(--teal); }
.schedtab-panels textarea { min-height: 32dvh; }
.cols { display: grid; gap: 14px; }
.editor[data-tab="edit"] .preview { display: none; }
.editor[data-tab="preview"] .form { display: none; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; padding: 16px; }
.panel + .panel { margin-top: 14px; }
.panel h2 { margin: 0 0 12px; font-size: 15px; }
.field { display: block; margin: 0 0 14px; }
.field > span { display: block; margin: 0 0 6px; font-size: 13px; font-weight: 700; color: var(--muted); }
.two { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
input, textarea { width: 100%; padding: 12px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); font-size: 16px; }
input:focus, textarea:focus { outline: 2px solid var(--teal); outline-offset: 0; border-color: transparent; }
textarea { min-height: 42dvh; resize: vertical; font: 14px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre; overflow: auto; }
.hint { margin: 8px 0 0; font-size: 12.5px; color: var(--muted); }
.hint code { font-family: ui-monospace, Menlo, monospace; background: var(--teal-soft); padding: 1px 5px; border-radius: 5px; }
.hint.bad { color: var(--alert); font-weight: 700; }
.linkrow { display: flex; gap: 8px; flex-wrap: wrap; }
.linkrow input { flex: 1 1 100%; font-size: 13px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); font-weight: 700; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--teal); border-color: var(--teal); color: var(--teal-ink); }
.btn:disabled { opacity: .6; cursor: default; }
.btn.grow { flex: 1; }
.danger { margin-top: 18px; text-align: center; }
.danger button { border: 0; background: none; color: var(--muted); font-size: 13px; text-decoration: underline; padding: 10px; }
.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 25; background: color-mix(in srgb, var(--bg) 94%, transparent); backdrop-filter: blur(10px); border-top: 1px solid var(--line); padding: 10px max(14px, env(safe-area-inset-left)) calc(10px + env(safe-area-inset-bottom)); }
.actionbar .in { max-width: 1080px; margin: 0 auto; display: flex; gap: 10px; }
.preview .public-frame { max-width: 460px; margin: 0 auto; }
.preview-tag { text-align: center; font-size: 12px; font-weight: 700; color: var(--muted); margin: 0 0 6px; }

.toast { position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translate(-50%, 12px); z-index: 40; max-width: min(92vw, 420px); padding: 11px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); font-size: 14px; font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-kind="error"] { background: var(--alert); color: #fff; }

.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; text-align: center; background: var(--surface); border: 1px solid var(--line); border-radius: 24px; padding: 32px 24px; box-shadow: var(--shadow); }
.auth-card img { width: 64px; height: 64px; border-radius: 16px; }
.auth-card h1 { margin: 16px 0 8px; font-size: 26px; letter-spacing: -.02em; }
.auth-card p { margin: 0 0 20px; color: var(--muted); font-size: 15px; }
.auth-card .btn { width: 100%; min-height: 52px; font-size: 16px; }
.auth-card .fine { margin: 16px 0 0; font-size: 12.5px; }
.auth-card .row { display: flex; gap: 8px; margin-top: 10px; }
.auth-card .row .btn { flex: 1; }
.auth-card .field { text-align: left; margin: 0 0 14px; }

@media (min-width: 900px) {
  .seg { display: none; }
  .cols { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .editor[data-tab] .preview, .editor[data-tab] .form { display: block; }
  .preview { position: sticky; top: 76px; }
  .two { grid-template-columns: 1fr 180px; }
  .actionbar .in { justify-content: flex-end; }
  .btn.grow { flex: none; min-width: 160px; }
}

/* event details under the name: always fully shown, body size, on a tonal surface so they stand apart from the name */
.event-details { margin-top: 10px; padding: 12px; background: var(--teal-soft); border-radius: 12px; font-size: 16px; line-height: 1.45; color: var(--ink); }
.ed-task { margin: 0 0 4px; font-weight: 700; font-size: 14px; color: var(--muted); }
.ed-row { display: flex; gap: 6px; margin-top: 8px; }
.ed-row:first-child { margin-top: 0; }
.ed-num { min-width: 24px; color: var(--muted); font-weight: 700; }
.ed-kind { display: block; font-weight: 700; }
.ed-note { margin: 0; white-space: pre-wrap; }
.open-app { margin: 12px 16px 0; display: flex; }
.open-app .btn { flex: 1; }
