/* ToT 共通の土台スタイル。サイト共通の /css/common.css の後に読み込む。
   白基調・主操作は青・成功は緑・エラーは赤＋文字。common.css に合わせてダークモードにも対応。 */
:root {
  --tot-surface: #f6f8fb;
  --tot-field-bg: #ffffff;
  --tot-border: #d6dce5;
  --tot-input-border: #9aa5b5;
  --tot-text: #1a2230;
  --tot-muted: #5a6575;
  --tot-primary: #1d5fd1;
  --tot-primary-hover: #164ba8;
  --tot-primary-soft: #e8f0fd;
  --tot-on-primary: #ffffff;
  --tot-success: #157347;
  --tot-success-text: #0f5132;
  --tot-success-soft: #e7f5ee;
  --tot-danger: #b42318;
  --tot-danger-soft: #fdecea;
  --tot-focus: #f2a900;
  --tot-radius: 8px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --tot-surface: #20242b;
    --tot-field-bg: #15181d;
    --tot-border: #3a414c;
    --tot-input-border: #5c6675;
    --tot-text: #e8ecf2;
    --tot-muted: #a7b0bd;
    --tot-primary: #6ea2ff;
    --tot-primary-hover: #8fb7ff;
    --tot-primary-soft: #1d2a40;
    --tot-on-primary: #0b1220;
    --tot-success: #4cc38a;
    --tot-success-text: #9be0bd;
    --tot-success-soft: #15291f;
    --tot-danger: #ff8a7a;
    --tot-danger-soft: #3a1d1a;
  }
}

.tot-main *, .tot-main *::before, .tot-main *::after { box-sizing: border-box; }

.tot-main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px 16px 64px;
  color: var(--tot-text);
  font-size: 16px;
  line-height: 1.7;
}
.tot-main a { color: var(--tot-primary); }
/* ツールの表示部分。中の2列・1列の切り替えは画面幅ではなくこの幅で決める（@container tot-tool。作業画面の並べて表示の片側でも合う） */
.tot-tool { container: tot-tool / inline-size; }
.tot-main :focus-visible { outline: 3px solid var(--tot-focus); outline-offset: 2px; }

.tot-visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}
.tot-main [hidden] { display: none !important; }

/* ── パンくず ── */
.tot-crumbs ol {
  display: flex;
  flex-wrap: wrap;
  gap: 0 6px;
  margin: 0 0 16px;
  padding: 0;
  list-style: none;
  font-size: 12px;
  color: var(--tot-muted);
}
.tot-crumbs li + li::before { content: "›"; margin-right: 6px; }
.tot-crumbs a { color: var(--tot-muted); text-decoration: none; }
.tot-crumbs a:hover { text-decoration: underline; }

/* ── タイトル ── */
.tot-version {
  display: inline-block;
  margin-bottom: 4px;
  padding: 0 8px;
  border: 1px solid var(--tot-border);
  border-radius: 999px;
  font-size: 12px;
  color: var(--tot-muted);
}
.tot-main .tot-open-tab {
  display: inline-flex; align-items: center; min-height: 36px; margin-left: 8px; padding: 2px 12px;
  border: 1px solid var(--tot-primary); border-radius: var(--tot-radius);
  font-size: 14px; font-weight: 600; text-decoration: none; vertical-align: middle;
}
.tot-main .tot-open-tab:hover { background: var(--tot-primary-soft); }
.tot-main .tot-title h1 { margin: 0 0 4px; font-size: 26px; line-height: 1.35; letter-spacing: 0; }
.tot-main .tot-lead { margin: 0 0 12px; color: var(--tot-muted); }

.tot-main .tot-privacy {
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin: 0 0 20px;
  padding: 10px 14px;
  border-radius: var(--tot-radius);
  background: var(--tot-success-soft);
  color: var(--tot-success-text);
  font-size: 14px;
}

.tot-doc { margin-top: 36px; }
.tot-main .tot-doc h2 {
  font-size: 20px;
  margin: 0 0 12px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--tot-border);
}

