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

:root {
  /* --- PREMIUM COCOA THEME --- */
  --bg-body: #f7f4f0; /* Smidge lighter warm tone */
  --bg-card: #ffffff;
  
  /* Typography */
  --text-main: #292524; /* Stone 800 */
  --text-secondary: #44403c; /* Stone 700 - Darker */
  --text-muted: #78716c; /* Stone 500 - Darker */
  --border: #e7e0da; /* Visible Warm Gray */

  /* Accents */
  --primary: #4a3b32; /* Deep Espresso */
  --primary-hover: #292524;
  --accent-green: #15803d; /* Finance Green (Dark) */
  --accent-red: #b91c1c; /* Finance Red (Dark) */
  --badge-bg: #f5f5f4;
  --badge-text: #44403c;
}

/* UTILITY */
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); border: 0;
}

body {
  font-family: "Outfit", sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  overflow-x: hidden;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh; /* Use dynamic viewport height for mobile browsers */
}

/* ... (skip to inputs) ... */

input, select {
  width: 100%; padding: 10px 12px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem; color: var(--text-main);
  box-sizing: border-box; margin-bottom: 0;
  font-family: inherit; font-weight: 500;
  transition: all 0.2s ease;
  -webkit-appearance: none; /* Remove native iOS styling */
  appearance: none;
}

/* Prevent auto-zoom on iOS by forcing 16px font on mobile inputs */
@media screen and (max-width: 600px) {
  input, select, textarea {
    font-size: 16px !important; 
  }
}

/* ... */

/* --- AUTH --- */
/* --- AUTH --- */
/* --- AUTH --- */
.auth-container {
  max-width: 380px;
  width: 90%;
  padding: 28px 24px; /* Further reduced for mobile */
  background: var(--bg-card);
  border-radius: 20px;
  box-shadow: 0 30px 60px -15px rgba(0,0,0,0.1);
  border: 1.5px solid var(--border);
  text-align: center;

  /* Flex Centering (Robust against footer overlap) */
  position: relative;
  margin: auto;
  top: auto; left: auto;
  transform: none;
}

/* LOADING OVERLAY */
#loading-overlay {
  position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
  background: var(--bg-body); z-index: 9999;
  display: flex; justify-content: center; align-items: center;
  transition: opacity 0.3s ease;
}
.spinner {
  width: 40px; height: 40px;
  border: 3px solid rgba(0,0,0,0.1);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#app-container {
  width: 100%; max-width: 900px;
  margin: 0 auto;
  padding: 30px 20px;
  box-sizing: border-box;
  
  /* Flex layout to allow vertical centering of children (like auth) */
  flex: 1;
  display: flex;
  flex-direction: column;
}


/* --- AUTH --- */

.auth-container h1 {
  font-size: 1.85rem; margin-bottom: 0.2rem; color: var(--primary); font-weight: 800;
}
.auth-container h1 span {
  display: inline-block;
  margin-bottom: 6px;
}
.auth-buttons {
  margin-top: 1.5rem; /* Reduced space */
  display: flex; flex-direction: column; gap: 12px; /* Decreased gap */
}

/* --- INPUTS --- */
.input-label {
  font-size: 0.75rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted);
  margin: 16px 0 6px 0; /* Tighter spacing */
  display: block; text-align: left;
}
.subtitle {
  color: var(--text-secondary); margin-bottom: 8px; font-size: 1rem; /* Tighter spacing */
}
.error-msg {
  color: var(--accent-red); margin-top: 12px; font-size: 0.9rem;
}


input:focus, select:focus {
  background: #fff; border-color: var(--primary); outline: none;
  box-shadow: 0 0 0 3px rgba(74, 59, 50, 0.1);
}

/* Hide Number Spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none; appearance: none; margin: 0;
}
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }

/* Input Group - for prefixed inputs like $ */
.input-group { 
  position: relative; 
  width: 100%; 
  display: flex;
  align-items: center;
}
.input-group .prefix {
  position: absolute; 
  left: 12px; 
  top: 52%; /* Optical centering fix */
  transform: translateY(-50%);
  color: var(--text-muted); 
  font-weight: 700; 
  pointer-events: none;
  font-size: 0.95rem;
  line-height: normal;
}
.input-group input { padding-left: 28px; }

/* --- BUTTONS --- */
button {
  padding: 10px 16px; font-weight: 700; font-size: 0.9rem;
  border-radius: 8px; border: none; cursor: pointer;
  font-family: inherit; transition: all 0.2s cubic-bezier(0.2, 0.8, 0.2, 1);
  display: inline-flex; justify-content: center; align-items: center;
}
button:active { transform: scale(0.96); }

