:root {
  --brand: #0f766e;
  --brand-tint: #e4f2f0;
  --bg: #f4f6f5;
  --card: #ffffff;
  --text: #16211d;
  --muted: #5a6b65;
  --line: #dde3e1;
  --danger: #b3261e;
  --warn: #8a5a00;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }
#app svg { width: 20px; height: 20px; flex: none; }

/* top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 4px;
  background: var(--brand); color: #fff;
  padding: calc(env(safe-area-inset-top) + 6px) 6px 6px;
  min-height: 54px;
}
.topbar h1 { flex: 1; margin: 0 0 0 6px; font-size: 18px; font-weight: 600; }
.brand { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; }
.topbar-spacer { width: 44px; height: 44px; }
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; padding: 0;
  background: none; border: 0; border-radius: 12px; cursor: pointer;
}
.topbar .icon-btn:active { background: rgba(255,255,255,.18); }

/* content */
.content { padding: 12px 12px calc(96px + env(safe-area-inset-bottom)); max-width: 640px; margin: 0 auto; }
.form.content { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }

/* tabs */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1; min-height: 56px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: 0; color: var(--muted); font-size: 13px; cursor: pointer;
}
.tab.active { color: var(--brand); font-weight: 600; }

/* month navigation */
.monthnav {
  display: flex; align-items: center; justify-content: space-between;
  margin: 0 0 12px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px;
}
.monthnav strong { font-size: 16px; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px;
  border: 1px solid transparent; border-radius: 12px;
  background: var(--card); color: var(--text);
  font-size: 16px; font-weight: 600; cursor: pointer;
}
.btn.wide { width: 100%; margin: 12px 0; }
.btn.primary { background: var(--brand); color: #fff; }
.btn.danger { background: var(--card); color: var(--danger); border-color: #e8cbc9; }
.btn.small { min-height: 44px; font-size: 14px; padding: 0 14px; }
.btn:disabled { opacity: .55; }

/* summary */
.statcard {
  display: flex; gap: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  padding: 12px; margin-bottom: 4px;
}
.stat { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.stat-label { font-size: 14px; color: var(--muted); }
.stat-value { font-size: 18px; }
.stat-value.over { color: var(--danger); }

/* filter chips */
.chips { display: flex; gap: 8px; margin: 0 0 10px; overflow-x: auto; }
.chip {
  flex: none; display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px;
  background: var(--card); color: var(--text);
  border: 1px solid var(--line); border-radius: 999px;
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.chip.active { background: var(--brand); border-color: var(--brand); color: #fff; }
.filtersum { margin: 0 0 8px; font-size: 14px; color: var(--muted); }

/* rows */
.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.row {
  width: 100%; display: flex; align-items: center; gap: 10px;
  min-height: 60px; padding: 10px 12px;
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  text-align: left; cursor: pointer;
}
.row-block { flex-direction: column; align-items: stretch; gap: 4px; }
.row-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: 14px; color: var(--muted); }
.row-amount { font-weight: 700; white-space: nowrap; }
.pending, .flag { display: inline-flex; align-items: center; gap: 4px; margin-top: 2px; font-size: 13px; color: var(--warn); }
.pending svg, .flag svg { width: 14px; height: 14px; }
.dot { display: inline-block; width: 12px; height: 12px; margin-right: 8px; border-radius: 50%; background: var(--muted); vertical-align: middle; }

/* bars and charts */
.bar { display: block; height: 8px; margin-top: 6px; border-radius: 999px; background: #e6ebe9; overflow: hidden; }
.bar-fill { display: block; height: 100%; background: var(--brand); }
.bar-fill.over { background: var(--danger); }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; margin: 12px 0; }
.card h2 { margin: 0 0 10px; font-size: 14px; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.catrow { margin-bottom: 12px; }
.catrow:last-child { margin-bottom: 0; }
.catrow-head { display: flex; justify-content: space-between; gap: 8px; font-size: 15px; }
.catrow-note { margin: 4px 0 0; font-size: 13px; color: var(--muted); }
.cols { display: flex; gap: 6px; align-items: flex-end; }
.col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.col-value { font-size: 12px; color: var(--muted); min-height: 16px; }
.col-track { width: 100%; height: 96px; display: flex; align-items: flex-end; }
.col-bar { display: block; width: 100%; background: var(--brand); border-radius: 6px 6px 0 0; }
.col-label { font-size: 12px; color: var(--muted); }

/* forms */
.field { margin-bottom: 16px; }
.field-label { display: block; margin-bottom: 6px; font-size: 15px; font-weight: 600; }
.req { color: var(--danger); }
input[type="text"], input[type="number"], input[type="date"], input[type="time"], input[type="email"], input[type="tel"], select, textarea {
  width: 100%; min-height: 48px; padding: 10px 12px;
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand); outline-offset: 1px; }
.field.invalid input, .field.invalid select, .field.invalid textarea { border-color: var(--danger); }
.err { margin: 6px 0 0; font-size: 14px; color: var(--danger); }
.hint { margin: 6px 0 0; font-size: 14px; color: var(--muted); }
.note { margin: 0 0 16px; padding: 10px 12px; background: var(--brand-tint); border-radius: 12px; font-size: 15px; }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.photo-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; min-height: 52px;
  border: 1px dashed var(--brand); border-radius: 12px;
  color: var(--brand); font-weight: 600; cursor: pointer;
}
.photo-preview { margin-top: 10px; }
.photo-preview img { display: block; width: 100%; max-height: 240px; object-fit: cover; border: 1px solid var(--line); border-radius: 12px; }
.photo-preview .btn { margin-top: 8px; }
.swatch { width: 28px; height: 28px; margin-top: 8px; border: 1px solid var(--line); border-radius: 50%; background: var(--line); }

/* empty states */
.empty { padding: 32px 16px; text-align: center; color: var(--muted); background: var(--card); border: 1px dashed var(--line); border-radius: 14px; }
.empty svg { width: 36px; height: 36px; color: var(--brand); }
.empty p { margin: 8px 0 0; }
.empty .btn { margin-top: 12px; }
.muted { color: var(--muted); }
.footnote { margin: 16px 4px 0; font-size: 14px; color: var(--muted); }

/* menu sheet */
.backdrop { position: fixed; inset: 0; z-index: 40; display: flex; align-items: flex-end; background: rgba(0,0,0,.45); }
.sheet { width: 100%; max-width: 640px; margin: 0 auto; padding: 12px 12px calc(12px + env(safe-area-inset-bottom)); background: var(--card); border-radius: 18px 18px 0 0; }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 4px 4px 12px; }
.avatar { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; border-radius: 50%; background: var(--brand-tint); color: var(--brand); }
.sheet-user { flex: 1; display: flex; flex-direction: column; }
.sheet-user small { color: var(--muted); font-size: 14px; }
.sheet-item {
  display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 0 12px;
  background: none; border: 0; border-radius: 12px; text-align: left; font-size: 16px; cursor: pointer;
}
.sheet-item:active { background: var(--brand-tint); }
