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

:root {
  --bg: #f4f0e8;
  --surface: #fffcf7;
  --primary: #1f6f5c;
  --primary-dark: #165747;
  --accent: #c9922a;
  --accent-dark: #a87820;
  --secondary: #3a3228;
  --text: #2c2620;
  --text-muted: #6b6258;
  --border: #ddd4c4;
  --danger: #b83a3a;
  --shadow: 0 4px 20px rgba(31, 111, 92, 0.1);
  --radius: 12px;
  --cart-width: 360px;
  --menu-min-col: 200px;
  --menu-img-height: 160px;
  --sticky-offset: 5.5rem;
  --touch-min: 44px;
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(18px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translateY(-12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes scaleIn {
  from {
    opacity: 0;
    transform: scale(0.92);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes slideUpBar {
  from {
    opacity: 0;
    transform: translateY(100%);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes cardAdded {
  0% { transform: scale(1); }
  40% { transform: scale(0.96); border-color: var(--primary); box-shadow: 0 0 0 3px rgba(31, 111, 92, 0.25); }
  100% { transform: scale(1); }
}

@keyframes totalBump {
  0% { transform: scale(1); }
  50% { transform: scale(1.08); color: var(--accent-dark); }
  100% { transform: scale(1); }
}

@keyframes shimmer {
  0% { background-position: -200% center; }
  100% { background-position: 200% center; }
}

@keyframes modalBackdropIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes modalContentIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

@keyframes emojiFloat {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  25% { transform: translateY(-4px) rotate(-5deg); }
  75% { transform: translateY(-2px) rotate(5deg); }
}

@keyframes bgShift {
  0%, 100% { background-position: 0% 50%; }
  50% { background-position: 100% 50%; }
}

@keyframes slideInLeft {
  from {
    opacity: 0;
    transform: translateX(-16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes qrPulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(31, 111, 92, 0.3); }
  50% { transform: scale(1.03); box-shadow: 0 0 0 12px rgba(31, 111, 92, 0); }
}

@keyframes tabGlow {
  from { box-shadow: 0 0 0 0 rgba(31, 111, 92, 0.4); }
  to { box-shadow: 0 4px 16px rgba(31, 111, 92, 0.35); }
}

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

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: linear-gradient(135deg, #f4f0e8 0%, #ebe4d6 35%, #f7f2ea 70%, #e8e0d0 100%);
  background-size: 300% 300%;
  animation: fadeIn 0.5s var(--ease-out), bgShift 18s ease infinite;
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  box-shadow: var(--shadow);
  position: sticky;
  top: 0;
  z-index: 100;
  animation: slideDown 0.5s var(--ease-out);
}

.header h1,
.site-title {
  font-size: 1.5rem;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.35rem;
  animation: fadeIn 0.6s var(--ease-out);
}

#restaurant-name {
  color: var(--primary);
  background: linear-gradient(90deg, var(--primary) 0%, var(--accent) 50%, var(--primary-dark) 100%);
  background-size: 200% auto;
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  animation: shimmer 5s linear infinite;
}

.title-emoji {
  display: inline-block;
  font-size: 1.25rem;
  margin-left: 0.15rem;
  -webkit-text-fill-color: initial;
  animation: emojiFloat 2.5s ease-in-out infinite;
}

.title-emoji span {
  display: inline-block;
}

.title-emoji span:nth-child(2) {
  animation: emojiFloat 2.5s ease-in-out 0.3s infinite;
}

.tabs {
  display: flex;
  gap: 0.5rem;
}

.tab,
.admin-tab {
  padding: 0.5rem 1.25rem;
  border: 2px solid var(--border);
  background: var(--surface);
  color: var(--secondary);
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: all 0.25s var(--ease-out);
}

.tab:hover,
.admin-tab:hover {
  border-color: var(--primary);
  color: var(--primary);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(31, 111, 92, 0.18);
}

.tab:active,
.admin-tab:active {
  transform: translateY(0) scale(0.98);
}

.tab.active,
.admin-tab.active {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  border-color: var(--primary);
  color: #fff;
  animation: tabGlow 0.4s var(--ease-out) forwards;
}

/* Views */
.view {
  display: none;
  padding: 1.5rem;
  max-width: 1400px;
  margin: 0 auto;
}

.view.active {
  display: block;
}

.view.view-enter {
  animation: fadeInUp 0.45s var(--ease-out);
}

.animate-in {
  animation: fadeInUp 0.5s var(--ease-out) both;
}

/* Billing layout */
.billing-layout {
  display: grid;
  grid-template-columns: 1fr var(--cart-width);
  gap: 1.5rem;
  align-items: start;
}

.menu-section h2,
.cart-panel h2 {
  font-size: 1.25rem;
  margin-bottom: 1rem;
  color: var(--secondary);
  animation: slideInLeft 0.5s var(--ease-out) both;
}

.menu-section h2 {
  animation-delay: 0.1s;
}

.cart-panel h2 {
  animation-delay: 0.2s;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--menu-min-col), 1fr));
  gap: 1rem;
}

.menu-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  cursor: pointer;
  overflow: hidden;
  text-align: center;
  transition: transform 0.3s var(--ease-out), box-shadow 0.3s var(--ease-out), border-color 0.3s;
  display: flex;
  flex-direction: column;
}

.menu-card:hover {
  transform: translateY(-6px) scale(1.02);
  box-shadow: 0 12px 28px rgba(31, 111, 92, 0.18);
  border-color: var(--primary);
}

.menu-card:active {
  transform: translateY(-2px) scale(0.98);
}

.menu-card.added {
  animation: cardAdded 0.45s var(--ease-spring);
}

.menu-card img {
  width: 100%;
  height: var(--menu-img-height);
  object-fit: cover;
  display: block;
  background: var(--bg);
  transition: transform 0.4s var(--ease-out);
}

.menu-card:hover img {
  transform: scale(1.06);
}

.menu-card-name {
  display: block;
  padding: 0.6rem 0.5rem 0.2rem;
  font-weight: 600;
  font-size: 1rem;
}

.menu-card-price {
  display: block;
  padding: 0 0.5rem 0.75rem;
  color: var(--accent);
  font-weight: 700;
}

/* Cart panel */
.cart-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  position: sticky;
  top: var(--sticky-offset);
  scroll-margin-top: var(--sticky-offset);
  animation: fadeInUp 0.55s var(--ease-out) 0.15s both;
}

.cart-items {
  min-height: 120px;
  max-height: 400px;
  overflow-y: auto;
  margin-bottom: 1rem;
}

.cart-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0;
  border-bottom: 1px solid var(--border);
}

.cart-line-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.cart-line-name {
  font-weight: 600;
  font-size: 0.95rem;
}

.cart-line-price {
  font-size: 0.85rem;
  color: var(--text-muted);
}

.cart-line-qty {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.qty-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--border);
  background: var(--bg);
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  color: var(--secondary);
}

