:root{
  --bg:#f4f6fb;
  --card:#ffffff;
  --muted:#6b7280;
  --text:#0f172a;
  --line:#e5eaf3;

  --primary:#5b6cff;
  --primary-soft: rgba(91,108,255,.10);

  --danger:#ef4444;
  --danger-soft: rgba(239,68,68,.10);

  --income:#10b981;
  --income-soft: rgba(16,185,129,.12);

  --outgoing:#f59e0b;
  --outgoing-soft: rgba(245,158,11,.12);

  --radius:18px;
  --shadow: 0 18px 40px rgba(15,23,42,.08);
  --shadow-soft: 0 8px 18px rgba(15,23,42,.05);
}

*{box-sizing:border-box}
html,body{height:100%}

body{
  margin:0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Arial, sans-serif;
  background:
    radial-gradient(900px 500px at 10% 0%, #ffffff 0%, var(--bg) 60%),
    radial-gradient(900px 500px at 90% 0%, #eef1ff 0%, var(--bg) 60%);
  color:var(--text);
  -webkit-font-smoothing: antialiased;
}

.container{
  max-width:1200px;
  margin:30px auto;
  padding:0 18px;
}

a {
  text-decoration: none;
}

/* ---------- Topbar ---------- */

.topbar{
  position:sticky;
  top:0;
  z-index:10;
  backdrop-filter: blur(12px);
  background: rgba(255,255,255,.75);
  border-bottom:1px solid var(--line);
}

.topbar-inner{
  max-width:1200px;
  margin:0 auto;
  padding:16px 18px;
  display:flex;
  justify-content:space-between;
  align-items:center;
}

.brand{
  font-weight:800;
  font-size:1.2rem;
  letter-spacing:.4px;
  color:var(--primary);
}

/* ---------- Cards ---------- */

.card{
  background:var(--card);
  border-radius:var(--radius);
  padding:22px;
  box-shadow:var(--shadow);
  border:1px solid var(--line);
  transition:.2s ease;
}

.card + .card{margin-top:22px}

.card:hover{
  box-shadow: 0 22px 50px rgba(15,23,42,.10);
}

h1,h2{
  margin:0 0 14px 0;
  font-weight:700;
}

h2{
  font-size:1.2rem;
}

.muted{
  color:var(--muted);
  font-size:.92rem;
}

/* ---------- Grid ---------- */

.grid{
  display:grid;
  grid-template-columns: 1fr 1fr;
  gap:22px;
  margin-bottom:22px;
}

@media (max-width: 900px){
  .grid{grid-template-columns:1fr}
}

/* spacing so summary hero doesn't touch the cycle bar */
.grid-top{
  margin-top: 18px;
}

.pie-wrap.compact{
  display:flex;
  align-items:center;
  justify-content:center;
}

.pie-canvas-wrap{
  position:relative;
  display:inline-block;
}

.pie-tooltip{
  position:absolute;
  z-index:5;
  min-width:140px;
  max-width:220px;
  padding:10px 12px;
  border-radius:14px;
  background:rgba(15,23,42,.94);
  color:#fff;
  box-shadow:0 18px 40px rgba(0,0,0,.22);
  pointer-events:none;
  transform:translate(0, 0);
}

.pie-tooltip-name{
  font-weight:800;
  font-size:.92rem;
  line-height:1.2;
}

.pie-tooltip-value{
  margin-top:4px;
  font-weight:700;
  font-size:.88rem;
  color:rgba(255,255,255,.84);
}

@media (max-width: 900px){
  #outgoingPie{
    width:100% !important;
    max-width:360px;
    height:240px !important;
  }

  .pie-canvas-wrap{
    width:100%;
    display:flex;
    justify-content:center;
  }
}

/* ---------- Buttons ---------- */

.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:10px 16px;
  border-radius:12px;
  font-weight:600;
  border:1px solid var(--line);
  background:#fff;
  cursor:pointer;
  transition:.15s ease;
  box-shadow:var(--shadow-soft);
}

