/* Mobile-first, designed at 375px. One-handed, thumb-only: primary actions
   are big, low on the screen, and never require drag or long-press. */

:root {
  --bg: #f7f6f3;
  --card: #ffffff;
  --ink: #26241f;
  --muted: #6f6a60;
  --line: #e3e0d8;
  --accent: #2f6f4f;
  --accent-ink: #ffffff;
  --danger: #a4463c;
  --warn-bg: #fdf3e4;
  --good: #2f6f4f;
  --radius: 12px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 17px;
  line-height: 1.45;
  color: var(--ink);
  background: var(--bg);
}

main { padding: 0 0 84px; }  /* room for the bottom nav */

.page { max-width: 560px; margin: 0 auto; padding: 16px; }

h1 { font-size: 1.35rem; margin: 8px 0 16px; }
h2 { font-size: 1.02rem; margin: 22px 0 10px; color: var(--muted); font-weight: 600; }
h3 { font-size: 0.92rem; margin: 14px 0 8px; color: var(--muted); font-weight: 600; }

.loc { color: var(--muted); font-weight: 400; margin-left: 6px; }
.meta { color: var(--muted); font-size: 0.9rem; margin: 4px 0; }
.label { color: var(--muted); font-size: 0.9rem; margin: 14px 0 6px; }
.hint { color: var(--muted); font-weight: 400; font-size: 0.85rem; }
.empty { color: var(--muted); }
.error { color: var(--danger); font-size: 0.92rem; margin: 4px 0; }
.ok { color: var(--good); font-size: 0.92rem; margin: 4px 0; }

/* ── Red-flag line: calm, one sentence, dismissible ── */
.red-flag {
  background: var(--warn-bg);
  border: 1px solid #ecd9b8;
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  align-items: center;
}
.red-flag .dismiss {
  margin-left: auto;
  border: 0; background: none; font-size: 1.3rem; color: var(--muted);
  min-width: 44px; min-height: 44px; cursor: pointer;
}

/* ── Bottom nav ── */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottom-nav a {
  flex: 1; text-align: center; padding: 14px 0; min-height: 48px;
  text-decoration: none; color: var(--muted); font-weight: 600; font-size: 0.95rem;
}
.bottom-nav a.active { color: var(--accent); }

/* ── Buttons ── */
button, .btn-primary, .btn-quick, .chip { font: inherit; }

.btn-primary {
  display: block; width: 100%;
  margin: 18px 0 6px;
  padding: 14px;
  min-height: 52px;
  border: 0; border-radius: var(--radius);
  background: var(--accent); color: var(--accent-ink);
  font-size: 1.08rem; font-weight: 700; text-align: center;
  text-decoration: none; cursor: pointer;
}

.quick-grid, .joint-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px;
}
.btn-quick {
  display: flex; align-items: center; justify-content: center;
  min-height: 56px; padding: 8px 12px;
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  color: var(--ink); font-weight: 600; text-align: center;
  text-decoration: none; cursor: pointer;
}
.btn-more { color: var(--muted); }
.btn-good.is-on { background: var(--good); color: #fff; border-color: var(--good); }

.btn-secondary {
  display: block; width: 100%;
  margin: 6px 0;
  padding: 14px;
  min-height: 52px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--card); color: var(--ink);
  font: inherit; font-size: 1.08rem; font-weight: 600; text-align: center;
  text-decoration: none; cursor: pointer;
}

/* ── Account menu (top-right dropdown) ── */
.account-menu { position: fixed; top: 6px; right: 6px; z-index: 50; }
.account-menu > summary {
  list-style: none; cursor: pointer;
  width: 40px; height: 40px;
  display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 1.4rem; line-height: 1;
  border-radius: 50%;
  -webkit-tap-highlight-color: transparent;
}
.account-menu > summary::-webkit-details-marker { display: none; }
.account-menu[open] > summary { background: var(--card); color: var(--ink); }
.account-menu-panel {
  position: absolute; top: 44px; right: 0;
  min-width: 180px; padding: 6px;
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0,0,0,0.12);
}
.account-who {
  margin: 0; padding: 8px 10px 10px;
  color: var(--muted); font-size: 0.85rem; line-height: 1.35;
  border-bottom: 1px solid var(--line);
}
.account-who strong { color: var(--ink); font-size: 0.95rem; }
.account-menu-panel a,
.account-menu-panel button {
  display: block; width: 100%;
  margin: 2px 0 0; padding: 11px 10px;
  min-height: 44px;
  background: none; border: 0; border-radius: 8px;
  color: var(--ink); font: inherit; font-size: 0.95rem;
  text-align: left; text-decoration: none; cursor: pointer;
}
.account-menu-panel a:active,
.account-menu-panel button:active { background: var(--bg); }

