:root {
  --color-primary: #2563EB;
  --color-primary-dark: #1D4ED8;
  --color-income: #10B981;
  --color-expense: #EF4444;
  --color-reserve: #7C3AED;
  --color-white: #FFFFFF;
  --color-gray-50: #F9FAFB;
  --color-gray-100: #F3F4F6;
  --color-gray-200: #E5E7EB;
  --color-gray-300: #D1D5DB;
  --color-gray-400: #9CA3AF;
  --color-gray-500: #6B7280;
  --color-gray-600: #4B5563;
  --color-gray-700: #374151;
  --color-gray-800: #1F2937;
  --color-gray-900: #111827;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { font-family: 'DM Sans', sans-serif; background: var(--color-gray-100); color: var(--color-gray-800); line-height: 1.5; }

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

/* ── SIDEBAR ──────────────────────────────────── */
.sidebar {
  width: 260px; background: var(--color-white); border-right: 1px solid var(--color-gray-200);
  position: fixed; height: 100vh; z-index: 100; display: flex; flex-direction: column;
  transition: transform 0.3s ease;
}
.sidebar__header { padding: 1.5rem; border-bottom: 1px solid var(--color-gray-100); }
.sidebar__logo { display: flex; align-items: center; gap: 0.75rem; font-weight: 700; color: var(--color-primary); font-size: 1.25rem; }
.sidebar__logo-icon { width: 36px; height: 36px; background: var(--color-primary); color: white; border-radius: 8px; display: flex; align-items: center; justify-content: center; }
.sidebar__nav { flex: 1; padding: 1rem; overflow-y: auto; }
.sidebar__section { margin-bottom: 1.5rem; }
.sidebar__title { font-size: 0.75rem; text-transform: uppercase; color: var(--color-gray-400); font-weight: 600; padding: 0 0.75rem; margin-bottom: 0.5rem; }
.sidebar__menu { display: flex; flex-direction: column; gap: 0.25rem; }
.sidebar__item {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem; border-radius: 8px;
  color: var(--color-gray-600); font-size: 0.875rem; font-weight: 500; cursor: pointer;
  border: none; background: none; width: 100%; text-align: left; transition: all 0.2s;
}
.sidebar__item:hover { background: var(--color-gray-50); color: var(--color-gray-900); }
.sidebar__item.active { background: #EFF6FF; color: var(--color-primary); }
.sidebar__icon { width: 20px; text-align: center; }

/* ── MAIN LAYOUT ──────────────────────────────── */
.main { flex: 1; margin-left: 260px; min-height: 100vh; }
.header {
  background: var(--color-white); border-bottom: 1px solid var(--color-gray-200);
  padding: 1rem 2rem; display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 50;
}
.header__left { display: flex; align-items: center; gap: 1rem; }
.menu-toggle { display: none; width: 40px; height: 40px; align-items: center; justify-content: center; background: var(--color-gray-100); border-radius: 8px; border: none; cursor: pointer; }
.header__title { font-size: 1.25rem; font-weight: 700; }

/* ── BUTTONS ──────────────────────────────────── */
.btn { padding: 0.625rem 1.25rem; border-radius: 8px; font-weight: 600; font-size: 0.875rem; cursor: pointer; border: none; display: inline-flex; align-items: center; gap: 0.5rem; transition: all 0.2s; font-family: inherit; }
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn-primary { background: var(--color-primary); color: white; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-gray-100); color: var(--color-gray-700); }
.btn-secondary:hover { background: var(--color-gray-200); }
.btn-danger { background: var(--color-expense); color: white; }
.btn-danger:hover { background: #DC2626; }
.btn-sm { padding: 0.5rem 1rem; font-size: 0.75rem; }
.btn-icon { padding: 0.5rem; }

/* ── CONTENT ──────────────────────────────────── */
.content { padding: 2rem; max-width: 1400px; margin: 0 auto; }
.page-title { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem; }
.page-header { margin-bottom: 1.5rem; }
.page-subtitle {
  color: var(--color-gray-500);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

/* ── MONTH NAVIGATOR ──────────────────────────── */
.month-navigator {
  display: inline-flex; align-items: center; gap: 0.5rem;
  background: var(--color-white); border: 1px solid var(--color-gray-200);
  border-radius: 8px; padding: 0.25rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.month-btn {
  width: 32px; height: 32px; border: none; background: transparent; border-radius: 6px;
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 1.25rem; color: var(--color-gray-600); transition: all 0.2s; font-weight: bold;
}
.month-btn:hover { background: var(--color-gray-100); color: var(--color-gray-900); }
.month-btn:active { transform: scale(0.95); }
.month-display {
  min-width: 140px; text-align: center; font-weight: 600; font-size: 0.875rem;
  color: var(--color-gray-800); padding: 0 0.5rem; user-select: none;
}
.month-display.future { color: var(--color-primary); }
.month-display.past { color: var(--color-gray-600); }
.current-month-badge {
  font-size: 0.75rem; background: var(--color-primary); color: white;
  padding: 4px 12px; border-radius: 12px; margin-left: 0.5rem;
  font-weight: 600; cursor: pointer; border: none; transition: all 0.2s; font-family: inherit;
}
.current-month-badge:hover { background: var(--color-primary-dark); transform: translateY(-1px); }
.current-month-badge.hidden { display: none; }

/* ── FILTER INDICATOR ─────────────────────────── */
.filter-indicator {
  display: inline-flex; align-items: center; gap: 0.5rem;
  background: #EFF6FF; color: var(--color-primary);
  padding: 4px 12px; border-radius: 20px; font-size: 0.875rem;
  font-weight: 500; border: 1px solid var(--color-primary);
}
.filter-indicator .filter-close { cursor: pointer; font-weight: bold; opacity: 0.7; }
.filter-indicator .filter-close:hover { opacity: 1; }

/* ── KPI CARDS ────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.kpi-card { background: white; padding: 1.5rem; border-radius: 12px; box-shadow: 0 1px 3px rgba(0,0,0,0.1); display: flex; align-items: center; gap: 1rem; border-left: 4px solid transparent; transition: transform 0.2s, box-shadow 0.2s; }
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.kpi-card.income { border-left-color: var(--color-income); }
.kpi-card.expense { border-left-color: var(--color-expense); }
.kpi-card.reserve { border-left-color: var(--color-reserve); }
.kpi-card.balance { border-left-color: var(--color-primary); }
.kpi-card__icon { width: 48px; height: 48px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; flex-shrink: 0; }
.kpi-card__icon.income { background: #D1FAE5; }
.kpi-card__icon.expense { background: #FEE2E2; }
.kpi-card__icon.reserve { background: #EDE9FE; }
.kpi-card__icon.balance { background: #EFF6FF; }
.kpi-card__label { font-size: 0.75rem; color: var(--color-gray-500); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
.kpi-card__value { font-size: 1.5rem; font-weight: 700; margin-top: 0.25rem; }
.kpi-card__value.income { color: var(--color-income); }
.kpi-card__value.expense { color: var(--color-expense); }
.kpi-card__value.reserve { color: var(--color-reserve); }
.kpi-card__comparison { font-size: 0.75rem; color: var(--color-gray-400); margin-top: 0.25rem; }

/* ── DASHBOARD GRID / CARDS ───────────────────── */
.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-bottom: 2rem; }
.card { background: white; border-radius: 12px; padding: 1.5rem; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--color-gray-100); }
.card-title { font-weight: 700; font-size: 1.125rem; }

/* ── CHART ────────────────────────────────────── */
.chart-wrapper { display: flex; flex-direction: column; align-items: center; }
.donut-container { position: relative; width: 240px; height: 240px; margin: 0 auto; }
.donut-chart { width: 100%; height: 100%; transform: rotate(-90deg); }
.donut-center { position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; }
.donut-value { font-size: 1.25rem; font-weight: 700; color: var(--color-gray-900); }
.donut-label { font-size: 0.75rem; color: var(--color-gray-500); text-transform: uppercase; letter-spacing: 0.5px; }
.chart-legend { margin-top: 1.5rem; width: 100%; max-height: 300px; overflow-y: auto; }
.legend-section { margin-bottom: 1rem; }
.legend-section-title { font-size: 0.75rem; font-weight: 700; text-transform: uppercase; color: var(--color-gray-400); margin-bottom: 0.5rem; letter-spacing: 0.5px; }
.legend-item { display: flex; align-items: center; justify-content: space-between; padding: 0.5rem 0; border-bottom: 1px solid var(--color-gray-50); }
.legend-info { display: flex; align-items: center; gap: 0.5rem; }
.legend-icon { width: 20px; text-align: center; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; }
.legend-name { font-size: 0.875rem; color: var(--color-gray-700); }
.legend-percent { font-size: 0.75rem; color: var(--color-gray-400); margin-left: 0.25rem; }
.legend-value { font-weight: 600; font-size: 0.875rem; }

/* ── CATEGORY TREE (DASHBOARD) ────────────────── */
.cat-tree { display: flex; flex-direction: column; gap: 0.5rem; max-height: 340px; overflow-y: auto; }
.cat-tree-type {
  border-radius: 8px;
  border: 1px solid var(--color-gray-100);
  overflow: hidden;
  background: white;
}
.cat-tree-type > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 0.875rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
  border-left: 3px solid transparent;
}
.cat-tree-type > summary::-webkit-details-marker { display: none; }
.cat-tree-type > summary:hover { background: var(--color-gray-50); }
.cat-tree-type.income > summary { border-left-color: var(--color-income); }
.cat-tree-type.expense > summary { border-left-color: var(--color-expense); }
.cat-tree-type.reserve > summary { border-left-color: var(--color-reserve); }
.cat-tree-chevron {
  font-size: 0.75rem;
  color: var(--color-gray-400);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}
details[open] > summary .cat-tree-chevron { transform: rotate(90deg); }
.cat-tree-type__name { font-weight: 700; font-size: 0.8125rem; flex: 1; text-transform: uppercase; letter-spacing: 0.3px; color: var(--color-gray-500); }
.cat-tree-type__total { font-weight: 700; font-size: 0.875rem; }
.cat-tree-body { padding: 0.375rem 0.5rem; background: var(--color-gray-50); display: flex; flex-direction: column; gap: 0.25rem; border-top: 1px solid var(--color-gray-100); }
.category-item { display: flex; justify-content: space-between; align-items: center; padding: 0.75rem 0.875rem; background: white; border-radius: 8px; transition: background 0.2s; border: 1px solid transparent; }
.category-item:hover { background: var(--color-gray-50); border-color: var(--color-gray-100); }
.category-info { display: flex; align-items: center; gap: 0.75rem; }
.category-icon { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 1rem; }
.category-name { font-size: 0.875rem; font-weight: 600; }
.category-count { font-size: 0.75rem; color: var(--color-gray-400); background: var(--color-gray-100); padding: 2px 6px; border-radius: 10px; }
.category-value { font-weight: 700; font-size: 0.9375rem; }

/* ── RECENT HISTORY (DASHBOARD) ───────────────── */
.history-section { margin-top: 2rem; }
.history-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.history-list { display: flex; flex-direction: column; gap: 0.75rem; }
.history-item { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.25rem; background: white; border-radius: 10px; box-shadow: 0 1px 2px rgba(0,0,0,0.05); transition: transform 0.2s, box-shadow 0.2s; }
.history-item:hover { transform: translateY(-2px); box-shadow: 0 4px 6px rgba(0,0,0,0.1); }
.history-main { display: flex; align-items: center; gap: 1rem; flex: 1; }
.history-icon { width: 44px; height: 44px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 1.25rem; flex-shrink: 0; }
.history-details h4 { font-weight: 600; margin-bottom: 0.25rem; color: var(--color-gray-800); }
.history-details p { font-size: 0.8125rem; color: var(--color-gray-500); margin: 0; }
.history-value { font-weight: 700; font-size: 1.125rem; margin-right: 1rem; }
.history-actions { display: flex; gap: 0.5rem; }

/* ── TREE (FULL HISTORY) ──────────────────────── */
.tree { display: flex; flex-direction: column; gap: 0.75rem; }

.tree-type {
  border-radius: 12px;
  border: 1px solid var(--color-gray-200);
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  overflow: hidden;
  background: white;
}
.tree-type > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 1.25rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.tree-type > summary::-webkit-details-marker { display: none; }
.tree-type > summary:hover { background: var(--color-gray-50); }
.tree-type.income > summary { border-left: 4px solid var(--color-income); }
.tree-type.expense > summary { border-left: 4px solid var(--color-expense); }
.tree-type.reserve > summary { border-left: 4px solid var(--color-reserve); }

.tree-chevron {
  font-size: 0.875rem;
  color: var(--color-gray-400);
  transition: transform 0.2s ease;
  flex-shrink: 0;
  line-height: 1;
}
details[open] > summary .tree-chevron { transform: rotate(90deg); }

.tree-type__badge { font-size: 1.25rem; flex-shrink: 0; }
.tree-type__name { font-weight: 700; font-size: 0.9375rem; flex: 1; color: var(--color-gray-800); }
.tree-type__meta { display: flex; align-items: center; gap: 0.625rem; flex-shrink: 0; }
.tree-badge {
  font-size: 0.75rem;
  background: var(--color-gray-100);
  color: var(--color-gray-600);
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 600;
}
.tree-type__total { font-weight: 700; font-size: 0.9375rem; }

.tree-type__body {
  padding: 0.625rem;
  background: var(--color-gray-50);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  border-top: 1px solid var(--color-gray-100);
}

.tree-category {
  border-radius: 8px;
  border: 1px solid var(--color-gray-100);
  background: white;
  overflow: hidden;
}
.tree-category > summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  user-select: none;
  transition: background 0.15s;
}
.tree-category > summary::-webkit-details-marker { display: none; }
.tree-category > summary:hover { background: var(--color-gray-50); }

