:root {
  --bg: #f3f6f8;
  --card: #ffffff;
  --ink: #0f1d2a;
  --muted: #5d6b79;
  --line: #e2e8ee;
  --soft: #f6f9fb;
  --primary: #0b5f78;
  --primary-ink: #ffffff;
  --primary-soft: #e3f1f6;
  --good: #137a43;
  --good-soft: #e3f5ea;
  --warn: #a55b06;
  --warn-soft: #fdf1df;
  --bad: #b42323;
  --bad-soft: #fde8e8;
  --shadow: 0 1px 2px rgba(15, 29, 42, 0.05), 0 6px 24px rgba(15, 29, 42, 0.06);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c141b;
    --card: #131e27;
    --ink: #e7eef4;
    --muted: #93a3b1;
    --line: #22313d;
    --soft: #172530;
    --primary: #3cb4d6;
    --primary-ink: #04202a;
    --primary-soft: #133241;
    --good: #4fd08a;
    --good-soft: #10301f;
    --warn: #f2b25c;
    --warn-soft: #33250f;
    --bad: #f37b7b;
    --bad-soft: #3a1717;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 24px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 'Plus Jakarta Sans', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
h1, h2, h3 { margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 1.05rem; font-weight: 700; }
h3 { font-size: 1.1rem; font-weight: 700; margin-bottom: 14px; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
[hidden] { display: none !important; }
svg { width: 1em; height: 1em; }
.num, .big-num, .stat-val, .mrow b, .pay-amt { font-variant-numeric: tabular-nums; }

/* Top bar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--card) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-inner {
  max-width: 1180px;
  margin: 0 auto;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-mark {
  flex: none;
  width: 36px; height: 36px;
  border-radius: 10px;
  background: linear-gradient(145deg, #0e7896, #0a4d62);
  display: grid; place-items: center;
}
.brand-mark svg { width: 18px; height: 18px; fill: #fff; }
.brand-mark.big { width: 56px; height: 56px; border-radius: 16px; margin: 0 auto 14px; }
.brand-mark.big svg { width: 28px; height: 28px; }
.brand-title { font-weight: 800; font-size: 1rem; line-height: 1.2; }
.brand-sub { color: var(--muted); font-size: 0.78rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.lang { display: inline-flex; background: var(--soft); border: 1px solid var(--line); border-radius: 999px; padding: 3px; }
.lang button {
  border: 0; background: transparent; color: var(--muted);
  font: inherit; font-size: 0.78rem; font-weight: 700;
  padding: 5px 11px; border-radius: 999px; cursor: pointer;
}
.lang button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

/* Buttons */
.btn, .ghost-btn, .icon-btn, .chip-btn {
  font: inherit; cursor: pointer; border-radius: 10px; transition: background .15s, border-color .15s, opacity .15s;
}
.btn {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  padding: 10px 16px; font-weight: 600;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .6; cursor: progress; }
.ghost-btn {
  border: 1px solid var(--line); background: transparent; color: var(--ink);
  padding: 7px 12px; font-size: 0.85rem; font-weight: 600;
}
.ghost-btn:hover { background: var(--soft); }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 1px solid var(--line); background: transparent; color: var(--ink);
}
.icon-btn svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; }
.icon-btn:hover { background: var(--soft); }
.chip-btn {
  border: 1px solid var(--line); background: var(--soft); color: var(--ink);
  padding: 5px 10px; font-size: 0.78rem; font-weight: 600;
}
.chip-btn:hover { border-color: var(--primary); color: var(--primary); }
.chip-btn.danger:hover { border-color: var(--bad); color: var(--bad); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

/* Layout */
.wrap { max-width: 1180px; margin: 0 auto; padding: 18px 16px 40px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }

.parties {
  display: flex; flex-wrap: wrap; gap: 8px 18px;
  color: var(--muted); font-size: 0.84rem; margin-bottom: 14px;
}
.parties b { color: var(--ink); font-weight: 600; }

.hero { display: grid; grid-template-columns: 1.25fr 1fr; gap: 14px; }
.hero-main {
  padding: 22px 22px 20px;
  background:
    radial-gradient(120% 140% at 100% 0%, rgba(60, 180, 214, .22), transparent 60%),
    linear-gradient(150deg, #0d6d89, #093f52);
  color: #fff; border: 0;
  display: flex; flex-direction: column; justify-content: center;
}
.hero-main .eyebrow { color: rgba(255,255,255,.75); }
.hero-main .muted { color: rgba(255,255,255,.78); }
.eyebrow { font-size: 0.78rem; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.big-num { font-size: clamp(2.1rem, 6vw, 3rem); font-weight: 800; letter-spacing: -0.02em; margin: 4px 0 14px; line-height: 1.1; }
.progress { height: 8px; border-radius: 99px; background: rgba(255,255,255,.18); overflow: hidden; margin-bottom: 8px; }
.progress span { display: block; height: 100%; width: 0; background: #7fe0c0; border-radius: 99px; transition: width .6s ease; }

.hero-month { padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; }
.hero-month .top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.hero-month .due { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.01em; }
.hero-month .line { display: flex; justify-content: space-between; gap: 10px; font-size: 0.9rem; }
.hero-month .line span:first-child { color: var(--muted); }
.hero-month .line b { font-variant-numeric: tabular-nums; }
.bar { height: 6px; border-radius: 99px; background: var(--soft); overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--good); border-radius: 99px; }
.callout { border-radius: 10px; padding: 10px 12px; font-size: 0.86rem; font-weight: 600; }
.callout.good { background: var(--good-soft); color: var(--good); }
.callout.warn { background: var(--warn-soft); color: var(--warn); }
.callout.bad { background: var(--bad-soft); color: var(--bad); }

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 0.72rem; font-weight: 700; letter-spacing: .02em;
  padding: 3px 9px; border-radius: 999px; white-space: nowrap;
  background: var(--soft); color: var(--muted);
}
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.info { background: var(--primary-soft); color: var(--primary); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 14px 0; }
.stat { padding: 14px 16px; }
.stat-label { font-size: 0.78rem; color: var(--muted); font-weight: 600; }
.stat-val { font-size: 1.2rem; font-weight: 800; margin-top: 2px; }
.stat-sub { font-size: 0.75rem; color: var(--muted); }

.rules { padding: 0; margin-bottom: 18px; }
.rules summary {
  list-style: none; cursor: pointer; padding: 14px 18px;
  display: flex; align-items: center; gap: 10px; font-weight: 700;
}
.rules summary::-webkit-details-marker { display: none; }
.rules summary::after { content: '+'; margin-left: auto; color: var(--muted); font-size: 1.2rem; }
.rules[open] summary::after { content: '–'; }
.rules-icon {
  width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center;
  background: var(--primary-soft); color: var(--primary); font-size: .8rem; font-weight: 800; font-style: italic;
}
.rules ul { margin: 0; padding: 0 18px 16px 46px; color: var(--muted); }
.rules li { margin: 6px 0; }
.rules li b { color: var(--ink); }

.layout { display: grid; grid-template-columns: 360px 1fr; gap: 18px; align-items: start; }
.side { position: sticky; top: 76px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 2px 2px 10px; }
.docs-head { margin-top: 26px; }

/* Forms */
.pay-form { padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 0.82rem; font-weight: 600; color: var(--muted); min-width: 0; }
.field input, .field select {
  font: inherit; font-size: 16px; font-weight: 500; color: var(--ink);
  background: var(--soft); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; width: 100%; min-width: 0;
}
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); background: var(--card); box-shadow: 0 0 0 3px var(--primary-soft); }
.quick { display: flex; flex-wrap: wrap; gap: 6px; margin-top: -4px; }
.form-error { margin: 0; color: var(--bad); font-size: 0.85rem; font-weight: 600; }