.qty-btn:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.cart-footer {
  border-top: 2px solid var(--border);
  padding-top: 1rem;
}

.cart-total {
  display: flex;
  justify-content: space-between;
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 1rem;
  color: var(--accent);
  transition: transform 0.2s;
}

.cart-total .total-bump,
#cart-total.total-bump {
  animation: totalBump 0.4s var(--ease-spring);
}

#cart-total {
  display: inline-block;
}

.cart-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

/* Buttons */
.btn {
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.95rem;
  font-weight: 600;
  transition: background 0.25s, transform 0.2s var(--ease-out), box-shadow 0.25s;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(44, 36, 24, 0.12);
}

.btn:active {
  transform: translateY(0) scale(0.97);
}

.btn-primary {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: #fff;
}

.btn-primary:hover {
  background: linear-gradient(135deg, #258f77 0%, var(--primary) 100%);
  box-shadow: 0 6px 20px rgba(31, 111, 92, 0.3);
}

.btn-secondary {
  background: var(--bg);
  color: var(--secondary);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: #a93226;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
}

/* Admin */
.admin-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.admin-panel {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.admin-panel.active {
  display: block;
  animation: fadeInUp 0.45s var(--ease-out);
}

.admin-panel h2 {
  margin-bottom: 1.25rem;
  color: var(--secondary);
}

.menu-form {
  max-width: 480px;
  margin-bottom: 2rem;
}

.form-row {
  margin-bottom: 1rem;
}

.form-row label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.35rem;
  font-size: 0.9rem;
}

.form-row input[type="text"],
.form-row input[type="number"],
.form-row input[type="month"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
}

.form-row input:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.checkbox-row label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 500;
  cursor: pointer;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
}