.tree-cat-icon {
  width: 28px; height: 28px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.875rem; flex-shrink: 0;
}
.tree-category__name { font-weight: 600; font-size: 0.875rem; flex: 1; color: var(--color-gray-700); }
.tree-category__meta { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.tree-category__total { font-weight: 600; font-size: 0.875rem; color: var(--color-gray-600); }
.tree-category__body { border-top: 1px solid var(--color-gray-50); }

.tree-leaf {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-gray-50);
  transition: background 0.15s;
  gap: 0.75rem;
}
.tree-leaf:last-child { border-bottom: none; }
.tree-leaf:hover { background: var(--color-gray-50); }
.tree-leaf__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--color-gray-300); flex-shrink: 0; margin-left: 0.25rem;
}
.tree-leaf__info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 0.15rem; }
.tree-leaf__desc { font-size: 0.875rem; font-weight: 500; color: var(--color-gray-800); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tree-leaf__date { font-size: 0.75rem; color: var(--color-gray-400); }
.tree-leaf__right { display: flex; align-items: center; gap: 0.625rem; flex-shrink: 0; }
.tree-leaf__value { font-weight: 700; font-size: 0.9375rem; white-space: nowrap; }
.tree-leaf__actions { display: flex; gap: 0.25rem; }

/* ── MODAL ────────────────────────────────────── */
.modal-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); z-index: 200; align-items: center; justify-content: center; padding: 1rem; }
.modal-overlay.active { display: flex; }
.modal { background: white; border-radius: 16px; width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1); animation: modalIn 0.3s ease; }
@keyframes modalIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.modal-header { padding: 1.5rem; border-bottom: 1px solid var(--color-gray-100); display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-size: 1.25rem; font-weight: 700; }
.modal-close { width: 32px; height: 32px; border-radius: 8px; display: flex; align-items: center; justify-content: center; color: var(--color-gray-400); background: none; border: none; cursor: pointer; font-size: 1.25rem; }
.modal-close:hover { background: var(--color-gray-100); color: var(--color-gray-600); }
.modal-body { padding: 1.5rem; }
.modal-footer { padding: 1rem 1.5rem; border-top: 1px solid var(--color-gray-100); background: var(--color-gray-50); display: flex; justify-content: flex-end; gap: 0.75rem; border-radius: 0 0 16px 16px; }

