/* GA4（Googleアナリティクス4）の見た目に寄せた配色とレイアウト。
   Googleのマテリアル系の値をそのまま使う: 面は白、地はごく薄いグレー、
   アクセントは青 #1a73e8、選択中の項目は薄青の角丸で塗る。 */
:root {
  --bg: #f8f9fa;
  --surface: #fff;
  --line: #dadce0;
  --line-soft: #e8eaed;
  --text: #202124;
  --muted: #5f6368;
  --accent: #1a73e8;
  --accent-soft: #e8f0fe;
  --up: #188038;
  --down: #d93025;
  --shadow: 0 1px 2px rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15);
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #202124; --surface: #292a2d; --line: #5f6368; --line-soft: #3c4043;
    --text: #e8eaed; --muted: #9aa0a6; --accent: #8ab4f8; --accent-soft: #283142;
    --up: #81c995; --down: #f28b82;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 1px 3px 1px rgba(0,0,0,.15);
  }
}

* { box-sizing: border-box; }
/* hidden属性は必ず効かせる。#id セレクタの display 指定のほうが詳細度で勝ってしまうため */
[hidden] { display: none !important; }

body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.5 Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }

/* --- ログイン --- */
#login { display: grid; place-items: center; min-height: 100vh; padding: 1rem; }
#login form {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 2.5rem 2rem; width: min(400px, 100%); display: grid; gap: 1.25rem;
}
#login h1 { font-size: 1.375rem; font-weight: 400; margin: 0 0 .5rem; }
#login label { display: grid; gap: .35rem; font-size: .75rem; color: var(--muted); }
input, select, button {
  font: inherit; padding: .55rem .75rem; border: 1px solid var(--line);
  border-radius: 4px; background: var(--surface); color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
button { cursor: pointer; border-radius: 4px; }
#login button {
  background: var(--accent); color: #fff; border-color: transparent;
  padding: .65rem; font-weight: 500; letter-spacing: .01em;
}
.error { color: var(--down); margin: 0; font-size: .8125rem; }

/* --- 骨格 --- */
#app { display: grid; grid-template-columns: 256px 1fr; min-height: 100vh; }

aside {
  background: var(--surface); border-right: 1px solid var(--line-soft);
  padding: 1rem 0; display: flex; flex-direction: column; gap: 1rem;
}
aside h1 {
  font-size: 1.125rem; font-weight: 400; margin: 0; padding: .5rem 1.5rem 1rem;
  color: var(--muted); line-height: 1.3;
}
nav { display: grid; gap: 2px; padding-right: 1rem; }
nav a {
  padding: .625rem 1.5rem; border-radius: 0 20px 20px 0; text-decoration: none;
  color: var(--text); font-size: .875rem; font-weight: 500;
}
nav a:hover { background: var(--bg); }
nav a.active { background: var(--accent-soft); color: var(--accent); }
.user { margin-top: auto; padding: 1rem 1.5rem 0; font-size: .75rem; color: var(--muted); display: grid; gap: .5rem; justify-items: start; }
.user button { font-size: .8125rem; padding: .35rem .75rem; }

.main { min-width: 0; max-width: 100%; overflow-x: hidden; display: flex; flex-direction: column; }

.tabs { display: flex; gap: .25rem; width: 100%; order: -1; margin-bottom: .25rem; }
.tab {
  border: none; background: transparent; color: var(--muted);
  padding: .5rem .9rem; border-radius: 0; border-bottom: 2px solid transparent;
  font-weight: 500; font-size: .875rem;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }
.siteform label.inline { display: inline-flex; gap: .4rem; align-items: center; font-size: .75rem; color: var(--muted); }

