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

/* ============ ROOT VARIABLES ============ */
:root {
  --primary: #0EA5E9; /* Sky-500 */
  --primary-dark: #0284C7; /* Sky-600 */
  --primary-light: #38BDF8; /* Sky-400 */
  --secondary: #06B6D4; /* Cyan-500 */
  --danger: #EF4444; /* Red-500 */
  --success: #10B981; /* Emerald-500 */
  --warning: #F59E0B; /* Amber-500 */
  
  --bg-primary: #FFFFFF; /* White */
  --bg-secondary: #F0F9FF; /* Sky-50 */
  --bg-tertiary: #E0F2FE; /* Sky-100 */
  
  --text-primary: #1E293B; /* Slate-800 */
  --text-secondary: #64748B; /* Slate-500 */
  --text-tertiary: #94A3B8; /* Slate-400 */
  
  --border-color: #BAE6FD; /* Sky-200 */
  
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  
  --border-radius-sm: 0.375rem; /* 6px */
  --border-radius: 0.5rem; /* 8px */
  --border-radius-lg: 0.75rem; /* 12px */
  
  --transition: all 0.3s ease;
}

/* ============ GENERAL STYLES ============ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
    'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
    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;
}

/* ============ 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; }
.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; }

.form-group { margin-bottom: 1.25rem; }
.form-group label { display: block; margin-bottom: 0.5rem; font-weight: 500; color: var(--text-primary); font-size: 0.9rem; }
.form-group input, .form-group select {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 1px solid #D1D5DB;
  border-radius: var(--border-radius);
  font-size: 0.95rem;
  transition: var(--transition);
  background: var(--bg-primary);
  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.2);
}
.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; }
.forgot-password-link:hover { color: var(--primary-dark); text-decoration: underline; }

.auth-divider { display: flex; align-items: center; margin: 1.5rem 0; color: var(--text-secondary); }
.auth-divider::before, .auth-divider::after { content: ''; flex: 1; height: 1px; background: #E5E7EB; }
.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; }
.auth-switch a:hover { text-decoration: underline; color: var(--primary-dark); }

.error-message, .success-message {
  padding: 1rem; border-radius: var(--border-radius); margin-top: 1.5rem; display: none; animation: slideDown 0.3s ease; font-weight: 500;
}
@keyframes slideDown { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.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 1rem;
  border: 1px solid transparent;
  border-radius: var(--border-radius);
  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: nowrap;
  line-height: 1.25;
}
.btn:focus-visible { outline: 2px solid var(--primary-dark); outline-offset: 2px; }

.btn-primary { background: var(--primary); color: white; width: 100%; margin-top: 0.75rem; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow); transform: translateY(-2px); }
.btn-primary:active { transform: translateY(0); }

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

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { opacity: 0.85; }
.btn-success { background: var(--success); color: white; }
.btn-success:hover { opacity: 0.85; }

.btn-google { width: 100%; background: var(--bg-primary); color: var(--text-primary); border: 1px solid #D1D5DB; }
.btn-google:hover { background: #F9FAFB; }

.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.375rem 0.75rem; font-size: 0.85rem; }

.logout-btn { width: 100%; margin-top: auto; background: var(--danger); }
.logout-btn:hover { background: #DC2626; box-shadow: var(--shadow); transform: translateY(-2px); }

/* ============ SECTION ACTIONS (FIXED) ============ */
.section-actions {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap; /* Allows wrapping */
  align-items: center;
}

.section-actions .btn {
  margin: 0;
  width: auto; /* Buttons fit content */
  flex-grow: 1; /* Grow to fill space */
  min-width: 140px; /* Prevent being too small */
  max-width: 250px; /* Prevent being too wide */
}

@media (max-width: 480px) {
  .section-actions .btn {
    width: 100%; /* Full width on very small screens */
    max-width: none;
  }
}

/* ============ USER ACTIONS (FIXED FOR TABLE) ============ */
/* This prevents the "piling up" issue in table actions */
.user-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: nowrap; /* Force side-by-side */
  justify-content: flex-start;
  align-items: center;
}

.user-actions .btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
    margin: 0;
    width: auto;
    min-width: 60px;
}

/* On very small screens, keep buttons side-by-side */
@media (max-width: 600px) {
    .user-actions {
        flex-wrap: nowrap; /* Force single line */
    }
    .user-actions .btn {
        flex-grow: 0;      /* Do not stretch */
        white-space: nowrap; 
    }
}

