:root {
  --green: #1e7d32;
  --green-2: #2e9e44;
  --green-soft: #e6f3e8;
  --blue: #2337be;
  --blue-soft: #e8ebfb;
  --red: #c62828;
  --red-soft: #fdecec;
  --amber: #b26a00;
  --amber-soft: #fff3df;
  --bg: #f3f5f2;
  --surface: #ffffff;
  --surface-2: #f8faf7;
  --text: #1b2420;
  --muted: #66736b;
  --line: #e1e6e0;
  --shadow: 0 1px 2px rgba(20, 40, 25, .06), 0 4px 14px rgba(20, 40, 25, .06);
  --radius: 14px;
  --nav-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --green: #5cc06f; --green-2: #6fd283; --green-soft: #1b3221;
    --blue: #8f9dff; --blue-soft: #1e2347;
    --red: #ff7b7b; --red-soft: #3a1f1f;
    --amber: #ffb84d; --amber-soft: #3a2c14;
    --bg: #101512; --surface: #18201b; --surface-2: #1d2620;
    --text: #e6ece7; --muted: #9aa69e; --line: #2a352e;
    --shadow: 0 1px 2px rgba(0,0,0,.3);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 16px; line-height: 1.45;
  min-height: 100dvh;
}
a { color: var(--blue); text-decoration: none; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
h2 { font-size: 1.05rem; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.in { color: var(--green); }
.out { color: var(--red); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 10px) 16px 10px;
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.topbar img { width: 38px; height: 38px; object-fit: contain; border-radius: 8px; background: #fff; }
.topbar .t { flex: 1; min-width: 0; }
.topbar .t b { display: block; font-size: 1.02rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .t span { font-size: .75rem; color: var(--muted); }
.icon-btn {
  border: 0; background: transparent; color: var(--text); width: 40px; height: 40px;
  border-radius: 10px; display: grid; place-items: center; cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- layout ---------- */
main { padding: 14px 16px calc(var(--nav-h) + var(--safe-b) + 90px); max-width: 760px; margin: 0 auto; }
.stack > * + * { margin-top: 12px; }
.card {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 14px; border: 1px solid var(--line);
}
.card h2 { margin-bottom: 8px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.section-title { display: flex; justify-content: space-between; align-items: baseline; margin: 18px 2px 8px; }
.section-title h2 { font-size: 1rem; }

/* ---------- solde ---------- */
.balance {
  background: linear-gradient(135deg, #1e7d32, #2a9a46 60%, #2d8c7a);
  color: #fff; border: 0; padding: 18px; position: relative; overflow: hidden;
}
.balance::after {
  content: ""; position: absolute; right: -30px; top: -30px; width: 140px; height: 140px;
  border-radius: 50%; background: rgba(255,255,255,.08);
}
.balance .lbl { font-size: .85rem; opacity: .9; }
.balance .amt { font-size: 2rem; font-weight: 750; margin: 4px 0 12px; letter-spacing: -.5px; }
.balance .split { display: flex; gap: 10px; }
.balance .split div { flex: 1; background: rgba(255,255,255,.14); border-radius: 10px; padding: 8px 10px; }
.balance .split small { display: block; font-size: .72rem; opacity: .9; }
.balance .split b { font-size: .98rem; }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.quick button {
  display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 54px;
  border-radius: 12px; border: 1px solid var(--line); background: var(--surface); font-weight: 650;
  font-size: .98rem; color: var(--text); box-shadow: var(--shadow); cursor: pointer;
}
.quick button .dot { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-size: 1.2rem; }
.quick .q-in .dot { background: var(--green-soft); color: var(--green); }
.quick .q-out .dot { background: var(--red-soft); color: var(--red); }

/* ---------- lists ---------- */
.list { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--line); box-shadow: var(--shadow); overflow: hidden; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--line); cursor: pointer; color: var(--text); }
.item:last-child { border-bottom: 0; }
.item:active { background: var(--surface-2); }
.item .ic { width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex: none; font-weight: 700; }
.item .ic.in { background: var(--green-soft); }
.item .ic.out { background: var(--red-soft); }
.item .ic.ev { background: var(--blue-soft); color: var(--blue); flex-direction: column; line-height: 1; font-size: .7rem; }
.item .ic.ev b { font-size: 1.05rem; }
.item .ic.pdf { background: var(--red-soft); color: var(--red); font-size: .72rem; }
.item .body { flex: 1; min-width: 0; }
.item .body b { display: block; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .body span { font-size: .8rem; color: var(--muted); display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item .right { text-align: right; font-weight: 650; }
.item.cancelled { opacity: .55; }
.item.cancelled .right { text-decoration: line-through; }
.day-head { padding: 8px 14px; font-size: .76rem; font-weight: 650; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: var(--surface-2); border-bottom: 1px solid var(--line); }
.empty { text-align: center; padding: 30px 16px; color: var(--muted); }
.empty .big { font-size: 2.2rem; }

.badge { display: inline-block; font-size: .7rem; font-weight: 650; padding: 2px 8px; border-radius: 99px; vertical-align: middle; }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.grey { background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }

/* ---------- chips / filters ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 4px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; border: 1px solid var(--line); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 99px; font-size: .88rem; cursor: pointer; font-weight: 550;
}
.chip.on { background: var(--green); color: #fff; border-color: var(--green); }
.seg { display: flex; background: var(--surface-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; border: 0; background: transparent; padding: 9px; border-radius: 9px; font-weight: 600; color: var(--muted); font-size: .92rem; cursor: pointer; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg.type button.on.in { background: var(--green); color: #fff; }
.seg.type button.on.out { background: var(--red); color: #fff; }

/* ---------- forms ---------- */
label.f { display: block; }
label.f > span { display: block; font-size: .82rem; font-weight: 600; color: var(--muted); margin: 0 0 5px 2px; }
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--line); border-radius: 11px; padding: 12px; min-height: 48px; outline: none;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px var(--green-soft); }
.amount-input { font-size: 1.8rem; font-weight: 700; text-align: center; letter-spacing: -.3px; padding: 14px; }
.amount-wrap { position: relative; }
.amount-wrap::after { content: "Ar"; position: absolute; right: 16px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; }
.words { font-size: .8rem; color: var(--muted); text-align: center; margin-top: 6px; min-height: 1.1em; font-style: italic; }
.form > * + * { margin-top: 14px; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0;
  border-radius: 12px; padding: 13px 18px; min-height: 48px; font: inherit; font-weight: 650; cursor: pointer;
  background: var(--green); color: #fff; text-align: center;
}
.btn.block { width: 100%; }
.btn.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
.btn.danger { background: var(--red-soft); color: var(--red); }
.btn.blue { background: var(--blue); }
.btn.red { background: var(--red); }
.btn:disabled { opacity: .6; cursor: default; }
.btn svg { width: 20px; height: 20px; }
.btns { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.file-drop {
  border: 1.5px dashed var(--line); border-radius: 12px; padding: 14px; text-align: center;
  color: var(--muted); cursor: pointer; display: block; background: var(--surface-2);
}
.file-drop input { display: none; }
.thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.thumb { position: relative; width: 74px; height: 74px; border-radius: 10px; overflow: hidden; background: var(--surface-2); border: 1px solid var(--line); display: grid; place-items: center; font-size: .7rem; color: var(--muted); text-align: center; }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 2px; right: 2px; border: 0; border-radius: 50%; width: 22px; height: 22px; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; line-height: 1; }

/* ---------- detail ---------- */
.detail-amt { text-align: center; padding: 8px 0 4px; }
.detail-amt .v { font-size: 2.1rem; font-weight: 750; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 8px 12px; font-size: .94rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.alert { padding: 12px 14px; border-radius: 12px; font-size: .9rem; }
.alert.red { background: var(--red-soft); color: var(--red); }
.alert.amber { background: var(--amber-soft); color: var(--amber); }
.alert.green { background: var(--green-soft); color: var(--green); }

/* ---------- bars (rapport) ---------- */
.bars .b { margin: 10px 0; }
.bars .b .l { display: flex; justify-content: space-between; font-size: .88rem; gap: 8px; }
.bars .b .t { height: 8px; background: var(--surface-2); border-radius: 99px; margin-top: 4px; overflow: hidden; }
.bars .b .t i { display: block; height: 100%; border-radius: 99px; }
.trend { display: flex; align-items: flex-end; gap: 8px; height: 110px; padding-top: 6px; }
.trend .m { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; }
.trend .m .p { display: flex; gap: 2px; align-items: flex-end; height: 100%; }
.trend .m .p i { width: 9px; border-radius: 3px 3px 0 0; min-height: 2px; }
.trend .m small { font-size: .68rem; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: .78rem; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }

/* ---------- calendar ---------- */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-head b { text-transform: capitalize; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal .dow { font-size: .7rem; text-align: center; color: var(--muted); font-weight: 650; padding: 4px 0; }
.cal .d { aspect-ratio: 1; border-radius: 10px; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: .9rem; cursor: pointer; position: relative; border: 0; background: transparent; color: var(--text); font: inherit; }
.cal .d.other { color: var(--muted); opacity: .45; }
.cal .d.today { outline: 2px solid var(--green); }
.cal .d.sel { background: var(--green); color: #fff; }
.cal .d .dots { display: flex; gap: 2px; height: 6px; margin-top: 2px; }
.cal .d .dots i { width: 5px; height: 5px; border-radius: 50%; background: var(--blue); }
.cal .d.sel .dots i { background: #fff; }

/* ---------- bottom nav ---------- */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; display: flex;
  background: var(--surface); border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b); height: calc(var(--nav-h) + var(--safe-b));
}
.nav a { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: .7rem; font-weight: 600; }
.nav a svg { width: 24px; height: 24px; }
.nav a.on { color: var(--green); }
.nav a.on svg { stroke-width: 2.3; }
.fab {
  position: fixed; right: 18px; bottom: calc(var(--nav-h) + var(--safe-b) + 16px); z-index: 25;
  width: 58px; height: 58px; border-radius: 18px; border: 0; background: var(--green); color: #fff;
  box-shadow: 0 6px 18px rgba(30,125,50,.4); display: grid; place-items: center; cursor: pointer;
}
.fab svg { width: 28px; height: 28px; }

/* ---------- sheet / modal ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 20, 14, .45); z-index: 50; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  background: var(--surface); width: 100%; max-width: 560px; border-radius: 20px 20px 0 0;
  padding: 10px 16px calc(18px + var(--safe-b)); max-height: 92dvh; overflow-y: auto; animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 9px; background: var(--line); margin: 0 auto 12px; }
.sheet h3 { font-size: 1.1rem; margin-bottom: 12px; }
@media (min-width: 700px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 20px; }
}
@keyframes up { from { transform: translateY(40px); opacity: .4 } to { transform: none; opacity: 1 } }
@keyframes fade { from { opacity: 0 } }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--nav-h) + var(--safe-b) + 86px);
  background: #1b2420; color: #fff; padding: 11px 18px; border-radius: 12px; z-index: 80; font-size: .92rem;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.25); animation: up .2s;
}
.toast.err { background: var(--red); }
.offline-bar { background: var(--amber-soft); color: var(--amber); text-align: center; font-size: .8rem; padding: 6px; font-weight: 600; }

/* ---------- login ---------- */
.login { min-height: 100dvh; display: flex; flex-direction: column; justify-content: center; padding: 24px 20px; max-width: 420px; margin: 0 auto; }
.login .logo { background: #fff; border-radius: 18px; padding: 10px; box-shadow: var(--shadow); margin-bottom: 22px; }
.login .logo img { width: 100%; display: block; }
.login h1 { font-size: 1.25rem; text-align: center; }
.login p.motto { text-align: center; color: var(--muted); margin: 4px 0 22px; letter-spacing: 1px; font-size: .85rem; }

.menu .item .ic { background: var(--surface-2); color: var(--green); }
.menu .item .ic svg { width: 20px; height: 20px; }
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; margin: 30px auto; }
@keyframes spin { to { transform: rotate(360deg) } }

@media (min-width: 900px) {
  main { max-width: 860px; }
  .desk-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .desk-2 > * + * { margin-top: 0; }
}
@media print {
  .nav, .fab, .topbar, .no-print { display: none !important; }
}