/* ── ボタン ── */
.tot-btn {
  appearance: none;
  min-height: 44px;
  padding: 8px 18px;
  border: 1px solid var(--tot-primary);
  border-radius: var(--tot-radius);
  background: transparent;
  color: var(--tot-primary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.tot-btn:hover { background: var(--tot-primary-soft); }
.tot-btn-primary { background: var(--tot-primary); color: var(--tot-on-primary); }
.tot-btn-primary:hover { background: var(--tot-primary-hover); }
.tot-btn-quiet { border-color: var(--tot-border); color: var(--tot-muted); }
.tot-btn-quiet:hover { background: var(--tot-surface); }

@media (min-width: 900px) {
  .tot-main { padding: 24px 24px 80px; }
  .tot-main .tot-title h1 { font-size: 30px; }
}

/* 利用状況の計測の設定（src/shared/usage/usage-page.js。画面の下に出し、ツールの操作を妨げない。閉じられる） */
.tot-usage-note { position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 50; max-width: 720px; max-height: 70vh; overflow: auto; margin: 0 auto; padding: 12px 14px; border: 1px solid var(--tot-border); border-radius: var(--tot-radius); background: var(--tot-field-bg); color: var(--tot-text); font-size: 13px; line-height: 1.6; box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15); }
.tot-usage-note p { margin: 0 0 6px; }
.tot-usage-title { font-weight: 700; font-size: 14px; }
.tot-usage-state { color: var(--tot-muted); }
.tot-usage-note a { color: var(--tot-primary); }
.tot-usage-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; margin-top: 8px; }
/* 「許可する」「許可しない」は同じ見た目（どちらかを目立たせない） */
.tot-usage-btn { min-height: 36px; padding: 4px 16px; border: 1px solid var(--tot-input-border); border-radius: 6px; background: var(--tot-surface); color: var(--tot-text); font: inherit; font-weight: 600; cursor: pointer; }
.tot-usage-btn:focus-visible, .tot-usage-note-close:focus-visible { outline: 3px solid var(--tot-focus); outline-offset: 2px; }
.tot-usage-note-close { margin-left: auto; padding: 2px 10px; border: 1px solid var(--tot-input-border); border-radius: 6px; background: transparent; color: var(--tot-text); font: inherit; cursor: pointer; }

/* TOT-040 eBayトラフィックCSVをグラフで見る。
   指標の色は画面全体でそろえる（カード・凡例・グラフ・吹き出し）。色だけに頼らず、名前・単位・値も出す。
   色は隣り合う組（インプレッションと PV、CTR と CVR）が色覚の違いでも見分けられることを確かめた値（ライト・ダーク別）。 */
.tot-trf {
  --trf-impressions: #2a78d6;
  --trf-pageViews: #eb6834;
  --trf-ctr: #1baf7a;
  --trf-cvr: #6250d6;
  --trf-track: #e9edf3;
  --trf-warn: #8a5a00;
  --trf-warn-soft: #fff4dc;
  max-width: 1280px;
}
@media (prefers-color-scheme: dark) {
  .tot-trf {
    --trf-impressions: #3987e5;
    --trf-pageViews: #d95926;
    --trf-ctr: #199e70;
    --trf-cvr: #9085e9;
    --trf-track: #2a3038;
    --trf-warn: #f2c46b;
    --trf-warn-soft: #33290f;
  }
}
.tot-trf-step { margin: 0 0 22px; }
.tot-trf-step > h3 { margin: 0 0 8px; font-size: 17px; }
.tot-trf h4 { margin: 8px 0; font-size: 15px; }
.tot-trf-drop { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 14px; border: 2px dashed var(--tot-border); border-radius: var(--tot-radius); background: var(--tot-surface); }
.tot-trf-drop.is-dragover { border-color: var(--tot-primary); background: var(--tot-primary-soft); }
.tot-trf-note { margin: 6px 0; font-size: 13px; color: var(--tot-muted); }
.tot-trf-msg { margin: 8px 0 0; font-size: 14px; min-height: 1.2em; }
.tot-trf .is-ok { color: var(--tot-success-text); }
.tot-trf .is-error { color: var(--tot-danger); }
.tot-trf .is-warn { color: var(--trf-warn); }
.tot-trf-note.is-warn { padding: 6px 10px; border-left: 4px solid var(--trf-warn); background: var(--trf-warn-soft); border-radius: var(--tot-radius); }
.tot-trf-guide { margin-top: 8px; padding: 8px 12px; border-left: 4px solid var(--tot-primary); background: var(--tot-primary-soft); border-radius: var(--tot-radius); font-size: 14px; }
.tot-trf-guide p { margin: 4px 0; }
.tot-trf-empty { padding: 12px; border: 1px dashed var(--tot-border); border-radius: var(--tot-radius); color: var(--tot-muted); font-size: 14px; }
.tot-trf-confirm { margin-top: 12px; padding: 12px; border: 2px solid var(--trf-warn); border-radius: var(--tot-radius); background: var(--tot-surface); }
.tot-trf-maptable { border-collapse: collapse; font-size: 13px; width: 100%; }
.tot-trf-maptable th, .tot-trf-maptable td { padding: 6px 8px; border-bottom: 1px solid var(--tot-border); text-align: left; vertical-align: top; }
.tot-trf-src { display: block; font-weight: 400; color: var(--tot-muted); font-size: 12px; overflow-wrap: anywhere; }
.tot-trf-badge { font-size: 12px; }
.tot-trf-badge.is-ok { color: var(--tot-success-text); }
.tot-trf-badge.is-warn { color: var(--trf-warn); font-weight: 700; }
.tot-trf-badge.is-error { color: var(--tot-danger); font-weight: 700; }
.tot-trf-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px; }
.tot-trf-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; min-width: 0; }
.tot-trf-field[hidden] { display: none; }
.tot-trf-input { min-height: 36px; padding: 4px 8px; font-size: 14px; border: 1px solid var(--tot-input-border); border-radius: var(--tot-radius); background: var(--tot-field-bg); color: var(--tot-text); max-width: 100%; }
input[type="search"].tot-trf-input { width: min(100%, 300px); }

