/* ==================== GLOBAL STYLES ==================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Prevent body scroll when modal is open */
body.modal-open {
  overflow: hidden;
  height: 100vh;
}

/* ==================== SCROLLBAR ==================== */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
  background: #d97706;
  border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
  background: #b45309;
}

body.dark::-webkit-scrollbar-track {
  background: #1f2937;
}

body.dark::-webkit-scrollbar-thumb {
  background: #d97706;
}

/* ==================== ANIMATIONS ==================== */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes pulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

@keyframes shake {
  0%, 100% {
    transform: translateX(0);
  }
  10%, 30%, 50%, 70%, 90% {
    transform: translateX(-10px);
  }
  20%, 40%, 60%, 80% {
    transform: translateX(10px);
  }
}

.animate-fadeIn {
  animation: fadeIn 0.5s ease-out;
}

.animate-slideInRight {
  animation: slideInRight 0.5s ease-out;
}

.animate-pulse {
  animation: pulse 2s infinite;
}

.animate-shake {
  animation: shake 0.5s;
}

/* ==================== CUSTOM UTILITIES ==================== */
.gradient-bg {
  background: linear-gradient(135deg, #fbbf24 0%, #f59e0b 100%);
}

.glass-effect {
  background: rgba(255, 255, 255, 0.1);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.shadow-custom {
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.1);
}

/* ==================== MODAL & OVERLAY PROPER Z-INDEX ==================== */
/* Main content should be below modals */
main {
  position: relative;
  z-index: 1;
}

/* Footer positioning is controlled per-page (e.g., using utility classes). */

/* Form containers in admin should not block */
#packageFormContainer,
#dishFormContainer,
#discountFormContainer {
  position: relative;
  z-index: 1;
}

/* Modal overlays */
#orderSummaryContainer {
  z-index: 100 !important;
}

#checkoutContainer {
  z-index: 110 !important;
}

#successModal {
  z-index: 120 !important;
}

#trackingModal {
  z-index: 105 !important;
}

#orderDetailModal {
  z-index: 100 !important;
}

#statusUpdateModal {
  z-index: 100 !important;
}

/* Notification should be above everything */
.notification {
  z-index: 9999 !important;
}

/* Ensure modal backdrops don't interfere */
section[id$="Modal"],
section[id$="Container"] {
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: auto;
}

/* Modal content should be clickable */
section[id$="Modal"] > div,
section[id$="Container"] > div,
section[id$="Container"] > form {
  pointer-events: auto;
}

/* ==================== IMAGE LOADING ==================== */
img {
  max-width: 100%;
  height: auto;
}

img[src*="placeholder"] {
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
}

/* ==================== FORM STYLES ==================== */
/* Light mode input visibility and contrast */
body:not(.dark) input[type="text"],
body:not(.dark) input[type="email"],
body:not(.dark) input[type="number"],
body:not(.dark) input[type="tel"],
body:not(.dark) textarea,
body:not(.dark) select {
  color: #333333 !important;
  background-color: #ffffff !important;
}

/* Placeholder visibility across modes */
input::placeholder,
textarea::placeholder {
  color: #888888 !important;
}

/* Admin tables visibility */
body:not(.dark) table thead th,
body:not(.dark) table tbody td {
  color: #dcdddd !important;
}
body.dark table thead th,
body.dark table tbody td,
html.dark table thead th,
html.dark table tbody td {
  color: #ffffff !important;
}

/* Focus state: clear border highlight, maintain dark text */
body:not(.dark) input:focus,
body:not(.dark) textarea:focus,
body:not(.dark) select:focus {
  outline: none;
  border: 2px solid #ff9800 !important;
  box-shadow: none !important;
  color: #333333 !important;
}

/* Dark mode input focus: match highlight while preserving theme */
body.dark input:focus,
body.dark textarea:focus,
body.dark select:focus {
  outline: none;
  border: 2px solid #ff9800 !important;
  box-shadow: none !important;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: #f59e0b;
  box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.1);
}

/* Dark mode overrides removed to keep solid backgrounds in modals */

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

/* ==================== TABLE STYLES ==================== */
table {
  border-collapse: collapse;
  width: 100%;
}

table thead {
  position: sticky;
  top: 0;
  z-index: 10;
}

table tbody tr:hover {
  background-color: rgba(251, 191, 36, 0.1);
}

