:root {
  --bg: #f2f4f7;
  --card: #ffffff;
  --ink: #1a2230;
  --muted: #6b7688;
  --line: #e2e6ec;
  --brand: #1e3a5f;
  --brand-ink: #ffffff;
  --pos: #1a7f4b;
  --neg: #c23b3b;
  --danger: #c23b3b;
  --radius: 14px;
  --tabbar-h: 62px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f141c;
    --card: #1a2230;
    --ink: #eef1f6;
    --muted: #93a0b4;
    --line: #2a3444;
    --brand: #3d6ea5;
    --pos: #4fc584;
    --neg: #f0736f;
    --danger: #f0736f;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
}

.content {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 16px);
}

a { color: var(--brand); text-decoration: none; }

/* ---------- Tab bar ---------- */
.tabbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--line);
  z-index: 20;
}
.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-size: 12px;
  color: var(--muted);
}
.tab.active { color: var(--brand); font-weight: 600; }
.tab-ico { font-size: 21px; }

/* ---------- Header / navigation ---------- */
.dayhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
}
.dayhead.simple { justify-content: center; }
.dayhead-center { text-align: center; flex: 1; }
.dayhead-weekday { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.dayhead-date { font-size: 20px; font-weight: 600; margin-top: 2px; }
.dayhead-date input[type=date] {
  border: none; background: transparent; color: var(--ink);
  font-size: 20px; font-weight: 600; text-align: center;
}
.navbtn {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  font-size: 28px; line-height: 1;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; color: var(--ink);
}

/* ---------- Balances ---------- */
.balances { display: flex; gap: 12px; margin-bottom: 16px; }
.bal {
  flex: 1;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
}
.bal-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.bal-value { font-size: 30px; font-weight: 700; margin: 4px 0; font-variant-numeric: tabular-nums; }
.bal-value.muted { color: var(--muted); }
.bal-sub { font-size: 13px; color: var(--muted); }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* ---------- Cards & forms ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.card-title { margin: 0; font-size: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }
label { font-size: 13px; color: var(--muted); }
input[type=time], input[type=date], input[type=number], input[type=text], input[type=password] {
  width: 100%;
  font-size: 18px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--ink);
}
.time-input { display: flex; gap: 8px; align-items: stretch; }
.time-input input { flex: 1; }
.btn-now {
  border: 1px solid var(--brand);
  background: transparent;
  color: var(--brand);
  border-radius: 10px;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
}

/* ---------- Segmented control ---------- */
.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.seg { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; }
.seg span {
  display: flex; align-items: center; justify-content: center;
  padding: 10px 4px;
  font-size: 13px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  text-align: center;
  min-height: 44px;
}
.seg input:checked + span {
  background: var(--brand);
  color: var(--brand-ink);
  border-color: var(--brand);
  font-weight: 600;
}

/* ---------- Buttons ---------- */
.btn {
  display: block;
  width: 100%;
  padding: 14px;
  font-size: 17px;
  font-weight: 600;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  cursor: pointer;
}
.btn-primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }

/* ---------- Month list ---------- */
.month-summary { align-items: center; text-align: center; }
.ms-main { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; }
.ms-grid { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; }
.ms-grid > div { display: flex; flex-direction: column; }
.ms-grid span { font-size: 12px; color: var(--muted); }
.ms-grid strong { font-size: 16px; font-variant-numeric: tabular-nums; }

.daylist { list-style: none; margin: 0; padding: 0; }
.daylist-item { border-bottom: 1px solid var(--line); }
.daylist-item a {
  display: grid;
  grid-template-columns: 54px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 12px 6px;
  color: var(--ink);
}
.daylist-item.weekend { background: color-mix(in srgb, var(--muted) 7%, transparent); }
.daylist-item.open .dl-open { color: var(--neg); font-weight: 600; }
.dl-date { display: flex; flex-direction: column; align-items: center; }
.dl-date strong { font-size: 18px; }
.dl-wd { font-size: 11px; color: var(--muted); }
.dl-info { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; }
.dl-brk { margin-left: 6px; font-size: 12px; }
.dl-bal { font-weight: 700; font-variant-numeric: tabular-nums; }
.dl-muted { color: var(--muted); }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  background: var(--brand); color: var(--brand-ink); font-size: 12px;
}

/* ---------- Login & misc ---------- */
.login-wrap { max-width: 360px; margin: 12vh auto 0; padding: 0 4px; }
.login-title { text-align: center; margin-bottom: 20px; }
.notice { background: color-mix(in srgb, var(--brand) 12%, var(--card)); border: 1px solid var(--line); padding: 12px; border-radius: 10px; font-size: 14px; }
.notice.ok { background: color-mix(in srgb, var(--pos) 18%, var(--card)); }
.notice.small { font-size: 13px; }
.error { color: var(--neg); font-weight: 600; text-align: center; }
.hint { font-size: 13px; color: var(--muted); margin: -4px 0 0; }
code { background: color-mix(in srgb, var(--muted) 18%, transparent); padding: 2px 6px; border-radius: 6px; font-size: 14px; }
.logout-row { text-align: center; margin-top: 8px; }
.logout-row a { color: var(--muted); font-size: 14px; }
.linkbtn {
  background: none; border: none; padding: 4px 8px;
  color: var(--muted); font-size: 14px; cursor: pointer;
  text-decoration: underline; font-family: inherit;
}
