:root {
  --brand: #e07a2f;
  --brand-dark: #b85f1d;
  --brand-soft: #fdf1e7;
  --bg: #f6f4f1;
  --card: #ffffff;
  --ink: #2b2926;
  --ink-soft: #6f6a63;
  --line: #e8e4de;
  --good: #2e8b57;
  --warn: #c0392b;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(30, 25, 20, 0.08), 0 4px 14px rgba(30, 25, 20, 0.05);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

#app { max-width: 1080px; margin: 0 auto; padding-bottom: 90px; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; gap: 12px; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  width: 44px; height: 44px; border-radius: 12px;
  background: var(--brand); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 700;
}
.brand-name { font-weight: 700; font-size: 17px; }
.brand-tag { font-size: 12.5px; color: var(--ink-soft); }
.recipient-chip {
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 6px 14px; display: flex; gap: 8px; align-items: baseline;
  box-shadow: var(--shadow);
}
.chip-label { font-size: 12px; color: var(--ink-soft); }
.chip-name { font-weight: 600; font-size: 14px; }
button.profile-chip { cursor: pointer; font-family: inherit; }
button.profile-chip:hover { border-color: var(--brand); }

/* ---------- Nav ---------- */
.nav {
  display: flex; gap: 4px; padding: 0 16px 8px; overflow-x: auto;
}
.nav-btn {
  flex: 1; min-width: 64px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 6px; border: none; background: transparent; cursor: pointer;
  border-radius: 10px; font-family: inherit; font-size: 12px; color: var(--ink-soft);
}
.nav-btn:hover { background: rgba(0,0,0,0.04); }
.nav-btn.active { background: var(--brand-soft); color: var(--brand-dark); font-weight: 600; }
.nav-icon { font-size: 19px; }

/* Bottom nav on phones */
@media (max-width: 640px) {
  .nav {
    position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
    background: var(--card); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    margin: 0;
  }
  .nav-btn { min-width: 0; font-size: 10.5px; padding: 6px 2px; }
}

/* ---------- Main / cards ---------- */
.main { padding: 8px 20px 40px; }
.view-title { font-size: 22px; font-weight: 700; margin: 10px 0 4px; }
.view-sub { color: var(--ink-soft); font-size: 14px; margin-bottom: 16px; }

.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; margin-bottom: 14px;
}
.card h3 {
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-soft); margin-bottom: 12px; font-weight: 600;
  display: flex; justify-content: space-between; align-items: center;
}
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 760px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Rows / list items ---------- */
.row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--line);
}
.row:last-child { border-bottom: none; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: 15px; }
.row-sub { font-size: 13px; color: var(--ink-soft); }
.row-side { text-align: right; font-size: 13px; color: var(--ink-soft); white-space: nowrap; }
.row-actions {
  display: flex; flex-direction: column; align-items: flex-end; gap: 4px;
}
@media (max-width: 640px) {
  .row { align-items: flex-start; }
  .row-actions { white-space: normal; }
}

.avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 14px;
}

.pill {
  display: inline-block; padding: 2px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.pill-brand { background: var(--brand-soft); color: var(--brand-dark); }
.pill-good { background: #e6f4ec; color: var(--good); }
.pill-warn { background: #fdecea; color: var(--warn); }
.pill-neutral { background: #efece8; color: var(--ink-soft); }

/* ---------- Med checkoff ---------- */
.dose-check {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  border: 2px solid var(--line); background: var(--card); cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; color: transparent; transition: all 0.15s;
}
.dose-check.taken { background: var(--good); border-color: var(--good); color: #fff; }
.dose-check:hover { border-color: var(--brand); }

/* ---------- Buttons / forms ---------- */
.btn {
  font-family: inherit; font-size: 14px; font-weight: 600; cursor: pointer;
  border-radius: 10px; padding: 9px 16px; border: 1px solid transparent;
}
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); }
.btn-ghost { background: transparent; color: var(--brand-dark); border-color: var(--line); }
.btn-ghost:hover { background: var(--brand-soft); }
.btn-sm { padding: 5px 12px; font-size: 13px; border-radius: 8px; }
.btn-danger { background: transparent; color: var(--warn); border-color: var(--line); }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 4px; }
.field input, .field select, .field textarea {
  width: 100%; font-family: inherit; font-size: 15px;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
  background: var(--card); color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--brand); outline-offset: -1px;
}
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }
.external-fields {
  background: var(--brand-soft);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin: -2px 0 12px;
}
.checkline {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--ink-soft);
}
.checkline input { width: auto; }

/* ---------- Modal ---------- */
.modal-backdrop[hidden] { display: none; }
.modal-backdrop {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(30, 25, 20, 0.45);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
  width: 100%; max-width: 460px; max-height: 88vh; overflow-y: auto;
  padding: 20px 22px;
}
.modal h2 { font-size: 18px; margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 100px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px;
  border-radius: 999px; font-size: 14px; z-index: 60;
  box-shadow: var(--shadow);
}
@media (min-width: 641px) { .toast { bottom: 30px; } }

/* ---------- Updates feed ---------- */
.post { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.post:last-child { border-bottom: none; }
.post-body { flex: 1; }
.post-meta { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 2px; }
.post-meta strong { color: var(--ink); font-size: 13.5px; }
.post-text { font-size: 14.5px; }
.composer { display: flex; gap: 10px; margin-bottom: 6px; }
.composer input { flex: 1; }

/* ---------- Vitals ---------- */
.vitals-actions {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 14px;
}
.metric-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px; margin-bottom: 14px;
}
.metric-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; min-width: 0;
}
.metric-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-soft); margin-bottom: 12px; font-weight: 600;
}
.metric-meta {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin: 6px 0 2px;
}
.vital-stat { display: flex; align-items: baseline; gap: 8px; margin-bottom: 4px; }
.vital-num { font-size: 26px; font-weight: 700; }
.vital-unit { font-size: 13px; color: var(--ink-soft); }
.sparkline { width: 100%; height: 46px; margin-top: 6px; }
@media (max-width: 900px) { .metric-grid { grid-template-columns: 1fr; } }
@media (max-width: 480px) {
  .vitals-actions .btn { flex: 1 1 100%; }
  .metric-head { align-items: flex-start; }
}

/* ---------- Settings brands ---------- */
.brand-option {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px; border: 2px solid var(--line); border-radius: 12px;
  background: var(--card); cursor: pointer; font-family: inherit; text-align: left;
  margin-bottom: 10px;
}
.brand-option.selected { border-color: var(--brand); background: var(--brand-soft); }
.brand-swatch { width: 34px; height: 34px; border-radius: 9px; flex-shrink: 0;
  color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center; }

.empty { color: var(--ink-soft); font-size: 14px; padding: 12px 0; text-align: center; }
.section-gap { height: 8px; }
.muted { color: var(--ink-soft); }
.small { font-size: 13px; }
