@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ============ ROOT VARIABLES (Premium SaaS UI) ============ */
:root {
  --primary: #0EA5E9; 
  --primary-dark: #0284C7; 
  --primary-light: #38BDF8; 
  --secondary: #6366F1; 
  --danger: #EF4444; 
  --success: #10B981; 
  --warning: #F59E0B; 
  
  --bg-primary: #FFFFFF; 
  --bg-secondary: #F8FAFC; 
  --bg-tertiary: #F1F5F9; 
  --glass-bg: rgba(255, 255, 255, 0.85);
  
  --text-primary: #0F172A; 
  --text-secondary: #475569; 
  --text-tertiary: #94A3B8; 
  
  --border-color: #E2E8F0; 
  --border-light: #F1F5F9;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05), 0 2px 4px -1px rgba(0, 0, 0, 0.03);
  --shadow-lg: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.1);
  --shadow-hover: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
  
  --border-radius-sm: 0.5rem; 
  --border-radius: 0.75rem; 
  --border-radius-lg: 1rem; 
  
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  background-color: var(--bg-secondary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* ============ OFFLINE BANNER ============ */
.offline-banner {
  display: none; background: var(--warning); color: white; text-align: center;
  padding: 0.5rem 1rem; font-size: 0.85rem; font-weight: 600; position: sticky;
  top: 0; z-index: 3000; box-shadow: var(--shadow-sm); animation: slideDown 0.3s ease;
}
.offline-banner.active { display: flex; align-items: center; justify-content: center; gap: 0.5rem; }
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* ============ AUTH PAGE ============ */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: linear-gradient(135deg, var(--bg-secondary) 0%, #E0F2FE 100%);
}

.auth-wrapper {
  width: 100%;
  max-width: 1000px;
  min-height: 600px;
  display: flex;
  background: var(--bg-primary);
  border-radius: var(--border-radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: slideUp 0.5s ease-out;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.auth-branding {
  width: 45%;
  background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
  color: white;
  padding: 3rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.auth-branding .icon { width: 60px; height: 60px; margin-bottom: 1.5rem; }
.auth-branding h1 { font-size: 2.5rem; font-weight: 700; line-height: 1.2; }
.auth-branding p { font-size: 1.1rem; opacity: 0.9; margin-top: 1rem; line-height: 1.6; }
.auth-branding-footer p { font-size: 0.9rem; opacity: 0.8; }

.auth-container {
  width: 55%;
  padding: 3rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  overflow-y: auto;
}

.auth-header { text-align: left; margin-bottom: 2rem; }
.auth-header-icon { display: none; color: var(--primary); margin-bottom: 0.5rem; }
.auth-header h1 { font-size: 1.75rem; color: var(--text-primary); margin-bottom: 0.5rem; font-weight: 700; letter-spacing: -0.025em; }
.auth-header p { color: var(--text-secondary); font-size: 1rem; }
.auth-header p.sub-p { font-size: 0.9rem; color: var(--text-tertiary); margin-top: 0.75rem; }

.auth-form { display: none; animation: fadeIn 0.3s ease-in; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.auth-form.active { display: block; }
.auth-form h2 { font-size: 1.5rem; margin-bottom: 1.5rem; color: var(--text-primary); font-weight: 600; letter-spacing: -0.025em; }

.form-group-extra { display: flex; justify-content: flex-end; margin-bottom: 1.25rem; margin-top: -0.5rem; }
.forgot-password-link { font-size: 0.9rem; color: var(--primary); text-decoration: none; font-weight: 500; transition: var(--transition); }
.forgot-password-link:hover { color: var(--primary-dark); }

.auth-divider { display: flex; align-items: center; margin: 1.5rem 0; color: var(--text-tertiary); }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: var(--border-color); }
.auth-divider span { padding: 0 1rem; font-size: 0.85rem; font-weight: 500; }

.auth-switch { text-align: center; margin-top: 1.5rem; font-size: 0.9rem; color: var(--text-secondary); }
.auth-switch a { color: var(--primary); text-decoration: none; font-weight: 600; cursor: pointer; transition: var(--transition); }
.auth-switch a:hover { color: var(--primary-dark); }

.error-message, .success-message {
  padding: 1rem; border-radius: var(--border-radius-sm); margin-top: 1.5rem; display: none; animation: slideDown 0.3s ease; font-weight: 500;
}
.error-message { background: rgba(239, 68, 68, 0.1); color: var(--danger); border-left: 4px solid var(--danger); }
.success-message { background: rgba(16, 185, 129, 0.1); color: var(--success); border-left: 4px solid var(--success); }

.page-footer { text-align: center; padding: 1.5rem; color: var(--text-tertiary); font-size: 0.9rem; width: 100%; }
.auth-page .page-footer { padding: 1.5rem 0 0 0; }

/* ============ BUTTONS ============ */
.btn {
  padding: 0.85rem 1.25rem; border: 1px solid transparent; border-radius: var(--border-radius-sm);
  font-size: 0.95rem; font-weight: 600; cursor: pointer; transition: var(--transition);
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem; white-space: normal; line-height: 1.25;
  text-align: center;
}
.btn:focus-visible { outline: 2px solid var(--primary-dark); outline-offset: 2px; }
.btn-primary { background: var(--primary); color: white; margin-top: 0.75rem; box-shadow: 0 1px 3px rgba(14, 165, 233, 0.4); }
.btn-primary:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 6px rgba(14, 165, 233, 0.3); }
.btn-primary:active { transform: translateY(0); box-shadow: 0 1px 2px rgba(14, 165, 233, 0.4); }
.btn-secondary { background: var(--bg-primary); color: var(--text-primary); border-color: var(--border-color); box-shadow: var(--shadow-sm); }
.btn-secondary:hover { background: var(--bg-tertiary); border-color: #CBD5E1; }
.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #D97706; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #DC2626; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #059669; }
.btn-google { width: 100%; background: var(--bg-primary); color: var(--text-primary); border: 1px solid var(--border-color); box-shadow: var(--shadow-sm); }
.btn-google:hover { background: var(--bg-secondary); border-color: #CBD5E1; }
.btn-icon { background: transparent; color: var(--text-secondary); padding: 0.5rem; width: auto; border-radius: 50%; }
.btn-icon:hover { background: var(--bg-tertiary); color: var(--primary); transform: scale(1.1); }
.btn-sm { padding: 0.4rem 0.85rem; font-size: 0.85rem; }
.logout-btn { width: 100%; margin-top: auto; background: var(--danger); color: white; border: none; }
.logout-btn:hover { background: #DC2626; box-shadow: 0 4px 6px rgba(239, 68, 68, 0.3); transform: translateY(-1px); }

/* ============ SECTION ACTIONS ============ */
.section-actions {
  display: flex; gap: 0.75rem; margin-bottom: 1.5rem; flex-wrap: wrap; align-items: stretch;
}
.section-actions .btn { flex: 1 1 auto; margin: 0; min-width: 0; }
.user-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: flex-start; align-items: center; }
.user-actions .btn { padding: 0.4rem 0.8rem; font-size: 0.8rem; margin: 0; flex: 1 1 auto; }

/* ============ DASHBOARD & SIDEBAR ============ */
.dashboard { display: flex; min-height: 100vh; background: var(--bg-secondary); }
.sidebar {
  width: 280px; flex-shrink: 0; background: var(--bg-primary); border-right: 1px solid var(--border-color);
  padding: 1.5rem; height: 100vh; position: sticky; top: 0; display: flex; flex-direction: column; transition: transform 0.3s ease; z-index: 2000;
}
.sidebar-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; }
.sidebar-header h2 { font-size: 1.25rem; color: var(--text-primary); font-weight: 700; display: flex; align-items: center; gap: 0.75rem; letter-spacing: -0.025em; }
.sidebar-header .icon { color: var(--primary); }
.sidebar-toggle { display: none; background: transparent; border: none; font-size: 1.8rem; cursor: pointer; color: var(--text-secondary); padding: 0.25rem; border-radius: var(--border-radius-sm); }
.sidebar-toggle:hover { color: var(--text-primary); background-color: var(--bg-tertiary); }

.user-info { display: flex; gap: 0.75rem; align-items: center; margin-bottom: 1.5rem; padding: 1rem; background: var(--bg-secondary); border-radius: var(--border-radius); border: 1px solid var(--border-color); }
.user-avatar { width: 48px; height: 48px; flex-shrink: 0; border-radius: 50%; background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%); color: white; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 1.2rem; }
.user-info div { min-width: 0; }
.user-info h4 { font-size: 0.95rem; color: var(--text-primary); margin: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.nav-menu { list-style: none; margin-bottom: 2rem; }
.nav-link {
  display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 1rem; margin-bottom: 0.25rem;
  border-radius: var(--border-radius-sm); text-decoration: none; color: var(--text-secondary); font-weight: 500;
  cursor: pointer; transition: var(--transition); border: 1px solid transparent;
}
.nav-link:hover { background: var(--bg-secondary); color: var(--text-primary); }
.nav-link.active { background: var(--primary); color: white; font-weight: 600; box-shadow: 0 2px 4px rgba(14, 165, 233, 0.3); }

/* ============ MAIN CONTENT ============ */
.main-content { flex: 1; padding: 2rem; overflow-y: auto; max-height: 100vh; padding-bottom: 1rem; display: flex; flex-direction: column; }
.main-content-wrapper { flex: 1; max-width: 1600px; margin: 0 auto; width: 100%; }
.content-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 1rem; margin-bottom: 2rem; }
.content-header h1 { font-size: clamp(1.5rem, 5vw, 2rem); color: var(--text-primary); font-weight: 700; letter-spacing: -0.025em; margin-bottom: 0; }

.current-month { font-weight: 600; color: var(--primary); padding: 0.6rem 1rem; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: var(--border-radius-sm); box-shadow: var(--shadow-sm); cursor: pointer; }
.current-month:focus { outline: none; border-color: var(--primary); }

.content-section { display: none; animation: fadeIn 0.4s ease; }
.content-section.active { display: block; }

/* ============ CARDS & STATS ============ */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; }
.stat-card {
  background: var(--glass-bg); backdrop-filter: blur(10px); border: 1px solid var(--border-light);
  border-radius: var(--border-radius-lg); padding: 1.5rem; box-shadow: var(--shadow);
  display: flex; gap: 1.25rem; align-items: center; transition: var(--transition);
  position: relative; overflow: hidden; cursor: default;
}
.stat-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--primary); border-radius: 4px 0 0 4px; }
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-hover); border-color: var(--border-color); }

