/* ============================================
   BrunchFlow Menu Engine - Styles
   Mobile-first, cute/pretty pastel design
   ============================================ */

/* ---- CSS Custom Properties (Theme Tokens) ---- */
:root {
  /* Default Light Theme - Cute Pastel */
  --bf-bg: #FFF5F8;
  --bf-card: #FFFFFF;
  --bf-text: #2D2D2D;
  --bf-muted: #8E8E93;
  --bf-accent: #FF4FB8;
  --bf-accent-soft: #FFE4F0;
  --bf-border: #F0E4E8;
  --bf-shadow: rgba(255, 79, 184, 0.08);
  --bf-success: #34C759;
  --bf-warning: #FF9500;
  --bf-danger: #FF3B30;

  /* Spacing */
  --bf-space-xs: 4px;
  --bf-space-sm: 8px;
  --bf-space-md: 16px;
  --bf-space-lg: 24px;
  --bf-space-xl: 32px;

  /* Border Radius */
  --bf-radius: 18px;
  --bf-radius-sm: 10px;
  --bf-radius-pill: 9999px;

  /* Typography */
  --bf-font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --bf-font-rounded: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;

  /* Transitions */
  --bf-transition: 0.2s ease;
  --bf-transition-slow: 0.3s ease;

  /* Header height for scroll offset */
  --bf-header-height: 60px;
  --bf-chips-height: 52px;
  --bf-search-height: 56px;
  --bf-toolbar-height: 44px;
  --bf-sticky-offset: calc(var(--bf-header-height) + var(--bf-search-height) + var(--bf-toolbar-height) + var(--bf-chips-height));
}

/* Dark Mode */
[data-theme="dark"] {
  --bf-bg: #1C1C1E;
  --bf-card: #2C2C2E;
  --bf-text: #FFFFFF;
  --bf-muted: #8E8E93;
  --bf-border: #3A3A3C;
  --bf-shadow: rgba(0, 0, 0, 0.3);
  --bf-accent-soft: rgba(255, 79, 184, 0.2);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: var(--bf-sticky-offset);
}

body {
  font-family: var(--bf-font);
  background-color: var(--bf-bg);
  color: var(--bf-text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

body.font-rounded {
  font-family: var(--bf-font-rounded);
}

/* ---- App Container ---- */
.app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ---- Sticky Header ---- */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bf-bg);
  border-bottom: 1px solid var(--bf-border);
  padding: var(--bf-space-sm) var(--bf-space-md);
  height: var(--bf-header-height);
}

.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--bf-space-md);
  height: 100%;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: var(--bf-space-sm);
  min-width: 0;
  flex: 1;
}

.header-logo {
  width: 40px;
  height: 40px;
  border-radius: var(--bf-radius-sm);
  object-fit: cover;
  flex-shrink: 0;
}

.header-logo[src=""],
.header-logo:not([src]),
.header-logo.hidden {
  display: none;
}

.header-text {
  min-width: 0;
}

.header-title {
  font-size: 1.125rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.2;
}

.header-meta {
  font-size: 0.75rem;
  color: var(--bf-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  gap: var(--bf-space-xs);
}

/* ---- Button Icon ---- */
.btn-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--bf-radius-sm);
  border: none;
  background: var(--bf-card);
  color: var(--bf-text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--bf-transition), transform var(--bf-transition);
  -webkit-tap-highlight-color: transparent;
}

.btn-icon:hover {
  background: var(--bf-accent-soft);
}

.btn-icon:active {
  transform: scale(0.95);
}

/* ---- Search Container ---- */
.search-container {
  position: sticky;
  top: var(--bf-header-height);
  z-index: 99;
  background: var(--bf-bg);
  padding: var(--bf-space-sm) var(--bf-space-md);
}

.search-container.hidden {
  display: none;
}

.search-bar {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 14px;
  color: var(--bf-muted);
  pointer-events: none;
}

.search-input {
  width: 100%;
  height: 44px;
  padding: 0 44px;
  border: 2px solid var(--bf-border);
  border-radius: var(--bf-radius-pill);
  background: var(--bf-card);
  color: var(--bf-text);
  font-size: 1rem;
  font-family: inherit;
  outline: none;
  transition: border-color var(--bf-transition), box-shadow var(--bf-transition);
  -webkit-appearance: none;
}

