/* 共有ダッシュボード。状態色は good/warning/serious/critical に固定（dataviz の参照パレット）。
   CSP が style-src 'self' なので外部フォント・CDN は使わない（システムフォント＋インライン SVG）。 */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface-1: #ffffff;
  --surface-2: #f7f8fa;
  --surface-3: #eef0f3;
  --border: #e3e6eb;
  --border-strong: #cfd4dc;
  --text-primary: #111827;
  --text-secondary: #4b5563;
  --text-muted: #6b7280;
  --ink: #0f172a;             /* ヘッダーの地 */
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-soft: #eef2ff;
  --good: #16a34a;
  --warning: #f59e0b;
  --serious: #ea7a3c;
  --critical: #dc2626;
  --good-text: #15803d;
  --critical-text: #b91c1c;
  --warning-text: #a16207;
  --good-soft: #ecfdf3;
  --warning-soft: #fffbeb;
  --critical-soft: #fef2f2;
  --neutral: #c4c9d2;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text-primary); font-size: 14px; line-height: 1.6; -webkit-font-smoothing: antialiased; }
a { color: var(--accent); }
.wrap { max-width: 1320px; margin: 0 auto; padding: 0 24px 64px; }
.num, td, .v, .big, .val { font-variant-numeric: tabular-nums; }