.stat-icon { font-size: 2rem; width: 56px; height: 56px; flex-shrink: 0; background: var(--bg-secondary); border-radius: 14px; display: flex; align-items: center; justify-content: center; color: var(--primary); box-shadow: inset 0 2px 4px rgba(0,0,0,0.02); }
.stat-details h3 { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 0.25rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 1.8rem; font-weight: 700; color: var(--text-primary); line-height: 1.2; letter-spacing: -0.025em; }

.card { background: var(--bg-primary); border-radius: var(--border-radius-lg); padding: 1.5rem; box-shadow: var(--shadow); border: 1px solid var(--border-light); margin-bottom: 1.5rem; transition: var(--transition); }
.card:hover { box-shadow: var(--shadow-hover); }
.card h2 { font-size: 1.25rem; color: var(--text-primary); margin-bottom: 1.25rem; font-weight: 600; letter-spacing: -0.01em; }

.charts-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; }
.chart-container { position: relative; width: 100%; height: 300px; }

/* ============ TOGGLE SWITCH (Self-Service UI) ============ */
.toggle-group { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 0; border-bottom: 1px solid var(--border-light); }
.toggle-group:last-child { border-bottom: none; }
.toggle-label { font-weight: 600; color: var(--text-primary); font-size: 0.95rem; display: flex; flex-direction: column; }
.toggle-label span { font-size: 0.75rem; color: var(--text-secondary); font-weight: 400; margin-top: 2px; }

