/* Menu Cards Custom CSS */

/* Hero Menu Section */
.hero-menu {
  /* background set via header-images.css */
  padding: 6rem 0;
  position: relative;
  overflow: hidden;
}

.hero-menu .welcome-text {
  font-size: 1.2rem;
  text-transform: uppercase;
  letter-spacing: 3px;
  color: var(--penkey-orange);
  margin-bottom: 1rem;
  font-weight: 600;
}

.grain-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: url('../images/grain-texture.png');
  opacity: 0.1;
  pointer-events: none;
}

/* Menu Container */
.menu-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 15px;
  position: relative;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 30px;
  justify-content: center;
}

/* Category headers for grouped display */
.category-header {
  grid-column: 1 / -1; /* Span all columns */
  margin-top: 3rem;
  margin-bottom: 1.5rem;
  position: relative;
}

.category-header:first-child {
  margin-top: 0;
}

.category-header h2 {
  font-size: 1.8rem;
  color: var(--penkey-navy);
  margin-bottom: 0.5rem;
  position: relative;
  display: inline-block;
  padding-bottom: 0.5rem;
}

.category-header h2:after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 3px;
  background-color: var(--penkey-orange);
  border-radius: 2px;
}

/* Media queries for responsive grid */
@media (max-width: 992px) {
  .menu-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  
  /* Adjust sidebar for tablet */
  .menu-sidebar {
    width: 240px;
  }
  
  .menu-filter-buttons {
    gap: 0.4rem;
  }
  
  .btn-menu-filter {
    padding: 0.4rem 0.8rem;
    font-size: 0.8rem;
  }
}

@media (max-width: 768px) {
  .menu-container {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  .menu-layout {
    display: block;
  }
  
  .mobile-filter-toggle {
    display: block !important; /* Force show mobile filter toggle */
    margin: 1rem auto 2rem;
    width: 100%;
  }
  
  /* Stack filter buttons vertically on mobile */
  .menu-filter-buttons {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;
  }
  
  .btn-menu-filter {
    width: 100%;
    text-align: left;
    padding: 0.5rem 1rem;
    margin: 0;
  }
  
  .menu-sidebar {
    position: fixed;
    top: 0;
    left: -320px; /* Start off-screen */
    width: 280px;
    height: 100vh;
    background-color: white;
    z-index: 1000;
    transition: left 0.3s ease;
    overflow-y: auto; /* Allow scrolling if needed */
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
    padding: 1rem; /* Reduced padding */
    display: flex;
    flex-direction: column;
  }
  
  .menu-sidebar.active {
    left: 0; /* Slide in */
  }
  
  .menu-search-filter-sticky {
    position: relative;
    top: 0;
    height: auto;
    max-height: calc(100vh - 3rem);
    border-radius: 0;
    padding-top: 1rem;
    margin-top: 0;
    overflow-y: auto;
    width: 100%;
    box-sizing: border-box;
  }
  
  /* Overlay when sidebar is open */
  .menu-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999;
  }
  
  .menu-overlay.active {
    display: block;
  }
}

@media (max-width: 640px) {
  .menu-grid {
    grid-template-columns: 1fr;
  }
}

.menu-card {
  width: 100%;
  height: 400px; /* Fixed height for all cards */
  background: white;
  border-radius: 0.5rem;
  box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  cursor: pointer;
}

.menu-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
}

.menu-card-image-container {
  height: 180px; /* Fixed height for image container */
  overflow: hidden;
}

.menu-card-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.menu-card-content {
  padding: 1rem;
  display: flex;
  flex-direction: column;
  flex-grow: 1;
}

.menu-card-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1a202c;
  margin-bottom: 0.5rem;
  line-height: 1.2;
  height: 3rem; /* Fixed height for title - approximately 2 lines */
  overflow: hidden;
}

.menu-card-description {
  color: #4a5568;
  font-size: 0.875rem;
  line-height: 1.4;
  flex-grow: 1;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 3; /* Limit to 3 lines */
  line-clamp: 3; /* Standard property for compatibility */
  -webkit-box-orient: vertical;
  height: 3.6rem; /* Fixed height for description - approximately 3 lines */
}

