:root {
  --bg: #f7f3ea;
  --card: #fffdf8;
  --sunk: #eee8db;
  --ink: #2d2a24;
  --muted: #7a7266;
  --line: #e6dfd0;
  --accent: #5b6b3a;      /* pasture green */
  --accent-ink: #ffffff;
  --warm: #c9824a;        /* barn-door tan */
  --danger: #a8432f;
  --danger-soft: #f6ded8;
  --soon-soft: #f6e7c6;
  --ok: #3d7a45; --ok-soft: #dcefd9;
  --info: #2f6d8f; --info-soft: #d9e9f1;
  --radius: 16px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1c1b17; --card: #26241f; --sunk: #302d27; --ink: #f1ece0; --muted: #a59d8f;
    --line: #3a372f; --accent: #9bb26a; --accent-ink: #1c1b17; --warm: #e0a46f;
    --danger: #e07a64; --danger-soft: #3d2320; --soon-soft: #3b3020;
    --ok: #8ccc93; --ok-soft: #203a22; --info: #7cbcdc; --info-soft: #1d3240;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
  -webkit-tap-highlight-color: transparent;
}
body.locked { overflow: hidden; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--warm); outline-offset: 2px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.small { font-size: 13px; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }

.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--bg); border-bottom: 1px solid var(--line);
}
.titles { flex: 1; min-width: 0; text-align: center; display: flex; flex-direction: column; }
.titles small { font-size: 12px; color: var(--muted); }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spacer, .icon-btn { width: 40px; flex: none; }
.icon-btn { height: 40px; border: 0; background: none; color: var(--accent); font-size: 32px; line-height: 1; padding: 0; }
.icon-btn[hidden] { display: block; visibility: hidden; }

main { max-width: 640px; margin: 0 auto; padding: 16px; outline: none; display: flex; flex-direction: column; gap: 18px; }
main > section, main > div { min-width: 0; }
.tagline { margin: 0; text-align: center; color: var(--muted); font-style: italic; }

