/* Design Tokens & Theme Variables */
:root {
  /* Font Family */
  --font-heading: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-body: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Colors (Light Theme Defaults) */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  
  --text-primary: #0f172a;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  
  --accent-color: #2563eb;
  --accent-light: #eff6ff;
  
  --success-color: #10b981;
  --success-light: #ecfdf5;
  --warning-color: #f59e0b;
  --danger-color: #ef4444;

  /* Glassmorphism & Shadow Tokens */
  --card-border: rgba(226, 232, 240, 0.8);
  --card-shadow: 0 10px 30px -10px rgba(15, 23, 42, 0.04), 0 1px 3px rgba(15, 23, 42, 0.02);
  --shadow-hover: 0 20px 40px -15px rgba(15, 23, 42, 0.08), 0 1px 5px rgba(15, 23, 42, 0.03);
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  
  /* Supermarket Specific Colors */
  --color-walmart: #0071dc;
  --color-soriana: #e21838;
  --color-chedraui: #ff8200;
  --color-aurrera: #4ab93b;
  
  --color-walmart-light: rgba(0, 113, 220, 0.08);
  --color-soriana-light: rgba(226, 24, 56, 0.08);
  --color-chedraui-light: rgba(255, 130, 0, 0.08);
  --color-aurrera-light: rgba(74, 185, 59, 0.08);

  --transition-fast: 0.2s ease;
  --transition-normal: 0.3s ease;
}

/* Dark Theme Variables */
[data-theme="dark"] {
  --bg-primary: #0b0f19;
  --bg-secondary: #131b2e;
  --bg-tertiary: #1e293b;
  
  --text-primary: #f8fafc;
  --text-secondary: #cbd5e1;
  --text-muted: #64748b;
  
  --accent-color: #3b82f6;
  --accent-light: rgba(59, 130, 246, 0.15);
  
  --success-color: #10b981;
  --success-light: rgba(16, 185, 129, 0.12);
  
  --card-border: rgba(51, 65, 85, 0.5);
  --card-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.3), 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-hover: 0 20px 40px -15px rgba(0, 0, 0, 0.4), 0 1px 5px rgba(0, 0, 0, 0.15);
  
  --color-walmart-light: rgba(0, 113, 220, 0.18);
  --color-soriana-light: rgba(226, 24, 56, 0.18);
  --color-chedraui-light: rgba(255, 130, 0, 0.18);
  --color-aurrera-light: rgba(74, 185, 59, 0.18);
}

/* Base resets & typography */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-secondary);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  position: relative;
  overflow-x: hidden;
  line-height: 1.5;
  transition: background-color var(--transition-normal), color var(--transition-normal);
}

h1, h2, h3, h4, h5, h6 {
  font-family: var(--font-heading);
  color: var(--text-primary);
  font-weight: 700;
  line-height: 1.25;
}

/* Background Glow Effect */
.glow-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 600px;
  pointer-events: none;
  z-index: -1;
  overflow: hidden;
}

.glow-circle {
  position: absolute;
  filter: blur(140px);
  border-radius: 50%;
  opacity: 0.15;
}

.glow-1 {
  width: 400px;
  height: 400px;
  background: var(--accent-color);
  top: -100px;
  right: 10%;
}

.glow-2 {
  width: 350px;
  height: 350px;
  background: var(--success-color);
  top: 100px;
  left: 5%;
}

/* App Header */
.app-header {
  background: rgba(var(--bg-secondary), 0.8);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--card-border);
  position: sticky;
  top: 0;
  z-index: 100;
  padding: 12px 0;
  transition: background var(--transition-normal), border var(--transition-normal);
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo-icon {
  font-size: 28px;
  background: var(--accent-light);
  width: 48px;
  height: 48px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-md);
  box-shadow: 0 4px 10px rgba(37, 99, 235, 0.1);
}

.brand h1 {
  font-size: 22px;
  font-weight: 800;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--text-primary) 30%, var(--accent-color));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.subtitle {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-top: 1px;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 16px;
}

.update-date {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
  background: var(--bg-tertiary);
  padding: 6px 12px;
  border-radius: 20px;
  border: 1px solid var(--card-border);
}

/* Main Container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 24px 80px;
  display: flex;
  flex-direction: column;
  gap: 40px;
}

/* Buttons and Controls */
.btn-icon {
  background: var(--bg-tertiary);
  border: 1px solid var(--card-border);
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  background: var(--accent-light);
  color: var(--accent-color);
  border-color: var(--accent-color);
  transform: scale(1.05);
}

.btn-icon svg {
  width: 20px;
  height: 20px;
}

.sun-icon { display: block; }
.moon-icon { display: none; }

[data-theme="dark"] .sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: block; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
}

.btn-secondary {
  background: var(--bg-secondary);
  border-color: var(--card-border);
  color: var(--text-primary);
  box-shadow: var(--card-shadow);
}

