:root {
  --red: #CC0006;
  --ink: #141414;
  --ink2: #555;
  --ink3: #8a8a8a;
  --bg: #f4f4f2;
  --card: #ffffff;
  --line: #e4e4e0;
  --good: #1f7a3a;
  --warn: #b25b00;
  --chip: #efefec;
  --target: #9a9a9a;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --red: #ff4d52;
    --ink: #f2f2f2;
    --ink2: #b9b9b9;
    --ink3: #8d8d8d;
    --bg: #0e0e0e;
    --card: #1a1a1a;
    --line: #2c2c2c;
    --good: #5cc57c;
    --warn: #f0a24a;
    --chip: #262626;
    --target: #777;
  }
}
:root[data-theme="dark"] {
  --red: #ff4d52; --ink: #f2f2f2; --ink2: #b9b9b9; --ink3: #8d8d8d; --bg: #0e0e0e;
  --card: #1a1a1a; --line: #2c2c2c; --good: #5cc57c; --warn: #f0a24a; --chip: #262626; --target: #777;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; cursor: pointer; }
.num { font-variant-numeric: tabular-nums; }

/* ヘッダー：黒帯＋赤ライン（Levela型） */
.bar { background: #111; color: #fff; border-bottom: 3px solid #CC0006; position: sticky; top: 0; z-index: 10; }
.bar-in { max-width: 980px; margin: 0 auto; padding: 10px 16px 6px; display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.brand { font-weight: 800; letter-spacing: .04em; font-size: 18px; }
.stamp { font-size: 12px; color: #bbb; }
.tabs { max-width: 980px; margin: 0 auto; padding: 0 8px; display: flex; gap: 2px; overflow-x: auto; }
.tabs button { background: none; border: 0; color: #bbb; padding: 8px 14px 9px; font-weight: 700; border-bottom: 3px solid transparent; margin-bottom: -3px; white-space: nowrap; }
.tabs button.on { color: #fff; border-bottom-color: #fff; }

.gate { min-height: 70vh; display: grid; place-items: center; padding: 16px; }
.gate form { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 28px 22px; width: min(360px, 100%); text-align: center; }
.gate h1 { font-size: 20px; margin: 0 0 4px; }
.gate p { color: var(--ink2); margin: 0 0 14px; font-size: 14px; }
.gate input { width: 100%; font-size: 17px; padding: 11px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); }
.gate button { margin-top: 12px; width: 100%; padding: 11px; border: 0; border-radius: 10px; background: var(--red); color: #fff; font-weight: 800; }
.gate .err { color: var(--red); min-height: 1.5em; margin-top: 10px; }

main { max-width: 980px; margin: 0 auto; padding: 12px 16px 40px; }

/* メンバー切替 */
.who { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.who::-webkit-scrollbar { display: none; }
.who button { flex: none; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.who button.on { background: var(--ink); color: var(--bg); border-color: var(--ink); font-weight: 700; }

h2 { font-size: 15px; margin: 22px 0 8px; display: flex; align-items: baseline; gap: 8px; }
h2 small { font-weight: 400; color: var(--ink3); font-size: 12px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }

/* KPIタイル */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.tile .lab { font-size: 12px; color: var(--ink2); font-weight: 700; }
.tile .val { font-size: 28px; font-weight: 800; line-height: 1.15; margin-top: 2px; }
.tile .val small { font-size: 14px; font-weight: 700; color: var(--ink2); }
.tile .sub { font-size: 12px; color: var(--ink3); margin-top: 2px; }
.tile.hero { grid-column: 1 / -1; }
.tile.hero .val { font-size: 40px; }
.meter { height: 8px; background: var(--chip); border-radius: 4px; margin-top: 8px; position: relative; overflow: hidden; }
.meter i { position: absolute; inset: 0 auto 0 0; background: var(--red); border-radius: 4px; }
.meter b { position: absolute; top: -2px; bottom: -2px; width: 2px; background: var(--ink); }
.delta-up { color: var(--good); font-weight: 700; }
.delta-down { color: var(--red); font-weight: 700; }

/* 表 */
.tbl-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 8px 10px; text-align: right; white-space: nowrap; border-bottom: 1px solid var(--line); }
th:first-child, td:first-child { text-align: left; position: sticky; left: 0; background: var(--card); }
th { font-size: 11px; color: var(--ink2); font-weight: 700; cursor: pointer; user-select: none; }
th.sorted::after { content: " ▼"; font-size: 9px; }
tr:last-child td { border-bottom: 0; }
tr.total td { font-weight: 800; background: var(--chip); }
tr.total td:first-child { background: var(--chip); }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--chip); }
td .nd { color: var(--ink3); font-size: 11px; margin-left: 4px; }
td.low { color: var(--red); font-weight: 700; }
td.high { color: var(--good); font-weight: 700; }

/* リスト */
.list { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.row { display: grid; grid-template-columns: 58px 1fr auto; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); align-items: center; }
.row:last-child { border-bottom: 0; }
.row .t { font-weight: 800; font-variant-numeric: tabular-nums; }
.row .m { min-width: 0; }
.row .c { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .r { font-size: 12px; color: var(--ink2); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.chip { font-size: 11px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--chip); color: var(--ink2); white-space: nowrap; }
.chip.win { background: var(--red); color: #fff; }
.chip.warn { background: transparent; color: var(--warn); border: 1px solid var(--warn); }
.chip.dim { opacity: .65; }
.empty { padding: 18px; text-align: center; color: var(--ink3); font-size: 13px; }

.daynav { display: flex; align-items: center; gap: 8px; }
.daynav button { border: 1px solid var(--line); background: var(--card); border-radius: 8px; padding: 4px 11px; font-weight: 800; }
.daynav .d { font-weight: 800; font-size: 16px; min-width: 110px; text-align: center; }

/* グラフ */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; }
.chart .tip { position: absolute; pointer-events: none; background: var(--ink); color: var(--bg); font-size: 12px; padding: 6px 8px; border-radius: 6px; white-space: nowrap; transform: translate(-50%, -110%); opacity: 0; transition: opacity .1s; }
.axis text { fill: var(--ink3); font-size: 11px; }
.grid line { stroke: var(--line); }

.note { font-size: 12px; color: var(--ink3); margin-top: 8px; }
.foot { font-size: 11px; color: var(--ink3); margin-top: 28px; line-height: 1.7; }
.seg { display: inline-flex; background: var(--chip); border-radius: 8px; padding: 2px; margin-left: auto; }
.seg button { border: 0; background: none; padding: 3px 10px; border-radius: 6px; font-size: 12px; font-weight: 700; color: var(--ink2); }
.seg button.on { background: var(--card); color: var(--ink); }