/* Bottom tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 6;
  display: grid; grid-template-columns: repeat(4, 1fr); align-items: end;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px max(8px, env(safe-area-inset-left)) calc(6px + env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-right));
}
.tb { border: 0; background: none; display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: 12px; font-weight: 600; color: var(--muted); padding: 4px 0; }
.tb > span { font-size: 22px; line-height: 1; filter: grayscale(.6); }
.tb[aria-current="page"] { color: var(--accent); }
.tb[aria-current="page"] > span { filter: none; }
.tb.add { color: var(--accent); }
.tb .plus { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 30px; margin-top: -18px; border: 3px solid var(--card); filter: none; }

.empty { text-align: center; padding: 48px 16px; }
.big-emoji { font-size: 64px; }
.empty h2 { margin: 8px 0 4px; }
.empty p { color: var(--muted); margin: 0 0 20px; }

h2.sec { font-size: 18px; margin: 0 0 8px; display: flex; align-items: baseline; gap: 8px; }
h2.sec .count { font-size: 13px; font-weight: 500; color: var(--muted); }

.search { width: 100%; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); font-size: 16px; }
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card);
  border-radius: 999px; padding: 6px 12px; font-size: 14px; }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
section .chips { margin-bottom: 8px; }

.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.list > * + * { border-top: 1px solid var(--line); }
.row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; width: 100%; }
a.row:active, button.row:active { background: var(--sunk); }
button.row { border: 0; background: none; text-align: left; }
.row > button.row-text { border: 0; background: none; padding: 0; text-align: left; }
.row-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-text strong, .row-text small { overflow: hidden; text-overflow: ellipsis; }
.row-text strong { white-space: nowrap; }
.row-text small { color: var(--muted); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.row-end { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; text-align: right; }
.row-end small { color: var(--muted); font-size: 12px; }
.chev { color: var(--muted); font-size: 22px; }
.empty-row { padding: 14px; color: var(--muted); }
.ev-icon { width: 36px; text-align: center; font-size: 22px; flex: none; }
.stripe { width: 4px; align-self: stretch; border-radius: 4px; flex: none; }
.st-over { background: var(--danger); } .st-soon { background: var(--warm); } .st-ok { background: var(--ok); }

.pill { display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; padding: 2px 9px; border-radius: 999px; white-space: nowrap; }
.p-over { background: var(--danger-soft); color: var(--danger); }
.p-soon { background: var(--soon-soft); color: var(--ink); }
.p-ok { background: var(--ok-soft); color: var(--ok); }
.p-info { background: var(--info-soft); color: var(--info); }
.bar { display: block; height: 6px; border-radius: 6px; background: var(--sunk); overflow: hidden; margin-top: 4px; }
.bar i { display: block; height: 100%; background: var(--danger); }

.avatar { width: 48px; height: 48px; border-radius: 50%; object-fit: cover; flex: none;
  background: color-mix(in srgb, var(--warm) 22%, var(--card));
  display: inline-flex; align-items: center; justify-content: center; font-size: 26px; }
.avatar.big { width: 112px; height: 112px; font-size: 60px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack p { margin: 0; }
.bottle { display: flex; flex-direction: column; gap: 10px; }
.bottle-top { display: flex; align-items: center; gap: 12px; }
.trio { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; text-align: center; }
.trio small { display: block; color: var(--muted); font-size: 12px; }
.trio b { font-size: 20px; overflow-wrap: anywhere; }

.profile { display: flex; align-items: center; gap: 16px; }
.profile h2 { margin: 0; font-size: 26px; }
.profile p { margin: 2px 0 0; }
.facts { margin: 0; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); }
.facts div { display: flex; justify-content: space-between; gap: 16px; padding: 11px 14px; }
.facts div + div { border-top: 1px solid var(--line); }
.facts dt { color: var(--muted); flex: none; }
.facts dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.notes { margin-top: 12px; }
.notes h3 { margin: 0 0 4px; font-size: 15px; }
.notes p { margin: 0; white-space: pre-wrap; }

.form { display: flex; flex-direction: column; gap: 14px; }
.form label, label.stack { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); min-width: 0; }
.form input:not([type=checkbox]), .form select, .form textarea, label.stack input {
  font-size: 16px; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; width: 100%; min-width: 0;
}
/* iPhones give date/time boxes a fixed minimum width unless their native look is turned off. */
input[type=date], input[type=time] { -webkit-appearance: none; appearance: none; min-height: 48px; display: block;
  width: 100%; min-width: 0; max-width: 100%; box-sizing: border-box; text-align: left; }
input::-webkit-date-and-time-value { text-align: left; }
label.stack textarea { font-size: 16px; color: var(--ink); background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px; width: 100%; min-width: 0; }
@media (max-width: 360px) { .two { grid-template-columns: minmax(0, 1fr); } }
.form input:focus, .form select:focus, .form textarea:focus, label.stack input:focus { outline: 2px solid var(--accent); border-color: transparent; }
.form label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--ink); font-size: 16px; }
.check input { width: 22px; height: 22px; accent-color: var(--accent); }
.two { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
[hidden] { display: none !important; }
.icon-btn[hidden] { display: block !important; visibility: hidden; }
.photo-pick { align-items: center; cursor: pointer; }
.photo-pick .link { color: var(--accent); font-weight: 600; }
details.more { display: flex; flex-direction: column; gap: 14px; }
details.more summary { cursor: pointer; color: var(--accent); font-weight: 600; margin-bottom: 4px; }
details.more[open] { display: flex; }
.error { color: var(--danger); margin: 0; }

.actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
.actions.start { justify-content: flex-start; }
.btn { font-weight: 600; border-radius: 12px; padding: 12px 20px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); text-align: center; display: inline-block; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: var(--sunk); border-color: var(--sunk); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 999px; align-self: flex-start; margin-top: 8px; }
.row .btn.small { margin-top: 0; }
.btn.wide { width: 100%; padding: 14px; }
.linkish { cursor: pointer; }

