:root {
  --brand: #0e9d94;
  --brand-600: #0b857d;
  --brand-700: #096b64;
  --brand-tint: #e6f6f4;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --text: #14201f;
  --text-muted: #64766f;
  --border: #e3e8ea;
  --danger: #d64545;
  --warn: #d9822b;
  --ok: #2e9e5b;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 2px 10px rgba(16, 40, 37, .06);
  --shadow-lg: 0 8px 30px rgba(16, 40, 37, .14);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --appbar-h: 56px;
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1413;
    --surface: #14201f;
    --surface-2: #1a2726;
    --text: #eaf1ef;
    --text-muted: #93a5a0;
    --border: #253534;
    --brand-tint: #10302d;
    --shadow: 0 2px 10px rgba(0,0,0,.3);
    --shadow-lg: 0 8px 30px rgba(0,0,0,.5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  overscroll-behavior-y: none;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
h1,h2,h3,h4 { margin: 0; font-weight: 700; letter-spacing: -.01em; }
input, select, textarea { font-family: inherit; font-size: 16px; }

/* ---------- App bar ---------- */
.appbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 40;
  height: calc(var(--appbar-h) + var(--safe-top));
  padding-top: var(--safe-top);
  display: flex; align-items: center; gap: 6px; padding-left: 8px; padding-right: 8px;
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(1.6) blur(12px);
  -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--border);
}
.appbar__title { font-size: 19px; flex: 1; padding: 0 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.appbar__back, .appbar__action {
  height: 40px; min-width: 40px; border: 0; background: transparent; color: var(--text);
  border-radius: 12px; display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600; font-size: 14px; padding: 0 10px;
}
.appbar__back:active, .appbar__action:active { background: var(--surface-2); }
.appbar__action { color: var(--brand); }

/* ---------- Main ---------- */
.main {
  padding: calc(var(--appbar-h) + var(--safe-top) + 12px) 16px calc(var(--tabbar-h) + var(--safe-bottom) + 24px);
  max-width: 720px; margin: 0 auto;
  min-height: 100vh;
}
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin: 20px 4px 8px; font-weight: 700; }
.muted { color: var(--text-muted); }

/* ---------- Cards ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 16px; margin-bottom: 12px;
}
.card--tap { transition: transform .08s ease; }
.card--tap:active { transform: scale(.985); }
.list { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Hero / greeting ---------- */
.hero {
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-700) 100%);
  color: #fff; border-radius: 20px; padding: 20px; margin-bottom: 16px;
  box-shadow: var(--shadow-lg);
}
.hero h2 { font-size: 21px; }
.hero p { margin: 4px 0 0; opacity: .9; font-size: 14px; }
.hero__stats { display: flex; gap: 10px; margin-top: 16px; }
.hero__stat { flex: 1; background: rgba(255,255,255,.16); border-radius: 12px; padding: 10px 12px; }
.hero__stat b { font-size: 22px; display: block; line-height: 1.1; }
.hero__stat span { font-size: 12px; opacity: .9; }

/* ---------- Pet row ---------- */
.pet-row { display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 52px; height: 52px; border-radius: 14px; object-fit: cover; flex: 0 0 auto;
  background: var(--brand-tint); color: var(--brand-600);
  display: inline-flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 700;
  overflow: hidden;
}
.avatar--lg { width: 84px; height: 84px; border-radius: 22px; font-size: 38px; }
.avatar--sm { width: 38px; height: 38px; border-radius: 11px; font-size: 18px; }
.pet-row__body { flex: 1; min-width: 0; }
.pet-row__body h3 { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pet-row__meta { color: var(--text-muted); font-size: 13px; }
.chev { color: var(--text-muted); flex: 0 0 auto; }

/* ---------- Badges / pills ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.badge--ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); border-color: transparent; }
.badge--warn { background: color-mix(in srgb, var(--warn) 16%, transparent); color: var(--warn); border-color: transparent; }
.badge--danger { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); border-color: transparent; }
.badge--brand { background: var(--brand-tint); color: var(--brand-600); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 12px; padding: 11px 16px; font-weight: 600; font-size: 15px; width: 100%;
}
.btn:active { transform: scale(.98); }
.btn--brand { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--ghost { background: transparent; }
.btn--danger { background: transparent; color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }
.btn--sm { padding: 8px 12px; font-size: 14px; width: auto; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { width: auto; flex: 1; }

/* ---------- Empty state ---------- */
.empty { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty svg { width: 64px; height: 64px; opacity: .4; margin-bottom: 12px; }
.empty h3 { color: var(--text); margin-bottom: 6px; }

/* ---------- FAB ---------- */
.fab {
  position: fixed; z-index: 35; right: 18px;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  width: 56px; height: 56px; border-radius: 18px; border: 0;
  background: var(--brand); color: #fff; box-shadow: var(--shadow-lg);
  display: inline-flex; align-items: center; justify-content: center;
}
.fab:active { transform: scale(.94); }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
  height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom);
  display: flex; background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.6) blur(12px); -webkit-backdrop-filter: saturate(1.6) blur(12px);
  border-top: 1px solid var(--border);
}
.tabbar__item {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-muted); font-size: 11px; font-weight: 600; padding-top: 8px;
}
.tabbar__item svg { width: 24px; height: 24px; }
.tabbar__item.active { color: var(--brand); }

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text); }
.field .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.input, .select, .textarea {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface-2); color: var(--text); outline: none;
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--brand); background: var(--surface); }
.textarea { min-height: 84px; resize: vertical; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg__opt { flex: 1; min-width: 70px; text-align: center; padding: 10px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); font-weight: 600; font-size: 14px; }
.seg__opt.active { background: var(--brand-tint); border-color: var(--brand); color: var(--brand-600); }