.toggle-switch { position: relative; display: inline-block; width: 50px; height: 28px; flex-shrink: 0;}
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--border-color); transition: .4s; border-radius: 34px; }
.toggle-slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 4px; bottom: 4px; background-color: white; transition: .4s; border-radius: 50%; box-shadow: var(--shadow-sm); }
.toggle-switch input:checked + .toggle-slider { background-color: var(--success); }
.toggle-switch input:disabled + .toggle-slider { background-color: var(--bg-tertiary); cursor: not-allowed; }
.toggle-switch input:checked + .toggle-slider:before { transform: translateX(22px); }

/* ============ MEAL CALENDAR & COST BREAKDOWN ============ */
.calendar-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 1rem; }
.calendar-day { background: var(--bg-secondary); border: 1px solid var(--border-color); border-radius: var(--border-radius); padding: 1rem; text-align: center; transition: var(--transition); }
.calendar-day:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); border-color: var(--primary-light); }
.day-header { font-weight: 700; color: var(--primary-dark); font-size: 1.1rem; margin-bottom: 0.75rem; }
.meal-display { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 0.75rem; display: flex; flex-direction: column; gap: 0.3rem; font-weight: 500; }
.day-total { font-weight: 700; color: var(--text-primary); padding-top: 0.75rem; border-top: 1px dashed var(--border-color); }

