:root {
  --primary: #4f46e5;
  --primary-600: #4338ca;
  --primary-soft: #eef2ff;
  --bg: #f4f5fb;
  --card: #ffffff;
  --text: #1e2330;
  --muted: #6b7280;
  --border: #e5e7eb;
  --green: #16a34a;
  --green-soft: #dcfce7;
  --red: #dc2626;
  --red-soft: #fee2e2;
  --amber: #d97706;
  --amber-soft: #fef3c7;
  --blue: #2563eb;
  --purple: #8b5cf6;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 3px rgba(30,35,48,.06), 0 1px 2px rgba(30,35,48,.04);
  --shadow-lg: 0 12px 40px rgba(30,35,48,.12);
  --sidebar-w: 250px;
  --bottomnav-h: 64px;
}

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

html, body { height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 15px; }

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

.sidebar {
  width: var(--sidebar-w);
  background: #111827;
  color: #e5e7eb;
  position: fixed;
  inset: 0 auto 0 0;
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; }
.brand-logo {
  width: 36px; height: 36px; border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 18px;
}
.brand-name { font-weight: 700; font-size: 16px; color: #fff; }

.side-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: #9ca3af; font-weight: 500; font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-item svg { width: 19px; height: 19px; flex-shrink: 0; }

.side-footer { padding: 12px; font-size: 12px; color: #6b7280; }
.user-chip {
  display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 10px;
  background: rgba(255,255,255,.05);
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.user-chip-name { font-size: 13px; color: #fff; font-weight: 600; }
.user-chip-role { font-size: 11px; color: #9ca3af; text-transform: capitalize; }

.main {
  flex: 1;
  margin-left: var(--sidebar-w);
  padding: 24px 28px 40px;
  min-width: 0;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px; gap: 16px;
}
.page-title h1 { font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.page-title p { color: var(--muted); font-size: 14px; margin-top: 2px; }

/* Bottom nav (mobile) */
.bottom-nav {
  display: none;
  position: fixed; left: 0; right: 0; bottom: 0;
  height: var(--bottomnav-h);
  background: #fff; border-top: 1px solid var(--border);
  z-index: 40;
}
.bottom-nav a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--muted); font-size: 11px; font-weight: 600;
}
.bottom-nav a.active { color: var(--primary); }
.bottom-nav svg { width: 22px; height: 22px; }

/* FAB */
.fab {
  position: fixed; right: 20px; bottom: calc(var(--bottomnav-h) + 16px);
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: var(--primary); color: #fff; box-shadow: var(--shadow-lg);
  display: grid; place-items: center; z-index: 45;
}
.fab svg { width: 26px; height: 26px; }
@media (min-width: 901px) { .fab { bottom: 24px; } }

/* ---------- Cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px;
}

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

.stat-card { position: relative; overflow: hidden; }
.stat-card .stat-icon {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  margin-bottom: 14px; color: #fff;
}
.stat-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 800; letter-spacing: -.02em; margin-top: 2px; }
.stat-sub { font-size: 12px; color: var(--muted); margin-top: 4px; }
.stat-sub .up { color: var(--green); font-weight: 600; }
.stat-sub .down { color: var(--red); font-weight: 600; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid transparent;
  font-weight: 600; font-size: 14px; transition: all .15s;
}
.btn svg { width: 18px; height: 18px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--bg); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--red-soft); color: var(--red); }
.btn-green { background: var(--green-soft); color: var(--green); }
.btn-sm { padding: 7px 12px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge svg { width: 13px; height: 13px; }
.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: #dbeafe; color: var(--blue); }
.badge-purple { background: #ede9fe; color: var(--purple); }
.badge-gray { background: #e5e7eb; color: #374151; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.status-pago, .status-recebido { background: var(--green); }
.status-pendente { background: var(--amber); }
.status-vencido { background: var(--red); }
.status-cancelado { background: #9ca3af; }

/* ---------- Money ---------- */
.money { font-variant-numeric: tabular-nums; }
.money-pos { color: var(--green); }
.money-neg { color: var(--red); }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; min-width: 640px; }
thead th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 600;
}
tbody td { padding: 13px 14px; border-bottom: 1px solid var(--border); font-size: 14px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfe; }
.cell-strong { font-weight: 600; }
.cell-muted { color: var(--muted); font-size: 13px; }

/* ---------- Forms ---------- */
.form { display: flex; flex-direction: column; gap: 14px; }
.form-row { display: grid; gap: 14px; }
.form-row-2 { grid-template-columns: 1fr 1fr; }
.form-row-3 { grid-template-columns: repeat(3, 1fr); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.field small { font-size: 12px; color: var(--muted); }
.input, .select, .textarea {
  width: 100%; padding: 11px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: #fff; color: var(--text);
  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);
}
.textarea { resize: vertical; min-height: 70px; }

.segmented { display: flex; background: var(--bg); border-radius: 10px; padding: 4px; gap: 4px; }
.segmented button {
  flex: 1; padding: 8px; border: none; background: transparent; border-radius: 8px;
  font-weight: 600; font-size: 13px; color: var(--muted); transition: all .15s;
}
.segmented button.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }

/* ---------- Modals ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,18,28,.5);
  display: none; align-items: flex-end; justify-content: center; z-index: 60;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }
.modal {
  background: #fff; width: 100%; max-width: 560px; border-radius: 20px 20px 0 0;
  padding: 22px; max-height: 92vh; overflow-y: auto; animation: slideUp .25s ease;
}
@media (min-width: 601px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: 20px; box-shadow: var(--shadow-lg); }
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-header h2 { font-size: 18px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--muted); font-size: 22px; line-height: 1; }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ---------- Toast ---------- */
.toasts { position: fixed; top: 18px; right: 18px; z-index: 80; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: #111827; color: #fff; padding: 12px 16px; border-radius: 12px;
  display: flex; align-items: center; gap: 10px; font-size: 14px; box-shadow: var(--shadow-lg);
  animation: slideIn .25s ease; max-width: 340px;
}
.toast.success { border-left: 4px solid var(--green); }
.toast.error { border-left: 4px solid var(--red); }
.toast.info { border-left: 4px solid var(--blue); }
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ---------- Empty state ---------- */
.empty {
  text-align: center; padding: 50px 20px; color: var(--muted);
  display: flex; flex-direction: column; align-items: center; gap: 12px;
}
.empty-icon { font-size: 46px; }
.empty h3 { color: var(--text); font-size: 17px; font-weight: 700; }

/* ---------- Skeleton ---------- */
.skeleton {
  background: linear-gradient(90deg, #eef0f4 25%, #e2e5ec 50%, #eef0f4 75%);
  background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 8px;
}
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- Progress ---------- */
.progress { height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 999px; transition: width .4s ease; }
.progress-bar.green { background: var(--green); }
.progress-bar.amber { background: var(--amber); }

/* ---------- Person/Account cards ---------- */
.entity-card { display: flex; align-items: center; gap: 14px; }
.entity-avatar {
  width: 46px; height: 46px; border-radius: 12px; display: grid; place-items: center;
  font-weight: 700; color: #fff; font-size: 17px; flex-shrink: 0;
}
.entity-info { flex: 1; min-width: 0; }
.entity-name { font-weight: 600; font-size: 15px; }
.entity-sub { font-size: 13px; color: var(--muted); }
.entity-value { font-weight: 700; font-size: 15px; }

/* ---------- Charts ---------- */
.chart-tabs { display: flex; gap: 6px; margin-bottom: 14px; }
.chart-tabs button {
  padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: #fff; font-size: 13px; font-weight: 600; color: var(--muted);
}
.chart-tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.chart-legend { display: flex; gap: 16px; font-size: 12px; color: var(--muted); margin-top: 10px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-dot { width: 10px; height: 10px; border-radius: 3px; }

/* ---------- Calendar ---------- */
.calendar { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-header { font-size: 11px; text-transform: uppercase; color: var(--muted); text-align: center; font-weight: 600; padding: 6px 0; }
.cal-day {
  min-height: 78px; background: #fff; border: 1px solid var(--border); border-radius: 10px;
  padding: 6px; cursor: pointer; transition: all .15s; text-align: left;
}
.cal-day:hover { border-color: var(--primary); }
.cal-day.today { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.cal-day.other { opacity: .4; }
.cal-day-num { font-size: 12px; font-weight: 600; color: var(--muted); }
.cal-day .items { display: flex; flex-direction: column; gap: 3px; margin-top: 4px; }
.cal-item { display: flex; align-items: center; gap: 3px; font-size: 10px; font-weight: 600; padding: 1px 5px; border-radius: 5px; white-space: nowrap; overflow: hidden; }
.cal-item.receita { background: var(--green-soft); color: var(--green); }
.cal-item.despesa { background: var(--red-soft); color: var(--red); }
.cal-item.vencido { background: var(--amber-soft); color: var(--amber); }

/* ---------- Installments ---------- */
.installment-row { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.installment-row:last-child { border-bottom: none; }
.inst-no { width: 40px; height: 40px; border-radius: 50%; background: var(--primary-soft); color: var(--primary); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex-shrink: 0; }
.inst-no.paid { background: var(--green-soft); color: var(--green); }
.inst-no.overdue { background: var(--red-soft); color: var(--red); }

/* ---------- Search ---------- */
.search { position: relative; }
.search input { padding-left: 38px; }
.search svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }

.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar .spacer { flex: 1; }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(1200px 600px at 50% -10%, #eef2ff 0%, var(--bg) 55%); }
.auth-card { width: 100%; max-width: 400px; }
.auth-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 26px; justify-content: center; }
.auth-card h2 { font-size: 22px; font-weight: 800; text-align: center; letter-spacing: -.02em; }
.auth-card .auth-sub { text-align: center; color: var(--muted); font-size: 14px; margin: 6px 0 24px; }
.auth-switch { text-align: center; font-size: 14px; color: var(--muted); margin-top: 18px; }
.auth-switch a { color: var(--primary); font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
.auth-switch svg { width: 14px; height: 14px; }
.auth-error { background: var(--red-soft); color: var(--red); padding: 10px 14px; border-radius: 10px; font-size: 13px; font-weight: 500; }
.auth-success { background: var(--green-soft); color: var(--green); padding: 10px 14px; border-radius: 10px; font-size: 13px; font-weight: 500; }

/* ---------- Tabs/Detail ---------- */
.detail-hero { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.detail-hero .big { font-size: 30px; font-weight: 800; letter-spacing: -.02em; }

.pill-list { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  padding: 8px 14px; border-radius: 999px; border: 1px solid var(--border);
  background: #fff; font-size: 13px; font-weight: 600; cursor: pointer; transition: all .15s;
}
.pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pill.green.active { background: var(--green); border-color: var(--green); }
.pill.red.active { background: var(--red); border-color: var(--red); }
.pill.gray.active { background: #374151; border-color: #374151; color: #fff; }

.mt-8 { margin-top: 8px; } .mt-12 { margin-top: 12px; } .mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; }

.section-title { font-size: 16px; font-weight: 700; margin-bottom: 14px; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.strong { font-weight: 700; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.grow { flex-grow: 1; }
.hidden { display: none !important; }
.text-right { text-align: right; }

/* Notifications */
.notif-item { display: flex; align-items: flex-start; gap: 12px; padding: 14px 0; border-bottom: 1px solid var(--border); }
.notif-item:last-child { border-bottom: none; }
.notif-icon { width: 36px; height: 36px; border-radius: 10px; display: grid; place-items: center; flex-shrink: 0; }
.notif-msg { font-size: 14px; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 900px) {
  .sidebar { display: none; }
  .main { margin-left: 0; padding: 18px 16px calc(var(--bottomnav-h) + 70px); }
  .bottom-nav { display: flex; }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 600px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .form-row-2, .form-row-3 { grid-template-columns: 1fr; }
  .stat-value { font-size: 22px; }
  .table-on-mobile tbody tr { display: block; }
}

/* ---------- Responsive utilities ---------- */
.desktop-only { display: block; }
.mobile-only { display: none; }
@media (max-width: 600px) {
  .desktop-only { display: none; }
  .mobile-only { display: block; }
  .hide-m { display: none !important; }
}
@media (min-width: 601px) { .hide-m { display: initial; } }

/* ---------- Transaction rows / cards ---------- */
.tx-list { padding: 2px 0; }
.tx-row {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 8px; border-bottom: 1px solid var(--border); cursor: pointer;
  transition: background .1s;
}
.tx-row:last-child { border-bottom: none; }
.tx-row:hover { background: #fafbfe; }
.tx-cards { display: flex; flex-direction: column; gap: 10px; }
.tx-card {
  background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 13px 14px; cursor: pointer;
}
.tx-card:hover { border-color: var(--primary); }

/* ---------- Icon button ---------- */
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px;
  border: 1px solid var(--border); background: #fff; color: var(--muted);
  display: grid; place-items: center; transition: all .15s; position: relative;
}
.icon-btn:hover { color: var(--text); border-color: var(--primary); }
.icon-btn svg { width: 18px; height: 18px; }
.bell .badge-count {
  position: absolute; top: -5px; right: -6px;
  background: var(--red); color: #fff; font-size: 10px; font-weight: 700;
  min-width: 17px; height: 17px; border-radius: 999px;
  display: grid; place-items: center; padding: 0 4px;
}

/* ---------- Bottom sheet ---------- */
.modal-overlay.sheet-overlay { align-items: flex-end; }
.sheet {
  background: #fff; width: 100%; max-width: 540px;
  border-radius: 20px 20px 0 0; padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
  animation: slideUp .25s ease;
}
@media (min-width: 601px) {
  .modal-overlay.sheet-overlay { align-items: center; }
  .sheet { border-radius: 20px; box-shadow: var(--shadow-lg); }
}
.sheet-option {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 13px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: #fff;
  font-weight: 600; font-size: 15px; color: var(--text); text-align: left;
  transition: all .15s;
}
.sheet-option:hover { border-color: var(--primary); background: var(--primary-soft); }
.sheet-ic {
  width: 44px; height: 44px; border-radius: 12px;
  display: grid; place-items: center; color: #fff; flex-shrink: 0;
}
.sheet-ic svg { width: 21px; height: 21px; }

/* ---------- Color input ---------- */
input[type=color] {
  width: 100%; height: 44px; border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 4px; background: #fff; cursor: pointer;
}

/* ---------- Stat trend ---------- */
.stat-up { color: var(--green); }
.stat-down { color: var(--red); }

/* ---------- Misc ---------- */
.page-title p:empty { display: none; }
.cell-min { font-size: 13px; }
table .strong { font-weight: 600; }