/* ✅ Android 14+ Safe Area Fix */
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}




/* Light theme */
:root {
  --progress-bg: #f9fafb;        /* light background */
  --progress-border: #d1d5db;    /* visible gray border */
}

/* Dark theme */
[data-theme="dark"] {
  --progress-bg: #0f172a;        /* dark background */
  --progress-border: #334155;    /* subtle dark border */
}


/* Hide app until auth is ready */
body.loading * {
  visibility: hidden;
}

/* …but show the FinCtrl logo and a spinner meanwhile, instead of an empty screen */
body.loading { background: #0f0f1a; }
body.loading::before {
  content: "FC";
  position: fixed;
  left: 50%; top: 42%;
  width: 72px; height: 72px;
  margin: -36px 0 0 -36px;
  border-radius: 20px;
  background: linear-gradient(135deg, #7c3aed, #3b82f6);
  box-shadow: 0 12px 40px rgba(124, 58, 237, 0.35);
  color: #fff;
  font: 800 30px/72px Inter, "Segoe UI", system-ui, sans-serif;
  letter-spacing: -0.02em;
  text-align: center;
  visibility: visible;
  z-index: 9999;
}
body.loading::after {
  content: "";
  position: fixed;
  left: 50%; top: calc(42% + 70px);
  width: 26px; height: 26px;
  margin-left: -13px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: #a78bfa;
  border-radius: 50%;
  animation: fc-spin 0.8s linear infinite;
  z-index: 9999;
}
@keyframes fc-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { body.loading::after { animation-duration: 2.4s; } }


/* FinCtrl — Smart Personal Finance Manager */

/* ===== CSS Variables & Reset ===== */
:root {
  /* Purple-themed Dark Theme (Default) */
  --bg-primary: #0f0f1a; /* Dark black-purple */
  --bg-secondary: #1a1a2e; /* Dark purple-blue */
  --bg-surface: #16213e; /* Dark navy */
  --bg-card: rgba(25, 25, 45, 0.8); /* Dark purple-gray */
  --text-primary: #ffffff; /* White */
  --text-secondary: #d8d8e8; /* Light purple-gray */
  --text-muted: #8a8ab5; /* Muted purple */
  --border-color: #2d2d4a; /* Dark purple */
  --primary-color: #7c3aed; /* Purple */
  --primary-light: rgba(124, 58, 237, 0.15); /* Light purple */
  --secondary-color: #3b82f6; /* Blue */
  --danger-color: #ef4444; /* Red */
  --warning-color: #f59e0b; /* Amber */
  --info-color: #06b6d4; /* Cyan */
  --success-color: #10b981; /* Green */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.4);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --transition: all 0.2s ease;
  --sidebar-width: 280px;
  --topbar-height: 70px;
}

[data-theme="light"] {
  /* Purple-themed Light Theme */
  --bg-primary: #f8f7ff; /* Light purple-white */
  --bg-secondary: #ffffff; /* White */
  --bg-surface: #f0efff; /* Very light purple */
  --bg-card: #ffffff; /* White */
  --text-primary: #1e1b4b; /* Dark purple-blue */
  --text-secondary: #4c4b6e; /* Medium purple-gray */
  --text-muted: #6b7280; /* Gray */
  --border-color: #e5e7eb; /* Light gray */
  --primary-color: #7c3aed; /* Purple */
  --primary-light: rgba(124, 58, 237, 0.1);
  --secondary-color: #3b82f6; /* Blue */
  --shadow-sm: 0 2px 4px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.1);
}

/* Reset & Base */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html {
  font-size: 16px;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  touch-action: pan-y;
}

/* Fix authentication page - ensure sidebar and topbar are hidden */
body.auth-mode {
  overflow: hidden !important;
}

body.auth-mode .sidebar,
body.auth-mode .topbar,
body.auth-mode .swipe-overlay,
body.auth-mode #addExpenseBtn {
  display: none !important;
}

body.auth-mode .content {
  margin-left: 0 !important;
  padding-top: 0 !important;
  min-height: 100vh !important;
}

/* Authentication page styling */
#auth {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden !important;
  z-index: 9999;
  background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.auth-hero {
  height: 100vh;
  width: 100vw;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  overflow: hidden !important;
  position: fixed;
  top: 0;
  left: 0;
}

/* ===== Typography ===== */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.3;
  margin-bottom: 0.5rem;
  color: var(--text-primary);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.75rem; }
h3 { font-size: 1.5rem; }
h4 { font-size: 1.25rem; }

p {
  margin-bottom: 1rem;
  color: var(--text-secondary);
}