/* ============ DASHBOARD & SIDEBAR ============ */
.dashboard { display: flex; min-height: 100vh; }

.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.3rem; color: var(--primary); display: flex; align-items: center; gap: 0.75rem; }

.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); }
.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.5rem;
  border-radius: var(--border-radius); 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-tertiary); color: var(--primary-dark); }
.nav-link.active { background: var(--bg-secondary); color: var(--primary-dark); font-weight: 600; border-left: 4px solid var(--primary); padding-left: calc(1rem - 4px); }

/* ============ 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; }
.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); }

.current-month { font-weight: 500; color: var(--text-secondary); padding: 0.5rem 0.75rem; background: var(--bg-primary); border: 1px solid var(--border-color); border-radius: var(--border-radius-sm); box-shadow: var(--shadow-sm); }
.content-section { display: none; animation: fadeIn 0.3s ease; }
.content-section.active { display: block; }

/* ============ STATS & CARDS ============ */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.5rem; margin-bottom: 2rem; }
.stat-card {
  background: var(--bg-primary); border-radius: var(--border-radius-lg); padding: 1.25rem; box-shadow: var(--shadow);
  display: flex; gap: 1rem; align-items: center; border-left: 4px solid var(--primary); transition: var(--transition);
  cursor: default;
}
/* ADDED: Hover/Active effect for Stat Cards */
.stat-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--primary-light); }
.stat-card:active { transform: scale(0.98); }

.stat-icon { font-size: 2rem; width: 60px; height: 60px; flex-shrink: 0; background: var(--bg-tertiary); border-radius: var(--border-radius); display: flex; align-items: center; justify-content: center; color: var(--text-secondary); }
.stat-details h3 { font-size: 0.9rem; color: var(--text-secondary); margin-bottom: 0.5rem; font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--primary); line-height: 1.2; }

.card { background: var(--bg-primary); border-radius: var(--border-radius-lg); padding: 1.5rem; box-shadow: var(--shadow); margin-bottom: 1.5rem; }
.card h2 { font-size: 1.3rem; color: var(--text-primary); margin-bottom: 1rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border-color); }

.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; }

/* ============ MEAL CALENDAR & COST BREAKDOWN ============ */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 0.75rem;
}

.calendar-day {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius);
  padding: 0.75rem;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.day-header {
  font-weight: 700;
  color: var(--primary);
  font-size: 1.2rem;
  margin-bottom: 0.5rem;
}

.meal-display {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.day-total {
  font-weight: 600;
  color: var(--text-primary);
  padding-top: 0.5rem;
  margin-top: 0.5rem;
  border-top: 1px solid var(--border-color);
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 2rem;
  background: var(--bg-secondary);
  border-radius: var(--border-radius);
}

/* Cost Breakdown */
.cost-breakdown {
  display: grid;
  gap: 0.75rem;
}

.cost-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  background: var(--bg-secondary);
  border-radius: var(--border-radius-sm);
  border-left: 4px solid var(--secondary);
  font-weight: 500;
}

.cost-item.total {
  background: var(--bg-tertiary);
  font-weight: 700;
  border-left-color: var(--primary-dark);
}

.cost-item span:last-child {
  font-weight: 600;
}

/* ============ MEAL EDIT CARD (FIXED GRID FOR MOBILE) ============ */
.meal-card-grid {
  display: grid;
  /* Reduced to 260px so cards don't overflow on small mobile */
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1.5rem;
  padding-bottom: 5rem;
}

.meal-card {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.02);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  transition: transform 0.2s, box-shadow 0.2s;
  height: 100%;
}
.meal-card:hover { transform: translateY(-3px); box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.08); 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; }
.meal-card-name { font-weight: 700; color: var(--text-primary); font-size: 1.05rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 60%; }
.meal-card-total { font-size: 0.85rem; color: var(--primary-dark); font-weight: 700; background: var(--bg-tertiary); padding: 0.25rem 0.75rem; border-radius: 20px; }

.stepper-row { display: flex; justify-content: space-between; gap: 0.5rem; }
.stepper-block { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 0.35rem; }
.stepper-label { font-size: 0.65rem; text-transform: uppercase; color: var(--text-secondary); font-weight: 700; letter-spacing: 0.05em; }

