/* ===== リセット & 基本 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; -webkit-font-smoothing: antialiased; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%;
  overscroll-behavior-y: contain;
}
body {
  font-family: -apple-system, "Hiragino Sans", "Yu Gothic UI", "BIZ UDPGothic", sans-serif;
  background: #f7f8fa;
  color: #1c1c1e;
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: env(safe-area-inset-bottom);
}
input, button, select, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; border: none; background: none; color: inherit; }

/* ===== レイアウト ===== */
#app {
  max-width: 520px;
  margin: 0 auto;
  min-height: 100vh;
  background: #f7f8fa;
  display: flex;
  flex-direction: column;
  padding-bottom: 70px;
}

.header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: rgba(247, 248, 250, 0.92);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 10px 18px 10px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 54px;
}
.header h1 {
  font-size: 22px;
  font-weight: 700;
}
.header .sub {
  color: #8e8e93;
  font-size: 12px;
  margin-top: 2px;
}
.header .right { display: flex; gap: 6px; align-items: center; }

.back-btn, .link-btn {
  color: #4f8cff;
  font-size: 15px;
  font-weight: 500;
  padding: 6px 4px;
}
.icon-btn {
  font-size: 22px;
  padding: 4px 8px;
  color: #4f8cff;
}

.content {
  flex: 1;
  padding: 4px 16px 20px;
}

