/* スマホ前提（モバイルファースト）。画面が広いときは、カードを複数列に並べる */

:root {
  --bg: #f3f5f8;
  --surface: #ffffff;
  --text: #1f2933;
  --muted: #667383;
  --line: #e1e5ea;
  --accent: #b45f06;
  --accent-text: #ffffff;
  --warn-bg: #fff1cc;
  --warn-text: #8a5a00;
  --warn-edge: #f0b429;
  --danger-bg: #fde3e3;
  --danger-text: #a12626;
  --danger-edge: #e05252;
  --radius: 12px;
  --tap: 48px;                       /* 指で押しやすい最小の高さ */
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161b;
    --surface: #1c2229;
    --text: #e6eaee;
    --muted: #96a3b0;
    --line: #2d3640;
    --accent: #f0b45a;
    --accent-text: #1f1405;
    --warn-bg: #3a2f10;
    --warn-text: #f1c767;
    --warn-edge: #b98a1f;
    --danger-bg: #3c1c1c;
    --danger-text: #f59a9a;
    --danger-edge: #b34848;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Yu Gothic UI", "Hiragino Sans", "Meiryo", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
}

/* ---- ヘッダー ---- */
.app-header {
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  display: flex; flex-direction: column; gap: 8px;
}
h1 { margin: 0; font-size: 20px; line-height: 1.3; }
.badge {
  font-size: 12px; font-weight: normal; padding: 2px 8px; margin-left: 6px;
  border-radius: 999px; background: var(--warn-bg); color: var(--warn-text); vertical-align: middle;
}
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.operator { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.userbox { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; color: var(--muted); }
.userbox span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }

main { padding: 12px 12px calc(156px + var(--safe-b)); max-width: 1100px; margin: 0 auto; }

