/* ============================================================
   Martin Farmstead Grocery — Dark Theme
   Mobile-first responsive design (375px iPhone base)
   ============================================================ */

/* --- CSS Variables --- */
:root {
  --bg: #0d1117;
  --bg-card: #161b22;
  --bg-card-alt: #1c2333;
  --border: #30363d;
  --text: #e6edf3;
  --text-muted: #7d8590;
  --green: #3fb950;
  --green-dark: #238636;
  --orange: #f0883e;
  --red: #f85149;
  --yellow: #d29922;
  --blue: #58a6ff;

  /* Store brand colors */
  --store-stop-and-shop: #d32f2f;
  --store-big-y: #1565c0;
  --store-shoprite: #2e7d32;
  --store-geisslers: #f57c00;
  --store-aldi: #0277bd;

  /* Layout */
  --sidebar-width: 240px;
  --header-height: 56px;
  --radius: 8px;
  --radius-lg: 12px;
  --transition: 0.2s ease;
}

/* --- Reset & Base --- */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  overflow-x: hidden;
}

a {
  color: var(--blue);
  text-decoration: none;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  font-size: inherit;
}

/* --- Layout Shell --- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-brand {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-brand .brand-icon {
  font-size: 24px;
}

.sidebar-brand .brand-text {
  font-size: 15px;
  font-weight: 600;
  color: var(--green);
  line-height: 1.2;
}

.sidebar-brand .brand-sub {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  min-height: 44px;
  font-size: 14px;
  color: var(--text-muted);
  transition: all var(--transition);
  cursor: pointer;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}

.nav-item:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.nav-item.active {
  color: var(--text);
  background: rgba(63, 185, 80, 0.1);
  border-right: 3px solid var(--green);
}

.nav-item .nav-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
  flex-shrink: 0;
}

.nav-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 16px;
}

.nav-section-label {
  padding: 8px 20px 4px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
}

.nav-private {
  display: none;
}

.nav-private.authed {
  display: block;
}

/* Sidebar overlay for mobile */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

.sidebar-overlay.open {
  display: block;
}

/* --- Main Content --- */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* --- Header --- */
.header {
  position: sticky;
  top: 0;
  height: var(--header-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 12px;
  z-index: 50;
}

.hamburger {
  display: none;
  width: 44px;
  height: 44px;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border-radius: var(--radius);
  flex-shrink: 0;
}

.hamburger:hover {
  background: rgba(255, 255, 255, 0.06);
}

.header-title {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- Store Quick-Switch Bar --- */
.store-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.store-bar::-webkit-scrollbar {
  display: none;
}

.store-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  min-height: 44px;
  border-radius: 22px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  transition: all var(--transition);
  flex-shrink: 0;
}

.store-btn:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.store-btn.active {
  color: #fff;
  border-color: transparent;
}

.store-btn[data-store="all"].active {
  background: var(--green-dark);
}

.store-btn[data-store="stop_and_shop"].active {
  background: var(--store-stop-and-shop);
}

.store-btn[data-store="big_y"].active {
  background: var(--store-big-y);
}

.store-btn[data-store="shoprite"].active {
  background: var(--store-shoprite);
}

.store-btn[data-store="geisslers"].active {
  background: var(--store-geisslers);
}

.store-btn[data-store="aldi"].active {
  background: var(--store-aldi);
}

.store-btn .store-count {
  background: rgba(255, 255, 255, 0.2);
  padding: 1px 7px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

/* --- Page Content --- */
.page-content {
  flex: 1;
  padding: 20px;
}

/* --- View Containers --- */
.view {
  display: none;
}

.view.active {
  display: block;
}

/* --- Section Headers --- */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.section-title {
  font-size: 18px;
  font-weight: 600;
}

.section-link {
  font-size: 13px;
  color: var(--blue);
  min-height: 44px;
  display: inline-flex;
  align-items: center;
}

/* --- Category Filter Pills --- */
.category-filters {
  display: flex;
  gap: 8px;
  padding-bottom: 16px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.category-filters::-webkit-scrollbar {
  display: none;
}

.cat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  min-height: 40px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  transition: all var(--transition);
  flex-shrink: 0;
  cursor: pointer;
}

.cat-pill:hover {
  border-color: var(--text-muted);
  color: var(--text);
}

.cat-pill.active {
  background: var(--green-dark);
  border-color: var(--green-dark);
  color: #fff;
}

.cat-pill .cat-icon {
  font-size: 15px;
}

/* --- Deal Card Grid --- */
.deal-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

/* --- Deal Card --- */
.deal-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  display: flex;
  gap: 12px;
  transition: border-color var(--transition), transform var(--transition);
}

.deal-card:hover {
  border-color: var(--text-muted);
}

/* Score Badge */
.deal-score {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  flex-shrink: 0;
  color: #fff;
}

.deal-score.score-high {
  background: var(--green-dark);
  box-shadow: 0 0 12px rgba(63, 185, 80, 0.3);
}

.deal-score.score-mid {
  background: #6e4e1e;
  box-shadow: 0 0 12px rgba(210, 153, 34, 0.2);
}

.deal-score.score-low {
  background: #30363d;
}

/* Deal Body */
.deal-body {
  flex: 1;
  min-width: 0;
}

.deal-top-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 4px;
  flex-wrap: wrap;
}