button.primary-btn {
  background: var(--primary); color: white;
  box-shadow: none;
}
button.primary-btn:hover {
  background: var(--primary-hover);
  transform: translateY(-1px);
  box-shadow: none;
}

button.secondary {
  background: white; color: var(--text-main);
  border: 1px solid var(--border);
  box-shadow: none;
}
button.secondary:hover {
  background: #fafaf9;
}
.auth-buttons button.secondary {
  border: 1px solid var(--border);
}

/* --- TOGGLE BUTTONS (Modal Toggle - Warm Theme) --- */
.type-toggle-container {
  display: flex; 
  background: linear-gradient(135deg, #f5f3f1 0%, #ede9e5 100%);
  padding: 4px; /* Increased padding slightly for the border look */
  border-radius: 12px; /* Slightly rounder */
  margin-bottom: 20px;
  border: 1px solid #d7ccc8; /* Darker border for visibility */
}
.type-btn {
  flex: 1; border: none; background: transparent;
  color: var(--text-muted); padding: 8px 6px; font-size: 0.85rem;
  border-radius: 8px; margin: 0; box-shadow: none;
  transition: all 0.2s ease;
  font-weight: 600;
}
.type-btn.active {
  background: white; 
  box-shadow: 0 2px 6px rgba(74, 59, 50, 0.1);
  font-weight: 700;
  border: 1px solid #d7ccc8; /* Added border for better definition */
}
#type-income.active { color: var(--accent-green); }
#type-expense.active { color: var(--primary); }

/* --- HEADER --- */
.dashboard-header {
  display: flex; justify-content: space-between; align-items: center;
  /* Reduced spacing for better vertical centering */
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border);
  line-height: normal;
}
.dash-brand { display: flex; align-items: center; gap: 10px; transition: opacity 0.2s;}
.dash-brand:hover { opacity: 0.8; }
.bread-icon { font-size: 1.4rem; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.1)); }
.dash-title {
  font-size: 1.1rem; font-weight: 800; color: var(--primary);
  letter-spacing: -0.02em;
}
.user-controls { display: flex; align-items: center; gap: 12px; }

/* User Dropdown */
.user-dropdown {
  position: relative;
}

.user-dropdown-trigger {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
}

.user-dropdown-trigger:hover {
  background: rgba(0, 0, 0, 0.04);
  border-color: var(--border);
}

.user-email-text {
  max-width: 320px; /* Increased from 240px to fit full email */
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 4px;
  min-width: 200px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(74, 59, 50, 0.15);
  z-index: 1000;
  overflow: hidden;
  animation: slideDown 0.15s ease-out;
}

@keyframes slideDown {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.dropdown-item {
  display: flex;
  align-items: center;
  justify-content: flex-start; /* Ensure left alignment */
  gap: 10px;
  width: 100%;
  padding: 12px 16px;
  background: transparent;
  border: none;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-main);
  text-decoration: none;
  cursor: pointer;
  transition: background 0.15s;
  font-family: inherit;
  text-align: left; /* Force left text alignment */
}

.dropdown-item:hover {
  background: #f9f7f5;
}

.dropdown-item svg {
  color: var(--text-muted);
  flex-shrink: 0;
}

.dropdown-logout {
  border-top: 1px solid #f0ebe5;
  color: var(--accent-red);
}

.dropdown-logout svg {
  color: var(--accent-red);
}

/* Mobile dropdown adjustments */
@media screen and (max-width: 600px) {
  .user-email-text {
    max-width: 55vw; /* Allow up to ~55% of screen width */
  }
}

/* --- CARDS --- */

.card {
  background: transparent; padding: 16px;
  border-radius: 12px;
  box-shadow: none;
  border: 2px solid var(--border);
}
.card h4 {
  font-size: 0.7rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted); margin-bottom: 4px;
}
.card p {
  font-size: clamp(1.2rem, 3vw, 1.5rem); font-weight: 800;
  margin: 0; color: var(--primary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.positive { color: var(--accent-green) !important; }
.negative { color: var(--text-main); }



/* --- SETTINGS LAYOUT --- */
.settings-group {
  margin-bottom: 24px;
}
.settings-divider {
  height: 1px;
  border-top: 1px dashed var(--border);
  margin: 30px 0;
  width: 100%;
}
.settings-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 0;
  border-bottom: 1px dashed var(--border);
}
.settings-row div {
  max-width: 70%;
}

/* --- SECTIONS --- */
.section-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px; padding-bottom: 0; border: none;
}
.section-header h3 {
  font-size: 1.1rem; font-weight: 700; color: var(--primary); margin: 0;
}
.header-actions { display: flex; gap: 8px; align-items: center; }

/* Overview section spacing */
.overview-header {
  margin-bottom: 12px;
}
#monthly-viz {
  margin-top: 8px;
}

