/* =====================================================================
   Paisa — design system
   Mobile-first. Dark by default, light via [data-theme="light"].
   ===================================================================== */

:root {
  --bg:          #0a0f1c;
  --bg-grad:     radial-gradient(1200px 600px at 15% -10%, #1e1b4b 0%, transparent 55%),
                 radial-gradient(900px 500px at 110% 0%, #0c4a6e 0%, transparent 50%);
  --surface:     #111827;
  --surface-2:   #1a2234;
  --surface-3:   #232d42;
  --border:      #26314a;
  --border-soft: #1c2437;
  --text:        #e8edf7;
  --text-dim:    #a4b1c9;
  --muted:       #6f7f9b;

  --primary:     #6366f1;
  --primary-dim: #4f46e5;
  --primary-soft:rgba(99,102,241,.14);
  --success:     #22c55e;
  --success-soft:rgba(34,197,94,.14);
  --danger:      #f43f5e;
  --danger-soft: rgba(244,63,94,.14);
  --warn:        #f59e0b;
  --warn-soft:   rgba(245,158,11,.14);
  --info:        #38bdf8;
  --info-soft:   rgba(56,189,248,.14);
  --violet:      #a855f7;

  --radius:   14px;
  --radius-sm:10px;
  --radius-lg:20px;
  --shadow:   0 4px 24px rgba(0,0,0,.35);
  --shadow-lg:0 18px 50px rgba(0,0,0,.5);
  --sidebar:  248px;
  --ff: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --fm: ui-monospace, "SF Mono", "JetBrains Mono", Menlo, monospace;
}

[data-theme="light"] {
  --bg:          #f4f6fb;
  --bg-grad:     radial-gradient(1100px 550px at 10% -15%, #e0e7ff 0%, transparent 55%),
                 radial-gradient(800px 450px at 105% -5%, #cffafe 0%, transparent 50%);
  --surface:     #ffffff;
  --surface-2:   #f7f9fc;
  --surface-3:   #eef2f8;
  --border:      #dfe5ef;
  --border-soft: #e9edf4;
  --text:        #0f172a;
  --text-dim:    #47536b;
  --muted:       #7c889e;
  --shadow:      0 2px 14px rgba(15,23,42,.07);
  --shadow-lg:   0 18px 44px rgba(15,23,42,.14);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--ff);
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

h1,h2,h3,h4 { line-height: 1.25; font-weight: 650; letter-spacing: -.01em; }
a { color: var(--primary); text-decoration: none; }
code { font-family: var(--fm); font-size: .88em; background: var(--surface-2); padding: .1em .4em; border-radius: 5px; }
.muted  { color: var(--muted); }
.dim    { color: var(--text-dim); }
.small  { font-size: .82rem; }
.tiny   { font-size: .74rem; }
.mono   { font-family: var(--fm); font-variant-numeric: tabular-nums; }
.nowrap { white-space: nowrap; }
.center { text-align: center; }
.right  { text-align: right; }
.hidden { display: none !important; }
.pos { color: var(--success); }
.neg { color: var(--danger); }

/* icons -------------------------------------------------------------- */
.icon { width: 18px; height: 18px; stroke-width: 2; flex: none; }
.icon-sm { width: 15px; height: 15px; }
.icon-lg { width: 22px; height: 22px; }
[data-lucide] { display: inline-block; vertical-align: -.18em; }

.ibox {
  width: 40px; height: 40px; border-radius: 12px;
  display: grid; place-items: center; flex: none;
  background: var(--primary-soft); color: var(--primary);
}
.ibox-sm { width: 32px; height: 32px; border-radius: 10px; }
.ibox-lg { width: 48px; height: 48px; border-radius: 14px; }

/* =====================================================================
   Shell
   ===================================================================== */
#app { min-height: 100vh; }

.layout { display: flex; min-height: 100vh; }

.sidebar {
  display: none;
  width: var(--sidebar); flex: none;
  padding: 20px 14px;
  border-right: 1px solid var(--border-soft);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
  backdrop-filter: blur(12px);
  position: sticky; top: 0; height: 100vh;
  flex-direction: column; gap: 4px;
}

.brand-mark { display: flex; align-items: center; gap: 11px; padding: 4px 8px 18px; }
.brand-logo {
  width: 38px; height: 38px; border-radius: 12px; flex: none;
  display: grid; place-items: center; font-weight: 800; font-size: 19px; color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  box-shadow: 0 6px 18px rgba(99,102,241,.4);
}
.brand-name { font-weight: 700; font-size: 1.05rem; letter-spacing: -.02em; }

.nav-group-label {
  font-size: .68rem; text-transform: uppercase; letter-spacing: .09em;
  color: var(--muted); padding: 14px 10px 6px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 11px; border-radius: var(--radius-sm);
  color: var(--text-dim); font-weight: 500; font-size: .92rem;
  cursor: pointer; border: 0; background: none; width: 100%; text-align: left;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav-item .badge-dot { margin-left: auto; }

.sidebar-foot { margin-top: auto; padding-top: 12px; border-top: 1px solid var(--border-soft); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.appbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-soft);
}
.appbar h1 { font-size: 1.12rem; margin: 0; }
.appbar .spacer { flex: 1; }

.content { padding: 16px; padding-bottom: 96px; max-width: 1180px; width: 100%; margin: 0 auto; }

/* bottom nav (mobile) ------------------------------------------------- */
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: grid; grid-template-columns: repeat(5, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
}
.bottomnav button {
  border: 0; background: none; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 2px; font-size: .66rem; font-weight: 600; cursor: pointer;
  border-radius: 10px;
}
.bottomnav button.active { color: var(--primary); background: var(--primary-soft); }

.fab {
  position: fixed; right: 18px; bottom: calc(74px + env(safe-area-inset-bottom));
  z-index: 55; width: 54px; height: 54px; border-radius: 18px; border: 0;
  background: linear-gradient(135deg, var(--primary), var(--violet));
  color: #fff; display: grid; place-items: center; cursor: pointer;
  box-shadow: 0 10px 26px rgba(99,102,241,.45);
}
.fab:active { transform: scale(.94); }

/* =====================================================================
   Cards & stats
   ===================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}
.card-head {
  display: flex; align-items: center; gap: 10px; margin-bottom: 12px;
}
.card-head h3 { margin: 0; font-size: .98rem; }
.card-head .spacer { flex: 1; }
.card-flat { box-shadow: none; background: var(--surface-2); }

.grid { display: grid; gap: 12px; }
.grid-2 { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-3 { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0,1fr)); }
.grid-4 { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0,1fr)); }

.stat {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 14px;
  position: relative; overflow: hidden;
  box-shadow: var(--shadow);
}
.stat::after {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 3px;
  background: var(--accent, var(--primary)); opacity: .9;
}
.stat-label { font-size: .74rem; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .06em; display: flex; align-items: center; gap: 6px; }
.stat-value { font-size: 1.42rem; font-weight: 700; letter-spacing: -.02em; margin-top: 6px; font-variant-numeric: tabular-nums; }
.stat-sub { font-size: .78rem; color: var(--text-dim); margin-top: 3px; }

/* =====================================================================
   Buttons
   ===================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 14px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font: inherit; font-size: .89rem; font-weight: 600; cursor: pointer;
  transition: filter .15s, transform .05s, background .15s;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-dim)); border-color: transparent; color: #fff; }
.btn-success { background: var(--success); border-color: transparent; color: #05230f; }
.btn-danger  { background: var(--danger);  border-color: transparent; color: #fff; }
.btn-ghost   { background: transparent; border-color: transparent; color: var(--text-dim); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm  { padding: 6px 10px; font-size: .8rem; border-radius: 9px; }
.btn-icon { padding: 8px; width: 36px; height: 36px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* =====================================================================
   Forms
   ===================================================================== */
.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: .8rem; font-weight: 600; color: var(--text-dim); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; padding: 10px 12px;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font: inherit; font-size: .92rem;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
input::placeholder, textarea::placeholder { color: var(--muted); }
textarea { min-height: 76px; resize: vertical; }
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%237c889e' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; padding-right: 32px;
}
input[type="checkbox"], input[type="radio"] { width: auto; }

.input-money { position: relative; }
.input-money > span.cur {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-weight: 600; pointer-events: none;
}
.input-money input { padding-left: 30px; font-variant-numeric: tabular-nums; font-weight: 600; }

.switch { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; margin-bottom: 12px; }
.switch input { width: 18px; height: 18px; accent-color: var(--primary); }
.switch .sw-text { flex: 1; }
.switch .sw-text b { display: block; font-size: .88rem; }
.switch .sw-text small { color: var(--muted); font-size: .76rem; }

.seg { display: flex; gap: 4px; background: var(--surface-2); padding: 4px; border-radius: 12px; border: 1px solid var(--border); }
.seg button {
  flex: 1; border: 0; background: none; color: var(--text-dim);
  padding: 8px 6px; border-radius: 9px; font: inherit; font-size: .84rem; font-weight: 600; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 6px;
}
.seg button.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.seg button.active[data-tone="expense"]    { color: var(--danger); }
.seg button.active[data-tone="income"]     { color: var(--success); }
.seg button.active[data-tone="investment"] { color: var(--info); }
.seg button.active[data-tone="lent"]       { color: var(--warn); }

.chips { display: flex; gap: 7px; flex-wrap: wrap; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 11px; border-radius: 999px; font-size: .8rem; font-weight: 600;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--text-dim); cursor: pointer;
}
.chip.active { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); }

/* icon picker --------------------------------------------------------- */
.icon-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px,1fr)); gap: 6px; max-height: 168px; overflow-y: auto; padding: 6px; background: var(--surface-2); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.icon-grid button { aspect-ratio: 1; border: 1px solid transparent; background: var(--surface); border-radius: 10px; color: var(--text-dim); display: grid; place-items: center; cursor: pointer; }
.icon-grid button.active { border-color: var(--primary); color: var(--primary); background: var(--primary-soft); }