.cost-breakdown { display: grid; gap: 0.75rem; }
.cost-item { display: flex; justify-content: space-between; align-items: center; padding: 1rem 1.25rem; background: var(--bg-secondary); border-radius: var(--border-radius-sm); border-left: 4px solid var(--primary-light); font-weight: 500; flex-wrap: wrap; gap: 0.5rem;}
.cost-item.total { background: var(--text-primary); color: white; font-weight: 700; border-left-color: var(--primary); }
.cost-item span:last-child { font-weight: 600; font-family: monospace; font-size: 1.05rem; }

/* ============ MEAL EDIT CARD (Manager Override) ============ */
.meal-card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1.5rem; padding-bottom: 2rem; }
.meal-card { background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: var(--border-radius-lg); padding: 1.25rem; box-shadow: var(--shadow-sm); display: flex; flex-direction: column; gap: 1rem; transition: var(--transition); height: 100%; }
.meal-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); border-color: var(--primary-light); }
.meal-card-header { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--bg-secondary); padding-bottom: 0.75rem; gap: 0.5rem;}
.meal-card-name { font-weight: 700; color: var(--text-primary); font-size: 1.05rem; white-space: normal; word-break: break-word; flex: 1;}
.meal-card-total { font-size: 0.8rem; color: var(--primary-dark); font-weight: 700; background: var(--bg-tertiary); padding: 0.35rem 0.65rem; border-radius: 99px; white-space: nowrap;}

.stepper-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
.stepper-block { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; }
.stepper-label { font-size: 0.65rem; text-transform: uppercase; color: var(--text-secondary); font-weight: 700; letter-spacing: 0.05em; text-align: center; white-space: nowrap;}

.stepper-controls { display: flex; align-items: center; background: var(--bg-secondary); border-radius: var(--border-radius-sm); width: 100%; height: 36px; position: relative; overflow: hidden; border: 1px solid var(--border-color); transition: border-color 0.2s; }
.stepper-controls:hover { border-color: var(--primary-light); }
.stepper-value-btn { flex: 1; border: none; background: transparent; font-weight: 700; font-size: 0.9rem; cursor: pointer; height: 100%; z-index: 2; transition: all 0.2s; padding: 0; color: var(--text-primary);}
.stepper-value-btn.inactive { color: var(--text-tertiary); }
.stepper-value-btn.active { background: var(--primary); color: white; }
.stepper-side-btn { width: 28px; height: 100%; border: none; background: transparent; color: var(--text-tertiary); font-weight: bold; font-size: 1.1rem; cursor: pointer; display: flex; align-items: center; justify-content: center; z-index: 1; flex-shrink: 0;}
.stepper-side-btn:hover { background: rgba(0,0,0,0.05); color: var(--primary); }

/* ============ TABLES & USER AVATARS ============ */
.table-responsive { overflow-x: auto; border-radius: var(--border-radius-lg); border: 1px solid var(--border-color); background: var(--bg-primary); box-shadow: var(--shadow-sm); }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.data-table thead { background: #F8FAFC; border-bottom: 2px solid var(--border-color); }
.data-table th { padding: 1rem; text-align: left; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; font-size: 0.75rem; letter-spacing: 0.05em; white-space: nowrap; }
.data-table td { padding: 1rem; border-bottom: 1px solid var(--border-color); color: var(--text-primary); vertical-align: middle; white-space: nowrap; transition: background-color 0.2s; }
.data-table tbody tr:hover td { background-color: var(--bg-secondary); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr.current-user-row td { background-color: var(--bg-tertiary); font-weight: 600; color: var(--primary-dark); }

.data-table input[type="number"] { width: 100%; min-width: 80px; padding: 0.5rem; border: 1px solid var(--border-color); border-radius: var(--border-radius-sm); outline: none; transition: var(--transition); font-family: monospace; font-size: 0.95rem; }
.data-table input[type="number"]:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15); }

