/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --primary-light: #e0e7ff;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-light: #fee2e2;
  --warning: #f59e0b;
  --warning-light: #fef3c7;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --sidebar-w: 240px;
  --topbar-h: 64px;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,.07), 0 2px 4px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 15px rgba(0,0,0,.08), 0 4px 6px rgba(0,0,0,.05);
}

html { font-size: 16px; }

body {
  font-family: 'Heebo', Arial, sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  direction: rtl;
  min-height: 100vh;
}

/* ===== SCREEN SYSTEM ===== */
.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* ===== AUTH ===== */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 24px;
}

.auth-card {
  background: white;
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}
.auth-logo .logo-icon { font-size: 48px; display: block; margin-bottom: 8px; }
.auth-logo h1 { font-size: 24px; font-weight: 700; color: var(--gray-900); }
.auth-logo p { color: var(--gray-500); font-size: 14px; margin-top: 4px; }

.auth-divider {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 16px 0;
  color: var(--gray-400);
  font-size: 13px;
}
.auth-divider::before, .auth-divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--gray-200);
}

/* ===== APP LAYOUT ===== */
#app-screen {
  display: flex;
  min-height: 100vh;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  background: white;
  border-left: 1px solid var(--gray-200);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  right: 0;
  height: 100vh;
  z-index: 100;
  transition: transform .25s ease;
  box-shadow: var(--shadow);
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 16px;
  border-bottom: 1px solid var(--gray-100);
}
.sidebar-header .logo-icon { font-size: 24px; }
.logo-text { font-weight: 700; font-size: 16px; color: var(--gray-900); flex: 1; }
.sidebar-close { display: none; background: none; border: none; cursor: pointer; font-size: 18px; color: var(--gray-400); }

.nav-menu { list-style: none; padding: 12px 8px; flex: 1; }
.nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--gray-600);
  font-size: 14px;
  font-weight: 500;
  transition: all .15s;
  margin-bottom: 2px;
}
.nav-link:hover { background: var(--gray-100); color: var(--gray-900); }
.nav-link.active { background: var(--primary-light); color: var(--primary); }
.nav-icon { font-size: 18px; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--gray-100);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.user-info { font-size: 13px; color: var(--gray-600); font-weight: 500; }

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

.top-bar {
  position: sticky;
  top: 0;
  height: var(--topbar-h);
  background: white;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  z-index: 50;
  box-shadow: var(--shadow);
}
.hamburger {
  display: none;
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--gray-600);
}
.page-title { font-size: 18px; font-weight: 600; flex: 1; color: var(--gray-900); }
.top-bar-actions { display: flex; align-items: center; gap: 10px; }

#month-selector {
  padding: 6px 10px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  color: var(--gray-700);
  background: white;
  cursor: pointer;
}

/* ===== PAGES ===== */
.page { padding: 24px; flex: 1; }

/* ===== CARDS ===== */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-100);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-100);
}
.card-header h3 { font-size: 15px; font-weight: 600; color: var(--gray-800); }

/* ===== SUMMARY CARDS ===== */
.summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}
.summary-card {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px;
}
.card-icon { font-size: 32px; }
.card-label { font-size: 12px; color: var(--gray-500); font-weight: 500; margin-bottom: 4px; }
.card-value { font-size: 22px; font-weight: 700; }
.summary-card.income .card-value { color: var(--success); }
.summary-card.expenses .card-value { color: var(--danger); }
.summary-card.balance .card-value { color: var(--primary); }
.summary-card.budget-used .card-value { color: var(--warning); }

/* ===== DASHBOARD GRID ===== */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin-bottom: 20px;
}
.chart-wrapper { padding: 20px; height: 260px; display: flex; align-items: center; justify-content: center; }
.chart-wrapper canvas { max-height: 100%; }

/* ===== TRANSACTION LIST ===== */
.transaction-list { }
.transaction-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--gray-100);
  transition: background .1s;
}
.transaction-item:last-child { border-bottom: none; }
.transaction-item:hover { background: var(--gray-50); }

.tx-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
}
.tx-icon.expense { background: var(--danger-light); }
.tx-icon.income { background: var(--success-light); }

.tx-info { flex: 1 }
.tx-title { font-size: 14px; font-weight: 500; color: var(--gray-800); }
.tx-meta { font-size: 12px; color: var(--gray-400); margin-top: 2px; }
.tx-category-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 500;
  margin-right: 6px;
}
.tx-amount { font-size: 15px; font-weight: 600; white-space: nowrap; }
.tx-amount.expense { color: var(--danger); }
.tx-amount.income { color: var(--success); }

.tx-actions { display: flex; gap: 6px; opacity: 0; transition: opacity .15s; }
.transaction-item:hover .tx-actions { opacity: 1; }

/* ===== PAGE TOOLBAR ===== */
.page-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}
.filter-group { display: flex; gap: 8px; flex-wrap: wrap; }
.hint-text { font-size: 14px; color: var(--gray-500); }