main table thead th,
main table tbody td {
  color: #ffffff !important;
}

main table tbody tr:hover th,
main table tbody tr:hover td {
  color: #fb923c !important;
}

/* Admin data tables: force white text, orange on hover (light & dark) */
#ordersTable,
#ordersTable * ,
#discountTable,
#discountTable *,
#packageTable,
#packageTable *,
#variantTemplatesTable,
#variantTemplatesTable *,
#dishTable,
#dishTable *,
#inquiriesTable,
#inquiriesTable *,
#articlesTable,
#articlesTable * {
  color: #ffffff !important;
}

#ordersTable tbody tr:hover,
#ordersTable tbody tr:hover *,
#discountTable tbody tr:hover,
#discountTable tbody tr:hover *,
#packageTable tbody tr:hover,
#packageTable tbody tr:hover *,
#variantTemplatesTable tbody tr:hover,
#variantTemplatesTable tbody tr:hover *,
#dishTable tbody tr:hover,
#dishTable tbody tr:hover *,
#inquiriesTable tbody tr:hover,
#inquiriesTable tbody tr:hover *,
#articlesTable tbody tr:hover,
#articlesTable tbody tr:hover * {
  color: #fb923c !important;
}

/* ==================== LOADING SPINNER ==================== */
.spinner {
  border: 3px solid #f3f3f3;
  border-top: 3px solid #f59e0b;
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* ==================== TOAST NOTIFICATION ==================== */
.toast {
  position: fixed;
  top: 20px;
  right: 20px;
  padding: 16px 24px;
  background: white;
  border-radius: 8px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  z-index: 9999;
  animation: slideInRight 0.3s ease-out;
}

.toast.success {
  border-left: 4px solid #10b981;
}

.toast.error {
  border-left: 4px solid #ef4444;
}

.toast.info {
  border-left: 4px solid #3b82f6;
}

/* ==================== BUTTON EFFECTS ==================== */
button {
  transition: all 0.3s ease;
}

button:active {
  transform: scale(0.95);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

/* ==================== CARD HOVER EFFECTS ==================== */
.card-hover {
  transition: all 0.3s ease;
}

.card-hover:hover {
  transform: translateY(-5px);
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
}

.form-input, .form-select, .form-textarea {
  @apply w-full border border-gray-300 rounded-lg px-3 py-2 bg-white dark:bg-gray-700 dark:border-gray-600 focus:ring-2 focus:ring-yellow-500 focus:border-yellow-500 transition-colors;
}

/* ==================== BADGE STYLES ==================== */
.badge {
  display: inline-block;
  padding: 4px 12px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-primary {
  background-color: #dbeafe;
  color: #1e40af;
}

.badge-success {
  background-color: #d1fae5;
  color: #065f46;
}

.badge-warning {
  background-color: #fef3c7;
  color: #92400e;
}

.badge-danger {
  background-color: #fee2e2;
  color: #991b1b;
}

/* ==================== RESPONSIVE UTILITIES ==================== */
@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }
  
  table {
    font-size: 0.875rem;
  }
  
  .modal-content {
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .table-responsive {
    overflow-x: auto;
  }
}

/* ==================== PRINT STYLES ==================== */
@media print {
  header,
  footer,
  .no-print {
    display: none !important;
  }
  
  body {
    background: white;
  }
  
  .print-only {
    display: block !important;
  }
}

@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }

  table {
    font-size: 0.875rem;
  }

  .modal-content {
    width: 95%;
    max-height: 90vh;
    overflow-y: auto;
  }

  .stats-grid {
    grid-template-columns: 1fr;
  }

  .form-grid {
    grid-template-columns: 1fr;
  }

  .table-responsive {
    overflow-x: auto;
  }
}

/* ==================== DARK MODE ENHANCEMENTS ==================== */
.dark {
  color-scheme: dark;
}

body.dark {
  background-color: #111827;
  color: #f9fafb;
}

body.dark input,
body.dark textarea,
body.dark select {
  background-color: #1f2937;
  border-color: #374151;
  color: #f9fafb;
}

body.dark input:focus,
body.dark textarea:focus,
body.dark select:focus {
  border-color: #f59e0b;
}

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

body.dark table tbody td,
body.dark table tbody td *,
html.dark table tbody td,
html.dark table tbody td *,
body.dark table thead th,
body.dark table thead th *,
html.dark table thead th,
html.dark table thead th * {
  color: #ffffff !important;
}