.btn:hover{
  transform:translateY(-1px);
  box-shadow:0 12px 24px rgba(15,23,42,.08);
}

.btn.primary{
  background:var(--primary);
  color:#fff;
  border:none;
}

.btn.danger{
  background:var(--danger);
  color:#fff;
  border:none;
}

/* ---------- Forms ---------- */

.form{
  display:flex;
  flex-direction:column;
  gap:14px;
}

.row{
  display:flex;
  gap:14px;
  flex-wrap:wrap;
}

label{
  display:flex;
  flex-direction:column;
  gap:6px;
  font-size:.9rem;
}

input,select,textarea{
  border-radius:12px;
  border:1px solid var(--line);
  padding:10px 12px;
  font-size:.95rem;
  transition:.15s ease;
}

input:focus,select:focus,textarea:focus{
  outline:none;
  border-color:var(--primary);
  box-shadow:0 0 0 4px rgba(91,108,255,.15);
}

/* ---------- Summary ---------- */

.kvs{display:flex; flex-direction:column; gap:14px; margin-top:10px}
.kv{display:flex; justify-content:space-between}
.kv.big .v{
  font-size:1.4rem;
  font-weight:800;
  color:var(--primary);
}

/* ---------- Tables ---------- */

.table-wrap{
  overflow:auto;
  border-radius:var(--radius);
  border:1px solid var(--line);
}

.table{
  width:100%;
  border-collapse:collapse;
  min-width:850px;
}

.table th{
  text-align:left;
  font-size:.8rem;
  text-transform:uppercase;
  letter-spacing:.05em;
  padding:14px;
  background:#f9fafc;
  color:#6b7280;
}

.table td{
  padding:14px;
  border-bottom:1px solid var(--line);
}

.table tbody tr:hover{
  background:#f8f9ff;
}

.row-paid{
  opacity:.5;
}

/* ---------- Tags ---------- */

.tag{
  padding:6px 12px;
  border-radius:999px;
  font-size:.8rem;
  font-weight:600;
}

.tag.income{
  background:var(--income-soft);
  color:var(--income);
}

.tag.outgoing{
  background:var(--outgoing-soft);
  color:#b45309;
}

/* ---------- Category Pill ---------- */

.cat-pill{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding:6px 14px;
  border-radius:999px;
  font-size:.82rem;
  font-weight:600;
  background:rgba(148,163,184,.15);
  border:1px solid rgba(148,163,184,.25);
  transition:.15s ease;
}

.cat-pill[data-cat]{
  background:rgba(0,0,0,.04);
}

.color-dot{
  width:10px;
  height:10px;
  border-radius:50%;
}

/* ---------- Switch ---------- */

.switch{
  position:relative;
  display:inline-block;
  width:46px;
  height:26px;
}

.switch input{display:none}

.slider{
  position:absolute;
  inset:0;
  border-radius:999px;
  background:#e5eaf3;
  transition:.2s ease;
}

.slider:before{
  content:"";
  position:absolute;
  height:20px;
  width:20px;
  left:3px;
  top:3px;
  border-radius:50%;
  background:#fff;
  transition:.2s ease;
  box-shadow:0 4px 12px rgba(0,0,0,.15);
}

.switch input:checked + .slider{
  background:var(--income);
}

.switch input:checked + .slider:before{
  transform:translateX(20px);
}

/* ---- Modal ---- */
.modal{
  position:fixed;
  inset:0;
  display:none;
  z-index:50;
}
.modal.open{display:block}

.modal-backdrop{
  position:absolute;
  inset:0;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(6px);
}

.modal-panel{
  position:relative;
  width:min(640px, calc(100vw - 24px));
  margin: 56px auto;
  background: var(--card);
  border:1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(15,23,42,.22);
  padding: 16px;
}

.modal-head{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  padding: 6px 6px 12px 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 14px;
}

.modal-title{
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: .2px;
}