/* ── FORM ─────────────────────────────────────── */
.form-group { margin-bottom: 1.25rem; }
.form-label { display: block; font-size: 0.875rem; font-weight: 600; color: var(--color-gray-700); margin-bottom: 0.5rem; }
.form-input, .form-select { width: 100%; padding: 0.75rem 1rem; border: 1px solid var(--color-gray-200); border-radius: 8px; font-size: 0.9375rem; transition: all 0.2s; font-family: inherit; }
.form-input:focus, .form-select:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.1); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.type-selector { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; margin-bottom: 1.5rem; }
.type-option { position: relative; }
.type-option input { position: absolute; opacity: 0; width: 0; height: 0; }
.type-option label { display: flex; flex-direction: column; align-items: center; padding: 1rem 0.5rem; border: 2px solid var(--color-gray-200); border-radius: 10px; cursor: pointer; text-align: center; font-size: 0.8125rem; font-weight: 600; color: var(--color-gray-600); transition: all 0.2s; }
.type-option label:hover { border-color: var(--color-gray-300); }
.type-option input:checked + label { border-color: var(--color-primary); background: #EFF6FF; color: var(--color-primary); }
.type-icon { font-size: 1.5rem; margin-bottom: 0.25rem; }
.checkbox-wrapper { display: flex; align-items: center; gap: 0.75rem; margin-top: 1rem; padding: 1rem; background: var(--color-gray-50); border-radius: 8px; border: 1px solid var(--color-gray-200); }
.checkbox-wrapper input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; accent-color: var(--color-primary); }
.checkbox-wrapper label { font-size: 0.875rem; color: var(--color-gray-700); cursor: pointer; font-weight: 500; }

