:root {
  --bg: #f6f7f9; --surface: #ffffff; --surface-2: #eef1f5; --text: #1a1c1e; --muted: #5c6470;
  --primary: #1F3A5F; --primary-soft: #dbe6f5; --on-primary: #ffffff; --outline: #d6dae0; --error: #b3261e;
  --shadow: 0 1px 2px rgba(0,0,0,.08);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1418; --surface: #1b2126; --surface-2: #242c33; --text: #e6e9ec; --muted: #9aa4ae;
    --primary: #8ec5ff; --primary-soft: #1e3450; --on-primary: #0b1a2c; --outline: #3a444e; --error: #ffb4ab;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.4 -apple-system, system-ui, "Segoe UI", Roboto, sans-serif; -webkit-text-size-adjust: 100%; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
#app { min-height: 100dvh; display: flex; flex-direction: column; }

header.top { position: sticky; top: 0; z-index: 5; background: var(--bg); padding: calc(env(safe-area-inset-top) + 8px) 8px 8px; display: flex; align-items: center; gap: 4px; }
header.top h1 { flex: 1; margin: 0 8px; font-size: 22px; font-weight: 500; }
.icon-btn { width: 44px; height: 44px; border-radius: 22px; display: inline-flex; align-items: center; justify-content: center; color: var(--text); }
.icon-btn:active { background: var(--surface-2); }
.icon-btn.pending { color: var(--error); }
.icon-btn svg { width: 24px; height: 24px; fill: currentColor; }

main { flex: 1; padding: 8px 16px calc(env(safe-area-inset-bottom) + 120px); display: flex; flex-direction: column; gap: 8px; }
.card { background: var(--surface); border-radius: 14px; padding: 12px 16px; box-shadow: var(--shadow); }
.card.tappable:active { background: var(--surface-2); }
.summary { background: var(--primary-soft); color: var(--text); padding: 16px; display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.summary .label { font-size: 12px; font-weight: 500; color: var(--muted); }
.summary .value { font-size: 22px; font-weight: 600; }
.summary .foot { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.row { display: flex; align-items: center; gap: 8px; }
.row .grow { flex: 1; }
.meta { font-size: 12px; color: var(--muted); }
.badge { font-size: 12px; font-weight: 600; color: var(--primary); white-space: nowrap; }
.station { font-size: 17px; font-weight: 500; margin: 2px 0; }
.empty { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); padding: 40px 20px; }

nav.bottom { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; background: var(--surface); padding-bottom: env(safe-area-inset-bottom); border-top: 1px solid var(--outline); }
nav.bottom a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 10px 0 12px; font-size: 12px; color: var(--muted); text-decoration: none; }
nav.bottom a.active { color: var(--text); }
nav.bottom a svg { width: 24px; height: 24px; fill: currentColor; border-radius: 16px; padding: 4px 16px; box-sizing: content-box; }
nav.bottom a.active svg { background: var(--primary-soft); }
.fab { position: fixed; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 84px); z-index: 6; background: var(--primary); color: var(--on-primary); border-radius: 16px; padding: 16px 20px; font-weight: 600; display: flex; align-items: center; gap: 8px; box-shadow: 0 4px 12px rgba(0,0,0,.25); }
.fab svg { width: 22px; height: 22px; fill: currentColor; }

form.entry { display: flex; flex-direction: column; gap: 6px; }
.field { display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--muted); }
.field .box { position: relative; }
.field input { width: 100%; padding: 14px 12px; border: 1px solid var(--outline); border-radius: 8px; background: var(--surface); font-size: 17px; }
.field input:focus { outline: 2px solid var(--primary); outline-offset: -1px; }
.field.error input { border-color: var(--error); }
.field .hint { font-size: 12px; color: var(--muted); min-height: 16px; }
.field.error .hint { color: var(--error); }
.field.derived .hint { color: var(--primary); }
.field .box .icon-btn { position: absolute; right: 2px; top: 50%; transform: translateY(-50%); }
.field .box .spinner { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.switch { display: flex; align-items: center; gap: 12px; padding: 8px 0; }
.switch .grow { flex: 1; }
.switch input { width: 48px; height: 28px; appearance: none; background: var(--outline); border-radius: 14px; position: relative; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 11px; background: var(--surface); transition: left .15s; }
.switch input:checked { background: var(--primary); }
.switch input:checked::after { left: 23px; }
.btn { border-radius: 24px; padding: 14px 20px; font-weight: 600; text-align: center; width: 100%; }
.btn.primary { background: var(--primary); color: var(--on-primary); }
.btn.outline { border: 1px solid var(--outline); color: var(--primary); }
.btn.text { color: var(--primary); width: auto; padding: 10px 12px; }
.btn:disabled { opacity: .5; }
.spinner { width: 18px; height: 18px; border: 2px solid var(--outline); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.error-text { color: var(--error); font-size: 13px; }

.chart-card h2 { margin: 0; font-size: 17px; font-weight: 500; }
.chart-card .unit { font-size: 12px; color: var(--muted); }
.chart-card .detail { font-size: 13px; color: var(--muted); min-height: 36px; white-space: pre-line; margin: 4px 0 8px; }
.chart-card canvas { width: 100%; height: 180px; display: block; touch-action: manipulation; }

dialog { border: 0; border-radius: 20px; background: var(--surface); color: var(--text); padding: 20px; width: min(92vw, 380px); box-shadow: 0 8px 30px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h2 { margin: 0 0 12px; font-size: 20px; font-weight: 500; }
dialog p { margin: 6px 0; font-size: 14px; }
dialog .actions { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
dialog .foot { display: flex; justify-content: flex-end; gap: 4px; margin-top: 8px; }
.toast { position: fixed; left: 16px; right: 16px; bottom: calc(env(safe-area-inset-bottom) + 150px); z-index: 7; background: var(--text); color: var(--bg); padding: 12px 16px; border-radius: 10px; font-size: 14px; text-align: center; }
