:root {
  --bg: #f2f5f3;
  --surface: #ffffff;
  --surface-2: #e9efeb;
  --text: #17211b;
  --muted: #6f7d75;
  --line: #dfe7e2;
  --accent: #2f6f4e;
  --accent-2: #3d8a63;
  --accent-soft: #e3efe8;
  --danger: #c0443c;
  --gold: #a9781f;
  --shadow: 0 10px 30px rgba(20, 40, 30, .08);
  --radius: 16px;
}

[data-theme="dark"] {
  --bg: #0d1310;
  --surface: #151f1a;
  --surface-2: #1d2a23;
  --text: #e9f2ec;
  --muted: #93a59b;
  --line: #26362d;
  --accent: #5cc08a;
  --accent-2: #7bd3a2;
  --accent-soft: #1b3327;
  --danger: #ff7b72;
  --gold: #e0b25c;
  --shadow: 0 10px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  transition: background .2s, color .2s;
}
button, input, textarea, select { font: inherit; }
button { color: inherit; }
.hidden { display: none !important; }

.app {
  width: 100%;
  max-width: 820px;
  margin: 0 auto;
  padding: 0 12px calc(84px + env(safe-area-inset-bottom));
}

/* ---------- top bar ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(10px + env(safe-area-inset-top)) 2px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 19px;
  font-weight: 750;
  letter-spacing: -.2px;
}
.logo {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
}
.badge {
  padding: 3px 7px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .4px;
}
.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  cursor: pointer;
  font-size: 17px;
}
.icon-btn:active { transform: scale(.96); }

/* ---------- search ---------- */
.search-wrap {
  position: sticky;
  top: calc(60px + env(safe-area-inset-top));
  z-index: 19;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 2px 0 10px;
  padding: 0 12px;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(0, 0, 0, .03);
}
.search-icon { opacity: .55; font-size: 15px; }
#search {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 16px;
}
#search::placeholder { color: var(--muted); }
.clear {
  width: 26px;
  height: 26px;
  border: 0;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

/* ---------- chips ---------- */
.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 1px 12px;
  scrollbar-width: none;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.chip small { opacity: .75; margin-left: 4px; }

/* ---------- catalog grid ---------- */
.content { min-height: 55vh; }
.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
@media (min-width: 540px) { .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; } }
@media (min-width: 760px) { .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }

.card {
  display: flex;
  flex-direction: column;
  text-align: left;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .03);
  overflow: hidden;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
}
.card:active { transform: scale(.985); box-shadow: var(--shadow); }
.thumb {
  position: relative;
  aspect-ratio: 1 / 1;
  background: var(--surface-2);
  overflow: hidden;
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.ph {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(120% 90% at 20% 10%, hsl(var(--hue) 45% 86%) 0%, transparent 60%),
    linear-gradient(145deg, hsl(var(--hue) 32% 76%), hsl(var(--hue) 38% 62%));
  color: rgba(255, 255, 255, .92);
}
[data-theme="dark"] .ph {
  background:
    radial-gradient(120% 90% at 20% 10%, hsl(var(--hue) 30% 32%) 0%, transparent 60%),
    linear-gradient(145deg, hsl(var(--hue) 26% 24%), hsl(var(--hue) 30% 15%));
}
.ph span { font-size: 38px; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .15)); }
.ph small {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .3px;
  text-transform: uppercase;
  opacity: .9;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-body { padding: 9px 10px 11px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.card-title {
  font-size: 13px;
  font-weight: 650;
  line-height: 1.25;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-sub {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-row { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; margin-top: 2px; }
.price { font-size: 15px; font-weight: 800; letter-spacing: -.2px; }
.profit { font-size: 11px; font-weight: 700; color: var(--accent); }
.profit.loss { color: var(--danger); }
.tag {
  position: absolute;
  top: 7px;
  left: 7px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(10, 20, 15, .62);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  backdrop-filter: blur(4px);
}
.tag.sold { background: rgba(60, 70, 66, .7); }
.tag.archive { background: rgba(120, 90, 30, .75); }
.qty {
  position: absolute;
  right: 7px;
  bottom: 7px;
  padding: 3px 7px;
  border-radius: 999px;
  background: rgba(10, 20, 15, .62);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
}

/* ---------- states ---------- */
.empty {
  padding: 56px 18px;
  text-align: center;
  color: var(--muted);
}
.empty .big { font-size: 40px; margin-bottom: 10px; }
.empty b { display: block; color: var(--text); font-size: 16px; margin-bottom: 4px; }
.skeleton-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
@media (min-width: 540px) { .skeleton-grid { grid-template-columns: repeat(3, 1fr); } }
.sk-card {
  aspect-ratio: .78;
  border-radius: var(--radius);
  background: linear-gradient(100deg, var(--surface) 20%, var(--surface-2) 40%, var(--surface) 60%);
  background-size: 220% 100%;
  animation: shine 1.2s infinite linear;
}
@keyframes shine { to { background-position: -120% 0; } }
.more {
  display: block;
  width: 100%;
  margin: 14px 0 4px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--surface);
  color: var(--accent);
  font-weight: 700;
  cursor: pointer;
}

/* ---------- bottom nav ---------- */
.bottom-nav {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: 100%;
  max-width: 820px;
  transform: translateX(-50%);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}
.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 7px 2px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: var(--muted);
  font-size: 10px;
  font-weight: 650;
  cursor: pointer;
}
.nav-btn span { font-size: 18px; line-height: 1.1; filter: grayscale(1); opacity: .75; }
.nav-btn.active { color: var(--accent); background: var(--accent-soft); }
.nav-btn.active span { filter: none; opacity: 1; }

/* ---------- sheet ---------- */
.backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, .45);
  animation: fade .18s ease;
}
@keyframes fade { from { opacity: 0; } }
.sheet {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 820px;
  max-height: 94vh;
  max-height: 94dvh;
  transform: translateX(-50%);
  border-radius: 22px 22px 0 0;
  background: var(--surface);
  box-shadow: 0 -10px 40px rgba(0, 0, 0, .22);
  animation: slide .22s cubic-bezier(.2, .8, .2, 1);
  overflow: hidden;
}
@keyframes slide { from { transform: translate(-50%, 100%); } }
.sheet-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.sheet-title {
  flex: 1;
  min-width: 0;
  font-size: 15px;
  font-weight: 750;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sheet-body {
  padding: 14px 14px calc(22px + env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

/* ---------- detail ---------- */
.gallery {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  margin: -4px -14px 14px;
  padding: 4px 14px;
  scrollbar-width: none;
}
.gallery::-webkit-scrollbar { display: none; }
.gallery .shot {
  position: relative;
  flex: 0 0 86%;
  max-width: 360px;
  max-height: 46vh;
  scroll-snap-align: center;
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  overflow: hidden;
  background: var(--surface-2);
}
.gallery .shot img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery .shot .ph span { font-size: 64px; }

.detail-title { margin: 0 0 4px; font-size: 21px; line-height: 1.2; letter-spacing: -.3px; }
.detail-sub { color: var(--muted); font-size: 13px; margin-bottom: 4px; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.pill {
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 650;
}
.pill.ok { background: var(--accent-soft); color: var(--accent); }
.money-box {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0;
}
.money-cell {
  padding: 11px 12px;
  border-radius: 13px;
  background: var(--surface-2);
}
.money-cell small { display: block; color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.money-cell b { font-size: 17px; }
.money-cell.accent { background: var(--accent-soft); }
.money-cell.accent b { color: var(--accent); }
.money-cell.bad b { color: var(--danger); }
.attrs { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.attr {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 12px;
  color: var(--muted);
}
.attr b { color: var(--text); font-weight: 650; }
.note {
  margin: 12px 0;
  padding: 11px 12px;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 13px;
  line-height: 1.45;
  color: var(--muted);
}
.link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
  margin: 4px 0 12px;
}
.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.actions .wide { grid-column: 1 / -1; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.soft { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--line)); }
.btn:disabled { opacity: .55; cursor: default; }

/* ---------- forms ---------- */
.form { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 600; }
.field input, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface);
  color: var(--text);
  font-size: 16px;
  outline: none;
}
.field input:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.hint { font-size: 12px; color: var(--muted); line-height: 1.4; }
.total-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  border-radius: 12px;
  background: var(--surface-2);
  font-size: 14px;
}
.total-line b { font-size: 19px; }
.total-line b.neg { color: var(--danger); }

/* ---------- stats ---------- */
.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-bottom: 14px; }
.stat {
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface);
}
.stat small { display: block; color: var(--muted); font-size: 11px; margin-bottom: 5px; }
.stat b { font-size: 19px; letter-spacing: -.3px; }
.stat.accent { background: var(--accent-soft); border-color: transparent; }
.stat.accent b { color: var(--accent); }
.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 20px 2px 10px;
  font-size: 13px;
  font-weight: 750;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
}
.month { display: flex; align-items: center; gap: 9px; margin: 7px 0; font-size: 12px; }
.month .m-name { width: 46px; color: var(--muted); flex: 0 0 auto; }
.month .m-bar { flex: 1; height: 8px; border-radius: 99px; background: var(--surface-2); overflow: hidden; }
.month .m-bar i { display: block; height: 100%; border-radius: 99px; background: var(--accent); }
.month .m-val { width: 86px; text-align: right; font-weight: 700; flex: 0 0 auto; }
.top-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
}
.top-row:last-child { border-bottom: 0; }
.top-row b { color: var(--accent); white-space: nowrap; }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 80;
  max-width: 86%;
  transform: translate(-50%, 16px);
  padding: 11px 15px;
  border-radius: 12px;
  background: #1d2a23;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  box-shadow: 0 8px 26px rgba(0, 0, 0, .25);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.err { background: #a63d36; }
