/* Base Styles & CSS Variables */
/* This file contains all styles for the application, replacing inline styles from layout.ts */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* Light Theme (Default) */
:root {
  --primary-blue: #2A5D90;
  --basket-dark-blue: #214C78;
  --accent-orange: #F38F1E;
  --main-background: #FDFDFD;
  --text-color: #214C78;
  --surface-color: #FFFFFF;
  
  /* Additional theme variables for consistency */
  --bg: #FDFDFD;
  --surface: #FFFFFF;
  --text: #214C78;
  --text-muted: #6b7280;
  --primary: #2A5D90;
  --primary-hover: #1e40af;
  --success: #059669;
  --danger: #dc2626;
  --warning: #d97706;
  --border: #e5e7eb;
  --border-focus: #2A5D90;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.12);
}

/* Dark Theme - overrides when data-theme="dark" is set on html element */
html[data-theme="dark"] {
  --primary-blue: #4A8DCF;
  --basket-dark-blue: #2A5D90;
  --accent-orange: #FFB35C;
  --main-background: #1A1A1A;
  --text-color: #F2F2F2;
  --surface-color: #2D2D2D;
  
  /* Override additional theme variables for dark mode */
  --bg: #1A1A1A;
  --surface: #2D2D2D;
  --text: #F2F2F2;
  --text-muted: #9ca3af;
  --primary-hover: #5a9ddf;
  --border: #404040;
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  font-size: 1rem;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ─────────────────────────────────────────── */

.container { max-width: 640px; margin: 0 auto; padding: 0 16px; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  height: 56px;
  display: flex;
  align-items: center;
}
header .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}
.logo {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  cursor: pointer;
}

.logo-img {
  height: 48px;
  margin-right: 10px;
}

.logo-text-img {
  height: 48px;
  margin-right: 10px;
}

.logo:hover { text-decoration: none; }

.search-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
  transition: background 0.15s;
  min-width: 40%;
  border: 1px black solid;
}
.search-trigger:hover { background: var(--bg); }

main { padding: 24px 0; min-height: 60vh; }

footer {
  text-align: center;
  padding: 24px;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  margin-top: 40px;
}

/* ── Cards ──────────────────────────────────────────── */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}
.card + .card { margin-top: 16px; }
.card-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 12px; }

/* ── Buttons ────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-height: 44px;
  transition: all 0.15s;
}
.btn:hover { background: var(--bg); text-decoration: none; }
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  font-weight: 600;
  min-height: 48px;
  padding: 12px 24px;
  font-size: 1rem;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: scale(0.98); }

.btn-sm { padding: 8px 14px; font-size: 0.875rem; min-height: 44px; }

.btn-action {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 0.875rem;
  font-weight: 600;
  min-height: 44px;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-action:hover { background: #eff6ff; }

.btn-back {
  background: none;
  border: none;
  color: var(--primary);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 8px 0;
  min-height: 44px;
  font-weight: 500;
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.875rem;
  cursor: pointer;
  padding: 8px;
  min-height: 44px;
}
.btn-text:hover { color: var(--text); }

.btn-disabled {
  opacity: 0.5;
  cursor: default;
}

/* ── Badges ─────────────────────────────────────────── */

.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-success { background: #dcfce7; color: var(--success); }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: var(--danger); }
.badge-info { background: #eff6ff; color: var(--primary); }

/* ── Search Input ──────────────────────────────────── */

.search-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  outline: none;
  min-height: 48px;
  transition: border-color 0.15s;
}
.search-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(29,78,216,0.1);
}

/* ── Ranking ───────────────────────────────────────── */

.ranking-list { display: grid; gap: 12px; }

/* Ranking card - shared position layout */
.ranking-card {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  padding: 16px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.ranking-card .ranking-position {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-muted);
  min-width: 40px;
  text-align: center;
  flex-shrink: 0;
  padding-top: 8px;
}

.ranking-merchants-container {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
}

/* Individual merchant row within a shared card */
.ranking-merchant-row {
  flex: 1;
  min-width: 280px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-template-rows: auto auto;
  align-items: center;
}

.ranking-merchant-row .ranking-logo,
.ranking-merchant-row .ranking-logo-placeholder {
  grid-column: 1;
  grid-row: 1;
  width: 120px;
  height: 90px;
  object-fit: contain;
}

.ranking-merchant-row .ranking-merchant {
  grid-column: 2;
  grid-row: 1;
}

.ranking-merchant-row .ranking-total {
  grid-column: 3;
  grid-row: 1;
  font-size: 1.125rem;
  font-weight: 700;
  white-space: nowrap;
  text-align: right;
}

.ranking-merchant-row .ranking-detail-wrapper {
  grid-column: 1 / -1;
  grid-row: 2;
  margin-top: 8px;
}

.ranking-merchant-name { font-size: 1.125rem; font-weight: 600; }
.ranking-meta { font-size: 0.875rem; color: var(--text-muted); }

