:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-2: #475569;
  --muted: #64748b;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-soft: #eef2ff;
  --green: #059669;
  --green-soft: #ecfdf5;
  --red: #dc2626;
  --red-soft: #fef2f2;
  --amber: #d97706;
  --amber-soft: #fffbeb;
  --blue: #2563eb;
  --blue-soft: #eff6ff;
  --purple: #7c3aed;
  --purple-soft: #f5f3ff;
  --hero-grad: linear-gradient(135deg, #0f172a 0%, #1e293b 55%, #312e81 100%);
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  --radius: 16px;
  --radius-sm: 10px;
  --sidebar-w: 248px;
}

[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111827;
  --surface-2: #1e293b;
  --border: #263245;
  --text: #f8fafc;
  --text-2: #cbd5e1;
  --muted: #94a3b8;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --primary-soft: rgba(99, 102, 241, 0.16);
  --green: #10b981;
  --green-soft: rgba(16, 185, 129, 0.15);
  --red: #f87171;
  --red-soft: rgba(248, 113, 113, 0.15);
  --amber: #fbbf24;
  --amber-soft: rgba(251, 191, 36, 0.15);
  --blue: #60a5fa;
  --blue-soft: rgba(96, 165, 250, 0.15);
  --purple: #a78bfa;
  --purple-soft: rgba(167, 139, 250, 0.15);
  --hero-grad: linear-gradient(135deg, #111827 0%, #1e1b4b 60%, #172554 100%);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
  line-height: 1.45;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
.w-full { width: 100%; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-amber { color: var(--amber); }
.text-blue { color: var(--blue); }
.text-purple { color: var(--purple); }
.text-right { text-align: right; }
.fw-600 { font-weight: 600; }
.fw-700 { font-weight: 700; }

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 24px; }
.login-brand h1 { margin: 0; font-size: 20px; letter-spacing: -0.02em; }
.login-brand p { margin: 2px 0 0; font-size: 13px; }
.login-foot { margin: 16px 0 0; font-size: 12px; text-align: center; }

.brand-logo {
  width: 44px; height: 44px; border-radius: 13px;
  background: linear-gradient(135deg, #4f46e5, #0ea5e9);
  color: #fff; font-weight: 800; font-size: 22px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.brand-logo.sm { width: 36px; height: 36px; border-radius: 10px; font-size: 18px; }
.brand-logo.xs { width: 28px; height: 28px; border-radius: 8px; font-size: 15px; }

/* App Shell */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: fixed; top: 0; bottom: 0; left: 0; z-index: 30;
  padding: 16px 12px;
}
.sidebar-top { display: flex; flex-direction: column; gap: 14px; margin-bottom: 18px; }
.sidebar-brand { display: flex; align-items: center; gap: 10px; cursor: pointer; padding: 4px 6px; }
.brand-title { font-weight: 700; font-size: 16px; letter-spacing: -0.02em; }
.brand-sub { font-size: 11px; color: var(--muted); }
.sidebar-add-btn { height: 42px; font-size: 14px; border-radius: 12px; }

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; padding: 10px 12px; border: 0; border-radius: 11px;
  background: transparent; color: var(--text-2);
  font-size: 14px; font-weight: 500; cursor: pointer; 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-ico { width: 20px; text-align: center; font-size: 16px; }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
}
.user-chip { display: flex; align-items: center; gap: 9px; min-width: 0; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary-soft); color: var(--primary);
  font-weight: 700; display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.user-meta { min-width: 0; }
.user-name { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; }
.sidebar-actions { display: flex; gap: 4px; }

.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1; min-width: 0;
  display: flex; flex-direction: column;
}
.view-root {
  max-width: 1260px; width: 100%; margin: 0 auto;
  padding: 22px 24px 48px;
}

.mobile-header, .bottom-nav { display: none; }

.pwd-banner {
  background: var(--amber-soft);
  border-bottom: 1px solid rgba(217, 119, 6, 0.25);
  color: var(--amber);
  padding: 10px 24px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  font-size: 13px; font-weight: 500;
}

/* Buttons & Inputs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: 11px;
  padding: 9px 15px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s; background: var(--surface-2); color: var(--text);
  text-decoration: none;
}
.btn:hover { filter: brightness(0.96); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); filter: none; }
.btn-green { background: var(--green); color: #fff; }
.btn-red { background: var(--red); color: #fff; }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--text-2); padding: 6px 10px; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-sm { padding: 6px 11px; font-size: 12px; border-radius: 9px; }
.btn-lg { padding: 12px 18px; font-size: 15px; border-radius: 13px; }

.icon-btn {
  width: 34px; height: 34px; border-radius: 10px;
  border: 1px solid transparent; background: transparent; color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer; font-size: 16px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.form-stack { display: flex; flex-direction: column; gap: 13px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 12px; font-weight: 600; color: var(--text-2); }
input, select, textarea {
  width: 100%; padding: 10px 12px; border-radius: 11px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font-size: 14px; font-family: inherit; outline: none; transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
textarea { resize: vertical; min-height: 68px; }

/* Amount-first big Saldo input */
.amount-hero-input {
  font-size: 30px; font-weight: 800; padding: 14px 16px;
  text-align: center; letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  border-radius: 14px; background: var(--surface-2); border: 2px solid transparent;
}
.amount-hero-input:focus { background: var(--surface); border-color: var(--primary); }

/* Page Header & Controls */
.page-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 18px;
}
.page-title { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -0.025em; }
.head-controls { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

/* Segmented Tabs (Saldo signature) */
.seg-tabs {
  display: inline-flex; background: var(--surface-2); padding: 4px;
  border-radius: 12px; gap: 2px; flex-wrap: wrap;
}
.seg-tab {
  border: 0; background: transparent; color: var(--text-2);
  padding: 7px 13px; border-radius: 9px; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: all .15s;
}
.seg-tab.active {
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* Chips */
.chips-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.chip {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); font-size: 12px; font-weight: 600;
  cursor: pointer; transition: all .15s;
}
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Cards & Grids */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow-sm);
}
.card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin-bottom: 14px;
}
.card-title { margin: 0; font-size: 15px; font-weight: 700; }