.menu-card-footer {
  margin-top: auto;
  padding-top: 0.75rem;
  border-top: 1px solid #e2e8f0;
}

.menu-card-footer-content {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.menu-card-price {
  font-size: 1.25rem;
  font-weight: 700;
  color: #1a202c;
}

/* Hide prices on the menu page only */
.menu-page .menu-card-price,
.menu-page .modal-price {
  display: none !important;
}

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

/* Search and Filter Styles */
.menu-search-filter-container {
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

.menu-search-input {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid var(--penkey-cream);
  border-radius: 5px;
  font-size: 1rem;
  transition: all 0.2s ease;
  background-color: rgba(255, 255, 255, 0.1);
  color: var(--penkey-cream);
}

.menu-search-input::placeholder {
  color: rgba(255, 248, 231, 0.7);
}

.menu-search-input:focus {
  border-color: var(--penkey-orange);
  box-shadow: 0 0 0 2px rgba(255, 152, 0, 0.3);
}

.menu-search-input:focus:not(:focus-visible) {
  outline: none;
}

.menu-filter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.5rem;
}

.category-btn {
  padding: 0.5rem 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.25rem;
  background-color: white;
  color: #4a5568;
  font-size: 0.875rem;
  cursor: pointer;
  transition: all 0.2s ease;
}

.category-btn:hover {
  background-color: #f7fafc;
  border-color: #cbd5e0;
}

.category-btn.active {
  background-color: #4a5568;
  color: white;
  border-color: #4a5568;
}

/* Menu Layout with Sidebar */
.menu-layout {
  display: flex;
  gap: 2rem;
  position: relative;
}

/* Left Sidebar */
.menu-sidebar {
  width: 280px;
  flex-shrink: 0;
}

/* Main Content */
.menu-content {
  flex-grow: 1;
}

/* Sticky Search and Filter */
.menu-search-filter-sticky {
  position: sticky;
  top: 140px; /* Increased by another 20px as requested */
  z-index: 100;
  background-color: var(--penkey-navy); /* Inverted to navy */
  color: var(--penkey-cream); /* Text color to cream */
  padding: 1.5rem;
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: all 0.3s ease;
  margin-top: 100px; /* Adjusted to align with first row of menu cards + 20px */
}

.menu-search-filter-container {
  width: 100%;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 3rem);
}

/* Mobile Filter Toggle Button */
.mobile-filter-toggle {
  display: none;
  margin: 1rem 0 2rem;
  text-align: center;
  position: relative;
  z-index: 50;
  width: 100%;
}

#mobile-filter-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background-color: var(--penkey-orange);
  color: white;
  padding: 1rem 2rem;
  border-radius: 50px;
  font-weight: 600;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  font-size: 1.2rem; /* Increased font size */
  width: 90%; /* Make button wider */
  justify-content: center; /* Center text */
  margin: 0 auto;
}

/* (floating-filter-btn removed) */

/* Mobile Close Button */
.mobile-filter-close {
  display: none;
  text-align: right;
  margin-bottom: 1rem;
}

#close-filter-btn {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--penkey-navy);
}

.menu-search {
  position: relative;
  margin-bottom: 1.5rem;
}

.search-icon {
  position: absolute;
  left: 1rem;
  top: 50%;
  transform: translateY(-50%);
  color: #94a3b8;
}

.menu-search input {
  width: 100%;
  padding: 0.75rem 1rem 0.75rem 2.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 50px;
  font-size: 1rem;
  background-color: white;
  transition: all 0.3s ease;
}

.menu-search input:focus {
  border-color: var(--penkey-orange);
  box-shadow: 0 0 0 3px rgba(255, 140, 43, 0.2);
}

.menu-search input:focus:not(:focus-visible) {
  outline: none;
}

.filter-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--penkey-navy);
  text-align: center;
}

.menu-filter-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  max-height: calc(100vh - 12rem); /* Ensure it fits within the viewport */
  overflow-y: auto; /* Allow scrolling within the buttons container */
  padding-bottom: 1rem;
  width: 100%;
}

