/* 消耗品リスト — 色や寸法の根拠は DESIGN_DIRECTION.md */

:root {
  --ground: #F3F0E8;
  --surface: #FFFFFF;
  --paper: #FFFDF8;
  --line: #E7E1D5;
  --ink: #2B302D;
  --ink-2: #646A63;
  --accent: #1F6F61;
  --accent-soft: #E3F0EC;
  --warn-ink: #8A5410;
  --warn-soft: #FFF4E2;
  --danger: #B0402E;
  --control-line: #8C877C;

  --r-s: 8px;
  --r-m: 14px;
  --r-pill: 999px;

  --shadow: 0 1px 2px rgba(60, 50, 30, .10), 0 6px 18px rgba(60, 50, 30, .06);
  --ease: 160ms ease-out;

  --font: "Zen Maru Gothic", "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", sans-serif;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--ground);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 500;
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}

[hidden] { display: none !important; }

h1, h2, p { margin: 0; }

button, input { font: inherit; color: inherit; }

svg { display: block; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---- ボタン ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 16px;
  border: 0;
  border-radius: var(--r-pill);
  background: transparent;
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: transform var(--ease), background-color var(--ease);
  user-select: none;
  -webkit-user-select: none;
}
.btn:active { transform: scale(.97); }

.btn.primary { background: var(--accent); color: #fff; }
.btn.ghost { color: var(--accent); }
.btn.ghost:active { background: var(--accent-soft); }
.btn.danger-text { color: var(--danger); }
.btn.wide { width: 100%; }

.btn.icon { width: 44px; padding: 0; }
.btn.icon svg {
  width: 22px; height: 22px;
  fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round;
}

/* ---- 合言葉 ---- */

.lock {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.lock-card {
  width: min(100%, 360px);
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: center;
}
.lock-card img { margin: 0 auto 4px; border-radius: 16px; }
.lock-card h1 { font-size: 22px; font-weight: 700; margin-bottom: 16px; }
.lock-card label { text-align: left; font-weight: 700; font-size: 14px; }
.lock-error { min-height: 1.5em; color: var(--danger); font-size: 14px; text-align: left; }

/* ---- 上のバー ---- */

.bar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 720px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 8px) 12px 8px 20px;
  background: var(--ground);
}
.bar h1 { font-size: 20px; font-weight: 700; letter-spacing: .02em; }
.bar-actions { display: flex; align-items: center; gap: 4px; }

.offline {
  max-width: 720px;
  margin: 0 auto 4px;
  padding: 8px 20px;
  font-size: 13px;
  color: var(--warn-ink);
}

/* ---- 一覧 ---- */

main {
  max-width: 720px;
  margin: 0 auto;
  padding: 4px 12px calc(env(safe-area-inset-bottom) + 112px);
}

.group + .group { margin-top: 24px; }

.group-title {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px 8px;
  font-size: 15px;
  font-weight: 700;
  color: var(--ink-2);
}
.group-title .count {
  font-variant-numeric: tabular-nums;
  font-size: 13px;
  font-weight: 700;
  min-width: 24px;
  padding: 0 8px;
  border-radius: var(--r-pill);
  background: rgba(43, 48, 45, .07);
  text-align: center;
}
.group.need .group-title { color: var(--accent); }
.group.need .group-title .count { background: var(--accent-soft); }
.group.due .group-title { color: var(--warn-ink); }
.group.due .group-title .count { background: var(--warn-soft); }

