/* ============================================================
   ledger-v2.css — エクセルライク帳簿グリッド
   ============================================================ */

/* ========== ライトモード変数 ========== */
[data-theme="light"] {
  --bg-primary: #f5f7fa;
  --bg-secondary: #ffffff;
  --bg-card: #ffffff;
  --bg-card-hover: #f0f2f5;
  --bg-input: #f8f9fb;
  --bg-modal: rgba(0, 0, 0, 0.4);
  --text-primary: #1a1a2e;
  --text-secondary: #4a5568;
  --text-muted: #718096;
  --border-subtle: rgba(0, 0, 0, 0.1);
  --border-active: rgba(79, 124, 255, 0.5);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* ========== ヘッダー ========== */
.v2-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}
.v2-header h1 {
  font-size: 1.2rem;
  margin: 0;
  color: var(--text-primary);
}
.v2-header-left,
.v2-header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.v2-year-selector {
  display: flex;
  gap: 4px;
}
.v2-year-btn {
  padding: 4px 16px;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.15s;
}
.v2-year-btn:hover {
  border-color: var(--accent-blue);
  color: var(--text-primary);
}
.v2-year-btn.active {
  background: var(--accent-blue);
  color: #fff;
  border-color: var(--accent-blue);
}
.v2-nav-link {
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.85rem;
  transition: color 0.2s;
}
.v2-nav-link:hover {
  color: var(--accent-blue);
}

.v2-theme-toggle {
  background: none;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  font-size: 1.1rem;
  transition: all 0.2s;
}
.v2-theme-toggle:hover {
  border-color: var(--accent-blue);
}

/* ========== ツールバー ========== */
.v2-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  background: var(--bg-card);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 49px; /* ヘッダーの高さ分 */
  z-index: 99;
}

/* ========== 月フィルタナビ ========== */
.v2-month-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 24px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 90px; /* ヘッダー + ツールバーの高さ分 */
  z-index: 98;
  overflow-x: auto;
  scrollbar-width: thin;
}
.v2-month-nav:empty {
  display: none;
}
.v2-month-btn {
  padding: 4px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.8rem;
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.15s;
}
.v2-month-btn:hover {
  border-color: var(--month-btn-color, var(--accent-blue));
  color: var(--text-primary);
  background: rgba(79, 124, 255, 0.08);
}
.v2-month-btn.active {
  background: var(--month-btn-color, var(--accent-blue));
  color: #fff;
  border-color: var(--month-btn-color, var(--accent-blue));
  font-weight: 600;
}
.v2-month-count {
  font-size: 0.7rem;
  opacity: 0.7;
  margin-left: 2px;
}
.v2-toolbar-left,
.v2-toolbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}
.v2-search-box input {
  padding: 6px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.85rem;
  width: 250px;
  outline: none;
  transition: border-color 0.2s;
}
.v2-search-box input:focus {
  border-color: var(--accent-blue);
}

/* ========== ボタン共通 ========== */
.v2-btn {
  padding: 6px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  transition: all 0.15s;
}
.v2-btn:hover {
  border-color: var(--accent-blue);
  background: rgba(79, 124, 255, 0.1);
}
.v2-btn-sm {
  padding: 4px 10px;
  font-size: 0.8rem;
}
.v2-btn-primary {
  background: var(--accent-blue);
  color: #fff;
  border-color: var(--accent-blue);
}
.v2-btn-primary:hover {
  background: #3b6cff;
  border-color: #3b6cff;
}
.v2-btn-ghost {
  background: transparent;
  border-color: var(--border-subtle);
  color: var(--text-secondary);
}
.v2-btn-dashed {
  border-style: dashed;
  border-color: var(--accent-blue);
  color: var(--accent-blue);
  background: rgba(79, 124, 255, 0.06);
  font-weight: 500;
}
.v2-btn-dashed:hover {
  background: rgba(79, 124, 255, 0.15);
  color: #fff;
}

.v2-record-count {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.v2-bulk-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* ========== ボタン ========== */
.v2-btn {
  padding: 6px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 0.85rem;
  font-family: inherit;
  transition: all 0.15s;
  white-space: nowrap;
}
.v2-btn:hover {
  border-color: var(--accent-blue);
}
.v2-btn-primary {
  background: var(--accent-blue);
  color: #fff;
  border-color: var(--accent-blue);
}
.v2-btn-primary:hover {
  filter: brightness(1.1);
}
.v2-btn-danger {
  background: var(--accent-red);
  color: #fff;
  border-color: var(--accent-red);
}
.v2-btn-ghost {
  background: transparent;
  border-color: transparent;
}
.v2-btn-ghost:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-subtle);
}