header {
  background: var(--surface); border-bottom: 1px solid var(--line-soft);
  padding: .875rem 1.5rem; display: flex; flex-wrap: wrap; gap: .75rem 1.25rem;
  align-items: center; justify-content: space-between;
}
.filter { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }
.filter label { display: flex; gap: .5rem; align-items: center; font-size: .75rem; color: var(--muted); }
.filter select { border-radius: 4px; padding: .4rem .5rem; font-size: .8125rem; }
.meta { font-size: .75rem; color: var(--muted); display: grid; text-align: right; gap: 2px; }

details.sites { position: relative; }
details.sites summary {
  cursor: pointer; padding: .4rem .75rem; border: 1px solid var(--line);
  border-radius: 16px; font-size: .8125rem; list-style: none; color: var(--muted);
}
details.sites summary::-webkit-details-marker { display: none; }
details[open].sites summary { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
#site-list {
  position: absolute; z-index: 5; top: 130%; left: 0; width: 280px; max-height: 340px; overflow: auto;
  background: var(--surface); border-radius: var(--radius); padding: .5rem;
  box-shadow: var(--shadow);
}
#site-list label { display: flex; gap: .625rem; align-items: center; padding: .375rem .5rem; font-size: .8125rem; border-radius: 4px; }
#site-list label:hover { background: var(--bg); }
.swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; }

.notice {
  margin: 1.25rem 1.5rem -.25rem; padding: .75rem 1rem; font-size: .8125rem;
  background: var(--accent-soft); color: var(--text);
  border-radius: var(--radius);
}

/* --- カード --- */
main { padding: 1.25rem 1.5rem 3rem; display: grid; gap: 1rem; align-content: start; }
.stack { display: grid; gap: 1rem; }

.panel {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.25rem 1.5rem;
}
.panel > button { background: var(--accent); color: #fff; border-color: transparent; padding: .55rem 1.25rem; font-weight: 500; justify-self: start; }
.panel > button:disabled { opacity: .6; cursor: default; }
.panel h2 { margin: 0 0 1rem; font-size: 1rem; font-weight: 500; color: var(--text); }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 1rem; }
.kpi { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem 1.5rem; }
.kpi .label { font-size: .75rem; color: var(--muted); letter-spacing: .02em; }
.kpi .value { font-size: 2rem; font-weight: 400; line-height: 1.3; font-variant-numeric: tabular-nums; }
.kpi .delta { font-size: .75rem; font-variant-numeric: tabular-nums; color: var(--muted); }
.delta.up { color: var(--up); }
.delta.down { color: var(--down); }

/* --- 表 --- */
/* 長いページタイトルやURLは折り返す。横スクロールさせない。 */
table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; table-layout: auto; }
th, td { padding: .75rem .5rem; border-bottom: 1px solid var(--line-soft); text-align: right; font-size: .8125rem; }
th { font-size: .75rem; color: var(--muted); font-weight: 500; white-space: nowrap; }
/* 数値の列は折り返さない。文字列は折り返す */
td { white-space: normal; overflow-wrap: anywhere; }
th:first-child, td:first-child { text-align: left; padding-left: 0; }
th:last-child, td:last-child { padding-right: 0; }
tbody tr:last-child td { border-bottom: none; }
td.path { word-break: break-all; }
td.path .detail-link { margin-left: .6rem; font-size: .75rem; white-space: nowrap; }
td.num { white-space: nowrap; }
tbody tr:hover { background: var(--bg); }
/* 折り返してもなお収まらない場合の保険 */
.scroll { overflow-x: auto; max-width: 100%; }

.guide { margin-bottom: 1.25rem; border: 1px solid var(--line-soft); border-radius: var(--radius); }
.guide > summary { cursor: pointer; padding: .75rem 1rem; font-weight: 500; font-size: .875rem; }
.guide[open] > summary { border-bottom: 1px solid var(--line-soft); }
.guide-body { padding: 1rem; display: grid; gap: 1rem; font-size: .875rem; }
.guide-body p { margin: .35rem 0; }
.guide-body ol { margin: 0; padding-left: 1.25rem; display: grid; gap: 1.25rem; }
.guide-body li strong { display: block; margin-bottom: .35rem; }
.guide-body h3 { font-size: .875rem; margin: .5rem 0 0; }
.guide-body table td { border-bottom: 1px solid var(--line-soft); text-align: left; }
.guide-body table td:last-child { text-align: right; color: var(--muted); }
.guide-body .warn { color: var(--down); }