.filter-bar {
  display: flex; 
  gap: 12px; 
  margin-bottom: 20px; 
  align-items: center;
}

.filter-bar input {
  flex: 2; 
  margin-bottom: 0; 
  height: 44px;
  padding: 0 16px; /* Use line-height/height for centering */
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.85rem !important; /* Force smaller text on mobile */
  line-height: 44px; /* Ensure vertical centering */
  transition: all 0.2s ease;
}

.filter-bar input:focus {
  background: white;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(74, 59, 50, 0.1);
}

.filter-bar select {
  flex: 1; 
  margin-bottom: 0; 
  height: 44px;
  /* Reset padding for select to accommodate fixed height */
  padding-top: 0;
  padding-bottom: 0;
  line-height: 44px;
  background: white; /* Match input background */
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 0.85rem !important;
  appearance: none;
  -webkit-appearance: none;
  padding-right: 32px;
  padding-left: 36px; /* Space for filter icon */
  background-image: 
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2378716c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolygon points='22 3 2 3 10 12.46 10 19 14 21 14 12.46 22 3'%3E%3C/polygon%3E%3C/svg%3E"),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2378716c' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat, no-repeat;
  background-position: left 12px center, right 12px center;
  background-size: 14px, 12px;
  cursor: pointer;
}

.filter-bar select:focus {
  background-color: white;
  border-color: var(--primary);
  outline: none;
}

/* --- CATEGORY LIST --- */

/* --- TABLE (DESKTOP) --- */
.month-group {
  margin-bottom: 24px;
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: white;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
}
  /* Transaction Month Header - Matches email dropdown trigger style */
/* DEFINITION MOVED TO LINE 711 */

.month-header:hover, .month-header:focus {
  background: rgba(0, 0, 0, 0.04); /* Subtle gray background */
  border-color: transparent; /* Keep border transparent to avoid jumpiness */
}

.month-header span:first-child {
  margin-right: auto;
  color: var(--text-muted);
  font-size: 0.75rem;
  /* Ensure text is vertically centered if it has line-height issues */
  display: flex;
  align-items: center;
}

.month-header span:last-of-type {
  font-feature-settings: "tnum";
  color: var(--primary);
  font-weight: 800;
}

/* Simple Down Arrow (SVG via background) */
.month-header::after {
  content: "";
  display: inline-block;
  width: 12px; 
  height: 12px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2378716c' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: contain;
  margin-left: 12px;
  transition: transform 0.2s ease;
}

.month-header[aria-expanded="true"]::after { 
  transform: rotate(0deg); 
}
.month-header[aria-expanded="false"]::after { 
  transform: rotate(-180deg); 
}

table {
  width: 100%; border-collapse: collapse;
  table-layout: fixed; /* Fix Clipping */
}
thead {
  background: #ffffff;
  border-bottom: 1px solid var(--border);
}
th {
  text-align: left;
  padding: 12px 20px;
  font-size: 0.75rem;
  font-weight: 800;
  color: var(--text-muted);
  text-transform: uppercase;
}
th:last-child,
th:nth-child(4) {
  text-align: right;
}
th, td {
  padding: 10px 14px; /* Reduced from 16px 20px */
  text-align: left;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}
tr {
  border-bottom: 1px solid #f5f5f4;
  transition: background-color 0.15s ease;
}
tbody tr:nth-child(even) {
  background-color: #fafafa;
}
tbody tr:hover {
  background-color: #ffffff;
  box-shadow: inset 0 0 0 1px rgba(74, 59, 50, 0.5), 0 4px 12px rgba(74, 59, 50, 0.1);
  position: relative;
  z-index: 10;
  transition: all 0.2s ease;
}
tbody tr:active {
  background-color: #f5f0eb;
}
td {
  padding: 14px 20px;
  vertical-align: middle;
}

/* Table Column Widths */
td:nth-child(1) { /* Date */
  color: var(--text-muted); font-size: 0.85rem; font-weight: 600; width: 10%; white-space: nowrap;
}
td:nth-child(2) { /* Desc */
  color: var(--text-main); font-weight: 600; font-size: 0.95rem; width: 50%;
  white-space: normal; overflow: visible; line-height: 1.3;
}
td:nth-child(3) { /* Cat */ width: 22%; }
td:nth-child(3) span,
.category-badge {
  padding: 4px 10px; border-radius: 8px; font-size: 0.75rem;
  font-weight: 700; display: inline-block;
  border: 1px solid rgba(0, 0, 0, 0.15); /* Darker border for definition */
  max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
td:nth-child(4) { /* Amt */
  text-align: right; font-weight: 700; font-size: 1rem; width: 18%;
  font-feature-settings: "tnum"; white-space: nowrap;
}

/* Upload Button Styling */
#trigger-upload-btn {
  background: white; border: 2px solid var(--border);
  color: var(--text-secondary); padding: 8px 14px;
  display: inline-flex; gap: 6px; align-items: center;
  border-radius: 8px; justify-content: center;
  transition: all 0.2s;
  font-size: 0.9rem;
}
#trigger-upload-btn:hover {
  border-color: var(--primary); color: var(--primary);
  box-shadow: 0 4px 12px rgba(0,0,0,0.05);
  background: white;
}
#trigger-upload-btn svg {
  flex-shrink: 0;
}

