/* ========================================================================
   ExpenseFlow — Daily Income & Expense Management System
   Global stylesheet (no external dependencies)
   ======================================================================== */

:root {
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-light: #eef2ff;
  --income: #16a34a;
  --income-light: #dcfce7;
  --expense: #dc2626;
  --expense-light: #fee2e2;
  --cash: #d97706;
  --bank: #0891b2;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-muted: #6b7280;
  --shadow: 0 1px 3px rgba(0, 0, 0, .08), 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, .10);
  --radius: 12px;
  --sidebar-w: 250px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }

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

.sidebar {
  width: var(--sidebar-w);
  background: #111827;
  color: #cbd5e1;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  display: flex;
  flex-direction: column;
  transition: transform .25s ease;
  z-index: 100;
}
.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 22px;
  font-size: 20px; font-weight: 700; color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar .brand .logo {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: grid; place-items: center; font-size: 18px;
}
.sidebar .brand small { display:block; font-size: 11px; font-weight: 400; color:#94a3b8; }

.nav { flex: 1; overflow-y: auto; padding: 12px 0; }
.nav .nav-section { padding: 14px 22px 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: #64748b; }
.nav a {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 22px; font-size: 14px;
  color: #cbd5e1; border-left: 3px solid transparent;
  transition: background .15s, color .15s;
}
.nav a .ico { width: 20px; text-align: center; font-size: 16px; }
.nav a:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav a.active { background: rgba(79,70,229,.18); color: #fff; border-left-color: var(--primary); }

.sidebar .side-foot { padding: 16px 22px; border-top: 1px solid rgba(255,255,255,.08); font-size: 12px; color:#64748b; }

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex; flex-direction: column;
  min-width: 0;
}

/* ---------------- Topbar ---------------- */
.topbar {
  height: 64px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 16px;
  padding: 0 24px;
  position: sticky; top: 0; z-index: 50;
}
.topbar .menu-btn { display: none; font-size: 22px; background: none; border: none; cursor: pointer; }
.topbar h1 { font-size: 18px; font-weight: 600; }
.topbar .search-mini {
  margin-left: auto;
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 999px; padding: 7px 14px; width: 260px; max-width: 40vw;
}
.topbar .search-mini input { border: none; background: none; outline: none; width: 100%; font-size: 13px; }
.topbar .user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 6px; border-radius: 999px;
}
.topbar .avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  color: #fff; display: grid; place-items: center; font-weight: 600;
}
.topbar .user-chip .u-name { font-size: 13px; font-weight: 600; }
.topbar .user-chip .u-role { font-size: 11px; color: var(--text-muted); }

.content { padding: 24px; flex: 1; }
.page-head { display: flex; align-items: center; flex-wrap: wrap; gap: 12px; margin-bottom: 20px; }
.page-head h2 { font-size: 22px; font-weight: 700; }
.page-head p { color: var(--text-muted); }
.page-head .spacer { flex: 1; }

/* ---------------- Cards / KPIs ---------------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 6px;
  position: relative; overflow: hidden;
}
.kpi .kpi-top { display: flex; align-items: center; justify-content: space-between; }
.kpi .kpi-label { color: var(--text-muted); font-size: 13px; }
.kpi .kpi-ico {
  width: 42px; height: 42px; border-radius: 11px;
  display: grid; place-items: center; font-size: 20px;
}
.kpi .kpi-value { font-size: 26px; font-weight: 700; }
.kpi .kpi-sub { font-size: 12px; color: var(--text-muted); }
.kpi .kpi-sub .up { color: var(--income); font-weight: 600; }
.kpi .kpi-sub .down { color: var(--expense); font-weight: 600; }
.kpi.income .kpi-ico { background: var(--income-light); color: var(--income); }
.kpi.expense .kpi-ico { background: var(--expense-light); color: var(--expense); }
.kpi.cash .kpi-ico { background: #fef3c7; color: var(--cash); }
.kpi.bank .kpi-ico { background: #cffafe; color: var(--bank); }
.kpi.total .kpi-ico { background: var(--primary-light); color: var(--primary); }
.kpi.profit .kpi-ico { background: #ede9fe; color: #7c3aed; }

/* creative accent bar on the left edge of each KPI */
.kpi::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.kpi.income::before  { background: var(--income); }
.kpi.expense::before { background: var(--expense); }
.kpi.cash::before    { background: var(--cash); }
.kpi.bank::before    { background: var(--bank); }
.kpi.total::before   { background: var(--primary); }
.kpi.profit::before  { background: #7c3aed; }

/* ---------------- Lucide SVG icons ---------------- */
.lucide { width: 20px; height: 20px; stroke-width: 2; display: inline-block; vertical-align: middle; flex: none; }
.kpi-ico .lucide { width: 22px; height: 22px; }
.brand .logo .lucide { width: 20px; height: 20px; color: #fff; }
.nav a .ico .lucide { width: 19px; height: 19px; }
.side-foot .lucide { width: 16px; height: 16px; vertical-align: -3px; }
.menu-btn .lucide { width: 24px; height: 24px; }
.search-mini .lucide { width: 16px; height: 16px; color: var(--text-muted); }
.bottom-nav a .ico .lucide { width: 22px; height: 22px; }
.bottom-nav a.fab .ico .lucide { width: 24px; height: 24px; color: #fff; }
.toast .t-ico .lucide { width: 19px; height: 19px; }
.confirm-box .c-ico .lucide { width: 34px; height: 34px; color: var(--expense); }
.btn .lucide { width: 16px; height: 16px; }
.panel-head h3 .lucide, .page-head h2 .lucide { width: 18px; height: 18px; vertical-align: -3px; }
.radio-chip span .lucide { width: 16px; height: 16px; }
.auth-brand .logo .lucide { width: 30px; height: 30px; color: #fff; }

/* ---------------- Chart cards (dashboard) ---------------- */
.chart-box { position: relative; height: 300px; padding: 18px 18px 14px; }
.chart-box.sm { height: 270px; }
@media (max-width: 768px) { .chart-box { height: 260px; } }

/* ---------------- Panels ---------------- */
.grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; margin-bottom: 24px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.panel .panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 16px 18px; border-bottom: 1px solid var(--border);
}
.panel .panel-head h3 { font-size: 15px; font-weight: 600; }
.panel .panel-head .spacer { flex: 1; }
.panel .panel-body { padding: 18px; }

/* ---------------- Charts (pure CSS/SVG) ---------------- */
.bar-chart { display: flex; align-items: flex-end; gap: 14px; height: 220px; padding-top: 10px; }
.bar-group { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 8px; height: 100%; justify-content: flex-end; }
.bars { display: flex; gap: 5px; align-items: flex-end; height: 100%; width: 100%; justify-content: center; }
.bar { width: 16px; border-radius: 5px 5px 0 0; transition: height .4s ease; }
.bar.inc { background: linear-gradient(var(--income), #22c55e); }
.bar.exp { background: linear-gradient(var(--expense), #f87171); }
.bar-label { font-size: 12px; color: var(--text-muted); }
.legend { display: flex; gap: 18px; }
.legend span { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.legend .dot { width: 11px; height: 11px; border-radius: 3px; }
.legend .dot.inc { background: var(--income); }
.legend .dot.exp { background: var(--expense); }

/* Donut */
.donut-wrap { display: flex; align-items: center; gap: 20px; }
.donut {
  width: 160px; height: 160px; border-radius: 50%;
  display: grid; place-items: center; position: relative;
}
.donut::after {
  content: ""; position: absolute; width: 96px; height: 96px;
  background: var(--surface); border-radius: 50%;
}
.donut .donut-center { position: relative; z-index: 1; text-align: center; }
.donut .donut-center b { font-size: 20px; }
.donut .donut-center span { font-size: 11px; color: var(--text-muted); }

/* ---------------- Tables ---------------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; background: #fafbfe; }
table.data tbody tr:hover { background: #f9fafb; }
table.data td .amt-in { color: var(--income); font-weight: 600; }
table.data td .amt-out { color: var(--expense); font-weight: 600; }

/* ---------------- Badges / pills ---------------- */
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.green { background: var(--income-light); color: var(--income); }
.badge.red { background: var(--expense-light); color: var(--expense); }
.badge.blue { background: var(--primary-light); color: var(--primary); }
.badge.amber { background: #fef3c7; color: var(--cash); }
.badge.cyan { background: #cffafe; color: var(--bank); }
.badge.gray { background: #f1f5f9; color: #475569; }

.pay-pill { display:inline-flex; align-items:center; gap:6px; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px; border-radius: 9px; font-size: 14px; font-weight: 600;
  border: 1px solid transparent; cursor: pointer; background: var(--primary); color: #fff;
  transition: background .15s, transform .05s;
}
.btn:hover { background: var(--primary-dark); }
.btn:active { transform: translateY(1px); }
.btn.outline { background: transparent; color: var(--text); border-color: var(--border); }
.btn.outline:hover { background: var(--bg); }
.btn.green { background: var(--income); }
.btn.green:hover { background: #15803d; }
.btn.red { background: var(--expense); }
.btn.red:hover { background: #b91c1c; }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.icon { padding: 8px; }

/* ---------------- Forms ---------------- */
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.full { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: #374151; }
.field label .req { color: var(--expense); }
.field input, .field select, .field textarea {
  padding: 11px 13px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 14px; font-family: inherit; background: #fff; color: var(--text); outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,.12);
}
.field textarea { resize: vertical; min-height: 84px; }
.form-actions { grid-column: 1 / -1; display: flex; gap: 12px; justify-content: flex-end; margin-top: 4px; }

/* payment type radio group */
.radio-row { display: flex; flex-wrap: wrap; gap: 10px; }
.radio-chip {
  position: relative; cursor: pointer;
}
.radio-chip input { position: absolute; opacity: 0; }
.radio-chip span {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 16px; border: 1px solid var(--border); border-radius: 9px;
  font-size: 13px; font-weight: 500; user-select: none; transition: all .15s;
}
.radio-chip input:checked + span {
  border-color: var(--primary); background: var(--primary-light); color: var(--primary); font-weight: 600;
}

/* ---------------- Filters bar ---------------- */
.filters {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: flex-end;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; margin-bottom: 20px; box-shadow: var(--shadow);
}
.filters .field { min-width: 150px; }

/* ---------------- Login ---------------- */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center;
  background: linear-gradient(135deg, #4f46e5, #7c3aed 60%, #0891b2);
  padding: 20px;
}
.auth-card {
  background: var(--surface); width: 100%; max-width: 420px;
  border-radius: 18px; box-shadow: var(--shadow-lg); padding: 38px 34px;
}
.auth-card .auth-brand { text-align: center; margin-bottom: 26px; }
.auth-card .auth-brand .logo {
  width: 58px; height: 58px; border-radius: 15px; margin: 0 auto 12px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: grid; place-items: center; font-size: 28px;
}
.auth-card .auth-brand h1 { font-size: 22px; }
.auth-card .auth-brand p { color: var(--text-muted); font-size: 13px; }
.auth-card .field { margin-bottom: 16px; }
.auth-card .btn { width: 100%; justify-content: center; }
.auth-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; font-size: 13px; }
.auth-row label { display: flex; align-items: center; gap: 7px; color: var(--text-muted); cursor: pointer; }
.auth-row a { color: var(--primary); font-weight: 600; }
.auth-foot { text-align: center; margin-top: 22px; font-size: 12px; color: var(--text-muted); }

/* ---------------- Ledger ---------------- */
.ledger-total td { font-weight: 700; background: #fafbfe; }

/* progress bar for accounts */
.progress { height: 8px; background: #f1f5f9; border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--primary); border-radius: 999px; }

/* ---------------- Misc ---------------- */
.text-muted { color: var(--text-muted); }
.mt-0 { margin-top: 0; }
.mb-16 { margin-bottom: 16px; }
.right { text-align: right; }
.center { text-align: center; }
.empty { text-align: center; padding: 40px; color: var(--text-muted); }

/* toggle switch */
.switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; inset: 0; background: #cbd5e1; border-radius: 999px; transition: .2s; cursor: pointer; }
.slider::before { content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + .slider { background: var(--income); }
.switch input:checked + .slider::before { transform: translateX(18px); }

/* checkbox grid for permissions */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 10px; }
.perm-item { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 9px; }

/* ---------------- Toast notifications ---------------- */
.toast-wrap { position: fixed; top: 20px; right: 20px; z-index: 400; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: #fff; border-left: 4px solid var(--primary); box-shadow: var(--shadow-lg);
  border-radius: 10px; padding: 13px 16px; min-width: 240px; max-width: 340px;
  display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 500;
  transition: all .25s ease;
}
.toast.success { border-left-color: var(--income); }
.toast.error   { border-left-color: var(--expense); }
.toast .t-ico  { font-size: 18px; }
@keyframes toastIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---------------- Confirm dialog ---------------- */
.confirm-bg { position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 420; display: none; align-items: center; justify-content: center; padding: 16px; }
.confirm-bg.show { display: flex; }
.confirm-box { background: #fff; border-radius: 16px; max-width: 380px; width: 100%; padding: 28px 24px 22px; box-shadow: var(--shadow-lg); text-align: center; }
.confirm-box .c-ico { font-size: 34px; margin-bottom: 10px; }
.confirm-box h4 { font-size: 17px; margin-bottom: 6px; }
.confirm-box p { color: var(--text-muted); margin-bottom: 22px; font-size: 14px; }
.confirm-box .row { display: flex; gap: 10px; }
.confirm-box .row .btn { flex: 1; justify-content: center; }

@media (max-width: 768px) {
  .toast-wrap { top: auto; bottom: 90px; left: 14px; right: 14px; }
  .toast { max-width: none; }
}

/* ---------------- App-like bottom nav (mobile) ---------------- */
.bottom-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 80;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 12px rgba(0,0,0,.06);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  grid-template-columns: repeat(5, 1fr);
}
.bottom-nav a {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 2px; font-size: 10px; color: var(--text-muted); border-radius: 10px;
}
.bottom-nav a .ico { font-size: 20px; line-height: 1; }
.bottom-nav a.active { color: var(--primary); }
.bottom-nav a.fab {
  color: #fff;
}
.bottom-nav a.fab .ico {
  width: 46px; height: 46px; margin-top: -22px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: grid; place-items: center; font-size: 24px;
  box-shadow: 0 6px 16px rgba(79,70,229,.4); border: 4px solid var(--bg);
}
.bottom-nav a.fab span:not(.ico) { color: var(--primary); }

/* ---------------- Responsive ---------------- */
.backdrop { display: none; }
@media (max-width: 1024px) {
  .grid-2 { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .topbar .menu-btn { display: block; }
  .topbar .search-mini { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .backdrop.show { display: block; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 90; }
  .bottom-nav { display: grid; }
  .content { padding: 16px 14px 90px; }   /* leave room for bottom nav */
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .kpi .kpi-value { font-size: 20px; }
  .page-head h2 { font-size: 19px; }
  .topbar h1 { font-size: 16px; }
  .filters { flex-direction: column; align-items: stretch; }
  .filters .field { min-width: 0; }
}
@media (max-width: 420px) {
  .kpi-grid { grid-template-columns: 1fr; }
}