.dropzone {
  border: 1.5px dashed var(--line); border-radius: 12px; padding: 16px;
  display: flex; align-items: center; justify-content: center; gap: 10px; text-align: center;
  color: var(--muted); font-size: 0.84rem; font-weight: 500; cursor: pointer; background: var(--soft);
  transition: border-color .15s, background .15s;
}
.dropzone svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; flex: none; }
.dropzone:hover, .dropzone.over { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }
.pending { display: flex; flex-wrap: wrap; gap: 8px; }
.pending:empty { display: none; }
.pending .thumb { width: 64px; height: 64px; }

.thumb {
  position: relative; width: 72px; height: 72px; border-radius: 10px; overflow: hidden;
  border: 1px solid var(--line); background: var(--soft); flex: none; padding: 0; cursor: zoom-in;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .x {
  position: absolute; top: 3px; right: 3px; width: 22px; height: 22px; border-radius: 50%;
  border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 14px; line-height: 1; cursor: pointer;
  display: grid; place-items: center;
}

.preview {
  border-radius: 12px; background: var(--primary-soft); padding: 12px 14px; font-size: 0.86rem;
  display: flex; flex-direction: column; gap: 4px;
}
.preview .line { display: flex; justify-content: space-between; gap: 10px; }
.preview .line b { font-variant-numeric: tabular-nums; }
.preview .total { border-top: 1px solid color-mix(in srgb, var(--primary) 25%, transparent); margin-top: 4px; padding-top: 6px; font-weight: 700; }
.preview .hint { color: var(--muted); font-size: 0.78rem; }

/* Month cards */
.month { margin-bottom: 14px; overflow: hidden; }
.month-head {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.month-title { font-weight: 800; font-size: 1.02rem; }
.month-due { font-size: 0.78rem; color: var(--muted); }
.mrow { display: grid; grid-template-columns: repeat(4, 1fr); border-bottom: 1px solid var(--line); }
.mrow > div { padding: 12px 18px; border-right: 1px solid var(--line); min-width: 0; }
.mrow > div:last-child { border-right: 0; }
.mrow small { display: block; color: var(--muted); font-size: 0.74rem; font-weight: 600; }
.mrow b { font-size: 0.98rem; font-weight: 700; }
.mrow .end b { color: var(--primary); }
.month-note { padding: 10px 18px; font-size: 0.82rem; border-bottom: 1px solid var(--line); }
.month-note:last-child { border-bottom: 0; }
.pays { list-style: none; margin: 0; padding: 0; }
.pay { padding: 14px 18px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 8px; }
.pay:last-child { border-bottom: 0; }
.pay-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.pay-amt { font-weight: 800; font-size: 1.05rem; }
.pay-meta { font-size: 0.8rem; color: var(--muted); }
.pay-split { font-size: 0.8rem; color: var(--muted); }
.pay-split b { color: var(--ink); font-weight: 600; }
.pay-note { font-size: 0.88rem; }
.pay-photos { display: flex; flex-wrap: wrap; gap: 8px; }
.pay-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }
.empty { padding: 16px 18px; color: var(--muted); font-size: 0.86rem; }

.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.doc { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.doc .thumb { width: 100%; height: 190px; }
.doc .cap { font-size: 0.8rem; font-weight: 600; padding: 0 2px; }
.doc .chip-btn { align-self: flex-start; }

.foot { text-align: center; margin-top: 34px; }

/* Login */
.login { min-height: calc(100vh - 70px); display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 380px; padding: 28px 24px; text-align: center; display: flex; flex-direction: column; gap: 12px; }
.login-card h1 { font-size: 1.4rem; }
.login-card p { margin: 0; }
.login-card .field { text-align: left; }
.login-card .remember { display: flex; align-items: center; gap: 8px; font-size: 0.85rem; color: var(--muted); cursor: pointer; user-select: none; }
.login-card .remember input { width: 18px; height: 18px; accent-color: var(--accent, #38bdf8); margin: 0; }

/* Dialogs */
.dialog {
  border: 1px solid var(--line); border-radius: 18px; padding: 22px; width: min(520px, calc(100vw - 24px));
  background: var(--card); color: var(--ink); box-shadow: 0 20px 60px rgba(0,0,0,.25);
}
.dialog form { display: flex; flex-direction: column; gap: 12px; }
.dialog h3 { margin-bottom: 2px; }
.dialog::backdrop { background: rgba(8, 18, 26, .5); backdrop-filter: blur(2px); }
.small-dialog { width: min(400px, calc(100vw - 24px)); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.lightbox { border: 0; padding: 0; background: transparent; max-width: 100vw; max-height: 100vh; width: 100vw; height: 100vh; }
.lightbox::backdrop { background: rgba(0,0,0,.88); }
.lightbox[open] { display: grid; place-items: center; }
.lightbox img { max-width: 96vw; max-height: 92vh; object-fit: contain; border-radius: 6px; }
.lb-close {
  position: fixed; top: calc(12px + env(safe-area-inset-top, 0px)); right: 14px;
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: rgba(255,255,255,.15);
  color: #fff; font-size: 26px; cursor: pointer;
}

.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px));
  transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 0.88rem; font-weight: 600; transition: all .25s; z-index: 50; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* Responsive */
@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: static; }
}
@media (max-width: 720px) {
  .hero { grid-template-columns: 1fr; }
  .brand-sub { display: none; }
}
@media (max-width: 520px) {
  .wrap { padding-top: 14px; }
  .mrow { grid-template-columns: 1fr 1fr; }
  .mrow > div:nth-child(2) { border-right: 0; }
  .mrow > div:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .mrow > div { padding: 10px 14px; }
  .month-head, .pay, .month-note, .empty { padding-left: 14px; padding-right: 14px; }
  .row2 { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats > .stat:last-child { grid-column: span 2; }
  .stat-val { font-size: 1.05rem; }
  .brand-title { font-size: 0.92rem; }
  .doc .thumb { height: 150px; }
}