.empty-state { padding: 3rem 1.5rem; text-align: center; color: var(--text-secondary); font-weight: 500; font-size: 0.95rem;}

.desktop-user-container { display: flex; align-items: center; gap: 10px; }
.desktop-user-avatar { width: 32px; height: 32px; border-radius: 50%; background-size: cover; background-position: center; font-size: 13px; font-weight: 600; display: flex; align-items: center; justify-content: center; color: white; border: 2px solid white; box-shadow: var(--shadow-sm); flex-shrink: 0;}
.mobile-user-header { display: none; }

/* ============ SEARCH BAR ============ */
.search-wrapper { margin-bottom: 1.5rem; max-width: 100%; }
.search-input-group { position: relative; display: flex; align-items: center; width: 100%; }
.search-icon { position: absolute; left: 14px; color: var(--text-tertiary); display: flex; align-items: center; pointer-events: none; }
.search-input { width: 100%; padding: 0.75rem 1rem 0.75rem 2.75rem; border: 1px solid var(--border-color); border-radius: var(--border-radius-sm); font-size: 0.95rem; background: var(--bg-primary); color: var(--text-primary); transition: var(--transition); box-shadow: inset 0 1px 2px rgba(0,0,0,0.02); }
.search-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15); }

/* ============ BADGES ============ */
.badge { display: inline-block; padding: 0.25rem 0.6rem; border-radius: 9999px; font-size: 0.7rem; font-weight: 600; line-height: 1.2; text-transform: capitalize; letter-spacing: 0.025em; white-space: nowrap;}
.badge-border { background: rgba(16, 185, 129, 0.15); color: #059669; }
.badge-manager { background: rgba(14, 165, 233, 0.15); color: #0284C7; }
.badge-market { background: rgba(245, 158, 11, 0.15); color: #D97706; }
.badge-shared { background: rgba(99, 102, 241, 0.15); color: #4F46E5; }
.badge-individual { background: rgba(236, 72, 153, 0.15); color: #DB2777; }
.badge-success { background: rgba(16, 185, 129, 0.15); color: #059669; }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: #D97706; }
.badge-danger { background: rgba(239, 68, 68, 0.15); color: #DC2626; }

/* ============ FORM ELEMENTS ============ */
.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; margin-bottom: 0.5rem; font-weight: 600; color: var(--text-secondary); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.05em; }
.form-group input, .form-group select { width: 100%; padding: 0.85rem 1rem; border: 1px solid var(--border-color); border-radius: var(--border-radius-sm); font-size: 0.95rem; background: var(--bg-primary); transition: var(--transition); color: var(--text-primary); }
.form-group input:focus, .form-group select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(14, 165, 233, 0.15); }

/* ============ UTILITIES & TOAST ============ */
.text-success { color: #059669; font-weight: 600; }
.text-danger { color: #DC2626; font-weight: 600; }
.text-secondary { color: var(--text-secondary); font-weight: 500; }

.skeleton { animation: pulse 1.5s cubic-bezier(0.4, 0, 0.6, 1) infinite; background-color: var(--border-color); border-radius: var(--border-radius-sm); }
.skeleton-text { height: 1.25rem; width: 80%; margin-bottom: 0.5rem; }
.skeleton-text-lg { height: 2rem; width: 60%; }
.content-hidden { display: none; }
.loading-done .skeleton { display: none !important; }
.loading-done .content-hidden { display: block; }
.loading-done .stat-icon.content-hidden { display: flex; }
.loading-done #summaryTable tbody tr.content-hidden { display: table-row; } 

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ============ MODERN MODALS (FIXED ANIMATIONS & GLASSMORPHISM) ============ */
.modal-overlay { 
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; 
  background: rgba(15, 23, 42, 0.6); 
  backdrop-filter: blur(4px); 
  -webkit-backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; 
  z-index: 3000; padding: 1rem;
  animation: overlayFadeIn 0.2s ease forwards;
}
@keyframes overlayFadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal { 
  background: var(--bg-primary); border-radius: var(--border-radius-lg); 
  max-width: 500px; width: 100%; max-height: 90vh; 
  display: flex; flex-direction: column; 
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255,255,255,0.1);
  opacity: 0; transform: scale(0.95);
  animation: modalPopIn 0.25s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}
@keyframes modalPopIn { to { opacity: 1; transform: scale(1); } }

.modal-overlay.closing { animation: overlayFadeOut 0.2s ease forwards; pointer-events: none; }
.modal-overlay.closing .modal { animation: modalPopOut 0.2s ease forwards; }

@keyframes overlayFadeOut { to { opacity: 0; } }
@keyframes modalPopOut { to { opacity: 0; transform: scale(0.95); } }

.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border-light); flex-shrink: 0; }
.modal-header h2 { font-size: 1.2rem; font-weight: 700; letter-spacing: -0.01em; color: var(--text-primary); margin: 0; }
.modal-close { background: var(--bg-secondary); border: none; font-size: 1.2rem; cursor: pointer; color: var(--text-secondary); width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: 50%; transition: var(--transition); flex-shrink: 0;}
.modal-close:hover { background: var(--danger); color: white; transform: rotate(90deg); }

.modal-body { padding: 1.5rem; overflow-y: auto; }
.modal-footer { padding: 1.25rem 1.5rem; border-top: 1px solid var(--border-light); display: flex; gap: 0.75rem; justify-content: flex-end; flex-wrap: wrap; background: var(--bg-secondary); border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg); flex-shrink: 0; }
.modal-footer .btn { margin: 0; flex: 1 1 auto; min-width: 120px;}


/* ============ LOADING & TOAST ============ */
.loading-overlay { position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(255, 255, 255, 0.8); backdrop-filter: blur(2px); display: none; align-items: center; justify-content: center; z-index: 4000; opacity: 0; transition: opacity 0.3s ease; }
.loading-overlay.active { display: flex; opacity: 1; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--border-light); border-top-color: var(--primary); border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast { position: fixed; bottom: 20px; right: 20px; left: 20px; background: var(--bg-primary); color: var(--text-primary); padding: 1rem; border-radius: var(--border-radius-sm); box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(20px); transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1); z-index: 3500; border-left: 4px solid var(--primary); font-weight: 500; display: flex; align-items: center; gap: 0.5rem; word-break: break-word;}
@media (min-width: 480px) { .toast { left: auto; max-width: 400px; } }
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-left-color: var(--success); }
.toast-error { border-left-color: var(--danger); }

/* ============ PROFILE STYLES ============ */
.profile-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border-light); flex-wrap: wrap;}
.profile-avatar-lg { width: 70px; height: 70px; border-radius: 50%; background-color: var(--primary); color: white; display: flex; align-items: center; justify-content: center; font-size: 1.8rem; font-weight: bold; background-size: cover; background-position: center; flex-shrink: 0; box-shadow: var(--shadow-sm); border: 2px solid white; }
.profile-info { flex: 1; min-width: 0; }
.profile-info h3 { margin: 0 0 0.2rem 0; font-size: 1.15rem; color: var(--text-primary); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}
.profile-info p { margin: 0; color: var(--text-secondary); font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}
.profile-details { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }
.detail-item label { display: block; font-size: 0.7rem; text-transform: uppercase; color: var(--text-tertiary); margin-bottom: 0.2rem; font-weight: 700; letter-spacing: 0.05em; }
.detail-item p { font-size: 0.95rem; color: var(--text-primary); font-weight: 500; margin: 0; word-break: break-word;}
.color-options { display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; }
.color-option { width: 28px; height: 28px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: transform 0.2s; box-shadow: inset 0 2px 4px rgba(0,0,0,0.1); }
.color-option:hover { transform: scale(1.15); }
.image-upload-container { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap;}
.image-preview { width: 64px; height: 64px; border-radius: 50%; background: var(--bg-secondary); background-size: cover; background-position: center; flex-shrink: 0; border: 2px solid var(--border-color); }