/* ===== GLOBAL BUDGET CARD ===== */
.global-budget-card {
  margin-bottom: 20px;
  border: 2px solid var(--primary-light);
  background: linear-gradient(135deg, #fafafa 0%, #f5f3ff 100%);
}
.global-budget-numbers {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 2px;
}

/* ===== BUDGET GRID ===== */
.budget-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 16px; }
.budget-card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--gray-100);
}
.budget-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}
.budget-category { font-size: 15px; font-weight: 600; display: flex; align-items: center; gap: 8px; }
.budget-amounts { display: flex; justify-content: space-between; font-size: 13px; color: var(--gray-500); margin-bottom: 8px; }
.budget-amounts strong { color: var(--gray-800); }

/* Rich budget card */
.budget-card-rich { border-right: 4px solid var(--gray-200); transition: box-shadow .15s; }
.budget-card-rich:hover { box-shadow: 0 4px 16px rgba(0,0,0,.1); }
.budget-card-rich.ok   { border-right-color: var(--success); }
.budget-card-rich.warning { border-right-color: #f59e0b; }
.budget-card-rich.danger  { border-right-color: var(--danger); }

.budget-spent-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  margin-top: 4px;
}
.budget-spent-amount {
  font-size: 28px;
  font-weight: 700;
  color: var(--gray-900);
  line-height: 1;
}
.budget-spent-amount.over-budget { color: var(--danger); }
.budget-of-total {
  font-size: 13px;
  color: var(--gray-400);
}
.budget-footer-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.budget-status-badge {
  font-size: 12px;
  font-weight: 500;
  padding: 3px 8px;
  border-radius: 20px;
  background: var(--gray-100);
  color: var(--gray-600);
}
.budget-status-badge.ok      { background: #d1fae5; color: #065f46; }
.budget-status-badge.warning { background: #fef3c7; color: #92400e; }
.budget-status-badge.danger  { background: #fee2e2; color: #991b1b; }
.budget-pct { font-size: 13px; font-weight: 600; color: var(--gray-400); }

.progress-bar {
  height: 8px;
  background: var(--gray-100);
  border-radius: 99px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: 99px;
  transition: width .4s ease;
  background: var(--success);
}
.progress-fill.warning { background: var(--warning); }
.progress-fill.danger { background: var(--danger); }

/* ===== CATEGORIES LIST ===== */
.categories-list { display: flex; flex-direction: column; gap: 8px; padding: 16px 20px; }
.category-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  background: var(--gray-50);
}
.category-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; }
.category-name { flex: 1; font-size: 14px; font-weight: 500; }
.category-type { font-size: 11px; color: var(--gray-400); }

/* ===== SETTINGS ===== */
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }

/* ===== CATEGORY BREAKDOWN ===== */
.breakdown-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--gray-100);
}
.breakdown-item:last-child { border-bottom: none; }
.breakdown-bar-wrap { flex: 1; }
.breakdown-label { font-size: 13px; font-weight: 500; color: var(--gray-700); margin-bottom: 4px; display: flex; justify-content: space-between; }
.breakdown-bar { height: 6px; background: var(--gray-100); border-radius: 99px; overflow: hidden; }
.breakdown-fill { height: 100%; border-radius: 99px; }
.breakdown-amount { font-size: 14px; font-weight: 600; color: var(--gray-800); white-space: nowrap; min-width: 80px; text-align: left; }

