/* 運営管理画面（docs/ADMIN_SPEC.md）。配色・字体は DESIGN.md §2.1〜2.2・§3 のネイビーに合わせる。外部フォント・CDN は読まない。 */
:root {
  --frame-bg: #283462;
  --frame-bg-deep: #1F2A52;
  --frame-text: rgba(255, 255, 255, 0.78);
  --frame-text-strong: #FFFFFF;
  --frame-hover: rgba(255, 255, 255, 0.08);
  --frame-selected: rgba(255, 255, 255, 0.16);
  --frame-divider: rgba(255, 255, 255, 0.10);
  --bg: #FFFFFF;
  --bg-subtle: #F8F8F8;
  --bg-muted: #F2F2F2;
  --text: #1D1C1D;
  --text-secondary: #616061;
  --text-tertiary: #868686;
  --border: rgba(29, 28, 29, 0.13);
  --border-strong: rgba(29, 28, 29, 0.30);
  --link: #3F5BD9;
  --link-hover: #2F47B8;
  --accent: #3F5BD9;
  --primary: #3F5BD9;
  --primary-hover: #2F47B8;
  --success: #1F9D6A;
  --danger: #E01E5A;
  --warning-bg: #FFF8E1;
  --warning-border: #F2C744;
  --warning-text: #7A5900;
  --radius-xs: 6px;
  --radius-sm: 10px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --shadow-pop: 0 0 0 1px rgba(29, 28, 29, 0.08), 0 8px 24px rgba(0, 0, 0, 0.12);
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Segoe UI", "Yu Gothic UI", Meiryo, "Noto Sans JP", sans-serif;
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  font-feature-settings: "palt" 0;
  -webkit-font-smoothing: antialiased;
  line-break: strict;
  overflow-wrap: anywhere;
}
[hidden] { display: none !important; }
a { color: var(--link); }
a:hover { color: var(--link-hover); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sidebar :focus-visible, .btn-frame:focus-visible { outline-color: var(--frame-text-strong); }
h1, h2, h3, p { margin: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.skip-link { position: absolute; left: 8px; top: -48px; z-index: 50; padding: 8px 12px; border-radius: var(--radius-sm); background: var(--text); color: #fff; }
.skip-link:focus { top: 8px; }

.nav-icon { display: inline-flex; width: 20px; height: 20px; flex: none; }
.nav-icon svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.5; stroke-linecap: round; stroke-linejoin: round; }

/* ボタン */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--bg); color: var(--text); cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--bg-subtle); }
.btn:disabled { cursor: default; opacity: 0.55; background: var(--bg-muted); }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; font-weight: 700; }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-primary:disabled { background: var(--primary); opacity: 0.5; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--link); }
.btn-ghost:hover { background: var(--bg-subtle); color: var(--link-hover); }
.btn-ghost:disabled { background: transparent; color: var(--text-secondary); }
.btn-block { width: 100%; }
.btn-icon { width: 36px; padding: 0; border-color: var(--border); color: var(--text-secondary); }
.btn-icon:hover { color: var(--text); }
.btn-sm { min-height: 30px; padding: 2px 10px; font-size: 13px; }
.btn-frame { border-color: var(--frame-divider); background: transparent; color: var(--frame-text); }
.btn-frame:hover { background: var(--frame-hover); color: var(--frame-text-strong); }
.btn-link { display: inline; min-height: 0; padding: 0; border: 0; background: none; color: var(--link); text-decoration: underline; text-underline-offset: 2px; font: inherit; cursor: pointer; }
.btn-link:hover { color: var(--link-hover); background: none; }
.btn-link.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

/* 入力 */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; font-weight: 700; color: var(--text-secondary); }
.field input, .field select {
  min-height: 40px; padding: 8px 12px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm); background: var(--bg);
}
.field input::placeholder { color: var(--text-tertiary); }
.field input:focus, .field select:focus { border-color: var(--text); outline: none; }
.field-inline { flex-direction: row; align-items: center; gap: 10px; }
.field-inline input { flex: 1 1 240px; min-width: 0; }