/* Saldo Hero Balance Card */
.hero-balance {
  background: var(--hero-grad);
  color: #ffffff;
  border-radius: 22px;
  padding: 24px 26px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  position: relative;
  overflow: hidden;
}
.hero-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.hero-label { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; color: rgba(255,255,255,0.68); font-weight: 600; }
.hero-amount { font-size: 38px; font-weight: 800; letter-spacing: -0.03em; margin: 4px 0 6px; line-height: 1.1; }
.hero-sub { font-size: 13px; color: rgba(255,255,255,0.78); display: flex; gap: 14px; flex-wrap: wrap; }
.hero-currencies { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.curr-pill {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.14);
  padding: 6px 12px; border-radius: 11px;
  font-size: 13px; font-weight: 600;
}
.hero-stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  margin-top: 18px; padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.14);
}
.hero-stat-label { font-size: 11px; color: rgba(255,255,255,0.65); }
.hero-stat-val { font-size: 16px; font-weight: 700; margin-top: 2px; }

/* KPI Grid */
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.kpi-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow-sm);
  cursor: pointer; transition: transform .15s, border-color .15s;
}
.kpi-card:hover { transform: translateY(-1px); border-color: var(--primary); }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 600; display: flex; align-items: center; justify-content: space-between; }
.kpi-val { font-size: 22px; font-weight: 800; margin: 6px 0 3px; letter-spacing: -0.02em; }
.kpi-sub { font-size: 12px; color: var(--muted); }

/* 2-col layout */
.grid-2 { display: grid; grid-template-columns: 1.2fr 1fr; gap: 16px; margin-bottom: 16px; }
.grid-equal { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }

/* Horizontal Saldo Wallet Cards */
.wallet-strip { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 12px; margin-bottom: 18px; }
.wallet-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 15px; padding: 14px 16px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 6px;
}
.wallet-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.wallet-name { font-weight: 700; font-size: 14px; }
.wallet-bal { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.wallet-meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }

/* Badges */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700;
}
.badge-green { background: var(--green-soft); color: var(--green); }
.badge-red { background: var(--red-soft); color: var(--red); }
.badge-amber { background: var(--amber-soft); color: var(--amber); }
.badge-blue { background: var(--blue-soft); color: var(--blue); }
.badge-purple { background: var(--purple-soft); color: var(--purple); }
.badge-gray { background: var(--surface-2); color: var(--text-2); }
.pill-badge {
  margin-left: auto; padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 700;
}
.pill-badge.danger { background: var(--red); color: #fff; }

/* Saldo Debt Cards */
.debt-list { display: flex; flex-direction: column; gap: 10px; }
.debt-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 15px; padding: 15px 18px;
  display: flex; flex-direction: column; gap: 10px;
  transition: border-color .15s;
}
.debt-card.overdue { border-color: rgba(220, 38, 38, 0.45); }
.debt-row-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.debt-cp { font-size: 16px; font-weight: 700; cursor: pointer; }
.debt-cp:hover { color: var(--primary); }
.debt-title { font-size: 13px; color: var(--text-2); margin-top: 2px; }
.debt-amount-box { text-align: right; }
.debt-rem { font-size: 20px; font-weight: 800; letter-spacing: -0.02em; }
.debt-orig { font-size: 12px; color: var(--muted); }
.progress-track { height: 7px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 999px; transition: width .3s; }
.progress-fill.payable { background: linear-gradient(90deg, #f97316, #ef4444); }
.progress-fill.receivable { background: linear-gradient(90deg, #10b981, #059669); }
.debt-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--muted); }
.debt-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Day-Grouped Ledger (Saldo style) */
.day-group { margin-bottom: 14px; }
.day-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 6px 4px; font-size: 12px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.04em;
}
.tx-row {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 14px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 13px; margin-bottom: 6px;
}
.tx-dot {
  width: 36px; height: 36px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: 700; flex-shrink: 0;
}
.tx-main { flex: 1; min-width: 0; }
.tx-title { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-sub { font-size: 12px; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.tx-right { text-align: right; flex-shrink: 0; }
.tx-amt { font-size: 15px; font-weight: 700; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 10px 12px; font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
td { padding: 11px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: 0; }
tr:hover td { background: var(--surface-2); }

/* Filters bar */
.filter-bar {
  display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px;
}
.filter-bar input, .filter-bar select { width: auto; min-width: 150px; padding: 8px 11px; font-size: 13px; }
.filter-bar input[type="search"] { flex: 1; min-width: 200px; }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border); border-radius: 16px;
  padding: 24px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.drag { border-color: var(--primary); background: var(--primary-soft); }

/* Modal / Bottom Sheet */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal-box {
  width: 100%; max-width: 520px; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 22px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 2;
}
.modal-header h3 { margin: 0; font-size: 17px; font-weight: 700; }
.modal-body { padding: 18px 20px 22px; }

/* Alerts & Toasts */
.alert-error {
  background: var(--red-soft); color: var(--red); padding: 10px 12px;
  border-radius: 10px; font-size: 13px; font-weight: 600;
}
.empty-state {
  text-align: center; padding: 36px 20px; color: var(--muted);
}
.empty-state h4 { margin: 0 0 6px; color: var(--text); font-size: 15px; }

.toast-host {
  position: fixed; right: 18px; bottom: 24px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: #0f172a; color: #fff; padding: 11px 16px; border-radius: 12px;
  font-size: 13px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,0.25);
  animation: fadeUp .2s ease;
}
.toast.ok { background: #059669; }
.toast.err { background: #dc2626; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* Charts */
.chart-box { width: 100%; overflow: hidden; }
.bar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; font-size: 13px; }
.bar-label { width: 150px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bar-track { flex: 1; height: 9px; background: var(--surface-2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; }
.bar-val { width: 105px; text-align: right; font-weight: 700; }

/* Responsive Mobile (Native Saldo Feel) */
@media (max-width: 960px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .hero-stats { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-equal { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .main-wrap { margin-left: 0; padding-bottom: 82px; }
  .mobile-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 25;
  }
  .mobile-brand { display: flex; align-items: center; gap: 9px; font-weight: 800; font-size: 16px; }
  .mobile-header-actions { display: flex; gap: 4px; }
  .view-root { padding: 14px 14px 30px; }
  .hero-balance { padding: 18px; border-radius: 18px; }
  .hero-amount { font-size: 30px; }
  .form-grid { grid-template-columns: 1fr; }
  .bottom-nav {
    display: grid; grid-template-columns: 1fr 1fr 64px 1fr 1fr;
    align-items: center; position: fixed; left: 0; right: 0; bottom: 0; z-index: 40;
    background: var(--surface); border-top: 1px solid var(--border);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
  }
  .bnav-item {
    border: 0; background: transparent; color: var(--muted);
    display: flex; flex-direction: column; align-items: center; gap: 2px;
    font-size: 10px; font-weight: 600; padding: 4px 0; cursor: pointer;
  }
  .bnav-item.active { color: var(--primary); }
  .bnav-ico { font-size: 18px; line-height: 1.1; }
  .bnav-fab {
    width: 52px; height: 52px; border-radius: 17px; margin: -22px auto 0;
    border: 0; background: linear-gradient(135deg, #4f46e5, #0ea5e9);
    color: #fff; font-size: 26px; font-weight: 700; cursor: pointer;
    box-shadow: 0 8px 20px rgba(79, 70, 229, 0.4);
    display: flex; align-items: center; justify-content: center;
  }
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal-box { border-radius: 22px 22px 0 0; max-width: 100%; max-height: 92vh; }
  .toast-host { left: 14px; right: 14px; bottom: 88px; }
}
