/* ── 色・大きさ（すべて変数。表示の色は data-theme で切り替える） ───────── */
:root {
  --bg: #f4f3f0; --surface: #ffffff; --sunk: #f8f7f4; --line: #e3e1db; --line-strong: #cfccc4;
  --text: #1d1e20; --muted: #5f6167; --faint: #6c6e74;
  --accent: #1e5b85; --accent-soft: #e6eef5;
  --ok: #2c7a4b; --ok-soft: #e5f2ea; --warn: #9a6d0b; --warn-soft: #faf1db; --err: #b23a2e; --err-soft: #f8e6e3; --off: #8b8c90;
  --band: #ecebe6; --total: #f5f4f0; --grand: #e9e7e1;
  --font: "Noto Sans JP", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  --num: "Roboto", "Helvetica Neue", Arial, sans-serif;
  --fs: 16px; --fs-s: 14px; --fs-l: 20px; --fs-xl: 32px;
  --row: 36px; --bar: 60px; --side: 224px; --r: 6px;
  --shadow: 0 1px 2px rgba(20, 20, 20, .06), 0 8px 24px -12px rgba(20, 20, 20, .18);
}
:root[data-theme="dark"] {
  --bg: #151618; --surface: #1d1f22; --sunk: #191a1d; --line: #2e3034; --line-strong: #3d4045;
  --text: #e9e8e4; --muted: #a2a3a8; --faint: #9a9ca2;
  --accent: #7fb3d9; --accent-soft: #1f3343;
  --ok: #6cc08d; --ok-soft: #1c3226; --warn: #e0b453; --warn-soft: #3a3019; --err: #ef8a7e; --err-soft: #3d2320; --off: #85878c;
  --band: #26282c; --total: #212327; --grand: #2a2c31;
  --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px -12px rgba(0, 0, 0, .6);
}

/* ── 土台 ───────────────────────────────── */
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--text); font: 400 var(--fs)/1.5 var(--font); -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 3px; }
.num, .ag-right-aligned-cell { font-family: var(--num); font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ── 画面の枠（器は画面の高さ。中身だけが動く） ───────── */
.app { display: grid; grid-template-columns: var(--side) 1fr; grid-template-rows: var(--bar) 1fr; height: 100vh; }
.bar { grid-column: 1 / 3; display: flex; align-items: center; gap: 12px; padding: 0 16px; background: var(--surface); border-bottom: 1px solid var(--line); min-width: 0; }
.side { background: var(--surface); border-right: 1px solid var(--line); padding: 12px 8px; overflow: auto; display: flex; flex-direction: column; gap: 2px; }
.main { overflow: hidden; display: flex; flex-direction: column; min-width: 0; min-height: 0; padding: 20px 24px 16px; gap: 14px; }
.spacer { flex: 1; }

/* ── 上の帯 ───────────────────────────────── */
.co { border: 0; background: none; font: 700 var(--fs-l)/1.2 var(--font); color: var(--text); padding: 8px 6px; border-radius: var(--r); cursor: pointer; max-width: 32vw; min-height: 44px; }
.co:hover { background: var(--sunk); }
.co-name { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chip { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--surface); color: var(--text); font: 500 var(--fs-s)/1 var(--num); cursor: pointer; white-space: nowrap; }
.chip:hover { border-color: var(--accent); }
.chip-k { font-family: var(--font); color: var(--muted); }
.readat { color: var(--muted); font-size: var(--fs-s); white-space: nowrap; font-variant-numeric: tabular-nums; }
.readat.stale { color: var(--warn); }
.readat.bad { color: var(--err); }
.period { position: relative; }

/* ── ボタン・スイッチ ───────────────────────── */
.btn { min-height: 40px; padding: 0 14px; border-radius: var(--r); border: 1px solid var(--line-strong); background: var(--surface); color: var(--text); font: 500 var(--fs-s)/1 var(--font); cursor: pointer; white-space: nowrap; transition: transform .08s ease, border-color .15s ease, background .15s ease; }
.btn:hover { border-color: var(--accent); }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #0e1b25; }
.btn.ghost { border-color: transparent; color: var(--muted); }
.btn.ghost:hover { border-color: var(--line-strong); color: var(--text); }
.btn[disabled] { opacity: .5; cursor: default; }
.sw { display: inline-flex; align-items: center; gap: 8px; min-height: 44px; font-size: var(--fs-s); color: var(--text); cursor: pointer; white-space: nowrap; user-select: none; }
.sw input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.sw-t { width: 34px; height: 20px; border-radius: 10px; background: var(--line-strong); position: relative; transition: background .15s ease; flex: none; }
.sw-t::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: 0 1px 2px rgba(0,0,0,.25); transition: transform .18s cubic-bezier(.2,.8,.2,1); }
.sw input:checked + .sw-t { background: var(--accent); }
.sw input:checked + .sw-t::after { transform: translateX(14px); }
.sw input:focus-visible + .sw-t { outline: 2px solid var(--accent); outline-offset: 2px; }
.seg { display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--r); overflow: hidden; background: var(--surface); }
.seg button { min-height: 40px; padding: 0 16px; border: 0; background: none; color: var(--muted); font: 500 var(--fs-s)/1 var(--font); cursor: pointer; border-right: 1px solid var(--line); }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

