/* Caregiving web UI — mobile-first, usable one-handed on a phone. */
:root {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #eef2f0;
  --ink: #1d2522;
  --ink-soft: #5c6b65;
  --ink-faint: #8a988f;
  --line: #dde4e0;
  --brand: #2f6f5e;
  --brand-ink: #ffffff;
  --brand-soft: #e3efe9;
  --danger: #c0392b;
  --warn: #c77c20;
  --amber: #b59020;
  --ok: #2f8f5e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 40, 33, .06), 0 6px 18px rgba(20, 40, 33, .06);
  --maxw: 680px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
/* A display: rule on a class beats the UA [hidden] rule, so enforce hidden explicitly. */
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand); text-decoration: none; }
button { font: inherit; cursor: pointer; }

.loading { padding: 4rem 1rem; text-align: center; color: var(--ink-faint); }

/* ── App shell ────────────────────────────────────────────────────────────── */
.appbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--brand); color: var(--brand-ink);
  padding: calc(env(safe-area-inset-top) + .7rem) 1rem .7rem;
  display: flex; align-items: center; gap: .6rem;
  box-shadow: var(--shadow);
}
.appbar .back {
  background: rgba(255,255,255,.16); color: #fff; border: 0;
  width: 2rem; height: 2rem; border-radius: 50%; font-size: 1.1rem;
  display: grid; place-items: center; flex: 0 0 auto;
}
.appbar h1 { font-size: 1.1rem; margin: 0; flex: 1; font-weight: 650; letter-spacing: .2px; }
.appbar .who { font-size: .78rem; opacity: .85; text-align: right; line-height: 1.2; }
.appbar .logout {
  background: transparent; color: #fff; border: 1px solid rgba(255,255,255,.4);
  padding: .3rem .6rem; border-radius: 999px; font-size: .78rem;
}

/* Top nav — horizontally scrollable on narrow phones. */
.nav {
  position: sticky; top: 0; z-index: 15;
  display: flex; gap: .25rem; overflow-x: auto; -webkit-overflow-scrolling: touch;
  background: var(--surface); border-bottom: 1px solid var(--line);
  padding: .4rem .6rem;
}
.nav a {
  white-space: nowrap; padding: .35rem .8rem; border-radius: 999px;
  color: var(--ink-soft); font-size: .9rem; font-weight: 600;
}
.nav a.on { background: var(--brand-soft); color: var(--brand); }

.wrap { max-width: var(--maxw); margin: 0 auto; padding: 1rem; padding-bottom: 3rem; }

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem; margin-bottom: 1rem;
}
.card-link { display: block; color: inherit; }
.card-link:active { transform: scale(.992); }

.person-head { display: flex; align-items: baseline; gap: .5rem; flex-wrap: wrap; }
.person-head .name { font-size: 1.15rem; font-weight: 650; }
.person-head .rel { color: var(--ink-soft); font-size: .9rem; }

