:root {
  color-scheme: light;
  --page: #f9f9f9;
  --surface: #ffffff;
  --ink: #191919;
  --ink-2: #666666;
  --grid: #e7e7e7;
  --axis: #c2c2c2;
  --border: rgba(11, 11, 11, 0.10);
  --s1: #257de0;   /* 連携室の営業 */
  --s2: #f47230;   /* 院長の病院営業 */
  --s3: #00b894;   /* お礼参り */
  --q1: #84b9f3;   /* 相談（同じ青の薄い段） */
  --q2: #1b64be;   /* 新患（同じ青の濃い段） */
  --warn: #dc3c3d;
  --good: #006c10;
  --accent-wash: rgba(37, 125, 224, 0.08);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --page: #0b0b0b;
    --surface: #191919;
    --ink: #efefef;
    --ink-2: #9c9c9c;
    --grid: #303030;
    --axis: #474747;
    --border: rgba(255, 255, 255, 0.10);
    --s1: #338ced;
    --s2: #e76624;
    --s3: #00a888;
    --q1: #1757ac;
    --q2: #6aabf1;
    --warn: #eb6263;
    --good: #53c556;
    --accent-wash: rgba(51, 140, 237, 0.14);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 15px;
  line-height: 1.6;
}
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px 0;
  position: sticky; top: 0; z-index: 5;
}
.head-row { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
h1 { font-size: 19px; margin: 0; font-weight: 700; }
.built { color: var(--ink-2); font-size: 13px; }
.spacer { flex: 1; }
select, input[type=search] {
  font: inherit; font-size: 14px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; padding: 6px 10px;
}
nav { display: flex; gap: 4px; margin-top: 10px; overflow-x: auto; }
nav button {
  font: inherit; background: none; border: none; color: var(--ink-2);
  padding: 8px 14px; border-bottom: 3px solid transparent; cursor: pointer; white-space: nowrap;
}
nav button.on { color: var(--ink); border-bottom-color: var(--s1); font-weight: 700; }
main { max-width: 1200px; margin: 0 auto; padding: 20px 24px 60px; }
section.tab { display: none; }
section.tab.on { display: block; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 18px 20px; margin-bottom: 18px;
}
.card h2 { font-size: 16px; margin: 0 0 4px; }
.card .sub { color: var(--ink-2); font-size: 13px; margin: 0 0 12px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 14px 18px; }
.tile .label { color: var(--ink-2); font-size: 13px; }
.tile .value { font-size: 30px; font-weight: 700; line-height: 1.3; }
.tile .note { color: var(--ink-2); font-size: 12px; }

.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.sw { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.chart-head { display: flex; align-items: flex-start; gap: 12px; }
.chart-head .grow { flex: 1; }
.linkbtn { font: inherit; font-size: 13px; background: none; border: 1px solid var(--border); color: var(--ink-2); border-radius: 8px; padding: 4px 10px; cursor: pointer; }
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--ink-2); font-size: 11px; }
.tip {
  position: absolute; pointer-events: none; background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 13px;
  box-shadow: 0 4px 14px rgba(0,0,0,.12); white-space: nowrap; display: none; z-index: 3;
}
.tip b { display: block; margin-bottom: 2px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
th { color: var(--ink-2); font-weight: 600; font-size: 13px; white-space: nowrap; position: sticky; top: 0; background: var(--surface); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--accent-wash); }
tr.sel td { background: var(--accent-wash); }
.table-wrap { max-height: 560px; overflow: auto; }
#kpiTable, #kTable, #kDorm, #cand, #eOffice, #officeTable, #stale, #noVisit, #nextByoin, #peopleTable { min-width: 880px; }
#kTable td:first-child, #kDorm td:nth-child(2), #kpiTable td:nth-child(2) { min-width: 220px; }
#cand td:nth-child(2), #eOffice td:first-child, #officeTable td:first-child, #stale td:first-child, #noVisit td:first-child { min-width: 220px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; align-items: center; }
.toolbar input[type=search] { min-width: 240px; flex: 1; }
.muted { color: var(--ink-2); }
.small { font-size: 12px; }

.badge { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; color: #fff; white-space: nowrap; }
.b-renkei { background: var(--s1); }
.b-byoin { background: var(--s2); }
.b-orei { background: var(--s3); }
.b-soudan { background: transparent; color: var(--ink-2); border: 1px solid var(--axis); }
.b-new { background: transparent; color: var(--good); border: 1px solid var(--good); font-weight: 700; }
.b-kyumin { background: transparent; color: var(--warn); border: 1px solid var(--warn); font-weight: 700; }
.eff-yes { font-size: 12px; color: var(--good); margin-left: 8px; }
.eff-no { font-size: 12px; color: var(--ink-2); margin-left: 8px; }
.late { color: var(--warn); font-weight: 700; }

.detail { margin-top: 18px; scroll-margin-top: 110px; }
.detail h3 { margin: 0 0 4px; font-size: 18px; }
.facts { display: flex; gap: 18px; flex-wrap: wrap; color: var(--ink-2); font-size: 13px; margin-bottom: 12px; }
.facts b { color: var(--ink); font-size: 15px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { display: grid; grid-template-columns: 96px 1fr; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--grid); }
.timeline .when { color: var(--ink-2); font-variant-numeric: tabular-nums; font-size: 13px; }
.timeline .who { color: var(--ink-2); font-size: 13px; margin-left: 6px; }
.timeline dl { margin: 6px 0 0; display: grid; grid-template-columns: max-content 1fr; gap: 2px 10px; font-size: 14px; }
.timeline dt { color: var(--ink-2); font-size: 13px; }
.timeline dd { margin: 0; white-space: pre-wrap; }
.timeline li.soudan { padding: 6px 0; }
.score-row { display: flex; gap: 8px; flex-wrap: wrap; font-size: 13px; color: var(--ink-2); }
.bar-h { height: 10px; border-radius: 0 4px 4px 0; background: var(--s1); display: inline-block; vertical-align: middle; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 860px) { .grid2 { grid-template-columns: 1fr; } main { padding: 14px; } header { padding: 12px 14px 0; } }
.hint { background: var(--accent-wash); border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 14px; }