/* ── 期間の窓 ───────────────────────────────── */
.pop { position: absolute; top: 48px; left: 0; z-index: 30; width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 12px; }
.pop-h { font-size: var(--fs-s); color: var(--muted); margin: 6px 4px; }
.pop-list { display: flex; flex-direction: column; margin-bottom: 8px; }
.pop-list button { text-align: left; min-height: 40px; padding: 0 10px; border: 0; background: none; border-radius: var(--r); color: var(--text); font: 400 var(--fs)/1 var(--font); cursor: pointer; display: flex; justify-content: space-between; }
.pop-list button:hover { background: var(--sunk); }
.pop-list button[aria-current="true"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.pop-list small { color: var(--muted); font-family: var(--num); font-size: var(--fs-s); }
.pop-row { display: flex; align-items: center; gap: 6px; }
.pop-row input { flex: 1; min-width: 0; min-height: 40px; border: 1px solid var(--line-strong); border-radius: var(--r); padding: 0 8px; font: 400 var(--fs) var(--num); background: var(--surface); color: var(--text); }
.pop-sep { color: var(--muted); }

/* ── 左の一覧 ───────────────────────────────── */
.side a { white-space: nowrap; display: flex; align-items: center; min-height: 40px; padding: 0 12px; border-radius: var(--r); color: var(--text); font-size: var(--fs); text-decoration: none; }
.side a:hover { background: var(--sunk); }
.side a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.side-h { font-size: var(--fs-s); color: var(--faint); padding: 14px 12px 4px; }

/* ── 画面の見出しと上の欄 ───────────────────── */
.head { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; flex: none; }
.head h1 { font-size: var(--fs-l); margin: 0 8px 0 0; font-weight: 700; }
.head .note { color: var(--muted); font-size: var(--fs-s); }
.links { display: flex; gap: 6px 18px; flex-wrap: wrap; font-size: var(--fs-s); }
.links span { color: var(--muted); }
.links .off { color: var(--faint); }

/* ── 数字の帯（ホーム・照合・比べる） ───────── */
.figs { display: flex; flex: none; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.fig { padding: 14px 20px; border-right: 1px solid var(--line); min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.fig:last-child { border-right: 0; }
.fig.lead { flex: 1.6; }
.fig.lead[data-state="ok"] { background: var(--ok-soft); }
.fig.lead[data-state="err"] { background: var(--err-soft); }
.fig.lead[data-state="warn"] { background: var(--warn-soft); }
.fig-k { font-size: var(--fs-s); color: var(--muted); white-space: nowrap; }
.fig-v { font: 500 var(--fs-xl)/1.1 var(--num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.fig-v small { font: 400 var(--fs-s) var(--font); color: var(--muted); margin-left: 4px; }
.fig-s { font-size: var(--fs-s); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fig[data-state="ok"] .fig-v { color: var(--ok); }
.fig[data-state="err"] .fig-v { color: var(--err); }
.fig[data-state="warn"] .fig-v { color: var(--warn); }
.fig a.fig-s { color: var(--accent); }
button.fig { border: 0; border-right: 1px solid var(--line); background: none; text-align: left; font: inherit; color: inherit; cursor: pointer; }
button.fig:hover { background: var(--sunk); }

/* ── 表（AG Grid の見た目を変数に合わせる） ─────── */
.grid { flex: 1; min-height: 160px; }
.grid.short, .grid.fit { flex: none; }
.ag-theme-quartz, .ag-theme-quartz-dark {
  --ag-font-family: var(--font); --ag-font-size: var(--fs); --ag-row-height: var(--row); --ag-header-height: 40px; --ag-list-item-height: 32px;
  --ag-background-color: var(--surface); --ag-foreground-color: var(--text); --ag-header-background-color: var(--sunk); --ag-header-foreground-color: var(--muted);
  --ag-border-color: var(--line); --ag-row-border-color: var(--line); --ag-odd-row-background-color: var(--surface); --ag-row-hover-color: var(--accent-soft);
  --ag-selected-row-background-color: var(--accent-soft); --ag-range-selection-border-color: var(--accent); --ag-active-color: var(--accent);
  --ag-wrapper-border-radius: 10px; --ag-cell-horizontal-padding: 12px; --ag-header-column-resize-handle-color: var(--line-strong);
  --ag-input-focus-border-color: var(--accent); --ag-checkbox-checked-color: var(--accent);
}
.ag-header-cell-label { justify-content: center; font-size: var(--fs-s); font-weight: 500; text-align: center; }
.ag-header-cell-text { line-height: 1.3; }
.ag-header-cell.ag-right-aligned-header .ag-header-cell-label { justify-content: center; }
.ag-cell { line-height: calc(var(--row) - 2px); }
.ag-row.r-band { background: var(--band); font-weight: 700; }
.ag-row.r-label .c-name { color: var(--muted); font-size: var(--fs-s); }
.ag-row.r-total { background: var(--total); font-weight: 500; }
.ag-row.r-profit { background: var(--total); font-weight: 700; }
.ag-row.r-grand { background: var(--grand); font-weight: 700; }
.ag-row.r-gap { background: var(--bg); }
.ag-row.r-sub .c-name { padding-left: 34px; color: var(--muted); }
.ag-row.r-diff .num-cell.nz { color: var(--err); font-weight: 700; }
.ag-row.r-diff .num-cell.z { color: var(--ok); font-weight: 700; }
.ag-row.r-unknown { color: var(--err); }
.c-name { display: flex; align-items: center; gap: 4px; }
.tg { width: 26px; height: 26px; flex: none; border: 0; background: none; border-radius: 4px; color: var(--muted); cursor: pointer; font: 400 12px/1 var(--font); display: inline-flex; align-items: center; justify-content: center; }
.tg:hover { background: var(--sunk); color: var(--text); }
.tg-sp { width: 26px; flex: none; }
.lk { color: var(--text); cursor: pointer; }
.ag-row-hover .lk { color: var(--accent); text-decoration: underline; }
.num-cell { text-align: right; font-family: var(--num); font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }
.neg { color: var(--err); }
.st-ok { color: var(--ok); } .st-warn { color: var(--warn); } .st-err { color: var(--err); font-weight: 700; } .st-off { color: var(--off); }
.cell-links { display: flex; gap: 14px; font-size: var(--fs-s); }

/* ── 照合・比べるの塊 ───────────────────────── */
.stack { flex: 1; min-height: 0; overflow: auto; display: flex; flex-direction: column; gap: 14px; padding-right: 4px; }
.sect { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }
.sect > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 10px; min-height: 48px; padding: 0 16px; font-weight: 500; }
.sect > summary::-webkit-details-marker { display: none; }
.sect > summary::before { content: "▸"; color: var(--muted); font-size: 12px; width: 14px; display: inline-block; transition: transform .15s ease; }
.sect[open] > summary::before { transform: rotate(90deg); }
.sect .cnt { margin-left: auto; font: 500 var(--fs) var(--num); }
.sect .cnt.z { color: var(--ok); } .sect .cnt.nz { color: var(--err); }
.sect .body { padding: 0 16px 16px; }
.sect .body .grid { height: 260px; }
.empty { color: var(--muted); font-size: var(--fs-s); padding: 4px 0 8px; }

/* ── 入口（ログイン・会社を選ぶ） ───────────── */
.center { margin: auto; max-width: 560px; text-align: left; display: flex; flex-direction: column; gap: 14px; }
.center h1 { font-size: var(--fs-l); margin: 0; }
.center p { margin: 0; color: var(--muted); }
.urlrow { display: flex; gap: 8px; }
.urlrow input { flex: 1; min-height: 40px; border: 1px solid var(--line-strong); border-radius: var(--r); padding: 0 10px; font: 400 var(--fs) var(--font); background: var(--surface); color: var(--text); }
.acct-pick { display: flex; gap: 8px; align-items: center; }
.acct-pick input { min-height: 40px; width: 220px; border: 1px solid var(--line-strong); border-radius: var(--r); padding: 0 10px; font: 400 var(--fs) var(--font); background: var(--surface); color: var(--text); }

/* ── 読み込み中・知らせ ─────────────────────── */
.skel { flex: 1; border-radius: 10px; background: linear-gradient(90deg, var(--surface) 0%, var(--sunk) 50%, var(--surface) 100%); background-size: 200% 100%; animation: sk 1.2s ease-in-out infinite; border: 1px solid var(--line); }
@keyframes sk { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.msg { padding: 12px 16px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.msg.err { border-color: var(--err); background: var(--err-soft); }
.msg.warn { border-color: var(--warn); background: var(--warn-soft); }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--surface); padding: 10px 18px; border-radius: 8px; font-size: var(--fs-s); box-shadow: var(--shadow); z-index: 50; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (max-width: 1100px) { .bar { gap: 8px; } .bar .sw span:last-child { display: none; } }