/* 2. 読み込んだ内容 */
.tot-trf-info { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0; font-size: 14px; }
.tot-trf-info dt { font-weight: 700; }
.tot-trf-info dd { margin: 0; overflow-wrap: anywhere; }
.tot-trf-warn { margin: 8px 0 0; padding-left: 1.4em; font-size: 13px; color: var(--trf-warn); }
.tot-trf-warn:empty { display: none; }
.tot-trf-mapdetails { margin-top: 8px; font-size: 13px; }
.tot-trf-mapdetails summary { cursor: pointer; }
.tot-trf-mapdetails ul { margin: 6px 0; padding-left: 1.4em; overflow-wrap: anywhere; }

/* 3. 4 指標のカード */
.tot-trf-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.tot-trf-card { padding: 10px 12px; border: 1px solid var(--tot-border); border-top: 4px solid var(--trf-c, var(--tot-border)); border-radius: var(--tot-radius); background: var(--tot-field-bg); min-width: 0; }
.tot-trf-card.is-impressions { --trf-c: var(--trf-impressions); }
.tot-trf-card.is-pageViews { --trf-c: var(--trf-pageViews); }
.tot-trf-card.is-ctr { --trf-c: var(--trf-ctr); }
.tot-trf-card.is-cvr { --trf-c: var(--trf-cvr); }
.tot-trf-cardhead { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; margin: 0; font-weight: 700; }
.tot-trf-cardshort { font-weight: 400; font-size: 12px; color: var(--tot-muted); }
.tot-trf-value { margin: 4px 0 2px; font-size: 26px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.tot-trf-unit { font-size: 14px; font-weight: 400; }
.tot-trf-cardnote { margin: 0; font-size: 12px; color: var(--tot-muted); }
.tot-trf-cardnote.is-target { color: var(--tot-text); }
.tot-trf-cardnote.is-warn { margin-top: 4px; color: var(--trf-warn); }
.tot-trf-carddesc { margin: 6px 0 0; font-size: 12px; }
.tot-trf-cards.is-small { margin: 8px 0; }
.tot-trf-cards.is-small .tot-trf-value { font-size: 20px; }
.tot-trf-allnote-key { color: var(--tot-text); font-weight: 700; }
.tot-trf-cardsel-title { grid-column: 1 / -1; margin: 0; font-size: 13px; font-weight: 700; }
.tot-trf-summary { margin-top: 10px; }

/* 4. グラフ */
.tot-trf-segs { display: inline-flex; flex-wrap: wrap; gap: 0; margin-bottom: 10px; border: 1px solid var(--tot-input-border); border-radius: var(--tot-radius); overflow: hidden; }
.tot-trf-seg { min-height: 38px; padding: 4px 14px; border: 0; border-right: 1px solid var(--tot-input-border); background: var(--tot-field-bg); color: var(--tot-text); font: inherit; font-size: 14px; cursor: pointer; }
.tot-trf-seg:last-child { border-right: 0; }
.tot-trf-seg[aria-pressed="true"] { background: var(--tot-primary); color: var(--tot-on-primary); font-weight: 700; }
.tot-trf-seg[aria-pressed="true"]::before { content: "✓ "; }
.tot-trf-controls { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 14px; margin-bottom: 8px; }
.tot-trf-dir { min-height: 36px; }
.tot-trf-selbar { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; font-size: 13px; margin: 4px 0 8px; }
.tot-trf-chartinfo { margin: 6px 0; font-size: 13px; }
.tot-trf-legend { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 0 0 8px; padding: 0; list-style: none; font-size: 13px; }
.tot-trf-legend li { display: inline-flex; align-items: center; gap: 6px; }
.tot-trf-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 3px; background: var(--trf-c, var(--tot-border)); flex: none; }
.tot-trf-swatch.is-impressions, .tot-trf-card.is-impressions .tot-trf-swatch { --trf-c: var(--trf-impressions); }
.tot-trf-swatch.is-pageViews, .tot-trf-card.is-pageViews .tot-trf-swatch { --trf-c: var(--trf-pageViews); }
.tot-trf-swatch.is-ctr, .tot-trf-card.is-ctr .tot-trf-swatch { --trf-c: var(--trf-ctr); }
.tot-trf-swatch.is-cvr, .tot-trf-card.is-cvr .tot-trf-swatch { --trf-c: var(--trf-cvr); }
.tot-trf-chartwrap { position: relative; }
.tot-trf-charts { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.tot-trf-chart { margin: 0; padding: 10px 12px; border: 1px solid var(--tot-border); border-radius: var(--tot-radius); background: var(--tot-field-bg); min-width: 0; }
.tot-trf-chart figcaption { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin-bottom: 6px; font-size: 14px; }
.tot-trf-chartsub { font-size: 12px; color: var(--tot-muted); }
/* 行：名前｜棒｜値。目盛りも同じ3列 */
/* 3列目（値）の幅は固定にして、目盛りの行と棒の行で棒の位置をそろえる */
.tot-trf-axis, .tot-trf-barrow { display: grid; grid-template-columns: minmax(90px, 34%) minmax(60px, 1fr) 78px; gap: 8px; align-items: center; }
.tot-trf-axis { font-size: 11px; color: var(--tot-muted); padding: 0 4px; }
.tot-trf-ticks { display: flex; justify-content: space-between; border-bottom: 1px solid var(--tot-border); padding-bottom: 2px; }
.tot-trf-bars { margin: 0; padding: 0; list-style: none; }
.tot-trf-barrow { width: 100%; min-height: 30px; padding: 2px 4px; border: 0; border-radius: 6px; background: transparent; color: var(--tot-text); font: inherit; font-size: 12px; text-align: left; cursor: pointer; }
.tot-trf-barrow:hover { background: var(--tot-surface); }
.tot-trf-label { display: flex; gap: 6px; min-width: 0; }
.tot-trf-rank { flex: none; min-width: 1.6em; text-align: right; color: var(--tot-muted); font-variant-numeric: tabular-nums; }
.tot-trf-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tot-trf-track { position: relative; display: flex; flex-direction: column; justify-content: center; gap: 2px; height: 18px; background: linear-gradient(to right, var(--tot-border) 1px, transparent 1px) 50% 0 / 50% 100% no-repeat, transparent; border-left: 1px solid var(--tot-input-border); }
.tot-trf-track.is-pair { height: 22px; }
.tot-trf-bar { display: block; height: 12px; min-width: 0; border-radius: 0 4px 4px 0; background: var(--trf-c); }
.tot-trf-track.is-pair .tot-trf-bar { height: 9px; }
.tot-trf-bar.is-none { width: 0; }
.tot-trf-bar.is-impressions { --trf-c: var(--trf-impressions); }
.tot-trf-bar.is-pageViews { --trf-c: var(--trf-pageViews); }
.tot-trf-bar.is-ctr { --trf-c: var(--trf-ctr); }
.tot-trf-bar.is-cvr { --trf-c: var(--trf-cvr); }
.tot-trf-val { display: flex; flex-direction: column; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; line-height: 1.25; }
.tot-trf-chart.is-pair .tot-trf-val { font-size: 11px; }
.tot-trf-tip { position: absolute; z-index: 5; padding: 10px 12px 10px; border: 1px solid var(--tot-input-border); border-radius: var(--tot-radius); background: var(--tot-field-bg); color: var(--tot-text); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.18); font-size: 13px; }
.tot-trf-tip ul { margin: 6px 0; padding: 0; list-style: none; }
.tot-trf-tip li { display: flex; align-items: center; gap: 6px; }
.tot-trf-tipsub { padding-left: 18px; color: var(--tot-muted); font-size: 12px; }
.tot-trf-tiptitle { margin: 0 24px 2px 0; font-weight: 700; overflow-wrap: anywhere; }
.tot-trf-tipid { margin: 0; color: var(--tot-muted); font-size: 12px; }
.tot-trf-tipclose { position: absolute; top: 4px; right: 4px; width: 28px; height: 28px; border: 0; background: transparent; color: var(--tot-text); font-size: 18px; cursor: pointer; }
.tot-trf-tippick { min-height: 32px; font-size: 13px; }