/* ログイン */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; background: var(--frame-bg); }
.auth-card { width: 100%; max-width: 420px; padding: 32px 28px 24px; border-radius: var(--radius-lg); background: var(--bg); box-shadow: var(--shadow-pop); }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text-secondary); }
.auth-brand img { border-radius: 10px; }
.auth-heading { margin: 16px 0 12px; font-size: 22px; font-weight: 700; line-height: 1.3; }
.auth-lead { color: var(--text); line-height: 1.7; }
.auth-note { margin-top: 10px; font-size: 13px; color: var(--text-secondary); line-height: 1.6; }
.auth .btn-block { margin-top: 16px; }
/* Google でログイン。白地に G の印（Google の配色）。無効の間は押せない見た目にする */
.btn-google { min-height: 44px; gap: 10px; font-weight: 700; }
.btn-google:disabled { opacity: 0.6; }
.google-mark { display: inline-flex; width: 20px; height: 20px; flex: none; }
.google-mark svg { width: 20px; height: 20px; }
.auth-status { min-height: 1.6em; margin-top: 14px; font-size: 13px; color: var(--text-secondary); }
.auth-status.is-error { color: var(--danger); }
.auth-status.is-ok { color: var(--success); }

/* シェル */
.shell { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; background: linear-gradient(to right, var(--frame-bg) var(--sidebar-w), var(--bg) var(--sidebar-w)); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 16px 12px; background: var(--frame-bg); color: var(--frame-text); }
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 14px; color: var(--frame-text-strong); font-weight: 700; font-size: 16px; }
.sidebar-brand img { border-radius: 8px; }
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding-top: 8px; border-top: 1px solid var(--frame-divider); }
.nav-item { display: flex; align-items: center; gap: 10px; min-height: 36px; padding: 6px 10px; border-radius: var(--radius-sm); color: var(--frame-text); text-decoration: none; }
.nav-item:hover { background: var(--frame-hover); color: var(--frame-text-strong); }
.nav-item[aria-current="page"] { background: var(--frame-selected); color: var(--frame-text-strong); font-weight: 700; }
.sidebar-account { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 14px 10px 0; border-top: 1px solid var(--frame-divider); font-size: 13px; }
.account-email { color: var(--frame-text-strong); word-break: break-all; }
.sidebar-account .btn-frame { justify-content: flex-start; margin-top: 4px; }

.main { min-width: 0; padding: 28px 32px 48px; }
.main:focus { outline: none; }
.screen-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.screen-title { font-size: 22px; font-weight: 700; line-height: 1.3; }
.screen-sub { margin-top: 6px; max-width: 72ch; font-size: 13px; line-height: 1.6; color: var(--text-secondary); }
.screen-tools { display: flex; align-items: center; gap: 10px; flex: none; }
.updated-at { font-size: 12px; color: var(--text-secondary); font-variant-numeric: tabular-nums; }
.screen-body { padding-top: 20px; display: flex; flex-direction: column; gap: 20px; }
.search-row, .filter-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding-top: 20px; }
.search-row .field { flex: 1 1 320px; }