.icon-btn{
  width:40px;
  height:40px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #fff;
  cursor:pointer;
  font-weight:900;
  box-shadow: 0 6px 14px rgba(15,23,42,.06);
}
.icon-btn:hover{transform: translateY(-1px)}

.modal-actions{
  display:flex;
  justify-content:flex-end;
  gap:10px;
  margin-top: 6px;
}

/* Prevent background scroll when modal open */
body.modal-open{overflow:hidden}

/* --- Native app feel --- */
:root{
  --safe-top: env(safe-area-inset-top);
  --safe-bottom: env(safe-area-inset-bottom);
}

/* reduce tap highlight + improve touch */
*{ -webkit-tap-highlight-color: transparent; }
button, .btn, a { touch-action: manipulation; }

/* App shell spacing */
.container{
  padding-bottom: calc(84px + var(--safe-bottom)); /* space for bottom nav on mobile */
}

/* Sticky header polish */
.topbar{
  padding-top: var(--safe-top);
}

/* Mobile bottom nav */
.bottom-nav{
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 10px 12px calc(10px + var(--safe-bottom));
  background: rgba(255,255,255,.78);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--line);
  display: none;
  z-index: 20;
}

.bottom-nav-inner{
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-around;
  gap: 10px;
}

.nav-item{
  flex: 1;
  display:flex;
  flex-direction:column;
  align-items:center;
  justify-content:center;
  gap: 6px;
  padding: 10px 8px;
  border-radius: 14px;
  font-weight: 700;
  font-size: .82rem;
  color: var(--muted);
}

.nav-item.active{
  background: var(--primary-soft);
  color: #1f3bd6;
}

.nav-icon{
  width: 22px;
  height: 22px;
  display:block;
}

/* Show bottom nav on mobile */
@media (max-width: 900px){
  .bottom-nav{ display:block; }
  .topbar-actions{ display:none; } /* optional: hide top links on mobile */
}

/* --- Modal as bottom sheet on mobile --- */
@media (max-width: 900px){
  .modal-panel{
    width: 100%;
    max-width: 100%;
    margin: 0;
    position: absolute;
    left: 0; right: 0;
    bottom: 0;
    border-radius: 18px 18px 0 0;
    padding-bottom: calc(16px + var(--safe-bottom));
    transform: translateY(18px);
  }

  .modal.open .modal-panel{
    animation: sheetUp .18s ease-out forwards;
  }

  @keyframes sheetUp{
    from { transform: translateY(40px); opacity: .96; }
    to   { transform: translateY(0); opacity: 1; }
  }
}

/* --- Toasts --- */
.toast-wrap{
  position: fixed;
  left: 0; right: 0;
  bottom: calc(92px + var(--safe-bottom));
  display:flex;
  justify-content:center;
  pointer-events:none;
  z-index: 60;
}

.toast{
  pointer-events:auto;
  background: rgba(15,23,42,.92);
  color: #fff;
  padding: 10px 14px;
  border-radius: 999px;
  box-shadow: 0 18px 40px rgba(0,0,0,.22);
  font-weight: 700;
  font-size: .92rem;
  opacity: 0;
  transform: translateY(8px);
  transition: .18s ease;
}

.toast.show{
  opacity: 1;
  transform: translateY(0);
}

/* Make controls feel more “native” sized on mobile */
@media (max-width: 900px){
  input, select, textarea{ padding: 12px 14px; }
  .btn{ padding: 12px 16px; }
}

.drag-handle{
  width:36px;
  height:36px;
  border-radius:12px;
  border:1px solid var(--line);
  background:#fff;
  cursor:grab;
  font-size:18px;
  line-height:1;
  box-shadow: 0 6px 14px rgba(15,23,42,.06);
  touch-action:none; /* key for mobile drag */
}
.drag-handle:active{ cursor:grabbing; }

.draggable-row.dragging{
  opacity:.55;
}
.draggable-row.placeholder td{
  border-bottom: 2px dashed rgba(91,108,255,.4);
}