.v2-btn-sm {
  padding: 3px 8px;
  font-size: 0.78rem;
}
.v2-btn-success {
  background: var(--accent-green);
  color: #fff;
  border-color: var(--accent-green);
}

/* ========== エクセルグリッド ========== */
.v2-grid-container {
  flex: 1;
  /* overflowなし — thead thのstickyがウィンドウスクロールで動作するように */
  background: var(--bg-primary);
}
.v2-grid {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.88rem;
  table-layout: fixed;
}

.v2-grid thead th {
  background: var(--bg-card);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.78rem;
  padding: 8px 6px;
  border-bottom: 2px solid var(--accent-blue);
  border-right: 1px solid var(--border-subtle);
  text-align: left;
  user-select: none;
  white-space: nowrap;
  position: sticky;
  top: 120px; /* ヘッダー(49px) + ツールバー(41px) + 月ナビ(30px) */
  z-index: 50;
}
.v2-grid thead th:last-child {
  border-right: none;
}
.v2-grid thead th.col-check {
  width: 32px;
  text-align: center;
}

.v2-grid thead th.col-date {
  width: 70px;
}
.v2-grid thead th.col-partner {
  width: 110px;
}
.v2-grid thead th.col-product {
  width: 130px;
}
.v2-grid thead th.col-qty {
  width: 40px;
  text-align: right;
}
.v2-grid thead th.col-price {
  width: 64px;
  text-align: right;
}
.v2-grid thead th.col-subtotal {
  width: 68px;
  text-align: right;
}
.v2-grid thead th.col-tax {
  width: 58px;
  text-align: right;
}
.v2-grid thead th.col-total {
  width: 68px;
  text-align: right;
}
.v2-grid thead th.col-memo {
  width: 70px;
}
.v2-grid thead th.col-grand {
  width: 78px;
  text-align: right;
}
.v2-grid thead th.col-payment {
  width: 64px;
  text-align: center;
}
.v2-grid thead th.col-actions {
  width: 100px;
}
.v2-grid thead th.col-cost-total {
  width: 72px;
  text-align: right;
}
.v2-grid thead th.col-profit {
  width: 72px;
  text-align: right;
}

/* ---- 行スタイル ---- */
.v2-grid tbody tr {
  border-bottom: 1px solid var(--border-subtle);
  transition: background 0.1s;
}
.v2-grid tbody tr:hover {
  background: rgba(79, 124, 255, 0.08);
}
.v2-grid tbody tr.row-parent {
  background: var(--bg-card);
}
.v2-grid tbody tr.row-child {
  background: var(--bg-secondary);
}
.v2-grid tbody tr.row-child td {
  color: var(--text-primary);
}
.v2-grid tbody tr.row-child td:nth-child(3),
.v2-grid tbody tr.row-child td:nth-child(4) {
  font-size: 0.82rem;
}
.v2-grid tbody tr.row-editing {
  background: rgba(79, 124, 255, 0.06);
  outline: 2px solid var(--accent-blue);
  outline-offset: -2px;
}
.v2-grid tbody tr.row-paid {
  background: rgba(16, 185, 129, 0.05);
}
.v2-grid tbody tr.row-partial {
  background: rgba(245, 158, 11, 0.05);
}

/* ---- グルーピング ---- */
.v2-grid tbody tr.row-group-first {
  border-top: 2px solid var(--border-subtle);
}
.v2-grid tbody tr.row-group-last {
  border-bottom: 2px solid var(--border-subtle);
}
.v2-grid tbody tr.row-shipping {
  background: rgba(139, 92, 246, 0.03);
}
.v2-grid tbody tr.row-shipping .shipping-label {
  color: #6ee7b7;
  font-weight: 500;
  font-size: 0.85rem;
}
.v2-grid tbody tr.row-shipping-empty td {
  padding: 3px 6px;
}
.shipping-label-empty {
  text-align: left !important;
}
.v2-grid tbody tr.row-add-item td {
  padding: 4px 6px;
  border-bottom-color: transparent;
}
.v2-grid tbody tr.row-add-item:hover {
  background: transparent;
}
/* 追加ボタン横並びレイアウト */
.row-add-item .add-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}
/* 追加ボタン: デフォルト非表示 — showAddトグルで制御 */
.row-add-item {
  display: none;
}
[data-show-add] .row-add-item {
  display: table-row;
}