.muted {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.small {
  font-size: 0.85rem;
}

.center {
  text-align: center;
}

/* ===== Layout ===== */
.content {
  padding: 2rem;
  margin-left: var(--sidebar-width);
  min-height: calc(100vh - var(--topbar-height));
  transition: margin-left 0.3s ease;
  padding-bottom: env(safe-area-inset-bottom);
}

body.sidebar-collapsed .content {
  margin-left: 0;
}

.frame {
  display: none;
  animation: fadeIn 0.3s ease;
}

.frame.active {
  display: block;
}

.frame-header {
  margin-bottom: 2rem;
}

.frame-header h2 {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.5rem;
}

/* ===== Sidebar ===== */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  width: var(--sidebar-width);
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transform: translateX(0);
  transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

body.sidebar-collapsed .sidebar {
  transform: translateX(-100%);
}

.brand {
  display: flex;
  align-items: center;
  padding: 1.5rem 1.5rem 1rem;
  gap: 1rem;
}

/* New FinCtrl Logo */
.logo {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(135deg, #7c3aed, #3b82f6);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.3);
}

.title {
  font-size: 1.6rem;
  font-weight: 800;
  background: linear-gradient(135deg, #7c3aed, #3b82f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.close-sidebar {
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.25rem;
  display: none;
}

.nav {
  flex: 1;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-align: left;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  min-height: 48px;
}

.nav-item:hover {
  background: var(--primary-light);
  color: var(--primary-color);
  border-color: var(--primary-light);
}

.nav-item.active {
  background: var(--primary-light);
  color: var(--primary-color);
  border-color: var(--primary-color);
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 60%;
  background: var(--primary-color);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

.nav-item i {
  width: 20px;
  font-size: 1.1rem;
}

.sidebar-footer {
  padding: 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  gap: 0.75rem;
  flex-direction: column;
}

/* ===== Topbar ===== */
.topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2rem;
  z-index: 900;
  transition: left 0.3s ease;
  padding-left: 1rem;
  padding-right: 1rem;
}

body.sidebar-collapsed .topbar {
  left: 0;
}

.top-left {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.app-name {
  font-size: 1.4rem;
  font-weight: 700;
  background: linear-gradient(135deg, #7c3aed, #3b82f6);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

/* Hide the three-line menu button COMPLETELY */
#openSidebarBtn {
  display: none !important;
}

.top-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* Hide the "Add Expense" button on specific pages */
#addExpenseBtn {
  display: flex;
}

body.auth-mode #addExpenseBtn,
#auth ~ .topbar #addExpenseBtn,
#onboarding ~ .topbar #addExpenseBtn,
#analytics ~ .topbar #addExpenseBtn,
#tips ~ .topbar #addExpenseBtn,
#report ~ .topbar #addExpenseBtn,
#profile ~ .topbar #addExpenseBtn {
  display: none !important;
}

/* ===== Authentication ===== */
.auth-card {
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  box-shadow: var(--shadow-lg);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.piggy {
  width: 80px;
  height: 80px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, #7c3aed, #3b82f6);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 1.5rem;
  font-size: 2.5rem;
}

.auth-card h2 {
  text-align: center;
  margin-bottom: 0.5rem;
}

.auth-card > .muted {
  text-align: center;
  margin-bottom: 2rem;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 2rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}

.tab {
  flex: 1;
  padding: 0.75rem 1rem;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--text-secondary);
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
  min-height: 48px;
}

.tab:hover {
  color: var(--primary-color);
}

.tab.active {
  color: var(--primary-color);
  border-bottom-color: var(--primary-color);
}

.auth-panels .panel {
  display: none;
}

.auth-panels .panel.active {
  display: block;
  animation: slideIn 0.3s ease;
}

/* ===== Forms ===== */
.form-row {
  margin-bottom: 1.25rem;
  position: relative;
}

.form-row label {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-bottom: 0.5rem;
  color: var(--text-secondary);
  font-weight: 500;
  font-size: 0.9rem;
}

.form-row input,
.form-row select,
.form-row textarea {
  width: 100%;
  padding: 0.875rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: var(--transition);
  -webkit-appearance: none;
  appearance: none;
  min-height: 48px;
}

.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-row input::placeholder {
  color: var(--text-muted);
}

.error-message {
  color: var(--danger-color);
  font-size: 0.85rem;
  margin-top: 0.25rem;
  min-height: 1.25rem;
}

.required {
  color: var(--danger-color);
}

.optional {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: normal;
  margin-left: auto;
}

.full-width {
  grid-column: 1 / -1;
}

/* ===== IMPROVED DATE INPUTS - FIXED CALENDAR ICON ===== */
.date-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.date-input-wrapper input[type="date"] {
  flex: 1;
  padding-right: 2.5rem;
  width: 100%;
  min-height: 48px;
  background: var(--bg-surface);
  /* Ensure the date picker is visible */
  appearance: textfield;
  -webkit-appearance: textfield;
}

.date-input-wrapper .date-icon {
  position: absolute;
  right: 1rem;
  color: var(--text-muted);
  pointer-events: none;
  z-index: 1;
}

/* Modern date picker styling */
input[type="date"] {
  /* This ensures the native calendar picker works */
  position: relative;
}

/* Show calendar icon properly */
input[type="date"]::-webkit-calendar-picker-indicator {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.25rem;
  height: 1.25rem;
  padding: 0.25rem;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0.7;
  transition: var(--transition);
  z-index: 2;
  /* Make sure it's visible */
  display: block !important;
  visibility: visible !important;
  filter: none !important;
}

input[type="date"]::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
  background: var(--primary-light);
}

/* For Firefox and other browsers */
input[type="date"]::-moz-calendar-picker-indicator {
  width: 1.25rem;
  height: 1.25rem;
  padding: 0.25rem;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0.7;
}

/* Better date input styling for all browsers */
input[type="date"] {
  color-scheme: dark; /* This helps with dark theme compatibility */
}

/* Light theme adjustment */
[data-theme="light"] input[type="date"] {
  color-scheme: light;
}

[data-theme="light"] input[type="date"]::-webkit-calendar-picker-indicator {
  filter: brightness(0.7);
}

[data-theme="light"] input[type="date"]::-webkit-calendar-picker-indicator:hover {
  filter: brightness(1);
}

/* Fix for custom date range inputs in reports - SPECIFIC FIX */
#customDateRange .date-range {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}

#customDateRange .date-range span {
  color: var(--text-muted);
  white-space: nowrap;
}

/* Specific fix for custom date range calendar icons */
#customDateRange .date-input-wrapper {
  position: relative;
  flex: 1;
  min-width: 140px;
}

#customDateRange .date-input-wrapper input[type="date"] {
  width: 100%;
  min-height: 48px;
  padding-right: 2.5rem;
  background: var(--bg-surface);
}