.deal-store-pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}

.deal-store-pill.store-stop_and_shop { background: var(--store-stop-and-shop); }
.deal-store-pill.store-big_y { background: var(--store-big-y); }
.deal-store-pill.store-shoprite { background: var(--store-shoprite); }
.deal-store-pill.store-geisslers { background: var(--store-geisslers); }
.deal-store-pill.store-aldi { background: var(--store-aldi); }

.deal-type-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-muted);
}

.deal-type-badge.type-bogo { background: rgba(248, 81, 73, 0.15); color: var(--red); }
.deal-type-badge.type-multi { background: rgba(88, 166, 255, 0.15); color: var(--blue); }
.deal-type-badge.type-pct { background: rgba(63, 185, 80, 0.15); color: var(--green); }

.deal-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 6px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.deal-price-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.deal-sale-price {
  font-size: 20px;
  font-weight: 700;
  color: var(--green);
}

.deal-orig-price {
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: line-through;
}

.deal-pct-off {
  font-size: 12px;
  font-weight: 600;
  color: var(--red);
  background: rgba(248, 81, 73, 0.1);
  padding: 1px 6px;
  border-radius: 4px;
}

.deal-meta {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.deal-category-icon {
  font-size: 14px;
}

/* --- Dashboard Stats --- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stat-value {
  font-size: 24px;
  font-weight: 700;
}

.stat-value.green { color: var(--green); }
.stat-value.orange { color: var(--orange); }
.stat-value.blue { color: var(--blue); }
.stat-value.red { color: var(--red); }

/* --- Pantry Alerts --- */
.alert-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.alert-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  min-height: 44px;
}

.alert-item.alert-low {
  border-left: 3px solid var(--orange);
}

.alert-item.alert-expired {
  border-left: 3px solid var(--red);
}

.alert-icon {
  font-size: 18px;
  flex-shrink: 0;
}

/* --- Placeholder / Coming Soon --- */
.placeholder-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  text-align: center;
  color: var(--text-muted);
}

.placeholder-view .placeholder-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.5;
}

.placeholder-view .placeholder-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.placeholder-view .placeholder-text {
  font-size: 14px;
  max-width: 300px;
}

/* --- Loading Skeleton --- */
.skeleton {
  background: linear-gradient(90deg, var(--bg-card) 25%, var(--bg-card-alt) 50%, var(--bg-card) 75%);
  background-size: 200% 100%;
  animation: skeleton-pulse 1.5s ease-in-out infinite;
  border-radius: var(--radius);
}

@keyframes skeleton-pulse {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-card {
  height: 100px;
  border-radius: var(--radius-lg);
}

/* --- Empty State --- */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.5;
}

/* --- Utilities --- */
.text-green { color: var(--green); }
.text-muted { color: var(--text-muted); }
.text-orange { color: var(--orange); }
.text-red { color: var(--red); }
.fw-600 { font-weight: 600; }
.mb-12 { margin-bottom: 12px; }
.mb-20 { margin-bottom: 20px; }

/* ============================================================
   Responsive — Tablet (600px+)
   ============================================================ */
@media (min-width: 600px) {
  .deal-grid {
    grid-template-columns: repeat(2, 1fr);
  }

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

/* ============================================================
   Responsive — Mobile (<768px)
   ============================================================ */
@media (max-width: 767px) {
  .sidebar {
    transform: translateX(-100%);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main-content {
    margin-left: 0;
  }

  .hamburger {
    display: flex;
  }

  .page-content {
    padding: 16px;
  }
}

/* ============================================================
   Responsive — Desktop (1024px+)
   ============================================================ */
@media (min-width: 1024px) {
  .deal-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }

  .page-content {
    padding: 24px;
    max-width: 1200px;
  }

  .deal-card:hover {
    transform: translateY(-1px);
  }
}
