/* =====================================================================
   Price Tracker — style.css
   白・深緑・金。大きな文字とボタン、高コントラスト。
   ===================================================================== */

:root {
  --green: #1b4a31;
  --green-2: #23613f;
  --green-soft: #e8f1eb;
  --gold: #8a6212;          /* 文字用（白背景でコントラスト確保） */
  --gold-bright: #d9a93c;   /* ボタン・アクセント背景 */
  --gold-soft: #fbf3df;
  --text: #141816;
  --text-2: #2f3732;        /* 補助テキストも濃いめ */
  --line: #c6cfc8;
  --line-soft: #e2e7e3;
  --bg: #f4f5f1;
  --card: #ffffff;
  --danger: #a3221a;
  --danger-soft: #fcebe9;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 2px 10px rgba(0, 0, 0, .04);
  --header-h: 60px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, sans-serif;
  font-size: 17px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}
body.has-bottom-nav { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }
@media (min-width: 900px) { body.has-bottom-nav { padding-bottom: 0; } }

h1, h2, h3 { line-height: 1.3; margin: 0; }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.2rem; }
p { margin: 0 0 .5em; }
a { color: var(--green-2); }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--gold-bright); outline-offset: 2px; }

.container { max-width: 1200px; margin: 0 auto; padding: 20px 16px 40px; }
@media (min-width: 900px) { .container { padding: 28px 32px 56px; } }
main:focus { outline: none; }

/* ---------- ヘッダー / ナビ ---------- */
.app-header { background: var(--green); color: #fff; position: sticky; top: 0; z-index: 30; }
.app-header-inner {
  max-width: 1200px; margin: 0 auto; padding: 0 16px; height: var(--header-h);
  display: flex; align-items: center; gap: 24px;
}
@media (min-width: 900px) { .app-header-inner { padding: 0 32px; } }
.brand { color: #fff; text-decoration: none; font-weight: 800; font-size: 1.2rem; display: flex; align-items: center; gap: 10px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 9px; background: var(--gold-bright); color: var(--green);
  display: grid; place-items: center; font-weight: 900; font-size: 1.15rem;
}
.top-nav { display: none; margin-left: auto; gap: 4px; }
@media (min-width: 900px) { .top-nav { display: flex; } }
.top-nav a {
  color: #fff; text-decoration: none; padding: 8px 14px; border-radius: var(--radius-sm);
  font-weight: 700; display: flex; align-items: center; gap: 6px;
}
.top-nav a svg { width: 20px; height: 20px; }
.top-nav a:hover { background: rgba(255, 255, 255, .14); }
.top-nav a[aria-current="page"] { background: #fff; color: var(--green); }

.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 30;
  background: #fff; border-top: 1px solid var(--line);
  display: grid; grid-template-columns: repeat(4, 1fr);
  padding-bottom: env(safe-area-inset-bottom);
}
@media (min-width: 900px) { .bottom-nav { display: none; } }
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: 64px; padding: 6px 4px; text-decoration: none; color: var(--text-2);
  font-size: .8rem; font-weight: 700; border-top: 3px solid transparent;
}
.bottom-nav a svg { width: 26px; height: 26px; }
.bottom-nav a[aria-current="page"] { color: var(--green); border-top-color: var(--green); }
.bottom-nav a.nav-add { color: var(--gold); }
.bottom-nav a.nav-add[aria-current="page"] { border-top-color: var(--gold-bright); }

.offline-banner {
  background: var(--danger); color: #fff; text-align: center; padding: 8px 16px; font-weight: 700;
}