/* ============ MOBILE HEADER ============ */
.mobile-header { display: none; background: var(--bg-primary); padding: 0.75rem 1rem; border-bottom: 1px solid var(--border-color); box-shadow: var(--shadow-sm); justify-content: space-between; align-items: center; position: sticky; top: 0; z-index: 998; }
.mobile-header h1 { font-size: 1.1rem; font-weight: 700; color: var(--text-primary); margin: 0;}
.mobile-header .sidebar-toggle { display: flex; align-items: center; justify-content: center;}
.mobile-header .mobile-logout-btn { background: transparent; border: none; color: var(--danger); cursor: pointer; padding: 0.4rem; border-radius: var(--border-radius-sm); transition: var(--transition); display: flex; align-items: center; justify-content: center;}
.mobile-header .mobile-logout-btn:hover { background: rgba(239, 68, 68, 0.1); }

/* ============ RESPONSIVE LAYOUT OPTIMIZATIONS ============ */
@media (max-width: 900px) {
  .auth-wrapper { flex-direction: column; min-height: 0; max-width: 440px; }
  .auth-branding { display: none; }
  .auth-container { width: 100%; padding: 2rem 1.5rem; }
  .auth-header { text-align: center; }
  .auth-header-icon { display: inline-flex; }
  .auth-header h1 { font-size: 1.4rem; }
}