/* #1 card variant */
.ranking-card.ranking-item-first { border-left: 4px solid var(--success); }
.ranking-card.ranking-item-first .ranking-position { color: var(--success); }
.ranking-card.ranking-item-first .ranking-merchant-row:first-child .ranking-total { font-size: 1.5rem; color: var(--success); }

/* ── Product List (Search Results) ─────────────────── */

.product-list { display: grid; gap: 8px; }
.product-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  transition: background 0.1s;
  min-height: 48px;
  color: var(--text);
}
.product-item:hover { background: var(--bg); text-decoration: none; }
.product-name { font-size: 1rem; font-weight: 500; }

/* ── Merchant Price List (Product Detail) ──────────── */

.merchant-price-list { display: grid; gap: 0; }
.merchant-price-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  font-size: 1rem;
  min-height: 48px;
}
.merchant-price-row:last-child { border-bottom: none; }

/* ── Price Table ────────────────────────────────────── */

.price-table { width: 100%; border-collapse: collapse; }
.price-table th, .price-table td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border); }
.price-table th { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; font-weight: 600; }
.price-lowest { color: var(--success); font-weight: 600; }
.price-highest { color: var(--danger); }

/* ── Category Groups ───────────────────────────────── */

.category-group { margin-bottom: 20px; }
.category-group-title {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 8px;
  padding: 12px 0 6px;
  border-bottom: 1px solid var(--border);
}

/* ── Alerts & Hints ────────────────────────────────── */

.search-hint { text-align: center; padding: 40px; color: var(--text-muted); font-size: 1rem; }
.alert { padding: 12px 16px; border-radius: var(--radius); background: #fef3c7; color: #92400e; font-size: 0.9rem; }

/* ── HTMX Indicators ───────────────────────────────── */

.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.spinner {
  width: 24px;
  height: 24px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Search Overlay ────────────────────────────────── */

.search-overlay {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: var(--bg);
  flex-direction: column;
  display: none;
}
.search-overlay-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}
.search-overlay-title {
  font-size: 1.125rem;
  font-weight: 600;
}
.search-overlay-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  max-width: 640px;
  margin: 0 auto;
  width: 100%;
}

/* ── Bottom Bar ────────────────────────────────────── */

.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
  z-index: 250;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
}
.bottom-bar-inner {
  max-width: 640px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.bottom-bar-label {
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
}
.bottom-bar .btn-primary {
  padding: 8px 20px;
  min-height: 40px;
  font-size: 0.9rem;
}

/* ── Bottom Sheet ──────────────────────────────────── */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 300;
  display: none;
}
.bottom-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 60vh;
  background: var(--surface);
  border-radius: 16px 16px 0 0;
  box-shadow: var(--shadow-lg);
  z-index: 310;
  transform: translateY(100%);
  transition: transform 0.25s ease-out;
  display: flex;
  flex-direction: column;
}
.bottom-sheet.open { transform: translateY(0); }
.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sheet-title { font-size: 1.125rem; font-weight: 600; }
.sheet-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-muted);
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sheet-items {
  flex: 1;
  overflow-y: auto;
  padding: 0 20px;
}
.sheet-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
  min-height: 48px;
}
.sheet-item-name { font-size: 0.9rem; flex: 1; }
.btn-remove {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-remove:hover { color: var(--danger); }
.sheet-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}
.sheet-footer .btn-primary { width: 100%; }
.sheet-footer .btn-text { text-align: center; }

/* ── Responsive ─────────────────────────────────────── */

@media (max-width: 640px) {
  /* Header layout - stack search below logos */
  header {
    height: auto;
    padding: 8px 0;
  }

  header .container {
    flex-direction: column;
    gap: 8px;
  }

  .logo {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
  }

  .logo-img {
    height: 36px;
    margin-right: 8px;
  }

  .logo-text-img {
    height: 36px;
    margin-right: 0;
  }

  .search-trigger {
    width: 100%;
    min-width: auto;
    justify-content: center;
  }

  /* Ranking card adjustments */
  .ranking-card {
    flex-direction: column;
    gap: 12px;
    padding: 14px 16px;
  }

  .ranking-card .ranking-position {
    padding-top: 0;
    font-size: 1.25rem;
    min-width: auto;
  }

  .ranking-merchants-container {
    width: 100%;
  }

  .ranking-merchant-row {
    min-width: 100%;
    grid-template-columns: auto 1fr auto;
    gap: 4px 8px;
  }

  .ranking-merchant-row .ranking-logo,
  .ranking-merchant-row .ranking-logo-placeholder {
    width: 40px;
    height: 40px;
    margin-right: 8px;
  }

  .ranking-merchant-row .ranking-total {
    font-size: 1rem;
  }

  .ranking-card.ranking-item-first .ranking-merchant-row:first-child .ranking-total {
    font-size: 1.25rem;
  }

  .ranking-merchant-name {
    font-size: 1rem;
  }

  .ranking-meta {
    font-size: 0.8rem;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
  }

  .ranking-meta .badge {
    font-size: 0.7rem;
    padding: 2px 6px;
  }

  .custom-basket-actions {
    display: block;
    margin-left: 0;
    margin-top: 8px;
  }
}

