:root {
  --red: #e8505b;
  --red-bg: #fdeef0;
  --amber: #b8860b;
  --amber-bg: #fdf6e3;
  --blue: #5466d6;
  --text: #1f2430;
  --muted: #7a8195;
  --border: #e4e7ee;
  --bg: #f6f7fa;
  --card: #ffffff;
}

* { box-sizing: border-box; }
/* hidden属性を常に最優先（.login-wrap の display:flex 等に上書きされないように） */
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic", Meiryo, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

/* ---- ログイン ---- */
.login-wrap {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
}
.login-box {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 12px; padding: 40px; width: 380px; text-align: center;
  box-shadow: 0 4px 24px rgba(0,0,0,.06);
}
.login-box h1 { margin: 0 0 4px; font-size: 22px; }
.login-box p { color: var(--muted); margin: 0 0 20px; }
.login-box input {
  width: 100%; padding: 10px 12px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.error { color: var(--red); }

/* ---- ヘッダー ---- */
header {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 12px 24px;
}
.brand { font-size: 17px; display: flex; align-items: center; gap: 8px; }
.brand .sub { color: var(--muted); font-size: 13px; margin-left: 2px; }
.logo-badge {
  display: inline-flex; align-items: center; justify-content: center;
  width: 22px; height: 22px; border-radius: 6px; flex: 0 0 auto;
  background: var(--red); color: #fff; font-weight: 700; font-size: 12px; line-height: 1;
  vertical-align: middle;
}
.login-box .logo-badge { width: 32px; height: 32px; border-radius: 9px; font-size: 16px; }
.header-right { display: flex; gap: 10px; align-items: center; }

select, input[type="number"], input[type="text"], input[type="date"], input[type="password"] {
  padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 13px; background: #fff;
}

/* ---- アプリ全体レイアウト（サイドバー + コンテンツ） ---- */
.app-shell { display: flex; align-items: flex-start; min-height: calc(100vh - 57px); }

.sidebar {
  width: 232px; flex-shrink: 0; background: var(--card);
  border-right: 1px solid var(--border);
  min-height: calc(100vh - 57px);
  padding: 14px 0;
  overflow-y: auto;
}
.sidebar-group-label {
  font-size: 11px; color: var(--muted); font-weight: 700;
  text-transform: uppercase; letter-spacing: .04em;
  padding: 4px 20px 8px;
}
.nav-link, .nav-parent {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; box-sizing: border-box; text-align: left;
  border: none; background: none; cursor: pointer;
  padding: 9px 20px; font-size: 13.5px; color: var(--text);
  text-decoration: none; border-left: 3px solid transparent;
}
.nav-link:hover, .nav-parent:hover { background: var(--bg); }
.nav-link.active { color: var(--red); border-left-color: var(--red); background: var(--red-bg); font-weight: 600; }
.nav-parent.expanded { font-weight: 600; }
.nav-parent .chev { font-size: 10px; color: var(--muted); transition: transform .12s; }
.nav-parent.expanded .chev { transform: rotate(90deg); }
.nav-children { padding-left: 14px; }
.nav-children .nav-link { padding-left: 26px; font-size: 13px; }
.nav-link.disabled {
  color: var(--muted); cursor: default; pointer-events: none;
}
.nav-badge {
  font-size: 10px; background: var(--bg); color: var(--muted);
  border-radius: 4px; padding: 1px 6px; margin-left: 6px; white-space: nowrap;
}

.content { flex: 1; min-width: 0; }
main { padding: 24px; max-width: 1280px; margin: 0 auto; }
.page-panel h2 { margin: 0 0 16px; font-size: 19px; }
.page-crumb { color: var(--muted); font-size: 12px; margin: 0 0 4px; }

.unavailable-notice {
  background: var(--bg); border: 1px dashed var(--border); border-radius: 10px;
  padding: 40px 24px; text-align: center; color: var(--muted); font-size: 13px;
}
.unavailable-notice strong { display: block; color: var(--text); font-size: 15px; margin-bottom: 8px; }

/* ---- オーバービュー: 広告サマリー / 不正クリックの内訳 ---- */
.summary-grid { display: flex; gap: 20px; align-items: flex-start; }
.summary-grid table { flex: 1; }
.cost-save-tile {
  flex: 0 0 260px; background: #e9f7ee; border: 1px solid #bfe6cc;
  border-radius: 10px; padding: 16px;
}
.cost-save-tile .kpi-value { color: #1e7e34; font-size: 24px; font-weight: 700; margin: 4px 0 8px; }
.muted.small { font-size: 12px; line-height: 1.5; }
@media (max-width: 900px) { .summary-grid { flex-direction: column; } .cost-save-tile { flex-basis: auto; width: 100%; } }

.stat-pair { display: flex; gap: 28px; margin-bottom: 12px; }
.stat-item .kpi-value { font-size: 22px; font-weight: 700; }
.change-badge { font-size: 12px; color: var(--muted); }
.change-badge.up { color: var(--red); }
.change-badge.down { color: #1e7e34; }

.chart-legend-list { margin-top: 10px; }
.chart-legend-list .legend-row {
  display: flex; align-items: center; gap: 8px; font-size: 13px; padding: 3px 0;
}
.chart-legend-list .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.chart-legend-list .legend-name { flex: 1; }
.chart-legend-list .legend-pct { font-variant-numeric: tabular-nums; color: var(--muted); }

/* ---- 不正サマリー: ハイライト + ミニカードリスト ---- */
.fraud-highlight-grid { display: grid; grid-template-columns: 1fr 1.3fr; gap: 20px; margin-bottom: 20px; align-items: start; }
@media (max-width: 900px) { .fraud-highlight-grid { grid-template-columns: 1fr; } }
.bar-track { background: var(--bg); border-radius: 4px; height: 6px; overflow: hidden; margin: 10px 0; }
.bar-fill { background: var(--red); height: 100%; border-radius: 4px; }
.mini-cat-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.mini-cat-row:last-child { border-bottom: none; }
.mini-cat-row .mini-cat-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 4px; }
.mini-cat-row .mini-cat-nums { color: var(--muted); }

/* ---- KPI ---- */
.kpi-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 14px; margin-bottom: 20px;
}
.kpi {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px;
}
.kpi-label { color: var(--muted); font-size: 12px; margin-bottom: 6px; }
.kpi-value { font-size: 24px; font-weight: 700; }
.kpi-red .kpi-value { color: var(--red); }
.kpi-amber .kpi-value { color: var(--amber); }

/* ---- カード・グリッド ---- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 18px; margin-bottom: 20px;
}
.card h3 { margin: 0 0 14px; font-size: 15px; }
.card canvas { max-height: 260px; max-width: 100%; }
.grid-2 > div { min-width: 0; }
.grid-2 {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
}
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

.notice {
  background: #eef3fd; border: 1px solid #c9d8f5; border-radius: 8px;
  padding: 10px 14px; margin-bottom: 16px; font-size: 13px;
}
.notice code { background: #fff; padding: 1px 6px; border-radius: 4px; }

/* ---- テーブル ---- */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--muted); font-weight: 600; font-size: 12px; white-space: nowrap; }
th.num, td.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }
tbody tr:hover { background: #fafbfd; }
td.danger { color: var(--red); font-weight: 600; }

.cat-badge {
  display: inline-block; background: var(--red-bg); color: var(--red);
  border-radius: 4px; padding: 1px 7px; font-size: 11px; margin: 1px 2px 1px 0;
  white-space: nowrap;
}
.ua-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.url-cell { max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- ボタン・ツールバー ---- */
.btn {
  display: inline-block; padding: 8px 16px; border-radius: 8px;
  font-size: 13px; cursor: pointer; border: 1px solid var(--border);
  background: #fff; color: var(--text); text-decoration: none;
}
.btn-primary { background: var(--red); border-color: var(--red); color: #fff; font-weight: 600; }
.btn-primary:hover { opacity: .9; }
.btn-ghost:hover { background: var(--bg); }
.toolbar { display: flex; gap: 10px; align-items: center; margin: 12px 0; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 13px; }

.howto {
  background: var(--amber-bg); border: 1px solid #ead9a8; border-radius: 8px;
  padding: 10px 14px; margin: 10px 0; font-size: 13px;
}
.howto ol { margin: 6px 0 0; padding-left: 20px; }

.code-block {
  background: #1f2430; color: #e4e7ee; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.6; padding: 14px 16px; border-radius: 8px;
  overflow-x: auto; white-space: pre; margin: 8px 0;
}

/* ---- ページ内サブタブ（レポートの月次タブ、ブロッキングルールのデフォルト/計測タグ別 等） ---- */
.subtabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.subtab {
  border: none; background: none; padding: 10px 16px;
  font-size: 13.5px; cursor: pointer; color: var(--muted);
  border-bottom: 2px solid transparent;
}
.subtab.active { color: var(--red); border-bottom-color: var(--red); font-weight: 600; }

/* ---- CRUD行（計測タグ管理・パラメータルール・手動除外リスト等） ---- */
.crud-row {
  display: flex; align-items: center; gap: 8px; padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.crud-row:last-child { border-bottom: none; }
.crud-row input, .crud-row select { flex: 1; min-width: 0; }
.crud-row .btn-remove {
  border: none; background: none; color: var(--red); cursor: pointer;
  font-size: 16px; padding: 2px 8px; flex: 0 0 auto;
}
.status-pill {
  display: inline-block; font-size: 11px; padding: 2px 9px; border-radius: 10px;
  background: #e6f4ea; color: #1e7e34;
}
.status-pill.status-pill-muted { background: #f1f1f4; color: var(--muted); }

/* ---- 設定 ---- */
.field { display: flex; align-items: center; gap: 10px; margin: 8px 0; font-size: 13px; }
.field input { width: 110px; }
.check { display: block; margin: 8px 0; font-size: 13px; }

/* ---- 設定＞アドネットワーク（左に媒体一覧、右に詳細のマスター・ディテール） ---- */
.ad-network-layout { display: flex; gap: 16px; align-items: flex-start; }
.ad-network-nav {
  flex: 0 0 220px; background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  overflow: hidden;
}
.ad-network-nav-item {
  display: flex; align-items: center; gap: 8px; width: 100%; text-align: left;
  padding: 10px 14px; font-size: 13px; border: none; border-left: 3px solid transparent;
  border-bottom: 1px solid var(--border); background: none; color: var(--text); cursor: pointer;
}
.ad-network-nav-item:last-child { border-bottom: none; }
.ad-network-nav-item:hover { background: var(--bg); }
.ad-network-nav-item.active { color: var(--red); border-left-color: var(--red); background: var(--red-bg); font-weight: 600; }
.ad-network-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--border); flex: 0 0 auto; }
.ad-network-dot.is-set { background: #1e7e34; }
.ad-network-detail { flex: 1; min-width: 0; }
@media (max-width: 900px) { .ad-network-layout { flex-direction: column; } .ad-network-nav { flex: none; width: 100%; } }
.toggle-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-label small { color: var(--muted); display: block; }

/* トグルスイッチ */
.switch { display: inline-block; position: relative; width: 42px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; inset: 0; background: #cfd4e0; border-radius: 24px;
  cursor: pointer; transition: .15s;
}
.slider::before {
  content: ""; position: absolute; width: 18px; height: 18px;
  left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s;
}
.switch input:checked + .slider { background: var(--red); }
.switch input:checked + .slider::before { transform: translateX(18px); }
