/* HealthWallet — mobile-first, works phone → desktop. Light/dark aware. */
:root {
  --bg: #f4f6f8; --surface: #ffffff; --surface-2: #eef1f4;
  --text: #17202a; --muted: #667180; --border: #dbe1e8;
  --brand: #0f766e; --brand-ink: #ffffff;
  --in: #16a34a; --near: #d97706; --above: #dc2626; --below: #2563eb; --unknown: #94a3b8;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.04);
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1116; --surface: #171b22; --surface-2: #1e242d;
    --text: #e6e9ee; --muted: #9aa4b2; --border: #2a323d;
    --brand: #2dd4bf; --brand-ink: #06231f;
    --shadow: 0 1px 3px rgba(0,0,0,.4);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.grow { flex: 1; }
button { font: inherit; cursor: pointer; }

/* ---------- Auth ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 28px 24px;
}
.brand { margin: 0 0 4px; font-size: 1.5rem; }
.tabs { display: flex; gap: 4px; background: var(--surface-2); border-radius: 10px; padding: 4px; margin: 18px 0; }
.tab { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 9px; border-radius: 7px; font-weight: 600; }
.tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
form label { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin-bottom: 12px; }
input, select, textarea {
  width: 100%; margin-top: 5px; padding: 11px 12px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: var(--brand); }
.btn {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 11px 14px; border-radius: 10px; font-weight: 600;
}
.btn.primary { width: 100%; background: var(--brand); color: var(--brand-ink); border-color: transparent; margin-top: 6px; }
.btn.small { padding: 7px 11px; font-size: .85rem; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--above); border-color: color-mix(in srgb, var(--above) 40%, var(--border)); }
.btn.ok { color: var(--in); border-color: color-mix(in srgb, var(--in) 40%, var(--border)); }
.error { color: var(--above); font-size: .85rem; min-height: 1.2em; margin: 8px 0 0; }

/* ---------- Shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 12px;
  padding: 12px 16px calc(12px); padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--surface) 85%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.brand-sm { font-weight: 700; }
.linkbtn { border: 0; background: transparent; color: var(--brand); font-weight: 600; padding: 6px; }
.view { padding: 16px; padding-bottom: 96px; max-width: 900px; margin: 0 auto; }
h2.view-title { font-size: 1.15rem; margin: 4px 2px 14px; }

/* ---------- Bottom nav (mobile) ---------- */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6; display: flex;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px); border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.navbtn {
  flex: 1; border: 0; background: transparent; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 9px 4px 8px; font-size: .72rem; font-weight: 600; position: relative;
}
.navbtn .ico { font-size: 1.25rem; line-height: 1; }
.navbtn.active { color: var(--brand); }
.badge {
  position: absolute; top: 4px; right: 50%; transform: translateX(20px);
  background: var(--above); color: #fff; font-style: normal; font-size: .62rem;
  min-width: 16px; height: 16px; padding: 0 4px; border-radius: 9px; display: grid; place-items: center;
}

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 15px 16px;
}
.card.click { cursor: pointer; transition: transform .06s ease; }
.card.click:active { transform: scale(.99); }
.card-top { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.card-name { font-weight: 650; }
.value { font-size: 1.6rem; font-weight: 700; letter-spacing: -.01em; }
.value .unit { font-size: .9rem; font-weight: 600; color: var(--muted); margin-left: 4px; }
.rowmeta { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.pill { font-size: .72rem; font-weight: 700; padding: 3px 9px; border-radius: 999px; text-transform: capitalize; }
.pill.in { background: color-mix(in srgb, var(--in) 16%, transparent); color: var(--in); }
.pill.near { background: color-mix(in srgb, var(--near) 18%, transparent); color: var(--near); }
.pill.above { background: color-mix(in srgb, var(--above) 15%, transparent); color: var(--above); }
.pill.below { background: color-mix(in srgb, var(--below) 15%, transparent); color: var(--below); }
.pill.unknown { background: var(--surface-2); color: var(--muted); }
.pill.flag { background: color-mix(in srgb, var(--near) 18%, transparent); color: var(--near); }
.date { font-size: .78rem; color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 48px 16px; }
.empty .big { font-size: 2.4rem; }

/* two columns on wider screens */
@media (min-width: 640px) { .grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 900px) { .grid.three { grid-template-columns: 1fr 1fr 1fr; } }

/* On desktop, move nav to the top as a horizontal bar */
@media (min-width: 780px) {
  .tabbar {
    position: sticky; top: 0; bottom: auto; border-top: 0; border-bottom: 1px solid var(--border);
    max-width: 900px; margin: 0 auto; justify-content: center; gap: 8px; padding: 6px;
  }
  .navbtn { flex: 0 0 auto; flex-direction: row; gap: 7px; padding: 8px 16px; border-radius: 10px; font-size: .9rem; }
  .navbtn .ico { font-size: 1rem; }
  .navbtn.active { background: var(--surface-2); }
  .badge { position: static; transform: none; }
  .view { padding-bottom: 40px; }
}

/* ---------- Detail / chart ---------- */
.detail-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.chart-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; overflow-x: auto; }
.chart-wrap svg { display: block; width: 100%; height: auto; min-width: 280px; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .78rem; color: var(--muted); margin-top: 8px; }
.legend .sw { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: middle; }
table.points { width: 100%; border-collapse: collapse; margin-top: 14px; font-size: .9rem; }
table.points th, table.points td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
table.points th { color: var(--muted); font-weight: 600; font-size: .78rem; }

/* ---------- Review / forms ---------- */
.report-group { margin-bottom: 22px; }
.group-head { display: flex; align-items: center; gap: 8px; padding: 8px 4px; flex-wrap: wrap; }
.group-meta { display: flex; align-items: center; gap: 8px; }
.date-in { width: auto; margin-top: 0; padding: 6px 9px; font-size: .85rem; }
.draft-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.form-grid { display: grid; gap: 12px; grid-template-columns: 1fr; }
@media (min-width: 560px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .full { grid-column: 1 / -1; } }
.seg { display: flex; gap: 4px; background: var(--surface-2); border-radius: 10px; padding: 4px; }
.seg button { flex: 1; border: 0; background: transparent; color: var(--muted); padding: 8px; border-radius: 7px; font-weight: 600; }
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dropzone {
  border: 2px dashed var(--border); border-radius: var(--radius); padding: 28px 16px; text-align: center;
  color: var(--muted); background: var(--surface);
}
.dropzone.drag { border-color: var(--brand); color: var(--brand); }
.section-h { font-size: .8rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 22px 2px 10px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  font-size: .88rem; font-weight: 600; box-shadow: var(--shadow); z-index: 20; max-width: 90vw;
}
@media (min-width: 780px) { .toast { bottom: 24px; } }
.spin { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border); border-top-color: var(--brand); border-radius: 50%; animation: sp .7s linear infinite; vertical-align: -3px; }
@keyframes sp { to { transform: rotate(360deg); } }