/* Menu Filter Buttons */
.btn-menu-filter {
  padding: 0.5rem 1rem;
  background-color: rgba(255, 248, 231, 0.15);
  border: 1px solid var(--penkey-cream);
  border-radius: 50px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  color: var(--penkey-cream);
}

.btn-menu-filter:hover {
  background-color: rgba(255, 248, 231, 0.25);
}

.btn-menu-filter.active {
  background-color: var(--penkey-orange);
  border-color: var(--penkey-orange);
  color: white;
  box-shadow: 0 0 0 2px rgba(255, 152, 0, 0.3);
  font-weight: 600;
}

/* Scrolled state for sticky filter */
.menu-search-filter-sticky.scrolled {
  padding: 1rem 1.5rem;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

/* Modal styles */
.menu-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 1000;
}

.menu-modal-content {
  background-color: white;
  border-radius: 0.5rem;
  width: 90%;
  max-width: 600px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
}

.menu-modal-header {
  position: relative;
  padding: 1.5rem;
  border-bottom: 1px solid #e2e8f0;
}

.menu-modal-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: 1.5rem;
  cursor: pointer;
  color: #4a5568;
}

.menu-modal-image {
  width: 100%;
  height: 300px;
  object-fit: cover;
}

.menu-modal-body {
  padding: 1.5rem;
}

.menu-modal-footer {
  padding: 1.5rem;
  border-top: 1px solid #e2e8f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Categories Modal (triggered by Subnav More) */
.menu-page .categories-modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100; /* above header (1000) and other modals */
}
.menu-page .categories-modal-content {
  background: #fff;
  width: 92%;
  max-width: 720px;
  max-height: 90vh;
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: 0 25px 50px -12px rgba(0,0,0,.25);
}
.menu-page .categories-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid #e8e5e0;
  gap: 12px;
}
.menu-page .categories-modal-header h2 { margin: 0; line-height: 1.2; flex: 1 1 auto; }
.menu-page .categories-modal-close {
  background: transparent;
  border: 0;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--penkey-orange);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
}
.menu-page .categories-modal-close:hover { opacity: .85; }
.menu-page .categories-modal-close:focus-visible { outline: 2px solid rgba(255,152,0,.35); border-radius: 999px; }
.menu-page .categories-modal-body {
  padding: 16px 20px calc(20px + env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  flex: 1 1 auto;
  min-height: 0; /* ensure scrollable area in flex container (Safari) */
}
.menu-page .categories-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.menu-page .categories-grid a {
  display: block;
  padding: 10px 12px;
  border: 1px solid #e8e5e0;
  border-radius: 10px;
  color: rgba(36,50,53,.88);
  text-decoration: none;
}
.menu-page .categories-grid a:hover { background: var(--penkey-cream); }
@media (max-width: 560px) {
  .menu-page .categories-grid { grid-template-columns: 1fr; }
}

/* Sticky Subnav (menu page) */
.menu-page .subnav {
  position: -webkit-sticky;
  position: sticky; /* keep nav sticky as well for robustness */
  top: var(--header-offset, 150px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #fff;
  border: 1px solid #e8e5e0;
  border-radius: 999px;
  padding: 6px;
  box-shadow: 0 2px 14px rgba(0,0,0,.06);
  margin: 18px auto;
  z-index: 999;
}
.menu-page .subnav .subnav-links {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overflow-y: hidden; /* no vertical overflow on mobile */
  -webkit-overflow-scrolling: touch; /* momentum scroll on iOS */
  position: relative;
}
.menu-page .subnav .subnav-more-wrap { position: relative; }
.menu-page .subnav .subnav-actions {
  display: flex;
  align-items: center;
}
.menu-page .subnav a, .menu-page .subnav .subnav-more {
  color: rgba(36,50,53,.88);
  text-decoration: none;
  padding: 8px 14px;
  border-radius: 999px;
  white-space: nowrap;
  transition: background .2s ease, color .2s ease;
}
.menu-page .subnav a:hover, .menu-page .subnav .subnav-more:hover { background: var(--penkey-cream); }
.menu-page .subnav a.active, .menu-page .subnav .subnav-more.active { background: var(--penkey-sand, #FFF8F1); color: var(--penkey-navy); font-weight: 700; }
.menu-page .subnav a:focus-visible { outline: 2px solid var(--penkey-orange); outline-offset: 2px; }

/* More dropdown */
.menu-page .subnav .subnav-more {
  background: transparent;
  border: none;
  cursor: pointer;
  font: inherit;
}
/* Legacy inline dropdown removed; using modal instead */

/* Improve anchor positioning so headers aren't hidden under sticky bars */
.menu-page .category-header { scroll-margin-top: calc(var(--header-offset, 150px) + 80px); }

/* Mobile */
@media (max-width: 768px) {
  /* top is inherited from --header-offset */
  .menu-page .category-header { scroll-margin-top: calc(var(--header-offset, 150px) + 80px); }
}

/* Hide horizontal scrollbars for subnav links */
.menu-page .subnav .subnav-links::-webkit-scrollbar { display: none; }
.menu-page .subnav .subnav-links { scrollbar-width: none; }

/* Mobile: compact subnav chips and reduced margins */
@media (max-width: 768px) {
  .menu-page .subnav { margin: 10px auto; padding: 4px; }
  .menu-page .subnav a, .menu-page .subnav .subnav-more { padding: 8px 12px; font-size: 0.95rem; }
}

/* Slide-out subnav (mobile) */
@media (max-width: 899px) {
  /* Toggle button */
  .menu-page .subnav-toggle {
    position: fixed;
    left: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom));
    z-index: 51;
    background: var(--penkey-navy);
    color: #fff;
    border: 0;
    border-radius: 999px;
    padding: 10px 14px;
    font-weight: 800;
    letter-spacing: .02em;
    box-shadow: 0 10px 24px rgba(0,0,0,.18);
    opacity: .72;
    transition: opacity .2s ease, transform .15s ease;
  }
  .menu-page .subnav-toggle:hover,
  .menu-page .subnav-toggle:active,
  .menu-page .subnav-toggle:focus-visible,
  .menu-page .subnav-toggle[aria-expanded="true"] { opacity: 1; }
  .menu-page .subnav-toggle:focus-visible { outline: 2px solid var(--penkey-orange); outline-offset: 3px; }
  .menu-page .subnav-toggle.hidden { display: none; }

  /* Backdrop */
  .menu-page .subnav-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.35);
    backdrop-filter: blur(2px);
    z-index: 50;
  }

  /* Panel: repurpose .subnav as a bottom sheet */
  .menu-page .subnav {
    position: fixed;
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom));
    top: auto;
    transform: translateY(120%);
    opacity: 0;
    pointer-events: none;
    transition: transform .25s ease, opacity .2s ease;
    z-index: 60;
  }
  .menu-page .subnav.open { transform: translateY(0); opacity: 1; pointer-events: auto; }
}

