/* ====== Reset & Base ====== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --sidebar-bg: #0f172a;
  --sidebar-text: #cbd5e1;
  --sidebar-active: #3b82f6;
  --text: #0f172a;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --green: #10b981;
  --green-bg: #d1fae5;
  --red: #ef4444;
  --red-bg: #fee2e2;
  --radius: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --sidebar-w: 260px;
}
html { font-size: 15px; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  display: flex;
  min-height: 100vh;
}

/* ====== Sidebar ====== */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform 0.3s ease;
}
.sidebar-header { padding: 24px 20px; }
.logo {
  display: flex; align-items: center; gap: 10px;
  font-size: 1.3rem; font-weight: 800; color: #fff;
}
.logo svg { color: var(--primary); }
.sidebar-nav { flex: 1; padding: 0 12px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px; border-radius: 10px;
  color: var(--sidebar-text); text-decoration: none;
  font-weight: 500; font-size: 0.93rem; margin-bottom: 4px;
  transition: all 0.2s;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.sidebar-footer { padding: 16px 20px; font-size: 0.8rem; color: #475569; }
.api-status {
  display: flex; align-items: center; gap: 6px; margin-top: 8px;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%; background: #64748b;
}
.status-dot.online { background: var(--green); }
.status-dot.offline { background: var(--red); }

.sidebar-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.4); z-index: 199;
}
.sidebar-overlay.show { display: block; }

/* ====== Main ====== */
.main {
  flex: 1; margin-left: var(--sidebar-w);
  min-height: 100vh; display: flex; flex-direction: column;
}

/* ====== Topbar ====== */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 20px 28px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.menu-toggle {
  display: none; background: none; border: none;
  cursor: pointer; color: var(--text); padding: 4px;
}
.page-title { font-size: 1.4rem; font-weight: 700; flex: 1; }
.topbar-actions { display: flex; gap: 10px; }

/* ====== Buttons ====== */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 18px; border: none; border-radius: 8px;
  font-size: 0.875rem; font-weight: 600; cursor: pointer;
  transition: all 0.2s; font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--bg); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger-ghost { background: transparent; color: var(--red); border: 1px solid var(--red); }
.btn-danger-ghost:hover { background: var(--red-bg); }

/* ====== Content ====== */
.content { padding: 28px; flex: 1; }
.view { display: none; }
.view.active { display: block; }