/* ===== タブバー ===== */
.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(62px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(255,255,255,0.96);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  max-width: 520px;
  margin: 0 auto;
  z-index: 20;
}
.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  color: #8e8e93;
  padding: 6px 2px;
}
.tab-item .icon { font-size: 22px; margin-bottom: 2px; }
.tab-item.active { color: #4f8cff; font-weight: 600; }

/* ===== カード ===== */
.card {
  background: white;
  border-radius: 14px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}
.card-title {
  font-size: 12px;
  color: #8e8e93;
  font-weight: 600;
  margin-bottom: 10px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

/* ===== 統計 ===== */
.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.stat {
  background: white;
  border-radius: 14px;
  padding: 12px 6px;
  text-align: center;
}
.stat .num { font-size: 22px; font-weight: 700; color: #4f8cff; }
.stat .label { font-size: 11px; color: #8e8e93; margin-top: 2px; }

/* ===== あいさつ ===== */
.greeting { margin: 4px 2px 14px; }
.greeting .hi { font-size: 13px; color: #8e8e93; }
.greeting .main { font-size: 18px; font-weight: 700; margin-top: 2px; }

/* ===== 項目行 ===== */
.item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid #f0f0f5;
  gap: 10px;
  cursor: pointer;
}
.item-row:last-child { border-bottom: none; }
.item-row:active { background: #f5f5f7; }
.item-row .left { min-width: 0; flex: 1; }
.item-row .name { font-size: 14px; font-weight: 500; word-break: break-word; }
.item-row .meta { font-size: 11px; color: #8e8e93; margin-top: 3px; display: flex; align-items: center; flex-wrap: wrap; gap: 4px; }
.item-row .right-col { text-align: right; flex-shrink: 0; }
.item-row .price { font-size: 15px; font-weight: 700; }
.item-row .per-unit { font-size: 11px; color: #4f8cff; font-weight: 600; }
.item-row .chevron { color: #c7c7cc; font-size: 18px; }

/* ===== バッジ ===== */
.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 8px;
  font-size: 10px;
  font-weight: 600;
  white-space: nowrap;
}
.badge-cat-食品 { background: #ffedd5; color: #c2410c; }
.badge-cat-日用品 { background: #dbeafe; color: #1d4ed8; }
.badge-cat-薬 { background: #fce7f3; color: #be185d; }
.badge-cat-飲料 { background: #d1fae5; color: #047857; }
.badge-cat-その他 { background: #f1f5f9; color: #475569; }
.badge-cat-default { background: #eef0f3; color: #475569; }
.badge-store { background: #e0e7ff; color: #4338ca; }
.badge-online { background: #fae8ff; color: #86198f; }
.badge-cheapest { background: #fef3c7; color: #b45309; }
.pill {
  display: inline-block;
  padding: 2px 8px;
  background: #e0f2fe;
  color: #0369a1;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 600;
}

/* ===== 検索・チップ ===== */
.search-bar {
  background: #eef0f3;
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  margin-bottom: 10px;
  width: 100%;
  border: none;
  outline: none;
}
.chips {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  flex-wrap: wrap;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.chip {
  padding: 6px 14px;
  background: white;
  border-radius: 14px;
  font-size: 12px;
  color: #555;
  border: 1px solid #e5e7eb;
  white-space: nowrap;
  cursor: pointer;
}
.chip.active {
  background: #4f8cff;
  color: white;
  border-color: #4f8cff;
  font-weight: 600;
}

/* ===== タブ切り替え ===== */
.tab-switch {
  display: flex;
  background: #eef0f3;
  border-radius: 10px;
  padding: 3px;
  margin-bottom: 14px;
}
.tab-switch .tab {
  flex: 1;
  text-align: center;
  padding: 8px;
  font-size: 13px;
  border-radius: 8px;
  color: #6b7280;
  font-weight: 500;
  cursor: pointer;
}
.tab-switch .tab.active {
  background: white;
  color: #1c1c1e;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}

/* ===== 比較行 ===== */
.price-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px;
  background: white;
  border-radius: 12px;
  margin-bottom: 8px;
  gap: 10px;
  cursor: pointer;
}
.price-row:active { opacity: 0.7; }
.price-row.best {
  background: linear-gradient(135deg, #fef9c3 0%, #fef3c7 100%);
  border: 1px solid #fcd34d;
}
.price-row .store { font-weight: 600; font-size: 14px; display: flex; align-items: center; flex-wrap: wrap; gap: 6px; }
.price-row .detail { font-size: 11px; color: #8e8e93; margin-top: 4px; }
.price-row .detail a { color: #4f8cff; text-decoration: none; }
.price-row .amount { text-align: right; flex-shrink: 0; }
.price-row .amount .main { font-size: 16px; font-weight: 700; }
.price-row .amount .sub { font-size: 11px; color: #4f8cff; font-weight: 600; }

/* ===== フォーム ===== */
.form-group { margin-bottom: 14px; }
.form-group label {
  display: block;
  font-size: 12px;
  color: #6b7280;
  margin-bottom: 6px;
  font-weight: 500;
}
.form-group label .note { color: #8e8e93; font-weight: normal; margin-left: 4px; }
.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  font-size: 15px;
  background: white;
  outline: none;
}
.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: #4f8cff;
}
.form-group textarea { resize: vertical; min-height: 70px; }
.form-row { display: flex; gap: 8px; }
.form-row > .form-group { flex: 1; }

.preview-box {
  background: #f0f7ff;
  border: 1px dashed #93c5fd;
  border-radius: 10px;
  padding: 14px;
  text-align: center;
  color: #1d4ed8;
  margin-top: 8px;
  margin-bottom: 14px;
}
.preview-box .label { font-size: 12px; }
.preview-box .big { font-size: 24px; font-weight: 700; margin-top: 4px; }
.preview-box .formula { font-size: 11px; margin-top: 4px; color: #4338ca; }
.preview-box.warn { background: #fef3c7; border-color: #fcd34d; color: #92400e; }

/* ===== ボタン ===== */
.primary-btn {
  width: 100%;
  background: #4f8cff;
  color: white;
  padding: 14px;
  border-radius: 12px;
  text-align: center;
  font-weight: 600;
  font-size: 15px;
  margin-top: 8px;
  cursor: pointer;
}
.primary-btn:active { opacity: 0.85; }
.primary-btn:disabled { background: #c7c7cc; cursor: not-allowed; }
.secondary-btn {
  width: 100%;
  background: white;
  color: #4f8cff;
  padding: 13px;
  border-radius: 12px;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid #e5e7eb;
  margin-bottom: 8px;
  cursor: pointer;
}
.danger-btn {
  width: 100%;
  background: white;
  color: #dc2626;
  padding: 13px;
  border-radius: 12px;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
  border: 1px solid #fecaca;
  cursor: pointer;
}
.ghost-btn {
  background: #eef0f3;
  color: #555;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

/* ===== 設定 ===== */
.setting-heading {
  font-size: 11px;
  color: #8e8e93;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  margin: 8px 4px 6px;
  font-weight: 600;
}
.setting-group {
  margin-bottom: 18px;
  border-radius: 12px;
  overflow: hidden;
  background: white;
}
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px;
  border-bottom: 1px solid #f0f0f5;
  cursor: pointer;
}
.setting-row:last-child { border-bottom: none; }
.setting-row:active { background: #f5f5f7; }
.setting-row .label { font-size: 15px; }
.setting-row .label .desc { font-size: 12px; color: #8e8e93; margin-top: 2px; }
.setting-row .value { color: #8e8e93; font-size: 13px; }
.setting-row .chevron { color: #c7c7cc; font-size: 18px; }

/* ===== モーダル風シート ===== */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  background: white;
  width: 100%;
  max-width: 520px;
  border-radius: 18px 18px 0 0;
  padding: 20px;
  max-height: 80vh;
  overflow-y: auto;
}
.sheet h3 { margin-bottom: 14px; }

/* ===== 空状態 ===== */
.empty {
  text-align: center;
  color: #8e8e93;
  padding: 40px 20px;
}
.empty .emoji { font-size: 48px; margin-bottom: 10px; }
.empty .msg { font-size: 14px; line-height: 1.7; }
.empty .sub { font-size: 12px; margin-top: 6px; }

/* ===== トースト ===== */
.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(30,30,30,0.9);
  color: white;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  z-index: 200;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  animation: toast-in 0.2s ease-out;
}
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ===== カテゴリ編集 ===== */
.cat-edit-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid #f0f0f5;
}
.cat-edit-row input { flex: 1; padding: 8px 10px; border: 1px solid #e5e7eb; border-radius: 8px; }
.cat-edit-row .del-btn { color: #dc2626; padding: 6px 10px; font-size: 18px; }

/* ===== ユーティリティ ===== */
.hidden { display: none !important; }
.muted { color: #8e8e93; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-2 { gap: 8px; }

.price-strong { font-size: 17px; font-weight: 700; }

/* インストール案内バナー */
.install-banner {
  background: #e0f2fe;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 13px;
  color: #0c4a6e;
  line-height: 1.6;
}
.install-banner .close-x {
  float: right;
  color: #0369a1;
  cursor: pointer;
  padding: 0 4px;
}