/* Additional CSS styles for template components */
/* These complement the base styles above */

/* ── Home Page ───────────────────────────────────────── */

.page-title {
  font-size: 1.5rem;
  margin-bottom: 4px;
}

.page-subtitle {
  color: var(--text-muted);
  margin-bottom: 20px;
  font-size: 0.9rem;
}

.custom-basket-actions {
  margin-left: 8px;
  font-size: 0.85rem;
}

.custom-basket-actions .btn-text {
  font-size: 0.85rem;
  padding: 4px 8px;
  min-height: auto;
}

.action-separator {
  color: var(--border);
  margin: 0 4px;
}

.home-actions {
  margin-top: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
}

.btn-full {
  width: 100%;
  max-width: 400px;
}

.basket-preview {
  margin-top: 24px;
}

.basket-details {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 0;
}

.basket-summary {
  padding: 14px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.95rem;
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-height: 48px;
}

.expand-icon {
  color: var(--text-muted);
  font-size: 0.85rem;
}

.basket-items {
  padding: 0 16px 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

/* ── Ranking Partial ─────────────────────────────────── */

.ranking-item-first {
  border-left: 4px solid var(--success);
}

.ranking-logo {
  width: 90px;
  height: 90px;
  object-fit: contain;
  margin-right: 12px;
}

.ranking-logo-placeholder {
  width: 80px;
  height: 80px;
  background: var(--border);
  border-radius: var(--radius);
  margin-right: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.7rem;
  color: var(--text-muted);
}

.ranking-merchant {
  flex: 1;
}

.ranking-savings {
  font-size: 0.85rem;
  color: var(--success);
  margin-top: 2px;
}

.ranking-detail-wrapper {
  margin-top: 8px;
  grid-column: 1 / -1;
  width: 100%;
}

.ranking-detail-toggle {
  font-size: 0.8rem;
  width: 100%;
  justify-content: center;
}

.ranking-detail-content {
  margin-top: 8px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  transition: max-height 0.3s ease-out, opacity 0.25s ease-out, padding 0.25s ease-out;
}

.ranking-detail-content.open {
  max-height: 2000px;
  opacity: 1;
}

.ranking-item-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.ranking-item-name {
  font-size: 0.9rem;
}

.ranking-item-price {
  font-weight: 600;
  white-space: nowrap;
}

.ranking-item-generic {
  font-size: 0.75rem;
  color: var(--primary);
}

.ranking-item-average {
  font-size: 0.75rem;
  color: var(--warning);
}

.ranking-missing-items {
  padding: 6px 0;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Ranking items sections - found and not-found */
.ranking-items-section {
  margin-bottom: 12px;
}

.ranking-items-section:last-child {
  margin-bottom: 0;
}

.ranking-not-found-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--warning);
  padding: 8px 0 6px;
  margin-bottom: 4px;
  border-bottom: 1px dashed var(--border);
}

.ranking-items-not-found {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  margin-top: 8px;
}

.ranking-items-not-found .ranking-item-row {
  border-bottom: 1px dashed var(--border);
}

.ranking-items-not-found .ranking-item-row:last-child {
  border-bottom: none;
}

.ranking-item-not-found .ranking-item-name {
  color: var(--text-muted);
}

/* ── Search Results Partial ──────────────────────────── */

.search-input-wrapper {
  position: relative;
  margin-bottom: 16px;
}

.search-spinner {
  position: absolute;
  right: 12px;
  top: 12px;
}

.suggestions-list {
  margin-bottom: 16px;
}

.suggestion-item {
  background: #eff6ff;
  border-left: 3px solid var(--primary);
  margin-bottom: 8px;
}

.suggestion-content {
  flex: 1;
}

.suggestion-name {
  font-weight: 600;
}

.suggestion-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.product-item-clickable {
  cursor: pointer;
}

.product-item-content {
  flex: 1;
}

.product-item-meta {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* ── Product Detail Partial ─────────────────────────── */

.product-detail-back {
  margin-bottom: 16px;
}

.product-detail-name {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 4px;
}

.product-detail-meta {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-bottom: 16px;
}

.product-detail-savings {
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.savings-amount {
  color: var(--success);
}

.merchant-price-logo {
  width: 24px;
  height: 24px;
  object-fit: contain;
  margin-right: 8px;
  border-radius: 4px;
}

.merchant-price-logo-placeholder {
  width: 24px;
  height: 24px;
  background: var(--border);
  border-radius: 4px;
  margin-right: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  color: var(--text-muted);
}

.merchant-price-label {
  display: flex;
  align-items: center;
}

.merchant-price-value {
  font-weight: 600;
}

.product-detail-actions {
  margin-top: 20px;
}
