/* スマホ前提（モバイルファースト）。画面が広いときは、カードを複数列に並べる */
:root {
  --bg: #f3f5f8; --surface: #ffffff; --text: #1f2933; --muted: #667383; --line: #e1e5ea;
  --accent: #1f6f8b; --accent-text: #ffffff;   /* 食料部：そうめん・うどんの「冷たい水」の青緑 */
  --warn-bg: #fff1cc; --warn-text: #8a5a00; --warn-edge: #f0b429;
  --danger-bg: #fde3e3; --danger-text: #a12626; --danger-edge: #e05252;
  --ok-bg: #e3f5ea; --ok-text: #1d6b3d; --ok-edge: #3fa66b;
  --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: #7cc4dc; --accent-text: #08202a;
    --warn-bg: #3a2f10; --warn-text: #f1c767; --warn-edge: #b98a1f;
    --danger-bg: #3c1c1c; --danger-text: #f59a9a; --danger-edge: #b34848;
    --ok-bg: #12301f; --ok-text: #8fdcaa; --ok-edge: #3a8f5e;
  }
}
* { 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; }
.round { margin: 4px 0 0; font-size: 15px; font-weight: 700; color: var(--warn-text); }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.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(40px + var(--safe-b)); max-width: 1100px; margin: 0 auto; }

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%; }
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.danger { color: var(--danger-text); border-color: var(--danger-edge); }
button.link { background: none; border: 0; min-height: 36px; color: var(--muted); text-decoration: underline; font-weight: normal; font-size: 13px; }
button:active { filter: brightness(.94); }
button:disabled { opacity: .5; cursor: default; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 1px; }

/* ログイン */
.login { padding: 16px; display: flex; justify-content: center; }
.login-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; width: 100%; max-width: 440px; display: flex; flex-direction: column; gap: 10px; }
.login-card h2 { margin: 0; font-size: 18px; }
.login-card label { font-size: 14px; }
.err-text { color: var(--danger-text); font-size: 14px; margin: 0; min-height: 1em; }
.meta { color: var(--muted); font-size: 12px; margin: 0; }
.hint { margin: 2px 0; }