/* ---------- ボタン ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 10px 20px; border-radius: 12px; border: 2px solid transparent;
  font: inherit; font-weight: 700; line-height: 1.2; text-decoration: none; text-align: center;
  cursor: pointer; background: #fff; color: var(--text);
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--green-2); }
.btn-gold { background: var(--gold-bright); color: #1d1405; }
.btn-gold:hover:not(:disabled) { background: #cc9a2e; }
.btn-outline { border-color: var(--green); color: var(--green); background: #fff; }
.btn-outline:hover:not(:disabled) { background: var(--green-soft); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-outline { border-color: var(--danger); color: var(--danger); background: #fff; }
.btn-danger-outline:hover:not(:disabled) { background: var(--danger-soft); }
.btn-small { min-height: 40px; padding: 6px 14px; font-size: .95rem; }
.btn-lg { min-height: 56px; padding: 12px 24px; font-size: 1.1rem; }
.btn-xl { min-height: 64px; padding: 14px 28px; font-size: 1.25rem; }
.btn-block { width: 100%; }
.text-link { font-weight: 700; text-decoration: none; }
.text-link:hover { text-decoration: underline; }

/* ---------- カード・見出し ---------- */
.card {
  background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px; margin-bottom: 20px;
}
@media (min-width: 900px) { .card { padding: 24px; } }
.card-flush { padding: 0; overflow: hidden; }
.card > h2 { margin-bottom: 12px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-title { margin-bottom: 16px; }
.back-link { display: inline-block; font-weight: 700; text-decoration: none; margin-bottom: 10px; padding: 4px 0; }
.back-link:hover { text-decoration: underline; }
.lead { color: var(--text-2); }
.hint { color: var(--text-2); font-size: .92rem; margin: 6px 0 0; }
.muted-strong { color: var(--text-2); font-weight: 600; }
.tag {
  display: inline-block; padding: 1px 10px; border-radius: 999px; background: var(--green-soft);
  color: var(--green); font-size: .85rem; font-weight: 700; white-space: nowrap;
}
.label-sm { font-size: .82rem; color: var(--text-2); font-weight: 600; }
.notice {
  background: var(--gold-soft); border: 1px solid var(--gold-bright); color: var(--text);
  border-radius: var(--radius-sm); padding: 12px 16px; margin-bottom: 16px; font-weight: 600;
}

/* ---------- 状態表示 ---------- */
.state { text-align: center; padding: 40px 16px; }
.state .btn { margin-top: 12px; }
.state-title { font-size: 1.15rem; font-weight: 700; margin-bottom: 8px; }
.state-loading { display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 700; color: var(--text-2); }
.state-error .state-title { color: var(--danger); }
.state-empty-small { padding: 20px 12px; text-align: center; color: var(--text-2); font-weight: 600; }
.state-empty-small .btn { margin-top: 10px; }
.spinner {
  width: 22px; height: 22px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--green);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2s; } }

/* ---------- 入力 ---------- */
.input {
  width: 100%; min-height: 52px; padding: 10px 14px; font: inherit; font-size: 1.05rem; color: var(--text);
  background: #fff; border: 2px solid var(--line); border-radius: 12px;
}
.input:focus { border-color: var(--green); outline: none; box-shadow: 0 0 0 3px rgba(27, 74, 49, .18); }
.input[aria-invalid="true"] { border-color: var(--danger); }
textarea.input { min-height: 72px; resize: vertical; }
.select { width: auto; padding-right: 36px; }
.select-small { min-height: 44px; font-size: 1rem; }
.input-search { font-size: 1.1rem; }
.input-xl { min-height: 64px; font-size: 1.25rem; padding: 12px 18px; }

.field { margin-bottom: 18px; }
.field > label { display: block; font-weight: 700; margin-bottom: 6px; font-size: 1.02rem; }
.field-row { display: grid; gap: 0 16px; }
@media (min-width: 640px) { .field-row { grid-template-columns: 1fr 1fr; } }
.field-error { color: var(--danger); font-weight: 700; font-size: .95rem; margin: 6px 0 0; min-height: 0; }
.field-error:empty { display: none; }
.form-error { color: var(--danger); font-weight: 700; white-space: pre-line; margin: 0 0 12px; }
.form-error:empty { display: none; }
.optional, .req { font-size: .8rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; margin-left: 6px; vertical-align: 1px; }
.optional { background: var(--line-soft); color: var(--text-2); }
.req { background: var(--danger-soft); color: var(--danger); }
.inline { display: flex; gap: 8px; align-items: center; }
.inline .input { flex: 1; }