/* Force high-contrast text for all tables in admin dashboard, regardless of theme */
#adminRoot table thead,
#adminRoot table thead tr {
  background-color: #111827 !important;
}

#adminRoot table tbody {
  background-color: #020617 !important;
}

#adminRoot table thead th,
#adminRoot table thead th * {
  color: #ffffff !important;
}

#adminRoot table thead tr.bg-gray-900,
#adminRoot table thead tr.bg-gray-900 * {
  color: #ffffff !important;
}

#adminRoot table tbody td {
  color: #ffffff !important;
}

#adminRoot table tbody td *:not(.badge):not(.order-status) {
  color: #ffffff !important;
}

#discountTable tbody tr:hover,
#discountTable tbody tr:hover td,
#discountTable tbody tr:hover td * {
  color: #000000 !important;
}

#adminRoot #ordersTable .order-status,
#ordersTable .order-status {
  color: #1f2937 !important;
}

#adminRoot h2,
#adminRoot h2 * {
  color: #ffffff !important;
}

button:focus-visible,
a:focus-visible {
  outline: 2px solid #f59e0b;
  outline-offset: 2px;
}

/* ==================== CUSTOM ANIMATIONS FOR MENU ITEMS ==================== */
.menu-item {
  animation: fadeIn 0.5s ease-out;
  animation-fill-mode: both;
}

.menu-item:nth-child(1) { animation-delay: 0.05s; }
.menu-item:nth-child(2) { animation-delay: 0.1s; }
.menu-item:nth-child(3) { animation-delay: 0.15s; }
.menu-item:nth-child(4) { animation-delay: 0.2s; }
.menu-item:nth-child(5) { animation-delay: 0.25s; }
.menu-item:nth-child(6) { animation-delay: 0.3s; }

/* ==================== FLOATING CART STYLES ==================== */
.floating-cart {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 30;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

/* ==================== QUANTITY CONTROLS ==================== */
.qty-control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.qty-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  border-radius: 8px;
  transition: all 0.2s;
}

.qty-btn:active {
  transform: scale(0.9);
}

/* ==================== IMAGE PLACEHOLDER ==================== */
.img-placeholder {
  background: linear-gradient(135deg, #f3f4f6 0%, #e5e7eb 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #9ca3af;
  font-size: 2rem;
}

/* ==================== EMPTY STATE ==================== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: #9ca3af;
}

.empty-state-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

/* ==================== SUCCESS CHECKMARK ANIMATION ==================== */
@keyframes checkmark {
  0% {
    stroke-dashoffset: 50;
  }
  100% {
    stroke-dashoffset: 0;
  }
}

.checkmark-circle {
  stroke-dasharray: 166;
  stroke-dashoffset: 166;
  animation: checkmark 0.6s ease-in-out;
}

/* ==================== UTILITY CLASSES ==================== */
.text-shadow {
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.truncate-2-lines {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.hover-scale {
  transition: transform 0.3s ease;
}

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

/* ==================== MODAL TRANSITIONS ==================== */
.modal-content {
  animation: modalFadeIn 0.3s ease-out;
}

@keyframes modalFadeIn {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* ==================== SCROLLBAR IN MODALS ==================== */
section > div,
section > form {
  scrollbar-width: thin;
  scrollbar-color: #d97706 #f3f4f6;
}

section > div::-webkit-scrollbar,
section > form::-webkit-scrollbar {
  width: 6px;
}

section > div::-webkit-scrollbar-track,
section > form::-webkit-scrollbar-track {
  background: #f3f4f6;
  border-radius: 3px;
}

section > div::-webkit-scrollbar-thumb,
section > form::-webkit-scrollbar-thumb {
  background: #d97706;
  border-radius: 3px;
}

/* ==================== BUTTON LOADING STATE ==================== */
button.loading {
  position: relative;
  color: transparent;
  pointer-events: none;
}

button.loading::after {
  content: "";
  position: absolute;
  width: 16px;
  height: 16px;
  top: 50%;
  left: 50%;
  margin-left: -8px;
  margin-top: -8px;
  border: 2px solid #ffffff;
  border-radius: 50%;
  border-top-color: transparent;
  animation: spin 0.8s linear infinite;
}

/* ==================== FILE INPUT STYLING ==================== */
input[type="file"] {
  cursor: pointer;
}

input[type="file"]::file-selector-button {
  padding: 8px 16px;
  background: #f59e0b;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  margin-right: 12px;
  font-weight: 600;
  transition: background 0.3s;
}

input[type="file"]::file-selector-button:hover {
  background: #d97706;
}

.dark input[type="file"]::file-selector-button {
  background: #d97706;
}

.dark input[type="file"]::file-selector-button:hover {
  background: #b45309;
}

/* ==================== SELECT DROPDOWN ==================== */
select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23666' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ==================== SUCCESS ANIMATION ==================== */
#successModal .text-6xl {
  animation: successBounce 0.6s ease-out;
}

@keyframes successBounce {
  0% {
    transform: scale(0);
    opacity: 0;
  }
  50% {
    transform: scale(1.2);
  }
  100% {
    transform: scale(1);
    opacity: 1;
  }
}

/* ==================== TRACKING CODE HIGHLIGHT ==================== */
#trackingCode {
  letter-spacing: 2px;
  user-select: all;
  padding: 8px;
  background: rgba(234, 179, 8, 0.1);
  border-radius: 8px;
  cursor: pointer;
}

#trackingCode:hover {
  background: rgba(234, 179, 8, 0.2);
}

/* ==================== FORM VALIDATION STATES ==================== */
input:invalid:not(:placeholder-shown),
textarea:invalid:not(:placeholder-shown),
select:invalid:not(:placeholder-shown) {
  border-color: #ef4444;
}

input:valid:not(:placeholder-shown),
textarea:valid:not(:placeholder-shown),
select:valid:not(:placeholder-shown) {
  border-color: #10b981;
}

/* ==================== LOADING OVERLAY ==================== */
.form-loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
}