.search-input:focus {
  border-color: var(--bf-accent);
  box-shadow: 0 0 0 3px var(--bf-accent-soft);
}

.search-input::placeholder {
  color: var(--bf-muted);
}

/* Remove default clear button in webkit */
.search-input::-webkit-search-cancel-button {
  display: none;
}

.search-clear {
  position: absolute;
  right: 8px;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--bf-accent-soft);
  color: var(--bf-accent);
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity var(--bf-transition), transform var(--bf-transition);
  -webkit-tap-highlight-color: transparent;
}

.search-clear:active {
  transform: scale(0.9);
}

.search-clear[hidden] {
  display: none;
}

/* ---- Toolbar (Language + Favourites) ---- */
.toolbar {
  position: sticky;
  top: calc(var(--bf-header-height) + var(--bf-search-height));
  z-index: 98;
  background: var(--bf-bg);
  padding: var(--bf-space-xs) var(--bf-space-md);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--bf-space-sm);
  height: var(--bf-toolbar-height);
}

.toolbar.hidden {
  display: none;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: var(--bf-space-sm);
}

.lang-select {
  padding: var(--bf-space-xs) var(--bf-space-sm);
  border: 2px solid var(--bf-border);
  border-radius: var(--bf-radius-sm);
  background: var(--bf-card);
  color: var(--bf-text);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  min-width: 60px;
}

.lang-select:focus {
  border-color: var(--bf-accent);
}

.lang-select.hidden {
  display: none;
}

.btn-fav-toggle {
  display: flex;
  align-items: center;
  gap: var(--bf-space-xs);
  padding: var(--bf-space-xs) var(--bf-space-sm);
  border: 2px solid var(--bf-border);
  border-radius: var(--bf-radius-pill);
  background: var(--bf-card);
  color: var(--bf-text);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--bf-transition);
  -webkit-tap-highlight-color: transparent;
}

.btn-fav-toggle:hover {
  border-color: var(--bf-accent);
}

.btn-fav-toggle[aria-pressed="true"] {
  background: var(--bf-accent);
  border-color: var(--bf-accent);
  color: white;
}

.btn-fav-toggle[aria-pressed="true"] .heart-icon {
  fill: white;
}

.btn-fav-toggle.hidden {
  display: none;
}

.heart-icon {
  transition: fill var(--bf-transition);
}

/* ---- Category Chips Navigation ---- */
.chips-nav {
  position: sticky;
  top: calc(var(--bf-header-height) + var(--bf-search-height) + var(--bf-toolbar-height));
  z-index: 97;
  background: var(--bf-bg);
  border-bottom: 1px solid var(--bf-border);
  height: var(--bf-chips-height);
}

.chips-scroll {
  display: flex;
  gap: var(--bf-space-sm);
  padding: var(--bf-space-sm) var(--bf-space-md);
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.chips-scroll::-webkit-scrollbar {
  display: none;
}

.chip {
  flex-shrink: 0;
  padding: var(--bf-space-sm) var(--bf-space-md);
  border-radius: var(--bf-radius-pill);
  background: var(--bf-card);
  border: 2px solid var(--bf-border);
  color: var(--bf-text);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
  scroll-snap-align: start;
  transition: all var(--bf-transition);
  -webkit-tap-highlight-color: transparent;
}

.chip:hover {
  border-color: var(--bf-accent);
}

.chip.active {
  background: var(--bf-accent);
  border-color: var(--bf-accent);
  color: white;
}

/* ---- Main Content ---- */
.main-content {
  flex: 1;
  padding: var(--bf-space-md);
  padding-bottom: var(--bf-space-xl);
}

/* ---- Category Section ---- */
.category {
  margin-bottom: var(--bf-space-lg);
}

.category:last-child {
  margin-bottom: 0;
}

.category-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: var(--bf-space-md);
  padding-top: var(--bf-space-md);
  scroll-margin-top: var(--bf-sticky-offset);
}

