/* ============ ReStock デザインシステム ============ */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --text: #1a2330;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --danger: #dc2626;
  --danger-soft: #fee2e2;
  --plus: #059669;
  --minus: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08);
  --tabbar-h: 58px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1520;
    --surface: #1a2330;
    --text: #e6edf5;
    --muted: #8b9bb0;
    --border: #2b3648;
    --accent: #2dd4bf;
    --accent-soft: #134e4a;
    --danger: #f87171;
    --danger-soft: #4c1d1d;
    --plus: #34d399;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-size: 15px;
}
h1 { font-size: 1.35rem; margin: 0 0 16px; }
h2 { font-size: 1.02rem; margin: 0; }
a { color: var(--accent); text-decoration: none; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }
.plus { color: var(--plus); }
.minus { color: var(--minus); }
.mobile-only { display: block; }

/* ---- レイアウト ---- */
.content {
  padding: 16px;
  padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 24px);
  max-width: 1080px;
  margin: 0 auto;
}
.sidenav { display: none; }
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 50;
}
.tabbar a {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 0 6px;
  color: var(--muted);
  font-size: .68rem;
}
.tabbar a.active { color: var(--accent); }
.tabbar svg { width: 22px; height: 22px; }

@media (min-width: 900px) {
  .mobile-only { display: none; }
  .tabbar { display: none; }
  body { display: flex; }
  .sidenav {
    display: flex; flex-direction: column;
    width: 210px; min-height: 100vh;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 12px;
    position: sticky; top: 0;
    flex-shrink: 0;
  }
  .brand { font-size: 1.15rem; font-weight: 700; padding: 0 10px 18px; }
  .sidenav nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
  .sidenav nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 12px;
    border-radius: 8px;
    color: var(--text);
    font-size: .92rem;
  }
  .sidenav nav a:hover { background: var(--bg); }
  .sidenav nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
  .sidenav svg { width: 19px; height: 19px; }
  .content { flex: 1; padding: 28px 32px; }
  .logout-form { padding: 0 10px; }
}

/* ---- カード ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 16px;
}
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }

/* ---- 統計タイル ---- */
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
@media (min-width: 900px) { .stat-grid { grid-template-columns: repeat(4, 1fr); } }
.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
}
.stat-label { font-size: .74rem; color: var(--muted); }
.stat-value { font-size: 1.45rem; font-weight: 700; line-height: 1.3; }
.stat-value small { font-size: .8rem; font-weight: 400; color: var(--muted); }
.stat-sub { font-size: .74rem; color: var(--muted); }

/* ---- リスト ---- */
.row-list { list-style: none; margin: 0; padding: 0; }
.row-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  padding: 10px 2px;
  border-top: 1px solid var(--border);
}
.row-list li:first-child { border-top: none; }
.row-list li > a { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex: 1; color: var(--text); min-width: 0; }
.row-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.row-meta { display: flex; align-items: center; gap: 8px; flex-shrink: 0; font-size: .82rem; color: var(--muted); }

