:root {
  --bg: #f5f6f4;
  --surface: #ffffff;
  --text: #1b1f1c;
  --text-muted: #6b756f;
  --border: #dfe3e0;
  --accent: #1b6f5c;
  --accent-contrast: #ffffff;
  --buy: #1b8a4c;
  --ok: #b3891a;
  --high: #c23b3b;
  --muted-badge: #8a8f8c;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14181a;
    --surface: #1e2426;
    --text: #ecf1ee;
    --text-muted: #9aa39d;
    --border: #303836;
    --accent: #3fae90;
    --accent-contrast: #08201a;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", system-ui, sans-serif;
}

#app {
  padding: 12px 12px 84px;
  max-width: 640px;
  margin: 0 auto;
  min-height: 100vh;
}

h1 { font-size: 1.2rem; margin: 4px 0 12px; }
h2 { font-size: 1.05rem; margin: 16px 0 8px; }
p.hint { color: var(--text-muted); font-size: 0.85rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 10px;
}

.tile {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}
.tile .name { font-weight: 600; }
.tile .price { text-align: right; }
.tile .price .value { font-size: 1.1rem; font-weight: 700; color: var(--accent); }
.tile .price .store { display: block; font-size: 0.75rem; color: var(--text-muted); }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
}
.badge.buy { background: var(--buy); }
.badge.ok { background: var(--ok); }
.badge.high { background: var(--high); }
.badge.insufficient_data { background: var(--muted-badge); }

.row { display: flex; gap: 8px; align-items: center; }
.row.between { justify-content: space-between; }
.row.wrap { flex-wrap: wrap; }

label { display: block; font-size: 0.8rem; color: var(--text-muted); margin: 8px 0 2px; }
input, select, textarea {
  width: 100%;
  padding: 9px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}
textarea { min-height: 60px; }

button {
  padding: 10px 16px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
}
button.primary {
  background: var(--accent);
  color: var(--accent-contrast);
  border-color: var(--accent);
  font-weight: 700;
}
button.danger { color: var(--high); border-color: var(--high); }
button:disabled { opacity: 0.5; }

.checkbox-row { display: flex; align-items: center; gap: 8px; }
.checkbox-row input { width: auto; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th, td { text-align: left; padding: 6px 4px; border-bottom: 1px solid var(--border); }
th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; }

.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); }

.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1;
  text-align: center;
  padding: 10px 0 8px;
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.78rem;
}
.tabbar a.active { color: var(--accent); font-weight: 700; }

.toast {
  position: fixed;
  top: env(safe-area-inset-top, 0);
  left: 50%;
  transform: translateX(-50%);
  margin-top: 10px;
  background: var(--text);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 100;
}
.toast.error { background: var(--high); color: #fff; }

.spinner {
  display: inline-block;
  width: 1em; height: 1em;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: -0.15em;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { color: var(--text-muted); text-align: center; padding: 24px 0; }