.btn-secondary:hover {
  background: var(--bg-tertiary);
  transform: translateY(-1px);
}

.btn-secondary.active {
  background: var(--accent-light);
  color: var(--accent-color);
  border-color: var(--accent-color);
}

.btn-tertiary {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 12px;
}

.btn-tertiary:hover {
  color: var(--danger-color);
}

/* Hero Section */
.hero-section {
  text-align: center;
  max-width: 800px;
  margin: 0 auto;
}

.hero-section h2 {
  font-size: 32px;
  margin-bottom: 12px;
  letter-spacing: -0.5px;
}

.hero-section p {
  font-size: 16px;
  color: var(--text-secondary);
}

/* Sections General */
.section-title {
  font-size: 20px;
  font-weight: 700;
  margin-bottom: 18px;
  position: relative;
  padding-left: 14px;
}

.section-title::before {
  content: '';
  position: absolute;
  left: 0;
  top: 4px;
  bottom: 4px;
  width: 4px;
  background: var(--accent-color);
  border-radius: 2px;
}

/* Store summary cards */
.store-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 20px;
}

.store-card {
  background: var(--bg-secondary);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: transform var(--transition-normal), box-shadow var(--transition-normal);
  position: relative;
  overflow: hidden;
}

.store-card::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 100%;
}

.store-card.walmart::after { background: var(--color-walmart); }
.store-card.soriana::after { background: var(--color-soriana); }
.store-card.chedraui::after { background: var(--color-chedraui); }
.store-card.aurrera::after { background: var(--color-aurrera); }

.store-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-hover);
}

.store-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.store-logo-name {
  font-weight: 700;
  font-size: 16px;
}

.store-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  text-transform: uppercase;
}

.badge-walmart { background: var(--color-walmart); }
.badge-soriana { background: var(--color-soriana); }
.badge-chedraui { background: var(--color-chedraui); }
.badge-aurrera { background: var(--color-aurrera); }

.store-wins {
  display: flex;
  align-items: baseline;
  gap: 6px;
}

.wins-count {
  font-size: 36px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1;
}

.wins-label {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 500;
}

.store-details {
  font-size: 12px;
  color: var(--text-muted);
}

.store-card.winner-banner {
  border-color: var(--success-color);
  background: linear-gradient(145deg, var(--bg-secondary) 80%, var(--success-light));
}

.store-card.winner-banner .wins-count {
  color: var(--success-color);
}

.crown-winner {
  position: absolute;
  top: 15px;
  right: 15px;
  font-size: 20px;
}

/* Controls section: search and filters */
.controls-section {
  background: var(--bg-secondary);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--card-shadow);
}

.controls-wrapper {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
  width: 100%;
}

.search-icon {
  position: absolute;
  left: 16px;
  color: var(--text-muted);
  width: 20px;
  height: 20px;
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 14px 16px 14px 48px;
  background: var(--bg-tertiary);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 15px;
  color: var(--text-primary);
  transition: all var(--transition-fast);
}

.search-box input:focus {
  outline: none;
  background: var(--bg-secondary);
  border-color: var(--accent-color);
  box-shadow: 0 0 0 4px var(--accent-light);
}

.filter-categories {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.filter-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--card-border);
  color: var(--text-secondary);
  padding: 8px 14px;
  font-family: var(--font-body);
  font-size: 13px;
  font-weight: 600;
  border-radius: 20px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.filter-btn:hover {
  background: var(--card-border);
  color: var(--text-primary);
}

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

/* Table Section */
.table-section {
  background: var(--bg-secondary);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--card-shadow);
  overflow: hidden;
}

.table-header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}

.table-actions {
  display: flex;
  gap: 10px;
}

.table-responsive-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--card-border);
}

.prices-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 14px;
}

.prices-table thead th {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  font-weight: 700;
  padding: 14px 16px;
  border-bottom: 2px solid var(--card-border);
  white-space: nowrap;
}

.prices-table tbody td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--card-border);
  vertical-align: middle;
  transition: background-color var(--transition-fast);
}

.prices-table tbody tr:last-child td {
  border-bottom: none;
}

.prices-table tbody tr:hover td {
  background-color: rgba(var(--bg-tertiary), 0.3);
}

/* Sticky first column for mobile usability */
.col-product {
  min-width: 180px;
}

.prices-table tbody td:first-child {
  font-weight: 600;
  color: var(--text-primary);
}

/* Responsive Sticky Product Column */
@media (max-width: 768px) {
  .prices-table thead th:first-child,
  .prices-table tbody td:first-child {
    position: sticky;
    left: 0;
    z-index: 10;
    background-color: var(--bg-secondary);
    box-shadow: 4px 0 8px -4px rgba(0, 0, 0, 0.1);
  }
  
  .prices-table thead th:first-child {
    background-color: var(--bg-tertiary);
  }
}

.col-category {
  color: var(--text-muted);
  font-size: 12px;
  text-transform: capitalize;
}