#customDateRange .date-input-wrapper .date-icon {
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  z-index: 1;
}

/* Ensure calendar picker indicator is visible in custom date range */
#customDateRange input[type="date"]::-webkit-calendar-picker-indicator {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.25rem;
  height: 1.25rem;
  padding: 0.25rem;
  background: var(--bg-surface);
  border-radius: var(--radius-sm);
  cursor: pointer;
  opacity: 0.7;
  transition: var(--transition);
  z-index: 2;
  display: block !important;
  visibility: visible !important;
  filter: none !important;
}

#customDateRange input[type="date"]::-webkit-calendar-picker-indicator:hover {
  opacity: 1;
  background: var(--primary-light);
}

/* ===== Buttons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.95rem;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  outline: none;
  border: none;
  min-height: 48px;
  -webkit-tap-highlight-color: transparent;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--primary-color);
}

.btn.primary {
  background: var(--primary-color);
  border-color: var(--primary-color);
  color: white;
}

.btn.primary:hover {
  background: #6d28d9;
  border-color: #6d28d9;
}

.btn.secondary {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}

.btn.secondary:hover {
  background: var(--bg-secondary);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.btn.danger {
  background: var(--danger-color);
  border-color: var(--danger-color);
  color: white;
}

.btn.danger:hover {
  background: #dc2626;
  border-color: #dc2626;
}

.btn.full {
  width: 100%;
}

.btn.small {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  min-height: 40px;
}

.icon-btn {
  width: 48px;
  height: 48px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  min-height: 48px;
}

.icon-btn:hover {
  background: var(--primary-light);
  color: var(--primary-color);
  border-color: var(--primary-light);
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary-color);
  cursor: pointer;
  padding: 0;
  font: inherit;
  text-decoration: underline;
}

.form-actions {
  display: flex;
  gap: 1rem;
  margin-top: 1.5rem;
}

/* ===== Enhanced Logout Button ===== */
#logoutBtn {
  background: linear-gradient(135deg, var(--danger-color), #f87171);
  border: none;
  color: white;
  padding: 0.75rem 1.25rem;
  border-radius: var(--radius-md);
  font-weight: 500;
  gap: 0.5rem;
  transition: all 0.3s ease;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
}

#logoutBtn:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  background: linear-gradient(135deg, #dc2626, #ef4444);
}

#logoutBtn:active {
  transform: translateY(0);
}

/* ===== Cards ===== */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  box-shadow: var(--shadow-md);
  transition: var(--transition);
}

.card:hover {
  box-shadow: var(--shadow-lg);
}

.cards {
  display: grid;
  gap: 1.5rem;
}

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

@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }
}

/* ===== Dashboard KPI ===== */
.kpi {
  padding: 1.5rem;
}

.kpi-label {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.kpi-value {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
}

.kpi-value.negative {
  color: var(--danger-color);
}

.kpi-value.positive {
  color: var(--success-color);
}

.kpi-sub {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ===== Dashboard Category Summary ===== */
.category-summary {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 0.5rem;
}

.category-item {
  display: flex;
  flex-direction: column;
  padding: 0.75rem;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  transition: var(--transition);
}

.category-item:hover {
  background: var(--primary-light);
  border-color: var(--primary-light);
}

.category-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.5rem;
}

.category-name {
  font-weight: 500;
  font-size: 0.9rem;
  color: var(--text-primary);
}

.category-amount {
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--primary-color);
}

.category-progress {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.25rem;
}

.category-progress .progress {
  flex: 1;
  height: 6px;
  margin: 0;
  background: var(--border-color);
}

.category-progress .progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #7c3aed, #3b82f6);
  border-radius: 3px;
}

.category-percentage {
  font-size: 0.8rem;
  color: var(--text-muted);
  min-width: 40px;
  text-align: right;
}

/* ===== Recent List ===== */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
}

.recent-list {
  list-style: none;
}

.recent-list li {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr;
  align-items: center;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border-color);
}

.recent-list li:last-child {
  border-bottom: none;
}

.recent-name {
  font-weight: 600;
}

.recent-muted {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.recent-amt {
  text-align: right;
  font-weight: 700;
}

/* ===== Tables ===== */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

th, td {
  padding: 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border-color);
}

th {
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-surface);
}

tr:hover {
  background: var(--primary-light);
}

.category-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  background: var(--primary-light);
  color: var(--primary-color);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
}

.amount-cell {
  font-weight: 600;
}

.action-cell {
  display: flex;
  gap: 0.5rem;
}

/* ===== Modal ===== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 2000;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.modal[aria-hidden="false"] {
  display: flex;
  animation: fadeIn 0.3s ease;
}

.modal-content {
  width: 100%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
  margin: 0;
}

.close-modal {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.25rem;
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== Analytics ===== */
.analytics-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

@media (max-width: 1024px) {
  .analytics-grid {
    grid-template-columns: 1fr;
  }
}

.chart-container {
  position: relative;
  height: 300px;
  margin: 1rem 0;
}

.chart-center-kpi {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}

.center-title {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 0.25rem;
}

.center-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary-color);
}

/* ===== Analytics Period Selectors ===== */
.breakdown-period-selector,
.trend-period-selector {
  display: flex;
  gap: 0.5rem;
  background: var(--bg-surface);
  padding: 0.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

.breakdown-period-tab,
.trend-period-tab {
  padding: 0.5rem 1rem;
  background: none;
  border: none;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  min-height: 40px;
}

.breakdown-period-tab:hover,
.trend-period-tab:hover {
  background: var(--primary-light);
  color: var(--primary-color);
}

.breakdown-period-tab.active,
.trend-period-tab.active {
  background: var(--primary-color);
  color: white;
}

.category-list {
  list-style: none;
  margin-bottom: 1.5rem;
}

.category-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.875rem 0;
  border-bottom: 1px solid var(--border-color);
}