/* 画面の切り替え */
.views { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.view-tab { border-radius: 999px; font-size: 15px; }
.view-tab.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

/* 進み具合 */
.summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.tile { padding: 8px 4px; text-align: center; 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 .sub2 { display: block; color: var(--muted); font-size: 11px; }
.tile.ok .value { color: var(--ok-text); }
.tile.warn .value { color: var(--warn-text); }
.tile.danger .value { color: var(--danger-text); }
.bar { height: 6px; background: var(--line); border-radius: 999px; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: var(--ok-edge); }

/* 絞り込み */
.controls { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.controls label { font-size: 12px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.filter-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.sum-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.sum-actions button { flex: 1 1 200px; font-size: 14px; }

/* カード */
.list { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 720px) { .list { grid-template-columns: 1fr 1fr; } .summary { max-width: 560px; } }
.item { background: var(--surface); border: 1px solid var(--line); border-left: 8px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: flex; justify-content: space-between; align-items: center; gap: 12px; cursor: pointer; text-align: left; width: 100%; font-weight: normal; min-height: 76px; }
.item.done { border-left-color: var(--ok-edge); }
.item-name { font-size: 17px; font-weight: 700; line-height: 1.35; }
.item-sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
.item-qty { text-align: right; white-space: nowrap; }
.item-qty b { font-size: 24px; line-height: 1.1; }
.item-qty small { color: var(--muted); margin-left: 2px; font-size: 12px; }
.item-qty .todo { color: var(--muted); font-size: 14px; }
.item-qty .cases { display: block; color: var(--muted); font-size: 11px; }
.chip { display: inline-block; font-size: 11px; padding: 1px 8px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); color: var(--muted); margin-right: 4px; }
.cdot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: baseline; }

/* コード別の集計 */
.code { background: var(--surface); border: 1px solid var(--line); border-left: 8px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.code.ok { border-left-color: var(--ok-edge); }
.code.diff { border-left-color: var(--danger-edge); }
.code.todo { border-left-color: var(--warn-edge); }
.code-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.code-name { font-weight: 700; font-size: 16px; line-height: 1.35; }
.code-no { color: var(--muted); font-size: 12px; }
.code-total { text-align: right; white-space: nowrap; }
.code-total b { font-size: 26px; line-height: 1.1; }
.code-total small { color: var(--muted); font-size: 12px; margin-left: 2px; }
.code-total .lbl { display: block; color: var(--muted); font-size: 11px; }
.parts { margin: 8px 0 0; padding: 0; list-style: none; font-size: 13px; color: var(--muted); }
.parts li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 0; border-top: 1px dashed var(--line); }
.parts .unset { font-style: italic; }
.book { margin-top: 8px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 13px; }
.pill { padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.pill.ok { background: var(--ok-bg); color: var(--ok-text); }
.pill.diff { background: var(--danger-bg); color: var(--danger-text); }
.pill.todo { background: var(--warn-bg); color: var(--warn-text); }

.empty { color: var(--muted); text-align: center; padding: 24px 0; }
.err { color: var(--danger-text); background: var(--danger-bg); border: 1px solid var(--danger-edge); border-radius: 10px; padding: 8px 12px; font-size: 14px; margin: 0 0 8px; }
.loading { display: flex; align-items: center; gap: 8px; justify-content: center; color: var(--muted); padding: 12px; }
.spinner { width: 18px; height: 18px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; left: 50%; bottom: calc(20px + var(--safe-b)); transform: translateX(-50%); background: #1f2937; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: 90%; z-index: 20; }
.foot { text-align: center; margin-top: 18px; }

/* 入力の画面 */
dialog { border: 0; border-radius: 16px; padding: 0; width: min(94vw, 460px); background: var(--surface); color: var(--text); box-shadow: 0 10px 40px rgba(0,0,0,.35); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog form { padding: 16px; display: flex; flex-direction: column; gap: 10px; }
dialog h2 { margin: 0; font-size: 18px; }
.fields { display: flex; flex-direction: column; gap: 10px; }
.fields label { font-size: 13px; color: var(--muted); display: flex; flex-direction: column; gap: 2px; }
.d-info { margin: 0; font-weight: 700; line-height: 1.4; }
.d-info small { display: block; color: var(--muted); font-weight: normal; font-size: 12px; }
.d-calc { margin: 0; font-size: 18px; font-weight: 700; color: var(--accent); min-height: 1.5em; }
.actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.actions .primary { flex: 1 1 120px; }

@media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }

/* ---- 背景の飾り：食料部らしい、水色（そうめん・うどんの冷たい水）と小麦色の、にじみと、ゆっくり流れる波（主張しない程度） ---- */
:root {
  --fx1: rgba(46, 150, 190, 0.10);    /* 右上のにじみ（水色） */
  --fx2: rgba(226, 178, 70, 0.10);    /* 左下のにじみ（小麦色） */
  /* 波の画像（色は、画像の中に直接書く。# は %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='%232e96be' fill-opacity='.08'/%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='%23e2b246' fill-opacity='.09'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root {
    --fx1: rgba(110, 190, 225, 0.09);
    --fx2: rgba(240, 200, 100, 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='%236ebee1' 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='%23f0c864' 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; } }

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

/* スマホの幅で、はみ出さないようにする（グリッド・横並びの中身が、文字の長さで広がらないように） */
.views > *, .summary > *, .filter-row > *, .list > *, .sum-actions > *, .code-head > *, .item > * { min-width: 0; }
.view-tab { padding-left: 6px; padding-right: 6px; }
.tile .label { overflow-wrap: anywhere; }
.item-name, .code-name { overflow-wrap: anywhere; }
.code-total .lbl { white-space: normal; }
.userbox button { flex: none; }
@media (max-width: 420px) {
  .view-tab { font-size: 14px; }
  .filter-row { grid-template-columns: 1fr 1fr; }
  .filter-row > label:last-child:nth-child(3) { grid-column: 1 / -1; }
  .item-qty b { font-size: 20px; }
  .code-total b { font-size: 22px; }
}