/* ---- New!バッジ ---- */
.new-badge {
  display: inline-block;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.62rem;
  font-weight: 700;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  letter-spacing: 0.5px;
  animation: newBadgePulse 2s ease-in-out infinite;
}
@keyframes newBadgePulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

/* ---- 明細削除ボタン ---- */
.item-delete-btn {
  opacity: 0.3;
  transition:
    opacity 0.15s,
    color 0.15s;
  padding: 6px 10px !important;
  font-size: 0.88rem !important;
}
.v2-grid tbody tr:hover .item-delete-btn {
  opacity: 1;
}
.item-delete-btn:hover {
  color: var(--accent-red) !important;
  background: rgba(239, 68, 68, 0.1);
}

.v2-grid td {
  padding: 6px 8px;
  color: var(--text-primary);
  vertical-align: middle;
  font-variant-numeric: tabular-nums;
  border-right: 1px solid rgba(255, 255, 255, 0.04);
}
.v2-grid td:last-child {
  border-right: none;
}
.v2-grid td.text-right {
  text-align: right;
}
.v2-grid td.text-center {
  text-align: center;
}
.v2-grid td.col-check {
  text-align: center;
}

.v2-grid td input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

/* ---- インライン編集可能セル ---- */
.v2-grid td.editable {
  cursor: text;
  position: relative;
}
.v2-grid td.editable:hover {
  background: rgba(79, 124, 255, 0.04);
}
.v2-grid td.editable .cell-display {
  display: block;
  min-height: 1.3em;
}
.v2-grid td.editable .cell-input {
  display: none;
}
.v2-grid td.editable.editing .cell-display {
  display: none;
}
.v2-grid td.editable.editing .cell-input {
  display: block;
  width: 100%;
  padding: 2px 4px;
  border: 1px solid var(--accent-blue);
  border-radius: 3px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: inherit;
  font-family: inherit;
  outline: none;
}
/* ネイティブスピナーを非表示（±ボタンで代替するため） */
.v2-grid td.editable .cell-input[type="number"]::-webkit-inner-spin-button,
.v2-grid td.editable .cell-input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.v2-grid td.editable .cell-input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}
/* 数値セル編集時の±ボタン */
.v2-grid td.editable.editing .num-controls {
  display: flex;
  align-items: center;
  gap: 2px;
}
.v2-grid td.editable .num-controls {
  display: none;
}
.num-controls .cell-input {
  text-align: center;
  flex: 1;
  min-width: 0;
}
.num-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 6px;
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  user-select: none;
  flex-shrink: 0;
  transition: all 0.15s;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}
