[hidden] { display: none !important; }

:root {
  color-scheme: light;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --line: #e2e0da;
  --ink: #1b1b1a;
  --ink-2: #4f4e4a;
  --ink-3: #6c6a64;
  --accent: #2c5f8a;
  --on-strong: #ffffff;
  --good: #1f7a3a;
  --bad: #b3372f;
  --warn-bg: #fff4d6;
  --s-lapis: #2a78d6;
  --s-soken: #eb6834;
  --s-doko: #1baf7a;
  --grid: #e9e7e1;
  --shadow: 0 1px 2px rgba(0,0,0,.05), 0 2px 8px rgba(0,0,0,.04);
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #151514;
    --surface: #1f1f1e;
    --surface-2: #2a2a28;
    --line: #363633;
    --ink: #f0efec;
    --ink-2: #c9c8c0;
    --ink-3: #a5a49c;
    --accent: #8fbbe6;
    --on-strong: #0f1114;
    --good: #5cc27a;
    --bad: #f08a80;
    --warn-bg: #3a3220;
    --s-lapis: #3987e5;
    --s-soken: #d95926;
    --s-doko: #199e70;
    --grid: #2c2c2a;
    --shadow: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
/* 入力欄に移ったとき、下の保存の帯に隠れないようにする */
html { scroll-padding-top: 70px; scroll-padding-bottom: 130px; }
/* ダブルタップの拡大を止める（ボタンを続けて押す画面なので） */
button, input, textarea, label, a { touch-action: manipulation; }
body { -webkit-tap-highlight-color: transparent; overscroll-behavior-y: none; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
  word-break: auto-phrase;
  line-break: strict;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; font-size: 16px; color: var(--ink); }
.num { font-variant-numeric: tabular-nums; }

.center-msg { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; color: var(--ink-3); }

/* ログイン */
.gate { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
.login { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; box-shadow: var(--shadow); }
.login h1 { margin: 0 0 4px; font-size: 22px; }
.login .sub { margin: 0 0 20px; color: var(--ink-3); font-size: 13px; }
.err { color: var(--bad); margin: 12px 0 0; font-size: 14px; }

/* 上の帯 */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--sat)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 16px; white-space: nowrap; }
.tabs { display: flex; gap: 4px; margin-left: auto; background: var(--surface-2); padding: 3px; border-radius: 10px; }
.tabs button { border: 0; background: transparent; padding: 7px 14px; border-radius: 8px; font-size: 14px; color: var(--ink-2); white-space: nowrap; flex: 0 0 auto; }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--ink); font-weight: 700; box-shadow: var(--shadow); }

.view { max-width: 760px; margin: 0 auto; padding: 14px 14px calc(110px + var(--sab)); }
#summary.view { padding-bottom: calc(40px + var(--sab)); }

.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; margin: 12px 0; box-shadow: var(--shadow); }
.card h2 { font-size: 14px; margin: 0 0 10px; color: var(--ink-2); font-weight: 700; }

/* 店の切り替え */
.stores { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.store-btn {
  border: 1.5px solid var(--line); background: var(--surface); border-radius: 12px;
  padding: 9px 6px; font-size: 13px; line-height: 1.3; text-align: center;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.store-btn .dot { width: 10px; height: 10px; border-radius: 50%; }
.store-btn .short { display: none; }
.store-btn:active, .btn:active, .icon-btn:active, .stepper .step:active, .ml-day:active { transform: scale(.97); }
.store-btn[aria-checked="true"] { border-color: var(--ink); font-weight: 700; background: var(--surface-2); }

.datebar { display: flex; align-items: center; gap: 8px; margin: 12px 0 4px; justify-content: center; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); font-size: 22px; line-height: 1; flex: 0 0 auto; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.date-pick { position: relative; flex: 1 1 auto; max-width: 260px; text-align: center; font-weight: 700; font-size: 17px; padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); }
.date-pick input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.month-label { font-weight: 700; font-size: 18px; min-width: 150px; text-align: center; }
.rec-state { text-align: center; margin: 4px 0 0; font-size: 13px; color: var(--ink-3); min-height: 1.5em; }
.rec-state.saved { color: var(--good); }
.rec-state.dirty { color: var(--bad); }

/* 入力欄 */
.pay-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-size: 13px; color: var(--ink-2); }
.field small { display: block; color: var(--ink-3); font-size: 11.5px; }
.field input, .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px;
  background: var(--surface); text-align: right; font-variant-numeric: tabular-nums;
}
.field textarea { text-align: left; resize: vertical; }
.field input:focus, .field textarea:focus, .stepper input:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
.field input.bad, .stepper input.bad { border-color: var(--bad); background: color-mix(in srgb, var(--bad) 8%, var(--surface)); }
.field.memo { margin-top: 12px; }
.total-row { display: flex; justify-content: space-between; align-items: baseline; margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--line); }
.total-row strong { font-size: 24px; font-variant-numeric: tabular-nums; }