/* ---- Menu Item Card ---- */
.item-card {
  background: var(--bf-card);
  border-radius: var(--bf-radius);
  padding: var(--bf-space-md);
  margin-bottom: var(--bf-space-sm);
  box-shadow: 0 2px 8px var(--bf-shadow);
  transition: transform var(--bf-transition), box-shadow var(--bf-transition);
  display: flex;
  gap: var(--bf-space-md);
}

.item-card:last-child {
  margin-bottom: 0;
}

.item-card:active {
  transform: scale(0.99);
}

.item-content {
  flex: 1;
  min-width: 0;
}

.item-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--bf-space-sm);
  margin-bottom: var(--bf-space-xs);
}

.item-name {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
}

.item-name mark {
  background: var(--bf-accent-soft);
  color: var(--bf-accent);
  border-radius: 2px;
  padding: 0 2px;
}

.btn-fav {
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  color: var(--bf-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: color var(--bf-transition), transform var(--bf-transition);
  -webkit-tap-highlight-color: transparent;
}

.btn-fav:hover {
  color: var(--bf-accent);
}

.btn-fav:active {
  transform: scale(0.85);
}

.btn-fav.active {
  color: var(--bf-accent);
}

.btn-fav.active .heart-icon {
  fill: var(--bf-accent);
}

.btn-fav.hidden {
  display: none;
}

.item-desc {
  font-size: 0.875rem;
  color: var(--bf-muted);
  margin-bottom: var(--bf-space-sm);
  line-height: 1.4;
}

.item-desc:empty {
  display: none;
}

.item-price {
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--bf-accent);
}

/* ---- Tags & Allergens ---- */
.item-badges {
  display: flex;
  flex-wrap: wrap;
  gap: var(--bf-space-xs);
  margin-top: var(--bf-space-sm);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--bf-radius-pill);
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.badge-tag {
  background: var(--bf-accent-soft);
  color: var(--bf-accent);
}

.badge-allergen {
  background: #FFF3E0;
  color: #E65100;
}

[data-theme="dark"] .badge-allergen {
  background: rgba(255, 149, 0, 0.2);
  color: #FF9500;
}

.badge-icon {
  width: 14px;
  height: 14px;
}

/* ---- Variants ---- */
.item-variants {
  margin-top: var(--bf-space-sm);
  padding-top: var(--bf-space-sm);
  border-top: 1px dashed var(--bf-border);
}

.variant-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
  padding: var(--bf-space-xs) 0;
}

.variant-name {
  color: var(--bf-muted);
}

.variant-price {
  font-weight: 600;
  color: var(--bf-text);
}

/* ---- Item Photo ---- */
.item-photo-wrap {
  flex-shrink: 0;
  width: 80px;
  height: 80px;
  border-radius: var(--bf-radius-sm);
  overflow: hidden;
  cursor: pointer;
}

.item-photo {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform var(--bf-transition);
}

.item-photo-wrap:hover .item-photo {
  transform: scale(1.05);
}