@media (max-width: 768px) {
  /* Sidebar */
  .sidebar { position: fixed; left: 0; top: 0; height: 100%; z-index: 2500; transform: translateX(-100%); width: 260px; box-shadow: var(--shadow-hover); }
  .sidebar.active { transform: translateX(0); }
  .sidebar-toggle { display: block; }
  .sidebar .logout-btn { display: none; }
  .dashboard { flex-direction: column; }
  
  /* Main Content */
  .main-content { padding: 1rem; margin-left: 0; max-height: none; }
  .mobile-header { display: flex; width: 100%; }

  /* Header Actions */
  .content-header { flex-direction: column; align-items: stretch; gap: 0.75rem; margin-bottom: 1.5rem;}
  .content-header h1 { display: none; /* Hide duplicate title on mobile */ }
  .header-actions { width: 100%; display: flex; justify-content: center;}
  .current-month { flex: 1; text-align: center; width: 100%; max-width: none;}
  .search-input { max-width: none;}

  /* Grid Layouts */
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 0.75rem; margin-bottom: 1.5rem;}
  .stat-card { padding: 1rem; gap: 0.75rem; flex-direction: column; align-items: flex-start; text-align: left;}
  .stat-card::before { top: auto; bottom: 0; left: 0; right: 0; height: 4px; width: 100%; border-radius: 0 0 4px 4px; }
  .stat-icon { width: 40px; height: 40px; font-size: 1.4rem; border-radius: 10px; margin-bottom: 0.25rem;}
  .stat-value { font-size: 1.4rem; }
  
  .charts-grid { grid-template-columns: 1fr; gap: 1rem; margin-bottom: 1.5rem;}
  .chart-container { height: 250px; }
  
  .meal-card-grid { grid-template-columns: 1fr; gap: 1rem; padding-bottom: 2rem;}

  .card { padding: 1.25rem; margin-bottom: 1rem; }
  .card h2 { font-size: 1.1rem; margin-bottom: 1rem; padding-bottom: 0.75rem;}

  /* Section Actions (Buttons) */
  .section-actions { flex-direction: column; align-items: stretch; gap: 0.5rem; margin-bottom: 1rem;}
  .section-actions .btn { width: 100%; max-width: none; }

  /* Table Container */
  .table-responsive { border: 1px solid var(--border-color); border-radius: var(--border-radius-sm); margin-bottom: 1rem;}
  
  /* Search Bar */
  .search-wrapper { max-width: 100%; margin-bottom: 1rem;}
  
  /* Form Groups */
  .form-group { margin-bottom: 1rem; }
  .settings-grid { grid-template-columns: 1fr; gap: 1rem; }

  /* ============ SPLIT-LAYOUT MOBILE SUMMARY ============ */
  #overviewSection .table-responsive, 
  #dashboardSection .table-responsive { border: none !important; background: transparent; box-shadow: none; border-radius: 0; padding: 0;}

  #summaryTable { display: block; }
  #summaryTable thead { display: none; } 
  #summaryTable tbody { display: block; width: 100%; }

  #summaryTable tbody tr {
    display: grid; grid-template-columns: 1fr 1fr; grid-auto-flow: dense;
    background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: var(--border-radius); margin-bottom: 1rem; padding: 0; box-shadow: var(--shadow-sm); overflow: hidden; transition: transform 0.2s ease, box-shadow 0.2s ease;
  }
  #summaryTable tbody tr:active { transform: scale(0.98); box-shadow: none; }
  #summaryTable tbody tr.current-user-row { border: 2px solid var(--primary); box-shadow: inset 0 0 0 1px rgba(14,165,233,0.1); }

  #summaryTable td:nth-child(2) { grid-column: 1 / -1; display: block; background: var(--bg-secondary); padding: 1rem; border-bottom: 1px solid var(--border-color); }
  .desktop-user-container { display: none; }
  .mobile-user-header { display: flex; align-items: center; gap: 0.75rem; width: 100%; }
  .mobile-user-avatar { width: 44px; height: 44px; border-radius: 50%; background-size: cover; background-position: center; font-size: 1.1rem; font-weight: bold; color: white; display: flex; align-items: center; justify-content: center; border: 2px solid white; box-shadow: var(--shadow-sm); flex-shrink: 0;}
  .mobile-user-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1;}
  .mobile-user-name { font-weight: 700; color: var(--text-primary); font-size: 1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;}
  .mobile-user-role { font-size: 0.7rem; color: var(--secondary); background: white; padding: 2px 6px; border-radius: 4px; display: inline-block; font-weight: 600; border: 1px solid var(--border-color); align-self: flex-start; }

  #summaryTable td:nth-child(1) { display: none; }

  #summaryTable td:nth-child(3), #summaryTable td:nth-child(4) { grid-column: 1; display: block; padding: 0.75rem 1rem; border-right: 1px solid var(--border-light); font-size: 0.9rem; color: var(--text-primary); }
  #summaryTable td:nth-child(3), #summaryTable td:nth-child(5) { border-bottom: 1px dashed var(--border-color); }
  #summaryTable td:nth-child(5), #summaryTable td:nth-child(6) { grid-column: 2; display: block; padding: 0.75rem 1rem; font-size: 0.9rem; color: var(--text-primary); }
  
  #summaryTable td:nth-child(3)::before, #summaryTable td:nth-child(4)::before, #summaryTable td:nth-child(5)::before, #summaryTable td:nth-child(6)::before, #summaryTable td:nth-child(7)::before {
    content: attr(data-label); display: block; font-size: 0.65rem; color: var(--text-secondary); text-transform: uppercase; font-weight: 700; margin-bottom: 4px; letter-spacing: 0.05em;
  }
  
  #summaryTable td:nth-child(7) { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; padding: 0.85rem 1rem; background: var(--bg-secondary); font-weight: 600; font-size: 0.95rem; border-top: 1px solid var(--border-color); border-bottom: 1px solid var(--border-color); }
  #summaryTable td:last-child { grid-column: 1 / -1; display: flex; justify-content: space-between; align-items: center; padding: 1rem; font-weight: 800; font-size: 1.05rem; }
  #summaryTable td:last-child.text-success { background-color: rgba(16, 185, 129, 0.1); color: #059669; }
  #summaryTable td:last-child.text-danger { background-color: rgba(239, 68, 68, 0.1); color: #DC2626; }
  #summaryTable td:last-child::before { content: "Balance"; font-size: 0.8rem; color: var(--text-secondary); font-weight: 700; text-transform: uppercase; }
}

@media (max-width: 400px) {
    .stat-card { flex-direction: row; align-items: center; text-align: left;}
    .stat-card::before { top: 0; bottom: 0; left: 0; right: auto; height: 100%; width: 4px; border-radius: 4px 0 0 4px; }
    .stats-grid { grid-template-columns: 1fr; }
    .profile-header { flex-direction: column; text-align: center; }
    .profile-details { grid-template-columns: 1fr; }
    .modal-footer { flex-direction: column; }
    .modal-footer .btn { width: 100%; }
}