/* 状態 */
.mode-badge, .pill {
  display: inline-flex; align-items: center; gap: 4px; min-height: 22px; padding: 1px 10px;
  border-radius: var(--radius-pill); font-size: 12px; font-weight: 700; line-height: 18px; white-space: nowrap;
}
.mode-badge:empty { display: none; }
.mode-live { background: #FDE2E6; color: #8E1230; }
.mode-test { background: #FFF1BF; color: #6B4E00; }
.mode-unconfigured { background: #E8E8E8; color: #4A4A4A; }
.sidebar .mode-badge { align-self: flex-start; }
.pill-neutral { background: var(--bg-muted); color: var(--text-secondary); }
.pill-ok { background: rgba(31, 157, 106, 0.14); color: #0F6B47; }
.pill-info { background: rgba(63, 91, 217, 0.12); color: #2F47B8; }
.pill-warn { background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--warning-border); }
.pill-danger { background: rgba(224, 30, 90, 0.10); color: #A3123F; }

.notice { padding: 12px 14px; border-radius: var(--radius-md); border: 1px solid var(--border); background: var(--bg-subtle); font-size: 14px; line-height: 1.6; }
.notice.is-error { border-color: rgba(224, 30, 90, 0.35); background: rgba(224, 30, 90, 0.06); color: #8E1230; }
.notice.is-warn { border-color: var(--warning-border); background: var(--warning-bg); color: var(--warning-text); }
.notice.is-muted { color: var(--text-secondary); }
.notice .btn { margin-left: 10px; vertical-align: middle; }
.state-loading { display: flex; align-items: center; gap: 10px; color: var(--text-secondary); font-size: 14px; }
.state-loading::before { content: ""; width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--border-strong); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .state-loading::before { animation: none; } }
.state-empty { padding: 28px 16px; text-align: center; color: var(--text-secondary); border: 1px dashed var(--border-strong); border-radius: var(--radius-md); }

/* カード・KPI */
.card { border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 15px; font-weight: 700; }
.card-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 10px; }
.card-note { font-size: 12px; color: var(--text-secondary); line-height: 1.6; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.kpi-grid-visits { grid-template-columns: repeat(3, minmax(0, 1fr)); }   /* 集客「LP の訪問」の 6 つだけ 3 列 × 2 行 */
.kpi { min-width: 0; padding: 12px 14px; border-radius: var(--radius-md); background: var(--bg-subtle); }
.kpi-label { font-size: 12px; font-weight: 700; color: var(--text-secondary); overflow-wrap: anywhere; }
.kpi-value { margin-top: 4px; font-size: 24px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.kpi-value small { font-size: 13px; font-weight: 400; color: var(--text-secondary); margin-left: 2px; }
.kpi-sub { margin-top: 4px; font-size: 12px; color: var(--text-secondary); overflow-wrap: anywhere; }
.kpi-value.is-muted { color: var(--text-secondary); font-size: 18px; }

.meta-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; font-size: 13px; color: var(--text-secondary); }
.meta-row strong { color: var(--text); font-variant-numeric: tabular-nums; }
.small { font-size: 13px; }

/* 期間の切替（集客） */
.segmented { display: inline-flex; border: 1px solid var(--border-strong); border-radius: var(--radius-sm); overflow: hidden; background: var(--bg); }
.segmented .seg { min-height: 36px; padding: 6px 14px; border: 0; border-right: 1px solid var(--border); background: transparent; color: var(--text-secondary); cursor: pointer; white-space: nowrap; }
.segmented .seg:last-child { border-right: 0; }
.segmented .seg:hover { background: var(--bg-subtle); color: var(--text); }
.segmented .seg[aria-pressed="true"] { background: rgba(63, 91, 217, 0.12); color: var(--link-hover); font-weight: 700; }
.segmented .seg:focus-visible { outline-offset: -2px; }

/* 日別の棒グラフ（集客）。文字の大きさは px 固定にし、幅は描画時に測る */
.chart { width: 100%; min-height: 220px; }
.chart-svg { display: block; width: 100%; height: auto; }
.chart-grid { stroke: var(--border); stroke-width: 1; }
.chart-axis { stroke: var(--border-strong); stroke-width: 1; }
.chart-label { fill: var(--text-secondary); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }
.chart-bar { fill: var(--primary); }
.chart-hit { fill: transparent; }
.chart-bar-group:hover .chart-bar { fill: var(--primary-hover); }
.chart-bar-group:hover .chart-hit { fill: rgba(63, 91, 217, 0.06); }
.chart-data > summary { cursor: pointer; font-size: 13px; color: var(--link); }
.chart-data > summary:hover { color: var(--link-hover); }
.chart-data .table-wrap { margin-top: 10px; }

/* 計測用リンク（集客） */
.utm-card { margin-top: 20px; }
.utm-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.utm-output { display: flex; align-items: flex-start; gap: 10px; }
.utm-url { display: block; flex: 1 1 auto; min-width: 0; min-height: 40px; padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-subtle); font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.6; word-break: break-all; }
.utm-url.is-url { user-select: all; }
.utm-url.is-empty { color: var(--text-secondary); font-family: var(--font); font-size: 13px; }
.utm-output .btn { flex: none; }
.utm-status { min-height: 1.6em; font-size: 13px; color: var(--text-secondary); }
.utm-status.is-error { color: var(--danger); }
.utm-status.is-ok { color: var(--success); }

/* 表 */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius-md); }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th, table.data td { padding: 10px 12px; text-align: left; vertical-align: top; border-bottom: 1px solid var(--border); }
table.data th { font-size: 12px; font-weight: 700; color: var(--text-secondary); background: var(--bg-subtle); white-space: nowrap; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover td { background: var(--bg-subtle); }
table.data td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data th.num { text-align: right; }
table.data td.nowrap { white-space: nowrap; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }
.muted { color: var(--text-secondary); }
.flags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.pager { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 13px; color: var(--text-secondary); }

/* リスト・定義リスト */
.plain-list { margin: 0; padding-left: 1.2em; display: flex; flex-direction: column; gap: 4px; }
.dl { display: grid; grid-template-columns: minmax(110px, 160px) minmax(0, 1fr); gap: 6px 14px; margin: 0; font-size: 14px; }
.dl dt { color: var(--text-secondary); font-size: 13px; }
.dl dd { margin: 0; }

/* 診断 */
.report { border: 1px solid var(--border); border-radius: var(--radius-md); }
.report > summary { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; padding: 12px 16px; cursor: pointer; list-style: none; }
.report > summary::-webkit-details-marker { display: none; }
.report > summary::before { content: ""; width: 8px; height: 8px; border-right: 1.5px solid var(--text-secondary); border-bottom: 1.5px solid var(--text-secondary); transform: rotate(-45deg); transition: transform 0.12s; margin-right: 2px; }
.report[open] > summary::before { transform: rotate(45deg); }
.report > summary:hover { background: var(--bg-subtle); }
.report-body { padding: 0 16px 14px; display: flex; flex-direction: column; gap: 10px; }
.report-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }

/* 詳細パネル */
.detail-backdrop { position: fixed; inset: 0; z-index: 30; background: rgba(29, 28, 29, 0.35); }
.detail {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 31;
  width: min(560px, 100vw); display: flex; flex-direction: column;
  background: var(--bg); box-shadow: var(--shadow-pop);
}
.detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 18px 20px 14px; border-bottom: 1px solid var(--border); }
.detail-kicker { font-size: 12px; font-weight: 700; color: var(--text-secondary); }
.detail-title { font-size: 18px; font-weight: 700; line-height: 1.33; word-break: break-all; }
.detail-tools { display: flex; gap: 8px; flex: none; }
.detail-body { flex: 1; overflow-y: auto; padding: 16px 20px 32px; display: flex; flex-direction: column; gap: 16px; }
.detail-section { display: flex; flex-direction: column; gap: 10px; }
.detail-section h3 { font-size: 15px; font-weight: 700; line-height: 1.4; display: flex; align-items: center; gap: 8px; }
.sub-list { display: flex; flex-direction: column; gap: 10px; }
.sub-item { padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-md); background: var(--bg-subtle); display: flex; flex-direction: column; gap: 6px; }
.sub-item-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.sub-item .dl { font-size: 13px; }