.color-row { display: flex; gap: 7px; flex-wrap: wrap; }
.color-row button { width: 28px; height: 28px; border-radius: 9px; border: 2px solid transparent; cursor: pointer; }
.color-row button.active { border-color: var(--text); }

/* =====================================================================
   Lists
   ===================================================================== */
.list { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 2px; border-bottom: 1px solid var(--border-soft);
}
.row:last-child { border-bottom: 0; }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; font-size: .92rem; display: flex; align-items: center; gap: 6px; }
.row-title .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { font-size: .77rem; color: var(--muted); display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 1px; }
.row-amt { font-weight: 700; font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; font-size: .95rem; }
.row-actions { display: flex; gap: 4px; }
.row.clickable { cursor: pointer; border-radius: 10px; padding-left: 8px; padding-right: 8px; margin: 0 -8px; }
.row.clickable:hover { background: var(--surface-2); }

.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 999px;
  font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  background: var(--surface-3); color: var(--text-dim);
}
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-warn    { background: var(--warn-soft);    color: var(--warn); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--danger); display: inline-block; }

.divider { height: 1px; background: var(--border-soft); margin: 14px 0; }

.progress { height: 7px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 99px; background: var(--primary); transition: width .4s ease; }

.empty { text-align: center; padding: 32px 16px; color: var(--muted); }
.empty .ibox { margin: 0 auto 12px; width: 52px; height: 52px; border-radius: 16px; }
.empty h4 { margin: 0 0 4px; color: var(--text); font-size: .96rem; }
.empty p { margin: 0 0 14px; font-size: .85rem; }