/* ---- 商品カード ---- */
.item-grid { display: grid; grid-template-columns: 1fr; gap: 10px; }
@media (min-width: 700px) { .item-grid { grid-template-columns: 1fr 1fr; } }
@media (min-width: 1100px) { .item-grid { grid-template-columns: 1fr 1fr 1fr; } }
.item-card { display: block; color: var(--text); margin-bottom: 0; }
.item-card:hover { border-color: var(--accent); }
.item-card-top { display: flex; justify-content: space-between; gap: 8px; align-items: flex-start; }
.item-card-top .row-title { font-weight: 600; white-space: normal; }
.item-card-meta { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.item-card-bottom { display: flex; justify-content: space-between; font-size: .84rem; color: var(--muted); }
.chip {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 99px;
  padding: 1px 9px;
  font-size: .74rem;
  color: var(--muted);
}

/* ---- バッジ ---- */
.badge {
  display: inline-block;
  border-radius: 99px;
  padding: 2px 10px;
  font-size: .72rem;
  font-weight: 600;
  background: var(--bg);
  color: var(--muted);
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.st-in_stock { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.badge.st-listed { background: #dbeafe; color: #1d4ed8; border-color: transparent; }
.badge.st-sold_out { background: var(--border); }
.badge.st-discarded { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
@media (prefers-color-scheme: dark) {
  .badge.st-listed { background: #1e3a5f; color: #93c5fd; }
}

/* ---- フォーム ---- */
label { display: block; font-size: .84rem; color: var(--muted); margin-bottom: 12px; }
input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  font-size: 16px; /* iOSズーム防止 */
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
  border-color: var(--accent);
}
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-card { max-width: 640px; }
.form-actions { display: flex; gap: 10px; margin-top: 6px; align-items: center; }
.req { color: var(--danger); font-size: .7rem; }
.inline-form { display: flex; gap: 8px; margin-top: 10px; }
.inline-form input { margin-top: 0; }
.inline-form button { flex-shrink: 0; }
.fee-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
@media (min-width: 900px) { .fee-grid { grid-template-columns: repeat(4, 1fr); } }

/* ---- ボタン ---- */
.btn {
  display: inline-block;
  padding: 9px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: .9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: var(--surface); border-color: var(--danger); color: var(--danger); }
.btn-block { display: block; width: 100%; }
.btn-ghost {
  background: none; border: none; cursor: pointer;
  color: var(--muted); font-size: .84rem; padding: 6px 8px; font-family: inherit;
}
.btn-ghost.danger { color: var(--danger); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #06251f; } }

/* ---- その他 ---- */
.page-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 10px; }
.page-head h1 { margin: 0; }
.item-title { word-break: break-all; }
.filter-bar { display: grid; grid-template-columns: 1fr; gap: 8px; margin-bottom: 16px; }
.filter-bar input, .filter-bar select { margin-top: 0; }
@media (min-width: 900px) { .filter-bar { grid-template-columns: 2fr 1fr 1fr auto; } }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; margin: 0 0 14px; }
@media (min-width: 900px) { .detail-grid { grid-template-columns: repeat(3, 1fr); } }
.detail-grid dt { font-size: .72rem; color: var(--muted); }
.detail-grid dd { margin: 0; font-weight: 500; word-break: break-all; }
.note-block { background: var(--bg); border-radius: 8px; padding: 10px 12px; white-space: pre-wrap; font-size: .9rem; }
.alert {
  background: var(--danger-soft); color: var(--danger);
  border-radius: 8px; padding: 10px 14px; font-size: .88rem;
}
.empty-state { text-align: center; padding: 40px 16px; }
.empty-state .btn { margin-top: 8px; }
.link { font-size: .84rem; }

/* ---- 認証画面 ---- */
.auth-wrap { min-height: 85vh; display: flex; align-items: center; justify-content: center; }
.auth-card { width: 100%; max-width: 380px; }
.auth-logo { text-align: center; font-size: 1.5rem; margin-bottom: 12px; }

/* ---- スキャン画面 ---- */
.scan-video-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  max-height: 55vh;
  aspect-ratio: 3 / 2;
  margin-bottom: 12px;
}
.scan-video-wrap video { width: 100%; height: 100%; object-fit: cover; display: block; }
.scan-frame {
  position: absolute; inset: 18% 12%;
  border: 2px solid rgba(255,255,255,.85);
  border-radius: 10px;
  box-shadow: 0 0 0 999px rgba(0,0,0,.25);
  pointer-events: none;
}
.cand-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.cand-card { display: flex; gap: 12px; align-items: center; cursor: pointer; margin-bottom: 0; }
.cand-card:hover { border-color: var(--accent); }
.cand-img {
  width: 72px; height: 72px; object-fit: contain;
  background: #fff; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center; font-size: 1.6rem;
}
.cand-body { min-width: 0; }
.cand-title {
  font-size: .88rem; font-weight: 600;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.alert-info {
  border-color: #d97706;
  background: #fef3c7; color: #92400e;
  font-size: .88rem;
}
.alert-info a { color: inherit; text-decoration: underline; }
@media (prefers-color-scheme: dark) { .alert-info { background: #452c07; color: #fcd34d; } }
.sel-preview { text-align: center; margin-bottom: 10px; }
.sel-preview img { max-height: 140px; border-radius: 8px; background: #fff; }

/* ---- 写真 ---- */
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}
.photo-cell { position: relative; }
.photo-cell img {
  width: 100%; aspect-ratio: 1; object-fit: cover;
  border-radius: 8px; display: block; border: 1px solid var(--border);
}
.photo-del {
  position: absolute; top: 4px; right: 4px;
  width: 24px; height: 24px; line-height: 1;
  border-radius: 50%; border: none; cursor: pointer;
  background: rgba(0,0,0,.6); color: #fff; font-size: .9rem;
}
.item-card-flex { display: flex; gap: 10px; }
.item-card-main { flex: 1; min-width: 0; }
.item-thumb {
  width: 64px; height: 64px; object-fit: cover;
  border-radius: 8px; flex-shrink: 0; border: 1px solid var(--border);
}

/* ---- トースト ---- */
.toast {
  position: fixed;
  bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 14px);
  left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg);
  padding: 9px 22px; border-radius: 99px;
  font-size: .86rem; font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
  z-index: 100;
  animation: toast-in .25s ease;
}
.toast.hide { opacity: 0; transition: opacity .4s; }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } }
@media (min-width: 900px) { .toast { bottom: 28px; } }
