*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', sans-serif;
  background: #f4f6f9;
  color: #333;
  min-height: 100vh;
}

/* ─── ページラッパ ────────────────────────────────────────────────────────── */
.page { padding: 24px; max-width: 1200px; margin: 0 auto; }
#view-list .page { max-width: 1600px; }

/* ─── ツールバー ──────────────────────────────────────────────────────────── */
.toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.toolbar-left { display: flex; align-items: center; gap: 12px; }
.toolbar-right { display: flex; align-items: center; gap: 8px; }
.toolbar h1 { font-size: 1.3rem; font-weight: 700; color: #232f3e; }
.count-badge {
  background: #e2e8f0; color: #555;
  padding: 2px 10px; border-radius: 10px;
  font-size: 0.8rem; font-weight: 600;
}

/* ─── フィルターバー ──────────────────────────────────────────────────────── */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  background: #fff; padding: 14px 16px;
  border-radius: 8px; margin-bottom: 16px;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}
.filter-item { display: flex; flex-direction: column; gap: 4px; }
.filter-item label { font-size: 0.75rem; font-weight: 600; color: #666; }
.filter-item input,
.filter-item select {
  padding: 5px 10px; border: 1px solid #ccc; border-radius: 5px;
  font-size: 0.85rem; min-width: 130px;
}

/* ─── 月セレクタ ──────────────────────────────────────────────────────────── */
.month-selector { display: flex; align-items: center; gap: 6px; }
.btn-month {
  padding: 6px 12px; border: 1px solid #cbd5e0; background: #fff;
  border-radius: 4px; cursor: pointer; font-size: 13px; color: #4a5568;
}
.btn-month:hover { background: #f7fafc; border-color: #a0aec0; }

/* ─── 期間タブ（一覧ビュー filter-bar 内） ────────────────────────────────── */
.period-tab-bar {
  display: inline-flex; gap: 0;
  border: 1px solid #e2e8f0; border-radius: 6px; overflow: hidden;
  background: #fff;
}
.period-tab-btn {
  padding: 6px 12px; background: transparent; border: none;
  font-size: 0.88rem; font-weight: 500; color: #718096;
  cursor: pointer; transition: color 0.15s, background 0.15s;
}
.period-tab-btn:hover:not(.active) { background: #f8f9fa; color: #232f3e; }
.period-tab-btn.active { background: #ff9900; color: #fff; }
.period-range-label { margin-left: 10px; font-size: 0.82rem; color: #718096; }

.period-date-input {
  padding: 6px 8px; border: 1px solid #cbd5e0; border-radius: 4px;
  font-size: 0.85rem; color: #2d3748; background: #fff;
  font-family: inherit;
}
.period-date-input:focus { outline: none; border-color: #ff9900; box-shadow: 0 0 0 2px rgba(255,153,0,0.15); }
.period-date-sep { margin: 0 4px; color: #94a3b8; font-size: 0.85rem; }

/* ─── ソート可能テーブル ───────────────────────────────────────────────── */
table.sortable thead th[data-sort-key] {
  cursor: pointer; user-select: none; position: relative;
}
table.sortable thead th[data-sort-key]:hover { background: #edf2f7; }
table.sortable thead th[data-sort-key].sort-asc::after  { content: ' ▲'; font-size: 0.75em; color: #ff9900; }
table.sortable thead th[data-sort-key].sort-desc::after { content: ' ▼'; font-size: 0.75em; color: #ff9900; }

/* ─── モールタブ ──────────────────────────────────────────────────────────── */
.mall-tab-bar {
  display: flex; gap: 4px; margin-bottom: 16px;
  border-bottom: 1px solid #e2e8f0;
}
.mall-tab-btn {
  padding: 10px 20px; background: transparent; border: none;
  border-bottom: 3px solid transparent; margin-bottom: -2px;
  font-size: 0.92rem; font-weight: 600; color: #718096;
  cursor: pointer; transition: color 0.15s, border-color 0.15s;
}
.mall-tab-btn:hover:not(:disabled) { color: #232f3e; background: #f8f9fa; }
.mall-tab-btn.active {
  color: #232f3e; border-bottom-color: #ff9900;
}
.mall-tab-btn:disabled {
  color: #cbd5e0; cursor: not-allowed;
}

/* 広告効果タブの Amazon 行：キャンペーン名の下に素の商品名を薄く副表示 */
.ad-subname {
  font-size: 11px; color: #a0aec0; margin-top: 2px;
  max-width: 560px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

/* ─── 広告サマリーカード ─────────────────────────────────────────────────── */
.ad-summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
/* 一覧ビューはカード数が増減するので auto-fit で詰める。最低 110px は確保。 */
#view-list .ad-summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
}
#view-list .ad-summary-card { padding: 8px 10px; }
#view-list .ad-summary-card .label { font-size: 10px; }
#view-list .ad-summary-card .value { font-size: 14px; }
.ad-summary-card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 8px;
  padding: 10px 12px; text-align: center;
}
.ad-summary-card .label { font-size: 11px; color: #718096; margin-bottom: 4px; }
.ad-summary-card .value { font-size: 16px; font-weight: 700; color: #2d3748; }

/* ─── テーブル ───────────────────────────────────────────────────────────── */
.table-wrap {
  background: #fff; border-radius: 10px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.08);
  overflow-x: auto;
  cursor: grab;
}
.table-wrap.dragging { cursor: grabbing; user-select: none; }
.table-wrap.dragging a { pointer-events: none; }
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 0.88rem; }
thead th {
  background: #f8f9fa; padding: 10px 14px;
  text-align: left; font-weight: 600; color: #555;
  border-bottom: 2px solid #e2e8f0;
  white-space: nowrap;
}
thead th.num { text-align: right; }
tbody td { padding: 10px 14px; border-bottom: 1px solid #f0f0f0; color: #333; background: #fff; }
tbody td.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover td { background: #fafafa; }
tbody tr:last-child td { border-bottom: none; }
.empty-msg { text-align: center; color: #aaa; padding: 36px !important; }

/* 一覧テーブル: thead を画面上端に貼り付け、左2列をスクロール時固定 */
/* table-wrap を縦スクロールコンテナにすることで thead の sticky を効かせる
   （overflow-x: auto だけだと祖先がスクロールコンテナにならず body スクロールに対して効かない） */
#view-list .table-wrap {
  max-height: calc(100vh - 200px);
  overflow: auto;
}
#ads-effect-table { min-width: max-content; }
#ads-effect-table thead th {
  position: sticky; top: 0; z-index: 3;
}
/* 左 2 列（コード／商品名）を固定。コード列幅を 120px に固定して 2 列目の left を計算 */
#ads-effect-table th.col-code,
#ads-effect-table td.item-code-cell {
  width: 120px; min-width: 120px; max-width: 120px;
}
#ads-effect-table th:nth-child(1),
#ads-effect-table td:nth-child(1) {
  position: sticky; left: 0; z-index: 2;
  background: #fff;
}
#ads-effect-table th:nth-child(2),
#ads-effect-table td:nth-child(2) {
  position: sticky; left: 120px; z-index: 2;
  background: #fff;
  box-shadow: 2px 0 4px rgba(0,0,0,0.06);
}
#ads-effect-table thead th:nth-child(1),
#ads-effect-table thead th:nth-child(2) { z-index: 4; background: #f8f9fa; }

.item-name-link {
  color: #3b82f6; text-decoration: none;
  display: inline-block;
  vertical-align: bottom;
  white-space: normal; word-break: break-word;
}
/* 一覧テーブル内の商品名列は折り返し表示（max-width で抑える） */
#ads-effect-table td.item-name-cell {
  white-space: normal; min-width: 220px; max-width: 360px;
  word-break: break-word;
}
#ads-effect-table .ad-subname {
  white-space: normal; max-width: 360px; font-size: 10px;
}
.item-name-link:hover { text-decoration: underline; }
/* コード列は Yahoo の長い商品コードでもセル幅が暴れないように省略表示 (title でフル参照可) */
.item-code-cell {
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* モール商品ページへの外部リンクアイコン（商品名の隣に小さく↗） */
.item-mall-link {
  display: inline-block;
  margin-left: 4px;
  color: #64748b;
  text-decoration: none;
  font-size: 11px;
  vertical-align: super;
}
.item-mall-link:hover { color: #3b82f6; }
.muted { color: #a0aec0; }

/* ─── ビュー切替 ──────────────────────────────────────────────────────────── */
.view.hidden { display: none; }
.hidden { display: none !important; }

/* ─── ボタン ──────────────────────────────────────────────────────────────── */
.btn {
  padding: 8px 16px; border-radius: 6px; border: none;
  font-size: 0.88rem; font-weight: 600; cursor: pointer;
  transition: background 0.2s;
}
.btn-primary   { background: #ff9900; color: #fff; }
.btn-primary:hover   { background: #e68a00; }
.btn-secondary { background: #fff; color: #555; border: 1px solid #ccc; }
.btn-secondary:hover { border-color: #888; }
.btn-danger    { background: #e53e3e; color: #fff; }
.btn-danger:hover    { background: #c53030; }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }

/* ─── フォーム（モーダル共用） ────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 0.8rem; font-weight: 600; color: #555; }
.field.required label::after { content: ' *'; color: #e53e3e; }
.field input,
.field select,
.field textarea {
  padding: 8px 10px; border: 1px solid #ccc; border-radius: 6px;
  font-size: 0.9rem; color: #333; font-family: inherit;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none; border-color: #ff9900;
  box-shadow: 0 0 0 2px rgba(255,153,0,0.2);
}
.field-row { display: flex; gap: 12px; flex-wrap: wrap; }
.field-row .field { flex: 1 1 140px; }
.required { color: #e53e3e; font-weight: 700; }

/* ─── 粗利カラー ──────────────────────────────────────────────────────────── */
.gross-amount.gross-positive { color: #2f855a; }
.gross-amount.gross-negative { color: #c53030; }
.gross-amount.muted          { color: #a0aec0; }

/* ─── 商品詳細ビュー ──────────────────────────────────────────────────────── */
#view-product { padding: 16px; }

.product-header { margin-bottom: 16px; }
.breadcrumb-back {
  display: inline-block; margin-bottom: 8px;
  color: #3b82f6; text-decoration: none; font-size: 14px;
}
.breadcrumb-back:hover { text-decoration: underline; }
.product-info-card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 8px;
  padding: 12px 16px;
}
.product-name-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.product-name { font-size: 18px; font-weight: 700; color: #1a202c; }
.product-meta { display: flex; gap: 16px; font-size: 12px; color: #718096; }
.product-meta b { color: #2d3748; }

.product-toolbar {
  display: flex; align-items: flex-start; gap: 12px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.product-mall-select { padding: 6px 8px; border: 1px solid #cbd5e0; border-radius: 6px; font-size: 14px; }

/* 期間ピッカー（A / B 共通） */
.range-picker {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px;
  padding: 6px 10px; border: 1px solid #e2e8f0; border-radius: 8px; background: #f9fafb;
}
.range-picker[data-range="B"] { background: #eff6ff; border-color: #bfdbfe; }
.range-label { font-size: 12px; font-weight: 700; color: #4a5568; padding: 0 4px; }
.range-picker[data-range="B"] .range-label { color: #1d4ed8; }
.range-sep { color: #718096; font-size: 12px; }
.range-picker input[type="date"] {
  padding: 4px 6px; border: 1px solid #cbd5e0; border-radius: 6px;
  font-size: 13px; background: #fff;
}
.range-presets { display: flex; gap: 4px; margin-left: 4px; flex-wrap: wrap; }
.btn-preset {
  padding: 3px 8px; border: 1px solid #cbd5e0; background: #fff; border-radius: 4px;
  cursor: pointer; font-size: 11px; color: #4a5568;
}
.btn-preset:hover { background: #edf2f7; border-color: #a0aec0; }
.compare-toggle {
  display: flex; align-items: center; gap: 4px; padding: 8px 10px;
  font-size: 13px; color: #2d3748;
}
.compare-toggle input[type="checkbox"] { margin: 0 4px 0 0; }
.compare-hidden { display: none !important; }

/* サマリーカードの比較表示 */
.ad-summary-card.has-compare { display: flex; flex-direction: column; gap: 2px; }
.ad-summary-card.has-compare .ad-card-value { font-size: 15px; }
.ad-summary-card .ad-card-value-b { font-size: 13px; font-weight: 600; color: #4a5568; }
.ad-summary-card .value-b { font-size: 12px; font-weight: 600; color: #4a5568; text-align: center; }
.ad-summary-card .cmp-divider {
  font-size: 10px; color: #94a3b8; text-align: center; line-height: 1;
  margin: 1px 0; letter-spacing: 1px;
}
.ad-summary-card .cmp-delta {
  font-size: 12px; font-weight: 700; margin-top: 2px; text-align: center;
}
/* 一覧ビューは 10 枚 1 行に詰めているため比較時はさらに圧縮 */
#view-list .ad-summary-card.has-compare .value   { font-size: 13px; }
#view-list .ad-summary-card.has-compare .value-b { font-size: 11px; }
#view-list .ad-summary-card.has-compare .cmp-delta { font-size: 10px; }
.cmp-up   { color: #16a34a; }
.cmp-down { color: #dc2626; }
.cmp-flat { color: #718096; }

/* 一覧テーブルのセル内 B 値（薄字）と Δ バッジ（実数差 + (% 差)） */
#ads-effect-table td.num .cell-prev {
  display: block; font-size: 10px; line-height: 1.1;
  margin-top: 2px; color: #94a3b8; white-space: nowrap;
}
#ads-effect-table td.num .cell-delta {
  display: block; font-size: 10px; line-height: 1.1;
  margin-top: 1px; font-weight: 700; white-space: nowrap;
}

/* 折れ線凡例（実線/破線） */
.legend-line-solid, .legend-line-dashed {
  display: inline-block; width: 18px; height: 0; margin-right: 4px;
  border-top: 2px solid #4a5568; vertical-align: middle;
}
.legend-line-dashed { border-top-style: dashed; }

.mall-tab-btn .tab-sales {
  display: inline-block; margin-left: 6px; font-size: 0.78rem;
  color: #a0aec0; font-weight: 500;
}
.mall-tab-btn.active .tab-sales { color: #718096; }

/* 商品詳細の ad-summary-grid（指標ごとに可変幅） */
#view-product .ad-summary-grid {
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
}
.ad-summary-card.muted-card { background: #f7fafc; }
.ad-card-label { font-size: 11px; color: #718096; margin-bottom: 4px; }
.ad-card-value { font-size: 16px; font-weight: 700; color: #2d3748; }

.product-chart-card, .product-matrix-card, .product-notes-card, .product-ads-card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 8px;
  padding: 12px 16px; margin-bottom: 16px;
}
.ads-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 12px; flex-wrap: wrap; }
.ads-title   { font-size: 14px; font-weight: 600; color: #2d3748; }
.ads-note    { font-size: 11px; color: #a0aec0; font-weight: 400; margin-left: 6px; }
.ads-table-wrap { overflow-x: auto; }
.ads-table   { width: 100%; border-collapse: collapse; font-size: 12px; }
.ads-table th, .ads-table td {
  border-bottom: 1px solid #edf2f7; padding: 6px 8px; white-space: nowrap;
}
.ads-table thead th { background: #f7fafc; color: #4a5568; font-weight: 600; }
.ads-table td.num, .ads-table th.num {
  text-align: right; font-variant-numeric: tabular-nums;
}
.ads-table tr:hover { background: #f7fafc; }
.ads-table .empty-msg { text-align: center; color: #a0aec0; padding: 16px; }

.chart-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.chart-title { font-size: 14px; font-weight: 600; color: #2d3748; }
.series-legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 12px; color: #4a5568; }
.legend-item { display: inline-flex; align-items: center; gap: 4px; }
.legend-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; }

.line-chart { width: 100%; }
.line-chart-svg { width: 100%; height: auto; max-height: 320px; display: block; }

.matrix-title { font-size: 14px; font-weight: 600; color: #2d3748; margin-bottom: 8px; }
.estimated-note { font-size: 11px; color: #a0aec0; font-weight: 400; margin-left: 8px; }
.matrix-table-wrap { overflow-x: auto; }
.matrix-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.matrix-table th, .matrix-table td {
  border-bottom: 1px solid #edf2f7; padding: 6px 8px; white-space: nowrap;
}
.matrix-table thead th { background: #f7fafc; color: #4a5568; font-weight: 600; }
.matrix-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.matrix-table th.num { text-align: right; }
.matrix-table td.estimated { color: #a0aec0; }
.matrix-table td.ad-col      { color: #b45309; background: #fffbeb; }
.matrix-table td.organic-col { color: #0e7490; background: #ecfeff; }
.matrix-table .matrix-total { font-weight: 700; background: #edf2f7; }
.matrix-table .matrix-total td.ad-col      { background: #fef3c7; }
.matrix-table .matrix-total td.organic-col { background: #cffafe; }

/* ─── Amazon 広告ファミリーカード ─────────────────────────────────────────── */
.ad-family-card {
  background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 8px;
  padding: 12px 16px; margin-bottom: 12px;
}
.ad-family-card .fam-header { margin-bottom: 8px; position: relative; }
.ad-family-card .fam-title { font-size: 13px; font-weight: 700; color: #1e3a8a; }
.ad-family-card .fam-desc  { font-size: 11.5px; color: #1e40af; margin-top: 4px; line-height: 1.5; }
.ad-family-card .fam-list  { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.ad-family-card .fam-row {
  display: grid; grid-template-columns: 110px 1fr auto; gap: 10px;
  align-items: center; padding: 6px 10px; border-radius: 6px;
  background: #fff; border: 1px solid #dbeafe; font-size: 12px;
}
.ad-family-card .fam-row.self { background: #dbeafe; border-color: #93c5fd; font-weight: 600; }
.ad-family-card .fam-sku { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; color: #1d4ed8; text-decoration: none; }
.ad-family-card .fam-sku.self { color: #1e3a8a; }
.ad-family-card .fam-name { color: #334155; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-family-card .fam-stats { color: #64748b; font-variant-numeric: tabular-nums; font-size: 11px; }
.ad-family-card .fam-edit-btn {
  position: absolute; top: 0; right: 0;
  background: #fff; border: 1px solid #93c5fd; color: #1e40af;
  border-radius: 6px; padding: 3px 10px; font-size: 11.5px; cursor: pointer;
}
.ad-family-card .fam-edit-btn:hover { background: #dbeafe; }
.ad-family-card .fam-edit-list {
  list-style: none; margin: 0 0 8px 0; padding: 0;
  display: flex; flex-wrap: wrap; gap: 6px;
}
.ad-family-card .fam-edit-row {
  display: inline-flex; align-items: center; gap: 6px;
  background: #fff; border: 1px solid #93c5fd; border-radius: 16px;
  padding: 3px 6px 3px 12px; font-size: 12px;
}
.ad-family-card .fam-edit-empty { color: #64748b; font-size: 12px; padding: 6px 0; }
.ad-family-card .fam-remove-btn {
  border: none; background: #fee2e2; color: #b91c1c; border-radius: 50%;
  width: 20px; height: 20px; line-height: 18px; text-align: center;
  cursor: pointer; padding: 0; font-size: 13px; font-weight: 700;
}
.ad-family-card .fam-remove-btn:hover { background: #fca5a5; color: #fff; }
.ad-family-card .fam-edit-actions {
  display: flex; gap: 8px; margin-bottom: 8px;
}
.ad-family-card .fam-edit-input {
  flex: 1; padding: 6px 10px; border: 1px solid #bfdbfe; border-radius: 6px; font-size: 12px;
}
.ad-family-card .fam-add-btn {
  background: #2563eb; color: #fff; border: none; border-radius: 6px;
  padding: 6px 14px; font-size: 12px; cursor: pointer;
}
.ad-family-card .fam-add-btn:hover { background: #1d4ed8; }
.ad-family-card .fam-edit-footer {
  display: flex; justify-content: flex-end; gap: 8px;
}
.ad-family-card .fam-cancel-btn {
  background: #fff; border: 1px solid #cbd5e1; color: #475569;
  border-radius: 6px; padding: 6px 14px; font-size: 12px; cursor: pointer;
}
.ad-family-card .fam-cancel-btn:hover { background: #f1f5f9; }
.ad-family-card .fam-save-btn {
  background: #059669; color: #fff; border: none; border-radius: 6px;
  padding: 6px 16px; font-size: 12px; font-weight: 600; cursor: pointer;
}
.ad-family-card .fam-save-btn:hover { background: #047857; }

/* ─── 流入構成（広告 vs オーガニック） ───────────────────────────────────── */
.traffic-composition-card {
  background: #fff; border: 1px solid #e2e8f0; border-radius: 8px;
  padding: 12px 16px; margin-bottom: 16px;
}
.traffic-title { font-size: 14px; font-weight: 600; color: #2d3748; margin-bottom: 10px; }
.traffic-summary {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 12px;
}
.traffic-kpi {
  background: #f7fafc; border: 1px solid #e2e8f0; border-radius: 6px;
  padding: 8px 10px; text-align: center;
}
.tk-label { font-size: 11px; color: #718096; margin-bottom: 4px; }
.tk-value { font-size: 15px; font-weight: 700; }
.tk-value.ad      { color: #b45309; }
.tk-value.organic { color: #0e7490; }
.tk-sub { font-size: 11px; color: #718096; margin-top: 2px; }
.traffic-row {
  display: flex; align-items: center; gap: 12px; margin-top: 8px;
}
.traffic-label { width: 88px; font-size: 12px; color: #4a5568; font-weight: 600; flex-shrink: 0; }
.traffic-bar {
  flex: 1; display: flex; height: 28px; border-radius: 4px; overflow: hidden;
  background: #edf2f7; border: 1px solid #e2e8f0;
}
.traffic-seg {
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  font-size: 11px; font-weight: 600; color: #fff; white-space: nowrap;
}
.traffic-seg.ad      { background: #f59e0b; }
.traffic-seg.organic { background: #06b6d4; }
.traffic-composition-card .empty-msg {
  text-align: center; color: #a0aec0; padding: 16px; font-size: 13px;
}

/* ─── 施策メモ ────────────────────────────────────────────────────────────── */
.notes-tabs { display: flex; gap: 4px; border-bottom: 2px solid #e2e8f0; margin-bottom: 12px; }
.notes-tab {
  padding: 8px 12px; background: none; border: none; border-bottom: 2px solid transparent;
  margin-bottom: -2px; cursor: pointer; font-size: 13px; color: #718096;
}
.notes-tab.active { color: #3b82f6; border-bottom-color: #3b82f6; font-weight: 600; }
.notes-add-bar { margin-bottom: 12px; }
.notes-list { display: flex; flex-direction: column; gap: 8px; }
.note-card {
  background: #f7fafc; border: 1px solid #e2e8f0; border-radius: 6px;
  padding: 10px 12px; cursor: pointer;
}
.note-card[data-note-id]:hover { background: #edf2f7; }
.note-title { font-weight: 600; color: #2d3748; margin-bottom: 4px; }
.note-content { color: #4a5568; font-size: 13px; white-space: pre-wrap; }
.note-meta { margin-top: 6px; font-size: 11px; color: #a0aec0; display: flex; gap: 8px; flex-wrap: wrap; }
.note-meta .note-created { margin-left: auto; }
.action-status { padding: 1px 6px; border-radius: 4px; font-size: 10px; font-weight: 600; }
.action-status-open  { background: #feebc8; color: #7b341e; }
.action-status-doing { background: #bee3f8; color: #2a4365; }
.action-status-done  { background: #c6f6d5; color: #22543d; }

/* ─── モーダル ────────────────────────────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.4); }
.modal-body {
  position: relative; background: #fff; border-radius: 8px;
  padding: 20px; width: 90%; max-width: 500px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
}
.modal-title { font-size: 16px; font-weight: 700; margin-bottom: 16px; color: #2d3748; }
.modal-actions { display: flex; gap: 8px; margin-top: 16px; }
.modal-actions .btn-danger { margin-left: auto; }
.note-kind-only { transition: opacity 0.1s; }

/* ─── 表示設定モーダル ───────────────────────────────────────────────────── */
.view-config-body { max-width: 580px; width: 92%; }
.view-config-desc { font-size: 12px; color: #718096; margin-bottom: 12px; }
.view-config-section { margin-bottom: 14px; }
.view-config-heading {
  font-size: 13px; font-weight: 700; color: #2d3748;
  margin-bottom: 6px; padding-bottom: 4px; border-bottom: 1px solid #e2e8f0;
}
.view-config-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 4px;
  max-height: 260px; overflow-y: auto;
  border: 1px solid #edf2f7; border-radius: 6px; padding: 6px;
  background: #fafbfc;
}
.vc-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; background: #fff;
  border: 1px solid #e2e8f0; border-radius: 6px;
  cursor: grab; font-size: 13px; color: #2d3748;
}
.vc-item:hover { background: #f7fafc; }
.vc-item.vc-dragging { opacity: 0.45; cursor: grabbing; }
.vc-item.vc-drop-before { border-top: 2px solid #3b82f6; }
.vc-item.vc-drop-after  { border-bottom: 2px solid #3b82f6; }
.vc-item label {
  flex: 1; display: flex; align-items: center; gap: 6px;
  cursor: pointer; user-select: none;
}
.vc-item input[type="checkbox"] { margin: 0; }
.grip-mark {
  color: #cbd5e0; font-weight: 700; letter-spacing: -1px;
  cursor: grab; user-select: none;
}

/* ─── モバイル ────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  #view-product .ad-summary-grid { grid-template-columns: repeat(4, 1fr); }
  .traffic-summary { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .page { padding: 12px; }
  .table-wrap { max-height: 70vh; overflow: auto; -webkit-overflow-scrolling: touch; }
  .table-wrap thead th { position: sticky; top: 0; z-index: 2; background: #f7fafc; }
  .mall-tab-btn { padding: 8px 12px; font-size: 0.85rem; }
  #view-product .ad-summary-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ═══════════════════════════════════════════════════════════════════ */
/* 自動運用ビュー (#view-auto) — ROAS 主軸の推奨アクションカンバン        */
/* ═══════════════════════════════════════════════════════════════════ */
.badge-pending {
  display: inline-block;
  background: #e53e3e;
  color: #fff;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 0.75rem;
  font-weight: 700;
  margin-left: 4px;
}
.auto-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin: 12px 0 16px;
}
.auto-kpi-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 12px 16px;
}
.auto-kpi-card .kpi-label { color: #718096; font-size: 0.85rem; }
.auto-kpi-card .kpi-value { font-size: 1.5rem; font-weight: 700; color: #2d3748; margin-top: 4px; }
.auto-filter-bar { margin-bottom: 8px; }
.auto-mode-note { color: #718096; font-size: 0.85rem; }

.kanban-board {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 12px;
  align-items: start;
}
.kanban-col {
  background: #f7fafc;
  border-radius: 8px;
  padding: 8px;
  min-height: 200px;
}
.kanban-col-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 6px 8px;
  font-weight: 600;
  color: #2d3748;
}
.kanban-col-count {
  background: #cbd5e0;
  border-radius: 10px;
  padding: 1px 8px;
  font-size: 0.8rem;
}
.kanban-col[data-status="pending"]  .kanban-col-count { background: #fed7d7; color: #c53030; }
.kanban-col[data-status="approved"] .kanban-col-count { background: #fefcbf; color: #b7791f; }
.kanban-col[data-status="applied"]  .kanban-col-count { background: #c6f6d5; color: #2f855a; }
.kanban-col-body { display: flex; flex-direction: column; gap: 8px; }
.kanban-empty { padding: 16px; text-align: center; font-size: 0.85rem; }

.kanban-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-left: 4px solid #cbd5e0;
  border-radius: 6px;
  padding: 10px 12px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.kanban-card.status-pending  { border-left-color: #e53e3e; }
.kanban-card.status-approved { border-left-color: #d69e2e; }
.kanban-card.status-applied  { border-left-color: #38a169; }
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 0.78rem;
}
.mall-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
}
.mall-amazon  { background: #ff9900; color: #fff; }
.mall-rakuten { background: #bf0000; color: #fff; }
.mall-yahoo   { background: #ff0033; color: #fff; }
.mall-other   { background: #718096; color: #fff; }
.card-title {
  font-weight: 600;
  margin: 4px 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}
.card-skus { margin-bottom: 6px; }
.sku-chip {
  display: inline-block;
  background: #edf2f7;
  border-radius: 3px;
  padding: 1px 6px;
  font-size: 0.72rem;
  color: #4a5568;
  margin-right: 4px;
}
.sku-chip.more { background: #cbd5e0; }

.card-metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  background: #f7fafc;
  border-radius: 4px;
  padding: 6px 8px;
  margin-bottom: 6px;
}
.card-metrics .metric { text-align: center; }
.card-metrics .m-label { display: block; font-size: 0.7rem; color: #718096; }
.card-metrics .m-value { display: block; font-size: 0.95rem; font-weight: 600; }
.achievement-bad    { color: #e53e3e; }
.achievement-great  { color: #38a169; }
.achievement-normal { color: #2d3748; }
.achievement-na     { color: #a0aec0; }

.card-window { font-size: 0.72rem; margin-bottom: 6px; }
.card-action {
  background: #fffaf0;
  border: 1px dashed #f6ad55;
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 0.85rem;
  margin-bottom: 6px;
}
.card-action .action-label { color: #744210; font-weight: 600; margin-right: 6px; }
.card-action .action-value { color: #c05621; font-weight: 700; }
.card-impact { font-size: 0.75rem; margin-bottom: 8px; }
.card-actions { display: flex; gap: 4px; flex-wrap: wrap; }
.card-actions .btn { font-size: 0.75rem; padding: 4px 8px; }

/* ルール設定モーダル */
.auto-settings-block {
  background: #f7fafc;
  border-radius: 6px;
  padding: 12px;
  margin-bottom: 12px;
}
.auto-settings-block .block-title {
  font-weight: 600;
  margin-bottom: 8px;
  color: #2d3748;
}
.rules-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.rules-table th, .rules-table td {
  border-bottom: 1px solid #e2e8f0;
  padding: 6px 8px;
  text-align: left;
}
.rules-table th { background: #edf2f7; }

@media (max-width: 900px) {
  .kanban-board { grid-template-columns: 1fr; }
}

/* ═══════════════════════════════════════════════════════════════════ */
/* 自動運用 拡張: フィルタ・一括・詳細モーダル・ロックアウト              */
/* ═══════════════════════════════════════════════════════════════════ */
.lockout-banner {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #fff5f5;
  border: 2px solid #fc8181;
  border-radius: 6px;
  padding: 8px 12px;
  margin: 12px 0;
}
.lockout-banner.hidden { display: none; }
.lockout-icon { font-size: 1.5rem; }
.lockout-text { flex: 1; color: #c53030; font-weight: 600; }

.auto-filter-bar select,
.auto-filter-bar input[type="search"] {
  padding: 6px 10px;
  border: 1px solid #cbd5e0;
  border-radius: 4px;
  font-size: 0.9rem;
}

.auto-bulk-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  background: #edf2f7;
  border-radius: 6px;
  padding: 8px 12px;
  margin-bottom: 12px;
}
.auto-bulk-bar .bulk-check { display: flex; align-items: center; gap: 6px; font-weight: 600; }
.auto-bulk-bar .bulk-count { font-size: 0.85rem; }
.auto-bulk-bar .bulk-actions { display: flex; gap: 6px; }
.auto-bulk-bar .auto-mode-note { flex: 1; min-width: 240px; text-align: right; }

.card-header-left {
  display: flex;
  align-items: center;
  gap: 6px;
}
.card-select {
  width: 16px;
  height: 16px;
  cursor: pointer;
}
.override-badge {
  background: #805ad5;
  color: #fff;
  border-radius: 3px;
  padding: 1px 6px;
  font-size: 0.7rem;
  font-weight: 600;
}
.kanban-card { cursor: pointer; }
.kanban-card .console-link {
  margin-left: auto;
  text-decoration: none;
  background: #fff;
  color: #2b6cb0;
  border: 1px solid #bee3f8;
}
.kanban-card .console-link:hover { background: #ebf8ff; }

/* 詳細モーダル */
.detail-body { display: flex; flex-direction: column; gap: 16px; }
.detail-section { background: #f7fafc; border-radius: 6px; padding: 12px; }
.detail-section .block-title { font-weight: 600; margin-bottom: 6px; color: #2d3748; }
.detail-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.detail-table td, .detail-table th {
  padding: 4px 8px;
  border-bottom: 1px solid #e2e8f0;
  text-align: left;
}
.detail-table td:first-child { color: #718096; width: 40%; }
.detail-skus { display: flex; flex-wrap: wrap; gap: 4px; }
.log-mode {
  padding: 1px 6px;
  border-radius: 3px;
  font-size: 0.75rem;
  font-weight: 600;
}
.mode-live          { background: #c6f6d5; color: #2f855a; }
.mode-dry_run       { background: #fefcbf; color: #b7791f; }
.mode-manual_marked { background: #bee3f8; color: #2c5282; }