.stepper-controls {
  display: flex; align-items: center; background: var(--bg-secondary); border-radius: 8px;
  width: 100%; height: 38px; position: relative; overflow: hidden; border: 1px solid transparent; transition: border-color 0.2s;
}
.stepper-controls:hover { border-color: var(--border-color); }

.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; }
.stepper-value-btn.inactive { color: var(--text-tertiary); }
.stepper-value-btn.active { background: var(--primary); color: white; }

.stepper-side-btn {
  width: 24px;
  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;
}
.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);
  border: 1px solid var(--border-color);
  background: white; /* Ensure background is white */
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem; /* Slightly larger font */
}

/* Table Header Styling to match "View Meals" blue bar */
.data-table thead {
  background: var(--bg-secondary); 
}

/* If you want the main "View Meals" header to be blue like the screenshot */
.table-header-blue {
    background-color: var(--primary);
    color: white;
    padding: 1rem;
    text-align: center;
    font-weight: 700;
    border-radius: var(--border-radius) var(--border-radius) 0 0;
}

.data-table th {
  padding: 1rem; /* More padding */
  text-align: left;
  font-weight: 600;
  color: var(--primary); /* Blue text for headers */
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  background-color: #E0F2FE; /* Light blue background for headers */
}

.data-table td {
  padding: 1rem; /* More padding */
  border-bottom: 1px solid var(--border-color);
  color: var(--text-primary);
  vertical-align: middle;
  white-space: nowrap; /* <--- THIS FIXES THE DOUBLE LINES */
}

.data-table tbody tr:hover { background: var(--bg-tertiary); }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr.current-user-row { background-color: var(--bg-tertiary); font-weight: 600; }

/* Input fields inside the table */
.data-table input[type="number"] {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid #CBD5E1; /* Slate-300 */
    border-radius: 4px;
    outline: none;
    transition: border-color 0.2s;
}

.data-table input[type="number"]:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(14, 165, 233, 0.1);
}

/* No data / Empty state */
.empty-state {
    padding: 2rem;
    text-align: center;
    color: var(--text-secondary);
}

/* Desktop User Info */
.desktop-user-container { display: flex; align-items: center; gap: 12px; }
.desktop-user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background-size: cover; background-position: center;
  font-size: 14px; font-weight: 600; display: flex; align-items: center; justify-content: center; color: white;
  border: 2px solid var(--bg-tertiary);
}
.mobile-user-header { display: none; }

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

