/* Themes: light (default), dark, or follow the phone. Dark is deliberately soft: neutral grey, muted teal, no bright fills. */
:root {
  color-scheme: light dark;
  --bg: #eef2f0; --surface: #ffffff; --ink: #12201c; --muted: #53625c; --line: #d4ddd9;
  --accent: #0a6b5b; --accent-ink: #ffffff; --accent-soft: #dff0eb;
  --warn: #8a5300; --warn-bg: #fff1d6; --bad: #b3261e; --bad-bg: #fde7e5; --info-bg: #e5eef8; --info: #1d4a7a;
  --header-bg: #0a6b5b; --header-ink: #ffffff; --header-line: transparent;
  --toast-bg: #12201c; --toast-ink: #eef2f0;
  --radius: 12px; --nav-h: 64px; --rail-w: 92px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark;
  --bg: #16191c; --surface: #1e2226; --ink: #d9dedb; --muted: #929b97; --line: #2e3438;
  --accent: #5aa898; --accent-ink: #0e1815; --accent-soft: #233430;
  --warn: #d8a649; --warn-bg: #2e2819; --bad: #e5877e; --bad-bg: #352220; --info-bg: #1f2a36; --info: #8db3d6;
  --header-bg: #1e2226; --header-ink: #d9dedb; --header-line: #2e3438;
  --toast-bg: #2e3438; --toast-ink: #e6ebe8;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16191c; --surface: #1e2226; --ink: #d9dedb; --muted: #929b97; --line: #2e3438;
    --accent: #5aa898; --accent-ink: #0e1815; --accent-soft: #233430;
    --warn: #d8a649; --warn-bg: #2e2819; --bad: #e5877e; --bad-bg: #352220; --info-bg: #1f2a36; --info: #8db3d6;
    --header-bg: #1e2226; --header-ink: #d9dedb; --header-line: #2e3438;
    --toast-bg: #2e3438; --toast-ink: #e6ebe8;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.45 var(--font); font-variant-numeric: tabular-nums; }
.boot { padding: 2rem; color: var(--muted); }
h1 { font-size: 22px; margin: 0 0 12px; font-weight: 650; }
h2 { font-size: 17px; margin: 0; font-weight: 650; }
h3 { font-size: 14px; margin: 12px 0 4px; color: var(--muted); font-weight: 600; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* shell */
.top { padding: calc(env(safe-area-inset-top) + 10px) 16px 10px; background: var(--header-bg); color: var(--header-ink); border-bottom: 1px solid var(--header-line); }
.brand { display: flex; align-items: baseline; gap: 10px; max-width: 1080px; margin: 0 auto; }
.brand strong { font-size: 20px; letter-spacing: .2px; }
.brand span { font-size: 13px; opacity: .85; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.frame { display: block; }
.view { padding: 14px 14px calc(var(--nav-h) + env(safe-area-inset-bottom) + 24px); max-width: 1080px; margin: 0 auto; }
.nav { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: grid; grid-template-columns: repeat(3, 1fr);
  background: var(--surface); border-top: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.nav a { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-height: var(--nav-h);
  color: var(--muted); text-decoration: none; font-size: 12px; }
.nav a.on { color: var(--accent); font-weight: 650; }
.ico { display: inline-flex; }

/* cards */
.page { display: flex; flex-direction: column; gap: 14px; }
.cards { display: grid; gap: 14px; grid-template-columns: minmax(0, 1fr); align-items: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.card.flush { padding: 0; overflow: hidden; }
.card.center { text-align: center; display: flex; flex-direction: column; gap: 10px; align-items: center; padding: 28px 16px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }
.empty { color: var(--muted); font-size: 14px; padding: 6px 0; }
.hint { color: var(--muted); font-size: 13px; }
.msg { margin-bottom: 14px; }
.err { color: var(--bad); font-size: 14px; min-height: 0; }
.err:empty { display: none; }
.neg { color: var(--bad); }

/* chips and banners */
.chip { display: inline-block; font-size: 12px; line-height: 1; padding: 4px 8px; border-radius: 999px; font-weight: 600; }
.chip.open { background: var(--accent-soft); color: var(--accent); }
.chip.closed { background: var(--line); color: var(--muted); }
.chip.pending { background: var(--warn-bg); color: var(--warn); }
.banner { font-size: 14px; padding: 8px 10px; border-radius: 8px; margin-top: 10px; }
.banner.warn { background: var(--warn-bg); color: var(--warn); }
.banner.info { background: var(--info-bg); color: var(--info); }
.banner.top { margin: 0; border-radius: 0; text-align: center; }

/* ledger (card 1) */
.monthbar { display: grid; grid-template-columns: 48px 1fr 48px; gap: 8px; align-items: center; }
.monthname { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); min-height: 48px; font-size: 18px; font-weight: 650; cursor: pointer; }
.ledger { border-top: 1px solid var(--line); }
.row { display: flex; width: 100%; align-items: baseline; justify-content: space-between; gap: 12px; padding: 11px 2px;
  border: 0; border-bottom: 1px solid var(--line); background: none; text-align: left; min-height: 44px; }
.row.tap { cursor: pointer; }
.row.tap:hover, .row.tap:active { background: var(--accent-soft); }
.row .lbl { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.row .lbl small { display: block; color: var(--muted); font-size: 12px; }
.row .amt { white-space: nowrap; font-weight: 500; }
.row.sum { border-bottom: 2px solid var(--muted); font-weight: 650; }
.row.plus .amt { color: var(--accent); }
.row.strong { font-weight: 650; }
.hero { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin-top: 14px; padding: 12px; border-radius: 10px; background: var(--accent-soft); }
.hero.neg { background: var(--bad-bg); }
.hero-lbl { font-size: 14px; color: var(--muted); }
.hero-num { font-size: 30px; font-weight: 700; color: var(--accent); }
.hero.neg .hero-num { color: var(--bad); }
.carry { margin-top: 10px; font-size: 14px; color: var(--muted); overflow-wrap: anywhere; }
.note { margin-top: 8px; font-size: 14px; padding: 8px 10px; border-left: 3px solid var(--accent); background: var(--bg); }

/* forms and buttons */
.form { display: flex; flex-direction: column; gap: 12px; }
.form label { display: flex; flex-direction: column; gap: 4px; font-size: 14px; color: var(--muted); }
.form label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--ink); min-height: 44px; }
.form input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.form input, .form select, .form textarea { width: 100%; min-height: 46px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); color: var(--ink); }
.form textarea { resize: vertical; }
.form fieldset { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 10px; margin: 0; }
.form legend { font-size: 14px; font-weight: 600; padding: 0 6px; }
.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.big-out { display: flex; align-items: center; min-height: 46px; font-size: 18px; font-weight: 650; color: var(--ink); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 8px 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.danger { color: var(--bad); border-color: var(--bad); }
.btn.danger-text { color: var(--bad); }
.btn.icon { min-width: 46px; padding: 8px 10px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; }
.btn-row.wrap { flex-wrap: wrap; justify-content: flex-start; }
.btn-row.wrap .btn { flex: 1 1 140px; }

/* months and flats */
.mrow { display: flex; width: 100%; justify-content: space-between; align-items: center; gap: 10px; padding: 14px; min-height: 64px;
  background: none; border: 0; border-bottom: 1px solid var(--line); text-align: left; cursor: pointer; }
.mrow:last-child { border-bottom: 0; }
.mrow:hover { background: var(--accent-soft); }
.mname { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.mnums { display: flex; flex-direction: column; align-items: flex-end; }
.mnums small { color: var(--muted); font-size: 12px; }
.mnums strong { font-size: 17px; }
.frow { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.fbadge { flex: none; min-width: 44px; height: 44px; padding: 0 6px; display: flex; align-items: center; justify-content: center; border-radius: 10px; background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 14px; }
.finfo { flex: 1; min-width: 0; font-size: 14px; }
.finfo p { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.finfo .sub { color: var(--muted); font-size: 13px; }
.history p { font-size: 13px; color: var(--muted); }
.errs { margin: 0 0 12px; padding-left: 18px; font-size: 13px; color: var(--muted); font-family: ui-monospace, monospace; }

/* modal and toast */
dialog.modal { border: 0; padding: 0; background: transparent; width: min(560px, calc(100vw - 20px)); max-height: calc(100dvh - 20px); color: var(--ink); }
dialog.modal::backdrop { background: rgba(8, 16, 13, .55); }
.modal-body { background: var(--surface); border-radius: 16px; padding: 18px; max-height: calc(100dvh - 20px); overflow: auto; }
.modal-body > h2 { margin-bottom: 12px; font-size: 18px; }
.preview-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: #fff; }
canvas.preview { display: block; width: 100%; height: auto; }
#toast { position: fixed; left: 50%; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 14px); transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--toast-bg); color: var(--toast-ink); padding: 10px 16px; border-radius: 10px; font-size: 14px; max-width: calc(100vw - 32px); z-index: 20; transition: opacity .15s, transform .15s; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: var(--bad); color: #fff; }

/* tablet and desktop: left rail, two columns */
@media (min-width: 768px) {
  .frame { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); max-width: 1180px; margin: 0 auto; }
  .nav { position: sticky; top: 0; align-self: start; grid-template-columns: 1fr; border-top: 0; border-right: 1px solid var(--line); height: 100dvh; background: transparent;
    align-content: start; padding-top: 12px; z-index: 1; }
  .nav a { min-height: 76px; border-radius: 12px; margin: 0 8px; }
  .nav a.on { background: var(--accent-soft); }
  .view { padding: 20px 24px 40px; max-width: none; margin: 0; }
  .cards { grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); }
  #toast { bottom: 24px; }
  .monthbar { max-width: 420px; }
}
@media (min-width: 1100px) { .cards { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); } }
@media (max-width: 359px) { .two { grid-template-columns: minmax(0, 1fr); } .hero-num { font-size: 26px; } }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* v1.1: generic units, society tile, saved status */
.brand { flex-wrap: wrap; row-gap: 0; }
.brand .saved { margin-left: auto; font-size: 12px; opacity: .85; white-space: nowrap; }
.brand .saved.dirty { opacity: 1; background: var(--warn-bg); color: var(--warn); padding: 2px 8px; border-radius: 999px; }
.stack { display: flex; flex-direction: column; gap: 14px; }
.tile { display: flex; flex-direction: column; gap: 2px; padding: 12px; border-radius: 10px; background: var(--accent-soft); }
.tile-lbl { font-size: 13px; color: var(--muted); }
.tile-num { font-size: 28px; color: var(--accent); }
.tile-sub { font-size: 13px; color: var(--muted); }
.btn-row.tight { margin: 0; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.btn.slim { min-height: 40px; }
.bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 8px 0; border-top: 1px solid var(--line); }
.bar .btn { min-height: 40px; padding: 6px 12px; font-size: 14px; }
.pick { display: flex; align-items: center; justify-content: center; min-width: 40px; min-height: 44px; cursor: pointer; }
.pick input { width: 22px; height: 22px; accent-color: var(--accent); }
.flist { border-top: 1px solid var(--line); }
.frow { display: flex; align-items: center; gap: 2px; padding: 0; border-bottom: 1px solid var(--line); }
.fedit { flex: 1; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 8px 4px; min-height: 56px; background: none; border: 0; text-align: left; cursor: pointer; }
.fedit:hover { background: var(--accent-soft); }
.finfo { flex: 1; min-width: 0; display: flex; flex-direction: column; font-size: 14px; }
.finfo span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.finfo .l2 { color: var(--muted); font-size: 13px; }
.famt { font-weight: 650; white-space: nowrap; }
.famt.missing { color: var(--warn); font-weight: 600; font-size: 13px; }
@media (min-width: 768px) {
  .cards.settings { grid-template-columns: minmax(0, 1fr) minmax(0, 1.3fr); grid-template-rows: auto auto 1fr; }
  .c-soc { grid-column: 1; grid-row: 1; } .c-bak { grid-column: 1; grid-row: 2; align-self: start; } .c-app { grid-column: 1; grid-row: 3; align-self: start; } .c-flats { grid-column: 2; grid-row: 1 / span 3; }
}

/* v1.2: months */
.tight-top { margin-top: 0; }
.gapnote { padding: 6px 14px; font-size: 13px; color: var(--muted); background: var(--bg); border-bottom: 1px solid var(--line); text-align: center; }

/* v1.3: appearance + update bar */
.seg { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; padding: 4px; border-radius: 12px; background: var(--bg); border: 1px solid var(--line); }
.seg label { display: flex; align-items: center; justify-content: center; min-height: 44px; border-radius: 9px; cursor: pointer; font-weight: 600; font-size: 14px; color: var(--muted); text-align: center; padding: 0 6px; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label:has(input:checked) { background: var(--surface); color: var(--ink); box-shadow: 0 0 0 1.5px var(--accent) inset; }
.seg label:has(input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.ver { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.update-bar { position: fixed; left: 12px; right: 12px; bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 10px); z-index: 30; display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px 10px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--accent); color: var(--ink); box-shadow: 0 6px 24px rgba(0,0,0,.25); font-size: 14px; }
.update-bar .btn { min-height: 40px; }
@media (min-width: 768px) { .update-bar { left: auto; right: 24px; bottom: 24px; max-width: 420px; } }

/* v1.4: special collections */
.sprow { display: flex; width: 100%; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 2px; min-height: 56px; background: none; border: 0; border-top: 1px solid var(--line); text-align: left; cursor: pointer; }
.sprow:hover { background: var(--accent-soft); }
.spname { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-weight: 600; }
.spnums { display: flex; flex-direction: column; align-items: flex-end; }
.spnums small { color: var(--muted); font-size: 12px; }
.payrow .fbadge { min-width: 44px; }
.payrow.paid .l1 { color: var(--accent); font-weight: 600; }
.payrow .finfo .l1 { font-size: 14px; }
.pickrow { cursor: pointer; padding: 2px 0; }
.pickrow .finfo { padding-left: 6px; }

/* v1.4.1: rows inside forms (create special collection) must stay one line: checkbox | flat | owner | amount.
   ".form label" makes labels columns, so these rows need a more specific override. */
.form .frow, .form .pick, .form .bar { flex-direction: row; }
.form label.frow { align-items: center; gap: 8px; color: var(--ink); font-size: 14px; }
.form .bar { align-items: center; gap: 8px; padding: 6px 0; }
.form .bar strong { color: var(--ink); font-size: 14px; }
.form .pick { gap: 0; }
.pickrow .famt { margin-left: auto; padding-right: 6px; }

/* action buttons stay reachable while a long list scrolls inside a dialog */
.modal-body .btn-row.sticky { position: sticky; bottom: -18px; margin: 12px -18px -18px; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); border-radius: 0 0 16px 16px; }

/* v1.4.2: iPhone Safari zooms into any text box smaller than 16px and never zooms back out.
   Inputs inherited 14px from their labels, so force 16px on every control. Pinch-zoom stays available. */
input, select, textarea, .form input, .form select, .form textarea { font-size: 16px; }

/* v1.5: logo, About card, share */
.brand .logo { width: 30px; height: 30px; border-radius: 8px; flex: none; align-self: center; margin-right: -2px; }
.about { display: flex; flex-direction: column; gap: 12px; }
.about-app { display: flex; align-items: center; gap: 14px; }
.about-app h2 { font-size: 20px; }
.about-logo { width: 56px; height: 56px; border-radius: 14px; flex: none; }
.urlline { font-size: 13px; color: var(--muted); overflow-wrap: anywhere; user-select: all; -webkit-user-select: all; padding: 8px 10px; background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; }
.sharegrid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.sharegrid .btn { min-height: 44px; }
.author { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding: 18px; border-radius: 14px; color: #fff; background: linear-gradient(135deg, #0f2041 0%, #1e3a5f 55%, #1a5c50 100%); }
.author-photo { width: 84px; height: 84px; flex: none; border-radius: 50%; object-fit: cover; border: 2px solid rgba(255,255,255,.28); background: rgba(255,255,255,.08); }
.author-body { flex: 1; min-width: 210px; }
.author .kicker { margin: 0 0 2px; font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: rgba(255,255,255,.65); }
.author-name { margin: 0; font-size: 18px; font-weight: 750; }
.author-role { margin: 2px 0 6px; font-size: 13px; color: #9fe3d9; }
.author-bio { margin: 0 0 12px; font-size: 13px; line-height: 1.6; color: rgba(255,255,255,.85); }
.author-links { display: flex; gap: 8px; flex-wrap: wrap; }
.author-links .btn { color: #fff; border: 0; text-decoration: none; font-size: 14px; }
.author-links .site { background: #2ec4b6; color: #0f2041; }
.author-links .li { background: #0a66c2; }
.author-links .mail { background: rgba(255,255,255,.16); }
.author-links .apps { background: #5a4a8f; }
.hint.fine { font-size: 12px; }
a.btn { text-decoration: none; color: var(--ink); }

/* v1.6: backup bar and dialog */
.banner.bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; text-align: left; padding: 10px 14px; margin: 0; border-bottom: 1px solid var(--line); font-weight: 600; }
.banner.bar > span:first-child { flex: 1 1 190px; }
.bar-actions { display: flex; gap: 8px; }
.banner.ok { background: var(--accent-soft); color: var(--accent); }
.stackbtns { display: flex; flex-direction: column; gap: 8px; }
.restore-start { margin-top: 8px; padding-top: 14px; border-top: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; align-items: center; }
.restore-start h3 { margin: 0; color: var(--ink); }