/* ── ヘッダー ── */
.top { position: sticky; top: 0; z-index: 30; background: var(--ink); color: #fff; }
.top .wrap { display: flex; align-items: center; gap: 28px; height: 60px; padding-bottom: 0; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 15px; letter-spacing: .02em; white-space: nowrap; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); display: grid; place-items: center; }
.brand-mark svg { width: 15px; height: 15px; }
nav { display: flex; gap: 2px; height: 100%; }
nav a { display: flex; align-items: center; padding: 0 14px; text-decoration: none; color: rgba(255, 255, 255, .66); font-weight: 600; font-size: 13.5px; border-bottom: 2px solid transparent; white-space: nowrap; }
nav a:hover { color: #fff; }
nav a[aria-current="page"] { color: #fff; border-bottom-color: #a5b4fc; }
.sync { margin-left: auto; display: flex; align-items: center; gap: 10px; min-width: 0; }
.sync-status { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; color: rgba(255, 255, 255, .85); background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .14); padding: 5px 12px; border-radius: 999px; white-space: nowrap; min-width: 0; overflow: hidden; }
.sync-status #updated { overflow: hidden; text-overflow: ellipsis; }
.sync-status .dot { flex: none; }
.sync-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 3px rgba(74, 222, 128, .2); }
.sync-status.loading .dot { background: #fbbf24; box-shadow: 0 0 0 3px rgba(251, 191, 36, .2); }
.sync-status.error .dot, .sync-status.stale .dot { background: #f87171; box-shadow: 0 0 0 3px rgba(248, 113, 113, .2); }
.btn-refresh { flex: none; display: inline-flex; align-items: center; gap: 6px; font: inherit; font-size: 13px; font-weight: 700; color: var(--ink); background: #fff; border: 0; border-radius: var(--radius-sm); padding: 7px 14px; cursor: pointer; white-space: nowrap; }
.btn-refresh:hover { background: #e0e7ff; }
.btn-refresh:disabled { opacity: .7; cursor: progress; }
.btn-refresh svg { width: 15px; height: 15px; }
.btn-refresh:disabled svg { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.logout { flex: none; color: rgba(255, 255, 255, .6); font-size: 12.5px; text-decoration: none; white-space: nowrap; }
.logout:hover { color: #fff; }

/* ── 見出し・共通部品 ── */
.page-head { padding: 32px 0 20px; }
h1 { font-size: 24px; line-height: 1.35; margin: 0 0 6px; letter-spacing: .01em; }
h2 { font-size: 16px; margin: 40px 0 14px; display: flex; align-items: center; gap: 10px; }
h2::before { content: ""; width: 4px; height: 18px; border-radius: 2px; background: var(--accent); }
.lead { color: var(--text-secondary); margin: 0; max-width: 900px; }
.note { color: var(--text-muted); font-size: 12px; }
.panel { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.err { background: var(--critical-soft); border: 1px solid #fecaca; color: var(--critical-text); border-radius: var(--radius); padding: 14px 18px; margin-top: 24px; }
.loading-box { padding: 80px 0; text-align: center; color: var(--text-muted); }
.pos { color: var(--good-text); }
.neg { color: var(--critical-text); }
button, select { font: inherit; color: var(--text-primary); }
select { background: var(--surface-1); border: 1px solid var(--border-strong); border-radius: var(--radius-sm); padding: 6px 30px 6px 10px; cursor: pointer; font-size: 13px; }
select:focus-visible, button:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ── 案件の KPI ── */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 16px; }
.tile { padding: 0; overflow: hidden; }
.tile-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 14px 20px; border-bottom: 1px solid var(--border); }
.tile-head h3 { margin: 0; font-size: 15px; }
.tile-meta { display: flex; gap: 6px; flex-wrap: wrap; }
.meta-pill { font-size: 11.5px; color: var(--text-secondary); background: var(--surface-3); border-radius: 999px; padding: 2px 10px; white-space: nowrap; }
.kpi { width: 100%; border-collapse: collapse; font-size: 13px; }
.kpi th, .kpi td { padding: 9px 20px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.kpi tr:last-child td { border-bottom: 0; }
.kpi thead th { font-size: 11.5px; color: var(--text-muted); font-weight: 600; background: var(--surface-2); }
.kpi th:first-child, .kpi td:first-child { text-align: left; color: var(--text-secondary); font-weight: 600; }
.kpi td { font-weight: 600; }
.kpi tr.profit td { font-weight: 800; font-size: 14px; }

/* ── ツールバー（絞り込み） ── */
.toolbar { margin: 28px 0 16px; display: flex; flex-wrap: wrap; align-items: flex-start; gap: 14px 22px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 11.5px; color: var(--text-muted); font-weight: 600; }
.seg { display: inline-flex; background: var(--surface-3); border-radius: var(--radius-sm); padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; border-radius: 6px; padding: 5px 12px; font-size: 13px; font-weight: 600; color: var(--text-secondary); cursor: pointer; white-space: nowrap; }
.seg button:hover { color: var(--text-primary); }
.seg button[aria-pressed="true"] { background: var(--surface-1); color: var(--accent); box-shadow: 0 1px 3px rgba(16, 24, 40, .12); }

/* ── 表 ── */
.tablecard { background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.tablewrap { overflow-x: auto; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.tablecard .tablewrap { border: 0; border-radius: 0; box-shadow: none; }
table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 13px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: right; white-space: nowrap; }
thead th { background: var(--surface-2); color: var(--text-secondary); font-weight: 700; font-size: 12px; }
thead tr.group th { font-size: 11.5px; color: var(--text-muted); text-align: center; border-bottom: 1px solid var(--border); }
thead tr.group th.g { border-left: 1px solid var(--border); }
td.gs, th.gs { border-left: 1px solid var(--border); }
tbody tr:hover td { background: #fafbff; }
tbody tr:last-child td { border-bottom: 0; }
td:first-child, th:first-child, td.l, th.l { text-align: left; }
td.wrap-name { white-space: normal; min-width: 200px; line-height: 1.55; }
tr.sum td { font-weight: 700; background: var(--surface-2); }
.dim { color: var(--text-muted); }

/* クリエイティブ表: 左の「広告」列は横スクロールしても残す */
.ctable td.ad, .ctable th.ad { position: sticky; left: 0; z-index: 2; background: var(--surface-1); box-shadow: 1px 0 0 var(--border); }
.ctable thead th.ad { background: var(--surface-2); z-index: 3; }
.ctable tbody tr:hover td.ad { background: #fafbff; }
.adcell { display: flex; gap: 12px; align-items: center; min-width: 260px; max-width: 320px; white-space: normal; }
.thumb { flex: none; width: 52px; height: 52px; border-radius: 8px; overflow: hidden; background: var(--surface-3); display: grid; place-items: center; color: var(--text-muted); font-size: 10px; border: 1px solid var(--border); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
a.thumb:hover { border-color: var(--accent); }
.adname { font-weight: 700; font-size: 12.5px; line-height: 1.45; word-break: break-all; }
.adsub { color: var(--text-muted); font-size: 11.5px; margin-top: 3px; display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.adsub .chip { font-size: 11.5px; }
.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; color: var(--text-secondary); white-space: nowrap; }
.chip::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--neutral); }
.chip.on { color: var(--good-text); }
.chip.on::before { background: var(--good); }
.pill { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; padding: 3px 10px; border-radius: 999px; white-space: nowrap; background: var(--surface-3); color: var(--text-secondary); }
.pill.good { background: var(--good-soft); color: var(--good-text); }
.pill.warn { background: var(--warning-soft); color: var(--warning-text); }
.pill.stop { background: var(--critical-soft); color: var(--critical-text); }
.judge-cell { white-space: normal; min-width: 170px; max-width: 240px; text-align: left; }
.judge-cell .why { display: block; font-size: 11.5px; color: var(--text-muted); margin-top: 4px; line-height: 1.45; }

/* ページ送り */
.pager { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; border-top: 1px solid var(--border); background: var(--surface-2); font-size: 13px; }
.pager-info { color: var(--text-secondary); }
.pager-info b { color: var(--text-primary); }
.pager-nav { display: flex; align-items: center; gap: 4px; }
.pager-nav button { min-width: 36px; height: 36px; padding: 0 10px; border: 1px solid var(--border); background: var(--surface-1); border-radius: var(--radius-sm); cursor: pointer; font-weight: 600; font-size: 13px; }
.pager-nav button.arrow { font-size: 18px; line-height: 1; }
.pager-nav button:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
.pager-nav button[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.pager-nav button:disabled { opacity: .4; cursor: default; }
.pager-nav .gap { padding: 0 4px; color: var(--text-muted); }
.pager-size { display: flex; align-items: center; gap: 8px; color: var(--text-secondary); }
.empty { padding: 48px; text-align: center; color: var(--text-muted); }

/* ── 撤退ライン ── */
.hero { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.cond-label { font-size: 12px; font-weight: 700; color: var(--text-muted); letter-spacing: .02em; }
.big { font-size: 36px; font-weight: 800; line-height: 1.2; margin: 10px 0 4px; letter-spacing: -.01em; }
.meter { height: 12px; background: var(--surface-3); border-radius: 6px; overflow: hidden; margin: 14px 0 6px; }
.meter > span { display: block; height: 100%; border-radius: 6px; }
.meter-scale { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--text-muted); }
.status { display: inline-flex; gap: 6px; align-items: center; font-weight: 700; font-size: 12.5px; padding: 3px 10px; border-radius: 999px; background: var(--surface-3); margin-top: 10px; }
.status .dot { width: 8px; height: 8px; border-radius: 50%; }
.months { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; margin-top: 14px; }
.month { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 4px; text-align: center; font-size: 11px; color: var(--text-secondary); background: var(--surface-1); }
.month b { display: block; font-size: 13px; margin: 2px 0; }
.month.black { background: var(--good-soft); border-color: #bbf7d0; }
.month.red { background: var(--critical-soft); border-color: #fecaca; }
.month.future { border-style: dashed; color: var(--text-muted); background: transparent; }
.month.now { box-shadow: 0 0 0 2px var(--accent); }
.chart { width: 100%; height: auto; display: block; }
.chart text { fill: var(--text-muted); font-size: 11px; }
.chart text.val { fill: var(--text-primary); font-weight: 700; }
.chart .grid { stroke: var(--border); stroke-width: 1; }
.chart .zero { stroke: var(--border-strong); stroke-width: 1.5; }
.legend { display: flex; gap: 18px; font-size: 12px; color: var(--text-secondary); margin-top: 10px; flex-wrap: wrap; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; vertical-align: -2px; }
.tip { position: fixed; pointer-events: none; background: var(--ink); color: #fff; border-radius: var(--radius-sm); padding: 6px 10px; font-size: 12px; box-shadow: 0 6px 20px rgba(0, 0, 0, .2); display: none; z-index: 40; }
.rules { background: var(--surface-1); border: 1px solid var(--border); border-left: 4px solid var(--accent); border-radius: var(--radius); padding: 6px 20px; box-shadow: var(--shadow); color: var(--text-secondary); }

/* ── プラン ── */
.checks { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.check { display: flex; flex-direction: column; }
.check h3 { margin: 0; font-size: 12.5px; color: var(--text-muted); font-weight: 700; }
.check .val { font-size: 22px; font-weight: 800; margin: 8px 0 4px; line-height: 1.35; }
.check ul { margin: 10px 0 0; padding: 12px 0 0 18px; font-size: 12.5px; color: var(--text-secondary); border-top: 1px solid var(--border); }
.check li + li { margin-top: 4px; }
.check li.ok::marker { content: "✓  "; color: var(--good-text); font-weight: 700; }
.check li.ng::marker { content: "✗  "; color: var(--critical-text); font-weight: 700; }
.timeline { display: grid; gap: 10px; position: relative; }
.stage { display: grid; grid-template-columns: 220px 1fr; gap: 16px; background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; box-shadow: var(--shadow); }
.stage.now { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.stage.done { opacity: .6; }
.stage h3 { margin: 0 0 4px; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stage .when { color: var(--text-muted); font-size: 12px; }
.stage ul { margin: 0; padding-left: 18px; color: var(--text-secondary); }
.stage li + li { margin-top: 3px; }
.gate { display: flex; gap: 12px; align-items: center; padding: 4px 0 4px 22px; color: var(--text-secondary); font-size: 13px; }
.gate::before { content: ""; width: 11px; height: 11px; transform: rotate(45deg); border: 2px solid var(--border-strong); background: var(--surface-1); flex: none; }
.gate.key::before { border-color: var(--accent); background: var(--accent-soft); }
.gate b { color: var(--text-primary); }
.badge-now { background: var(--accent); color: #fff; font-size: 11px; padding: 2px 9px; border-radius: 999px; font-weight: 700; }
.tasks { padding: 4px 20px; }
.task { display: flex; gap: 16px; align-items: baseline; padding: 12px 0; border-bottom: 1px solid var(--border); }
.task:last-child { border-bottom: 0; }
.task .d { color: var(--accent); font-weight: 700; width: 64px; flex: none; font-size: 13px; }

/* ── ログイン ── */
.login-page { min-height: 100vh; display: grid; place-items: center; background: var(--ink); padding: 24px; }
.login { width: 100%; max-width: 380px; padding: 32px; }
.login h1 { font-size: 20px; margin-bottom: 4px; }
.login label { display: block; font-size: 12px; font-weight: 700; color: var(--text-secondary); margin-top: 20px; }
.login input { width: 100%; font: inherit; padding: 11px 12px; border-radius: var(--radius-sm); border: 1px solid var(--border-strong); background: var(--surface-1); color: var(--text-primary); margin: 6px 0 16px; }
.login input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
.login button { width: 100%; padding: 11px; background: var(--accent); color: #fff; border: 0; border-radius: var(--radius-sm); font-weight: 700; cursor: pointer; }
.login button:hover { background: var(--accent-hover); }
.login #msg { color: var(--critical-text); min-height: 1em; margin: 10px 0 0; }

@media (max-width: 1100px) {
  .top .wrap { height: auto; flex-wrap: wrap; gap: 6px 16px; padding-top: 10px; padding-bottom: 8px; }
  nav { height: 40px; order: 3; width: 100%; overflow-x: auto; }
  nav a { padding: 0 10px; }
}
@media (max-width: 760px) {
  .sync-status .label { display: none; }
}
@media (max-width: 640px) {
  .wrap { padding: 0 14px 48px; }
  .tiles { grid-template-columns: 1fr; }
  .kpi th, .kpi td { padding: 8px 12px; }
  .stage { grid-template-columns: 1fr; gap: 8px; }
  .months { grid-template-columns: repeat(4, 1fr); }
  .big { font-size: 28px; }
  .pager { justify-content: center; }
  .adcell { min-width: 190px; gap: 8px; }
  .thumb { width: 40px; height: 40px; }
  .sync { gap: 6px; }
  .btn-refresh { padding: 7px 10px; }
  .brand { font-size: 14px; }
}