/* ====== Cards ====== */
.cards-grid {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 20px; margin-bottom: 24px;
}
.card {
  background: var(--surface); border-radius: var(--radius);
  padding: 22px; display: flex; align-items: center;
  gap: 16px; box-shadow: var(--shadow-sm);
}
.card-icon {
  width: 48px; height: 48px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.card-income .card-icon { background: var(--green-bg); color: var(--green); }
.card-expense .card-icon { background: var(--red-bg); color: var(--red); }
.card-balance .card-icon { background: #dbeafe; color: var(--primary); }
.card-label { font-size: 0.82rem; color: var(--text-muted); font-weight: 500; }
.card-value { font-size: 1.55rem; font-weight: 700; margin-top: 2px; }

/* ====== Panel ====== */
.panel {
  background: var(--surface); border-radius: var(--radius);
  padding: 22px; box-shadow: var(--shadow-sm); margin-bottom: 24px;
}
.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px; flex-wrap: wrap; gap: 12px;
}
.panel-title { font-size: 1.1rem; font-weight: 700; }
.panel-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.filter-group { display: flex; gap: 10px; flex-wrap: wrap; }

/* ====== Charts ====== */
.charts-grid {
  display: grid; grid-template-columns: 2fr 1fr;
  gap: 20px; margin-bottom: 24px;
}
.chart-wrap { position: relative; height: 300px; }
.chart-wrap-doughnut { display: flex; align-items: center; justify-content: center; }
#categoryChart { max-width: 260px; }

/* ====== Table ====== */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; padding: 10px 14px; font-size: 0.8rem;
  font-weight: 600; color: var(--text-muted); text-transform: uppercase;
  letter-spacing: 0.5px; border-bottom: 2px solid var(--border);
}
.table td { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 0.9rem; }
.table tbody tr:hover { background: var(--bg); }
.ta-right { text-align: right; }
.ta-center { text-align: center; }
.badge { display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600; }
.badge-income { background: var(--green-bg); color: var(--green); }
.badge-expense { background: var(--red-bg); color: var(--red); }
.amount-income { color: var(--green); font-weight: 600; }
.amount-expense { color: var(--red); font-weight: 600; }
.cat-pill { display: inline-block; padding: 2px 10px; border-radius: 6px; font-size: 0.78rem; background: var(--bg); color: var(--text-muted); font-weight: 500; }
.action-btns { display: flex; gap: 6px; justify-content: center; }
.icon-btn {
  background: none; border: 1px solid var(--border);
  border-radius: 6px; padding: 5px; cursor: pointer;
  color: var(--text-muted); transition: all 0.2s;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { color: var(--text); border-color: var(--text-muted); }
.icon-btn.danger:hover { color: var(--red); border-color: var(--red); }

/* ====== Empty State ====== */
.empty-state { display: none; text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state.show { display: block; }
.empty-state svg { color: var(--border); margin-bottom: 12px; }
.empty-state p { font-size: 0.92rem; }
.empty-state strong { color: var(--primary); }

/* ====== Form & Input ====== */
.input, .select {
  padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 0.9rem; font-family: inherit;
  background: var(--surface); color: var(--text); transition: border-color 0.2s; outline: none;
}
.input:focus, .select:focus { border-color: var(--primary); }
.select { cursor: pointer; }

/* ====== Modal ====== */
.modal-backdrop {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.5); z-index: 300;
  align-items: center; justify-content: center; padding: 20px;
}
.modal-backdrop.show { display: flex; }
.modal {
  background: var(--surface); border-radius: 16px;
  width: 100%; max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2); animation: modalIn 0.25s ease;
}
.modal-sm { max-width: 380px; }
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 1.15rem; font-weight: 700; }
.modal-close {
  background: none; border: none; font-size: 1.8rem; cursor: pointer;
  color: var(--text-muted); line-height: 1; padding: 0; width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 6px; transition: all 0.2s;
}
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 24px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
.form-group { margin-bottom: 18px; }
.form-label { display: block; font-size: 0.82rem; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.type-toggle { display: flex; gap: 10px; }
.type-option { cursor: pointer; }
.type-option input { display: none; }
.type-badge {
  display: block; padding: 8px 24px; border-radius: 8px;
  border: 2px solid var(--border); font-weight: 600; font-size: 0.88rem;
  transition: all 0.2s; text-align: center;
}
.type-option input:checked + .type-badge-expense { border-color: var(--red); background: var(--red-bg); color: var(--red); }
.type-option input:checked + .type-badge-income { border-color: var(--green); background: var(--green-bg); color: var(--green); }

/* ====== Settings ====== */
.settings-panel { max-width: 600px; }
.setting-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 0; border-bottom: 1px solid var(--border); gap: 20px;
}
.setting-row:last-child { border-bottom: none; }
.setting-label { font-weight: 600; font-size: 0.95rem; }
.setting-desc { font-size: 0.82rem; color: var(--text-muted); margin-top: 2px; }
.setting-input { width: 80px; text-align: center; }

/* ====== Report ====== */
.report-table { width: 100%; border-collapse: collapse; margin-top: 16px; }
.report-table th, .report-table td {
  padding: 10px 14px; border-bottom: 1px solid var(--border);
  text-align: left; font-size: 0.9rem;
}
.report-table th { font-weight: 600; color: var(--text-muted); }
.report-summary { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; margin-bottom: 20px; }
.report-stat { background: var(--bg); border-radius: 10px; padding: 16px; }
.report-stat-label { font-size: 0.8rem; color: var(--text-muted); font-weight: 500; }
.report-stat-value { font-size: 1.3rem; font-weight: 700; margin-top: 4px; }
.confirm-msg { font-size: 0.92rem; color: var(--text-muted); line-height: 1.6; }

/* ====== Toast ====== */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--text); color: #fff; padding: 12px 22px;
  border-radius: 10px; font-size: 0.88rem; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.2); z-index: 400;
  transform: translateY(100px); opacity: 0;
  transition: all 0.3s ease; pointer-events: none;
}
.toast.show { transform: translateY(0); opacity: 1; }

/* ====== Loading ====== */
.loading-bar {
  position: fixed; top: 0; left: 0; width: 100%; height: 3px;
  background: var(--primary); z-index: 9999;
  animation: loadingSlide 1.5s ease infinite;
}
@keyframes loadingSlide {
  0% { transform: translateX(-100%); }
  50% { transform: translateX(0); }
  100% { transform: translateX(100%); }
}

/* ====== Responsive ====== */
@media (max-width: 900px) {
  .cards-grid { grid-template-columns: 1fr; }
  .charts-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
  .content { padding: 16px; }
  .topbar { padding: 14px 16px; }
  .page-title { font-size: 1.2rem; }
  .btn span { display: none; }
  .btn-primary { padding: 9px 12px; }
  .report-summary { grid-template-columns: 1fr; }
}