/* ── TOAST ────────────────────────────────────── */
.toast-container { position: fixed; top: 1rem; right: 1rem; z-index: 300; display: flex; flex-direction: column; gap: 0.5rem; }
.toast { background: white; padding: 1rem 1.25rem; border-radius: 10px; box-shadow: 0 10px 15px rgba(0,0,0,0.1); display: flex; align-items: center; gap: 0.75rem; min-width: 300px; animation: slideIn 0.3s ease; border-left: 4px solid; transition: opacity 0.3s, transform 0.3s; }
.toast.success { border-left-color: var(--color-income); }
.toast.error { border-left-color: var(--color-expense); }
.toast-icon { font-size: 1.25rem; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── MISC ─────────────────────────────────────── */
.empty { text-align: center; padding: 3rem; color: var(--color-gray-400); }
.empty-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; }
.hidden { display: none !important; }

/* ── RESPONSIVE ───────────────────────────────── */
@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: flex; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .content { padding: 1rem; }
}
@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .type-selector { grid-template-columns: 1fr; }
  .history-item { flex-direction: column; align-items: flex-start; gap: 0.75rem; }
  .history-actions { width: 100%; justify-content: flex-end; }
  .month-display { min-width: 100px; font-size: 0.8rem; }
  .page-subtitle { flex-direction: column; align-items: flex-start; }
  .tree-type__total { display: none; }
  .tree-category__total { display: none; }
  .tree-leaf { flex-wrap: wrap; }
  .tree-leaf__right { flex: 0 0 100%; justify-content: space-between; }
}