:root {
  --ground: #F6F3EA;
  --card: #FFFFFF;
  --ink: #1F2A22;
  --ink-2: #3A4339;
  --quiet: #5B6359;
  --line: #E3DED0;
  --line-2: #D5CFBF;
  --green: #2E5B3A;
  --green-dark: #1F3F28;
  --green-tint: #E3EDD9;
  --green-light: #CFE6B8;
  --warn-bg: #FFF4D6;
  --warn-line: #EAD9A4;
  --warn-ink: #4A3700;
  --danger: #A3321F;
  --serif: 'Instrument Serif', Georgia, 'Times New Roman', serif;
  --sans: 'DM Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
}
img { max-width: 100%; display: block; }
a { color: var(--green); }
a:hover { color: var(--green-dark); }
h1, h2, h3 { margin: 0; font-weight: 400; }
h1 { font-family: var(--serif); font-size: 34px; line-height: 1.05; }
h2 { font-family: var(--serif); font-size: 26px; line-height: 1.1; }
h3 { font-size: 16px; font-weight: 600; }
.em { font-style: italic; color: var(--green); }
.quiet { color: var(--quiet); }
.small { font-size: 14px; }
.tiny { font-size: 12px; }
.eyebrow { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; font-weight: 600; color: var(--quiet); }
.stack { display: flex; flex-direction: column; gap: 16px; }
.stack-s { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.between { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.grow { flex: 1 1 auto; min-width: 0; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- layout ---------- */
.splash { min-height: 100vh; display: grid; place-items: center; }
.spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--green); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.page { max-width: 520px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }
.page.wide { max-width: 760px; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 20px; padding-top: calc(14px + env(safe-area-inset-top, 0px));
  background: var(--ground); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); }
.brand-mark { width: 36px; height: 36px; border-radius: 18px; background: var(--green); display: grid; place-items: center; flex-shrink: 0; }
.brand-name { font-family: var(--serif); font-size: 22px; line-height: 1; }
.brand-sub { font-size: 12px; color: var(--quiet); }
.content { flex: 1 1 auto; padding: 20px; padding-bottom: calc(96px + var(--safe-bottom)); display: flex; flex-direction: column; gap: 16px; }
.content.no-nav { padding-bottom: calc(32px + var(--safe-bottom)); }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  background: var(--card); border-top: 1px solid var(--line);
  padding: 6px 8px calc(8px + var(--safe-bottom));
}
.tabbar-inner { max-width: 520px; margin: 0 auto; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); }
.tab {
  min-height: 52px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  font-size: 12px; font-weight: 600; color: #6B7268; text-decoration: none; border-radius: 12px;
}
.tab[aria-current="page"] { color: var(--green); }
.tab svg { width: 22px; height: 22px; }