.admin-table-wrap {
  overflow-x: auto;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.admin-table th,
.admin-table td {
  padding: 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.admin-table tbody tr.animate-in {
  animation: fadeInUp 0.45s var(--ease-out) both;
}

.admin-table th {
  background: var(--bg);
  font-weight: 600;
  color: var(--secondary);
}

.summary-card.animate-in {
  animation: scaleIn 0.5s var(--ease-out) both;
}

.table-thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
}

.table-actions {
  display: flex;
  gap: 0.4rem;
}

.empty-msg {
  color: var(--text-muted);
  font-style: italic;
  padding: 1rem 0;
}

/* Reports */
.report-filters {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}

.report-filters label {
  font-weight: 600;
}

.summary-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.summary-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  transition: transform 0.3s var(--ease-out), box-shadow 0.3s;
}

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

.summary-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.summary-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

#report-summary h3 {
  margin: 1rem 0 0.75rem;
  font-size: 1rem;
  color: var(--secondary);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(44, 36, 24, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
  opacity: 0;
  transition: opacity 0.3s var(--ease-out);
}

.modal.modal-open {
  opacity: 1;
  animation: modalBackdropIn 0.3s var(--ease-out);
}

.modal[hidden] {
  display: none;
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 400px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  transform: scale(0.92);
  opacity: 0;
}

.modal.modal-open .modal-content {
  animation: modalContentIn 0.4s var(--ease-spring) forwards;
}

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

.modal-close:hover {
  color: var(--text);
}

.modal-content h2 {
  margin-bottom: 1rem;
  color: var(--primary);
}

.pay-summary {
  margin-bottom: 1rem;
}

.pay-line {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 0;
  font-size: 0.95rem;
}

.pay-line.pay-total {
  border-top: 2px solid var(--border);
  margin-top: 0.5rem;
  padding-top: 0.75rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
}

.qr-code {
  display: flex;
  justify-content: center;
  margin: 1rem 0;
  min-height: 200px;
  align-items: center;
  border-radius: var(--radius);
  padding: 0.5rem;
}

.qr-code.qr-pulse {
  animation: qrPulse 2s ease-in-out infinite;
}

.pay-note {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
}

.modal-actions .btn {
  flex: 1;
}

/* Print bill */
.print-bill {
  display: none;
}

@media print {
  body * {
    visibility: hidden;
  }

  .print-bill,
  .print-bill * {
    visibility: visible;
  }

  .print-bill {
    display: block;
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    padding: 2rem;
    font-family: 'Courier New', monospace;
  }

  .print-bill h2 {
    text-align: center;
    margin-bottom: 0.5rem;
  }

  .print-bill p {
    text-align: center;
    margin-bottom: 1rem;
    font-size: 0.9rem;
  }

  .print-bill table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1rem;
  }

  .print-bill th,
  .print-bill td {
    padding: 0.4rem;
    border-bottom: 1px dashed #ccc;
    text-align: left;
  }

  .print-total {
    font-size: 1.2rem;
    font-weight: bold;
    text-align: right !important;
  }

  .print-thanks {
    margin-top: 1.5rem;
    font-style: italic;
  }
}