/* Visualization Header Alignment */
.viz-header {
  display: flex; justify-content: flex-start; /* Left Align */
  align-items: flex-end; margin-bottom: 20px; gap: 40px; /* Group together */
}
.viz-total-section { text-align: left; } /* Align text left too */

.actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  opacity: 0;
  transition: opacity 0.2s;
}
tr:hover .actions {
  opacity: 1;
}
.btn-action {
  padding: 6px 10px;
  font-size: 0.75rem;
  background: white;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: 8px;
  font-weight: 600;
  min-height: 32px;
}
.btn-action:hover {
  border-color: var(--primary);
  color: var(--primary);
}

/* EMPTY STATE */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-icon {
  font-size: 3rem;
  margin-bottom: 10px;
  opacity: 0.5;
  display: block;
}

/* --- MODAL --- */
/* --- MODAL REDESIGN (Unified with AI Insights) --- */
.modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  display: flex; justify-content: center; align-items: center;
  background-color: rgba(41, 37, 36, 0.4); /* Slightly lighter overlay */
  backdrop-filter: blur(16px); /* Stronger premium blur */
  z-index: 2000; padding: 20px; box-sizing: border-box;
  animation: fadeIn 0.2s ease-out;
}
.modal {
  background: #ffffff;
  padding: 0;
  border-radius: 20px; /* More rounded */
  width: 100%; max-width: 440px;
  box-shadow: 0 20px 60px -10px rgba(74, 59, 50, 0.3);
  position: relative;
  max-height: 90vh; overflow-y: auto;
  border: 1px solid #e7dfd9;
  transform: translateY(0);
  animation: slideUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  background: transparent;
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-body {
  padding: 20px 24px 24px;
}

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

.modal h3 {
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--primary);
  margin: 0;
}

.modal-actions {
  display: flex; gap: 12px; margin-top: 24px; width: 100%;
}
.modal-actions button {
  flex: 1; height: 44px; font-size: 0.95rem; border-radius: 10px;
}

/* Outline button for modals */
.btn-outline {
  padding: 10px 16px;
  font-weight: 700;
  font-size: 0.9rem;
  border-radius: 10px; /* Match modal actions radius */
  cursor: pointer;
  font-family: inherit;
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border); /* Thinner border for elegance */
  transition: all 0.2s ease;
}
.btn-outline:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: #fafaf9; /* Subtle hover bg */
}

/* Delete link in modals */
.btn-delete-link {
  display: block;
  width: 100%;
  text-align: center;
  margin-top: 16px;
  padding: 8px;
  background: transparent;
  border: none;
  color: var(--accent-red);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.2s;
}
.btn-delete-link:hover {
  opacity: 1;
}

  /* Transaction Month Header - Matches email dropdown trigger style */
.month-header {
  width: calc(100% - 8px); 
  margin: 4px auto; /* balanced top/bottom margins to 4px */
  font-size: 0.85rem; 
  font-weight: 700;
  font-family: inherit; 
  color: var(--text-secondary);
  text-transform: uppercase; 
  padding: 14px 10px; /* Reduced side padding (was 20px) to align closer to edges */
  line-height: 1; /* Force line-height to 1 to remove font leading issues */
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px; /* Consistent rounded corners */
  display: flex; 
  align-items: center; /* Fix vertical alignment */
  justify-content: space-between; 
  cursor: pointer; 
  text-align: left;
  transition: all 0.2s ease;
  letter-spacing: 0.04em;
  outline: none; /* Remove blue browser ring */
}
/* ... */
/* --- TOAST --- */
#status-toast {
  position: fixed;
  bottom: 30px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--text-main);
  color: white;
  padding: 12px 24px;
  border-radius: 50px;
  font-weight: 600;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
  display: flex;
  align-items: center;
  gap: 10px;
  z-index: 2000;
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  opacity: 0;
  width: max-content; /* Allow width to grow */
  max-width: 90vw; /* Prevent screen overflow */
  white-space: nowrap; /* Keep on one line if possible */
}
#status-toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
#status-toast.loading .status-dot {
  background-color: #fbbf24;
  animation: pulse 1s infinite;
}
#status-toast.success .status-dot {
  background-color: #4ade80;
}
#status-toast.error .status-dot {
  background-color: #f87171;
}
.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background-color: white;
}
@keyframes pulse {
  0% {
    opacity: 1;
    transform: scale(1);
  }
  50% {
    opacity: 0.5;
    transform: scale(0.8);
  }
  100% {
    opacity: 1;
    transform: scale(1);
  }
}

