:root {
  --bg: #f3f4f6;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --brand: #14213d;
  --accent: #fca311;
  --ok: #15803d;
  --ok-bg: #dcfce7;
  --bad: #b91c1c;
  --bad-bg: #fee2e2;
  --warn: #92400e;
  --warn-bg: #fef3c7;
  --radius: 12px;
  --tabbar-h: 60px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
.app { max-width: 640px; margin: 0 auto; padding: 12px 16px calc(var(--tabbar-h) + 24px + env(safe-area-inset-bottom)); }
.app.has-sticky { padding-bottom: calc(var(--tabbar-h) + 220px + env(safe-area-inset-bottom)); }
.loading { padding: 40px 0; text-align: center; color: var(--muted); }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: var(--brand); color: #fff;
}
.topbar-title { font-weight: 600; }
.link { background: none; border: 0; color: inherit; opacity: .85; padding: 6px 0; cursor: pointer; }

.offline { position: sticky; top: 0; z-index: 20; background: var(--bad); color: #fff; text-align: center; padding: 8px; font-size: 14px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; height: var(--tabbar-h); display: flex; align-items: center; justify-content: center;
  color: var(--muted); text-decoration: none; font-size: 14px; font-weight: 500;
}
.tabbar a.active { color: var(--brand); box-shadow: inset 0 3px 0 var(--accent); }

h1 { font-size: 22px; margin: 8px 0 12px; }
h2 { font-size: 15px; margin: 0 0 10px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.row + .row { margin-top: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

label.field { display: block; }
label.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 4px; }
input[type=text], input[type=password], input[type=date], input[type=month], input:not([type]), select, textarea {
  width: 100%; min-height: 46px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px; background: #fff; font-size: 17px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: transparent; }
input.money { text-align: right; font-variant-numeric: tabular-nums; }
input[readonly] { background: var(--bg); }
.field + .field, .grid2 + .field, .field + .grid2 { margin-top: 10px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 10px 16px; border-radius: 10px; border: 0;
  background: var(--brand); color: #fff; font-weight: 600; cursor: pointer; text-decoration: none;
}
.btn.block { width: 100%; }
.btn.secondary { background: #e5e7eb; color: var(--text); }
.btn.accent { background: var(--accent); color: var(--brand); }
.btn.danger { background: var(--bad); }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; margin-top: 12px; }
.btn-row > * { flex: 1; }

.value { font-variant-numeric: tabular-nums; font-weight: 600; white-space: nowrap; }
.big { font-size: 22px; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }

.sticky-sum {
  position: fixed; left: 0; right: 0; bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom)); z-index: 9;
  background: var(--card); border-top: 1px solid var(--line); box-shadow: 0 -4px 12px rgba(0,0,0,.06);
}
.sticky-sum .inner { max-width: 640px; margin: 0 auto; padding: 10px 16px 12px; }
.sticky-sum .row + .row { margin-top: 4px; }
.save-state { font-size: 12px; color: var(--muted); text-align: right; min-height: 16px; }

.expense { display: flex; gap: 10px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); }
.expense:first-child { border-top: 0; }
.expense .info { flex: 1; min-width: 0; }
.expense .info .c { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; }
.thumb { width: 44px; height: 44px; border-radius: 8px; object-fit: cover; background: var(--bg); flex: none; }
.icon-btn { background: none; border: 0; padding: 8px; color: var(--muted); font-size: 20px; line-height: 1; cursor: pointer; }

.badge { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 999px; white-space: nowrap; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.bad { background: var(--bad-bg); color: var(--bad); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.neutral { background: #e5e7eb; color: var(--text); }

.list a, .list .item { display: block; text-decoration: none; color: inherit; padding: 12px 14px; border-top: 1px solid var(--line); }
.list > :first-child { border-top: 0; }
.list.card { padding: 0; overflow: hidden; }
.item.missing { background: var(--bad-bg); }
.item.flagged { box-shadow: inset 4px 0 0 var(--bad); }
.item .badges { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }

.month-nav { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.month-nav .title { flex: 1; text-align: center; font-weight: 600; font-size: 18px; }

.notice { padding: 12px 14px; border-radius: 10px; margin-bottom: 12px; font-size: 15px; }
.notice.bad { background: var(--bad-bg); color: var(--bad); }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.ok { background: var(--ok-bg); color: var(--ok); }

.login-wrap { min-height: 80vh; display: flex; flex-direction: column; justify-content: center; }
.login-logo { width: 72px; height: 72px; border-radius: 18px; margin: 0 auto 12px; display: block; }

.toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabbar-h) + 20px + env(safe-area-inset-bottom)); z-index: 50;
  max-width: 480px; margin: 0 auto; background: #111827; color: #fff; padding: 12px 14px; border-radius: 10px; text-align: center;
}
.toast.error { background: var(--bad); }

dialog { border: 0; border-radius: 14px; padding: 18px; width: min(92vw, 420px); }
dialog::backdrop { background: rgba(0,0,0,.45); }
dialog h3 { margin: 0 0 8px; }

table.t { width: 100%; border-collapse: collapse; font-size: 15px; }
table.t td, table.t th { padding: 8px 0; border-top: 1px solid var(--line); text-align: left; }
table.t tr:first-child td, table.t tr:first-child th { border-top: 0; }
table.t .r { text-align: right; font-variant-numeric: tabular-nums; }
table.t th { font-size: 13px; color: var(--muted); font-weight: 500; }

.audit { font-size: 14px; padding: 8px 0; border-top: 1px solid var(--line); }
.audit:first-child { border-top: 0; }
.photo-full { max-width: 100%; border-radius: 10px; }
.hidden { display: none !important; }
.grid2 > .field { margin-top: 0; }

.hint { font-size: 13px; color: var(--muted); margin: 6px 0 0; line-height: 1.35; }
.field + .hint + .field { margin-top: 12px; }
.guide summary { font-weight: 600; cursor: pointer; padding: 2px 0; color: var(--brand); }
.guide ol { margin: 10px 0 6px; padding-left: 20px; font-size: 15px; }
.guide li + li { margin-top: 6px; }
.help-row { cursor: pointer; }
.q { display: inline-flex; align-items: center; justify-content: center; width: 17px; height: 17px; border-radius: 50%;
  background: var(--line); color: var(--muted); font-size: 11px; font-weight: 700; margin-left: 2px; vertical-align: 1px; }
