:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-2: #f1f3ef;
  --border: #e1e4de;
  --text: #19201b;
  --muted: #69726b;
  --faint: #9aa29c;
  --accent: #1f7a4d;
  --accent-h: #186640;
  --accent-soft: #e5f2ea;
  --pos: #1f7a4d;
  --neg: #c0392b;
  --warn: #9a6200;
  --pend-bg: #edefec; --pend: #5c645e;
  --part-bg: #fcf1d8; --part: #865600;
  --done-bg: #e1f1e7; --done: #1b6640;
  --over-bg: #fbe3e0; --over: #a3281c;
  --shadow: 0 1px 2px rgba(20, 30, 22, .04), 0 6px 20px rgba(20, 30, 22, .05);
  --radius: 14px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1311;
    --surface: #171c19;
    --surface-2: #1e2420;
    --border: #2a322d;
    --text: #e8ece9;
    --muted: #9aa49d;
    --faint: #6b746e;
    --accent: #3fae75;
    --accent-h: #52bf86;
    --accent-soft: #1b2e23;
    --pos: #5cc28d;
    --neg: #ef7b6c;
    --warn: #e0a84a;
    --pend-bg: #252b27; --pend: #a7b0aa;
    --part-bg: #352a12; --part: #e9b95a;
    --done-bg: #183324; --done: #6fd09c;
    --over-bg: #3a1d19; --over: #f19285;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1311; --surface: #171c19; --surface-2: #1e2420; --border: #2a322d;
  --text: #e8ece9; --muted: #9aa49d; --faint: #6b746e;
  --accent: #3fae75; --accent-h: #52bf86; --accent-soft: #1b2e23;
  --pos: #5cc28d; --neg: #ef7b6c; --warn: #e0a84a;
  --pend-bg: #252b27; --pend: #a7b0aa; --part-bg: #352a12; --part: #e9b95a;
  --done-bg: #183324; --done: #6fd09c; --over-bg: #3a1d19; --over: #f19285;
  --shadow: 0 1px 2px rgba(0, 0, 0, .3);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body.pf-body {
  background: var(--bg);
  color: var(--text);
  font-family: Manrope, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  font-variant-numeric: tabular-nums;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.neg { color: var(--neg) !important; }
.pos { color: var(--pos); }
.mut { color: var(--faint); }
[hidden] { display: none !important; }

/* ---------- Header ---------- */
.pf-top { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--border); }
.pf-top-in { max-width: 1160px; margin: 0 auto; padding: 10px 16px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.pf-brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 17px; letter-spacing: -.01em; }
.pf-logo { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 800; font-size: 18px; }
.pf-brand-lg { font-size: 22px; justify-content: center; }
.pf-brand-lg .pf-logo { width: 40px; height: 40px; font-size: 22px; border-radius: 11px; }
.pf-tabs { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 11px; }
.pf-tab { border: 0; background: transparent; padding: 6px 14px; border-radius: 8px; cursor: pointer; font-weight: 600; color: var(--muted); }
.pf-tab.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.pf-user { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 14px; }
.pf-uname { color: var(--muted); font-weight: 600; }
.pf-link { text-decoration: none; font-weight: 600; }
.pf-link:hover { text-decoration: underline; }

.pf-main { max-width: 1160px; margin: 0 auto; padding: 20px 16px 48px; }
.pf-loading { padding: 64px 0; text-align: center; color: var(--muted); }