.category-list li:last-child {
  border-bottom: none;
}

.category-list .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 0.75rem;
  display: inline-block;
}

.category-info {
  display: flex;
  align-items: center;
}

.category-details {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.category-percentage {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.insights {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

.insights-text {
  font-size: 0.95rem;
  line-height: 1.6;
}

/* ===== Savings Goals ===== */
.empty-state {
  text-align: center;
  padding: 3rem 2rem;
}

.empty-state i {
  font-size: 3rem;
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.progress {
  width: 100%;
  height: 8px;
  background: var(--border-color);
  border-radius: 4px;
  overflow: hidden;
  margin: 1rem 0;
}

.progress-bar {
  height: 100%;
  background: linear-gradient(90deg, #7c3aed, #3b82f6);
  border-radius: 4px;
  transition: width 0.3s ease;
}

/* Goal Card Styles */
.goal-card {
  transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.goal-card:hover {
  transform: translateY(-5px);
  box-shadow: var(--shadow-lg);
}

.goal-card.overdue {
  border-left: 4px solid var(--danger-color);
  background: rgba(239, 68, 68, 0.05);
}

.goal-card.completed {
  border-left: 4px solid var(--success-color);
  background: rgba(16, 185, 129, 0.05);
}

.goal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.priority-badge {
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  color: white;
}

.goal-progress {
  margin: 1.5rem 0;
}

.progress-info {
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.progress-details {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.goal-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

.goal-actions .btn {
  flex: 1;
}

/* Cancel Edit Button */
#cancelEditBtn {
  margin-top: 0.5rem;
}

/* ===== Professional Report Styles (Dark Theme Compatible) ===== */
.professional-report {
  color: var(--text-primary);
  font-family: 'Inter', sans-serif;
  line-height: 1.6;
}

.professional-report h4 {
  color: var(--primary-color);
  font-size: 1.25rem;
  margin: 1.5rem 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--primary-color);
}

.professional-report h5 {
  color: var(--text-secondary);
  font-size: 1rem;
  margin: 1rem 0 0.75rem;
  font-weight: 600;
}

.professional-report p {
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

/* Report cards and containers */
.report-section {
  margin-bottom: 2rem;
  padding: 1.5rem;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
}

/* Metrics grid */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin: 1.5rem 0;
}

.metric-card {
  background: var(--bg-card);
  padding: 1.5rem;
  border-radius: var(--radius-md);
  text-align: center;
  border: 1px solid var(--border-color);
  transition: var(--transition);
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.metric-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 0.5rem;
}

.metric-label {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* Table styles */
.professional-report table {
  width: 100%;
  border-collapse: collapse;
  margin: 1.5rem 0;
  background: var(--bg-card);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.professional-report thead {
  background: var(--bg-surface);
}

.professional-report th {
  padding: 1rem;
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--primary-color);
}

.professional-report td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
}

.professional-report tr:hover {
  background: var(--primary-light);
}

/* Progress bars */
.progress-container {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin: 0.5rem 0;
}

.progress-bar-bg {
  flex: 1;
  height: 6px;
  background: var(--border-color);
  border-radius: 3px;
  overflow: hidden;
}


.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
  border-radius: 3px;
}

/* Insights box */
.insights-box {
  background: var(--primary-light);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  margin: 1.5rem 0;
}

.insight-item {
  display: flex;
  align-items: flex-start;
  margin-bottom: 0.75rem;
}

.insight-bullet {
  color: var(--primary-color);
  margin-right: 0.75rem;
  flex-shrink: 0;
  font-size: 1.1rem;
}

/* Print-only elements (hidden by default) */
.print-header,
.print-footer {
  display: none !important;
}

/* ===== Split Bill ===== */
.split-container {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}

@media (max-width: 768px) {
  .split-container {
    grid-template-columns: 1fr;
  }
}

.tip-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.tip-controls input[type="range"] {
  flex: 1;
}

.split-result {
  padding: 1.5rem 0;
}

.result-row {
  display: flex;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border-color);
}

.result-row.total {
  font-weight: 700;
  font-size: 1.1rem;
  border-bottom: 2px solid var(--border-color);
}

.result-row.per-person {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--primary-light);
  border-radius: var(--radius-md);
  font-weight: 700;
  font-size: 1.25rem;
}

.quick-tips {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid var(--border-color);
}

.quick-tips ul {
  list-style: none;
  padding-left: 1rem;
}

.quick-tips li {
  margin-bottom: 0.5rem;
  position: relative;
  padding-left: 1.5rem;
}

.quick-tips li:before {
  content: "•";
  color: var(--primary-color);
  position: absolute;
  left: 0;
}

/* Optional field styling */
.optional-field {
  opacity: 0.9;
}

.optional-field:hover {
  opacity: 1;
}

/* ===== Financial Tips ===== */
.tip-categories {
  margin-bottom: 1.5rem;
}

.category-tabs {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.5rem;
  -webkit-overflow-scrolling: touch;
}

.category-tab {
  padding: 0.75rem 1.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
  min-height: 48px;
}

.category-tab:hover {
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.category-tab.active {
  background: var(--primary-light);
  border-color: var(--primary-color);
  color: var(--primary-color);
}

.tip-card {
  height: 100%;
}

.tip-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.tip-number {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
}

.tip-category {
  padding: 0.25rem 0.75rem;
  background: var(--primary-light);
  color: var(--primary-color);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
}

.tip-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
}

/* ===== Reports ===== */
.report-controls {
  margin-bottom: 1.5rem;
}

.date-range {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.date-range input {
  flex: 1;
}

.report-preview {
  min-height: 400px;
}

.report-header {
  text-align: center;
  padding: 2rem 0;
  border-bottom: 1px solid var(--border-color);
}

.report-content {
  padding: 2rem 0;
}

.empty-report {
  text-align: center;
  padding: 3rem 2rem;
  color: var(--text-muted);
}

.empty-report i {
  font-size: 3rem;
  margin-bottom: 1rem;
}

/* Report Summary Styles */
.report-summary {
  padding: 1rem;
}

.summary-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
  margin: 2rem 0;
}

.stat-item {
  text-align: center;
  padding: 1.5rem;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--primary-color);
  margin-bottom: 0.5rem;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.top-categories {
  margin: 2rem 0;
}

.category-item {
  display: flex;
  justify-content: space-between;
  padding: 1rem;
  border-bottom: 1px solid var(--border-color);
}

.category-item:last-child {
  border-bottom: none;
}

.report-total {
  text-align: right;
  padding: 1.5rem;
  background: var(--bg-surface);
  border-radius: var(--radius-md);
  margin-top: 2rem;
  font-size: 1.25rem;
}

/* ===== Settings ===== */
.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.5rem;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  cursor: pointer;
}

.checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary-color);
}