/* --- MOBILE OPTIMIZATION --- */
@media screen and (max-width: 600px) {
  body {
    min-height: 100vh;
    min-height: 100dvh; /* Use dynamic viewport height */
  }

  #app-container {
    padding: 16px 12px;
    min-height: auto; /* Remove min-height to allow natural sizing */
    justify-content: center; /* Center vertically */
  }

  .auth-container {
    margin: 0 auto; /* Ensure centering on mobile */
    width: calc(100% - 24px); /* Account for padding */
    max-width: 360px;
    padding: 32px 24px; /* Balanced padding */
    left: 0; right: 0; /* Clear any positioning artifacts */
    transform: none;
    position: relative;
    border-radius: 20px; /* Slightly less rounded on mobile */
  }

  /* Reduce spacing in auth elements on mobile */
  .auth-container h1 {
    font-size: 1.65rem;
    margin-bottom: 8px;
    line-height: 1.15;
  }

  .auth-container h1 span {
    font-size: 1.9rem !important; /* Smaller emoji icon */
    margin-bottom: 6px;
  }

  .auth-container .subtitle {
    margin-bottom: 8px;
    font-size: 0.9rem;
    line-height: 1.4;
  }

  /* "What is this?" link on mobile */
  .auth-container div[style*="margin-bottom"] {
    margin-bottom: 16px !important;
    margin-top: 0 !important;
  }

  .auth-container div[style*="margin-bottom"] a {
    font-size: 0.8rem !important;
  }

  .auth-buttons {
    margin-top: 16px; /* Consistent spacing */
    gap: 10px;
  }

  .auth-buttons button {
    padding: 11px 16px;
    font-size: 0.9rem;
  }

  .input-label {
    margin: 16px 0 6px 0;
    font-size: 0.7rem;
  }

  .auth-container input[type="email"],
  .auth-container input[type="password"] {
    padding: 11px 12px;
    font-size: 16px !important; /* Prevent zoom on iOS */
    margin-bottom: 0;
  }

  .error-msg {
    margin-top: 12px;
    font-size: 0.875rem;
  }

  /* Ensure footer doesn't interfere */
  .site-footer {
    margin-top: 24px;
    padding: 20px 0 32px;
    padding-bottom: max(32px, env(safe-area-inset-bottom));
  }

  /* Fixed Mobile Navbar */
  .dashboard-header {
    flex-direction: row; 
    align-items: center; /* Ensures vertical centering */
    justify-content: space-between;
    gap: 0; 
    margin-bottom: 24px;
    height: auto; /* Allow natural height */
  }
  .user-controls {
    display: flex; 
    align-items: center; /* Ensures text aligns with icon */
    gap: 12px;
    background: transparent; 
    border: none; 
    padding: 0; 
    width: auto;
    font-size: 0.9rem; /* Match header size for visual balance */
  }



  /* Mobile Viz Header Fix */
  .viz-header {
    align-items: baseline; 
    margin-bottom: 16px;
  }
  .viz-month-select {
    font-size: 1.1rem; 
    padding-right: 18px; /* Tighter arrow gap */
    transform: translateY(1px);
    background-position: right 0 center; /* Fix arrow pos */
  }
  .viz-big-number {
    font-size: 1.5rem; line-height: 1;
  }
  
  /* Mobile Search Bar */

  
  /* Month Header Mobile Overrides */

  .month-group {
    background: transparent; border: none; box-shadow: none; border-radius: 0;
    margin-bottom: 16px;
  }


  .filter-bar {
    flex-direction: row;
    flex-wrap: wrap;
    margin-bottom: 12px;
  }
  .filter-bar input {
    flex: 2;
    height: 38px;
    line-height: normal; /* Allow padding to center or use explicit line-height if needed. 38px is small. */
    /* Previous cutoff was due to 16px font + small height. Now font is 0.85rem (~13.6px), so it should fit better. */
    /* Let's try explicit line-height to force centering similar to desktop */
    line-height: 38px; 
    padding: 0 12px; /* Reduce side padding for mobile */
  }
  .filter-bar select {
    flex: 1;
    height: 38px;
    line-height: 38px;
    padding-top: 0;
    padding-bottom: 0;
  }

  thead {
    display: none;
  }
  .month-group {
    background: transparent;
    border: none;
    box-shadow: none;
  }


  /* Single-line mobile transaction cards with color dot */
  /* Single-line mobile transaction cards - Copilot Style */
  tr {
    display: flex;
    align-items: center;
    justify-content: space-between; /* Ensure outer items hit the edges */
    gap: 4px; /* Minimal gap */
    background: #ffffff !important;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 8px; /* Reduce outer padding */
    margin-bottom: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
    min-height: 48px;
    overflow: hidden; /* Prevent overflow */
  }

  /* Chevron to indicate clickable */
  tr::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 10px;
    margin-left: 8px; /* Space from amount */
    margin-right: 4px; /* Right padding */
    flex-shrink: 0;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 6 10' fill='none' stroke='%23a8a29e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='1 1 5 5 1 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: center;
    background-size: contain;
    opacity: 0.8;
  }

  /* Date - Hide on mobile */
  td:nth-child(1) {
    display: none;
    border-bottom: none;
  }

  /* Description - Primary content (Flex Grow) */
  td:nth-child(2) {
    flex: 1 1 auto; /* Grow and shrink */
    width: 0; /* Critical for truncation in flex */
    font-size: 0.9rem;
    font-weight: 600;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-main);
    border-bottom: none;
    line-height: normal;
    padding: 0 0 0 4px; /* Small left padding */
    text-align: left;
    margin-right: 4px; /* Reduced margin */
  }

  /* Category Column - Fixed Width Container - LEFT ALIGNED */
  td:nth-child(3) {
    display: flex;
    justify-content: flex-start; /* Left align pills */
    align-items: center;
    flex-shrink: 0;
    width: 82px; /* Tighter yardstick for "Transportation" */
    border-bottom: none;
    padding: 0;
  }

  /* Category Pill - Auto sized within column */
  td:nth-child(3) span {
    font-size: 0.6rem; /* Slightly smaller text for fit */
    padding: 3px 6px;
    border-radius: 5px;
    max-width: 100%;
    width: auto;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
  }

  /* Amount - Fixed to right */
  td:nth-child(4) {
    font-size: 0.9rem;
    font-weight: 750;
    white-space: nowrap;
    text-align: right;
    flex-shrink: 0; /* Never shrink */
    border-bottom: none;
    padding: 0 4px 0 0; /* Small right padding */
    margin-left: auto; /* Push to far right if flex spacing behaves oddly */
    min-width: unset; /* Remove min-width to avoid overflow */

  }

  /* Actions - hidden */
  td:nth-child(5) {
    display: none;
    border-bottom: none;
  }

  .actions {
    opacity: 1;
    display: flex;
    flex-direction: row;
    gap: 6px;
  }
  .btn-action {
    padding: 2px 6px;
    font-size: 0.65rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.02em;
    font-weight: 700;
    box-shadow: none;
    min-height: 24px;
  }
  .btn-action:hover {
    background: transparent;
    color: var(--primary);
    border: none;
  }
  .btn-del {
    color: var(--accent-red);
    opacity: 0.8;
  }
}

