:root {
  --blue: #067BC2;
  --sky: #84BCDA;
  --amber: #ECC30B;
  --coral: #F37748;
  --pink: #D56062;

  --bg: #F4F8FB;
  --card: #FFFFFF;
  --ink: #12263A;
  --muted: #6B7F93;
  --line: #E3ECF3;
  --shadow: 0 1px 2px rgba(18, 38, 58, .04), 0 8px 24px rgba(18, 38, 58, .06);
  --radius: 18px;
  --spring: cubic-bezier(.34, 1.56, .64, 1);
}

* { box-sizing: border-box; }
html [hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Drifting background blobs */
.blobs { position: fixed; inset: 0; z-index: -1; overflow: hidden; pointer-events: none; }
.blobs span { position: absolute; border-radius: 50%; filter: blur(70px); opacity: .28; animation: drift 22s ease-in-out infinite alternate; }
.blobs span:nth-child(1) { width: 420px; height: 420px; background: var(--sky); top: -120px; left: -80px; }
.blobs span:nth-child(2) { width: 360px; height: 360px; background: var(--amber); top: 30%; right: -120px; opacity: .18; animation-delay: -7s; }
.blobs span:nth-child(3) { width: 380px; height: 380px; background: var(--coral); bottom: -160px; left: 30%; opacity: .14; animation-delay: -14s; }
@keyframes drift { to { transform: translate(60px, 40px) scale(1.15); } }

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 24px 32px 8px; max-width: 1280px; margin: 0 auto; animation: rise .6s var(--spring) both; }
.brand { display: flex; align-items: center; gap: 14px; }
.logo { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-weight: 800; font-size: 22px; color: #fff; background: linear-gradient(135deg, var(--blue), var(--sky)); box-shadow: 0 6px 18px rgba(6, 123, 194, .35); animation: wobble 6s ease-in-out infinite; }
@keyframes wobble { 0%, 90%, 100% { transform: rotate(0); } 93% { transform: rotate(-8deg); } 96% { transform: rotate(6deg); } }
h1 { font-size: 22px; margin: 0; letter-spacing: -.02em; }
.sub { margin: 2px 0 0; color: var(--muted); font-size: 13px; }
.actions { display: flex; gap: 10px; }

.btn { border: 0; border-radius: 12px; padding: 11px 18px; font-weight: 700; font-size: 14px; transition: transform .2s var(--spring), box-shadow .2s, background .2s; }
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--blue); color: #fff; box-shadow: 0 6px 16px rgba(6, 123, 194, .3); }
.btn.primary:hover { box-shadow: 0 10px 24px rgba(6, 123, 194, .4); }
.btn.ghost { background: #fff; border: 1px solid var(--line); }
.btn.danger { background: #fdecec; color: var(--pink); }
.plus { display: inline-block; transition: transform .3s var(--spring); }
.btn:hover .plus { transform: rotate(90deg); }

main { max-width: 1280px; margin: 0 auto; padding: 16px 32px 96px; display: grid; gap: 20px; }

/* KPI cards */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.kpi { position: relative; overflow: hidden; background: var(--card); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; animation: rise .7s var(--spring) both; transition: transform .25s var(--spring); }
.kpi:hover { transform: translateY(-4px); }
.kpi:nth-child(2) { animation-delay: .07s; } .kpi:nth-child(3) { animation-delay: .14s; } .kpi:nth-child(4) { animation-delay: .21s; }
.kpi::after { content: ''; position: absolute; right: -30px; top: -30px; width: 110px; height: 110px; border-radius: 50%; opacity: .14; background: var(--accent); }
.kpi::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--accent); }
.kpi-balance { --accent: var(--blue); }
.kpi-income { --accent: var(--sky); }
.kpi-expense { --accent: var(--coral); }
.kpi-recurring { --accent: var(--amber); }
.label { font-size: 13px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.value { font-size: 32px; font-weight: 800; letter-spacing: -.03em; font-variant-numeric: tabular-nums; }
.hint { font-size: 12.5px; color: var(--muted); }

/* Cards */
.grid { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 16px; }
.card { background: var(--card); border-radius: var(--radius); padding: 20px 22px; box-shadow: var(--shadow); animation: rise .8s var(--spring) both; animation-delay: .25s; min-width: 0; }
.grid .card:nth-child(2) { animation-delay: .32s; } .grid .card:nth-child(3) { animation-delay: .39s; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
h2 { font-size: 16px; margin: 0; letter-spacing: -.01em; }
.muted { color: var(--muted); font-size: 12.5px; }
@keyframes rise { from { opacity: 0; transform: translateY(18px) scale(.98); } to { opacity: 1; transform: none; } }

/* Line chart */
.chart-wrap { position: relative; height: 240px; }
#lineChart { width: 100%; height: 100%; overflow: visible; }
.line-path { fill: none; stroke: var(--blue); stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.area-path { fill: url(#areaGrad); }
.zero-line { stroke: var(--line); stroke-dasharray: 4 4; }
.grid-label { fill: var(--muted); font-size: 11px; }
.dot { fill: #fff; stroke-width: 2.5; transition: r .15s; }
.hover-line { stroke: var(--sky); stroke-width: 1.5; }
.tooltip { position: absolute; pointer-events: none; background: var(--ink); color: #fff; padding: 8px 12px; border-radius: 10px; font-size: 12.5px; opacity: 0; transform: translate(-50%, -110%); transition: opacity .15s; white-space: nowrap; }
.tooltip b { display: block; font-size: 14px; }

/* Donut */
.donut-wrap { position: relative; width: 170px; height: 170px; margin: 4px auto 12px; }
#donut { width: 100%; height: 100%; transform: rotate(-90deg); }
#donut circle { fill: none; stroke-width: 16; transition: stroke-dasharray .9s var(--spring), stroke-dashoffset .9s var(--spring), stroke-width .2s; }
#donut circle:hover { stroke-width: 20; }
.donut-center { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.donut-center b { font-size: 22px; }
.donut-center span { font-size: 12px; color: var(--muted); }
.legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; font-size: 13px; }
.legend li { display: flex; align-items: center; gap: 8px; animation: rise .4s both; }
.legend i { width: 10px; height: 10px; border-radius: 3px; }
.legend span { margin-left: auto; font-weight: 700; font-variant-numeric: tabular-nums; }

.seg { display: inline-flex; background: var(--bg); border-radius: 10px; padding: 3px; gap: 2px; }
.seg button { border: 0; background: transparent; padding: 6px 12px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--muted); transition: background .2s, color .2s; }
.seg button.on { background: #fff; color: var(--blue); box-shadow: 0 1px 4px rgba(18, 38, 58, .1); }

/* Top customers bars */
.bars { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.bars li { display: grid; gap: 5px; font-size: 13.5px; }
.bars .top { display: flex; justify-content: space-between; }
.bars .top b { font-variant-numeric: tabular-nums; }
.bars .track { height: 9px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bars .fill { height: 100%; border-radius: 99px; width: 0; transition: width 1s var(--spring); }

/* Table */
.table-head { flex-wrap: wrap; }
.count { font-size: 12px; font-weight: 700; color: var(--blue); background: rgba(6, 123, 194, .1); padding: 3px 9px; border-radius: 99px; margin-left: 6px; vertical-align: middle; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.filters input, .filters select { border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 8px 12px; font-size: 13.5px; outline: none; transition: border-color .2s, box-shadow .2s; }
.filters input { width: 240px; }
.filters input:focus, .filters select:focus { border-color: var(--sky); box-shadow: 0 0 0 4px rgba(132, 188, 218, .25); }
.table-scroll { overflow-x: hidden; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
th[data-sort] { cursor: pointer; user-select: none; }
th[data-sort]:hover { color: var(--blue); }
th.sorted::after { content: ' ↓'; } th.sorted.asc::after { content: ' ↑'; }
td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr { cursor: pointer; transition: background .15s, transform .15s; animation: rowIn .45s var(--spring) both; }
tbody tr:hover { background: #F7FAFD; }
tbody tr.flash { animation: flash 1.6s ease; }
@keyframes rowIn { from { opacity: 0; transform: translateX(-10px); } to { opacity: 1; transform: none; } }
@keyframes flash { 0%, 30% { background: rgba(236, 195, 11, .25); } 100% { background: transparent; } }
td.id { color: var(--muted); font-variant-numeric: tabular-nums; width: 48px; }
td.date { color: var(--muted); white-space: nowrap; }
td.who { font-weight: 700; white-space: nowrap; }
td.what { color: #3d5468; max-width: 460px; overflow-wrap: anywhere; }
td.num { text-align: right; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
th.num { text-align: right; }
.pos { color: var(--blue); }
.neg { color: var(--pink); }
.empty { text-align: center; color: var(--muted); padding: 40px; }

td.date.undated { color: var(--pink); font-weight: 700; }
td.date.undated::after { content: ' ?'; font-size: 11px; }
.nodate-banner { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: -4px 0 12px; padding: 10px 14px; border-radius: 12px; background: rgba(213, 96, 98, .1); color: #a33c3e; font-size: 13.5px; font-weight: 600; animation: rise .4s var(--spring) both; }
.nodate-banner .mini { background: var(--pink); color: #fff; }
#dateField.missing span { color: var(--pink); }
#dateField.missing input { border-color: var(--pink); box-shadow: 0 0 0 4px rgba(213, 96, 98, .15); }

/* Floating action button (shows on scroll / mobile) */
.fab { position: fixed; right: 28px; bottom: 28px; width: 60px; height: 60px; border-radius: 50%; border: 0; display: grid; place-items: center; padding: 0; cursor: pointer; color: #fff; background: var(--blue); box-shadow: 0 10px 28px rgba(6, 123, 194, .45); transform: scale(0); transition: transform .35s var(--spring); z-index: 20; }
.fab.show { transform: scale(1); }
.fab:hover { transform: scale(1.1) rotate(90deg); }

/* Modal */
.overlay { position: fixed; inset: 0; background: rgba(18, 38, 58, .35); backdrop-filter: blur(6px); display: grid; place-items: center; z-index: 50; padding: 16px; animation: fade .25s both; }
.overlay.closing { animation: fade .2s reverse both; }
.overlay.closing .modal { animation: pop .2s reverse both; }
@keyframes fade { from { opacity: 0; } }
.modal { width: 100%; max-width: 480px; max-height: calc(100vh - 32px); overflow-y: auto; background: #fff; border-radius: 22px; padding: 24px; box-shadow: 0 30px 80px rgba(18, 38, 58, .3); display: grid; gap: 16px; animation: pop .45s var(--spring) both; }
@keyframes pop { from { opacity: 0; transform: translateY(30px) scale(.92); } }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { font-size: 20px; }
.x { border: 0; background: var(--bg); width: 34px; height: 34px; border-radius: 10px; font-size: 22px; line-height: 1; transition: transform .25s var(--spring); }
.x:hover { transform: rotate(90deg); }
.modal label { display: grid; gap: 6px; font-size: 13px; font-weight: 600; color: var(--muted); }
.modal input, .modal textarea { border: 1.5px solid var(--line); border-radius: 12px; padding: 11px 13px; font-size: 15px; color: var(--ink); outline: none; transition: border-color .2s, box-shadow .2s; resize: vertical; }
.modal input:focus, .modal textarea:focus { border-color: var(--sky); box-shadow: 0 0 0 4px rgba(132, 188, 218, .25); }
.row2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 12px; }

.type-toggle { position: relative; display: grid; grid-template-columns: 1fr 1fr; background: var(--bg); border-radius: 14px; padding: 4px; }
.type-toggle button { position: relative; z-index: 1; border: 0; background: none; padding: 10px; font-weight: 700; color: var(--muted); transition: color .25s; }
.type-toggle button.on { color: #fff; }
.type-toggle .slider { position: absolute; top: 4px; bottom: 4px; left: 4px; width: calc(50% - 4px); border-radius: 11px; background: var(--blue); transition: transform .4s var(--spring), background .3s; }
.type-toggle.out .slider { transform: translateX(100%); background: var(--pink); }

.amount-field { display: flex !important; grid-template-columns: none; align-items: center; gap: 6px; border-bottom: 2px solid var(--line); padding-bottom: 4px; transition: border-color .2s; }
.amount-field:focus-within { border-color: var(--blue); }
.amount-field span { font-size: 34px; font-weight: 800; color: var(--muted); }
.amount-field input { border: 0 !important; box-shadow: none !important; font-size: 40px !important; font-weight: 800; padding: 0 !important; width: 100%; letter-spacing: -.03em; }
.modal.out .amount-field:focus-within { border-color: var(--pink); }


.check { display: flex !important; align-items: center; gap: 10px; cursor: pointer; color: var(--ink) !important; }
.check input { width: 18px; height: 18px; accent-color: var(--amber); }
.error { color: var(--pink); margin: 0; font-size: 13px; min-height: 0; }
.error:empty { display: none; }
.modal-foot { display: flex; gap: 10px; align-items: center; }
.spacer { flex: 1; }
.shake { animation: shake .4s; }
@keyframes shake { 20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); } }

/* Sign-in */
body.loading #app, body.loading .signin { visibility: hidden; }
.signin { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.signin-card { width: 100%; max-width: 400px; background: var(--card); border-radius: 26px; padding: 40px 32px; box-shadow: var(--shadow); text-align: center; display: grid; justify-items: center; gap: 12px; animation: pop .6s var(--spring) both; }
.signin-card h1 { font-size: 26px; }
.signin-card .sub { font-size: 14.5px; line-height: 1.5; margin: 0 0 12px; }
.logo.big { width: 72px; height: 72px; font-size: 34px; border-radius: 22px; margin-bottom: 6px; }
.btn.google { display: inline-flex; align-items: center; gap: 10px; background: #fff; border: 1.5px solid var(--line); padding: 13px 22px; font-size: 15px; box-shadow: 0 4px 14px rgba(18, 38, 58, .08); }
.btn.google:hover { border-color: var(--sky); }

/* Account menu */
.user { position: relative; }
.avatar { width: 42px; height: 42px; border-radius: 50%; border: 2px solid #fff; background: var(--sky) center / cover; color: #fff; font-weight: 800; box-shadow: 0 2px 8px rgba(18, 38, 58, .15); transition: transform .2s var(--spring); }
.avatar:hover { transform: scale(1.08); }
.menu { position: absolute; right: 0; top: 50px; background: #fff; border-radius: 14px; box-shadow: 0 16px 40px rgba(18, 38, 58, .18); padding: 8px; min-width: 220px; z-index: 30; animation: pop .3s var(--spring) both; }
.menu-who { font-size: 12.5px; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); margin-bottom: 4px; word-break: break-all; }
.menu button { width: 100%; text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 9px; font-weight: 600; }
.menu button:hover { background: var(--bg); color: var(--pink); }

/* Recurring card */
.mini { border: 0; background: rgba(6, 123, 194, .1); color: var(--blue); font-weight: 700; font-size: 12.5px; padding: 6px 11px; border-radius: 9px; transition: transform .2s var(--spring), background .2s; }
.mini:hover { transform: translateY(-1px); background: rgba(6, 123, 194, .16); }
.rules { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.rules li.rule { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; background: var(--bg); cursor: pointer; animation: rise .4s var(--spring) both; transition: transform .2s var(--spring), background .2s; }
.rules li.rule:hover { transform: translateX(3px); background: #EAF2F8; }
.rules li.paused { opacity: .5; }
.rule-icon { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 16px; color: #fff; }
.rule-main b { display: block; font-size: 14px; }
.rule-main span { font-size: 12px; color: var(--muted); }
.rule-amt { font-weight: 800; font-variant-numeric: tabular-nums; font-size: 14px; }
.rules .muted { padding: 8px 2px; line-height: 1.5; }
.pill-rec { display: inline-block; margin-left: 6px; font-size: 11px; font-weight: 700; color: #8a6d00; background: rgba(236, 195, 11, .22); padding: 2px 8px; border-radius: 99px; vertical-align: middle; }

/* Repeat picker in modal */
.repeat { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.repeat-label { font-size: 13px; font-weight: 600; color: var(--muted); }
.repeat-note { margin: -8px 0 0; }
.repeat-note:empty { display: none; }
.empty .btn { margin-top: 12px; }

/* Toasts */
.toasts { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); display: grid; gap: 8px; z-index: 60; }
.toast { background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 14px; font-weight: 600; box-shadow: 0 12px 30px rgba(18, 38, 58, .3); display: flex; gap: 12px; align-items: center; animation: toastIn .45s var(--spring) both; }
.toast.out { animation: toastOut .3s both; }
.toast button { background: none; border: 0; color: var(--amber); font-weight: 800; }
@keyframes toastIn { from { opacity: 0; transform: translateY(20px) scale(.9); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(10px) scale(.95); } }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 70; }

@media (max-width: 1050px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: 1fr 1fr; }
  .chart-card { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .topbar { padding: 18px 16px 4px; }
  .actions .ghost, .actions .primary { display: none; }
  main { padding: 12px 16px 96px; }
  .kpis, .grid { grid-template-columns: 1fr; }
  .value { font-size: 26px; }
  .filters input { width: 100%; }
  td.what { min-width: 0; }
  .row2 { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