.price-input { position: relative; }
.price-input .yen {
  position: absolute; left: 16px; top: 50%; transform: translateY(-50%);
  font-size: 1.5rem; font-weight: 800; color: var(--text-2); pointer-events: none;
}
.input-price { font-size: 1.6rem; font-weight: 800; min-height: 64px; padding-left: 44px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 6px 14px;
  border-radius: 999px; border: 2px solid var(--line); background: #fff; font: inherit; font-size: .95rem;
  font-weight: 700; color: var(--text); cursor: pointer;
}
.chip:hover { border-color: var(--green); }
.chip-on { background: var(--green); border-color: var(--green); color: #fff; }
.swatch { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }
.legend { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; }

/* ---------- 商品ピッカー ---------- */
.picker { position: relative; }
.picker-results {
  list-style: none; margin: 6px 0 0; padding: 6px; position: absolute; left: 0; right: 0; z-index: 20;
  background: #fff; border: 2px solid var(--green); border-radius: 12px; box-shadow: 0 8px 24px rgba(0, 0, 0, .12);
  max-height: 360px; overflow-y: auto;
}
.picker-option {
  width: 100%; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; text-align: left;
  min-height: 52px; padding: 8px 12px; border: none; background: none; border-radius: 8px;
  font: inherit; color: var(--text); cursor: pointer;
}
.picker-option:hover, .picker-option:focus-visible { background: var(--green-soft); }
.po-name { font-weight: 700; font-size: 1.05rem; }
.po-unit { color: var(--text-2); font-weight: 600; }
.picker-new { color: var(--green); font-weight: 800; border-top: 1px solid var(--line-soft); border-radius: 0 0 8px 8px; }
.picker-note { padding: 10px 12px; color: var(--text-2); font-weight: 600; }
.picker-error { color: var(--danger); white-space: pre-line; }
.picked {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  min-height: 56px; padding: 8px 8px 8px 16px; border: 2px solid var(--green); border-radius: 12px; background: var(--green-soft);
}
.picked-name { font-weight: 800; font-size: 1.15rem; }

/* ---------- 価格記録フォーム ---------- */
.form-layout { max-width: 720px; }
.form-actions { display: grid; gap: 12px; margin-top: 8px; }
.success-card { border: 2px solid var(--green); text-align: center; }
.success-title { font-size: 1.5rem; font-weight: 800; color: var(--green); margin-bottom: 6px; }
.success-summary { font-weight: 700; margin-bottom: 18px; }
.success-actions { display: grid; gap: 12px; }

/* ---------- ホーム ---------- */
.hero { padding: 24px; }
.hero-title { margin-bottom: 16px; }
.hero-row { display: grid; gap: 14px; }
@media (min-width: 760px) { .hero-row { grid-template-columns: 1fr auto; align-items: start; } }
.hero-search { position: relative; }
.hero-add { white-space: nowrap; }
.search-results {
  margin-top: 8px; border: 2px solid var(--line); border-radius: 12px; background: #fff; overflow: hidden;
}
.result-row {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 14px 16px; text-decoration: none; color: var(--text); border-bottom: 1px solid var(--line-soft);
}
.result-row:hover { background: var(--green-soft); }
.result-name { font-weight: 800; font-size: 1.08rem; }
.result-unit { color: var(--text-2); font-weight: 600; }
.result-price { font-weight: 800; }
.result-more { display: block; padding: 12px 16px; font-weight: 700; text-decoration: none; }

.recent-list { border-top: 1px solid var(--line-soft); }
.recent-row {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 14px 4px;
  text-decoration: none; color: var(--text); border-bottom: 1px solid var(--line-soft);
}
.recent-row:hover { background: var(--green-soft); }
.recent-name { font-weight: 800; font-size: 1.08rem; }
.recent-unit { color: var(--text-2); font-weight: 600; }
.recent-price { font-weight: 800; font-size: 1.2rem; text-align: right; }
.recent-store { font-weight: 600; }
.recent-date { color: var(--text-2); text-align: right; font-size: .95rem; }
@media (min-width: 760px) {
  .recent-row { grid-template-columns: minmax(0, 2fr) 120px minmax(0, 1.2fr) minmax(0, 1.5fr); align-items: center; padding: 12px 8px; }
  .recent-date { text-align: left; }
}

/* ---------- 商品一覧 ---------- */
.toolbar { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .input-search { flex: 1 1 260px; }
.item-row {
  display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 14px 16px;
  text-decoration: none; color: var(--text); border-bottom: 1px solid var(--line-soft);
}
a.item-row:hover { background: var(--green-soft); }
.item-row-head { display: none; }
.item-row-name { font-weight: 800; font-size: 1.1rem; }
.item-row-unit { color: var(--text-2); font-weight: 700; text-align: right; }
.item-row-price { font-weight: 800; font-size: 1.1rem; }
.item-row-date { text-align: right; }
@media (min-width: 760px) {
  .item-row { grid-template-columns: minmax(0, 2fr) 110px 130px minmax(0, 1.6fr) 150px; align-items: center; padding: 14px 20px; }
  .item-row-unit { text-align: left; }
  .item-row-head { display: grid; background: var(--green-soft); font-weight: 800; font-size: .92rem; color: var(--green); padding: 10px 20px; }
  .item-row-date .label-sm { display: none; }
}
.more-wrap { text-align: center; margin-top: 12px; }

/* ---------- バッジ ---------- */
.badge {
  display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: .82rem; font-weight: 800;
  white-space: nowrap; vertical-align: 1px;
}
.badge-sale { background: var(--gold-bright); color: #1d1405; }
.badge-ended { background: var(--line-soft); color: var(--text-2); border: 1px solid var(--line); }
.badge-upcoming { background: var(--green-soft); color: var(--green); }
.badge-best { background: var(--green); color: #fff; margin-left: 8px; }

/* ---------- 商品詳細 ---------- */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin-bottom: 18px; }
.detail-title h1 { font-size: 2rem; }
.detail-meta { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.detail-unit { font-size: 1.25rem; font-weight: 800; color: var(--text-2); }
.detail-note { color: var(--text-2); }
.head-actions { display: flex; gap: 10px; flex-wrap: wrap; }

.summary-grid { display: grid; gap: 16px; margin-bottom: 20px; }
@media (min-width: 760px) { .summary-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1100px) { .summary-grid { grid-template-columns: 1.2fr 1.2fr 1fr; } }
.summary-group { background: var(--card); border: 1px solid var(--line-soft); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.group-title { font-size: 1rem; color: var(--green); margin-bottom: 10px; }
.stat-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat {
  display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--line-soft); background: #fbfcfa; min-width: 0;
}
.stat-accent { background: var(--gold-soft); border: 2px solid var(--gold-bright); }
.stat-label { font-weight: 800; font-size: .92rem; color: var(--text-2); }
.stat-accent .stat-label { color: var(--gold); }
.stat-price { font-size: 1.8rem; font-weight: 900; line-height: 1.2; }
.stat-sub { font-weight: 700; color: var(--text-2); font-size: .95rem; overflow-wrap: anywhere; }
.stat-empty { font-weight: 700; color: var(--text-2); padding: 8px 0; }
.mini-stats { margin: 0; display: grid; gap: 8px; }
.mini-stats div { display: flex; justify-content: space-between; gap: 8px; border-bottom: 1px solid var(--line-soft); padding-bottom: 6px; }
.mini-stats dt { font-weight: 700; color: var(--text-2); }
.mini-stats dd { margin: 0; font-weight: 800; }

.detail-grid { display: grid; gap: 0 20px; }
@media (min-width: 1000px) { .detail-grid { grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); } }

.chart-box { margin-top: 12px; width: 100%; overflow: hidden; }
.price-chart { display: block; max-width: 100%; height: auto; }
.c-grid { stroke: var(--line-soft); stroke-width: 1; }
.c-axis { stroke: var(--line); stroke-width: 1.5; }
.c-label { fill: var(--text-2); font-size: 13px; font-weight: 600; }
.c-dot { stroke: #fff; stroke-width: 2; cursor: pointer; }
.c-dot:hover, .c-dot:focus, .c-dot.active { stroke: var(--text); stroke-width: 3; outline: none; }
.chart-info { margin: 8px 0 0; font-weight: 700; min-height: 1.6em; }

.store-table { border-top: 1px solid var(--line-soft); margin-top: 10px; }
.store-row {
  width: 100%; display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; align-items: center; text-align: left;
  padding: 12px 8px; background: none; border: none; border-bottom: 1px solid var(--line-soft);
  font: inherit; color: var(--text); cursor: pointer;
}
button.store-row:hover { background: var(--green-soft); }
.store-row.is-selected { background: var(--green-soft); box-shadow: inset 4px 0 0 var(--green); }
.store-row-head { display: none; }
.store-name { font-weight: 800; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.store-price { font-weight: 900; font-size: 1.15rem; text-align: right; }
.store-date { grid-column: 1 / -1; color: var(--text-2); font-size: .95rem; }
.is-stale .store-price { color: var(--text-2); }
.stale-note { display: block; font-size: .8rem; font-weight: 700; }

.filter-bar {
  display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap;
  background: var(--green-soft); border-radius: var(--radius-sm); padding: 10px 14px; margin-bottom: 12px; font-weight: 600;
}

.history-table { border-top: 1px solid var(--line-soft); }
.history-row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; align-items: center;
  padding: 14px 4px; border-bottom: 1px solid var(--line-soft);
}
.history-row-head { display: none; }
.h-date { font-weight: 700; }
.h-store { font-weight: 800; }
.h-price { font-weight: 900; font-size: 1.2rem; text-align: right; grid-row: 1; grid-column: 2; }
.h-status { grid-column: 1 / -1; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
@media (max-width: 759px) { .h-status:empty { display: none; } }
.h-note { color: var(--text-2); }
.h-actions { grid-column: 1 / -1; display: flex; gap: 8px; }
@media (min-width: 760px) {
  .history-row { grid-template-columns: 130px minmax(0, 1fr) 120px minmax(0, 1.4fr) auto; padding: 12px 8px; }
  .history-row-head { display: grid; font-weight: 800; font-size: .92rem; color: var(--green); background: var(--green-soft); padding: 10px 8px; }
  .h-price { grid-row: auto; grid-column: auto; }
  .h-status, .h-actions { grid-column: auto; }
}

/* ---------- ダイアログ ---------- */
.dialog {
  border: none; border-radius: var(--radius); padding: 0; width: min(560px, calc(100vw - 24px));
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3); color: var(--text);
}
.dialog::backdrop { background: rgba(10, 20, 14, .5); }
.dialog-body { padding: 24px; }
.dialog-body h2 { margin-bottom: 16px; font-size: 1.3rem; }
.dialog-text { margin-bottom: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.confirm-lines { font-size: 1.1rem; line-height: 1.7; background: var(--bg); border-radius: var(--radius-sm); padding: 12px 16px; }
.confirm-price { font-size: 1.4rem; font-weight: 900; }

/* ---------- トースト ---------- */
.toast-box {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(88px + env(safe-area-inset-bottom));
  z-index: 50; display: grid; gap: 8px; width: min(480px, calc(100vw - 32px));
}
@media (min-width: 900px) { .toast-box { bottom: 32px; } }
.toast {
  padding: 14px 18px; border-radius: 12px; font-weight: 700; color: #fff; background: var(--green);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2); white-space: pre-line;
}
.toast-error { background: var(--danger); }

/* ---------- ログイン / 設定 ---------- */
.login-card { max-width: 460px; margin: 24px auto; }
.login-card h1 { margin-bottom: 8px; }
.settings-grid { display: grid; gap: 0 20px; }
@media (min-width: 900px) { .settings-grid { grid-template-columns: 1fr 1fr; } }
.kv { margin: 0 0 16px; display: grid; gap: 8px; }
.kv div { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; border-bottom: 1px solid var(--line-soft); padding-bottom: 6px; }
.kv dt { font-weight: 700; color: var(--text-2); }
.kv dd { margin: 0; font-weight: 700; overflow-wrap: anywhere; }
.button-stack { display: grid; gap: 10px; margin-top: 12px; }
.simple-list { list-style: none; margin: 12px 0 0; padding: 0; }
.simple-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); font-weight: 700; }