.toast { position: fixed; left: 50%; bottom: 20px; z-index: 40; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 10px 16px; border-radius: var(--radius-sm); background: var(--text); color: #fff; font-size: 13px; box-shadow: var(--shadow-pop); }
.toast:empty { display: none; }

/* モバイル */
@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; background: var(--bg); }
  .sidebar { position: static; height: auto; padding: 10px 12px 8px; gap: 8px; }
  .sidebar-brand { padding: 2px 4px 8px; }
  .sidebar-nav { flex-direction: row; overflow-x: auto; gap: 4px; padding: 8px 0 4px; scrollbar-width: none; }
  .sidebar-nav::-webkit-scrollbar { display: none; }
  .nav-item { flex: none; min-height: 34px; padding: 4px 8px; gap: 6px; font-size: 14px; }
  .sidebar-account { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 8px 4px 0; }
  .account-email { flex: 1 1 160px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar-account .btn-frame { margin-top: 0; min-height: 32px; padding: 2px 10px; font-size: 13px; }
  .main { padding: 18px 16px 40px; }
  .screen-head { flex-direction: column; }
  .screen-tools { align-self: flex-end; }
  .search-row .btn, .filter-row .field { flex: 1 1 auto; }
  .field-inline { flex-wrap: wrap; }
  .field-inline input { flex-basis: 100%; }
  /* 390px では小さい KPI を 2 列に。主要な 1 つ（.kpi-wide）だけ 1 行を使う */
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .kpi-grid-visits { grid-template-columns: repeat(2, minmax(0, 1fr)); }   /* 訪問の 6 つは 2 列 × 3 行 */
  .kpi { padding: 10px 12px; }
  .kpi-wide { grid-column: 1 / -1; }
  .kpi-value { font-size: 20px; }
  .kpi-value.is-muted { font-size: 16px; }
  .segmented .seg { padding: 6px 12px; }
  .utm-form { grid-template-columns: 1fr; }
  .utm-output { flex-wrap: wrap; }
  .utm-output .btn { flex: 1 1 auto; }
  .dl { grid-template-columns: 1fr; gap: 2px; }
  .dl dt { margin-top: 6px; }
  .detail { width: 100vw; }
  .detail-body { padding: 14px 16px 28px; }
  .table-wrap { border: 0; }
  table.stack, table.stack tbody, table.stack tr, table.stack td { display: block; width: 100%; }
  table.stack thead { display: none; }
  table.stack tr { margin-bottom: 10px; padding: 6px 12px; border: 1px solid var(--border); border-radius: var(--radius-md); }
  table.stack td { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--border); text-align: left; white-space: normal; }
  table.stack td:last-child { border-bottom: 0; }
  table.stack td::before { content: attr(data-label); font-size: 12px; font-weight: 700; color: var(--text-secondary); }
  table.stack td.num { text-align: left; }
  table.stack tbody tr:hover td { background: transparent; }
}
@media (max-width: 420px) {
  .nav-item .nav-icon { display: none; }
}
