:root {
  --bg: #f4f2ed;
  --card: #ffffff;
  --ink: #1c211e;
  --muted: #6b716c;
  --line: #e3e0d8;
  --brand: #2f6b4f;
  --brand-ink: #ffffff;
  --gain: #1e7f4f;
  --loss: #b3372f;
  --warn: #a86b12;
  --bar: #1f2a24;
  --radius: 14px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --s-acquired: #5a6b8c; --s-rehab: #a86b12; --s-listed: #2f6ba8;
  --s-sold: #1e7f4f; --s-scrapped: #6d5a8c; --s-loss: #b3372f; --s-kept: #6b716c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121513; --card: #1b201d; --ink: #e8ebe8; --muted: #9aa29c; --line: #2b322e;
    --brand: #4c9a73; --gain: #52c08a; --loss: #ef6b61; --bar: #0c0f0d;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; background: var(--bg); color: var(--ink);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
a { color: var(--brand); }
button, input, select, textarea { font: inherit; color: inherit; }

.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 8px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px; background: var(--bar); color: #fff; }
.topbar h1 { font-size: 18px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-spacer { flex: 1; }
.icon-btn { background: none; border: 0; color: inherit; font-size: 30px; line-height: 1; padding: 0 8px 0 0; cursor: pointer; }

main { max-width: 760px; margin: 0 auto; padding: 16px 16px calc(var(--tab-h) + var(--safe-b) + 24px); }

.tabbar { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; justify-content: space-around; align-items: center;
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b); background: var(--card); border-top: 1px solid var(--line); }
.tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; font-size: 11px; color: var(--muted); text-decoration: none; gap: 2px; }
.tabbar a span { font-size: 20px; line-height: 1; }
.tabbar a.active { color: var(--brand); font-weight: 600; }
.tabbar .tab-add span { width: 52px; height: 52px; border-radius: 50%; background: var(--brand); color: var(--brand-ink);
  display: grid; place-items: center; font-size: 28px; margin-top: -18px; box-shadow: 0 4px 12px rgb(0 0 0 / .2); }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.card h2 { font-size: 14px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 10px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.gain { color: var(--gain); } .loss { color: var(--loss); }
.num { font-variant-numeric: tabular-nums; }
.center { text-align: center; }
.stack > * + * { margin-top: 10px; }

.kpis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 12px; }
@media (min-width: 600px) { .kpis { grid-template-columns: repeat(4, 1fr); } }
.kpi { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.kpi .label { font-size: 12px; color: var(--muted); }
.kpi .value { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 12px; scrollbar-width: none; }
.chip { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.chip.active { background: var(--ink); color: var(--bg); border-color: var(--ink); }

.badge { display: inline-block; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .03em;
  padding: 3px 8px; border-radius: 999px; color: #fff; background: var(--s-kept); }
.badge.acquired { background: var(--s-acquired); } .badge.rehab { background: var(--s-rehab); } .badge.listed { background: var(--s-listed); }
.badge.sold { background: var(--s-sold); } .badge.scrapped { background: var(--s-scrapped); } .badge.loss { background: var(--s-loss); }

.list { list-style: none; margin: 0; padding: 0; }
.list-item { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; }
.list-item:last-child { border-bottom: 0; }
.thumb { width: 56px; height: 56px; border-radius: 10px; object-fit: cover; background: var(--line); flex: none; display: grid; place-items: center; color: var(--muted); font-size: 22px; }
.title-line { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

label.field { display: block; margin-bottom: 12px; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input, select, textarea { width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--card); font-size: 16px; }
textarea { min-height: 80px; resize: vertical; }
input:not([type=checkbox]):not([type=file]), select { height: 48px; min-width: 0; }
.grid2 > * { min-width: 0; }
input[type=date] { -webkit-appearance: none; appearance: none; display: block; }
.sheet-actions .row { flex-wrap: wrap; }
.sheet-actions .row .btn { flex: 1 1 30%; white-space: nowrap; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--card);
  border-radius: 10px; padding: 11px 14px; font-weight: 600; cursor: pointer; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.danger { color: var(--loss); }
.btn.block { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 14px; }
.btn:disabled { opacity: .5; }
.btn-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 8px; }

.photos { display: flex; gap: 8px; overflow-x: auto; margin: -2px 0 12px; }
.photos img { height: 160px; border-radius: 12px; flex: none; }
.photo-add { height: 160px; width: 120px; flex: none; border: 2px dashed var(--line); border-radius: 12px; display: grid; place-items: center; color: var(--muted); cursor: pointer; text-align: center; font-size: 14px; }

.money td { padding: 4px 0; } .money td:last-child { text-align: right; font-variant-numeric: tabular-nums; }
.money { width: 100%; border-collapse: collapse; }
.money tr.total td { border-top: 1px solid var(--line); font-weight: 700; padding-top: 8px; }

.bars .bar-row { display: grid; grid-template-columns: 90px 1fr 70px; gap: 8px; align-items: center; font-size: 13px; margin: 6px 0; }
.bar-track { height: 10px; background: var(--line); border-radius: 5px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--gain); border-radius: 5px; }
.bar-fill.neg { background: var(--loss); }

.stats-range { display: grid; grid-template-columns: repeat(3, 1fr); text-align: center; gap: 6px; margin: 8px 0; }
.stats-range .value { font-size: 20px; font-weight: 700; }
.comp { display: flex; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.comp img { width: 44px; height: 44px; object-fit: cover; border-radius: 8px; flex: none; }
.comp.picked { background: color-mix(in srgb, var(--gain) 9%, transparent); }
.comp.comp-all { border-bottom-width: 2px; }
.comp input[type=checkbox] { width: 22px; height: 22px; flex: none; }
button.comp.recent-search { width: 100%; background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left; cursor: pointer; font: inherit; color: inherit; }

.sheet { position: fixed; inset: 0; z-index: 50; }
.sheet-backdrop { position: absolute; inset: 0; background: rgb(0 0 0 / .45); }
.sheet-panel { position: absolute; left: 0; right: 0; bottom: 0; max-height: 90vh; overflow-y: auto; background: var(--bg);
  border-radius: 18px 18px 0 0; padding: 18px 16px calc(18px + var(--safe-b)); max-width: 760px; margin: 0 auto; animation: up .18s ease-out; }
.sheet-panel h3 { margin: 0 0 12px; }
@keyframes up { from { transform: translateY(40px); opacity: .5; } }

/* Collapsible sections (AI report, forms) */
details.sec { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin-bottom: 8px; }
details.sec > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 8px; padding: 12px 14px; font-weight: 600; }
details.sec > summary::-webkit-details-marker { display: none; }
details.sec > summary::after { content: '›'; margin-left: 4px; color: var(--muted); font-size: 20px; line-height: 1; transition: transform .15s; }
details.sec[open] > summary::after { transform: rotate(90deg); }
details.sec > summary .t { flex: 1; min-width: 0; }
details.sec > summary .meta { font-weight: 400; color: var(--muted); font-size: 13px; text-align: right; }
details.sec > .sec-body { padding: 0 14px 12px; font-size: 14px; }
details.sec.plain { background: none; border-style: dashed; }

/* Sticky action bars: bottom of a sheet, or above the tab bar on a page */
.sheet-actions { position: sticky; bottom: calc(-18px - var(--safe-b)); margin: 12px -16px calc(-18px - var(--safe-b));
  padding: 10px 16px calc(10px + var(--safe-b)); background: var(--bg); border-top: 1px solid var(--line); display: grid; gap: 8px; z-index: 2; }
.sheet-actions .row .btn { flex: 1; }
.page-actions { position: sticky; bottom: calc(var(--tab-h) + var(--safe-b) + 8px); z-index: 5; margin-top: 12px;
  padding: 8px; background: color-mix(in srgb, var(--bg) 85%, transparent); backdrop-filter: blur(6px); border-radius: var(--radius); }

/* Decision summary at the top of an AI report */
.decision { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }
.decision .big { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.decision .big .label { font-size: 12px; color: var(--muted); }
.decision .big .value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.1; }
.decision .lines { margin-top: 10px; display: grid; gap: 4px; font-size: 14px; }
.pill { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); }
.pill.high { color: var(--gain); border-color: currentColor; } .pill.medium { color: var(--warn); border-color: currentColor; } .pill.low { color: var(--loss); border-color: currentColor; }
.callout { border-left: 3px solid var(--warn); padding: 6px 10px; background: color-mix(in srgb, var(--warn) 10%, transparent); border-radius: 6px; font-size: 13px; }

/* Slim photo row */
.photo-strip { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 12px; align-items: center; }
.photo-strip img { height: 96px; width: 96px; object-fit: cover; border-radius: 12px; flex: none; }
.photo-strip .photo-add.sm { height: 96px; width: 96px; font-size: 13px; }
.btn.photo-btn { width: 100%; border-style: dashed; color: var(--muted); font-weight: 500; margin-bottom: 12px; }

.outcomes { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.outcomes .btn { flex: 1 1 auto; }
.tips { margin: 0; padding-left: 18px; }
.tips li + li { margin-top: 4px; }

.ai-pill { border: 0; border-radius: 999px; padding: 6px 12px; font-size: 13px; font-weight: 600; background: rgb(255 255 255 / .14); color: #fff; cursor: pointer; white-space: nowrap; }
.ai-pill.ready { background: #e8b64c; color: #1c211e; animation: pulse 1.6s ease-in-out 3; }
@keyframes pulse { 50% { transform: scale(1.06); } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + var(--safe-b) + 16px); z-index: 60;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 14px; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.login { max-width: 360px; margin: 15vh auto; }