/* ---- 入力部品（16px以上：iPhoneで拡大されない） ---- */
input, select, textarea, button {
  font: inherit; color: inherit; font-size: 16px;
  min-height: var(--tap);
  padding: 8px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface);
}
input, select, textarea { width: 100%; }
textarea { min-height: 88px; resize: vertical; }
button { cursor: pointer; font-weight: 600; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.ghost { background: var(--surface); }
button:active { filter: brightness(.94); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }
.operator input { min-height: 44px; }

/* ---- サマリー（タップで絞り込み） ---- */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.tile {
  min-height: 0; padding: 8px 4px; text-align: center; font-weight: normal;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.tile .label { display: block; color: var(--muted); font-size: 11px; line-height: 1.3; }
.tile .value { display: block; font-size: 22px; font-weight: 700; line-height: 1.3; }
.tile.warn .value { color: var(--warn-text); }
.tile.danger .value { color: var(--danger-text); }
.tile.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
div.tile { cursor: default; }

/* ---- 検索・絞り込み ---- */
.controls { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
details > summary {
  list-style: none; cursor: pointer; min-height: 40px; display: flex; align-items: center;
  color: var(--accent); font-size: 14px; font-weight: 600;
}
details > summary::-webkit-details-marker { display: none; }
details > summary::before { content: "▸"; margin-right: 6px; display: inline-block; transition: transform .15s; }
details[open] > summary::before { transform: rotate(90deg); }
.filter-grid { display: grid; gap: 10px; padding-bottom: 6px; }
.filter-grid label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.range-box { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.meta { white-space: pre-line; }
.list-head { display: flex; justify-content: space-between; align-items: center; position: relative; }
.count { color: var(--muted); font-size: 13px; }
.more { position: relative; }
.more-menu {
  position: absolute; right: 0; top: 100%; z-index: 5; min-width: 180px;
  display: flex; flex-direction: column; gap: 6px; padding: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .18);
}

/* ---- 在庫カード ---- */
.list { display: grid; grid-template-columns: 1fr; gap: 10px; }
.item {
  background: var(--surface); border: 1px solid var(--line); border-left: 6px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
}
.item.soon { border-left-color: var(--warn-edge); }
.item.expired { border-left-color: var(--danger-edge); }
.item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.item-name { font-size: 17px; font-weight: 700; line-height: 1.35; }
.item-qty { text-align: right; white-space: nowrap; }
.item-qty b { font-size: 26px; line-height: 1.1; }
.item-qty small { color: var(--muted); margin-left: 2px; font-size: 12px; }
.item-qty .w b { font-size: 20px; }
.tile .sub { display: block; color: var(--muted); font-size: 11px; line-height: 1.2; }
.hint { margin: -4px 0 12px; }
.sub a { color: var(--accent); text-decoration: underline; }
.unset { color: var(--muted); font-style: italic; }
/* 「商品ごとの合計」と「絞り込み・並び替え」は、同じ見た目のカードにそろえる */
.by-item, .filters { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.by-item { margin-bottom: 12px; }
.by-item > summary, .filters > summary { padding: 10px 12px; cursor: pointer; font-size: 14px; }
.filters > .filter-grid { padding: 12px; border-top: 1px solid var(--line); }
.filters > summary small, .by-item > summary small { color: var(--muted); font-weight: normal; margin-left: 12px; }
.bi-row { display: flex; justify-content: space-between; gap: 12px; padding: 8px 12px; border-top: 1px solid var(--line); font-size: 14px; }
button.bi-row { width: 100%; min-height: 0; border: 0; border-top: 1px solid var(--line); border-radius: 0; background: transparent; text-align: left; font-weight: normal; color: inherit; cursor: pointer; }
button.bi-row.active { box-shadow: inset 4px 0 0 var(--accent); background: var(--surface-2, rgba(180, 95, 6, .08)); }
.chip { align-self: flex-start; min-height: 0; padding: 6px 12px; border-radius: 999px; font-size: 13px; background: var(--accent); color: var(--accent-text); border: 1px solid var(--accent); }
.bi-name { font-weight: 600; }
.bi-val { text-align: right; white-space: nowrap; }
.bi-empty { padding: 8px 12px; color: var(--muted); font-size: 13px; }
.item-exp { margin-top: 4px; font-size: 15px; }
.item-dest { margin-top: 2px; font-size: 15px; }
.item-dest span:not(.sep) { color: var(--muted); font-size: 12px; margin-right: 6px; }
.item-dest .sep { color: var(--muted); margin: 0 8px; }
.item-memo {
  margin: 8px 0 0; padding: 8px 10px; background: var(--bg); border-radius: 8px;
  color: var(--muted); font-size: 14px; white-space: pre-wrap; word-break: break-word;
}
.item-foot { margin-top: 10px; display: flex; flex-direction: column; gap: 8px; }
.item-meta { color: var(--muted); font-size: 11px; line-height: 1.5; word-break: break-all; }
.item-actions { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 8px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; margin-left: 8px; font-weight: 600; }
.tag.warn { background: var(--warn-bg); color: var(--warn-text); }
.tag.danger { background: var(--danger-bg); color: var(--danger-text); }
.cat-tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 11px; margin-left: 8px; font-weight: 600; vertical-align: middle; background: var(--line); color: var(--muted); }
.loading {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 28px 16px; color: var(--muted); font-size: 15px;
}
.spinner {
  width: 24px; height: 24px; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--accent);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }
.busy { opacity: .45; pointer-events: none; transition: opacity .15s; }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }

/* ---- 入庫・出庫ボタン（親指が届く右下に固定。入庫の下に出庫） ---- */
.fabs {
  position: fixed; right: 16px; bottom: calc(16px + var(--safe-b)); z-index: 10;
  display: flex; flex-direction: column; gap: 10px;
}
.fab {
  min-height: 56px; padding: 0 22px; border-radius: 999px;
  background: var(--accent); color: var(--accent-text); border-color: var(--accent);
  font-size: 17px; box-shadow: 0 6px 18px rgba(0, 0, 0, .3);
}
.fab span { font-size: 22px; margin-right: 2px; vertical-align: -1px; }
.fab.fab-out { background: var(--surface); color: var(--accent); border: 2px solid var(--accent); }

/* ---- 出庫のあとなどの、短いお知らせ（数秒で消える） ---- */
.toast {
  position: fixed; left: 16px; right: 140px; bottom: calc(16px + var(--safe-b)); z-index: 11;
  padding: 10px 14px; border-radius: 10px; font-size: 14px;
  background: var(--text); color: var(--surface); box-shadow: 0 6px 18px rgba(0, 0, 0, .3);
}

/* ---- 注意のポップアップ（画面の真ん中） ---- */
dialog.dlg-warn { margin: auto; width: calc(100% - 32px); max-width: 420px; border-radius: 16px; }
.warn-msg { margin: 0 0 8px; font-size: 15px; line-height: 1.6; white-space: pre-line; color: var(--text); }
.actions.one { grid-template-columns: 1fr; }
.after-ng { color: var(--danger-text); font-weight: 600; }

/* ---- 商品ごとの合計：分類のタブ（多いときは、横にスクロール） ---- */
.bi-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 8px 12px; border-top: 1px solid var(--line); -webkit-overflow-scrolling: touch; }
.bi-tab {
  flex: 0 0 auto; min-height: 36px; padding: 4px 14px; border-radius: 999px; font-size: 14px;
  background: var(--surface); color: var(--muted); border: 1px solid var(--line);
}
.bi-tab.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.bi-tab small { font-weight: normal; margin-left: 4px; }
.bi-group { padding: 6px 12px; font-size: 12px; font-weight: 700; color: var(--muted); background: var(--bg); border-top: 1px solid var(--line); }

/* ---- 登録・編集（スマホでは、画面下からせり上がるシート） ---- */
dialog {
  border: 0; padding: 0; color: var(--text); background: var(--surface);
  width: 100%; max-width: 100%;
  max-height: 94dvh; margin: auto 0 0;
  border-radius: 18px 18px 0 0;
}
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog form { display: flex; flex-direction: column; max-height: 94dvh; }
dialog h2 { margin: 0; padding: 16px 16px 8px; font-size: 18px; }
.fields { padding: 4px 16px 8px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
dialog label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 12px; }
dialog label > input, dialog label > select, dialog label > textarea { display: block; margin-top: 4px; color: var(--text); }
.row { display: grid; grid-template-columns: 1fr; gap: 0; }
.meta { color: var(--muted); font-size: 12px; margin: 0 0 8px; }
.err { background: var(--danger-bg); color: var(--danger-text); padding: 10px 12px; border-radius: 10px; margin: 0 0 8px; font-size: 14px; }
.err-text { color: var(--danger-text); min-height: 1.5em; font-size: 14px; }
.actions {
  display: grid; grid-template-columns: 1fr 2fr; gap: 10px;
  padding: 12px 16px calc(12px + var(--safe-b));
  border-top: 1px solid var(--line); background: var(--surface);
}