/* ============ BADGES ============ */
.badge { display: inline-block; padding: 0.25rem 0.75rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 600; line-height: 1.25; text-transform: capitalize; }
.badge-border { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.badge-manager { background: rgba(14, 165, 233, 0.1); color: var(--primary); }
.badge-market { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.badge-shared { background: rgba(139, 92, 246, 0.1); color: #8B5CF6; }
.badge-individual { background: rgba(236, 72, 153, 0.1); color: #EC4899; }
.badge-success { background: rgba(16, 185, 129, 0.1); color: var(--success); }
.badge-warning { background: rgba(245, 158, 11, 0.1); color: var(--warning); }
.badge-danger { background: rgba(239, 68, 68, 0.1); color: var(--danger); }

/* ============ UTILITIES ============ */
.text-success { color: var(--success); font-weight: 600; }
.text-danger { color: var(--danger); 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(--bg-tertiary); border-radius: var(--border-radius-sm); }
.skeleton-text { height: 1.25rem; width: 80%; margin-bottom: 0.5rem; }
.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; } }

/* ============ 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 .sidebar-toggle { display: block; }
.mobile-header .mobile-logout-btn { background: transparent; border: none; color: var(--danger); cursor: pointer; padding: 0.5rem; border-radius: var(--border-radius); }
.mobile-header .mobile-logout-btn .icon { width: 24px; height: 24px; }

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

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

  /* Stats Grid */
  .stats-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }
  .charts-grid { grid-template-columns: 1fr; }

  /* Meal Editor Mobile Fix */
  .meal-card-grid { grid-template-columns: 1fr; gap: 1rem; }
  
  /* ============ STYLISH SPLIT-LAYOUT MOBILE SUMMARY ============ */
  
  /* FIX: We ensure normal .table-responsive elements (like Track Meals) KEEP their border on mobile. */
  .table-responsive { border: 1px solid var(--border-color); }

  /* FIX: We REMOVE the border specifically for the Summary Table's wrapper on mobile.
     We target specific sections where the summary table lives to be safe. */
  #overviewSection .table-responsive, 
  #dashboardSection .table-responsive {
      border: none !important;
  }

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

  #summaryTable tbody tr {
    display: grid;
    grid-template-columns: 1fr 1fr; /* Split into 2 columns */
    /* IMPORTANT FIX: Dense flow ensures 2x2 grid fills perfectly */
    grid-auto-flow: dense;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 16px;
    margin-bottom: 1.5rem;
    padding: 0;
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.05);
    overflow: hidden;
    transition: transform 0.2s ease, box-shadow 0.2s ease;
  }
  
  #summaryTable tbody tr:active {
    transform: scale(0.98);
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
  }
  
  #summaryTable tbody tr.current-user-row { border: 2px solid var(--primary); }

  /* 1. HEADER (User Info) - Spans full width */
  #summaryTable td:nth-child(2) {
    grid-column: 1 / -1;
    display: block;
    background: linear-gradient(135deg, #F8FAFC 0%, #E0F2FE 100%);
    padding: 1.25rem;
    border-bottom: none; 
  }
  
  .desktop-user-container { display: none; }
  .mobile-user-header { display: flex; align-items: center; gap: 1rem; width: 100%; }
  
  .mobile-user-avatar {
    width: 56px; height: 56px; border-radius: 50%;
    background-size: cover; background-position: center;
    font-size: 1.5rem; font-weight: bold; color: white; display: flex; align-items: center; justify-content: center;
    border: 3px solid white; box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  }
  
  .mobile-user-info { display: flex; flex-direction: column; gap: 4px; }
  .mobile-user-name { font-weight: 700; color: var(--text-primary); font-size: 1.1rem; }
  .mobile-user-role { font-size: 0.75rem; color: var(--primary-dark); background: white; padding: 2px 8px; border-radius: 10px; display: inline-block; font-weight: 600; border: 1px solid var(--border-color); align-self: flex-start; }

  /* 2. BODY (Split Stats) */
  #summaryTable td:nth-child(1) { display: none; } /* Hide No. */

  /* Left Column: Total Meals (3) & Meal Cost (4) */
  #summaryTable td:nth-child(3), 
  #summaryTable td:nth-child(4) {
    grid-column: 1;
    display: block;
    padding: 0.75rem 1rem;
    /* Added Vertical Divider */
    border-right: 1px solid var(--bg-tertiary);
    font-size: 0.95rem;
    color: var(--text-primary);
  }
  
  /* Top items (Meals and Shared) have bottom border to separate rows */
  #summaryTable td:nth-child(3) { border-bottom: 1px dashed var(--bg-tertiary); }
  #summaryTable td:nth-child(5) { border-bottom: 1px dashed var(--bg-tertiary); }

  /* Right Column: Shared Cost (5) & Ind Cost (6) */
  #summaryTable td:nth-child(5), 
  #summaryTable td:nth-child(6) {
    grid-column: 2;
    display: block;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    color: var(--text-primary);
  }
  
  /* Labels */
  #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.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: 0.05em;
  }
  
  /* Deposit (7) - Spans Full Width to Remove Empty Space */
  #summaryTable td:nth-child(7) {
    grid-column: 1 / -1; /* Full width */
    display: flex; /* Flex to align label and amount */
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: transparent; /* Remove fixed green background */
    color: var(--text-primary); /* CHANGED: Match other numbers */
    font-weight: 600;
    /* Separator to ensure visual break */
    border-top: 1px solid var(--border-color); 
    border-bottom: 1px solid var(--border-color);
  }

  /* 3. FOOTER (Balance) - Spans Full Width with Dynamic Colors */
  #summaryTable td:last-child {
    grid-column: 1 / -1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem;
    font-weight: 800;
    font-size: 1.2rem;
    /* Removed color: white !important; */
  }
  
  /* Positive Balance (Greenish Background) */
  #summaryTable td:last-child.text-success {
    background-color: rgba(16, 185, 129, 0.15); /* Light Green */
    color: var(--success); /* Green Text */
  }
  
  /* Negative Balance (Reddish Background) */
  #summaryTable td:last-child.text-danger {
    background-color: rgba(239, 68, 68, 0.15); /* Light Red */
    color: var(--danger); /* Red Text */
  }
  
  #summaryTable td:last-child::before {
    content: "Current Balance";
    font-size: 0.9rem;
    color: var(--text-secondary); /* Darker label for contrast on light bg */
    font-weight: 600;
    text-transform: uppercase;
  }
}

