/* ============================================================
   BudgetFlow – Global Stylesheet
   ============================================================ */

/* ── Theme tokens ─────────────────────────────────────────── */
/* Each theme overrides --primary, --primary-dark, --primary-light,
   --primary-rgb, --sidebar-bg, --sidebar-accent               */

/* Default: Blue */
:root {
  --primary:        #2563eb;
  --primary-dark:   #1d4ed8;
  --primary-light:  #dbeafe;
  --primary-rgb:    37,99,235;
  --sidebar-bg:     #1e293b;
  --sidebar-accent: rgba(37,99,235,.35);
}

/* Green */
[data-theme="green"] {
  --primary:        #059669;
  --primary-dark:   #047857;
  --primary-light:  #d1fae5;
  --primary-rgb:    5,150,105;
  --sidebar-bg:     #064e3b;
  --sidebar-accent: rgba(5,150,105,.4);
}

/* Purple */
[data-theme="purple"] {
  --primary:        #7c3aed;
  --primary-dark:   #6d28d9;
  --primary-light:  #ede9fe;
  --primary-rgb:    124,58,237;
  --sidebar-bg:     #2e1065;
  --sidebar-accent: rgba(124,58,237,.4);
}

/* Rose */
[data-theme="rose"] {
  --primary:        #e11d48;
  --primary-dark:   #be123c;
  --primary-light:  #ffe4e6;
  --primary-rgb:    225,29,72;
  --sidebar-bg:     #4c0519;
  --sidebar-accent: rgba(225,29,72,.4);
}

/* Orange */
[data-theme="orange"] {
  --primary:        #ea580c;
  --primary-dark:   #c2410c;
  --primary-light:  #ffedd5;
  --primary-rgb:    234,88,12;
  --sidebar-bg:     #431407;
  --sidebar-accent: rgba(234,88,12,.4);
}

/* Teal */
[data-theme="teal"] {
  --primary:        #0891b2;
  --primary-dark:   #0e7490;
  --primary-light:  #cffafe;
  --primary-rgb:    8,145,178;
  --sidebar-bg:     #083344;
  --sidebar-accent: rgba(8,145,178,.4);
}

/* Light (white / minimal) */
[data-theme="light"] {
  --primary:        #2563eb;
  --primary-dark:   #1d4ed8;
  --primary-light:  #dbeafe;
  --primary-rgb:    37,99,235;
  --sidebar-bg:     #ffffff;
  --sidebar-accent: rgba(37,99,235,.1);
}

/* Light theme: sidebar is white so text must be dark */
[data-theme="light"] .app-sidebar {
  border-right: 1px solid #e2e8f0;
}
[data-theme="light"] .sidebar-nav-link {
  color: #334155 !important;
}
[data-theme="light"] .sidebar-nav-link:hover {
  background: rgba(var(--primary-rgb),0.08) !important;
  color: var(--primary) !important;
}
[data-theme="light"] .sidebar-nav-link.active {
  color: var(--primary) !important;
}
[data-theme="light"] .sidebar-divider { border-color: #e2e8f0; }
[data-theme="light"] .sidebar-plan-badge,
[data-theme="light"] .badge-free { color: #64748b; background: #f1f5f9; }
[data-theme="light"] .sidebar-logout { color: rgba(239,68,68,.7) !important; }
[data-theme="light"] .brand-name,
[data-theme="light"] .sidebar-user-name { color: #1e293b !important; }
[data-theme="light"] .sidebar-upgrade { background: rgba(var(--primary-rgb),0.06); }

:root {
  --success:    #10b981;
  --danger:     #ef4444;
  --warning:    #f59e0b;
  --info:       #06b6d4;
  --purple:     #7c3aed;
  --gray-50:    #f8fafc;
  --gray-100:   #f1f5f9;
  --gray-200:   #e2e8f0;
  --gray-500:   #64748b;
  --gray-700:   #334155;
  --gray-900:   #0f172a;

  --sidebar-w:  260px;
  --radius:     12px;
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.07), 0 1px 2px rgba(0,0,0,0.05);
  --shadow:     0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
  --shadow-lg:  0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

/* ── Base ────────────────────────────────────────────────── */
* { box-sizing: border-box; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 0.9375rem;
  color: var(--gray-700);
  background: var(--gray-100);
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: #fff;
  border-right: 1px solid var(--gray-200);
  z-index: 1040;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 0.3s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
  text-decoration: none;
}
.sidebar-logo {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--primary), var(--success));
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar-brand-name {
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--gray-900);
}

.sidebar-user {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--gray-200);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
.sidebar-avatar {
  width: 38px; height: 38px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  flex-shrink: 0;
}
.sidebar-user-name  { font-weight: 600; font-size: 0.875rem; color: var(--gray-900); }
.sidebar-user-plan  { font-size: 0.75rem; }

.sidebar-nav { padding: 0.75rem 1rem; flex: 1; }

.sidebar-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gray-500);
  padding: 0.75rem 0.5rem 0.25rem;
}