.cnt-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stepper { display: grid; grid-template-columns: 44px 1fr 44px; grid-template-rows: auto 44px; gap: 4px; }
.stepper .lbl { grid-column: 1 / -1; font-size: 13px; color: var(--ink-2); }
.stepper .step { border: 1px solid var(--line); background: var(--surface-2); border-radius: 10px; font-size: 20px; }
.stepper input { width: 100%; min-width: 0; border: 1px solid var(--line); border-radius: 10px; text-align: center; font-size: 18px; font-weight: 700; background: var(--surface); }

/* この月の入力 */
.month-list { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.ml-head { font-size: 11px; color: var(--ink-3); text-align: center; }
.ml-day {
  border: 1px solid var(--line); border-radius: 8px; background: var(--surface);
  padding: 4px 2px; min-height: 50px; display: flex; flex-direction: column; align-items: center; justify-content: flex-start;
  font-size: 11px; line-height: 1.25;
}
.ml-day .d { font-size: 12px; font-weight: 700; }
.ml-day .v { font-variant-numeric: tabular-nums; color: var(--ink-2); }
.ml-day.has { background: var(--surface-2); }
.ml-day.miss { border-style: dashed; }
.ml-day.miss .v { color: var(--bad); }
.ml-day.future { opacity: .45; }
.ml-day.sel { outline: 2px solid var(--ink); outline-offset: 0; }
.ml-day.flash { animation: flash 1.2s ease-out; }
@keyframes flash { 0% { opacity: .3; } 100% { opacity: 1; } }
.ml-empty { grid-column: span 1; }
.ml-sum { grid-column: 1 / -1; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 13px; color: var(--ink-2); }
.ml-sum b { color: var(--ink); font-variant-numeric: tabular-nums; }

.monthly summary { cursor: pointer; font-weight: 700; font-size: 14px; color: var(--ink-2); display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.monthly .hint { font-weight: 400; font-size: 12px; color: var(--ink-3); }
.monthly .hint.todo { color: var(--bad); }
.mon-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 12px; margin: 12px 0; }
.note { font-size: 12.5px; color: var(--ink-3); margin: 6px 0; }
.note.center { text-align: center; }

/* 保存の帯 */
.savebar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: color-mix(in srgb, var(--surface) 96%, transparent); border-top: 1px solid var(--line); padding: 10px 14px calc(10px + var(--sab)); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.savebar-in { max-width: 760px; margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.savebar-info { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.savebar-info span { font-size: 12px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.savebar-info strong { font-size: 18px; font-variant-numeric: tabular-nums; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 12px; padding: 11px 20px; font-weight: 700; white-space: nowrap; flex: 0 0 auto; }
.btn.primary { background: var(--ink); color: var(--on-strong); border-color: var(--ink); }
.btn.primary:disabled { opacity: .5; cursor: default; }
.btn.wide { width: 100%; margin-top: 16px; }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn.ghost { background: transparent; }
.linklike { border: 0; background: none; color: var(--ink-3); text-decoration: underline; font-size: 13px; }
.foot { text-align: center; margin-top: 24px; }

/* 集計 */
.hero { padding: 16px; }
.hero .ttl { font-size: 13px; color: var(--ink-3); margin: 0 0 2px; }
.hero .big { font-size: 34px; font-weight: 800; letter-spacing: -.01em; font-variant-numeric: tabular-nums; line-height: 1.15; }
.hero .big small { font-size: 16px; font-weight: 700; margin-left: 2px; }
.cmp { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 6px; font-size: 13.5px; color: var(--ink-2); }
.cmp .up { color: var(--good); font-weight: 700; }
.cmp .down { color: var(--bad); font-weight: 700; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-top: 12px; }
.kpi { background: var(--surface-2); border-radius: 10px; padding: 8px 10px; }
.kpi .k { font-size: 11.5px; color: var(--ink-3); }
.kpi .v { font-size: 17px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi .v small { font-size: 11px; font-weight: 400; color: var(--ink-3); margin-left: 1px; }

.store-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.store-cards .card { margin: 0; padding: 12px 14px; }
.sc-name { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 700; margin-bottom: 4px; }
.sc-name .dot { width: 10px; height: 10px; border-radius: 50%; flex: 0 0 auto; }
.sc-big { font-size: 24px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1.2; }
.sc-big small { font-size: 13px; font-weight: 700; }
.sc-rows { margin-top: 6px; font-size: 12.5px; color: var(--ink-2); display: grid; gap: 2px; }
.sc-rows b { color: var(--ink); font-variant-numeric: tabular-nums; }
.sc-rows .up { color: var(--good); font-weight: 700; }
.sc-rows .down { color: var(--bad); font-weight: 700; }
.sc-warn { margin-top: 8px; font-size: 12px; background: var(--warn-bg); border-radius: 8px; padding: 5px 8px; }

.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12.5px; color: var(--ink-2); margin-bottom: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.chart { width: 100%; position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart text { fill: var(--ink-3); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .gridline { stroke: var(--grid); stroke-width: 1; }
.chart .hit { fill: transparent; }
.chart .hit:hover { fill: color-mix(in srgb, var(--ink) 6%, transparent); }
.tip { position: fixed; z-index: 50; pointer-events: none; background: var(--surface); color: var(--ink); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 12.5px; box-shadow: 0 4px 16px rgba(0,0,0,.15); min-width: 150px; }
.tip .t { font-weight: 700; margin-bottom: 4px; }
.tip .r { display: flex; justify-content: space-between; gap: 14px; font-variant-numeric: tabular-nums; }
.tip i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 5px; }

.table-view { margin-top: 8px; }
.table-view summary { cursor: pointer; font-size: 13px; color: var(--ink-3); }
.scroll-x { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { border-collapse: collapse; width: 100%; font-size: 13px; font-variant-numeric: tabular-nums; }
table.t th, table.t td { padding: 6px 8px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t thead th { color: var(--ink-3); font-weight: 400; font-size: 12px; }
table.t tr.sum td { font-weight: 700; border-top: 1.5px solid var(--ink-3); }
table.t td.muted { color: var(--ink-3); }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + var(--sab)); z-index: 60; background: var(--ink); color: var(--on-strong); padding: 11px 16px; border-radius: 12px; font-size: 14px; box-shadow: 0 6px 20px rgba(0,0,0,.2); max-width: calc(100vw - 28px); }
.toast.bad { background: var(--bad); color: #fff; }

table.t .tot { font-weight: 700; }
table.t th.st { text-align: right; }
table.t th.st i { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin-right: 4px; vertical-align: 0; }

/* 読み込み直すボタン */
.reload-btn { flex: 0 0 auto; width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); color: var(--ink-2); display: grid; place-items: center; padding: 0; }
.reload-btn:active { transform: scale(.94); }
.reload-btn.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 予算の達成ゲージ */
.gauge-box { display: flex; align-items: center; gap: 14px; margin-top: 10px; }
.gauge-box .gauge { width: 150px; flex: 0 0 auto; display: block; }
.gauge .g-bg { fill: none; stroke: var(--surface-2); stroke-width: 16; }
.gauge .g-fg { fill: none; stroke-width: 16; transition: stroke-dasharray .6s ease; }
.gauge .g-pace { stroke: var(--ink); stroke-width: 3; stroke-linecap: round; }
.gauge .g-pct { fill: var(--ink); font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; }
.gauge .g-unit { font-size: 16px; font-weight: 700; }
.gauge .g-sub { fill: var(--ink-3); font-size: 12px; }
.gauge-txt { font-size: 13px; color: var(--ink-2); display: grid; gap: 3px; min-width: 0; }
.gauge-txt b { color: var(--ink); font-variant-numeric: tabular-nums; }
.gauge-txt .up { color: var(--good); font-weight: 700; }
.gauge-txt .down { color: var(--bad); font-weight: 700; }
.gauge-box.none { justify-content: space-between; background: var(--surface-2); border-radius: 10px; padding: 8px 10px; font-size: 13px; color: var(--ink-3); }
.gauge-box.none p { margin: 0; }
@media (min-width: 641px) {
  .store-cards .gauge-box { flex-direction: column; align-items: stretch; gap: 6px; }
  .store-cards .gauge-box .gauge { width: 150px; margin: 0 auto; }
}
.sc-nobudget { margin-top: 6px; font-size: 12px; color: var(--ink-3); }

/* 入力の画面の細いゲージ */
.bar-box { margin: 0 0 12px; font-size: 13px; color: var(--ink-2); }
.bar-box.none { display: flex; justify-content: space-between; gap: 8px; color: var(--ink-3); }
.bar-head { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 2px 10px; margin-bottom: 5px; }
.bar-head b { color: var(--ink); font-size: 15px; font-variant-numeric: tabular-nums; }
.bar { position: relative; height: 12px; border-radius: 6px; background: var(--surface-2); }
.bar-fill { position: absolute; left: 0; top: 0; bottom: 0; border-radius: 6px; }
.bar-pace { position: absolute; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--ink); border-radius: 1px; }
.bar-note { font-size: 11.5px; color: var(--ink-3); margin-top: 4px; }

/* 予算の画面 */
.budget-rows { display: grid; gap: 12px; }
.budget-row { flex-direction: row; align-items: center; justify-content: space-between; gap: 10px; }
.budget-row > span:first-child { font-size: 14px; color: var(--ink); font-weight: 700; min-width: 0; }
.budget-row .dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; }
.budget-row small { font-weight: 400; margin-top: 2px; }
.budget-in { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; }
.budget-in input { width: 130px; font-size: 18px; font-weight: 700; }
.budget-in em { font-style: normal; font-size: 13px; color: var(--ink-3); }
.budget-btns { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 14px; }
table.blist tr[data-ym] { cursor: pointer; }
table.blist tr.sel td { background: var(--surface-2); font-weight: 700; }
table.blist small.pct { display: block; font-size: 11px; color: var(--ink-3); font-weight: 400; }

@media (max-width: 640px) {
  body { font-size: 14.5px; }
  .top { padding: calc(8px + var(--sat)) 12px 8px; }
  .view { padding-left: 10px; padding-right: 10px; }
  .card { padding: 12px 12px; margin: 10px 0; border-radius: 12px; }
  .store-cards { grid-template-columns: 1fr; }
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .brand { font-size: 15px; }
  .tabs button { padding: 8px 12px; }
  /* 店は短い名前で1行に */
  .store-btn { flex-direction: row; justify-content: center; padding: 11px 4px; font-size: 14px; gap: 5px; }
  .store-btn .full { display: none; }
  .store-btn .short { display: inline; white-space: nowrap; }
  .pay-grid { gap: 8px 10px; }
  .field input { padding: 10px 10px; }
  .total-row strong { font-size: 22px; }
  .datebar { margin-top: 10px; gap: 6px; }
  .date-pick { font-size: 16px; padding: 8px 6px; }
  .savebar { padding: 8px 10px calc(8px + var(--sab)); }
  .savebar .btn { padding: 12px 18px; }
  .hero .big { font-size: 30px; }
  .gauge-box .gauge { width: 130px; }
  table.t { font-size: 12.5px; }
  table.t th, table.t td { padding: 6px 4px; }
}
@media (max-width: 400px) {
  table.t { font-size: 12px; }
  table.t th, table.t td { padding: 6px 3px; }
  table.t td:first-child { white-space: normal; min-width: 4.5em; }
  table.t th.st i { display: none; }
}
@media (max-width: 360px) {
  table.t th, table.t td { padding: 6px 2px; }
  table.t td:first-child { min-width: 3.6em; }
  .mon-grid { grid-template-columns: 1fr; }
  .tabs button { padding: 8px 8px; font-size: 13px; }
  .budget-in input { width: 108px; }
  .top { gap: 6px; }
  .reload-btn { width: 34px; height: 34px; }
  .brand { font-size: 14px; }
}