.adminnav { display: flex; gap: 4px; flex-wrap: wrap; padding: 8px 20px 0; max-width: 760px; margin: 0 auto; width: 100%; }
.adminnav a { padding: 8px 14px; border-radius: 20px; text-decoration: none; font-size: 14px; font-weight: 600; color: var(--quiet); }
.adminnav a[aria-current="page"] { background: var(--green-tint); color: var(--green-dark); }
.badge { display: inline-block; min-width: 20px; padding: 0 6px; border-radius: 10px; background: var(--green); color: #fff; font-size: 12px; line-height: 20px; text-align: center; margin-left: 4px; }

.banner { background: var(--green-dark); color: var(--ground); padding: 10px 20px; font-size: 14px; display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.banner a { color: var(--green-light); font-weight: 600; }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 10px; }
.card.dark { background: var(--green); border-color: var(--green); color: var(--ground); }
.card.dark .eyebrow { color: #CFE0C4; }
.card.dark .sub { color: #E4EDDD; font-size: 14px; }
.card.tint { background: var(--green-tint); border-color: var(--green-tint); }
.card.warn { background: var(--warn-bg); border-color: var(--warn-line); color: var(--warn-ink); flex-direction: row; gap: 12px; align-items: flex-start; }
.card.error { background: #FBE9E5; border-color: #EBC2B8; color: #6B1E10; }
.card.empty { align-items: center; text-align: center; padding: 28px 20px; color: var(--quiet); }
.card-title { font-family: var(--serif); font-size: 26px; line-height: 1.1; }

.avatar { width: 40px; height: 40px; border-radius: 20px; background: var(--green-tint); color: var(--green); font-weight: 600; display: grid; place-items: center; flex-shrink: 0; }

/* health bars */
.meter { display: flex; flex-direction: column; gap: 4px; }
.meter-track { height: 8px; border-radius: 4px; background: #ECE8DC; overflow: hidden; }
.meter-fill { height: 8px; border-radius: 4px; background: var(--green); }

/* timeline */
.timeline { display: flex; flex-direction: column; }
.tl-item { display: flex; gap: 14px; }
.tl-rail { display: flex; flex-direction: column; align-items: center; width: 14px; flex-shrink: 0; }
.tl-dot { width: 12px; height: 12px; border-radius: 6px; background: var(--green); margin-top: 6px; }
.tl-line { flex: 1; width: 2px; background: var(--line-2); }
.tl-item:last-child .tl-line { background: transparent; }
.tl-body { flex: 1; min-width: 0; padding-bottom: 22px; display: flex; flex-direction: column; gap: 4px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 12px; background: var(--card); border: 1px solid var(--line); color: var(--ink-2); }

/* photos */
.thumbs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.thumb { padding: 0; border: 0; background: #D9D4C5; border-radius: 10px; overflow: hidden; aspect-ratio: 1 / 1; cursor: zoom-in; position: relative; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb .cap { position: absolute; left: 6px; bottom: 6px; font-size: 11px; padding: 2px 6px; border-radius: 8px; background: rgba(0,0,0,.55); color: #fff; }
.compare { position: relative; border-radius: 18px; overflow: hidden; background: #D9D4C5; aspect-ratio: 4 / 5; }
.compare img { width: 100%; height: 100%; object-fit: cover; }
.compare .tag { position: absolute; left: 12px; top: 12px; font-size: 12px; font-weight: 600; padding: 4px 10px; border-radius: 12px; background: var(--ground); color: var(--green-dark); }
.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(10,14,11,.92); display: grid; place-items: center; padding: 16px; }
.lightbox img { max-height: 90vh; border-radius: 12px; }
.lightbox button { position: absolute; top: calc(12px + env(safe-area-inset-top, 0px)); right: 12px; }

/* segmented control */
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; padding: 4px; border-radius: 24px; background: #ECE8DC; }
.seg button { min-height: 40px; border-radius: 20px; border: 0; background: transparent; font: inherit; font-size: 14px; font-weight: 600; color: var(--quiet); cursor: pointer; padding: 0 10px; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--green-dark); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ---------- buttons & forms ---------- */
.btn {
  min-height: 44px; padding: 0 18px; border-radius: 22px; border: 1px solid var(--green);
  background: var(--green); color: var(--ground); font: inherit; font-size: 15px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; cursor: pointer; text-decoration: none;
  white-space: nowrap; flex-shrink: 0;
}
.btn:hover { background: var(--green-dark); color: var(--ground); }
.btn.secondary { background: transparent; color: var(--green); }
.btn.secondary:hover { background: var(--green-tint); color: var(--green-dark); }
.btn.light { background: var(--ground); border-color: var(--ground); color: var(--green-dark); }
.btn.ghost-light { background: transparent; border-color: #8FB08A; color: var(--ground); }
.btn.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: #FBE9E5; }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 14px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: default; }
.iconbtn { width: 44px; height: 44px; border-radius: 22px; border: 1px solid var(--line-2); background: var(--card); display: grid; place-items: center; cursor: pointer; color: var(--green); text-decoration: none; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--green); font-weight: 600; cursor: pointer; text-decoration: underline; }

label { font-size: 14px; font-weight: 600; display: flex; flex-direction: column; gap: 6px; }
label .hint { font-weight: 400; color: var(--quiet); font-size: 13px; }
input, select, textarea {
  font: inherit; font-size: 16px; color: var(--ink); background: var(--card);
  border: 1px solid var(--line-2); border-radius: 12px; padding: 11px 12px; width: 100%; min-height: 44px;
}
textarea { min-height: 88px; resize: vertical; }
input:focus, select:focus, textarea:focus, .btn:focus-visible, .tab:focus-visible, .seg button:focus-visible, .thumb:focus-visible { outline: 3px solid #9CC48A; outline-offset: 1px; }
.check { flex-direction: row; align-items: center; gap: 10px; font-weight: 500; }
.check input { width: 22px; height: 22px; min-height: 0; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.grid4 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
@media (min-width: 640px) { .grid4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
fieldset { border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin: 0; display: flex; flex-direction: column; gap: 12px; }
legend { font-size: 14px; font-weight: 600; padding: 0 6px; }
legend .hint { font-weight: 400; color: var(--quiet); margin-left: 4px; }

details.card > summary { cursor: pointer; list-style: none; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: '+'; font-size: 22px; color: var(--green); }
details.card[open] > summary::after { content: '–'; }
details.card[open] > summary { margin-bottom: 8px; }

.list { display: flex; flex-direction: column; gap: 10px; }
.list-item { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; display: flex; gap: 12px; align-items: center; text-decoration: none; color: var(--ink); }
a.list-item:hover { border-color: var(--green); color: var(--ink); }
.pill { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 12px; background: var(--green-tint); color: var(--green-dark); white-space: nowrap; }
.pill.grey { background: #ECE8DC; color: var(--quiet); }
.pill.new { background: var(--warn-bg); color: var(--warn-ink); }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + var(--safe-bottom)); transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 14px; max-width: calc(100% - 32px);
  box-shadow: 0 6px 20px rgba(0,0,0,.2);
}

/* login */
.login { max-width: 420px; margin: 0 auto; min-height: 100vh; padding: 48px 24px; display: flex; flex-direction: column; gap: 24px; justify-content: center; }
.login .brand-mark { width: 56px; height: 56px; border-radius: 28px; }
.demo-note { font-size: 14px; background: var(--warn-bg); border: 1px solid var(--warn-line); color: var(--warn-ink); border-radius: 12px; padding: 12px 14px; }