.btn-joint { justify-content: flex-start; gap: 8px; min-height: 52px; }
.side-tag {
  font-size: 0.72rem; font-weight: 700; color: var(--muted);
  border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px;
}

/* ── Chips (backdate, toggles, small actions) ── */
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.chip {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 8px 14px;
  background: var(--card);
  border: 1px solid var(--line); border-radius: 22px;
  color: var(--ink); font-size: 0.95rem;
  text-decoration: none; cursor: pointer;
}
.chip.take { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

/* Radio/checkbox chips: hide the input, style the label, mark :checked */
.chip-row input[type="radio"],
.chip-row input[type="checkbox"] {
  position: absolute; opacity: 0; pointer-events: none;
}
.chip-row input:checked + .chip {
  background: var(--ink); color: var(--bg); border-color: var(--ink);
}
.chip-row input:focus-visible + .chip { outline: 2px solid var(--accent); }

/* The free datetime picker is the fallback, never the primary control */
.custom-dt { display: none; width: 100%; margin-top: 6px; }
.chip-row input[value="custom"]:checked ~ .custom-dt { display: block; }

/* ── Severity row: buttons, not a slider ── */
.sev-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px; margin: 8px 0;
}
.sev-row input[type="radio"] { position: absolute; opacity: 0; pointer-events: none; }
.sev-btn {
  display: flex; align-items: center; justify-content: center;
  min-height: 48px;
  background: var(--card);
  border: 1px solid var(--line); border-radius: 10px;
  font-weight: 700; font-size: 1.05rem; cursor: pointer;
}
.sev-row input:checked + .sev-btn,
.sev-btn:active {
  background: var(--ink); color: var(--bg); border-color: var(--ink);
}
.sev-row input:focus-visible + .sev-btn { outline: 2px solid var(--accent); }