/* ===== Enhanced Danger Zone ===== */
.danger-zone {
  margin-top: 2rem;
  padding: 1.5rem;
  border: 2px solid var(--danger-color);
  border-radius: var(--radius-lg);
  background: rgba(239, 68, 68, 0.05);
  position: relative;
  overflow: hidden;
}

.danger-zone::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 4px;
  background: linear-gradient(90deg, var(--danger-color), #f87171);
}

.danger-zone h4 {
  color: var(--danger-color);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.danger-zone p {
  margin-bottom: 1.5rem;
  font-size: 0.9rem;
}

.danger-actions {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
}

.danger-actions .btn.danger {
  flex: 1;
  min-width: 200px;
  justify-content: center;
}

.data-actions {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

/* ===== Transaction Summary ===== */
.transaction-summary {
  margin-top: 1.5rem;
}

.transaction-summary .grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}

.summary-label {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.summary-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-color);
}

/* ===== Subscription Stats ===== */
.subscription-stats {
  margin: 1.5rem 0;
}

.subscription-stats .grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1.5rem;
}

.stat-label {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 0.5rem;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary-color);
}

/* ===== Toast Notifications ===== */
#toastContainer {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 400px;
}

.toast {
  padding: 1rem 1.25rem;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: slideInRight 0.3s ease;
  max-width: 400px;
}

.toast.success {
  border-left: 4px solid var(--success-color);
}

.toast.error {
  border-left: 4px solid var(--danger-color);
}

.toast.warning {
  border-left: 4px solid var(--warning-color);
}

.toast.info {
  border-left: 4px solid var(--info-color);
}

.toast-icon {
  font-size: 1.25rem;
}

.toast.success .toast-icon {
  color: var(--success-color);
}

.toast.error .toast-icon {
  color: var(--danger-color);
}

.toast.warning .toast-icon {
  color: var(--warning-color);
}