/* ===== FORMS ===== */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--gray-700); margin-bottom: 6px; }
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.flex-1 { flex: 1; }

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--gray-200);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  color: var(--gray-800);
  background: white;
  transition: border-color .15s;
  direction: rtl;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.1);
}
textarea { resize: vertical; min-height: 60px; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: 8px;
  border: none;
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: white; color: var(--gray-700); border: 1.5px solid var(--gray-200); }
.btn-outline:hover { background: var(--gray-50); border-color: var(--gray-300); }
.btn-ghost { background: transparent; color: var(--gray-500); }
.btn-ghost:hover { background: var(--gray-100); color: var(--gray-700); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #dc2626; }
.btn-icon { padding: 6px; border-radius: 6px; font-size: 14px; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-full { width: 100%; }

/* ===== TYPE TOGGLE ===== */
.type-toggle {
  display: flex;
  background: var(--gray-100);
  border-radius: 8px;
  padding: 3px;
  margin-bottom: 20px;
}
.toggle-btn {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  color: var(--gray-500);
  transition: all .15s;
}
.toggle-btn.active { background: white; color: var(--gray-900); box-shadow: var(--shadow); }

/* ===== TOGGLE SWITCH ===== */
.toggle-switch { position: relative; display: inline-block; width: 40px; height: 22px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-track {
  position: absolute; inset: 0; background: var(--gray-200);
  border-radius: 22px; cursor: pointer; transition: background .2s;
}
.toggle-track::before {
  content: ""; position: absolute; width: 16px; height: 16px;
  right: 3px; top: 3px; background: white; border-radius: 50%;
  transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-switch input:checked + .toggle-track { background: var(--primary); }
.toggle-switch input:checked + .toggle-track::before { transform: translateX(-18px); }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
  backdrop-filter: blur(2px);
}
.modal {
  background: white;
  border-radius: 16px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  max-height: 90dvh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-sm { max-width: 360px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--gray-100);
  position: sticky;
  top: 0;
  background: white;
  z-index: 1;
}
.modal-header h3 { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--gray-400); padding: 4px; border-radius: 6px; }
.modal-close:hover { background: var(--gray-100); color: var(--gray-700); }
.modal-body { padding: 20px 24px; }
.modal-footer { display: flex; gap: 10px; justify-content: flex-end; padding: 16px 24px; border-top: 1px solid var(--gray-100); position: sticky; bottom: 0; background: white; z-index: 1; }

/* ===== ALERTS ===== */
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert-error { background: var(--danger-light); color: #b91c1c; border: 1px solid #fca5a5; }
.alert-success { background: var(--success-light); color: #065f46; }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--gray-900);
  color: white;
  padding: 12px 24px;
  border-radius: 99px;
  font-size: 14px;
  font-weight: 500;
  z-index: 999;
  box-shadow: var(--shadow-lg);
  transition: all .3s;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ===== EMPTY STATE ===== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-400);
}
.empty-icon { font-size: 48px; display: block; margin-bottom: 12px; }
.empty-state p { font-size: 15px; margin-bottom: 16px; }

/* ===== LINK ===== */
.link { font-size: 13px; color: var(--primary); text-decoration: none; font-weight: 500; }
.link:hover { text-decoration: underline; }

/* ===== BUDGET STATUS ===== */
#budget-status-list { padding: 8px 0; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .summary-cards { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}

/* ===== BOTTOM NAV (mobile) ===== */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: 64px;
  background: white;
  border-top: 1px solid var(--gray-200);
  z-index: 200;
  box-shadow: 0 -2px 12px rgba(0,0,0,.06);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottom-nav-inner {
  display: flex;
  width: 100%;
  height: 100%;
  align-items: stretch;
  justify-content: space-evenly;
}
.bottom-nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--gray-400);
  font-size: 10px;
  font-family: inherit;
  font-weight: 600;
  padding: 8px 4px;
  transition: color .15s;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav-btn .bn-icon { font-size: 22px; line-height: 1; }
.bottom-nav-btn.active { color: var(--primary); }
.bottom-nav-btn.active .bn-icon { transform: scale(1.1); }

/* ===== FAB (mobile add button) ===== */
.fab {
  display: none;
  position: fixed;
  bottom: 76px;
  left: 20px;
  width: 52px; height: 52px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 50%;
  font-size: 26px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(99,102,241,.4);
  z-index: 190;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
  transition: transform .15s, box-shadow .15s;
}
.fab:active { transform: scale(.93); box-shadow: 0 2px 8px rgba(99,102,241,.3); }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .summary-cards { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  /* sidebar becomes drawer */
  .sidebar { transform: translateX(100%); box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: -4px 0 24px rgba(0,0,0,.15); }
  .sidebar-close { display: block; }
  .hamburger { display: block; }

  /* sidebar overlay */
  .sidebar-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,.35);
    z-index: 99;
  }
  .sidebar-overlay.visible { display: block; }

  /* main */
  .main-content { margin-right: 0; padding-bottom: 64px; }
  .summary-cards { grid-template-columns: 1fr 1fr; gap: 12px; }
  .page { padding: 14px 14px 80px; }
  .top-bar { padding: 0 14px; }
  .top-bar-actions .btn-sm:not(#sync-btn) { display: none; } /* hide desktop + button */

  /* show mobile elements */
  .bottom-nav { display: flex; }
  .fab { display: flex; }

  /* larger touch targets */
  .btn { min-height: 44px; }
  input, select, textarea { font-size: 16px !important; min-height: 44px; } /* prevent iOS zoom */
  .transaction-item { padding: 14px 14px; }
  .tx-actions { opacity: 1; } /* always visible on mobile */

  /* modal full-screen on mobile */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal {
    border-radius: 20px 20px 0 0;
    max-height: 92vh;
    max-height: 92dvh;
    width: 100%;
    max-width: 100%;
  }
  .modal-sm { border-radius: 20px 20px 0 0; }

  /* top bar sync btn text hidden */
  #sync-btn .sync-label { display: none; }
}

@media (max-width: 480px) {
  .summary-cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card-value { font-size: 18px; }
  .form-row { flex-direction: column; }
  .filter-group { flex-direction: column; }
  .filter-group input, .filter-group select { width: 100%; }
  .budget-grid { grid-template-columns: 1fr; }
  .top-bar { height: 56px; }
  .page-title { font-size: 16px; }
}

/* safe area for notch phones */
@supports (padding-top: env(safe-area-inset-top)) {
  .top-bar { padding-top: env(safe-area-inset-top); height: calc(var(--topbar-h) + env(safe-area-inset-top)); }
}