/* −ボタン: 赤系 */
.num-btn:first-child {
  background: linear-gradient(135deg, #ef4444, #dc2626);
}
.num-btn:first-child:hover {
  background: linear-gradient(135deg, #dc2626, #b91c1c);
  transform: scale(1.08);
}
/* +ボタン: 青系 */
.num-btn:last-child {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
}
.num-btn:last-child:hover {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  transform: scale(1.08);
}
.num-btn:active {
  transform: scale(0.92);
}
/* 数値セル編集時の拡大表示 */
.v2-grid td.editable.editing-expanded {
  position: relative;
  z-index: 10;
}
.v2-grid td.editable.editing-expanded .cell-input {
  font-size: 1.1rem;
  padding: 6px 8px;
  min-width: 80px;
  font-weight: 600;
}
.v2-grid td.product-cell {
  cursor: pointer;
}
.v2-grid td.product-cell:hover {
  color: var(--accent-blue);
  text-decoration: underline;
}

/* ---- 数値セル右寄せ ---- */
.v2-grid td.num {
  text-align: right;
  color: var(--text-primary);
}

/* ---- グランドトータル ---- */
.v2-grid td.grand-total {
  font-weight: 800;
  color: #60a5fa;
  text-align: right;
  font-size: 0.92rem;
}

/* ---- 仕入れ・粗利列（常時表示） ---- */

.v2-grid td.cost-total,
.v2-grid td.profit-value {
  text-align: right;
  font-weight: 600;
}

/* ---- 仕入れサブ行 ---- */
.row-cost {
  background: rgba(251, 146, 60, 0.08);
  border-left: 3px solid #fb923c;
}
.v2-grid tbody tr.row-cost td {
  font-size: 0.82rem;
  color: #fb923c;
}
.row-cost .cost-label {
  color: #fb923c;
  font-weight: 600;
  font-size: 0.82rem;
}
.row-cost:hover {
  background: rgba(251, 146, 60, 0.16);
}
/* 仕入れサブ行のデフォルト非表示 — showCostトグルで制御 */
.row-cost {
  display: none;
}
[data-show-cost] .row-cost {
  display: table-row;
}
[data-show-cost] .month-stat-sep.cost-col {
  display: inline;
}
.v2-grid td.cost-total {
  color: var(--accent-orange);
  font-weight: 600;
  text-align: right;
}
.profit-value {
  color: var(--accent-green) !important;
  font-weight: 600;
}
.v2-btn.active {
  background: var(--accent-blue);
  color: #fff;
  border-color: var(--accent-blue);
}

/* ---- 月別ヘッダー行 ---- */
.row-month-header {
  cursor: pointer;
  user-select: none;
}
.row-month-header td {
  padding: 0 !important;
  border-bottom: none !important;
  background: color-mix(
    in srgb,
    var(--month-color, #6b7280) 20%,
    var(--bg-secondary)
  ) !important;
}
.month-header-content {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  border-left: 5px solid var(--month-color, #6b7280);
}
.month-arrow {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.7);
  transition: transform 0.2s;
}
.month-label {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--month-color, var(--text-primary));
}
.month-count {
  font-size: 0.78rem;
  color: rgba(255, 255, 255, 0.8);
  background: rgba(0, 0, 0, 0.25);
  padding: 2px 8px;
  border-radius: 10px;
}
.month-stats {
  margin-left: auto;
  font-size: 0.82rem;
  color: rgba(255, 255, 255, 0.75);
  display: flex;
  align-items: center;
  gap: 8px;
}
.month-stats strong {
  color: rgba(255, 255, 255, 0.95);
}
.month-stat-sep {
  color: rgba(255, 255, 255, 0.3);
  opacity: 0.6;
}
.row-month-header:hover td {
  background: color-mix(
    in srgb,
    var(--month-color, #6b7280) 30%,
    var(--bg-secondary)
  ) !important;
}

/* ---- 月別サマリー行 ---- */
.row-month-summary td {
  padding: 10px 8px !important;
  border-top: 1px dashed rgba(255, 255, 255, 0.15);
  border-bottom: 1px solid var(--border-subtle) !important;
  background: rgba(255, 255, 255, 0.02) !important;
}
.month-summary-label {
  text-align: right !important;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--text-secondary);
  padding-right: 16px !important;
}
.month-summary-value {
  font-weight: 700;
  font-size: 0.9rem;
  color: rgba(255, 255, 255, 0.85);
}

/* ---- 入金ステータスバッジ ---- */
.v2-payment-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 500;
  cursor: pointer;
}
.v2-payment-badge.unpaid {
  background: rgba(239, 68, 68, 0.25);
  color: #fca5a5;
  font-weight: 600;
}
.v2-payment-badge.partial {
  background: rgba(245, 158, 11, 0.25);
  color: #fcd34d;
  font-weight: 600;
}
.v2-payment-badge.paid {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
  font-weight: 600;
}

/* ---- 備考バッジ ---- */
.v2-memo-badge {
  display: inline-block;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 0.72rem;
  background: rgba(56, 189, 248, 0.15);
  color: #7dd3fc;
  margin-right: 4px;
}

/* ---- 操作ボタン ---- */
.v2-row-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}
.v2-row-actions .v2-btn {
  padding: 2px 8px;
  font-size: 0.72rem;
}

/* ---- [I-009] 入金列レイアウト（アイコン＋バッジ横並び） ---- */
.v2-payment-cell {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
}