.toast.info .toast-icon {
  color: var(--info-color);
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.toast-message {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.toast-close {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1.25rem;
  padding: 0.25rem;
  margin-left: 0.5rem;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== Swipe Gesture Overlay ===== */
.swipe-overlay {
  position: fixed;
  top: var(--topbar-height);
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 800;
  display: none;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  touch-action: none;
}

body.sidebar-open .swipe-overlay {
  display: block;
  animation: fadeIn 0.3s ease;
}

.swipe-handle {
  position: absolute;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 40px;
  height: 4px;
  background: var(--border-color);
  border-radius: 2px;
}

/* ===== Mobile Touch Improvements ===== */
.touch-action-none {
  touch-action: none;
}

.min-touch-target {
  min-height: 48px;
  min-width: 48px;
}

/* ===== Enhanced Print Styles ===== */
@media print {
  /* Reset everything for print */
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  
  body {
    background: white !important;
    color: black !important;
    font-family: 'Inter', sans-serif !important;
    font-size: 12pt !important;
    line-height: 1.5 !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  /* Hide all UI elements */
  .sidebar,
  .topbar,
  .swipe-overlay,
  #toastContainer,
  .report-controls,
  .btn,
  .frame-header,
  .muted,
  .empty-report,
  .frame:not(#report) {
    display: none !important;
  }
  
  /* Show only the report */
  #report {
    display: block !important;
    position: static !important;
    animation: none !important;
    opacity: 1 !important;
    visibility: visible !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  .content {
    margin: 0 !important;
    padding: 0 !important;
    min-height: auto !important;
    width: 100% !important;
    max-width: none !important;
  }
  
  /* Report styling for print */
  .professional-report {
    color: black !important;
    max-width: 100% !important;
    page-break-inside: avoid !important;
    margin: 0 !important;
    padding: 0 !important;
  }
  
  .professional-report h4 {
    color: #7c3aed !important;
    border-bottom-color: #7c3aed !important;
  }
  
  .professional-report h5 {
    color: #666 !important;
  }
  
  .professional-report p {
    color: #444 !important;
  }
  
  /* Cards and containers for print */
  .report-section {
    background: white !important;
    border: 1px solid #ddd !important;
    border-radius: 8px !important;
    margin-bottom: 1.5rem !important;
    padding: 1.25rem !important;
    break-inside: avoid !important;
    page-break-inside: avoid !important;
  }
  
  /* Tables for print */
  .professional-report table {
    background: white !important;
    border: 1px solid #ddd !important;
    break-inside: avoid !important;
  }
  
  .professional-report th {
    background: #f8f7ff !important;
    color: #666 !important;
    border-bottom-color: #7c3aed !important;
  }
  
  .professional-report td {
    color: #333 !important;
    border-bottom-color: #eee !important;
  }
  
  .professional-report tr:nth-child(even) {
    background: #fafaff !important;
  }
  
  /* Progress bars for print */
  .progress-bar-bg {
    background: #e5e7eb !important;
  }
  
  .progress-bar-fill {
    background: #7c3aed !important;
  }
  
  /* Metrics for print */
  .metric-card {
    background: #f8f7ff !important;
    border: 1px solid #ddd !important;
  }
  
  .metric-value {
    color: #7c3aed !important;
  }
  
  .metric-label {
    color: #666 !important;
  }
  
  /* Remove shadows and transitions */
  .card, .professional-report > div {
    box-shadow: none !important;
    transition: none !important;
    transform: none !important;
  }
  
  /* Print header and footer */
  .print-header {
    display: block !important;
    text-align: center;
    margin-bottom: 2rem !important;
    padding-bottom: 1rem !important;
    border-bottom: 2px solid #333 !important;
    page-break-after: avoid !important;
  }
  
  .print-footer {
    display: block !important;
    text-align: center;
    margin-top: 3rem !important;
    padding-top: 1rem !important;
    border-top: 1px solid #ddd !important;
    font-size: 10pt !important;
    color: #666 !important;
    page-break-before: avoid !important;
  }
  
  /* Ensure proper spacing */
  .professional-report {
    margin: 0 !important;
    padding: 20px !important;
  }
  
  /* Page margins */
  @page {
    margin: 20mm;
  }
  
  /* Page breaks */
  .page-break {
    page-break-before: always !important;
    margin-top: 2rem !important;
  }
}

/* ===== Print Preview Styling ===== */
@media screen {
  .professional-report.print-preview {
    background: white !important;
    color: black !important;
    padding: 2rem !important;
    border: 1px solid var(--border-color) !important;
    border-radius: var(--radius-lg) !important;
    box-shadow: var(--shadow-lg) !important;
  }
  
  .professional-report.print-preview h4 {
    color: #7c3aed !important;
    border-bottom-color: #7c3aed !important;
  }
  
  .professional-report.print-preview p {
    color: #444 !important;
  }
  
  .professional-report.print-preview .report-section {
    background: white !important;
    border: 1px solid #ddd !important;
  }
  
  .professional-report.print-preview table {
    background: white !important;
  }
  
  .professional-report.print-preview th {
    background: #f8f7ff !important;
    color: #666 !important;
  }
  
  .professional-report.print-preview td {
    color: #333 !important;
  }
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(-20px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes slideOutRight {
  from {
    opacity: 1;
    transform: translateX(0);
  }
  to {
    opacity: 0;
    transform: translateX(100%);
  }
}

/* ===== Utility Classes ===== */
.hidden {
  display: none !important;
}

.visible {
  display: block !important;
}

.flex {
  display: flex;
}

.flex-col {
  flex-direction: column;
}

.items-center {
  align-items: center;
}

.justify-between {
  justify-content: space-between;
}

.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }

.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mt-8 { margin-top: 2rem; }

.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-8 { margin-bottom: 2rem; }

/* ===== Responsive Design ===== */
@media (max-width: 1024px) {
  .sidebar {
    width: 280px;
  }
  
  .content {
    margin-left: 0;
    padding-top: calc(var(--topbar-height) + 1rem);
  }
  
  .topbar {
    left: 0;
    width: 100%;
  }
  
  .danger-actions .btn.danger {
    min-width: calc(50% - 0.5rem);
  }
}

@media (max-width: 768px) {
  html {
    font-size: 14px;
  }
  
  .sidebar {
    width: 85%;
    max-width: 320px;
    transform: translateX(-100%);
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
  }
  
  body.sidebar-open .sidebar {
    transform: translateX(0);
  }
  
  .content {
    padding: 1rem;
    padding-top: calc(var(--topbar-height) + 1rem);
    padding-bottom: calc(env(safe-area-inset-bottom) + 1rem);
  }
  
  .topbar {
    left: 0;
    padding: 0 1rem;
    height: 60px;
  }
  
  .close-sidebar {
    display: block;
  }
  
  .brand {
    padding: 1rem;
  }
  
  .nav {
    padding: 0.5rem;
  }
  
  .sidebar-footer {
    flex-direction: row;
    padding: 1rem;
  }
  
  .breakdown-period-selector,
  .trend-period-selector {
    flex-wrap: wrap;
  }
  
  .breakdown-period-tab,
  .trend-period-tab {
    flex: 1;
    min-width: calc(50% - 0.5rem);
    font-size: 0.85rem;
    padding: 0.5rem 0.75rem;
  }
  
  .danger-actions .btn.danger {
    min-width: 100%;
  }
  
  .transaction-summary .grid-3,
  .subscription-stats .grid-3,
  .summary-stats,
  .metrics-grid {
    grid-template-columns: 1fr;
  }
  
  .kpi-value {
    font-size: 1.5rem;
  }
  
  h2 {
    font-size: 1.5rem;
  }
  
  h3 {
    font-size: 1.25rem;
  }
  
  .card {
    padding: 1rem;
  }
  
  .auth-card {
    padding: 1.5rem;
    margin: 1rem;
  }
  
  .piggy {
    width: 60px;
    height: 60px;
    font-size: 2rem;
  }
  
  .form-actions {
    flex-direction: column;
  }
  
  .form-actions .btn {
    width: 100%;
  }
  
  .table-wrap {
    margin: 0 -1rem;
    width: calc(100% + 2rem);
  }
  
  #toastContainer {
    bottom: 1rem;
    right: 1rem;
    left: 1rem;
    max-width: none;
  }
  
  .toast {
    max-width: none;
  }
  
  /* Mobile report adjustments */
  .professional-report .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  /* Custom date range on mobile - UPDATED */
  #customDateRange .date-range {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  
  #customDateRange .date-range span {
    display: none;
  }
  
  #customDateRange .date-range .date-input-wrapper {
    width: 100%;
  }
  
  #customDateRange .date-range input[type="date"] {
    width: 100%;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 13px;
  }
  
  .sidebar {
    width: 90%;
  }
  
  .topbar {
    height: 56px;
  }
  
  .content {
    padding-top: calc(56px + 0.5rem);
  }
  
  .grid-2,
  .grid-3,
  .grid-4 {
    gap: 1rem;
  }
  
  .kpi {
    padding: 1rem;
  }
  
  .kpi-value {
    font-size: 1.4rem;
  }
  
  /* Mobile report adjustments */
  .professional-report .metrics-grid {
    grid-template-columns: 1fr;
  }
  
  .report-section {
    padding: 1rem;
  }
}

.menu-btn {
    display: none;
}


/* Hide menu button on desktop */
.menu-btn {
    display: none;
}

/* ===== Mobile Sidebar Toggle ===== */
@media (max-width: 768px) {

  /* Sidebar - must be on top and clickable */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    min-height: 100dvh;
height: auto;

    width: 260px;
    background: #0f172a;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 9999;
    pointer-events: auto;
  }

  /* Show sidebar when active */
  .sidebar.active {
    transform: translateX(0);
  }

  /* Content should take full width */
  .main-content {
    margin-left: 0 !important;
  }

  /* Menu button visible only on mobile */
  .menu-btn {
    display: block;
    background: none;
    border: none;
    font-size: 22px;
    cursor: pointer;
    color: white;
    z-index: 10000;
    position: relative;
  }

  /* 🔥 FIX: Make close (X) button clickable */
  #closeSidebarBtn {
    position: absolute;
    top: 15px;
    right: 15px;
    z-index: 10001;
    pointer-events: auto;
    cursor: pointer;
  }
}

 /* ==== Mobile Sidebar Overlay ==== */