/* ---------- Buttons & inputs ---------- */
.pf-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
  padding: 8px 14px; border-radius: 10px; font-weight: 700; cursor: pointer; text-decoration: none;
  white-space: nowrap; transition: background .15s;
}
.pf-btn:hover { background: var(--accent-h); }
.pf-btn:disabled { opacity: .55; cursor: default; }
.pf-btn.sm { padding: 5px 11px; font-size: 13.5px; border-radius: 8px; }
.pf-btn.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.pf-btn.ghost:hover { background: var(--surface-2); }
.pf-btn.danger { color: var(--neg); }
.pf-btn-wide { width: 100%; padding: 11px; }
.pf-icon { border: 1px solid var(--border); background: var(--surface); width: 36px; height: 36px; border-radius: 10px; cursor: pointer; font-size: 20px; line-height: 1; display: grid; place-items: center; }
.pf-icon:disabled { opacity: .35; cursor: default; }
.pf-mini { border: 0; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; padding: 4px 6px; border-radius: 6px; }
.pf-mini:hover { background: var(--surface-2); color: var(--text); }
.pf-mini.danger:hover { color: var(--neg); }

input[type=text], input[type=password], input[type=date], input[type=number], input[type=email], input:not([type]), select {
  width: 100%; min-width: 0; padding: 9px 11px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
input:focus-visible, select:focus-visible { outline: none; }

.pf-f { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.pf-f > span { font-size: 13px; font-weight: 600; color: var(--muted); }
.pf-f2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pf-check { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); margin: 4px 0 16px; }
.pf-stack { display: flex; flex-direction: column; max-width: 380px; }
.pf-stack .pf-btn { align-self: flex-start; }

/* ---------- Login ---------- */
.pf-auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.pf-auth-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 32px 28px; box-shadow: var(--shadow); }
.pf-auth-sub { text-align: center; color: var(--muted); margin: 10px 0 22px; }
.pf-auth-link { display: block; text-align: center; margin-top: 14px; font-size: 14px; }
.pf-alert { background: var(--over-bg); color: var(--over); padding: 10px 12px; border-radius: 10px; font-size: 14px; font-weight: 600; }

/* ---------- Bars ---------- */
.pf-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.pf-sel { display: flex; align-items: center; gap: 8px; }
.pf-sel select { width: auto; font-weight: 800; font-size: 17px; padding: 6px 34px 6px 12px; }
.pf-bar-act { display: flex; gap: 8px; flex-wrap: wrap; }
.pf-seg { display: flex; background: var(--surface-2); padding: 4px; border-radius: 10px; gap: 2px; flex-wrap: wrap; }
.pf-seg-b { border: 0; background: transparent; padding: 6px 12px; border-radius: 7px; font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer; }
.pf-seg-b.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