.sidebar-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  color: var(--gray-700);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
  position: relative;
  margin-bottom: 2px;
}
.sidebar-link:hover { background: var(--gray-100); color: var(--primary); }
.sidebar-link.active { background: #eff6ff; color: var(--primary); font-weight: 600; }
.sidebar-link .sidebar-icon { width: 18px; text-align: center; }
.sidebar-link .lock-icon { margin-left: auto; font-size: 0.7rem; color: var(--gray-500); }
.sidebar-link .badge-count {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  border-radius: 20px;
  padding: 0 6px;
  font-size: 0.7rem;
  min-width: 18px;
  text-align: center;
}

.sidebar-upgrade {
  margin: 1rem;
  padding: 1rem;
  background: linear-gradient(135deg, #eff6ff, #f0fdf4);
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  text-align: center;
}
.sidebar-upgrade h6 { font-size: 0.8rem; font-weight: 700; color: var(--gray-900); margin-bottom: 0.5rem; }
.sidebar-upgrade p  { font-size: 0.75rem; color: var(--gray-500); margin-bottom: 0.75rem; }

.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--gray-200);
}

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

/* ── Top bar ─────────────────────────────────────────────── */
.top-bar {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  padding: 0 1.5rem;
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 1030;
}

/* ── Cards ───────────────────────────────────────────────── */
.card {
  border-radius: var(--radius);
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-sm);
}
.card-header { border-radius: var(--radius) var(--radius) 0 0 !important; }

/* KPI cards */
.kpi-card { transition: transform 0.15s; }
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow) !important; }

/* Wallet cards */
.wallet-card { border-left-width: 4px !important; border-left-style: solid !important; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn { border-radius: 8px; font-weight: 500; transition: all 0.15s; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-color: transparent;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(var(--primary-rgb),0.35); border-color: transparent; }

/* ── Forms ───────────────────────────────────────────────── */
.form-control, .form-select {
  border-radius: 8px;
  border-color: var(--gray-200);
  font-size: 0.9rem;
  padding: 0.55rem 0.875rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(var(--primary-rgb),0.1);
}

/* ── Tables ──────────────────────────────────────────────── */
.table th {
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--gray-500);
  border-bottom-width: 1px;
  padding: 0.75rem 1rem;
}
.table td { padding: 0.875rem 1rem; vertical-align: middle; }
.table-hover tbody tr:hover { background: rgba(var(--primary-rgb),0.025); }

/* ── Progress bars ───────────────────────────────────────── */
.progress { background: var(--gray-200); border-radius: 20px; }
.progress-bar { border-radius: 20px; transition: width 0.6s ease; }

/* ── Badges ──────────────────────────────────────────────── */
.badge { font-weight: 500; letter-spacing: 0.02em; }
.bg-purple { background-color: var(--purple) !important; }

/* ── Alerts ──────────────────────────────────────────────── */
.alert {
  border-radius: var(--radius);
  border: none;
  box-shadow: var(--shadow-sm);
}

/* ── Modals ──────────────────────────────────────────────── */
.modal-content {
  border-radius: 16px;
  border: none;
}
.modal-backdrop.show { opacity: 0.4; }

/* ── Pagination ──────────────────────────────────────────── */
.pagination .page-link {
  border-radius: 6px !important;
  font-size: 0.85rem;
  color: var(--primary);
  border-color: var(--gray-200);
}
.pagination .page-item.active .page-link {
  background: var(--primary);
  border-color: var(--primary);
}

/* ── Dropdown ────────────────────────────────────────────── */
.dropdown-menu {
  border-radius: 10px;
  border: 1px solid var(--gray-200);
  box-shadow: var(--shadow-lg);
  font-size: 0.875rem;
}
.dropdown-item { padding: 0.5rem 1rem; border-radius: 6px; }
.dropdown-item:hover { background: var(--gray-100); }