/* ── Observation cards ── */
.obs-card {
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin: 10px 0;
}
.obs-card.is-stale { border-color: #e0b96a; background: var(--warn-bg); }
.obs-card.is-closed { opacity: 0.75; }
.obs-card header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.obs-card details { margin-top: 8px; }
.obs-card summary {
  cursor: pointer; color: var(--accent); font-weight: 600;
  padding: 10px 0; min-height: 44px; display: flex; align-items: center;
}

.sev {
  margin-left: auto;
  min-width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 17px; font-weight: 700; font-size: 0.95rem;
  background: var(--line);
}
.sev-0, .sev-1, .sev-2, .sev-3 { background: #dcead9; color: #2c5232; }
.sev-4, .sev-5, .sev-6 { background: #f4e3bd; color: #6d5518; }
.sev-7, .sev-8, .sev-9, .sev-10 { background: #f2d3cd; color: #78352c; }

.note-inline { display: flex; gap: 8px; margin-top: 12px; }
.note-inline input[type="text"] { flex: 1; }

/* ── Forms ── */
input[type="text"], input[type="password"], input[type="number"],
input[type="date"], input[type="datetime-local"], select, textarea {
  width: 100%;
  padding: 12px;
  min-height: 48px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink);
  font: inherit;
}
textarea { resize: vertical; }
label { display: block; margin: 14px 0 6px; font-weight: 600; }
fieldset { border: 0; padding: 0; margin: 16px 0 0; }
legend { font-weight: 600; padding: 0; margin-bottom: 6px; }
.field-pair { display: flex; align-items: center; gap: 10px; }
.field-pair input { flex: 1; }

details.optional { margin-top: 20px; }
details.optional summary {
  color: var(--muted); font-weight: 600; cursor: pointer;
  padding: 10px 0; min-height: 44px; display: flex; align-items: center;
}

.region-checks ul { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.region-checks label { display: flex; align-items: center; gap: 8px; font-weight: 400; margin: 0; min-height: 44px; }
.region-checks input[type="checkbox"] { width: 22px; height: 22px; }

/* ── Medications ── */
.med-list { list-style: none; padding: 0; margin: 0; }
.med-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--card);
  border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; margin: 8px 0;
}
.med-row .med-name { flex: 1; font-weight: 600; }
.med-dose { color: var(--muted); font-weight: 400; }
.med-full { flex-direction: column; align-items: stretch; }
.med-list.past .med-row { opacity: 0.8; }
.badge {
  font-size: 0.75rem; font-weight: 700;
  border: 1px solid var(--line); border-radius: 6px;
  padding: 2px 6px; color: var(--muted); margin-left: 6px;
}
.badge.good { color: var(--good); border-color: var(--good); }

/* ── Notes & history ── */
.note-list, .event-list { list-style: none; padding: 0; margin: 12px 0; }
.note-list li {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px; margin: 8px 0;
}
.note-list li p { margin: 2px 0; }
.event-list li { padding: 6px 0; display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.event-list .t { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 0.9rem; }
.day { border-top: 1px solid var(--line); }
.day:first-of-type { border-top: 0; }

/* ── Maps (joint map, hand/foot sub-maps, region map) ── */
[x-cloak] { display: none !important; }

.body-map, .limb-map, .region-map svg {
  width: 100%; height: auto; display: block; margin: 8px 0;
}
.sil { fill: #eae7de; }
.sil-line { stroke: #eae7de; stroke-linecap: round; }
.map-label {
  fill: var(--muted); font-size: 15px; font-weight: 600;
  text-anchor: middle; pointer-events: none;
}

/* The wide translucent stroke is a tap halo: it grows the hit area (SVG
   hit-testing includes the stroke) and doubles as a "tappable" affordance. */
.joint {
  fill: #fff;
  stroke: rgba(47, 111, 79, 0.18); stroke-width: 12;
  cursor: pointer;
}
.joint:active, .joint.is-selected { fill: var(--accent); }

.zoom-zone {
  fill: rgba(47, 111, 79, 0.08);
  stroke: var(--accent); stroke-width: 2; stroke-dasharray: 4 4;
  cursor: pointer;
}
.map-links { margin-top: 4px; }

.region {
  fill: #e3e0d8;
  stroke: var(--bg); stroke-width: 3;
  cursor: pointer;
}
.region:active, .region.is-on { fill: var(--accent); }
.region-chip { border-color: var(--accent); }

/* ── Bottom sheet: the map's logging form, low and thumb-reachable ── */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--card);
  border-top: 1px solid var(--line);
  border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.18);
  max-height: 75vh; overflow-y: auto;
  padding: 4px 0 calc(16px + env(safe-area-inset-bottom));
}
.sheet .page { padding-top: 4px; }
.sheet-close {
  position: absolute; top: 2px; right: 6px; z-index: 1;
  min-width: 44px; min-height: 44px;
  border: 0; background: none; font-size: 1.5rem; color: var(--muted);
  cursor: pointer;
}

/* ── Photos ── */
.photo-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.photo-row img {
  width: 72px; height: 72px; object-fit: cover; display: block;
  border: 1px solid var(--line); border-radius: 10px;
}
.photo-inline { display: flex; gap: 8px; align-items: center; margin-top: 12px; }
.photo-inline input[type="file"] { flex: 1; width: auto; border-style: dashed; }

/* ── Morning stiffness one-tap ── */
.stiffness { margin-bottom: 14px; }
.stiffness .btn-primary { margin: 6px 0 0; }
.stiffness details.optional { margin-top: 2px; }

@media (min-width: 700px) {
  .quick-grid, .joint-grid { grid-template-columns: repeat(3, 1fr); }
  .sev-row { grid-template-columns: repeat(11, 1fr); }
}