/* ---- [I-009] 発行済みドキュメントアイコン ---- */
.v2-doc-icon {
  font-size: 0.85rem;
  cursor: pointer;
  opacity: 0.8;
  transition:
    opacity 0.15s,
    transform 0.15s;
  line-height: 1;
}
.v2-doc-icon:hover {
  opacity: 1;
  transform: scale(1.15);
}
.v2-doc-invoice {
  filter: drop-shadow(0 0 2px rgba(96, 165, 250, 0.5));
}
.v2-doc-delivery {
  filter: drop-shadow(0 0 2px rgba(167, 139, 250, 0.5));
}

/* ---- [I-009] 📋発行ボタン ---- */
.v2-btn-invoice {
  color: #93c5fd !important;
  transition:
    color 0.15s,
    background 0.15s;
}
.v2-btn-invoice:hover {
  color: #60a5fa !important;
  background: rgba(96, 165, 250, 0.12);
}

/* ---- [I-009] モーダルフッター 請求書/納品書ボタン ---- */
.tx-invoice-buttons {
  display: flex;
  gap: 6px;
  margin-right: auto;
}
.tx-btn-invoice,
.tx-btn-delivery {
  font-size: 0.78rem !important;
  padding: 4px 10px !important;
  transition: opacity 0.15s;
}
.tx-btn-invoice:disabled,
.tx-btn-delivery:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
.tx-btn-invoice:not(:disabled):hover {
  background: rgba(96, 165, 250, 0.1);
  border-color: #60a5fa;
  color: #93c5fd;
}
.tx-btn-delivery:not(:disabled):hover {
  background: rgba(167, 139, 250, 0.1);
  border-color: #a78bfa;
  color: #c4b5fd;
}

/* ---- 詳細パネル（アコーディオン展開行） ---- */
.v2-detail-row td {
  padding: 0 !important;
  border-bottom: 2px solid var(--border-subtle);
}
.v2-detail-panel {
  padding: 12px 24px 12px 68px;
  background: var(--bg-secondary);
  border-top: 1px dashed var(--border-subtle);
}
.v2-detail-panel .detail-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}
.v2-detail-panel .detail-item label {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: block;
}
.v2-detail-panel .detail-item .detail-value {
  font-size: 0.88rem;
  color: var(--text-primary);
  font-weight: 500;
}
.v2-detail-panel .detail-item .detail-value.profit {
  color: var(--accent-green);
}
.v2-detail-panel .detail-item .detail-value.cost {
  color: var(--accent-orange);
}

/* ---- 新規行追加エリア ---- */
.v2-add-row {
  padding: 12px 24px;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-secondary);
}

/* ========== 商品選択モーダル ========== */
.v2-modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg-modal);
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
}
/* 商品選択ポップアップはtx-modalの上に表示 */
#product-modal.open {
  z-index: 1200;
}
.v2-modal-overlay.open {
  display: flex;
}

.v2-modal {
  background: var(--bg-card);
  border-radius: 12px;
  box-shadow: var(--shadow-lg);
  width: min(560px, 90vw);
  max-height: 80vh;
  overflow-y: auto;
}
.v2-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
}
.v2-modal-header h3 {
  margin: 0;
  font-size: 1.05rem;
  color: var(--text-primary);
}
.v2-modal-close {
  background: none;
  border: none;
  font-size: 1.2rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
}
.v2-modal-close:hover {
  color: var(--accent-red);
}
.v2-modal-body {
  padding: 20px;
}

/* ---- カテゴリグリッド ---- */
.v2-category-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.v2-category-card {
  padding: 16px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 10px;
  background: var(--bg-secondary);
  cursor: pointer;
  text-align: center;
  transition: all 0.2s;
  font-size: 0.9rem;
  color: var(--text-primary);
}
.v2-category-card:hover {
  border-color: var(--accent-blue);
  background: rgba(79, 124, 255, 0.06);
  transform: translateY(-1px);
}
.v2-category-card .cat-icon {
  font-size: 1.6rem;
  display: block;
  margin-bottom: 6px;
}
.v2-category-card .cat-count {
  font-size: 0.72rem;
  color: var(--text-muted);
}

