[hidden] { display: none !important; }
:root {
  --bg: #f6f7f5;
  --card: #ffffff;
  --text: #1d2320;
  --muted: #66706b;
  --line: #dfe3e0;
  --accent: #1f6f5c;
  --accent-text: #ffffff;
  --accent-soft: #e2f0eb;
  --warn: #b4531a;
  --warn-soft: #fbeee4;
  --danger: #b3261e;
  --chip: #eef1ef;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121614;
    --card: #1b201e;
    --text: #e6ebe8;
    --muted: #9aa5a0;
    --line: #2d3431;
    --accent: #4fb89b;
    --accent-text: #0b1512;
    --accent-soft: #1d3a31;
    --warn: #f0a068;
    --warn-soft: #3a2a1e;
    --danger: #ff8a80;
    --chip: #262d2a;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
}
body.no-scroll { overflow: hidden; }
a { color: var(--accent); }
h2, h3 { margin: 0 0 10px; line-height: 1.3; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
small { color: var(--muted); font-size: 13px; }
.muted { color: var(--muted); font-size: 14px; }
.warn-text { color: var(--danger); }
.mono { font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-all; }

/* 上の帯と、スマホでは下のタブ */
.top {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; }
.tabs { display: flex; gap: 4px; }
.tabs a {
  padding: 8px 14px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 600;
}
.tabs a.on { background: var(--accent-soft); color: var(--accent); }
@media (max-width: 700px) {
  .top { justify-content: center; }
  .tabs {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: var(--card); border-top: 1px solid var(--line);
    padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
  }
  .tabs a { flex: 1; text-align: center; padding: 10px 0; }
}
@media (min-width: 701px) { body { padding-bottom: 24px; } }

main { max-width: 860px; margin: 0 auto; padding: 12px 16px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px; margin-bottom: 12px;
}
details.card > summary { cursor: pointer; font-weight: 600; }

/* 入力 */
input, select, textarea, button, .btn-like, a.primary, a.big {
  font: inherit; color: inherit;
}
input, select, textarea {
  width: 100%; min-width: 0; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); font-size: 16px; /* 16px未満だとiPhoneが拡大する */
}
input[type=checkbox] { width: auto; }
button, .btn-like, a.primary, a.big {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 14px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--card); cursor: pointer; text-decoration: none; white-space: nowrap;
  min-height: 44px;
}
button:disabled { opacity: .55; }
.primary { background: var(--accent) !important; color: var(--accent-text) !important; border-color: var(--accent) !important; font-weight: 700; }
.ghost { background: transparent; }
.big { width: 100%; min-height: 54px; font-size: 17px; font-weight: 700; margin: 6px 0; }
.row { display: flex; align-items: center; }
.gap { gap: 8px; margin: 8px 0; }
.wrap { flex-wrap: wrap; }
.field { display: block; margin: 12px 0; }
.field > span { display: block; font-size: 14px; font-weight: 600; margin-bottom: 4px; }
.field small { display: block; margin-top: 4px; }
.check { display: flex; align-items: center; gap: 8px; margin: 12px 0; }
.small-link { font-size: 14px; white-space: nowrap; }

.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1 1 auto; min-width: 64px; }
.seg button.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); font-weight: 700; }

.stepper { display: flex; gap: 6px; }
.stepper input { text-align: center; font-size: 20px; font-weight: 700; }
.stepper button { width: 56px; font-size: 22px; }

/* ホーム */
.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 12px; }
.quick .big { margin: 0; }
@media (max-width: 420px) { .quick { grid-template-columns: 1fr; } }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; margin-bottom: 12px; }
.stat {
  display: block; background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; text-decoration: none; color: var(--text);
}
.stat span { display: block; font-size: 13px; color: var(--muted); }
.stat b { display: block; font-size: 22px; margin: 2px 0; }
.stat.warn { border-color: var(--warn); background: var(--warn-soft); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip {
  padding: 6px 12px; border-radius: 999px; background: var(--chip); border: 1px solid transparent;
  text-decoration: none; color: var(--text); min-height: 36px; font-size: 14px;
}
.chip.on { background: var(--accent); color: var(--accent-text); }
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 8px; align-items: center; }

/* 一覧 */
.list .item {
  display: flex; gap: 10px; align-items: center; padding: 10px; margin-bottom: 8px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px; text-decoration: none; color: var(--text);
}
.item img, .item .noimg { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; flex: none; background: var(--chip); }
.item .body { flex: 1; min-width: 0; }
.item .body b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .body small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .nums { text-align: right; flex: none; }
.item .nums b { font-size: 20px; display: block; }
.item .nums small { display: block; }
.line { display: flex; justify-content: space-between; gap: 8px; padding: 8px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: var(--text); }