@media (max-width: 768px) {

  #sidebarOverlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    z-index: 900;
    pointer-events: none;   /* 🔥 BLOCK CLICKS ONLY WHEN HIDDEN */
  }

  /* When menu is open */
  #sidebarOverlay.active {
    display: block;
    pointer-events: auto;   /* ✅ ALLOW CLICKS ON OVERLAY */
  }

  .sidebar {
    z-index: 9999;
  }

  /* You said you don't want the close button anymore */
  #closeSidebarBtn {
    display: none;          /* ✅ Hide cross button */
  }
}



/* Budget Progress Bar */
.budget-progress-container {
  margin-top: 1rem;
}

.budget-progress-bar {
  width: 100%;
  height: 12px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  overflow: hidden;
}

.budget-progress-fill {
  height: 100%;
  width: 0%;
  background: #10b981; /* green */
  border-radius: 999px;
  transition: width 0.4s ease, background 0.4s ease;
}

.budget-warning {
  margin-top: 0.5rem;
  color: #ef4444;
  font-weight: 600;
  display: none;
}

/* ============================= */
/* Mobile Analytics Chart Fix   */
/* ============================= */

.chart-container {
  position: relative;
  height: 320px;
}

@media (max-width: 768px) {
  .chart-container {
    height: 260px;
    padding: 0.5rem;
    overflow: visible;
  }

  canvas {
    max-width: 100% !important;
    height: 100% !important;
  }

  /* Stack analytics cards on mobile */
  .analytics-grid,
  .cards-grid-2 {
    grid-template-columns: 1fr !important;
    gap: 1rem;
  }
}

/* ============================= */
/* Category Chart Mobile Fix */
/* ============================= */

.chart-container {
  position: relative;
  width: 100%;
  height: 340px;   /* Desktop height */
}

/* Center text inside doughnut */
.chart-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  pointer-events: none;
}

/* 📱 Mobile fixes */
@media (max-width: 768px) {
  .chart-container {
    height: 460px !important;   /* 🔥 Extra space for legend */
    padding-bottom: 1.5rem;
    overflow: visible !important;
  }

  #categoryChart {
    width: 100% !important;
    height: 100% !important;
  }

  /* Prevent legend from overlapping the chart */
  canvas {
    margin-bottom: 1.2rem;
  }

  .chart-center {
    top: 45%;   /* Slightly move text up on mobile */
  }
}

/* ===== Mobile Sidebar Slide ===== */
@media (max-width: 768px) {

  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100%;
    width: 260px;
    transition: transform 0.3s ease, background 0.3s ease, color 0.3s ease;
    z-index: 1000;
  }

  /* 🌙 Dark Mode */
  html[data-theme="dark"] .sidebar {
    background: #0f172a !important;
    color: #ffffff !important;
  }

  html[data-theme="dark"] .sidebar .menu-item {
    color: #e5e7eb;
  }

  html[data-theme="dark"] .sidebar .menu-item.active {
    background: rgba(255,255,255,0.08);
  }

  /* ☀️ Light Mode */
  html[data-theme="light"] .sidebar {
    background: #f8fafc !important;
    color: #0f172a !important;
  }

  html[data-theme="light"] .sidebar .menu-item {
    color: #1f2937;
  }

  html[data-theme="light"] .sidebar .menu-item.active {
    background: rgba(0,0,0,0.06);
  }

  .sidebar.closed {
    transform: translateX(-100%);
    pointer-events: none;
  }

  .sidebar.open {
    transform: translateX(0);
    pointer-events: auto;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
/* ============================= */
/* Budget Progress Bar Styling */
/* ============================= */

.budget-progress-container {
  width: 100%;
  height: 6px;
  background: #f3f4f6;        /* Light grey background */
  border: 1px solid #d1d5db;  /* Visible border in white theme */
  border-radius: 4px;
  overflow: hidden;
}

.budget-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--primary-color), var(--secondary-color));
  border-radius: 4px;
  transition: width 0.3s ease;
}
/* Dark theme override */
[data-theme="dark"] .budget-progress-container {
  background: #0f172a;
  border-color: #334155;
}