/* ---- 商品リスト ---- */
.v2-product-list-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}
.v2-product-items {
  display: grid;
  gap: 6px;
  max-height: 400px;
  overflow-y: auto;
}
.v2-product-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}
.v2-product-item:hover {
  border-color: var(--accent-blue);
  background: rgba(79, 124, 255, 0.06);
}
.v2-product-item .product-name {
  font-size: 0.88rem;
  color: var(--text-primary);
}
.v2-product-item .product-code {
  font-size: 0.72rem;
  color: var(--text-muted);
}
.v2-product-item .product-price {
  font-size: 0.85rem;
  color: var(--accent-blue);
  font-weight: 500;
}

/* ---- 自由入力 ---- */
.v2-free-fields {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 10px;
  margin: 12px 0;
}
.v2-free-fields label {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}
.v2-free-fields input {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.88rem;
}

/* ========== 入金モーダル ========== */
.v2-payment-info {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}
.v2-payment-info .info-item {
  text-align: center;
  padding: 10px;
  border-radius: 8px;
  background: var(--bg-secondary);
}
.v2-payment-info .info-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  display: block;
}
.v2-payment-info .info-value {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-primary);
}
.v2-payment-info .info-value.paid-color {
  color: var(--accent-green);
}
.v2-payment-info .info-value.remaining-color {
  color: var(--accent-red);
}

.v2-payment-form {
  display: flex;
  gap: 8px;
  align-items: end;
  margin-bottom: 16px;
}
.v2-payment-form label {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}
.v2-payment-form input {
  padding: 8px;
  border: 1px solid var(--border-subtle);
  border-radius: 6px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.88rem;
}

.v2-payment-history h4 {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}
.v2-payment-history-list {
  font-size: 0.82rem;
}
.v2-payment-history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border-subtle);
}

/* ========== トースト ========== */
.v2-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 12px 24px;
  border-radius: 8px;
  background: var(--accent-blue);
  color: #fff;
  font-size: 0.9rem;
  opacity: 0;
  transform: translateY(20px);
  transition: all 0.3s;
  z-index: 9999;
  pointer-events: none;
}
.v2-toast.show {
  opacity: 1;
  transform: translateY(0);
}
.v2-toast.error {
  background: var(--accent-red);
}
.v2-toast.success {
  background: var(--accent-green);
}

/* ========== 取引先ドロップダウン ========== */
.v2-partner-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border: 1px solid var(--accent-blue);
  border-radius: 0 0 6px 6px;
  box-shadow: var(--shadow-md);
  z-index: 50;
  max-height: 200px;
  overflow-y: auto;
}
.v2-partner-dropdown.open {
  display: block;
}
.v2-partner-option {
  padding: 6px 10px;
  cursor: pointer;
  font-size: 0.82rem;
  color: var(--text-primary);
  transition: background 0.1s;
}
.v2-partner-option:hover {
  background: rgba(79, 124, 255, 0.1);
}
.v2-partner-option.active {
  background: rgba(79, 124, 255, 0.2);
  color: var(--accent-blue);
}

/* ---- 取引先検索ボタン ---- */
.partner-cell {
  position: relative;
}
.v2-partner-search-btn {
  display: none;
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--text-muted);
  padding: 2px 4px;
  border-radius: 3px;
  transition:
    color 0.15s,
    background 0.15s;
  z-index: 5;
}
.partner-cell:hover .v2-partner-search-btn,
.partner-cell.editing .v2-partner-search-btn {
  display: inline-block;
}
.v2-partner-search-btn:hover {
  color: var(--accent-blue);
  background: rgba(79, 124, 255, 0.1);
}

/* ---- 新規取引先追加ボタン ---- */
.v2-partner-add-new {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--accent-blue);
  border-top: 1px solid var(--border-subtle);
  font-weight: 600;
  transition: background 0.1s;
}
.v2-partner-add-new:hover {
  background: rgba(79, 124, 255, 0.1);
}