.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }
.tiny { font-size: .8rem; }
.row { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.stack > * + * { margin-top: .35rem; }

/* ── Badges & chips ───────────────────────────────────────────────────────── */
.badge {
  display: inline-block; font-size: .72rem; font-weight: 650; letter-spacing: .3px;
  padding: .15rem .5rem; border-radius: 999px; text-transform: uppercase;
  background: var(--surface-2); color: var(--ink-soft);
}
.badge.level-active { background: #fbe5e1; color: var(--danger); }
.badge.level-observational { background: #e2ecf7; color: #2f5e8f; }
.badge.level-self { background: var(--surface-2); color: var(--ink-soft); }

.chip {
  display: inline-flex; align-items: center; gap: .3rem; font-size: .76rem; font-weight: 600;
  padding: .2rem .55rem; border-radius: 999px; background: var(--surface-2); color: var(--ink-soft);
}
.chip.u-urgent { background: #fbe2de; color: var(--danger); }
.chip.u-high   { background: #fdeede; color: var(--warn); }
.chip.u-medium { background: #fcf6df; color: var(--amber); }
.chip.u-low    { background: var(--surface-2); color: var(--ink-soft); }
.chip.ok       { background: #e2f2ea; color: var(--ok); }

.dot { width: .55rem; height: .55rem; border-radius: 50%; display: inline-block; }
.dot.OK { background: var(--ok); }
.dot.Low { background: var(--amber); }
.dot.Out { background: var(--danger); }
.dot.Unknown { background: var(--ink-faint); }

/* ── Attention list ───────────────────────────────────────────────────────── */
.attn { list-style: none; margin: .5rem 0 0; padding: 0; }
.attn li {
  display: flex; gap: .5rem; align-items: flex-start; padding: .45rem 0;
  border-top: 1px solid var(--line); font-size: .92rem;
}
.attn li:first-child { border-top: 0; }
.attn .u-pill {
  flex: 0 0 auto; margin-top: .15rem; width: .55rem; height: .55rem; border-radius: 50%;
}
.u-pill.u-urgent { background: var(--danger); }
.u-pill.u-high { background: var(--warn); }
.u-pill.u-medium { background: var(--amber); }
.u-pill.u-low { background: var(--ink-faint); }

/* ── Section blocks (person detail) ───────────────────────────────────────── */
.section { margin-top: 1.4rem; }
.section > h2 {
  font-size: .82rem; text-transform: uppercase; letter-spacing: .6px;
  color: var(--ink-faint); margin: 0 0 .5rem .15rem;
}
.list { list-style: none; margin: 0; padding: 0; }
.list > li { padding: .6rem 0; border-top: 1px solid var(--line); }
.list > li:first-child { border-top: 0; }
.kvs { display: grid; grid-template-columns: auto 1fr; gap: .15rem .8rem; font-size: .92rem; }
.kvs dt { color: var(--ink-faint); }
.kvs dd { margin: 0; }

.empty { color: var(--ink-faint); font-size: .9rem; font-style: italic; }

.log-text { white-space: pre-wrap; }
.log-meta { color: var(--ink-faint); font-size: .78rem; margin-top: .15rem; }

.supply { display: flex; align-items: center; gap: .6rem; }
.supply .nm { flex: 1; }
.supply .qty { font-variant-numeric: tabular-nums; color: var(--ink-soft); font-size: .88rem; }
.supply .run { font-size: .76rem; color: var(--ink-faint); }

/* ── Forms / buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  background: var(--brand); color: var(--brand-ink); border: 0;
  padding: .65rem 1rem; border-radius: 10px; font-weight: 650; font-size: .95rem;
}
.btn:disabled { opacity: .55; }
.btn.ghost { background: var(--brand-soft); color: var(--brand); }
.btn.block { width: 100%; }
.btn.sm { padding: .4rem .7rem; font-size: .82rem; border-radius: 8px; }

label.field { display: block; margin-bottom: .7rem; }
label.field > span { display: block; font-size: .82rem; color: var(--ink-soft); margin-bottom: .25rem; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 10px;
  padding: .6rem .7rem;
}
textarea { resize: vertical; min-height: 5.5rem; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--brand); border-color: var(--brand); }

.error { color: var(--danger); font-size: .88rem; margin: .4rem 0; min-height: 1.1rem; }

/* ── Login ────────────────────────────────────────────────────────────────── */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 1.5rem; }
.login-card { width: 100%; max-width: 360px; }
.login-card .brandmark { text-align: center; margin-bottom: 1rem; }
.login-card .brandmark .logo { font-size: 2.4rem; }
.login-card .brandmark h1 { font-size: 1.25rem; margin: .2rem 0 0; }
.login-card .brandmark p { margin: .15rem 0 0; color: var(--ink-faint); font-size: .85rem; }

.toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: 999px;
  font-size: .88rem; box-shadow: var(--shadow); z-index: 50; max-width: 90vw;
}

/* ── Phase 7b additions ───────────────────────────────────────────────────── */
.form-h { font-size: .82rem; text-transform: uppercase; letter-spacing: .6px; color: var(--ink-faint); margin: 0 0 .6rem; }

/* Attachment thumbnails */
.thumbs { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .5rem; }
.thumb { width: 84px; height: 84px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); display: block; }

/* Inline supply quantity editor */
.sup-edit { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.sup-edit input { width: 6.5rem; padding: .4rem .5rem; }

/* Two-column form grid (admin) — collapses to one column on small screens */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .8rem; }
@media (max-width: 460px) { .grid2 { grid-template-columns: 1fr; } }

/* Revoke (×) button inside a chip */
.chip .x { background: transparent; border: 0; color: inherit; font-size: 1rem; line-height: 1; padding: 0 0 0 .15rem; opacity: .7; }
.chip .x:hover { opacity: 1; }

select.sm, input.sm { padding: .35rem .5rem; font-size: .85rem; border-radius: 8px; width: auto; }