/* Settings Icon Button */
.icon-btn {
  display: flex; align-items: center; justify-content: center;
  width: 36px; height: 36px; /* Square button */
  border-radius: 8px; /* Match standard radius */
  color: var(--text-muted); /* Default muted */
  background: transparent; /* No background default */
  border: 1px solid transparent;
  transition: all 0.2s;
}
.icon-btn:hover {
  background: #e7e5e4; /* Light gray on hover */
  color: var(--text-main);
  box-shadow: none;
}
.icon-btn svg { stroke-width: 2px; width: 18px; height: 18px; }

/* Helper to hide email on mobile */
.desktop-only {
  display: inline-block;
  margin-right: 10px;
}
@media screen and (max-width: 600px) {
  .desktop-only {
    display: none;
  }
}

/* --- AI INSIGHTS CARD --- */
.insights-card {
  background: linear-gradient(135deg, #fafaf9 0%, #f5f5f4 100%); /* Neutral Stone */
  border: 1px solid #d6d3d1; /* Darker Stone 300 Border */
  border-radius: 12px;
  padding: 16px 20px;
  margin-bottom: 24px;
  animation: fadeIn 0.5s ease-out;
}

.insights-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.insights-icon {
  width: 1rem;
  height: 1rem;
  color: var(--primary); /* Strong contrast: #4a3b32 on light gray */
}

.insights-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary); /* Darker Neutral Text for Readability */
}

.insights-refresh {
  margin-left: auto;
  background: transparent;
  border: none;
  padding: 6px;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0.6;
  transition: all 0.2s;
}