.rows {
  list-style: none;
  margin: 0;
  padding: 0;
  background: var(--surface);
  border-radius: var(--r-m);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.group.due .rows { background: var(--warn-soft); }

.row {
  position: relative;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  grid-template-areas:
    "tog name buy"
    "tog meta buy";
  column-gap: 10px;
  align-items: center;
  min-height: 68px;
  padding: 10px 12px 10px 8px;
  cursor: pointer;
  transition: background-color var(--ease);
}
.row + .row::before {
  content: "";
  position: absolute;
  top: 0; left: 62px; right: 0;
  border-top: 1px solid var(--line);
}
.group.due .row + .row::before { border-color: rgba(138, 84, 16, .14); }
.row:active { background: rgba(43, 48, 45, .04); }

.row.flash { animation: flash 900ms ease-out; }
@keyframes flash {
  from { background: var(--accent-soft); }
  to { background: transparent; }
}

.toggle {
  grid-area: tog;
  width: 44px; height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
}
.toggle .dot {
  width: 28px; height: 28px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 2px solid var(--control-line);
  transition: background-color var(--ease), border-color var(--ease), transform var(--ease);
}
.toggle svg {
  width: 16px; height: 16px;
  fill: none; stroke: #fff; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round;
  opacity: 0;
}
.toggle[aria-pressed="true"] .dot { background: var(--accent); border-color: var(--accent); }
.toggle[aria-pressed="true"] svg { opacity: 1; }
.row:active .toggle .dot { transform: scale(.92); }

.name {
  grid-area: name;
  align-self: end;
  font-size: 17px;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}
.meta {
  grid-area: meta;
  align-self: start;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  column-gap: 10px;
  row-gap: 2px;
  margin-top: 2px;
  font-size: 13px;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
}
.group.due .meta { color: var(--warn-ink); }

.amazon {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 26px;
  padding: 0 10px;
  border-radius: var(--r-pill);
  background: rgba(43, 48, 45, .06);
  color: var(--ink);
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
  transition: transform var(--ease);
}
.amazon::after {               /* 押せる範囲を上下に広げる */
  content: "";
  position: absolute;
  inset: -9px -4px;
}
.amazon:active { transform: scale(.96); }
.amazon svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.group.due .amazon { background: rgba(138, 84, 16, .10); }

.buy {
  grid-area: buy;
  min-width: 72px;
  padding: 0 14px;
  background: var(--accent-soft);
  color: var(--accent);
}
.row.need .buy { background: var(--accent); color: #fff; }

/* 編集モード */
.editing .row {
  grid-template-columns: minmax(0, 1fr) 24px;
  grid-template-areas:
    "name chev"
    "meta chev";
  padding-left: 16px;
}
.editing .row + .row::before { left: 16px; }
.editing .toggle,
.editing .buy,
.editing .amazon { display: none; }
.chev { display: none; grid-area: chev; width: 20px; height: 20px; fill: none; stroke: var(--control-line); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.editing .chev { display: block; }

.edit-note {
  margin: 0 8px 16px;
  font-size: 14px;
  color: var(--ink-2);
}

/* 空のとき */
.empty-row {
  padding: 18px 16px;
  font-size: 14px;
  color: var(--ink-2);
  text-align: center;
}
.empty-all {
  margin-top: 15vh;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  color: var(--ink-2);
}
.loading { margin-top: 20vh; text-align: center; color: var(--ink-2); }

/* ---- 追加・編集のシート ---- */

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - 24px);
  margin: auto auto 0;
  padding: 0;
  border: 0;
  border-radius: 20px 20px 0 0;
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 -8px 32px rgba(40, 32, 20, .18);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.sheet::backdrop { background: rgba(43, 48, 45, .38); }
.sheet[open] { animation: sheet-in 220ms ease-out; }
@keyframes sheet-in {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
@media (min-width: 700px) {
  .sheet { margin: auto; border-radius: 20px; }
}

.sheet form {
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding: 8px 20px calc(env(safe-area-inset-bottom) + 20px);
}
.sheet-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 -20px;
  padding: 12px 8px 8px 20px;
  background: var(--surface);
}
.sheet-head h2 { font-size: 18px; font-weight: 700; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field label, .field legend { font-size: 14px; font-weight: 700; padding: 0; }
.field legend { margin-bottom: 8px; }
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.link { color: var(--accent); font-size: 14px; font-weight: 700; text-decoration: underline; text-underline-offset: 3px; padding: 6px 0; }
.hint { font-size: 13px; color: var(--ink-2); }
.field-error { font-size: 13px; color: var(--danger); }
.field-error:empty { display: none; }

input[type="text"], input:not([type]), input[type="password"], input[type="date"] {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--control-line);
  border-radius: 10px;
  background: var(--surface);
  font-size: 16px;
  font-weight: 500;
  -webkit-appearance: none;
  appearance: none;
}
input[type="date"] { font-variant-numeric: tabular-nums; }
input[aria-invalid="true"] { border-color: var(--danger); }

.date-row { display: flex; gap: 8px; align-items: center; }
.date-row input { flex: 1; min-width: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { position: relative; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0 16px;
  border-radius: var(--r-pill);
  border: 1px solid var(--control-line);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: background-color var(--ease), color var(--ease);
}
.chips input:checked + span { background: var(--accent); border-color: var(--accent); color: #fff; }
.chips input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

.sheet-actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }

/* ---- レシート（「買った」のあと） ---- */

.toast {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(env(safe-area-inset-bottom) + 16px);
  z-index: 20;
  display: flex;
  justify-content: center;
  padding: 0 12px;
  pointer-events: none;
  filter: drop-shadow(0 2px 3px rgba(40, 32, 20, .16)) drop-shadow(0 10px 20px rgba(40, 32, 20, .12));
  animation: toast-in 200ms ease-out;
}
@keyframes toast-in {
  from { transform: translateY(16px); opacity: 0; }
  to { transform: none; opacity: 1; }
}
.receipt {
  --z: 6px;
  pointer-events: auto;
  width: min(100%, 480px);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(var(--z) + 12px) 8px 12px 16px;
  background: var(--paper);
  /* 上の端だけギザギザ（ちぎったレシート） */
  -webkit-mask:
    conic-gradient(from 135deg at top, #000 90deg, #0000 0) top / calc(2 * var(--z)) var(--z) repeat-x,
    linear-gradient(#000 0 0) 0 var(--z) / 100% calc(100% - var(--z)) no-repeat;
  mask:
    conic-gradient(from 135deg at top, #000 90deg, #0000 0) top / calc(2 * var(--z)) var(--z) repeat-x,
    linear-gradient(#000 0 0) 0 var(--z) / 100% calc(100% - var(--z)) no-repeat;
  border-radius: 0 0 var(--r-s) var(--r-s);
}
.stamp {
  flex: none;
  padding: 2px 8px;
  border: 2px solid var(--accent);
  border-radius: 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  transform: rotate(-4deg);
  white-space: nowrap;
}
.toast-msg {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  line-height: 1.4;
  overflow-wrap: anywhere;
}
.toast-btn { flex: none; color: var(--accent); }
.toast-btn:active { background: var(--accent-soft); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
  }
}