.form-loading-overlay .spinner {
  width: 60px;
  height: 60px;
  border-width: 4px;
}

/* ==================== TOGGLE SWITCH ==================== */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  transition: .4s;
  border-radius: 24px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked + .toggle-slider {
  background-color: #f59e0b;
}

input:checked + .toggle-slider:before {
  transform: translateX(20px);
}

/* ==================== RESPONSIVE IMPROVEMENTS ==================== */
@media (max-width: 640px) {
  section > div,
  section > form {
    max-height: 85vh;
    margin: 0 8px;
  }
  #cartAside { display: none; }
  .mobile-cart-button { display: flex !important; }
}

/* Mobile cart */
.mobile-cart-button {
  position: fixed;
  right: 16px;
  bottom: 16px;
  width: 56px;
  height: 56px;
  border-radius: 9999px;
  background: #f59e0b;
  color: #1f2937;
  box-shadow: 0 10px 20px rgba(0,0,0,0.15);
  align-items: center;
  justify-content: center;
  font-size: 22px;
  z-index: 40;
}
.mobile-cart-button:active { transform: scale(0.95); }
.mobile-cart-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #ef4444;
  color: #fff;
  font-size: 12px;
  line-height: 1;
  padding: 4px 6px;
  border-radius: 9999px;
  min-width: 20px;
  text-align: center;
}
.mobile-cart-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
}
.mobile-cart-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  background: #ffffff;
  border-top-left-radius: 16px;
  border-top-right-radius: 16px;
  box-shadow: 0 -10px 30px rgba(0,0,0,0.2);
  max-height: 80vh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  animation: slideUp 0.25s ease-out;
}
.mobile-cart-header {
  display: grid;
  grid-template-columns: 1fr auto 32px;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid #f3f4f6;
}
.mobile-cart-title { font-weight: 700; color: #111827; }
.mobile-cart-total { font-weight: 700; color: #065f46; }
.mobile-cart-close { font-size: 24px; color: #6b7280; }
.mobile-cart-body { padding: 12px 16px; max-height: 52vh; overflow-y: auto; }
.mobile-cart-footer { padding: 12px 16px; border-top: 1px solid #f3f4f6; }
.mobile-cart-action {
  width: 100%;
  background: #d97706;
  color: #ffffff;
  padding: 12px;
  border-radius: 8px;
  font-weight: 600;
}

@media (min-width: 641px) {
  .mobile-cart-button { display: none !important; }
  #mobileCartSheet { display: none !important; }
}

@media (max-width: 640px) {
  #contactSection > div { max-height: none; overflow: visible; }
}