/* ========== 取引先フィルタバナー ========== */
.v2-filter-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 24px;
  background: var(--bg-secondary, #1a1a2e);
  background-image: linear-gradient(
    135deg,
    rgba(79, 124, 255, 0.25),
    rgba(139, 92, 246, 0.2)
  );
  border-bottom: 2px solid var(--accent-blue);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
  font-size: 0.9rem;
  color: var(--text-primary);
  animation: filterBannerSlideIn 0.3s ease;
  position: sticky;
  top: 120px; /* ヘッダー(49px) + ツールバー(41px) + 月ナビ(30px) */
  z-index: 98;
}
@keyframes filterBannerSlideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
.filter-banner-icon {
  font-size: 1.1rem;
}
.filter-banner-text {
  flex: 1;
}
.filter-banner-text strong {
  color: var(--accent-blue);
}
.filter-banner-clear-main {
  font-size: 0.9rem !important;
  padding: 6px 16px !important;
  font-weight: 600;
  letter-spacing: 0.02em;
  animation: filterBtnPulse 2s ease-in-out infinite;
}
@keyframes filterBtnPulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(79, 124, 255, 0.4);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(79, 124, 255, 0);
  }
}

/* ============================================================
   取引モーダル（新規登録/編集共通）
   ============================================================ */

.v2-tx-modal {
  width: 92%;
  max-width: 1100px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  z-index: 1100;
}

/* ---- ヘッダー ---- */
.tx-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border-color);
  background: var(--bg-card);
}
.tx-modal-header h3 {
  margin: 0;
  font-size: 1.15rem;
}
.tx-modal-header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}
.tx-modal-grand-total {
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: 0.03em;
}

/* ---- ボディ ---- */
.tx-modal-body {
  overflow-y: auto;
  padding: 16px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

/* ---- セクション共通 ---- */
.tx-section {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 14px 16px;
}
.tx-section-label {
  font-size: 0.8rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 10px;
}

/* ---- セクション1: 取引情報 ---- */
.tx-info-row {
  display: flex;
  gap: 12px;
}
.tx-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.tx-field label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}
.tx-field input,
.tx-field select {
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.2s;
}
.tx-field input:focus,
.tx-field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}
.tx-field-grow {
  flex: 1;
}
.tx-partner-wrap {
  position: relative;
}
.tx-partner-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  z-index: 100;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 0 0 6px 6px;
  max-height: 200px;
  overflow-y: auto;
  display: none;
}
.tx-partner-dropdown.open {
  display: block;
}
.tx-partner-dropdown .tx-partner-opt {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 0.85rem;
}
.tx-partner-dropdown .tx-partner-opt:hover {
  background: var(--bg-card-hover);
}

/* ---- セクション2: 商品明細テーブル ---- */
.tx-items-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.85rem;
}
.tx-items-table th {
  background: var(--bg-card);
  padding: 6px 8px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.75rem;
  border-bottom: 2px solid var(--border-color);
}
.tx-items-table td {
  padding: 6px 8px;
  border-bottom: 1px solid var(--border-color);
  vertical-align: middle;
}
.tx-items-table input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.85rem;
  outline: none;
  transition: border-color 0.2s;
}
.tx-items-table input:focus {
  border-color: var(--accent);
}
.tx-items-table input[type="number"] {
  text-align: right;
}
.tx-col-name {
  width: 30%;
}
.tx-col-qty {
  width: 8%;
}
.tx-col-price {
  width: 13%;
}
.tx-col-subtotal {
  width: 14%;
}
.tx-col-tax {
  width: 12%;
}
.tx-col-total {
  width: 14%;
}
.tx-col-del {
  width: 36px;
  text-align: center;
}

.tx-item-calc {
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
}

.tx-item-del {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  padding: 4px;
  border-radius: 4px;
  transition:
    color 0.15s,
    background 0.15s;
}
.tx-item-del:hover {
  color: #ef4444;
  background: rgba(239, 68, 68, 0.1);
}

.tx-item-shipping td:first-child {
  color: #6ee7b7;
  font-weight: 600;
}

/* 商品名セル内のカテゴリ選択ボタン */
.tx-name-wrap {
  display: flex;
  gap: 4px;
  align-items: center;
}
.tx-name-wrap input {
  flex: 1;
}
.tx-btn-pick-product {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  color: var(--accent);
  cursor: pointer;
  padding: 4px 6px;
  font-size: 0.75rem;
  white-space: nowrap;
  transition: background 0.15s;
}
.tx-btn-pick-product:hover {
  background: rgba(59, 130, 246, 0.1);
}