/* ── Dark mode ───────────────────────────────────────────── */
body.dark-mode {
  --gray-50: #111827;
  --gray-100: #1f2937;
  --gray-200: #374151;
  --gray-500: #9ca3af;
  --gray-700: #e5e7eb;
  --gray-900: #f9fafb;
  background: #111827;
  color: #e5e7eb;
}
body.dark-mode .card,
body.dark-mode .sidebar,
body.dark-mode .top-bar { background: #1f2937; border-color: #374151; }
body.dark-mode .table-light { background: #1f2937; }
body.dark-mode .form-control,
body.dark-mode .form-select { background: #111827; color: #e5e7eb; border-color: #374151; }
body.dark-mode .dropdown-menu { background: #1f2937; border-color: #374151; }
body.dark-mode .dropdown-item:hover { background: #374151; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 991.98px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.show {
    transform: translateX(0);
    box-shadow: var(--shadow-lg);
  }
  .main-wrapper {
    margin-left: 0;
  }
  .top-bar .hamburger-btn { display: flex !important; }
}

/* ── Animations ──────────────────────────────────────────── */
@keyframes fadeInUp {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
.fade-in-up { animation: fadeInUp 0.35s ease both; }

@keyframes countUp {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Print styles ────────────────────────────────────────── */
@media print {
  .sidebar, .top-bar, .btn, .modal, nav { display: none !important; }
  .main-wrapper { margin-left: 0 !important; }
  .card { box-shadow: none !important; border: 1px solid #ddd !important; }
}

/* ── Utility helpers ─────────────────────────────────────── */
.text-purple  { color: var(--purple) !important; }
.bg-gradient-primary { background: linear-gradient(135deg, var(--primary), var(--success)); }
.cursor-pointer { cursor: pointer; }
.hover-shadow:hover { box-shadow: var(--shadow) !important; transition: box-shadow 0.2s; }
.border-primary-soft { border: 1.5px solid rgba(var(--primary-rgb),0.3); }

/* ============================================================
   App Sidebar (dark theme) — matches sidebar.php HTML structure
   ============================================================ */
.app-sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--sidebar-bg);
  z-index: 1040;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
  transition: transform 0.3s ease;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,0.1) transparent;
}

/* ── Overlay (mobile) ─────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 1039;
  cursor: pointer;
}
.sidebar-overlay.show { display: block; }
body.sidebar-is-open  { overflow: hidden; }

/* ── Plan badges ──────────────────────────────────────────── */
.sidebar-plan-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.badge-free    { background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.65); }
.badge-premium { background: rgba(245,158,11,0.25);  color: #fbbf24; }
.badge-family  { background: rgba(124,58,237,0.25);  color: #a78bfa; }

/* ── Sidebar nav links ────────────────────────────────────── */
.sidebar-nav-link {
  color: rgba(255,255,255,0.65) !important;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.15s, color 0.15s;
}
.sidebar-nav-link:hover {
  background: rgba(255,255,255,0.07) !important;
  color: #fff !important;
}
.sidebar-nav-link.active {
  background: var(--sidebar-accent) !important;
  color: #fff !important;
  font-weight: 600;
}
.sidebar-nav-link.locked { opacity: 0.55; }
.sidebar-ai-link { background: rgba(99,102,241,.15) !important; }
.sidebar-ai-link:hover { background: rgba(99,102,241,.28) !important; }
.sidebar-ai-link .nav-icon { color: #a5b4fc !important; }
.sidebar-ai-link .nav-label { color: #c4b5fd !important; font-weight: 600; }
.sidebar-gm-link { background: rgba(245,158,11,.12) !important; }
.sidebar-gm-link:hover { background: rgba(245,158,11,.22) !important; }
.sidebar-gm-link .nav-icon { color: #fcd34d !important; }
.sidebar-gm-link .nav-label { color: #fde68a !important; font-weight: 600; }
.sidebar-logout { color: rgba(239,68,68,0.75) !important; }
.sidebar-logout:hover {
  background: rgba(239,68,68,0.12) !important;
  color: #ef4444 !important;
}

/* ── Sidebar upgrade banner ───────────────────────────────── */
.sidebar-upgrade {
  background: linear-gradient(135deg, rgba(37,99,235,0.25), rgba(16,185,129,0.15)) !important;
  border: 1px solid rgba(255,255,255,0.08) !important;
}

/* ── Main content area ────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--gray-100);
}

/* ── Topbar ───────────────────────────────────────────────── */
.topbar {
  background: #fff;
  border-bottom: 1px solid var(--gray-200);
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 1030;
}
.topbar-title { font-size: 1rem; color: var(--gray-900); }

/* ── Flash container ──────────────────────────────────────── */
.flash-container .alert { margin-bottom: 0; }

/* ── Page content ─────────────────────────────────────────── */
.page-content { flex: 1; }

/* ── Mobile responsive ────────────────────────────────────── */
@media (max-width: 991.98px) {
  .app-sidebar {
    transform: translateX(-100%);
  }
  .app-sidebar.sidebar-open {
    transform: translateX(0);
    box-shadow: 4px 0 24px rgba(0,0,0,0.25);
  }
  .main-content {
    margin-left: 0;
  }
}

/* ── Dark mode additions ──────────────────────────────────── */
body.dark-mode .topbar              { background: #1f2937; border-color: #374151; }
body.dark-mode .topbar-title        { color: #f9fafb; }
body.dark-mode .topbar .btn-outline-secondary { color: #9ca3af; border-color: #374151; }
body.dark-mode .main-content        { background: #111827; }
body.dark-mode .page-content .text-dark { color: #f9fafb !important; }
