:root {
  --bg: #f4f5f3;
  --card: #ffffff;
  --text: #1a1c1a;
  --muted: #6b7280;
  --border: #e3e5e1;
  --accent: #1f6f4f;
  --accent-soft: #e5f0ea;
  --danger: #b3261e;
  --radius: 14px;
  --tabbar-h: 60px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121412;
    --card: #1e211e;
    --text: #eef0ec;
    --muted: #9aa39a;
    --border: #313531;
    --accent: #4cbf8f;
    --accent-soft: #1c2b24;
    --danger: #ff6b61;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro", "Segoe UI", Roboto,
    "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  line-height: 1.45;
}
.app {
  max-width: 640px;
  margin: 0 auto;
  padding: 14px 14px calc(var(--tabbar-h) + var(--safe-b) + 24px);
}

h1 { font-size: 1.35rem; margin: 6px 2px 14px; }
h2 { font-size: 1.05rem; margin: 4px 2px 10px; }
p.muted, .muted { color: var(--muted); }
small { color: var(--muted); }

button, .btn {
  font: inherit;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 14px;
  cursor: pointer;
}
button.primary, .btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
}
button.ghost { background: transparent; }
button.link {
  border: none; background: none; color: var(--accent);
  padding: 4px 2px; text-decoration: underline;
}
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button:disabled { opacity: .5; cursor: default; }
button.block, .btn.block { width: 100%; display: block; text-align: center; }

input, select {
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
label.field { display: block; margin: 8px 0; min-width: 0; }
label.field span { display: block; font-size: .8rem; color: var(--muted); margin-bottom: 4px; }
/* iOS date inputs report a wide intrinsic size and won't shrink inside a
   flex/grid cell without this — that was pushing the 구매일 box off-screen. */
input[type="date"] { -webkit-appearance: none; appearance: none; min-width: 0; max-width: 100%; }

.search-input {
  font-size: 1.1rem;
  padding: 13px 14px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 12px;
}
a.card { display: block; color: inherit; text-decoration: none; }

.row { display: flex; gap: 10px; align-items: center; }
.row.between { justify-content: space-between; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 10px; }

.group-label { font-size: 1.05rem; font-weight: 650; }
.price-big { font-size: 1.5rem; font-weight: 700; letter-spacing: -.01em; }
.price-big .won { font-size: .95rem; font-weight: 500; color: var(--muted); margin-left: 2px; }
.meta { color: var(--muted); font-size: .85rem; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 6px 0 14px; }
.stats .stat {
  background: var(--accent-soft); border-radius: 10px; padding: 8px 6px; text-align: center;
}
.stats .stat b { display: block; font-size: 1rem; }
.stats .stat span { font-size: .72rem; color: var(--muted); }

.spark { width: 100%; height: 56px; display: block; margin: 4px 0 14px; }

.hist-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; padding: 10px 0; border-top: 1px solid var(--border); }
.hist-row:first-child { border-top: none; }
.hist-row .date { font-weight: 600; }
.hist-row .sub { color: var(--muted); font-size: .82rem; }
.hist-row .amt { text-align: right; font-weight: 650; }
.hist-actions { grid-column: 1 / -1; display: flex; gap: 12px; }
.edit-grid { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.edit-grid .full { grid-column: 1 / -1; }

.thumbs { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 8px; margin: 12px 0; }
.thumb { position: relative; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button {
  position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; padding: 0;
  border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; border: none; line-height: 1;
}

.review-item { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 10px; }
.line { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.line > * { min-width: 0; }
.line .full { grid-column: 1 / -1; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + var(--safe-b));
  padding-bottom: var(--safe-b);
  display: flex; background: var(--card); border-top: 1px solid var(--border);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 2px; text-decoration: none; color: var(--muted); font-size: 1.2rem;
}
.tabbar a span { font-size: .68rem; }
.tabbar a.active { color: var(--accent); }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--tabbar-h) + var(--safe-b) + 16px);
  background: #222; color: #fff; padding: 10px 16px; border-radius: 999px;
  font-size: .9rem; z-index: 50; max-width: 90vw; text-align: center;
}
.empty { text-align: center; color: var(--muted); padding: 40px 16px; }
.spinner { display: inline-block; width: 16px; height: 16px; border: 2px solid var(--border);
  border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -3px; }
@keyframes spin { to { transform: rotate(360deg); } }
.hidden { display: none !important; }