@media (max-width: 480px) {
  .auth-page { padding: 1.5rem; }
  .auth-wrapper { width: 100%; height: auto; border-radius: var(--border-radius-lg); }
  .content-header { flex-direction: column; align-items: flex-start; }
  .header-actions { width: 100%; }
}

/* ============ MODAL ============ */
.modal-overlay {
  position: fixed; top: 0; left: 0; right: 0; bottom: 0; background: rgba(0, 0, 0, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 1000; animation: fadeIn 0.3s ease;
}
.modal {
  background: var(--bg-primary); border-radius: var(--border-radius-lg); max-width: 500px; width: 90%; max-height: 90vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow-lg); animation: slideUp 0.3s ease-out;
}
.modal-overlay.closing .modal { animation: slideDown 0.3s ease-in forwards; }
.modal-overlay.closing { animation: fadeOut 0.3s ease-in forwards; }
@keyframes fadeOut { from { opacity: 1; } to { opacity: 0; } }

.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 1.25rem 1.5rem; border-bottom: 1px solid var(--border-color); flex-shrink: 0; }
.modal-header h2 { font-size: 1.3rem; color: var(--text-primary); }
.modal-close { background: transparent; border: none; font-size: 1.5rem; cursor: pointer; color: var(--text-secondary); width: 32px; height: 32px; display: flex; align-items: center; justify-content: center; border-radius: var(--border-radius-sm); transition: var(--transition); }
.modal-close:hover { background: var(--bg-tertiary); color: var(--text-primary); transform: rotate(90deg); }

.modal-body { padding: 1.5rem; overflow-y: auto; }
.modal-footer { padding: 1.25rem 1.5rem; border-top: 1px solid var(--border-color); display: flex; gap: 0.75rem; justify-content: flex-end; flex-shrink: 0; }
.modal-footer .btn { margin: 0; width: auto; }

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

.toast {
  position: fixed; bottom: 20px; right: 20px; background: var(--bg-primary); color: var(--text-primary);
  padding: 1rem 1.25rem; border-radius: var(--border-radius); box-shadow: var(--shadow-lg); opacity: 0; transform: translateY(20px); transition: all 0.3s ease; z-index: 1500;
  max-width: 90%; width: 320px; border-left: 4px solid var(--primary); font-weight: 500;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-success { border-left-color: var(--success); background: rgba(16, 185, 129, 0.05); color: var(--success); }
.toast-error { border-left-color: var(--danger); background: rgba(239, 68, 68, 0.05); color: var(--danger); }

/* Profile View Styles */
.profile-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1.5rem; padding-bottom: 1.5rem; border-bottom: 1px solid var(--border-color); }
.profile-avatar-lg { width: 80px; height: 80px; border-radius: 50%; background-color: var(--primary); color: white; display: flex; align-items: center; justify-content: center; font-size: 2rem; font-weight: bold; background-size: cover; background-position: center; flex-shrink: 0; }
.profile-info h3 { margin: 0 0 0.25rem 0; font-size: 1.25rem; color: var(--text-primary); }
.profile-info p { margin: 0; color: var(--text-secondary); font-size: 0.9rem; }
.profile-details { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.5rem; }
.detail-item label { display: block; font-size: 0.75rem; text-transform: uppercase; color: var(--text-secondary); margin-bottom: 0.25rem; font-weight: 600; }
.detail-item p { font-size: 1rem; color: var(--text-primary); font-weight: 500; }
.color-options { display: flex; gap: 0.5rem; margin-top: 0.5rem; flex-wrap: wrap; }
.color-option { width: 32px; height: 32px; border-radius: 50%; cursor: pointer; border: 2px solid transparent; transition: transform 0.2s; }
.color-option:hover { transform: scale(1.1); }
.image-upload-container { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.image-preview { width: 60px; height: 60px; border-radius: 50%; background: #eee; background-size: cover; background-position: center; flex-shrink: 0; border: 1px solid var(--border-color); }
