:root {
  color-scheme: dark;
  --bg: #06111f;
  --panel: rgba(8, 26, 48, .9);
  --panel-strong: rgba(11, 34, 57, .96);
  --line: rgba(133, 201, 238, .28);
  --line-soft: rgba(133, 201, 238, .14);
  --text: #f7fbff;
  --muted: #a8bfd3;
  --accent: #22d3ee;
  --green: #22c55e;
  --yellow: #eab308;
  --gold: #e5b853;
  --danger: #f87171;
  --blue: #60a5fa;
  font-family: "Noto Sans JP", "Segoe UI", "Yu Gothic UI", Meiryo, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 16% 0%, rgba(34, 211, 238, .16), transparent 28%),
    linear-gradient(180deg, #06111f 0%, #071a2d 44%, #04101d 100%);
  color: var(--text);
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: #9ee8ff; text-decoration: none; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.ledger-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px 14px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: rgba(4, 14, 28, .92);
  backdrop-filter: blur(14px);
}
.ledger-title { min-width: 0; }
.eyebrow { margin: 0 0 2px; color: #89a8bf; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.ledger-header h1 { margin: 0; font-size: clamp(22px, 5vw, 34px); line-height: 1.1; }
.ledger-lead { margin: 4px 0 0; color: var(--muted); font-size: 12px; }
.ledger-links { display: flex; flex-wrap: wrap; gap: 6px; }

.pill-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 6px 14px;
  border: 1px solid rgba(168, 223, 255, .26);
  border-radius: 999px;
  background: var(--panel-strong);
  color: var(--text);
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
  white-space: nowrap;
}
.pill-btn.primary { border-color: rgba(103, 232, 249, .45); background: linear-gradient(135deg, #1fc7e7, #116f9d); }
.pill-btn.small { min-height: 32px; padding: 4px 12px; font-size: 12px; }
.pill-btn:disabled { opacity: .5; cursor: progress; }

.ledger-shell { width: min(1180px, calc(100% - 32px)); margin: 12px auto 40px; display: grid; gap: 12px; }
.ledger-status { margin: 0; color: var(--muted); font-size: 12px; }
.ledger-status[data-error="1"] { color: var(--danger); font-weight: 700; }
.ledger-data { display: grid; gap: 12px; }

.ledger-empty { padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--panel); }
.ledger-empty h2 { margin: 0 0 8px; font-size: 18px; }
.ledger-empty p { margin: 6px 0 0; color: var(--muted); font-size: 13px; line-height: 1.6; }

/* 状態ごとの件数カード（出品ツール v253 の状態カードと同じ考え方：押すと絞り込む） */
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 8px; }
.tile {
  display: grid;
  gap: 2px;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line-soft);
  border-radius: 12px;
  background: var(--panel);
  text-align: left;
  cursor: pointer;
}
.tile.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.tile-label { color: var(--muted); font-size: 12px; font-weight: 700; }
.tile-value { font-size: 24px; line-height: 1.1; font-variant-numeric: tabular-nums; }
.tile-sub { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile[data-tone="green"] .tile-value { color: #4ade80; }
.tile[data-tone="offer"] .tile-value { color: #fde047; }
.tile[data-tone="hand"] .tile-value { color: var(--gold); }
.tile[data-tone="done"] .tile-value { color: #cbd5e1; }

.ledger-meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 4px 12px; color: var(--muted); font-size: 11.5px; line-height: 1.5; }

.filters { display: grid; gap: 8px; padding: 10px 12px; border: 1px solid var(--line-soft); border-radius: 12px; background: var(--panel); }
.filter-search input {
  width: 100%;
  min-height: 40px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #061524;
  font-size: 16px;
}
.filter-row { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; }
.filter-row label { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.filter-row select, .status-select select, .ledger-dialog select, .ledger-dialog input, .ledger-dialog textarea {
  min-height: 34px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #061524;
  font-size: 14px;
}
.filter-row .check input { width: 18px; height: 18px; }
.filter-count { margin: 0; color: var(--muted); font-size: 12px; }

.card-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 10px; }
.no-result { margin: 0; color: var(--muted); }
.card {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-left: 4px solid #475569;
  border-radius: 12px;
  background: var(--panel);
}
.card[data-kind="green"] { border-left-color: var(--green); }
.card[data-kind="yellow"] { border-left-color: var(--yellow); }
.card[data-kind="waiting"] { border-left-color: #94a3b8; }
.card[data-kind="done"] { opacity: .82; }
.card-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.badge { flex: 0 0 auto; padding: 2px 8px; border-radius: 6px; background: #334155; font-size: 12px; font-weight: 800; white-space: nowrap; }
.badge[data-kind="green"] { background: #16a34a; }
.badge[data-kind="yellow"] { background: #ca8a04; color: #111827; }
.badge[data-kind="waiting"] { background: #475569; }
.badge[data-kind="done"] { background: #1e293b; color: var(--muted); }
.card-name { flex: 1 1 auto; min-width: 0; margin: 0; overflow: hidden; font-size: 15px; line-height: 1.3; text-overflow: ellipsis; white-space: nowrap; }
.grade { flex: 0 0 auto; color: var(--gold); font-size: 13px; font-weight: 800; }
.card-sub { margin: 0; color: var(--muted); font-size: 11.5px; overflow-wrap: anywhere; }
.loc[data-loc="手元"] { color: var(--gold); font-weight: 800; }
.loc[data-loc="未確認"] { color: #fca5a5; }
.card-nums { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; margin: 0; }
.card-nums div { min-width: 0; padding: 4px 6px; border-radius: 8px; background: rgba(255, 255, 255, .04); }
.card-nums dt { color: var(--muted); font-size: 10.5px; font-weight: 700; }
.card-nums dd { margin: 0; font-size: 13px; font-weight: 700; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.card-nums small { display: block; color: var(--muted); font-size: 10.5px; font-weight: 600; }
.card-ratios { display: flex; flex-wrap: wrap; gap: 4px 12px; margin: 0; font-size: 12.5px; font-weight: 700; font-variant-numeric: tabular-nums; }
.profit[data-sign="plus"] { color: #4ade80; }
.profit[data-sign="minus"] { color: var(--danger); }
.sale-line { margin: 0; color: #cbd5e1; font-size: 12px; }
.card-memo { margin: 0; color: var(--muted); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.status-select select { min-height: 32px; font-size: 13px; }
.sold-btn { border-color: rgba(229, 184, 83, .55); color: #fde68a; }
.more-row { display: flex; justify-content: center; }

.ledger-dialog {
  width: min(520px, calc(100vw - 24px));
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #0a1d33;
  color: var(--text);
}
.ledger-dialog::backdrop { background: rgba(0, 0, 0, .55); }
.dialog-head { padding: 14px 16px 6px; }
.dialog-head h2 { margin: 0; font-size: 18px; }
.dialog-head p { margin: 4px 0 0; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.dialog-body { display: grid; gap: 10px; padding: 6px 16px 10px; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.ledger-dialog label { display: grid; gap: 4px; color: var(--muted); font-size: 12px; font-weight: 700; }
.ledger-dialog input, .ledger-dialog select, .ledger-dialog textarea { width: 100%; font-size: 16px; color: var(--text); }
.ledger-dialog fieldset { margin: 0; padding: 8px 10px 10px; border: 1px solid var(--line-soft); border-radius: 10px; }
.ledger-dialog legend { padding: 0 4px; color: var(--text); font-size: 12px; font-weight: 800; }
.dialog-error { margin: 0; min-height: 1em; color: var(--danger); font-size: 12.5px; font-weight: 700; }
.dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 10px 16px 14px; border-top: 1px solid var(--line-soft); }

.toast {
  position: fixed;
  left: 50%;
  bottom: max(16px, env(safe-area-inset-bottom));
  z-index: 50;
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border: 1px solid rgba(74, 222, 128, .45);
  border-radius: 12px;
  background: #052e16;
  color: #dcfce7;
  font-size: 13px;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .4);
}
.toast[data-error="1"] { border-color: rgba(248, 113, 113, .5); background: #450a0a; color: #fee2e2; }

@media (max-width: 560px) {
  .ledger-header { position: static; }
  .ledger-shell { width: calc(100% - 24px); }
  .ledger-lead { display: none; }
  .tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .tile { padding: 7px 8px; border-radius: 10px; }
  .tile-label { font-size: 11px; }
  .tile-value { font-size: 20px; }
  .tile-sub { font-size: 10px; white-space: normal; }
  .card-list { grid-template-columns: 1fr; }
  .card-nums { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .field-grid { grid-template-columns: 1fr; }
}

/* ---- v2（2026-10-09）：タブと注文・発送台帳 ---- */
.ledger-tabs { display: flex; gap: 6px; padding: 4px; border: 1px solid var(--line); border-radius: 12px; background: rgba(5, 18, 33, .9); }
.ledger-tabs button { flex: 1 1 0; min-height: 38px; border: 1px solid transparent; border-radius: 9px; background: transparent; color: var(--muted); font-weight: 800; font-size: 13px; cursor: pointer; }
.ledger-tabs button.active { border-color: rgba(103, 232, 249, .45); background: linear-gradient(135deg, rgba(34, 211, 238, .25), rgba(59, 130, 246, .22)); color: var(--text); }
.orders-panel { display: grid; gap: 10px; }
.orders-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.orders-help { flex: 1 1 100%; margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.orders-scroll { overflow-x: auto; border: 1px solid var(--line-soft); border-radius: 12px; background: var(--panel); }
.orders-table { width: 100%; min-width: 1180px; border-collapse: collapse; font-size: 13px; }
.orders-table th, .orders-table td { padding: 8px 10px; border-bottom: 1px solid var(--line-soft); text-align: left; vertical-align: top; white-space: nowrap; }
.orders-table th { position: sticky; top: 0; background: var(--panel-strong); color: var(--muted); font-size: 12px; font-weight: 800; }
.orders-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.orders-table td.merge { background: rgba(34, 211, 238, .06); border-left: 3px solid rgba(96, 165, 250, .6); vertical-align: middle; }
.orders-table td small, .orders-table td .missing { display: block; color: var(--muted); font-size: 11px; font-weight: 400; white-space: normal; }
.orders-table td.muted { color: var(--muted); }
.orders-table .missing-cell { white-space: normal; min-width: 180px; }
.orders-table .missing { color: #fca5a5; font-weight: 700; }
.link-btn { padding: 0; border: 0; background: none; color: #9ee8ff; font: inherit; cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link-btn.strong { font-weight: 800; }
.mark { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 999px; font-size: 10.5px; font-weight: 800; line-height: 16px; text-align: center; vertical-align: middle; }
.mark-ok { background: rgba(34, 197, 94, .2); color: #4ade80; }
.mark-warn { background: rgba(234, 179, 8, .22); color: #fde047; }
.mark-ng { background: rgba(248, 113, 113, .22); color: #fca5a5; }
.mark-none { background: rgba(148, 163, 184, .18); color: var(--muted); }
.status-chip { display: inline-block; padding: 1px 8px; border-radius: 999px; background: #334155; font-size: 11.5px; font-weight: 800; }
.status-chip[data-status="鑑定中"], .status-chip[data-status="発送済み・鑑定中"] { background: rgba(96, 165, 250, .25); color: #bfdbfe; }
.status-chip[data-status="返送済み"], .status-chip[data-status="鑑定完了"] { background: rgba(34, 197, 94, .2); color: #86efac; }
.ledger-dialog .field-grid label input[readonly] { opacity: .7; }
@media (max-width: 560px) {
  .ledger-tabs button { font-size: 12px; min-height: 36px; }
  .orders-table { font-size: 12px; }
}

/* v3（2026-10-09・設計書 第5版）：状態は5つ。未入金のタイル、カードの状態バッジ、期間の入力 */
.tile[data-tone="unpaid"] .tile-value { color: #fca5a5; }
.badge[data-status="売却済み"] { background: #475569; }
.badge[data-status="保管中"] { background: #1d4ed8; }
.badge[data-status="鑑定中"], .badge[data-status="返送中"], .badge[data-status="提出準備"] { background: #92400e; }
.badge.unpaid { background: #b91c1c; }
.period-custom { display: inline-flex; align-items: center; gap: 4px; }
.sale-line .paid { color: #86efac; }
.sale-line .unpaid-text { color: #fca5a5; font-weight: 700; }

/* v4（2026-10-09 ユーザー要望）：鑑定台帳の表（1行＝1枚）と、カード名にカーソルを合わせたときの画像 */
.cards-scroll { margin-top: 10px; }
.cards-table { min-width: 1280px; }
.cards-table td { vertical-align: middle; }
.cards-table td small { display: block; color: var(--muted); font-size: 11px; font-weight: 400; white-space: nowrap; }
.cards-table .thumb-cell { width: 44px; }
.cards-table .thumb { width: 36px; height: 50px; object-fit: cover; border-radius: 4px; background: #0b1220; cursor: zoom-in; }
.cards-table .name-cell { min-width: 220px; max-width: 360px; white-space: normal; }
.cards-table .name-hover { cursor: zoom-in; border-bottom: 1px dotted var(--muted); }
.cards-table .marks { display: flex; gap: 3px; justify-content: flex-end; }
.cards-table .mark { padding: 0 4px; border-radius: 4px; font-size: 10px; font-weight: 700; }
.cards-table .actions-cell { white-space: nowrap; }
.cards-table .actions-cell select { margin-right: 4px; }
.image-popover { position: fixed; z-index: 1000; width: 320px; padding: 8px; background: var(--panel-strong); border: 1px solid var(--line-soft); border-radius: 10px; box-shadow: 0 16px 40px rgba(0, 0, 0, .5); pointer-events: none; }
.image-popover img { display: block; width: 100%; max-height: 380px; object-fit: contain; border-radius: 6px; background: #0b1220; }
.image-popover p { margin: 6px 0 0; font-size: 12px; color: var(--muted); }
@media (max-width: 700px) { .cards-table { min-width: 1100px; } }