.alert { padding: 11px 13px; border-radius: var(--radius-sm); font-size: .86rem; display: flex; gap: 9px; align-items: flex-start; margin-bottom: 12px; }
.alert-danger { background: var(--danger-soft); color: var(--danger); }
.alert-warn   { background: var(--warn-soft);   color: var(--warn); }
.alert-info   { background: var(--info-soft);   color: var(--info); }
.alert-success{ background: var(--success-soft);color: var(--success); }

/* =====================================================================
   Modal / sheet
   ===================================================================== */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(2,6,23,.66); backdrop-filter: blur(3px);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .16s ease;
}
.modal {
  background: var(--surface); width: 100%; max-width: 520px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border: 1px solid var(--border); border-bottom: 0;
  max-height: 92vh; display: flex; flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: slideup .22s cubic-bezier(.2,.8,.3,1);
}
.modal-head { display: flex; align-items: center; gap: 10px; padding: 15px 16px; border-bottom: 1px solid var(--border-soft); }
.modal-head h3 { margin: 0; font-size: 1rem; flex: 1; }
.modal-body { padding: 16px; overflow-y: auto; flex: 1; }
.modal-foot { padding: 12px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--border-soft); display: flex; gap: 8px; }
.modal-foot .btn { flex: 1; }

@keyframes fade   { from { opacity: 0 } }
@keyframes slideup{ from { transform: translateY(24px); opacity: .4 } }