/* Photo placeholder for broken images */
.item-photo-wrap.photo-placeholder {
  background: var(--bf-bg);
  border: 2px dashed var(--bf-border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: default;
}

.item-photo-wrap.photo-placeholder .placeholder-icon {
  color: var(--bf-muted);
  opacity: 0.5;
}

/* ---- Skeleton Loading ---- */
.skeleton-container {
  animation: pulse 1.5s ease-in-out infinite;
}

.skeleton-container.hidden {
  display: none;
}

.skeleton-category {
  margin-bottom: var(--bf-space-lg);
}

.skeleton-title {
  width: 40%;
  height: 24px;
  background: var(--bf-border);
  border-radius: var(--bf-radius-sm);
  margin-bottom: var(--bf-space-md);
}

.skeleton-card {
  height: 100px;
  background: var(--bf-card);
  border-radius: var(--bf-radius);
  margin-bottom: var(--bf-space-sm);
  box-shadow: 0 2px 8px var(--bf-shadow);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ---- No Results ---- */
.no-results {
  text-align: center;
  padding: var(--bf-space-xl) var(--bf-space-md);
  color: var(--bf-muted);
}

.no-results[hidden] {
  display: none;
}

.no-results svg {
  margin-bottom: var(--bf-space-md);
  opacity: 0.5;
}

.no-results p {
  font-size: 1rem;
}

/* ---- Error Message ---- */
.error-message {
  text-align: center;
  padding: var(--bf-space-xl) var(--bf-space-md);
  color: var(--bf-muted);
}

.error-message[hidden] {
  display: none;
}

.error-message svg {
  margin-bottom: var(--bf-space-md);
  color: var(--bf-danger);
}

.btn-retry {
  margin-top: var(--bf-space-md);
  padding: var(--bf-space-sm) var(--bf-space-lg);
  border: none;
  border-radius: var(--bf-radius-pill);
  background: var(--bf-accent);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: transform var(--bf-transition);
}

.btn-retry:active {
  transform: scale(0.95);
}

/* ---- Footer ---- */
.footer {
  text-align: center;
  padding: var(--bf-space-lg) var(--bf-space-md);
  border-top: 1px solid var(--bf-border);
  background: var(--bf-bg);
}

.footer p {
  font-size: 0.75rem;
  color: var(--bf-muted);
  margin-bottom: var(--bf-space-xs);
}

.footer-branding {
  font-size: 0.6875rem;
}

.footer-branding strong {
  color: var(--bf-accent);
}

/* ---- Modal / Bottom Sheet ---- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: var(--bf-space-md);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--bf-transition-slow), visibility var(--bf-transition-slow);
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal-overlay[hidden] {
  display: none;
}

.modal {
  background: var(--bf-card);
  border-radius: var(--bf-radius) var(--bf-radius) 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform var(--bf-transition-slow);
}

.modal-overlay.open .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--bf-space-md);
  border-bottom: 1px solid var(--bf-border);
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 700;
}

.modal-close {
  background: transparent;
}

.modal-body {
  padding: var(--bf-space-md);
  overflow-y: auto;
}

/* ---- Modal Links ---- */
.info-links {
  display: flex;
  flex-direction: column;
  gap: var(--bf-space-sm);
}

.info-link {
  display: flex;
  align-items: center;
  gap: var(--bf-space-md);
  padding: var(--bf-space-md);
  border-radius: var(--bf-radius-sm);
  background: var(--bf-bg);
  color: var(--bf-text);
  text-decoration: none;
  font-weight: 500;
  transition: background var(--bf-transition);
}

.info-link:hover {
  background: var(--bf-accent-soft);
}

.info-link svg {
  flex-shrink: 0;
  color: var(--bf-accent);
}

/* ---- Lightbox ---- */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 300;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--bf-space-md);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--bf-transition-slow), visibility var(--bf-transition-slow);
}

.lightbox.open {
  opacity: 1;
  visibility: visible;
}

.lightbox[hidden] {
  display: none;
}

.lightbox-close {
  position: absolute;
  top: var(--bf-space-md);
  right: var(--bf-space-md);
  width: 48px;
  height: 48px;
  border: none;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 50%;
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--bf-transition);
}

.lightbox-close:hover {
  background: rgba(255, 255, 255, 0.2);
}

.lightbox-img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: var(--bf-radius);
  object-fit: contain;
}

/* ---- Utility Classes ---- */
.hidden {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---- Focus Styles for Accessibility ---- */
:focus-visible {
  outline: 2px solid var(--bf-accent);
  outline-offset: 2px;
}

button:focus:not(:focus-visible),
a:focus:not(:focus-visible),
input:focus:not(:focus-visible),
select:focus:not(:focus-visible) {
  outline: none;
}

/* ---- Responsive Adjustments ---- */
@media (min-width: 480px) {
  .app {
    border-left: 1px solid var(--bf-border);
    border-right: 1px solid var(--bf-border);
  }

  .modal {
    border-radius: var(--bf-radius);
    margin-bottom: var(--bf-space-xl);
  }
}

/* ---- Reduced Motion ---- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---- Print Styles ---- */
@media print {
  .header,
  .search-container,
  .toolbar,
  .chips-nav,
  .btn-fav,
  .footer-branding {
    display: none !important;
  }

  .main-content {
    padding: 0;
  }

  .item-card {
    box-shadow: none;
    border: 1px solid #ccc;
    break-inside: avoid;
  }
}