/* Desktop: show sticky chips and hide toggle/backdrop */
@media (min-width: 900px) {
  .menu-page .subnav-toggle { display: none; }
  .menu-page .subnav-backdrop { display: none !important; }
}

/* Subnav wrapper aligns nav and inline search */
.menu-page .subnav-wrap {
  /* Use a non-grid sticky wrapper for best cross-browser support */
  position: -webkit-sticky;
  position: sticky;
  top: var(--header-offset, 150px);
  z-index: 999;
}
.menu-page .subnav .inline-search {
  height: 40px;
  border: 1px solid #e8e5e0;
  border-radius: 999px;
  padding: 0 12px;
  width: 260px;
}
.menu-page .subnav .inline-search:focus { outline: none; box-shadow: 0 0 0 2px rgba(255,152,0,.25); border-color: var(--penkey-orange); }

/* Hide inline search on small screens (mobile uses sidebar overlay) */
@media (max-width: 768px) {
  .menu-page .subnav-actions { display: none; }
}

/* Hide legacy sidebar on desktop; keep mobile overlay behavior */
@media (min-width: 769px) {
  .menu-page .menu-sidebar { display: none; }
}

/* A11y utility */
.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;
}

/* Highlight utility for modal title */
.hl-orange { color: var(--penkey-orange); }