.insights-refresh:hover {
  opacity: 1;
  background: rgba(0,0,0,0.05);
}

.insights-refresh:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.insights-body {
  font-size: 0.95rem;
  line-height: 1.5;
  color: var(--text-secondary); /* Neutral body text */
  margin: 0;
}

.insights-body.loading {
  color: var(--text-muted);
  font-style: italic;
}

.insights-body.error {
  color: var(--accent-red);
}

/* --- MONTHLY VIZ (NATIVE) --- */
#monthly-viz {
  margin-bottom: 30px;
  animation: fadeIn 0.5s ease-out;
}

.viz-card {
  background: transparent;
  color: var(--text-main);
  padding: 0;
  box-shadow: none;
  border-radius: 0;
}

/* Header Section - Month Dropdown as Header */
.viz-header {
  margin-bottom: 16px;
}

/* Stat Cards Row - 3 cards sharing a row */
.stat-cards-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}

.stat-card-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.stat-card-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

.stat-card-value {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--primary);
  font-feature-settings: "tnum";
}

.stat-card-value.positive {
  color: var(--accent-green);
}

.stat-card-value.negative {
  color: var(--accent-red);
}

.stat-card-ticker {
  font-size: 0.7rem;
  font-weight: 700;
}

/* Legacy viz-header elements (can be removed later) */
.viz-header-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.viz-title-row {
  display: flex;
  align-items: baseline;
  gap: 0;
  flex-wrap: nowrap; /* Keep on one line */
}

.viz-title-label {
  font-size: 1.1rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
}

.viz-total-inline {
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.viz-big-number {
  font-size: 2.25rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}

.viz-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  font-weight: 700;
}
.viz-trend.up { color: var(--accent-red); }
.viz-trend.down { color: var(--accent-green); }
.viz-trend.neutral { color: var(--text-muted); }

/* Summary Row - text only, inline */
.viz-summary-inline {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.viz-stat {
  display: flex;
  align-items: center;
  gap: 6px;
}

.viz-stat-label {
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.7rem;
  letter-spacing: 0.05em;
}

.viz-stat span:not(.viz-stat-label) {
  font-weight: 700;
  color: var(--primary);
}
.viz-stat span.positive { color: var(--accent-green); }
.viz-stat span.negative { color: var(--accent-red); }

.viz-stat-divider {
  color: var(--border);
  font-size: 0.8rem;
}

/* Month dropdown container with inline arrow */
/* Month dropdown container (TEXT + ICON + OVERLAY) */
.viz-month-container {
  position: relative;
  display: inline-flex;
  align-items: baseline;
  cursor: pointer;
  transition: opacity 0.2s;
}

.viz-month-container:hover {
  opacity: 0.7;
}

.viz-month-text {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  letter-spacing: -0.02em;
  line-height: 1;
}

.viz-month-arrow-icon {
  margin-left: 6px;
  color: var(--primary);
  flex-shrink: 0;
  position: relative;
  top: 5px; /* Offset for optical baseline alignment */
  margin-bottom: 0;
}

.viz-month-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
}

.viz-month-select option {
  font-size: 1rem;
  font-weight: 600;
  padding: 8px;
  text-align: left;
}

.viz-label {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: block;
}
.viz-big-number {
  font-size: 2rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
}
.viz-trend {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.8rem;
  font-weight: 700;
  margin-top: 4px;
}
.viz-trend.up { color: var(--accent-red); }
.viz-trend.down { color: var(--accent-green); }
.viz-trend.neutral { color: var(--text-muted); }

/* Spending Breakdown Section Header */
.viz-breakdown-header {
  margin-bottom: 12px;
}

.viz-breakdown-title {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
}

/* Segmented Bar - Clean Style */
.viz-bar-container {
  height: 48px; /* Taller to accommodate internal padding */
  background: white; 
  border: 1px solid var(--border); 
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.05); 
  border-radius: 12px; /* Consistent app radius */
  display: flex;
  overflow: hidden;
  margin-bottom: 24px;
  padding: 5px; /* Padding creates the "tube" effect */
  gap: 0; 
  align-items: center;
}
.viz-segment {
  height: 100%;
  border-radius: 0; /* Rectangular by default */
  transition: all 0.6s cubic-bezier(0.22, 1, 0.36, 1);
  box-shadow: 0 1px 2px rgba(0,0,0,0.1); /* Subtle shadow on the segments */
  margin-right: 3px; /* Consistent gap matching outer padding */
  cursor: pointer; /* Clickable */
}
.viz-segment:first-child {
  border-top-left-radius: 8px; /* inner radius (12-4ish) */
  border-bottom-left-radius: 8px;
}
.viz-segment:last-child {
  margin-right: 0;
  border-top-right-radius: 8px;
  border-bottom-right-radius: 8px;
}
.viz-segment:first-child:last-child {
  border-radius: 8px;
}
/* Use opacity for pastel look */
.viz-segment:hover {
  filter: brightness(0.8); /* Much darker on hover */
  transform: scaleY(1.05); /* Slight pop */
}

