/* BidMemo 共通スタイル（拡張機能のサイドパネルと、iPhone/PC用の閲覧画面で共用） */
:root {
  --bg: #ffffff;
  --bg-sub: #f6f7f9;
  --bg-hover: #eef1f5;
  --line: #e2e5ea;
  --line-strong: #cfd4db;
  --text: #1c1f24;
  --text-sub: #5f6773;
  --text-faint: #8a919c;
  --accent: #1f6feb;
  --accent-weak: #e8f0fe;
  --accent-text: #ffffff;
  --won: #1a7f37;
  --won-bg: #e6f4ea;
  --lost: #b42318;
  --lost-bg: #fdecea;
  --unsold: #5f6773;
  --unsold-bg: #eef0f3;
  --pending: #9a6700;
  --pending-bg: #fff4d6;
  --danger: #b42318;
  --radius: 8px;
  --shadow: 0 8px 30px rgba(0, 0, 0, 0.18);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1b1d21;
    --bg-sub: #23262b;
    --bg-hover: #2b2f35;
    --line: #33373e;
    --line-strong: #454a52;
    --text: #e8eaed;
    --text-sub: #a9afb8;
    --text-faint: #7f8690;
    --accent: #5b9dff;
    --accent-weak: #1f2f4a;
    --accent-text: #0e1116;
    --won: #57c27a;
    --won-bg: #1c3325;
    --lost: #ff8a7f;
    --lost-bg: #3a2220;
    --unsold: #a9afb8;
    --unsold-bg: #2b2f35;
    --pending: #e3b341;
    --pending-bg: #3a3120;
    --danger: #ff8a7f;
    --shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Segoe UI", sans-serif;
  font-size: 13px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
[hidden] { display: none !important; }

/* ── ボタン ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 32px; padding: 0 12px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--bg); color: var(--text);
  cursor: pointer; white-space: nowrap; font-size: 13px;
}
.btn:hover { background: var(--bg-hover); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.primary:hover { filter: brightness(1.06); }
.btn.danger { color: var(--danger); }
.btn.block { width: 100%; height: 38px; font-size: 14px; }
.btn.small { height: 26px; padding: 0 8px; font-size: 12px; }
.link-btn { background: none; border: none; padding: 0; color: var(--accent); cursor: pointer; font-size: 12px; }

/* ── 入力 ── */
.field { margin-bottom: 10px; }
.field > label, .field-label {
  display: block; font-size: 11px; font-weight: 600; color: var(--text-sub); margin-bottom: 4px; letter-spacing: 0.02em;
}
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.input, .select, .textarea {
  width: 100%; height: 34px; padding: 0 10px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--bg); outline: none;
}
.textarea { height: auto; min-height: 64px; padding: 8px 10px; resize: vertical; }
.input:focus, .select:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }
.input.money { text-align: right; font-variant-numeric: tabular-nums; font-size: 14px; }
.input-wrap { position: relative; }
.input-wrap .unit { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--text-faint); pointer-events: none; }
.input-wrap .input.money { padding-left: 26px; }

