/* スマホ前提（モバイルファースト）。画面が広いときは、カードを複数列に並べる */
:root {
  --bg: #f3f5f8; --surface: #ffffff; --text: #1f2933; --muted: #667383; --line: #e1e5ea;
  --accent: #1b6ec2; --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: #4a9be8; --accent-text: #0b1620;
    --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; } }

/* スマホの幅で、はみ出さないようにする（グリッド・横並びの中身が、文字の長さで広がらないように） */
.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; }
}