.cmd { display: flex; gap: .5rem; align-items: flex-start; margin: .5rem 0; }
.cmd pre {
  flex: 1; margin: 0; padding: .6rem .75rem; overflow-x: auto;
  background: var(--bg); border-radius: 4px; font-size: .8125rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-all;
}
.cmd .copy { flex: none; font-size: .75rem; padding: .35rem .6rem; }

.siteform { display: grid; gap: .75rem; margin-bottom: 1rem; justify-items: start; }
.siteform textarea {
  width: 100%; max-width: 560px; font: inherit; padding: .6rem .75rem;
  border: 1px solid var(--line); border-radius: 4px; background: var(--surface);
  color: var(--text); resize: vertical; line-height: 1.6;
}
.siteform textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
.siteform .row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; }
.panel > .row { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.panel > .row button { background: var(--accent); color: #fff; border-color: transparent; padding: .55rem 1.25rem; font-weight: 500; }
.panel > .row button:disabled { opacity: .6; cursor: default; }
.siteform button { background: var(--accent); color: #fff; border-color: transparent; padding: .55rem 1.25rem; font-weight: 500; }
.siteform button:disabled { opacity: .6; cursor: default; }
.ng-text { color: var(--down); }
.ok-text { color: var(--up); }
.linkbtn {
  display: inline-block; background: var(--accent); color: #fff; text-decoration: none;
  padding: .55rem 1.25rem; border-radius: 4px; font-weight: 500; font-size: .8125rem;
}
.verify { display: inline-flex; gap: .5rem; align-items: center; justify-content: flex-end; flex-wrap: wrap; }
.verify .muted, .verify .ok-text, .verify .ng-text { font-size: .75rem; }

.userform { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-bottom: 1rem; }
.userform input { min-width: 220px; }
.userform button { background: var(--accent); color: #fff; border-color: transparent; padding: .55rem 1.25rem; font-weight: 500; }
.muted { color: var(--muted); }

.steps { display: grid; gap: .5rem; margin: 1rem 0; }
.step { display: grid; grid-template-columns: 1.5rem 10rem 1fr; gap: .5rem; align-items: baseline; font-size: .875rem; }
.step .mark { font-weight: 700; }
.step.ok .mark { color: var(--up); }
.step.ng .mark { color: var(--down); }
.step .name { color: var(--muted); }
.plan { display: grid; gap: 1rem; justify-items: start; margin-bottom: 1rem; }
.plan button { background: var(--accent); color: #fff; border-color: transparent; padding: .55rem 1.25rem; font-weight: 500; }
.plan button:disabled { opacity: .6; cursor: default; }

input[type="search"] {
  width: min(320px, 100%); margin-bottom: 1rem; border-radius: 4px;
}

.empty { color: var(--muted); padding: 2.5rem 0; text-align: center; font-size: .875rem; }
.chart { height: 280px; }
.chart-sm { height: 140px; }
#map { height: 420px; border-radius: var(--radius); }
.leaflet-container { font: inherit; background: var(--bg); }

/* リアルタイムの大きな数字（GA4の「過去30分間のユーザー」に相当） */
.rt-hero { display: flex; flex-wrap: wrap; gap: 2rem 3rem; align-items: flex-start; }
.rt-hero .n { font-size: 3.5rem; font-weight: 400; line-height: 1; font-variant-numeric: tabular-nums; }
.rt-hero .cap { font-size: .75rem; color: var(--muted); margin-bottom: .5rem; }
.rt-hero .grow { flex: 1 1 320px; min-width: 260px; }

@media (max-width: 840px) {
  #app { grid-template-columns: 1fr; }
  aside { flex-direction: row; align-items: center; flex-wrap: wrap; padding: .75rem 1rem; gap: .75rem; }
  aside h1 { padding: 0; font-size: 1rem; }
  nav { grid-auto-flow: column; padding: 0; }
  nav a { padding: .5rem .75rem; border-radius: 16px; }
  .user { margin: 0; padding: 0; }
  main, header { padding-left: 1rem; padding-right: 1rem; }
  .notice { margin-left: 1rem; margin-right: 1rem; }
}

/* --- 改善 --- */
.change, .cand { border: 1px solid var(--line-soft); border-radius: var(--radius); padding: .9rem 1rem; margin: .75rem 0; }
.change-head, .cand-head { display: flex; flex-wrap: wrap; gap: .5rem .75rem; align-items: center; font-size: .8125rem; }
.change-head a, .cand-head a { overflow-wrap: anywhere; }
.badge { font-size: .6875rem; padding: .15rem .5rem; border-radius: 10px; background: var(--bg); color: var(--muted); }
.badge.st-proposed { background: #fef7e0; color: #b06000; }
.badge.st-applied  { background: #e6f4ea; color: var(--up); }
.badge.st-failed, .badge.st-rejected { background: #fce8e6; color: var(--down); }
h3.sub { font-size: .8125rem; font-weight: 500; color: var(--muted); margin: 1rem 0 .25rem; }
.rationale { margin: .6rem 0; font-size: .8125rem; }
.diff { display: grid; grid-template-columns: 9rem 1fr; gap: .35rem .75rem; margin: .5rem 0; font-size: .8125rem; }
.diff dt { color: var(--muted); }
.diff dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.change .row { display: flex; gap: .5rem; margin-top: .6rem; }
.change .primary { background: var(--accent); color: #fff; border-color: transparent; font-weight: 500; }
.score { font-size: 1.25rem; font-weight: 500; min-width: 2.5rem; color: var(--accent); }
.cand-meta { font-size: .75rem; margin: .35rem 0 .5rem; }
.reason { font-size: .8125rem; margin: .45rem 0; }
.reason .rule { color: #fff; font-size: .6875rem; padding: .1rem .45rem; border-radius: 3px; margin-right: .5rem; }
.reason .action { margin: .2rem 0 0; font-size: .75rem; }
.badge.st-reverted { background: #f3e8fd; color: #8430ce; }
.effects { margin-top: .6rem; }
.effect { border-top: 1px solid var(--line-soft); padding-top: .5rem; margin-top: .5rem; font-size: .8125rem; }
.effect h4 { margin: 0 0 .35rem; font-size: .75rem; font-weight: 500; color: var(--muted); }
.effect p { margin: .35rem 0; font-size: .75rem; }
.effect table { font-size: .8125rem; }
button.link { border: none; background: none; color: var(--accent); padding: 0; cursor: pointer; font-size: .8125rem; }
dialog.history { width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 48px); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 1rem 1.25rem; }
dialog.history::backdrop { background: rgba(0, 0, 0, .35); }
.history-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.history-head h3 { margin: 0; font-size: 1rem; font-weight: 500; }
.history a { overflow-wrap: anywhere; }
.timeline { list-style: none; margin: .5rem 0 0; padding: 0 0 0 1rem; border-left: 2px solid var(--line-soft); }
.timeline li { position: relative; margin: 0 0 .9rem; font-size: .8125rem; }
.timeline li::before { content: ''; position: absolute; left: calc(-1rem - 6px); top: .35rem; width: 10px; height: 10px; border-radius: 50%; background: var(--line); }
.timeline li.ev-applied::before { background: var(--up); }
.timeline li.ev-reverted::before, .timeline li.ev-failed::before, .timeline li.ev-rejected::before { background: var(--down); }
.timeline li.ev-effect::before { background: var(--accent); }
.timeline .when { display: block; font-size: .6875rem; }
.timeline div { overflow-wrap: anywhere; }