/* 5. 表 */
.tot-trf-checklist { margin: 0 0 6px; padding-left: 1.2em; font-size: 13px; }
.tot-trf-tablewrap { max-width: 100%; overflow-x: auto; border: 1px solid var(--tot-border); border-radius: var(--tot-radius); }
.tot-trf-tablewrap:focus-visible { outline: 3px solid var(--tot-focus); }
.tot-trf-table { border-collapse: collapse; font-size: 13px; min-width: 100%; }
.tot-trf-table th, .tot-trf-table td { padding: 6px 8px; border-bottom: 1px solid var(--tot-border); text-align: left; vertical-align: top; }
.tot-trf-table thead th { position: sticky; top: 0; background: var(--tot-surface); white-space: nowrap; }
.tot-trf-table td.is-num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tot-trf-table tr.is-selected td { background: var(--tot-primary-soft); }
.tot-trf-id { white-space: nowrap; font-variant-numeric: tabular-nums; }
.tot-trf-dup { display: inline-block; margin-left: 4px; padding: 0 4px; border: 1px solid var(--trf-warn); border-radius: 4px; color: var(--trf-warn); font-size: 11px; }
.tot-trf-title { min-width: 220px; max-width: 360px; overflow-wrap: anywhere; }
.tot-trf-chk { white-space: nowrap; }
.tot-trf-chk.is-large { color: var(--tot-danger); font-weight: 700; }
.tot-trf-chk.is-large::before { content: "⚠ "; }
.tot-trf-chk.is-rounding { color: var(--tot-muted); }
.tot-trf-chk.is-match { color: var(--tot-success-text); }
.tot-trf-step > .tot-btn { margin-top: 8px; }