.sheet-bg { position: fixed; inset: 0; z-index: 20; background: rgba(10, 12, 8, .45);
  display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; max-height: 92%; overflow: auto;
  border-radius: 20px 20px 0 0; padding: 18px 16px calc(20px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 12px; outline: none; }
.sheet h3 { margin: 0; font-size: 20px; }
.sheet p { margin: 0; }
.preview { margin: 0; padding: 0; list-style: none; display: flex; flex-wrap: wrap; gap: 6px; }
.preview li { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 14px; }
@media (prefers-reduced-motion: no-preference) {
  .sheet { animation: up .2s ease-out; }
  @keyframes up { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
}
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(92px + env(safe-area-inset-bottom));
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 14px; z-index: 30;
  max-width: calc(100% - 32px); text-align: center; }
label.stack select { font-size: 16px; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 12px; width: 100%; }

/* Money */
.seg { display: flex; background: var(--sunk); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button { flex: 1; border: 0; background: none; border-radius: 9px; padding: 8px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.seg.small { margin-bottom: 8px; }
.seg.small button { padding: 6px; font-size: 14px; }
.period { display: flex; align-items: center; justify-content: space-between; }
.period h2 { margin: 0; font-size: 20px; text-align: center; flex: 1; }
.pos { color: var(--ok); }
.neg { color: var(--danger); }
.spend-top { display: flex; justify-content: space-between; gap: 10px; }
.spend-top strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.spendbar i { background: var(--accent); }
.row.spend.picked { background: var(--sunk); }
.clear { border: 0; background: none; color: var(--accent); font-weight: 600; font-size: 14px; margin-left: auto; padding: 0; }
.mchart { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; align-items: end; height: 140px; }
.mbar { border: 0; background: none; padding: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 4px; }
.mbar-fill { width: 100%; max-width: 22px; min-height: 2px; background: var(--accent); border-radius: 4px 4px 0 0; }
.mbar small { color: var(--muted); font-size: 11px; }
.receipt-row { display: flex; align-items: center; gap: 12px; }
.thumb { border: 1px solid var(--line); border-radius: 8px; padding: 0; width: 56px; height: 72px; overflow: hidden; background: var(--card); flex: none; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.receipt-row .btn.small { margin-top: 0; margin-left: auto; }
.bar.progress { height: 10px; }
.bar.progress i { background: var(--accent); transition: width .3s; }
.photo-view { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.88); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px; padding: calc(16px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom)); }
.photo-view img { max-width: 100%; max-height: 85vh; object-fit: contain; border-radius: 6px; }
.photo-view p { color: #fff; opacity: .8; font-size: 13px; margin: 0; text-align: center; }

/* Sitter sheet & health record */
.link-card { display: flex; align-items: center; gap: 12px; }
.link-card:active { background: var(--sunk); }
.sharebar { display: flex; flex-direction: column; gap: 8px; }
.sheet-page { display: flex; flex-direction: column; gap: 18px; }
.sit-animal p { margin: 6px 0 0; font-size: 15px; }
.sit-animal .care { color: var(--danger); }
.sit-animal .btn.small { margin-top: 0; margin-left: auto; }
.pre { white-space: pre-wrap; margin: 0; }
.phone { color: var(--accent); font-weight: 600; white-space: nowrap; }
.print-only { display: none; }
@media print {
  :root { --bg: #fff; --card: #fff; --ink: #000; --muted: #444; --line: #bbb; color-scheme: light; }
  body { padding: 0; background: #fff; font-size: 12pt; }
  .topbar, .tabbar, .no-print, .toast, #layer { display: none !important; }
  .print-only { display: block; }
  .print-only h1 { font-size: 18pt; margin: 0 0 4px; }
  main { max-width: none; padding: 0; gap: 10px; }
  .card, .list, .facts { break-inside: avoid; border-color: #bbb; }
  .sit-animal { break-inside: avoid; }
  .avatar { width: 32px; height: 32px; font-size: 18px; }
  .avatar.big { width: 64px; height: 64px; font-size: 36px; }
  .pill { border: 1px solid #999; }
  a { color: #000; }
}
.hold-banner { display: flex; flex-direction: column; gap: 2px; background: var(--danger-soft); color: var(--danger);
  border-radius: var(--radius); padding: 12px 14px; }
.hold-banner small { color: var(--ink); opacity: .75; }
