:root {
  --bg: #f6f5ef;
  --card: #ffffff;
  --ink: #1d2a1d;
  --muted: #5d6b5d;
  --line: #dfe3d6;
  --brand: #2f6b2f;
  --brand-ink: #ffffff;
  --brand-soft: #e3efdc;
  --accent: #c7801d;
  --danger: #b3261e;
  --danger-soft: #fbe3e1;
  --warn: #9a5b00;
  --warn-soft: #fff1d6;
  --ok: #1f6b3a;
  --ok-soft: #dcf2e3;
  --info-soft: #e2edf7;
  --leaf: #4f8f3a;
  --leaf-dark: #2f5e22;
  --soil: #7a5a3a;
  --sick: #8a5a1c;
  --shadow: 0 1px 2px rgba(0,0,0,.06), 0 2px 8px rgba(0,0,0,.05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #121612; --card: #1b211b; --ink: #e7ede4; --muted: #a3b0a0; --line: #2d362c;
    --brand: #6fb36a; --brand-ink: #0d160d; --brand-soft: #22341f; --accent: #e3a548;
    --danger: #ff8a80; --danger-soft: #3a1f1d; --warn: #ffc56b; --warn-soft: #3a2d14;
    --ok: #7fd49a; --ok-soft: #1a3324; --info-soft: #1c2a38;
    --leaf: #6aa954; --leaf-dark: #8fc77a; --soil: #b08a64; --sick: #d6a35a;
    --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #121612; --card: #1b211b; --ink: #e7ede4; --muted: #a3b0a0; --line: #2d362c;
  --brand: #6fb36a; --brand-ink: #0d160d; --brand-soft: #22341f; --accent: #e3a548;
  --danger: #ff8a80; --danger-soft: #3a1f1d; --warn: #ffc56b; --warn-soft: #3a2d14;
  --ok: #7fd49a; --ok-soft: #1a3324; --info-soft: #1c2a38;
  --leaf: #6aa954; --leaf-dark: #8fc77a; --soil: #b08a64; --sick: #d6a35a;
  --shadow: 0 1px 2px rgba(0,0,0,.4); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
a { color: var(--brand); }
h1 { font-size: 1.45rem; line-height: 1.25; margin: .2rem 0 .6rem; }
h2 { font-size: 1.15rem; margin: 1.2rem 0 .5rem; }
h3 { font-size: 1rem; margin: .9rem 0 .3rem; }
p { margin: .4rem 0; }
ul, ol { padding-left: 1.25rem; margin: .3rem 0 .6rem; }
li { margin: .15rem 0; }
small, .muted { color: var(--muted); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--brand); color: var(--brand-ink);
}
.brand { flex: 1; color: inherit; text-decoration: none; font-weight: 700; font-size: 1.1rem; }
.icon-btn {
  background: transparent; border: 0; color: inherit; font-size: 1.3rem; text-decoration: none;
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center; cursor: pointer;
}
.icon-btn:hover { background: rgba(255,255,255,.12); }

#view { max-width: 920px; margin: 0 auto; padding: 14px 16px 24px; outline: none; }

.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav a {
  display: flex; flex-direction: column; align-items: center; padding: 6px 2px 8px;
  font-size: .72rem; color: var(--muted); text-decoration: none;
}
.bottomnav a span { font-size: 1.35rem; line-height: 1.3; }
.bottomnav a.active { color: var(--brand); font-weight: 700; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; margin: 10px 0; box-shadow: var(--shadow);
}
.grid { display: grid; gap: 10px; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.grid.wide { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.tile {
  display: flex; flex-direction: column; gap: 4px; text-decoration: none; color: var(--ink);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px; box-shadow: var(--shadow); min-height: 92px;
}
.tile:hover { border-color: var(--brand); }
.tile .ico { font-size: 1.8rem; line-height: 1; }
.tile b { font-size: 1rem; }
.tile small { font-size: .8rem; }
.tile.hero { background: var(--brand-soft); }

.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.badge {
  display: inline-block; font-size: .72rem; font-weight: 700; padding: 2px 8px; border-radius: 99px;
  background: var(--brand-soft); color: var(--brand); vertical-align: middle; white-space: nowrap;
}
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.ok { background: var(--ok-soft); color: var(--ok); }
.badge.info { background: var(--info-soft); color: var(--ink); }

.alert { border-radius: 12px; padding: 10px 12px; margin: 10px 0; border: 1px solid transparent; }
.alert.danger { background: var(--danger-soft); border-color: var(--danger); }
.alert.warn { background: var(--warn-soft); border-color: var(--warn); }
.alert.ok { background: var(--ok-soft); }
.alert.info { background: var(--info-soft); }

details.sec {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  margin: 10px 0; box-shadow: var(--shadow); overflow: hidden;
}
details.sec > summary {
  cursor: pointer; padding: 12px 14px; font-weight: 700; list-style: none; display: flex; gap: 8px; align-items: center;
}
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::after { content: "▸"; margin-left: auto; transition: transform .15s; color: var(--muted); }
details.sec[open] > summary::after { transform: rotate(90deg); }
details.sec > .body { padding: 0 14px 12px; border-top: 1px solid var(--line); }

table { border-collapse: collapse; width: 100%; font-size: .92rem; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 600; font-size: .8rem; text-transform: uppercase; letter-spacing: .02em; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.pic { display: block; width: 100%; max-width: 260px; height: auto; border-radius: 12px; background: var(--brand-soft); }
.pic-row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-start; }
.pic-row .pic { flex: 0 0 auto; width: 150px; }
.pic-row .txt { flex: 1 1 220px; min-width: 0; }
.pic-cap { font-size: .75rem; color: var(--muted); text-align: center; max-width: 150px; }

.list-item {
  display: flex; gap: 12px; align-items: center; text-decoration: none; color: var(--ink);
  padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.list-item:last-child { border-bottom: 0; }
.list-item .ico { font-size: 1.5rem; width: 36px; text-align: center; }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .grow b { display: block; }
.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.list-item .thumb { width: 54px; height: 54px; flex: 0 0 54px; border-radius: 10px; overflow: hidden; }
.list-item .thumb svg { width: 100%; height: 100%; display: block; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 99px; padding: 7px 12px; font: inherit; font-size: .9rem; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.chip-group h3 { margin-top: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--brand); background: var(--brand); color: var(--brand-ink);
  border-radius: 10px; padding: 10px 14px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.ghost { background: transparent; color: var(--brand); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.small { padding: 6px 10px; font-size: .85rem; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

label.f { display: block; margin: 10px 0; font-size: .9rem; font-weight: 600; }
label.f > span { display: block; margin-bottom: 4px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--ink); background: var(--card);
  border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
textarea { min-height: 80px; resize: vertical; }
.form-grid { display: grid; gap: 0 12px; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }

.searchbox { position: relative; margin: 6px 0 12px; }
.searchbox input { padding-left: 38px; font-size: 1rem; }
.searchbox::before { content: "🔍"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-size: .95rem; }

.result { display: flex; gap: 12px; align-items: center; }
.meter { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; flex: 0 0 80px; }
.meter > i { display: block; height: 100%; background: var(--brand); }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin: 6px 0 10px; }
.tabs a {
  flex: 0 0 auto; padding: 7px 12px; border-radius: 99px; border: 1px solid var(--line);
  text-decoration: none; color: var(--ink); background: var(--card); font-size: .9rem;
}
.tabs a.active { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }

.stat { display: flex; flex-direction: column; }
.stat b { font-size: 1.4rem; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }

/* Budget lines: item on its own row on phones, numbers below */
.bline { display: grid; grid-template-columns: 2.4fr 1fr 1.2fr 1.2fr 1.3fr 32px; gap: 6px; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); }
.bline input { padding: 7px 8px; }
.bline .b-tot { text-align: right; font-size: .9rem; white-space: nowrap; }
.bline .icon-btn { width: 32px; height: 32px; padding: 0; }
.bhead { font-size: .75rem; color: var(--muted); padding-top: 0; }
.bgrid > .btn { margin-top: 8px; }
@media (max-width: 640px) {
  .bline { grid-template-columns: 1fr 1fr 1fr 32px; }
  .bline .b-item { grid-column: 1 / -1; }
  .bline .b-tot { grid-column: 1 / 4; }
  .bline .icon-btn { grid-column: 4; grid-row: 3; }
  .bhead .b-item, .bhead span:nth-child(5), .bhead span:nth-child(6) { display: none; }
}
/* Money: monthly bars */
.mbars { display: flex; gap: 8px; align-items: flex-end; height: 140px; }
.mbar { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.mbar-cols { flex: 1; width: 100%; display: flex; gap: 3px; align-items: flex-end; justify-content: center; }
.mbar-cols i { display: block; width: 40%; max-width: 22px; min-height: 2px; border-radius: 4px 4px 0 0; }
.mbar-cols .inc, .dot.inc { background: var(--ok); }
.mbar-cols .exp, .dot.exp { background: var(--danger); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; vertical-align: middle; }

.task { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); }
.task:last-child { border-bottom: 0; }
.task .when { flex: 0 0 86px; font-size: .8rem; color: var(--muted); }
.task.overdue .when { color: var(--danger); font-weight: 700; }
.task.done { opacity: .55; text-decoration: line-through; }

.map-svg { width: 100%; height: 300px; background: var(--brand-soft); border-radius: 12px; touch-action: none; }

#toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%) translateY(20px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  opacity: 0; pointer-events: none; transition: all .2s; z-index: 50; max-width: calc(100% - 32px);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; font-size: .93rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.disclaimer { font-size: .8rem; color: var(--muted); border-top: 1px dashed var(--line); margin-top: 16px; padding-top: 10px; }

@media (min-width: 760px) {
  body { padding-bottom: 0; }
  .bottomnav { position: sticky; top: 60px; bottom: auto; max-width: 920px; margin: 0 auto; border: 0; background: transparent; grid-template-columns: repeat(5, max-content); gap: 6px; padding: 8px 16px 0; }
  .bottomnav a { flex-direction: row; gap: 6px; font-size: .9rem; padding: 6px 12px; border-radius: 99px; }
  .bottomnav a span { font-size: 1rem; }
  .bottomnav a.active { background: var(--brand-soft); }
  #toast { bottom: 24px; }
}
@media print {
  .topbar, .bottomnav, .btn, .no-print { display: none !important; }
  body { padding: 0; background: #fff; color: #000; }
  details.sec > .body { display: block !important; }
}

/* ---------- Subscription, vets & chat ---------- */
.plans { display: grid; gap: 8px; margin: 8px 0 12px; }
.plan { display: flex; gap: 8px; align-items: center; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); cursor: pointer; }
.plan:has(input:checked) { border-color: var(--brand); background: var(--brand-soft); }
.list-item.vet { align-items: center; }
.list-item.vet small { display: block; }
.vet-actions { display: flex; gap: 6px; flex-shrink: 0; }
.chat { display: flex; flex-direction: column; gap: 8px; max-height: 58vh; overflow-y: auto; padding: 12px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin: 12px 0; }
.msg { max-width: 82%; padding: 8px 12px; border-radius: 14px; line-height: 1.4; overflow-wrap: anywhere; }
.msg small { display: block; font-size: .72rem; opacity: .7; margin-top: 2px; }
.msg.them { align-self: flex-start; background: var(--info-soft); border-bottom-left-radius: 4px; }
.msg.me { align-self: flex-end; background: var(--brand-soft); border-bottom-right-radius: 4px; text-align: right; }
.chat-input { display: flex; gap: 8px; align-items: flex-end; }
.chat-input textarea { flex: 1; min-width: 0; font: inherit; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); color: var(--ink); resize: vertical; }

/* Schedule details */
.task-detail { margin: 6px 0 0; padding-left: 18px; font-size: .86rem; color: var(--ink); }
.task-detail li { margin: 2px 0; }
.task.done .task-detail { display: none; }
@media print { .bottomnav, .topbar { display: none !important; } }

/* Construction drawings (always light so labels stay readable) */
.plan { display: block; width: 100%; max-width: 620px; height: auto; margin: 8px 0; color: #1d2a1d; background: #fbf8f0; border: 1px solid #e3dccb; border-radius: 12px; }

/* Language picker */
.lang-pick { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(20,40,20,.55); }
.lang-pick .card { max-width: 380px; width: 100%; text-align: center; }
.lang-pick .btn { display: block; width: 100%; margin: 10px 0; font-size: 1.15rem; padding: 14px; }
.lang-btn { font-size: .85rem; width: auto; padding: 0 8px; white-space: nowrap; }