/* Mobile sticky cart bar */
.mobile-cart-bar {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 150;
  background: var(--surface);
  border-top: 3px solid var(--accent);
  padding: 0.75rem 1rem;
  padding-bottom: calc(0.75rem + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -6px 24px rgba(31, 111, 92, 0.15);
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.mobile-cart-bar:not([hidden]) {
  display: flex;
  animation: slideUpBar 0.4s var(--ease-spring);
}

.mobile-cart-bar.bar-enter {
  animation: slideUpBar 0.4s var(--ease-spring);
}

.mobile-cart-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  min-width: 0;
}

#mobile-cart-count {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

#mobile-cart-total {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--accent);
}

#btn-mobile-cart-scroll {
  flex-shrink: 0;
  padding: 0.65rem 1.25rem;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  min-height: var(--touch-min);
}

#btn-mobile-cart-scroll:hover {
  background: var(--primary-dark);
}

/* Responsive */
@media (max-width: 1024px) {
  :root {
    --menu-min-col: 180px;
    --menu-img-height: 140px;
  }

  .billing-layout {
    grid-template-columns: 1fr;
  }

  .cart-panel {
    position: static;
  }

  .cart-actions {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .cart-actions .btn {
    flex: 1;
    min-width: 120px;
  }

  .admin-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.25rem;
  }

  .admin-tab {
    flex-shrink: 0;
  }
}

@media (max-width: 767px) {
  :root {
    --menu-min-col: 140px;
    --menu-img-height: 140px;
    --sticky-offset: 4.5rem;
  }

  body {
    padding-bottom: 0;
  }

  #billing-view.view.active {
    padding-bottom: calc(4.5rem + env(safe-area-inset-bottom, 0px));
  }

  .header {
    flex-direction: column;
    align-items: stretch;
    padding: 0.75rem 1rem;
  }

  .site-title,
  .header h1 {
    font-size: 1.25rem;
  }

  .tabs {
    width: 100%;
  }

  .tab {
    flex: 1;
    text-align: center;
    min-height: var(--touch-min);
  }

  .view {
    padding: 1rem;
  }

  .menu-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
  }

  .menu-card-name {
    font-size: 0.9rem;
  }

  .menu-card-price {
    font-size: 0.9rem;
  }

  .btn {
    padding: 0.75rem 1rem;
    min-height: var(--touch-min);
  }

  .qty-btn {
    width: var(--touch-min);
    height: var(--touch-min);
    font-size: 1.1rem;
  }

  .cart-actions {
    flex-direction: column;
  }

  .cart-actions .btn {
    width: 100%;
    min-width: unset;
  }

  .form-row input[type="text"],
  .form-row input[type="number"],
  .form-row input[type="month"] {
    font-size: 16px;
  }

  .admin-table th,
  .admin-table td {
    padding: 0.5rem;
    font-size: 0.85rem;
  }

  .table-actions {
    flex-direction: column;
  }

  .table-actions .btn {
    width: 100%;
  }

  .report-filters {
    flex-direction: column;
    align-items: stretch;
  }

  .report-filters input[type="month"] {
    width: 100%;
    font-size: 16px;
  }

  .modal-content {
    padding: 1.25rem;
    max-height: 85vh;
  }

  .modal-actions {
    flex-direction: column;
  }
}

@media (min-width: 1025px) {
  .site-title,
  .header h1 {
    font-size: 1.75rem;
  }

  .mobile-cart-bar {
    display: none !important;
  }
}

@media (min-width: 1400px) {
  :root {
    --menu-min-col: 220px;
    --menu-img-height: 170px;
  }

  .view {
    max-width: 1600px;
    padding: 1.5rem 2rem;
  }
}

/* Image credits */
.image-credits {
  margin-top: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.image-credits summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--secondary);
}

.image-credits ul {
  margin: 0.75rem 0 0 1.25rem;
}

.image-credits li {
  margin-bottom: 0.35rem;
}

.image-credits a {
  color: var(--primary);
}

.credits-note {
  margin-top: 0.75rem;
  font-size: 0.8rem;
}
