/* =====================================================================
   デザインの定義（ここだけを変えれば、サイト全体の見た目が変わる）
     - 下のルールでは数値や色を直接書かず、必ず var(--xxx) で使う
     - 色はライト / ダークの両方を定義する
   ===================================================================== */
:root {
  /* ---------- 色（ライトモード） ---------- */
  --bg: #f6f7f9;            /* ページの背景 */
  --surface: #ffffff;       /* バー・一覧・カードの背景 */
  --surface-2: #f0f2f5;     /* 一段沈んだ背景（カード見出し・検索欄など） */
  --border: #e1e4e8;        /* 枠線・区切り線 */
  --text: #1f2328;          /* ふつうの文字 */
  --text-muted: #636c76;    /* 補足の文字 */
  --accent: #3b5bdb;        /* 選択中・XDM */
  --accent-soft: #e7ecff;
  --state: #2b8a3e;         /* 画面表示（trackState）・接続中 */
  --state-soft: #e3f6e8;
  --action: #c2410c;        /* 操作（trackAction） */
  --action-soft: #fff0e6;
  --other: #6b7280;         /* その他 */
  --other-soft: #eef0f3;
  --danger: #c92a2a;        /* 削除・エラー */
  --new-flash: #fff7cc;     /* 新着の行を一瞬光らせる色 */
  --group-bg: #eef1fb;      /* シナリオのまとまりの見出しの背景 */
  --wait: #a16207;          /* 「待っています」 */
  --wait-soft: #fef6dc;

  /* ---------- 文字 ---------- */
  --font-ui: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  --font-mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  --text-2xs: 11px;         /* バッジ・ラベル */
  --text-xs: 12px;          /* 時刻・補足 */
  --text-sm: 13px;          /* 表の中身・カード見出し */
  --text-md: 14px;          /* 基本 */
  --text-lg: 16px;          /* サイト名 */
  --text-xl: 20px;          /* 詳細の見出し */
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 650;
  --line-relaxed: 1.7;

  /* ---------- 余白（基本の目盛り） ---------- */
  --space-1: 2px;
  --space-2: 4px;
  --space-3: 6px;
  --space-4: 8px;
  --space-5: 10px;
  --space-6: 12px;
  --space-7: 14px;
  --space-8: 16px;
  --space-10: 20px;
  --space-12: 24px;
  --space-20: 40px;

  /* ---------- 余白（部品ごと） ---------- */
  --page-gutter: var(--space-10);         /* 上のバーなどの左右の余白 */
  --page-gutter-narrow: var(--space-8);   /* 幅が狭いときの左右の余白 */
  --detail-padding: var(--space-10) var(--space-12) var(--space-20);
  --card-header-padding: var(--space-5) var(--space-7);
  --cell-padding: 7px var(--space-7);     /* 表の1マス */
  --chip-padding: 5px var(--space-6);
  --badge-padding: 1px var(--space-3);
  --tag-padding: 0 5px;
  --group-indent: var(--space-12);       /* まとまりの中のビーコンの字下げ */

  /* ---------- 角の丸み・線 ---------- */
  --radius: 8px;            /* カード・入力欄・ボタン */
  --radius-sm: 4px;         /* バッジ・タグ */
  --radius-mark: 5px;       /* サイト名の横のマーク */
  --radius-pill: 999px;     /* 絞り込みボタン（丸い端） */
  --line: 1px solid var(--border);
  --indicator-width: 3px;   /* 選択中の行の左の線・接続中の点の光 */

  /* ---------- 大きさ・幅 ---------- */
  --brand-mark-size: 18px;
  --status-dot-size: 8px;
  --list-width-min: 300px;  /* 左の一覧の幅（最小〜最大） */
  --list-width-max: 420px;
  --list-height-narrow: 45vh; /* 幅が狭いときの一覧の高さ */
  --search-min-width: 180px;
  --summary-col-min: 180px; /* 概要の1マスの最小幅 */
  --kv-key-width: 34%;      /* キーと値の表の、キー側の幅 */
  --compare-concept-width: 22%; /* 比較表の「項目」列の幅 */
  --entry-width: 460px;     /* コードの入力画面の幅 */

  /* ---------- 動き ---------- */
  --flash-duration: 1.6s;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2b303b;
    --text: #e6e8eb;
    --text-muted: #9aa3ae;
    --accent: #8ea2ff;
    --accent-soft: #232b4d;
    --state: #69db7c;
    --state-soft: #1c3324;
    --action: #ffa94d;
    --action-soft: #3a2815;
    --other: #a1a8b3;
    --other-soft: #262a33;
    --danger: #ff6b6b;
    --new-flash: #3d3714;
    --group-bg: #1c2133;
    --wait: #fcc419;
    --wait-soft: #3a3214;
  }
}