.col-store {
  font-weight: 600;
}

.price-val {
  padding: 6px 10px;
  border-radius: 6px;
  display: inline-block;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.price-val.best {
  color: var(--success-color);
  background: var(--success-light);
  font-weight: 700;
}

.price-val.best::after {
  content: ' 👑';
  font-size: 11px;
}

.price-val.na {
  color: var(--text-muted);
  font-style: italic;
  font-weight: 400;
}

/* Edit Mode styling */
.edit-active .price-val {
  border: 1px dashed var(--accent-color);
  background: rgba(37, 99, 235, 0.03);
}

.edit-active .price-val:hover {
  background: var(--accent-light);
  border-style: solid;
}

.price-input {
  width: 70px;
  padding: 4px 6px;
  font-family: var(--font-body);
  font-size: 14px;
  font-weight: 600;
  border: 2px solid var(--accent-color);
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-primary);
}

/* Cart Column */
.col-cart {
  text-align: center;
  min-width: 130px;
}

.cart-controls {
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--card-border);
  border-radius: 6px;
  background: var(--bg-tertiary);
  overflow: hidden;
  height: 32px;
}

.cart-btn {
  background: transparent;
  border: none;
  width: 32px;
  height: 100%;
  cursor: pointer;
  font-size: 16px;
  font-weight: 700;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
}

.cart-btn:hover {
  background: var(--card-border);
  color: var(--text-primary);
}

.cart-qty {
  width: 36px;
  text-align: center;
  font-weight: 700;
  font-size: 13px;
  border: none;
  background: transparent;
  color: var(--text-primary);
}

.cart-qty:focus {
  outline: none;
}

.edit-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 12px;
  font-style: italic;
}

/* Cart Calculator Section */
.cart-calculator-section {
  background: var(--bg-secondary);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--card-shadow);
}

.cart-layout {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 24px;
  margin-top: 10px;
}

@media (max-width: 900px) {
  .cart-layout {
    grid-template-columns: 1fr;
  }
}

.cart-items-panel, .cart-comparison-panel {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.cart-items-panel h4, .cart-comparison-panel h4 {
  font-size: 16px;
  border-bottom: 1px solid var(--card-border);
  padding-bottom: 8px;
}

.cart-items-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 320px;
  overflow-y: auto;
  padding-right: 6px;
}

.empty-cart-text {
  color: var(--text-muted);
  font-style: italic;
  font-size: 14px;
  text-align: center;
  padding: 40px 0;
}

.cart-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.cart-item-info {
  display: flex;
  flex-direction: column;
}

.cart-item-name {
  font-weight: 600;
  color: var(--text-primary);
}

.cart-item-qty {
  font-size: 11px;
  color: var(--text-muted);
}

.cart-item-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.cart-item-remove {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 2px;
  border-radius: 4px;
  transition: all var(--transition-fast);
}

.cart-item-remove:hover {
  color: var(--danger-color);
  background: rgba(239, 68, 68, 0.08);
}

.totals-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.total-store-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  border: 2px solid transparent;
  transition: all var(--transition-normal);
}

.total-store-row.winner {
  background: var(--success-light);
  border-color: var(--success-color);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.1);
}

.total-store-row.winner .total-amount {
  color: var(--success-color);
  font-size: 20px;
}

.total-store-name {
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.total-amount {
  font-family: var(--font-heading);
  font-size: 18px;
  font-weight: 800;
  color: var(--text-primary);
}

.total-amount.na {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 400;
}

.saving-alert {
  background: var(--accent-light);
  border: 1px solid var(--accent-color);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.saving-alert strong {
  color: var(--accent-color);
}

/* Locations Section */
.locations-section {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.locations-intro {
  font-size: 14px;
}

.locations-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
}

.location-card {
  background: var(--bg-secondary);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-md);
  padding: 24px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: transform var(--transition-normal);
}

.location-card:hover {
  transform: translateY(-2px);
}

.location-card h4 {
  font-size: 17px;
  margin-top: 4px;
}

.address {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.4;
  flex-grow: 1;
}

.maps-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--card-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: all var(--transition-fast);
}

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

/* Toast Notifications */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--bg-secondary);
  color: var(--text-primary);
  border: 1px solid var(--card-border);
  border-left: 4px solid var(--accent-color);
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
  font-size: 13px;
  font-weight: 600;
  z-index: 1000;
  opacity: 0;
  transform: translateY(20px);
  pointer-events: none;
  transition: all var(--transition-normal);
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

/* Footer styling */
.app-footer {
  border-top: 1px solid var(--card-border);
  padding: 30px 24px;
  background: var(--bg-secondary);
}

.footer-content {
  max-width: 1200px;
  margin: 0 auto;
  text-align: center;
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.disclaimer {
  max-width: 800px;
  margin: 0 auto;
  line-height: 1.6;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--card-border);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