.tx-add-buttons {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.tx-btn-add-item {
  font-size: 0.8rem !important;
  padding: 6px 14px !important;
  border-radius: 20px !important;
}
.v2-btn-outline {
  background: transparent;
  border: 1px dashed var(--accent);
  color: var(--accent);
}
.v2-btn-outline:hover {
  background: rgba(59, 130, 246, 0.08);
}
.tx-btn-shipping {
  border-color: #6ee7b7 !important;
  color: #6ee7b7 !important;
}
.tx-btn-shipping:hover {
  background: rgba(110, 231, 183, 0.08) !important;
}

/* ---- セクション3: 仕入れ値 ---- */
.tx-section-cost {
  border-color: rgba(245, 158, 11, 0.3);
}
.tx-label-cost {
  color: #f59e0b !important;
}
.tx-cost-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.tx-cost-table th {
  padding: 4px 8px;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: 0.72rem;
  border-bottom: 1px solid var(--border-color);
}
.tx-cost-table td {
  padding: 4px 8px;
  border-bottom: 1px solid var(--border-color);
}
.tx-cost-table input {
  width: 100%;
  padding: 4px 6px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.82rem;
  text-align: right;
  outline: none;
}
.tx-cost-table input:focus {
  border-color: #f59e0b;
}
.tx-cost-summary {
  display: flex;
  gap: 20px;
  margin-top: 8px;
  font-size: 0.85rem;
}
.tx-cost-summary strong {
  color: #f59e0b;
  font-weight: 800;
}

/* ---- セクション4: 入金情報 ---- */
.tx-section-payment {
  border-color: rgba(20, 184, 166, 0.3);
}
.tx-label-payment {
  color: #14b8a6 !important;
}
.tx-payment-row {
  display: flex;
  gap: 12px;
}
.tx-payment-row .tx-field {
  flex: 1;
}
.tx-yen-input {
  display: flex;
  align-items: center;
  gap: 4px;
}
.tx-yen-input span {
  color: var(--text-muted);
  font-weight: 600;
}
.tx-yen-input input {
  flex: 1;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
}
.tx-yen-input input:focus {
  border-color: #14b8a6;
  box-shadow: 0 0 0 2px rgba(20, 184, 166, 0.15);
}
.tx-payment-note {
  color: var(--text-muted);
  font-size: 0.72rem;
  margin: 6px 0 0;
  opacity: 0.8;
}

/* ---- フッター ---- */
.tx-modal-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-card);
}
.tx-footer-summary {
  display: flex;
  gap: 16px;
  font-size: 0.85rem;
  align-items: center;
}
.tx-footer-summary strong {
  font-weight: 800;
}
.tx-footer-grand strong {
  font-size: 1.15rem;
  color: var(--accent);
}
.tx-footer-sep {
  color: var(--border-color);
  font-size: 0.9rem;
}
.tx-footer-cost strong {
  color: #f59e0b;
}
.tx-footer-profit strong {
  color: #10b981;
}
.tx-footer-buttons {
  display: flex;
  gap: 10px;
}
.tx-btn-submit {
  padding: 10px 28px !important;
  font-size: 0.95rem !important;
  font-weight: 700 !important;
  border-radius: 8px !important;
  background: linear-gradient(135deg, #3b82f6, #2563eb) !important;
}
.tx-btn-submit:hover {
  background: linear-gradient(135deg, #60a5fa, #3b82f6) !important;
}

/* ============================================================
   取引先検索ポップアップ (M-5)
   ============================================================ */
#partner-search-modal.open {
  z-index: 1300;
}
.v2-partner-search-modal {
  width: min(520px, 92vw);
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.ps-search-box {
  margin-bottom: 14px;
}
.ps-search-box input {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: border-color 0.2s;
}
.ps-search-box input:focus {
  border-color: var(--accent-blue);
  outline: none;
}
.ps-partner-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  max-height: 50vh;
  overflow-y: auto;
  padding: 2px;
  margin-bottom: 14px;
}
.ps-partner-card {
  padding: 10px 12px;
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
  background: var(--bg-card);
  color: var(--text-primary);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  transition: all 0.15s;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ps-partner-card:hover {
  background: var(--accent-blue);
  color: #fff;
  border-color: var(--accent-blue);
  transform: translateY(-1px);
  box-shadow: 0 3px 8px rgba(59, 130, 246, 0.3);
}
.ps-partner-card.ps-match {
  border-color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.1);
}
.ps-new-partner-btn {
  width: 100%;
  padding: 10px !important;
  font-size: 0.9rem !important;
  border-radius: 8px !important;
}