/* 入荷 */
.found, .newp { padding: 10px; border-radius: 10px; background: var(--accent-soft); margin-bottom: 6px; }
.found { display: flex; justify-content: space-between; gap: 10px; align-items: center; }
.newp { background: var(--warn-soft); }
.hit { display: block; width: 100%; text-align: left; justify-content: flex-start; margin: 6px 0; white-space: normal; }
.hit.new { border-style: dashed; }
.done p { margin-top: 0; }

/* 商品 */
.ptitle { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.ptitle h2 { word-break: break-word; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.thumbs img { width: 84px; height: 84px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); }
.ph { position: relative; }
.ph .x {
  position: absolute; top: -6px; right: -6px; min-height: 0; width: 26px; height: 26px; padding: 0;
  border-radius: 50%; font-size: 14px; line-height: 1;
}
.addph {
  width: 84px; height: 84px; display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--line); border-radius: 8px; cursor: pointer; color: var(--muted);
}
.srow {
  display: flex; justify-content: space-between; gap: 10px; padding: 10px 0; border-top: 1px solid var(--line);
}
.srow:first-of-type { border-top: 0; }
.srow .btns { display: flex; flex-direction: column; gap: 6px; flex: none; }
.srow .btns button { min-height: 38px; padding: 6px 10px; font-size: 14px; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; background: var(--chip); }
.st-wait { background: var(--warn-soft); color: var(--warn); }
.st-done { background: var(--accent-soft); color: var(--accent); }
.st-off { color: var(--muted); }
.hist { padding: 6px 0; border-top: 1px solid var(--line); font-size: 14px; }

/* 取込 */
.tablewrap { overflow-x: auto; margin: 8px 0; }
table { border-collapse: collapse; width: 100%; font-size: 14px; }
th, td { border-bottom: 1px solid var(--line); padding: 6px; text-align: left; vertical-align: top; }
tr.ng td { background: var(--warn-soft); }

/* ダイアログ */
.modal {
  position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .45);
  display: flex; align-items: flex-end; justify-content: center;
}
.modal[hidden] { display: none; }
.sheet {
  background: var(--card); width: 100%; max-width: 520px; max-height: 92vh; overflow: auto;
  border-radius: 16px 16px 0 0; padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
@media (min-width: 701px) { .modal { align-items: center; } .sheet { border-radius: 16px; } }
.actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 16px; }
.actions button { flex: 1; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 70;
  bottom: calc(90px + env(safe-area-inset-bottom));
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px;
  max-width: calc(100% - 32px); font-size: 15px; box-shadow: 0 4px 16px rgba(0, 0, 0, .2);
}
.toast.error { background: var(--danger); color: #fff; }

/* スキャナ */
.scanner { position: fixed; inset: 0; z-index: 60; background: #000; }
.scanner video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.scan-guide {
  position: absolute; left: 7%; right: 7%; top: 33%; height: 34%;
  border: 3px solid rgba(255, 255, 255, .9); border-radius: 12px;
  box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35);
}
.scan-line { position: absolute; left: 6%; right: 6%; top: 50%; height: 2px; background: #ff5252; opacity: .8; }
.scan-top {
  position: absolute; left: 0; right: 0; top: 0; padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
  color: #fff; text-align: center; background: linear-gradient(rgba(0,0,0,.6), transparent);
}
.scan-zoom { position: absolute; left: 12%; right: 12%; bottom: calc(150px + env(safe-area-inset-bottom)); }
.scan-bar {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
  padding: 14px 12px calc(14px + env(safe-area-inset-bottom)); background: linear-gradient(transparent, rgba(0,0,0,.7));
}
.scan-bar button, .scan-bar .btn-like { background: rgba(255,255,255,.92); color: #111; border: 0; }
.scan-bar button.on { background: #ffd54f; }

.login { max-width: 420px; margin: 40px auto; }
@media (max-width: 420px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat { padding: 10px; }
  .stat b { font-size: 19px; }
  .stat small { font-size: 12px; }
}

/* v0.2: Amazonの商品画像と、任意項目の畳み */
.found .pimg { width: 64px; height: 64px; object-fit: contain; background: #fff; border-radius: 8px; flex: none; }
.found .grow { flex: 1; min-width: 0; }
.found { justify-content: flex-start; }
.linkish { background: none; border: 0; padding: 4px 0; min-height: 0; color: var(--accent); text-decoration: underline; font-size: 14px; }
.opt { font-weight: 400; margin-left: 6px; }
#more { margin-top: 6px; }
#more > summary { cursor: pointer; padding: 10px 0; color: var(--muted); font-size: 14px; }
details > summary { cursor: pointer; }
#productBox details { margin: 6px 0; }
/* 下の固定タブの裏に入力欄やボタンが隠れないようにする */
@media (max-width: 700px) { html { scroll-padding-bottom: calc(90px + env(safe-area-inset-bottom)); scroll-padding-top: 70px; } }