#logoutBtn {
    pointer-events: auto !important;
    z-index: 9999;
}
/* 🔧 WebView Fix: Ensure logout button receives touch */
#logoutBtn {
    pointer-events: auto !important;
    position: relative !important;
    z-index: 999999 !important;
}

/* 🔧 Prevent invisible layers from blocking taps */
.sidebar,
.drawer,
.menu,
.nav,
.overlay,
.backdrop {
    pointer-events: auto !important;
}
/* 🔥 FIX: Allow logout button to receive taps in Android WebView */
#logoutBtn {
  position: relative;
  z-index: 99999;
  pointer-events: auto !important;
}

/* Prevent invisible overlays from blocking taps */
.swipe-overlay,
#sidebarOverlay {
  pointer-events: none;
}

/* When sidebar is open, only overlay blocks background, not buttons */
body.sidebar-open #sidebarOverlay {
  pointer-events: auto;
}


/* Ensure logout is always clickable and not covered by hidden sidebars */
#logoutBtn {
    cursor: pointer !important;
    pointer-events: auto !important;
    position: relative !important;
    z-index: 999999 !important;
    -webkit-tap-highlight-color: transparent; /* Removes the grey box on mobile tap */
}


/* 🔧 Ensure logout button is ALWAYS on top and reachable */
#logoutBtn {
    position: relative !important;
    z-index: 1000001 !important; /* Higher than any overlay */
    pointer-events: auto !important;
    touch-action: manipulation; /* Optimizes for mobile taps */
}

/* 🔧 Ensure overlays don't block clicks when they are inactive */
#sidebarOverlay:not(.active), 
.swipe-overlay {
    pointer-events: none !important; /* Allow clicks to pass through to buttons */
}

/* Ensure the container doesn't clip the button's touch area */
.sidebar-footer {
    overflow: visible !important;
}

/* ANDROID WEBVIEW FIX — SAFE */
html, body {
  height: auto !important;
  min-height: 100%;
  overflow-y: auto;
}

/* Replace 100vh issue on Android 14+ */
body,
#app,
.app,
.main,
.container {
  min-height: 100dvh;
}









.auth-footer {
  position: fixed;
  bottom: 12px;
  left: 0;
  width: 100%;
  text-align: center;
  font-size: 13px;
  z-index: 9999;

  /* force visibility */
  display: block !important;
  visibility: visible !important;
}

.auth-footer a {
  color: #b9a7ff;
  text-decoration: none;
  margin: 0 6px;
  opacity: 0.85;
}

.auth-footer a:hover {
  opacity: 1;
  text-decoration: underline;
}

/* ===== Custom categories (Settings) ===== */
.category-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.category-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 6px 12px;
  border-radius: 999px;
  background: var(--primary-light);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  font-size: 0.9rem;
}

.chip-remove {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.chip-remove:hover { color: var(--danger-color); background: rgba(239, 68, 68, 0.12); }




/* ===== Income, category budgets, CSV import (features.js) ===== */
.entry-type-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 1.25rem;
  border-radius: var(--radius-md);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
}

.entry-type {
  border: 0;
  border-radius: calc(var(--radius-md) - 4px);
  padding: 10px 12px;
  background: transparent;
  color: var(--text-secondary);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.entry-type[data-entry-type="expense"].active { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.entry-type[data-entry-type="income"].active { background: rgba(16, 185, 129, 0.15); color: var(--success-color); }

.income-kpis {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.income-kpis[hidden] { display: none; }

@media (max-width: 640px) {
  .income-kpis { grid-template-columns: minmax(0, 1fr); }
}

.income-cta {
  grid-column: 1 / -1;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-weight: 600;
}

.income-cta[hidden] { display: none; }

.kpi-value.positive, .summary-value.positive { color: var(--success-color); }
.kpi-value.negative { color: var(--danger-color); }

.amount-cell.income,
.recent-amt.income { color: var(--success-color); }

.category-badge.income {
  background: rgba(16, 185, 129, 0.15);
  color: var(--success-color);
}

.category-budget-list {
  display: grid;
  gap: 8px;
  margin: 12px 0 16px;
  max-height: 360px;
  overflow-y: auto;
  padding-right: 4px;
}

.category-budget-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.95rem;
}

.category-budget-input {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 150px;
  flex: none;
}

.category-budget-input input { width: 100%; }

.import-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.import-dialog {
  width: 100%;
  max-width: 760px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.import-dialog h3 { margin: 0; }

.import-table {
  overflow: auto;
  max-height: 45vh;
}

.import-table table { font-size: 0.85rem; }
.import-table td:nth-child(2) { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Top-bar "Add Transaction" button: shorter label on small phones */
#addExpenseBtn .label-short { display: none; }
@media (max-width: 420px) {
  #addExpenseBtn .label-long { display: none; }
  #addExpenseBtn .label-short { display: inline; }
}
