:root {
  --bg: #EAF2EC; --card: #FFFFFF; --ink: #14301D; --muted: #54705E; --border: #C6D6CB;
  --primary: #217A45; --on-primary: #FFFFFF; --accent: #F0A800; --warn: #A33A12; --ok: #1E7A45;
  --near: #8A6100; --track: #DCE8DF;
  --tabbar-h: 64px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0B1A10; --card: #14291B; --ink: #E9F4EC; --muted: #9CB8A6; --border: #28462F;
    --primary: #6FCE94; --on-primary: #08230F; --accent: #FFC02E; --warn: #FF9A6B; --ok: #6FD39A;
    --near: #FFC02E; --track: #1E3A27;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 17px; line-height: 1.4;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 14px calc(env(safe-area-inset-bottom, 0px) + var(--tabbar-h) + 24px);
}
main { max-width: 460px; margin: 0 auto; }
[hidden] { display: none !important; }
h1 { font-size: 1.15rem; font-weight: 700; margin: 0 0 12px; }
h2 { font-size: 1.05rem; font-weight: 700; margin: 22px 0 10px; }

/* ---------- app shell ---------- */
.apphead { display: flex; align-items: center; gap: 10px; margin: 0 0 12px; }
.apphead img { width: 44px; height: 44px; border-radius: 10px; }
.apphead h1 { margin: 0; font-size: 1.25rem; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.backbtn { flex: 0 0 auto; margin-right: -4px; }
.headactions { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.chip.viewonly { flex: 0 0 auto; color: var(--muted); margin-left: 0; border-color: var(--near); font-size: 0.75rem; }
.chip.shared-color { color: var(--primary); border-color: var(--primary); background: var(--bg); }
.chip.shared-color { color: var(--primary); border-color: var(--primary); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 1000;
  display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--card); border-top: 1px solid var(--border);
  padding: 4px 8px calc(env(safe-area-inset-bottom, 0px) + 4px);
}
.tabbar button {
  appearance: none; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 0.85rem; font-weight: 600; min-height: 56px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.tabbar button svg { width: 26px; height: 26px; }
.tabbar button[aria-selected="true"] { color: var(--primary); }
.banner {
  background: var(--card); border: 1px solid var(--accent); border-radius: 14px;
  padding: 10px 14px; margin: 0 0 12px; font-size: 0.92rem;
  display: flex; gap: 10px; align-items: flex-start;
}
.banner p { margin: 0; flex: 1; }
.banner button { appearance: none; border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 1.3rem; line-height: 1; cursor: pointer; padding: 0 2px; }
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 3000;
  bottom: calc(env(safe-area-inset-bottom, 0px) + var(--tabbar-h) + 16px);
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-weight: 600; font-size: 0.95rem; max-width: 90vw; text-align: center;
  opacity: 0; transition: opacity .2s; pointer-events: none;
}
.toast.show { opacity: 1; }

/* ---------- month switcher ---------- */
.months {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 2px 4px; margin-bottom: 12px;
}
.months span { font-weight: 700; font-size: 1.05rem; }
.mbtn {
  appearance: none; border: 0; background: transparent; color: var(--primary);
  min-width: 48px; min-height: 48px; border-radius: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.mbtn svg { width: 26px; height: 26px; }
.months[hidden] { display: none; }

/* ---------- form controls ---------- */
.field { margin-bottom: 14px; }
.field > label, .field > .lab { display: block; font-weight: 600; margin-bottom: 6px; }
select, input.text, textarea {
  width: 100%; min-height: 56px;
  border: 1px solid var(--border); border-radius: 14px; background-color: var(--card); color: var(--ink);
  font: inherit; font-size: 1.1rem; font-weight: 600; padding: 8px 14px;
}
input[type="date"] {
  width: 100%; min-height: 56px;
  border: 1px solid var(--border); border-radius: 14px; background-color: var(--card); color: var(--ink);
  font: inherit; font-size: 1.1rem; font-weight: 600; padding: 8px 14px;
}
select {
  appearance: none; -webkit-appearance: none; padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='9'%3E%3Cpath d='M1 1l6 6 6-6' fill='none' stroke='%237A8F9A' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.note { color: var(--muted); font-size: 0.9rem; margin: 8px 0 12px; }

.btn {
  appearance: none; display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  min-height: 56px; border-radius: 14px; border: 1px solid var(--border);
  background: var(--card); color: var(--ink); font: inherit; font-weight: 700; font-size: 1.05rem;
  cursor: pointer; touch-action: manipulation; padding: 8px 14px; text-decoration: none;
}
.btn.primary { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }
.btn.big { min-height: 68px; font-size: 1.25rem; }
.btn.small { width: auto; min-height: 44px; padding: 4px 18px; font-size: 0.95rem; }
.btn.danger { color: var(--warn); border-color: var(--warn); }
.btn:disabled { opacity: 0.55; }
.btns { display: grid; gap: 10px; margin: 12px 0; }
.check { display: flex; align-items: center; gap: 12px; font-weight: 600; min-height: 48px; cursor: pointer; }
.check input { width: 26px; height: 26px; accent-color: var(--primary); }
.scopes { border: 1px solid var(--border); border-radius: 14px; padding: 6px 12px 4px; margin: 10px 0; }
.scopes legend { font-weight: 700; font-size: 0.95rem; padding: 0 4px; }
.scope { display: flex; align-items: flex-start; gap: 12px; min-height: 44px; padding: 8px 0; cursor: pointer; }
.scope input { width: 24px; height: 24px; margin: 2px 0 0; flex: 0 0 auto; accent-color: var(--primary); }
.scope .lbl { display: grid; gap: 2px; }
.scope .note2 { font-size: 0.88rem; font-weight: 400; color: var(--muted); }

/* ---------- cards and lists ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 18px; padding: 14px 16px; margin-bottom: 14px; }
.card h2 { margin-top: 0; }
.card p { margin: 6px 0; }
.status { font-size: 0.92rem; color: var(--muted); }
.empty { color: var(--muted); text-align: center; padding: 20px 0; }
.viewstop { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 4px; }
.viewstop h2 { margin: 12px 0 4px; min-width: 0; }
.viewstop .btn { margin: 12px 0 4px; }
.viewstop .btn.small { white-space: nowrap; }

.list { display: grid; gap: 10px; margin-bottom: 14px; }
.list .row {
  display: flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 6px 8px 6px 0;
}
.list .row > .main {
  appearance: none; flex: 1; min-width: 0; text-align: left; cursor: pointer;
  background: transparent; color: var(--ink); border: 0; font: inherit;
  min-height: 48px; padding: 6px 12px; display: grid; gap: 2px;
}
.list .bcard { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.list .bcard > .main { min-height: 60px; padding: 10px 14px; }
.list .bcard .morebtn {
  appearance: none; flex: 0 0 auto; border: 1px solid var(--border); border-radius: 10px;
  background: transparent; color: var(--muted); width: 44px; min-height: 44px;
  cursor: pointer; font: inherit; font-size: 1.25rem; font-weight: 700; line-height: 1;
  display: inline-flex; align-items: center; justify-content: center; padding-bottom: 2px;
}
.list .t1 { font-weight: 700; display: flex; justify-content: space-between; gap: 8px; }
.list .t1 span:last-child { color: var(--muted); font-weight: 600; font-size: 0.95rem; white-space: nowrap; font-variant-numeric: tabular-nums; }
.list .t2 { color: var(--muted); font-size: 0.92rem; white-space: nowrap; }
.list .main .t1 span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list .main .chips { flex: 0 0 auto; display: flex; gap: 4px; }
.list .reorder { display: flex; flex-direction: column; gap: 2px; }
.reorder button {
  appearance: none; border: 1px solid var(--border); background: var(--card); color: var(--primary);
  min-width: 44px; min-height: 44px; border-radius: 10px; cursor: pointer; font: inherit; font-weight: 800;
  display: flex; align-items: center; justify-content: center;
}
.reorder button svg { width: 20px; height: 20px; }
.reorder button:disabled { opacity: 0.35; }

/* ---------- summary card ---------- */
.summary-row { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; font-variant-numeric: tabular-nums; }
.summary-row + .summary-row { border-top: 1px solid var(--border); }
.summary-row .lab { color: var(--muted); }
.summary-row .val { font-weight: 700; }
.summary-row.total .lab, .summary-row.total .val { font-weight: 800; color: var(--ink); }
.summary-row .val.warn { color: var(--warn); }
.summary-note { color: var(--ok); font-weight: 600; font-size: 0.92rem; margin: 8px 0 0; }
.sarow { appearance: none; width: 100%; background: transparent; border-width: 0; color: var(--ink); font: inherit; cursor: pointer; text-align: left; }
.sarow .salognote { color: var(--muted); font-weight: 400; font-size: 0.9rem; }

/* ---------- track ---------- */
.tcard { padding: 12px 14px; }
.tcard .thead {
  appearance: none; width: 100%; display: grid; gap: 4px; text-align: left; cursor: pointer;
  background: transparent; border: 0; color: var(--ink); font: inherit; padding: 4px 0; min-height: 48px;
}
.thead .t1 { font-weight: 700; display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.thead .nums { display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 0.92rem; font-variant-numeric: tabular-nums; }
.thead .nums .rem { font-weight: 700; }
.thead .nums .rem.ok { color: var(--ok); }
.thead .nums .rem.near { color: var(--near); }
.thead .nums .rem.over { color: var(--warn); }
.chip { display: inline-block; font-size: 0.8rem; font-weight: 700; padding: 1px 8px; border-radius: 999px; border: 1px solid var(--border); margin-left: 6px; }
.chip.empty { border-color: var(--near); color: var(--near); }
.chip.over { border-color: var(--warn); color: var(--warn); }
.chip.fund { border-color: var(--primary); color: var(--primary); }
.prog { height: 10px; border-radius: 5px; background: var(--track); overflow: hidden; margin: 6px 0 2px; }
.prog i { display: block; height: 100%; border-radius: 5px; background: var(--ok); min-width: 0; transition: width .25s; }
.prog.near i { background: var(--near); }
.prog.over i { background: var(--warn); }
.texp { border-top: 1px solid var(--border); margin-top: 8px; padding-top: 6px; display: grid; gap: 2px; }
.texp .xrow {
  appearance: none; width: 100%; display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
  background: transparent; border: 0; color: var(--ink); font: inherit; text-align: left; cursor: pointer;
  min-height: 44px; padding: 8px 2px;
}
.xrow + .xrow { border-top: 1px solid var(--border); }
.xrow .xwhat { min-width: 0; }
.xrow .xnote { display: block; color: var(--muted); font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- sharing ---------- */
.headactions .btn.small { min-height: 40px; padding: 2px 12px; font-size: 0.9rem; }
.headactions .btn svg { width: 16px; height: 16px; }
.skipnote { border: 1px solid var(--near); border-radius: 14px; padding: 10px 12px; margin: 10px 0; font-size: 0.92rem; }
.skipnote p { margin: 0 0 8px; }
.skipnote .btn { width: auto; min-height: 44px; padding: 4px 18px; font-size: 0.95rem; }
.btns.grid2 { grid-template-columns: 1fr 1fr; }
#joinCard .modal h2 { color: var(--ink); }
#joinCard .modal ol { padding-left: 20px; margin: 8px 0; }
#joinCard .modal li { margin-bottom: 6px; }
#joinCard .modal-actions { grid-template-columns: 1fr; }
.xrow .xamt { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- sheet ---------- */
.sheet {
  position: fixed; inset: 0; z-index: 2000; background: var(--bg); overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) max(14px, calc((100% - 460px) / 2)) calc(env(safe-area-inset-bottom, 0px) + 40px);
}
.sheethead {
  position: sticky; top: calc(-1 * (env(safe-area-inset-top, 0px) + 8px)); z-index: 2;
  background: var(--bg); display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 0 10px; margin-top: calc(-1 * (env(safe-area-inset-top, 0px) + 8px));
  border-bottom: 1px solid var(--border); margin-bottom: 12px;
}
.sheethead h2 { margin: 0; }
.headbtns { display: flex; gap: 8px; }
.headbtns .btn { width: auto; min-height: 46px; padding: 6px 16px; }

/* ---------- danger zone + confirmation dialog ---------- */
.danger-zone { border-color: var(--warn); }
.danger-zone h2 { color: var(--warn); }
.btn.danger-fill { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn.danger-fill:disabled { opacity: 0.4; }
.modal-back {
  position: fixed; inset: 0; z-index: 4600; background: rgba(4, 14, 8, 0.6);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal {
  background: var(--card); color: var(--ink); border: 1px solid var(--border); border-radius: 18px;
  padding: 18px 18px 14px; width: min(440px, 100%); max-height: calc(100vh - 32px); overflow-y: auto;
  box-shadow: 0 10px 40px rgba(0,0,0,.35);
}
.modal h2 { margin: 0 0 8px; color: var(--warn); }
.modal p, .modal li { font-size: 0.95rem; }
.modal ul { padding-left: 20px; margin: 8px 0; }
.modal li { margin-bottom: 6px; }
.modal-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.wipeerr { color: var(--warn); font-weight: 600; margin: 10px 0 0; }

/* ---------- lock screen ---------- */
.lock {
  position: fixed; inset: 0; z-index: 5000; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 24px;
}
.lock img { width: 120px; height: 120px; border-radius: 28px; }
.lock input { max-width: 240px; text-align: center; font-size: 1.6rem; letter-spacing: 0.3em; }
.lock .btn { max-width: 240px; }
.lock .bad { color: var(--warn); font-weight: 600; min-height: 1.4em; margin: 0; }

/* ---------- update banner ---------- */
.update {
  position: fixed; left: 50%; transform: translateX(-50%); z-index: 4000;
  top: calc(env(safe-area-inset-top, 0px) + 10px); width: min(440px, calc(100% - 28px));
  background: var(--primary); color: var(--on-primary); border-radius: 14px; padding: 10px 12px 10px 16px;
  display: flex; align-items: center; gap: 10px; box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.update p { margin: 0; flex: 1; font-weight: 600; }
.update button { appearance: none; border: 0; border-radius: 10px; font: inherit; font-weight: 700; cursor: pointer; min-height: 44px; padding: 0 14px; background: var(--on-primary); color: var(--primary); }
.update button.x { background: transparent; color: var(--on-primary); font-size: 1.4rem; padding: 0 6px; }