/* セグメント（状態ランク・販売先・結果） */
.seg { display: flex; border: 1px solid var(--line-strong); border-radius: var(--radius); overflow: hidden; }
.seg button {
  flex: 1; height: 32px; border: none; border-left: 1px solid var(--line); background: var(--bg);
  cursor: pointer; font-size: 13px; color: var(--text-sub); padding: 0 4px; white-space: nowrap;
}
.seg button:first-child { border-left: none; }
.seg button:hover { background: var(--bg-hover); }
.seg button.on { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.seg.rank button { font-weight: 600; font-size: 14px; }

/* ── バッジ ── */
.badge {
  display: inline-block; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; line-height: 18px; white-space: nowrap;
}
.badge.won { background: var(--won-bg); color: var(--won); }
.badge.lost { background: var(--lost-bg); color: var(--lost); }
.badge.unsold { background: var(--unsold-bg); color: var(--unsold); }
.badge.pending { background: var(--pending-bg); color: var(--pending); }
.badge.rank { background: var(--bg-sub); color: var(--text); border: 1px solid var(--line-strong); }
.badge.plain { background: var(--bg-sub); color: var(--text-sub); }

/* ── 記録カード（一覧） ── */
.cards { display: flex; flex-direction: column; gap: 8px; }
.card {
  display: grid; grid-template-columns: 64px 1fr; gap: 10px;
  padding: 8px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--bg); cursor: pointer; text-align: left; width: 100%;
}
.card:hover { background: var(--bg-hover); }
.card .thumb, .grid-item .thumb {
  width: 64px; height: 64px; border-radius: 6px; background: var(--bg-sub); object-fit: cover; display: block;
}
.card .noimg, .grid-item .noimg {
  width: 64px; height: 64px; border-radius: 6px; background: var(--bg-sub); color: var(--text-faint);
  display: flex; align-items: center; justify-content: center; font-size: 10px;
}
.card .body { min-width: 0; }
.card .title { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card .meta { font-size: 11px; color: var(--text-sub); display: flex; flex-wrap: wrap; gap: 4px 8px; align-items: center; margin-top: 2px; }
.card .prices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-top: 4px; }
.price-cell { font-size: 10px; color: var(--text-faint); }
.price-cell b { display: block; font-size: 13px; color: var(--text); font-weight: 600; font-variant-numeric: tabular-nums; }
.price-cell .diff { display: block; font-size: 10px; color: var(--text-sub); font-weight: 600; }
.price-cell .diff.diff-up { color: var(--lost); }
.price-cell .diff.diff-down { color: var(--won); }
.card .memo-line { font-size: 11px; color: var(--text-sub); margin-top: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* 画像グリッド表示 */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.grid-item {
  border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; cursor: pointer; background: var(--bg);
  padding: 0; text-align: left; width: 100%;
}
.grid-item:hover { border-color: var(--line-strong); }
.grid-item .thumb, .grid-item .noimg { width: 100%; height: auto; aspect-ratio: 1 / 1; border-radius: 0; }
.grid-item .cap { padding: 4px 6px 6px; font-size: 11px; }
.grid-item .cap .t { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-sub); }
.grid-item .cap .p { display: flex; justify-content: space-between; align-items: center; gap: 4px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ── 一覧の検索バー ── */
.search-bar { display: flex; gap: 6px; margin-bottom: 8px; }
.search-bar .input { flex: 1; }
.filters { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.filters .select { height: 30px; font-size: 12px; padding: 0 6px; }
.list-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: 12px; color: var(--text-sub); }
.view-toggle { display: flex; border: 1px solid var(--line-strong); border-radius: 6px; overflow: hidden; }
.view-toggle button { border: none; background: var(--bg); height: 24px; padding: 0 8px; font-size: 11px; cursor: pointer; color: var(--text-sub); }
.view-toggle button.on { background: var(--bg-sub); color: var(--text); font-weight: 600; }
.empty { padding: 24px 8px; text-align: center; color: var(--text-faint); font-size: 12px; }
.more { margin-top: 10px; }

/* ── 編集画面（モーダル） ── */
.modal-back {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.35); z-index: 100;
  display: flex; justify-content: center; align-items: flex-start; overflow-y: auto; padding: 16px 8px;
}
.modal {
  width: 100%; max-width: 560px; background: var(--bg); border-radius: 12px; box-shadow: var(--shadow);
  padding: 14px; position: relative;
}
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; margin-bottom: 10px; }
.modal-head h2 { font-size: 14px; margin: 0; line-height: 1.4; word-break: break-all; }
.modal-close { border: none; background: none; font-size: 13px; color: var(--text-sub); cursor: pointer; padding: 2px 4px; white-space: nowrap; }
.info-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-bottom: 12px; }
.info-table th { text-align: left; color: var(--text-sub); font-weight: 500; padding: 3px 8px 3px 0; white-space: nowrap; width: 1%; vertical-align: top; }
.info-table td { padding: 3px 0; word-break: break-all; font-variant-numeric: tabular-nums; }
.modal-foot { display: flex; justify-content: space-between; gap: 8px; margin-top: 12px; }
.modal-foot .btn.primary { flex: 1; }

/* 画像一覧（編集画面） */
.img-strip { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 10px; }
.img-strip .img-box { position: relative; flex: 0 0 auto; }
.img-strip img { width: 76px; height: 76px; object-fit: cover; border-radius: 6px; cursor: zoom-in; display: block; background: var(--bg-sub); }
.img-strip .img-del {
  position: absolute; right: 2px; top: 2px; border: none; border-radius: 4px; background: rgba(0, 0, 0, 0.6); color: #fff;
  font-size: 10px; padding: 1px 4px; cursor: pointer;
}
.img-strip .img-box.removed img { opacity: 0.25; }
.img-strip .img-add {
  width: 76px; height: 76px; border: 1px dashed var(--line-strong); border-radius: 6px; display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: var(--text-sub); cursor: pointer; flex: 0 0 auto; background: var(--bg);
}

/* 拡大表示 */
.lightbox {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.88); z-index: 200; display: flex; align-items: center; justify-content: center;
  cursor: zoom-out;
}
.lightbox img { max-width: 96vw; max-height: 90vh; object-fit: contain; }
.lightbox .lb-nav {
  position: absolute; top: 50%; transform: translateY(-50%); border: none; background: rgba(255, 255, 255, 0.15); color: #fff;
  width: 40px; height: 56px; font-size: 20px; cursor: pointer; border-radius: 6px;
}
.lightbox .lb-prev { left: 8px; }
.lightbox .lb-next { right: 8px; }
.lightbox .lb-count { position: absolute; bottom: 12px; left: 0; right: 0; text-align: center; color: #ddd; font-size: 12px; }

/* 通知 */
.toast {
  position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 300;
  background: #1c1f24; color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 12px; box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
}
.toast.error { background: #b42318; }

/* 確認ダイアログ */
.confirm-box { max-width: 340px; margin-top: 30vh; }
.confirm-box p { margin: 0 0 14px; font-size: 13px; }
.confirm-box .modal-foot { justify-content: flex-end; }
.confirm-box .modal-foot .btn.primary { flex: 0 0 auto; }

.muted { color: var(--text-sub); }
.faint { color: var(--text-faint); }
.section-title { font-size: 12px; font-weight: 700; color: var(--text-sub); margin: 14px 0 6px; display: flex; justify-content: space-between; align-items: center; }
.hr { border: none; border-top: 1px solid var(--line); margin: 12px 0; }