/* =====================================================================
   ここから下は、上の定義を使って各部品の見た目を決める
   ===================================================================== */

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: var(--text-md);
  display: flex;
  flex-direction: column;
}

/* ===== 上のバー ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-6) var(--page-gutter);
  background: var(--surface);
  border-bottom: var(--line);
}
.brand { display: flex; align-items: center; gap: var(--space-5); }
.brand-mark {
  width: var(--brand-mark-size); height: var(--brand-mark-size); border-radius: var(--radius-mark);
  background: linear-gradient(135deg, var(--accent), var(--state));
}
h1 { font-size: var(--text-lg); margin: 0; font-weight: var(--weight-bold); }
.status { display: flex; align-items: center; gap: var(--space-4); color: var(--text-muted); font-size: var(--text-sm); }
.status .dot { width: var(--status-dot-size); height: var(--status-dot-size); border-radius: 50%; background: var(--other); }
.status[data-state="live"] .dot { background: var(--state); box-shadow: 0 0 0 var(--indicator-width) var(--state-soft); }
.status[data-state="error"] .dot { background: var(--danger); }

/* ===== 絞り込みのバー ===== */
.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-5);
  padding: var(--space-5) var(--page-gutter);
  border-bottom: var(--line);
  background: var(--surface);
}
.chips { display: flex; flex-wrap: wrap; gap: var(--space-3); }
.chip {
  border: var(--line); background: var(--surface); color: var(--text);
  border-radius: var(--radius-pill); padding: var(--chip-padding); font: inherit; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.chip .count { color: var(--text-muted); font-variant-numeric: tabular-nums; margin-left: var(--space-1); }
.search {
  flex: 1; min-width: var(--search-min-width);
  border: var(--line); background: var(--surface-2); color: var(--text);
  border-radius: var(--radius); padding: var(--space-3) var(--space-5); font: inherit;
}
.button-danger {
  border: var(--line); background: var(--surface); color: var(--danger);
  border-radius: var(--radius); padding: var(--space-3) var(--space-6); font: inherit; cursor: pointer;
}
.button-danger:hover { border-color: var(--danger); }

/* ===== 左右の2段組み ===== */
.layout {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(var(--list-width-min), var(--list-width-max)) 1fr;
}
.list-pane { overflow-y: auto; border-right: var(--line); background: var(--surface); }
.detail-pane { overflow-y: auto; padding: var(--detail-padding); }

/* ===== 一覧 ===== */
.beacon-list { list-style: none; margin: 0; padding: 0; }
.beacon-item {
  display: grid; grid-template-columns: auto 1fr; gap: var(--space-1) var(--space-5);
  padding: var(--space-5) var(--space-8); border-bottom: var(--line); cursor: pointer;
}
.beacon-item:hover { background: var(--surface-2); }
.beacon-item[aria-selected="true"] { background: var(--accent-soft); box-shadow: inset var(--indicator-width) 0 0 var(--accent); }
.beacon-item.is-new { animation: flash var(--flash-duration) ease-out; }
@keyframes flash { from { background: var(--new-flash); } to { background: transparent; } }
.beacon-time { grid-row: span 2; color: var(--text-muted); font-family: var(--font-mono); font-size: var(--text-xs); padding-top: var(--space-1); }
.beacon-name { font-weight: var(--weight-semibold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.beacon-sub { color: var(--text-muted); font-size: var(--text-xs); display: flex; gap: var(--space-3); align-items: center; overflow: hidden; }
.beacon-sub .ctx { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font-mono); }

/* 種類のバッジ（色は種類ごと） */
.badge {
  display: inline-block; border-radius: var(--radius-sm); padding: var(--badge-padding);
  font-size: var(--text-2xs); font-weight: var(--weight-semibold); white-space: nowrap;
  background: var(--other-soft); color: var(--other);
}
.badge.trackState { background: var(--state-soft); color: var(--state); }
.badge.trackAction { background: var(--action-soft); color: var(--action); }
.badge.xdm { background: var(--accent-soft); color: var(--accent); }

/* シナリオのまとまりの見出し */
.group-head {
  display: grid; grid-template-columns: auto 1fr; column-gap: var(--space-5); row-gap: var(--space-1);
  padding: var(--space-5) var(--space-8); background: var(--group-bg); border-bottom: var(--line);
}
.group-head.is-new { animation: flash var(--flash-duration) ease-out; }
.group-title { font-weight: var(--weight-bold); }
.group-note { grid-column: 2; color: var(--text-muted); font-size: var(--text-xs); line-height: var(--line-relaxed); }
.group-status { border-radius: var(--radius-sm); padding: var(--badge-padding); font-size: var(--text-2xs); font-weight: var(--weight-semibold); }
.group-status.done { background: var(--state-soft); color: var(--state); }
.group-status.wait { background: var(--wait-soft); color: var(--wait); }
.group-status.none { background: var(--other-soft); color: var(--other); }
/* まとまりの中のビーコンは、字下げして見出しの下にぶら下げる */
.beacon-item.in-group { padding-left: var(--group-indent); }
/* 「SDK が自動で送信」「前回分」などの印 */
.role-tag {
  border-radius: var(--radius-sm); padding: var(--tag-padding);
  font-size: var(--text-2xs); background: var(--other-soft); color: var(--other); white-space: nowrap;
}
/* 詳細の上に出す補足（「前回の『閉じる』の情報を含みます」など） */
.detail-note {
  margin: 0 0 var(--space-8); padding: var(--space-5) var(--space-7);
  border-radius: var(--radius); background: var(--accent-soft); color: var(--text); line-height: var(--line-relaxed);
}

/* ===== セッション ===== */
.session-badge {
  border-radius: var(--radius-pill); padding: var(--badge-padding) var(--space-5);
  background: var(--accent-soft); color: var(--accent);
  font-family: var(--font-mono); font-size: var(--text-sm); font-weight: var(--weight-semibold);
}
/* コードの入力画面のときは、一覧・比較・上のバーの操作を隠す */
body[data-page="entry"] .toolbar,
body[data-page="entry"] .layout,
body[data-page="entry"] .compare-pane { display: none; }
.entry-pane[hidden] { display: none; }  /* hidden を display: flex で上書きしないように */
.entry-pane { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: var(--space-20) var(--page-gutter); }
.entry-card {
  width: 100%; max-width: var(--entry-width); background: var(--surface); border: var(--line); border-radius: var(--radius);
  padding: var(--space-12); display: flex; flex-direction: column; gap: var(--space-6);
}
.entry-card label { font-weight: var(--weight-semibold); }
.entry-row { display: flex; gap: var(--space-4); }
.entry-input {
  flex: 1; min-width: 0; font: inherit; font-family: var(--font-mono); font-size: var(--text-xl); letter-spacing: var(--space-1);
  text-transform: uppercase; padding: var(--space-4) var(--space-6); border: var(--line); border-radius: var(--radius);
  background: var(--surface-2); color: var(--text);
}
.entry-button {
  font: inherit; font-weight: var(--weight-semibold); padding: var(--space-4) var(--space-10);
  border: none; border-radius: var(--radius); background: var(--accent); color: var(--surface); cursor: pointer;
}
.entry-message { margin: 0; padding: var(--space-5) var(--space-7); border-radius: var(--radius); background: var(--wait-soft); color: var(--text); }
.entry-help { margin: 0; color: var(--text-muted); font-size: var(--text-xs); line-height: var(--line-relaxed); }

/* ===== 一覧 / 比較 の切り替え ===== */
.view-switch { display: flex; border: var(--line); border-radius: var(--radius); overflow: hidden; }
.view-button { border: none; background: var(--surface); color: var(--text-muted); padding: var(--chip-padding); cursor: pointer; font: inherit; }
.view-button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: var(--weight-semibold); }
/* 比較のときは一覧・絞り込みを隠し、一覧のときは比較を隠す */
body[data-view="compare"] .layout,
body[data-view="compare"] .chips,
body[data-view="compare"] .search { display: none; }
body[data-view="list"] .compare-pane { display: none; }

/* まとまりの見出しの「比較」 */
.link-button {
  margin-left: var(--space-4); border: none; background: none; padding: 0; cursor: pointer;
  color: var(--accent); font: inherit; font-size: var(--text-xs); font-weight: var(--weight-regular);
}
.link-button:hover { text-decoration: underline; }

/* ===== 比較ビュー ===== */
.compare-pane { flex: 1; overflow-y: auto; padding: var(--detail-padding); }
.compare-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--space-4) var(--space-6); margin-bottom: var(--space-8); }
.compare-head label { font-weight: var(--weight-semibold); }
.compare-head select { font: inherit; padding: var(--space-2) var(--space-4); border: var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); }
.compare-help { margin: 0; color: var(--text-muted); font-size: var(--text-xs); flex-basis: 100%; }
.compare-card { background: var(--surface); border: var(--line); border-radius: var(--radius); }
.compare-table { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.compare-table th, .compare-table td { text-align: left; vertical-align: top; padding: var(--cell-padding); border-bottom: var(--line); }
.compare-table thead th { background: var(--surface-2); }
.compare-table tbody tr:last-child th, .compare-table tbody tr:last-child td { border-bottom: none; }
.compare-table td { font-family: var(--font-mono); word-break: break-all; }
.compare-concept { width: var(--compare-concept-width); font-weight: var(--weight-semibold); }
.compare-concept .label { display: block; color: var(--text-muted); font-size: var(--text-2xs); font-weight: var(--weight-regular); }
.compare-method { font-weight: var(--weight-bold); }
.compare-meta { display: flex; gap: var(--space-4); align-items: center; color: var(--text-muted); font-size: var(--text-xs); font-weight: var(--weight-regular); margin-top: var(--space-1); }
.compare-note { color: var(--text-muted); font-size: var(--text-2xs); font-weight: var(--weight-regular); margin-top: var(--space-2); line-height: var(--line-relaxed); }
.compare-empty { color: var(--text-muted); }

/* どのツールから届いたかのタグ */
.tool-tag {
  border: var(--line); border-radius: var(--radius-sm); padding: var(--tag-padding);
  font-size: var(--text-2xs); color: var(--text-muted); white-space: nowrap;
}

.empty { padding: var(--space-20) var(--space-12); color: var(--text-muted); text-align: center; line-height: var(--line-relaxed); }
.empty-title { color: var(--text); font-weight: var(--weight-semibold); margin-bottom: var(--space-2); }
.placeholder { color: var(--text-muted); padding: var(--space-20) 0; }

/* ===== 詳細 ===== */
.detail-head { display: flex; align-items: center; gap: var(--space-5); margin-bottom: var(--space-2); }
.detail-head h2 { margin: 0; font-size: var(--text-xl); }
.detail-meta { color: var(--text-muted); font-size: var(--text-xs); margin-bottom: var(--space-10); font-family: var(--font-mono); }

.card { background: var(--surface); border: var(--line); border-radius: var(--radius); margin-bottom: var(--space-8); overflow: hidden; }
/* カードの見出し。クリックで開閉する（HTML の <details> / <summary>） */
.card > summary {
  cursor: pointer; list-style: none;
  padding: var(--card-header-padding); font-size: var(--text-sm); font-weight: var(--weight-bold);
  background: var(--surface-2);
  display: flex; align-items: baseline; gap: var(--space-4);
}
.card > summary::-webkit-details-marker { display: none; }
.card > summary::before { content: "▸"; color: var(--text-muted); margin-right: var(--space-2); }
.card[open] > summary::before { content: "▾"; }
.card[open] > summary { border-bottom: var(--line); }
.card > summary small { font-weight: var(--weight-regular); color: var(--text-muted); margin-left: auto; }
.card .none { padding: var(--card-header-padding); color: var(--text-muted); }

/* キーと値の表 */
.kv { width: 100%; border-collapse: collapse; }
.kv th, .kv td { text-align: left; padding: var(--cell-padding); border-bottom: var(--line); vertical-align: top; }
.kv tr:last-child th, .kv tr:last-child td { border-bottom: none; }
.kv th { width: var(--kv-key-width); font-weight: var(--weight-medium); font-family: var(--font-mono); font-size: var(--text-sm); }
.kv th .label { display: block; font-family: inherit; color: var(--text-muted); font-size: var(--text-2xs); font-weight: var(--weight-regular); }
.kv td { font-family: var(--font-mono); font-size: var(--text-sm); word-break: break-all; }

/* 商品の一覧表（横に長いときは表だけ横スクロール） */
.table-scroll { overflow-x: auto; }
.grid { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
.grid th, .grid td { text-align: left; padding: var(--cell-padding); border-bottom: var(--line); white-space: nowrap; }
.grid th { color: var(--text-muted); font-weight: var(--weight-medium); font-size: var(--text-xs); }
.grid td { font-family: var(--font-mono); }
.grid tr:last-child td { border-bottom: none; }

/* 概要（項目名と値のマス目） */
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(var(--summary-col-min), 1fr)); }
.summary-grid div { padding: var(--card-header-padding); border-right: var(--line); }
.summary-grid div:last-child { border-right: none; }
.summary-grid dt { color: var(--text-muted); font-size: var(--text-2xs); margin-bottom: var(--space-1); }
.summary-grid dd { margin: 0; font-family: var(--font-mono); font-size: var(--text-sm); word-break: break-all; }

/* 生のリクエスト */
pre.raw {
  margin: 0; padding: var(--space-6) var(--space-7);
  font-family: var(--font-mono); font-size: var(--text-xs); white-space: pre-wrap; word-break: break-all;
  background: var(--surface-2);
}

/* ===== スマホなど幅が狭いとき：上下に並べる =====
   ※ 760px の切り替え幅は、CSS の仕組み上 var() が使えないのでここに直接書いている */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; grid-template-rows: var(--list-height-narrow) 1fr; }
  .list-pane { border-right: none; border-bottom: var(--line); }
  .toolbar, .topbar { padding-left: var(--page-gutter-narrow); padding-right: var(--page-gutter-narrow); }
  .detail-pane { padding: var(--page-gutter-narrow); }
}