/* 使い方・定義 */
.tot-trf-docs { margin-top: 28px; padding-top: 12px; border-top: 1px solid var(--tot-border); font-size: 14px; }
.tot-trf-docs details { margin: 6px 0; }
.tot-trf-docs summary { cursor: pointer; font-weight: 700; }
.tot-trf-docs ul, .tot-trf-docs ol { margin: 6px 0; padding-left: 1.4em; }

/* 広い時：4 指標のグラフを 2 列に。狭い時：カード 2 列、グラフは縦に 1 列 */
@container tot-tool (min-width: 900px) {
  .tot-trf-charts.is-many { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@container tot-tool (max-width: 760px) {
  .tot-trf-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@container tot-tool (max-width: 480px) {
  .tot-trf-value { font-size: 21px; }
  /* 狭い幅：カードは名前・単位・値・計算の内訳だけにする（定義は下の「指標の定義と計算式」） */
  .tot-trf-carddesc { display: none; }
  .tot-trf-axis, .tot-trf-barrow { grid-template-columns: minmax(70px, 38%) minmax(40px, 1fr) 68px; gap: 6px; }
  .tot-trf-info { grid-template-columns: 1fr; }
  .tot-trf-info dd { margin-bottom: 4px; }
}

/* 単独ページ：PC を主な分析画面にするため、ページの幅を広げる（このツールのページだけ） */
.tot-main.tot-main-wide { max-width: 1320px; }