/* ---------- Summary cards ---------- */
.pf-cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 18px; }
.pf-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.pf-card.hl { background: var(--accent-soft); border-color: transparent; }
.pf-card-l { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.pf-card-v { font-size: 25px; font-weight: 800; letter-spacing: -.02em; margin: 4px 0 2px; }
.pf-card-s { font-size: 13px; color: var(--muted); }
.pf-prog { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; margin-top: 10px; }
.pf-prog span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.pf-prog.over span { background: var(--neg); }

/* ---------- Sections & item list ---------- */
.pf-sec { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 18px; overflow: hidden; }
.pf-sec-h { display: flex; align-items: center; gap: 16px; padding: 14px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.pf-sec-h h2 { margin: 0; font-size: 17px; font-weight: 800; letter-spacing: -.01em; }
.pf-sec-h h2 small { font-size: 13px; font-weight: 600; color: var(--muted); }
.pf-sec-tog { display: flex; align-items: center; gap: 8px; border: 0; background: transparent; padding: 4px 8px 4px 2px; margin: -4px 0 -4px -4px; border-radius: 8px; cursor: pointer; text-align: left; }
.pf-sec-tog:hover { background: var(--surface-2); }
.pf-sec-tog .pf-caret { transform: rotate(90deg); color: var(--accent); width: 14px; text-align: center; }
.pf-sec.shut .pf-sec-tog .pf-caret { transform: none; color: var(--faint); }
.pf-sec.shut .pf-sec-h { border-bottom: 0; }
.pf-theme { width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 16px; line-height: 1; display: grid; place-items: center; color: var(--text); }
.pf-theme:hover { background: var(--surface-2); }
.pf-sec-t { display: flex; gap: 16px; font-size: 13.5px; color: var(--muted); margin-left: auto; }
.pf-sec-t b { color: var(--text); }
.pf-sec-h .pf-btn { margin-left: 4px; }
.pf-narrow { max-width: 520px; }
.pf-narrow .pf-stack, .pf-narrow > .pf-hint { padding: 16px; }
.pf-narrow > .pf-hint { padding-top: 0; }

.pf-row {
  display: grid; grid-template-columns: 18px minmax(0, 1fr) 130px 130px 130px 100px; align-items: center; gap: 12px;
  width: 100%; padding: 12px 16px; border: 0; background: transparent; text-align: left; cursor: pointer;
}
.pf-row-head { cursor: default; padding-top: 9px; padding-bottom: 9px; font-size: 12px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .04em; background: var(--surface-2); }
.pf-item { border-top: 1px solid var(--border); }
.pf-row-head + .pf-item { border-top: 0; }
.pf-item > .pf-row:hover { background: var(--surface-2); }
.pf-item.open > .pf-row { background: var(--surface-2); }
.r { text-align: right; }
.c { text-align: center; }
.pf-caret { color: var(--faint); font-size: 18px; transition: transform .15s; display: inline-block; line-height: 1; }
.pf-item.open .pf-caret { transform: rotate(90deg); color: var(--accent); }
.pf-name { display: flex; flex-direction: column; min-width: 0; }
.pf-n { font-weight: 700; }
.pf-meta { font-size: 12.5px; color: var(--muted); }
.pf-note { font-size: 12.5px; color: var(--warn); font-style: italic; }
.pf-num { font-weight: 600; }
.pf-badge { display: inline-block; font-size: 12px; font-weight: 700; padding: 3px 9px; border-radius: 99px; }
.pf-badge.pend { background: var(--pend-bg); color: var(--pend); }
.pf-badge.part { background: var(--part-bg); color: var(--part); }
.pf-badge.done { background: var(--done-bg); color: var(--done); }
.pf-badge.over { background: var(--over-bg); color: var(--over); }
.pf-empty-row { padding: 18px 16px; color: var(--muted); font-size: 14px; }

/* ---------- Item detail (movements) ---------- */
.pf-detail { padding: 6px 16px 14px 46px; background: var(--surface-2); }
.pf-movs { list-style: none; margin: 0 0 10px; padding: 0; background: var(--surface); border: 1px solid var(--border); border-radius: 11px; overflow: hidden; }
.pf-mov { display: grid; grid-template-columns: 26px minmax(0, 1fr) 100px 120px auto; gap: 10px; align-items: center; padding: 8px 12px; font-size: 14px; }
.pf-mov + .pf-mov { border-top: 1px solid var(--border); }
.pf-mov-i { width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 800; display: grid; place-items: center; }
.pf-mov-d { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pf-mov-f { color: var(--muted); }
.pf-mov-a { text-align: right; font-weight: 700; }
.pf-mov-x { display: flex; gap: 2px; justify-content: flex-end; }
.pf-mov.editing { display: block; }
.pf-movform { display: grid; grid-template-columns: minmax(0, 1.4fr) 150px 140px auto; gap: 8px; }
.pf-movform.inline { grid-template-columns: minmax(0, 1.4fr) 150px 120px auto; }
.pf-movform input { padding: 7px 10px; }
.pf-movform-x { display: flex; gap: 6px; }
.pf-detail-f { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.pf-detail-x { display: flex; gap: 4px; margin-left: auto; }
.pf-hint { font-size: 13.5px; color: var(--muted); margin: 6px 0; }
.pf-hint.warn { color: var(--warn); font-weight: 600; padding: 0 16px 12px; margin: 0; }
.pf-hint b { color: var(--text); }

/* ---------- Grids, tables, categories ---------- */
.pf-grid2 { display: grid; grid-template-columns: 1.25fr 1fr; gap: 18px; align-items: start; }
.pf-grid2 .pf-sec { margin-bottom: 0; }
.pf-tablewrap { overflow-x: auto; }
.pf-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.pf-table th, .pf-table td { padding: 10px 12px; text-align: right; border-bottom: 1px solid var(--border); white-space: nowrap; }
.pf-table th:first-child { text-align: left; }
.pf-table thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--faint); background: var(--surface-2); }
.pf-table td small { display: block; font-size: 12px; color: var(--muted); font-weight: 500; }
.pf-table tbody tr:last-child > * { border-bottom: 0; }
.pf-saldo b { font-weight: 800; }

.pf-annual { font-size: 13.5px; }
.pf-annual th, .pf-annual td { padding: 8px 10px; }
.pf-annual thead th.mut { color: var(--border); }
.pf-sticky { position: sticky; left: 0; background: var(--surface); z-index: 1; max-width: 240px; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.pf-annual thead .pf-sticky { background: var(--surface-2); }
.pf-annual td.bud { color: var(--faint); font-style: italic; }
.pf-annual td.empty { background: repeating-linear-gradient(135deg, transparent 0 6px, var(--surface-2) 6px 7px); }
.pf-annual .pf-tot { font-weight: 800; background: var(--surface-2); }
.pf-grp th { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--accent) !important; font-weight: 800; padding-top: 16px !important; }
.pf-grp td { border-bottom-color: var(--border); }
.pf-total th, .pf-total td { font-weight: 800; background: var(--surface-2); }
.pf-total .pf-sticky { background: var(--surface-2); }
.pf-total.strong th, .pf-total.strong td { background: var(--accent-soft); }
.pf-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; background: var(--faint); vertical-align: middle; margin-right: 4px; }
.pf-sec > .pf-hint { padding: 0 16px 14px; margin: 10px 0 0; }

.pf-cats { padding: 14px 16px 16px; display: flex; flex-direction: column; gap: 14px; }
.pf-cat-h { display: flex; justify-content: space-between; gap: 10px; font-size: 14px; font-weight: 700; }
.pf-cat-h small { color: var(--muted); font-weight: 500; }
.pf-cat .pf-prog { margin-top: 6px; }

.pf-foot { font-size: 13px; color: var(--faint); margin-top: 18px; }

/* ---------- Empty state ---------- */
.pf-empty { background: var(--surface); border: 1px dashed var(--border); border-radius: 18px; padding: 48px 24px; text-align: center; max-width: 560px; margin: 32px auto; }
.pf-empty-ico { width: 56px; height: 56px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 28px; font-weight: 800; margin: 0 auto 14px; }
.pf-empty h2 { margin: 0 0 8px; font-size: 21px; }
.pf-empty p { color: var(--muted); margin: 0 0 18px; }

/* ---------- Modal & toasts ---------- */
.pf-overlay { position: fixed; inset: 0; background: rgba(10, 16, 12, .45); display: grid; place-items: center; padding: 16px; z-index: 50; animation: pf-fade .15s; }
.pf-modal { width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--surface); border-radius: 18px; box-shadow: 0 20px 60px rgba(0, 0, 0, .25); }
.pf-modal-h { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px 6px; }
.pf-modal-h h3 { margin: 0; font-size: 18px; font-weight: 800; }
.pf-modal-h .pf-icon { border: 0; }
.pf-modal-b { padding: 10px 18px; }
.pf-modal-f { display: flex; justify-content: flex-end; gap: 8px; padding: 6px 18px 18px; }
.pf-form-err { background: var(--over-bg); color: var(--over); padding: 9px 11px; border-radius: 9px; font-size: 13.5px; font-weight: 600; margin: 4px 0 0; }
.pf-toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 60; width: calc(100% - 32px); max-width: 420px; pointer-events: none; }
.pf-toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 11px; font-weight: 600; font-size: 14px; box-shadow: 0 8px 24px rgba(0, 0, 0, .2); animation: pf-up .2s; transition: opacity .3s, transform .3s; text-align: center; }
.pf-toast.err { background: var(--neg); color: #fff; }
.pf-toast.has-act { display: flex; align-items: center; justify-content: space-between; gap: 12px; text-align: left; pointer-events: auto; }
.pf-toast-btn { border: 0; background: transparent; color: var(--accent-soft); font-weight: 800; cursor: pointer; padding: 4px 6px; border-radius: 6px; text-decoration: underline; white-space: nowrap; }
.pf-toast-btn:hover { background: rgba(255, 255, 255, .12); }
.pf-badge.act { cursor: pointer; transition: box-shadow .15s, transform .1s; }
.pf-badge.act i { font-style: normal; opacity: .45; margin-left: 2px; }
.pf-badge.act:hover { box-shadow: 0 0 0 2px var(--accent); }
.pf-badge.act:hover i { opacity: 1; }
.pf-mark { color: var(--accent); }
.pf-mark:hover { color: var(--accent-h); }
.pf-toast.out { opacity: 0; transform: translateY(6px); }
@keyframes pf-fade { from { opacity: 0; } }
@keyframes pf-up { from { opacity: 0; transform: translateY(8px); } }

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .pf-cards { grid-template-columns: repeat(2, 1fr); }
  .pf-grid2 { grid-template-columns: 1fr; }
  .pf-row { grid-template-columns: 18px minmax(0, 1fr) 110px 110px 110px 92px; }
}
@media (max-width: 720px) {
  body.pf-body { font-size: 14.5px; }
  .pf-top-in { gap: 10px; }
  .pf-tabs { order: 3; width: 100%; }
  .pf-tab { flex: 1; }
  .pf-uname { display: none; }
  .pf-main { padding-top: 14px; }
  .pf-card { padding: 13px; }
  .pf-card-v { font-size: 20px; }
  .pf-sec-t { margin-left: 0; width: 100%; order: 3; }
  .pf-sec-tog { flex: 1; }
  .pf-row-head { display: none; }
  .pf-row { grid-template-columns: 16px 1fr 1fr 1fr auto; grid-template-areas: "c n n n s" ". p r d d"; row-gap: 6px; column-gap: 10px; padding: 12px 14px; }
  .pf-row > .pf-caret { grid-area: c; align-self: start; margin-top: 2px; }
  .pf-row > .pf-name { grid-area: n; }
  .pf-row > .pf-st { grid-area: s; align-self: start; }
  .pf-row > .pf-num { text-align: left; font-size: 13.5px; display: flex; flex-direction: column; }
  .pf-row > .pf-num::before { content: attr(data-l); color: var(--faint); font-weight: 500; font-size: 11.5px; }
  .pf-row > .pf-num:nth-child(3) { grid-area: p; }
  .pf-row > .pf-num:nth-child(4) { grid-area: r; }
  .pf-row > .pf-num:nth-child(5) { grid-area: d; }
  .pf-detail { padding: 6px 12px 14px; }
  .pf-mov { grid-template-columns: 22px minmax(0, 1fr) auto; grid-template-areas: "i d a" ". f x"; row-gap: 2px; }
  .pf-mov-i { grid-area: i; } .pf-mov-d { grid-area: d; } .pf-mov-a { grid-area: a; }
  .pf-mov-f { grid-area: f; font-size: 12.5px; } .pf-mov-x { grid-area: x; }
  .pf-movform, .pf-movform.inline { grid-template-columns: 1fr 1fr; }
  .pf-movform > input:first-child { grid-column: 1 / -1; }
  .pf-movform > .pf-btn, .pf-movform-x { grid-column: 1 / -1; }
  .pf-movform-x .pf-btn { flex: 1; }
  .pf-f2 { grid-template-columns: 1fr; gap: 0; }
  .pf-bar-act { width: 100%; }
  .pf-bar-act .pf-btn { flex: 1; }
  .pf-sel { width: 100%; }
  .pf-sel select { flex: 1; }
}
@media (max-width: 380px) {
  .pf-cards { grid-template-columns: 1fr; }
}