/* ---- ログイン ---- */
.login { display: flex; justify-content: center; padding: 32px 16px; }
.login-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 24px 20px; width: min(420px, 100%); text-align: center;
}
.login-card h2 { margin: 0 0 8px; font-size: 18px; }
.login-card p { color: var(--muted); font-size: 14px; }
#gsi-btn { display: flex; justify-content: center; margin: 16px 0 8px; min-height: 44px; }

/* ---- 少し広い画面（タブレット・PC）：カードを複数列に ---- */
@media (min-width: 640px) {
  .app-header { flex-direction: row; justify-content: space-between; align-items: flex-end; }
  .operator input { width: 200px; }
  .filter-grid { grid-template-columns: repeat(3, 1fr); }
  .list { grid-template-columns: repeat(2, 1fr); }
  .item-foot { flex-direction: row; align-items: center; justify-content: space-between; }
  .item-actions { grid-template-columns: auto auto auto; }
  .item-actions button { min-height: 40px; padding: 4px 16px; }
  dialog { max-width: 560px; margin: auto; border-radius: 16px; max-height: 90dvh; }
  dialog form { max-height: 90dvh; }
  .row { grid-template-columns: 1fr 1fr; gap: 12px; }
}
@media (min-width: 1000px) {
  .list { grid-template-columns: repeat(3, 1fr); }
}

/* 保存した行を、少しだけ目立たせる */
.item.flash { animation: flash 2s ease-out; }
@keyframes flash { from { background: #fff3b0; } to { background: transparent; } }

/* ---- 背景の飾り：食品部の在庫管理アプリと同じ、琥珀色と淡い桃色の、にじみと、ゆっくり流れる波（主張しない程度） ---- */
:root {
  --fx1: rgba(232, 162, 58, 0.10);    /* 右上のにじみ（あたたかい琥珀色） */
  --fx2: rgba(229, 128, 107, 0.08);   /* 左下のにじみ（ハムのような淡い桃色） */
  /* 波の画像（色は、画像の中に直接書く。# は %23）。奥：琥珀色、手前：桃色 */
  --wave-img1: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 120' preserveAspectRatio='none'%3E%3Cpath d='M0 60 C150 100 350 20 600 60 C850 100 1050 20 1200 60 L1200 120 L0 120Z' fill='%23e8a23a' fill-opacity='.07'/%3E%3C/svg%3E");
  --wave-img2: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 900 120' preserveAspectRatio='none'%3E%3Cpath d='M0 70 C110 40 340 100 450 70 C560 40 790 100 900 70 L900 120 L0 120Z' fill='%23e5806b' fill-opacity='.08'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root {
    --fx1: rgba(240, 184, 90, 0.09);
    --fx2: rgba(240, 150, 130, 0.07);
    --wave-img1: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 1200 120' preserveAspectRatio='none'%3E%3Cpath d='M0 60 C150 100 350 20 600 60 C850 100 1050 20 1200 60 L1200 120 L0 120Z' fill='%23f0b45a' fill-opacity='.10'/%3E%3C/svg%3E");
    --wave-img2: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 900 120' preserveAspectRatio='none'%3E%3Cpath d='M0 70 C110 40 340 100 450 70 C560 40 790 100 900 70 L900 120 L0 120Z' fill='%23f09682' fill-opacity='.09'/%3E%3C/svg%3E");
  }
}
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(900px 520px at 100% 0%, var(--fx1), transparent 70%),
    radial-gradient(800px 520px at 0% 100%, var(--fx2), transparent 70%);
}
body::after {
  content: ""; position: fixed; left: 0; right: 0; bottom: 0; height: 120px; z-index: -1; pointer-events: none;
  background-repeat: repeat-x;
  background-image: var(--wave-img1), var(--wave-img2);
  background-size: 1200px 100%, 900px 85%;
  background-position: 0 100%, 0 100%;
  animation: wave-drift 90s linear infinite;
}
@keyframes wave-drift {
  to { background-position: 1200px 100%, -900px 100%; }
}
@media (prefers-reduced-motion: reduce) { body::after { animation: none; } }
@media print { body::before, body::after { display: none; } }

/* ---- 絞り込みの条件のチップ（✕で1つずつ解除）と、すべて解除 ---- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips .chip { align-self: auto; text-align: left; }
.chips .chip.clear-all { background: transparent; color: var(--accent); }
/* ---- マイナスの在庫（出庫で足りなくなったとき）は、赤字で出す ---- */
.item-qty .neg b { color: #c62828; }