.photo-picker { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.photo-picker input { display: none; }

/* ---------- Modal / bottom sheet ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center; }
.modal__backdrop { position: absolute; inset: 0; background: rgba(6, 16, 15, .48); animation: fade .2s ease; }
.modal__sheet {
  position: relative; width: 100%; max-width: 720px; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border-radius: 22px 22px 0 0; padding: 8px 16px calc(20px + var(--safe-bottom));
  box-shadow: var(--shadow-lg); animation: slideup .26s cubic-bezier(.2,.9,.3,1);
}
.modal__handle { width: 40px; height: 4px; border-radius: 4px; background: var(--border); margin: 8px auto 12px; }
.modal__title { font-size: 18px; margin-bottom: 16px; }
@keyframes slideup { from { transform: translateY(100%); } to { transform: translateY(0); } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Timeline ---------- */
.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ""; position: absolute; left: 8px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.tl-item { position: relative; margin-bottom: 16px; }
.tl-item::before { content: ""; position: absolute; left: -22px; top: 4px; width: 12px; height: 12px; border-radius: 50%; background: var(--brand); border: 2px solid var(--surface); }
.tl-item .tl-date { font-size: 12px; color: var(--text-muted); font-weight: 600; }

/* ---------- Pedigree tree ---------- */
.pedigree { overflow-x: auto; padding: 8px 2px 12px; }
.ped-tree { display: flex; align-items: stretch; gap: 14px; min-width: min-content; }
.ped-col { display: flex; flex-direction: column; justify-content: space-around; gap: 10px; }
.ped-node {
  min-width: 130px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 8px 10px; box-shadow: var(--shadow);
}
.ped-node.self { border-color: var(--brand); background: var(--brand-tint); }
.ped-node .n { font-weight: 700; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ped-node .s { font-size: 11px; color: var(--text-muted); }
.ped-node.empty-node { border-style: dashed; color: var(--text-muted); font-size: 12px; display: flex; align-items: center; justify-content: center; }
.ped-col-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); text-align: center; margin-bottom: 4px; font-weight: 700; }

/* ---------- Toast ---------- */
.toasts { position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px); z-index: 80; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; padding: 0 16px; }
.toast { background: #14201f; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; font-weight: 600; box-shadow: var(--shadow-lg); animation: slideup .24s ease; max-width: 100%; }
.toast--ok { background: var(--ok); }
.toast--danger { background: var(--danger); }

/* ---------- Info rows ---------- */
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.kv:last-child { border-bottom: 0; }
.kv__k { color: var(--text-muted); }
.kv__v { font-weight: 600; text-align: right; }

.subtabs { display: flex; gap: 4px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 12px; padding: 4px; margin-bottom: 16px; }
.subtab { flex: 1; text-align: center; padding: 9px 4px; border-radius: 9px; font-weight: 600; font-size: 13px; color: var(--text-muted); }
.subtab.active { background: var(--surface); color: var(--brand); box-shadow: var(--shadow); }

.row-actions { display: flex; gap: 8px; margin-top: 4px; }
.icon-btn { border: 0; background: var(--surface-2); color: var(--text-muted); width: 34px; height: 34px; border-radius: 10px; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn svg { width: 18px; height: 18px; }

.due-soon { border-left: 3px solid var(--warn); }
.due-over { border-left: 3px solid var(--danger); }
.due-ok { border-left: 3px solid var(--ok); }

.install-banner { display: flex; align-items: center; gap: 12px; background: var(--brand-tint); border: 1px solid var(--brand); color: var(--brand-700); padding: 12px 14px; border-radius: 14px; margin-bottom: 14px; }
.install-banner .btn { width: auto; }