/* ===== Summary hero (gradient card) ===== */
.summary-hero{
  border: none;
  color: #fff;
  background: radial-gradient(700px 320px at 10% 15%, rgba(255,255,255,.22), transparent 60%),
              radial-gradient(520px 280px at 90% 0%, rgba(255,255,255,.16), transparent 55%),
              linear-gradient(135deg, #6a5bff 0%, #4f86ff 55%, #3bd3ff 130%);
  box-shadow: 0 24px 60px rgba(91,108,255,.22);
}

.summary-hero .muted{ color: rgba(255,255,255,.78); }
.summary-hero .btn{ box-shadow:none; }

.summary-hero-top{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:14px;
}

.summary-eyebrow{
  font-weight:700;
  letter-spacing:.2px;
  opacity:.9;
  font-size:.95rem;
}

.summary-big{
  font-size: 2.1rem;
  font-weight: 900;
  letter-spacing: -.02em;
  margin-top: 6px;
}

.summary-sub{
  margin-top: 6px;
  color: rgba(255,255,255,.84);
  font-size: .95rem;
}

.summary-actions .btn.ghost{
  background: rgba(255,255,255,.16);
  color:#fff;
  border: 1px solid rgba(255,255,255,.22);
}
.summary-actions .btn.ghost:hover{
  background: rgba(255,255,255,.22);
}

.summary-metrics{
  display:grid;
  grid-template-columns: repeat(3, 1fr);
  gap:12px;
  margin-top: 16px;
}

.metric{
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.18);
  border-radius: 14px;
  padding: 12px 14px;
}

.metric-k{
  font-size: .82rem;
  color: rgba(255,255,255,.78);
  font-weight: 700;
  letter-spacing:.2px;
}

.metric-v{
  margin-top: 6px;
  font-size: 1.1rem;
  font-weight: 900;
  color:#fff;
}

.summary-foot{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  margin-top: 14px;
}

.summary-foot .chip{
  display:inline-flex;
  align-items:center;
  gap:8px;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(255,255,255,.14);
  border: 1px solid rgba(255,255,255,.18);
  font-weight: 800;
  font-size: .9rem;
}

@media (max-width: 900px){
  .summary-metrics{ grid-template-columns: 1fr; }
  .summary-big{ font-size: 1.9rem; }
}

/* Hide paid rows by default; show when user toggles "Show paid" */
.row-paid{ display:none; }
body.show-paid .row-paid{ display:table-row; }

/* Optional: tidy alignment for the toggle line */
.toggle-line{
  display:inline-flex;
  align-items:center;
  gap:10px;
  user-select:none;
}

/* Hide paid rows by default; show when toggled */
.row-paid{ display:none; }
body.show-paid .row-paid{ display:block; }
body.show-paid tr.row-paid{ display:table-row; } /* keep table row behaviour */

/* Toggle alignment */
.toggle-line{
  display:inline-flex;
  align-items:center;
  gap:10px;
  user-select:none;
}

/* Desktop vs Mobile */
.desktop-table{ display:block; }
.mobile-list{ display:none; }

@media (max-width: 900px){
  .desktop-table{ display:none; }
  .mobile-list{ display:block; }
}

/* Payment cards */
.pay-card{
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 16px;
  box-shadow: var(--shadow-soft);
  padding: 12px 12px;
  margin-bottom: 12px;
}

.pay-card-top{
  display:flex;
  justify-content:space-between;
  gap:12px;
  align-items:flex-start;
}

.pay-left{ min-width: 0; flex:1; }

.pay-title{
  font-weight: 900;
  font-size: 1rem;
  line-height: 1.2;
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pay-sub{
  margin-top: 4px;
  overflow:hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pay-right{
  display:flex;
  flex-direction:column;
  align-items:flex-end;
  gap:8px;
}

.pay-amount{
  font-weight: 900;
  font-size: 1.05rem;
}

.pay-card-bottom{
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

/* Slightly dim paid cards when showing paid */
body.show-paid .pay-card.row-paid{
  opacity:.6;
}