/* Legend Grid */
.viz-legend {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.viz-item {
  /* Category cards - styled consistently with AI Insights */
  background: white;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  transition: all 0.2s ease;
  cursor: pointer; /* Clickable */
}
.viz-item:hover {
  border-color: rgba(74, 59, 50, 0.5); /* Softened outline */
  box-shadow: 0 4px 12px rgba(74, 59, 50, 0.15);
}

.viz-color-pill {
  width: 4px;
  height: 32px;
  border-radius: 4px;
}

.viz-info {
  flex: 1;
}
.viz-row-top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
  align-items: center;
}
.viz-cat-name {
  font-size: 0.8rem; font-weight: 700; color: var(--text-main);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 140px;
}
.viz-cat-pct {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}
.viz-row-bot {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}
.viz-cat-amt {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--primary);
}
.viz-cat-change {
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 2px;
}

/* Animations */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@media screen and (max-width: 600px) {
  /* --- Viz Legend & Items (Mobile) - Keep 2 columns --- */
  .viz-legend {
    display: grid;
    grid-template-columns: repeat(2, 1fr); /* Back to 2 columns */
    gap: 8px;
  }
  /* Removed span 2 for last child to keep consistent grid sizing */
  .viz-item {
    padding: 10px 12px;
    border-radius: 10px;
  }
  
  /* ... Viz Header Mobile ... */
  .viz-header {
    gap: 12px;
  }
  
  .viz-header-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  
  .viz-total-inline {
    width: 100%;
    justify-content: space-between;
    align-items: center;
  }

  .viz-big-number {
    font-size: 1.5rem;
  }
  
  .viz-summary-inline {
    flex-wrap: wrap;
    gap: 8px 12px;
    font-size: 0.8rem;
  }
  
  .viz-stat-divider {
    display: none;
  }
  
  .viz-month-text {
    font-size: 1.25rem;
  }

  /* Mobile stat cards - stack or fit in row */
  .stat-cards-row {
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
  }
  
  .stat-card {
    padding: 10px 12px;
  }
  
  .stat-card-value {
    font-size: 1rem;
  }
  
  /* Stack Value and Ticker on Mobile */
  .stat-card-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
  }
  .stat-card-ticker {
    font-size: 0.65rem; /* Smaller ticker on mobile */
  }
}

/* Footer */
.site-footer {
  text-align: center;
  padding: 24px 0 40px; /* Base padding */
  padding-bottom: env(safe-area-inset-bottom, 40px); /* Adjust for iPhone home bar */
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 500;
  border-top: 1px solid transparent; 
  margin-top: auto; /* Push to bottom */
}

/* Tooltip Styling */
.viz-tooltip {
  position: fixed;
  background: rgba(255, 255, 255, 0.98); /* Light Mode */
  color: var(--text-main);
  padding: 8px 12px; /* Slightly more padding */
  border-radius: 8px;
  font-size: 0.75rem; /* Smaller text */
  pointer-events: none;
  z-index: 10000;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12); /* Softer shadow */
  opacity: 0;
  transform: translate(-50%, -100%); /* Position ABOVE the cursor */
  margin-top: -16px; /* Offset from cursor */
  min-width: 160px; /* Increased width */
  max-width: 280px; /* Increased width */
  backdrop-filter: blur(4px);
  border: 1px solid var(--border);
  transition: opacity 0.1s ease, transform 0.1s ease;
}
.viz-tooltip.visible { 
  opacity: 1; 
  /* No transform change needed if we rely on left/top updates, 
     but we can add a subtle slide effect if desired. 
     For now, keep simple to avoid fighting JS. */
}
.viz-tooltip-header {
  font-weight: 800;
  margin-bottom: 4px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--border);
  display: flex; 
  justify-content: space-between;
  align-items: center;
  gap: 16px; /* Added significant gap */
}
.viz-tooltip-header .amt {
  color: var(--accent-green);
  font-feature-settings: "tnum";
}
.viz-tooltip-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.viz-tooltip-row {
  display: flex; 
  justify-content: space-between;
  font-size: 0.7rem; /* Smaller row text */
  color: var(--text-secondary);
}
.viz-tooltip-row span:last-child {
  font-weight: 700;
  color: var(--text-main);
  font-feature-settings: "tnum";
}

/* Hide tooltips on mobile */
@media screen and (max-width: 600px) {
  .viz-tooltip {
    display: none !important;
  }
}