/* toast --------------------------------------------------------------- */
.toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(88px + env(safe-area-inset-bottom)); z-index: 200; display: flex; flex-direction: column; gap: 8px; width: min(94vw, 420px); }
.toast {
  display: flex; align-items: center; gap: 9px;
  padding: 11px 14px; border-radius: 12px; font-size: .87rem; font-weight: 500;
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border); box-shadow: var(--shadow-lg);
  animation: slideup .2s ease;
}
.toast.ok  { border-color: var(--success); color: var(--success); }
.toast.err { border-color: var(--danger);  color: var(--danger); }

/* =====================================================================
   Login
   ===================================================================== */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 22px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .card { padding: 24px; }
.auth-hero { text-align: center; margin-bottom: 22px; }
.auth-hero .brand-logo { width: 56px; height: 56px; border-radius: 18px; font-size: 27px; margin: 0 auto 14px; }
.auth-hero h1 { margin: 0 0 4px; font-size: 1.5rem; }
.auth-hero p { margin: 0; color: var(--muted); font-size: .88rem; }
.auth-features { display: flex; justify-content: center; gap: 18px; margin-top: 20px; flex-wrap: wrap; }
.auth-features div { display: flex; flex-direction: column; align-items: center; gap: 5px; color: var(--muted); font-size: .7rem; font-weight: 600; }

/* charts -------------------------------------------------------------- */
.chart-box { position: relative; height: 220px; }
.chart-box.tall { height: 260px; }

.legend { display: flex; flex-direction: column; gap: 7px; margin-top: 12px; }
.legend-row { display: flex; align-items: center; gap: 8px; font-size: .83rem; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; flex: none; }
.legend-row .spacer { flex: 1; }

/* skeleton ------------------------------------------------------------ */
.skel { background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%); background-size: 200% 100%; animation: shim 1.3s infinite; border-radius: 8px; }
@keyframes shim { to { background-position: -200% 0 } }

.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -16px; padding: 0 16px; }

/* =====================================================================
   Desktop
   ===================================================================== */
@media (min-width: 900px) {
  body { font-size: 15px; }
  .sidebar { display: flex; }
  .bottomnav { display: none; }
  .fab { display: none; }
  .content { padding: 22px 28px 40px; }
  .appbar { padding: 16px 28px; }
  .appbar h1 { font-size: 1.3rem; }
  .grid-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
  .grid-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }
  .stat-value { font-size: 1.6rem; }
  .modal-backdrop { align-items: center; }
  .modal { border-radius: var(--radius-lg); border-bottom: 1px solid var(--border); }
  .toasts { bottom: 24px; right: 24px; left: auto; transform: none; }
  .chart-box { height: 260px; }
  .chart-box.tall { height: 320px; }
  .table-scroll { margin: 0; padding: 0; }
  .cols-2 { display: grid; grid-template-columns: 1.35fr 1fr; gap: 14px; align-items: start; }
  .cols-2 > * > .card:last-child { margin-bottom: 0; }
}

@media (min-width: 1200px) {
  .grid-6 { display: grid; grid-template-columns: repeat(6, minmax(0,1fr)); gap: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
