/* Reset and base */
body {
  margin: 0;
  overflow: hidden;
  font-family: Arial, sans-serif;
}

#loading.viewer-loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: blur(4px);
  z-index: 1200;
  transition: opacity 0.25s ease;
}

#loading.viewer-loading-overlay.hidden {
  display: none;
}

.viewer-loading-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-width: 170px;
  padding: 24px 28px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 45px rgba(0, 0, 0, 0.16);
}

.viewer-loading-spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 4px solid rgba(9, 21, 75, 0.15);
  border-top-color: #09154b;
  animation: viewerSpin 0.8s linear infinite;
}

.viewer-loading-text {
  font-size: 16px;
  font-weight: 600;
  color: #1d2a42;
  text-align: center;
}

@keyframes viewerSpin {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

canvas {
  display: block;
  cursor: grab;
  
  /* CRITICAL FIX: Change from touch-action: none to manipulation */
  /* This allows pinch-zoom and pan while preventing double-tap zoom */
  touch-action: manipulation;
  
  /* Remove tap highlight on mobile */
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

canvas:active {
  cursor: grabbing;
}

/* Global reset button */
#global-reset-btn {
  position: fixed;
  top: 20px;
  right: 81px;
  z-index: 1000;
  background: white;
  border: 1px solid #ddd;
  padding: 8px 15px;
  border-radius: 25px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 6px rgba(0,0,0,0.1);
  display: flex;
  align-items: center;
  gap: 8px;
  transition: all 0.2s ease;
}

#global-reset-btn:hover {
  background: #f8f8f8;
  transform: scale(1.05);
  border-color: #2e86de;
  color: #2e86de;
}

#global-reset-btn i {
  font-size: 14px;
}

@media (max-width: 768px) {
  #global-reset-btn {
    top: 13px;
    right: 60px;
  }
  #global-reset-btn i {
    font-size: 22px;
  }
}

/* Toggle button bottom right */
#toggle-tools-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  background: linear-gradient(145deg, #ffffff, #f3f3f3);
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.2s ease;
  z-index: 100;
}

#toggle-tools-btn:hover {
  background-color: #e7f0fe;
}

#toggle-tools-btn i {
  font-size: 26px;
  color: rgb(0, 0, 49);
  transition: transform 0.3s ease;
}

@media (max-width: 768px) {
  #toggle-tools-btn {
    width: 40px;
    height: 40px;
    bottom: 25px;
  }
  #toggle-tools-btn i {
    font-size: 22px;
  }
}
 
/* Background color picker container - NOW AT BOTTOM LEFT */
#bg-color-picker-container {
  position: fixed;
  bottom: 20px;  /* Same as scale button */
  left: 17px;    /* Same as scale button */
  z-index: 150;
  display: flex;
  flex-direction: column-reverse;
  align-items: center;
  gap: 12px;
  transition: bottom 0.3s ease; /* Smooth transition when moving */
}

/* When scale button is visible, move color picker up */
#bg-color-picker-container.shifted-up {
  bottom: 90px; 
  /* Move above the scale button (20px + 40px button + 20px gap) */
}

/* Toggle button for color picker */
#color-picker-toggle {
  width: 46px;
  height: 46px;
  background: linear-gradient(145deg, #ffffff, #f3f3f3);
  border-radius: 50%;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s ease;
}

/* Style for the custom icon image */
#color-picker-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
  transition: transform 0.3s ease;
  pointer-events: none;
}

#color-picker-toggle:hover #color-picker-icon {
  transform: scale(1.05);
}

#color-picker-toggle i {
  font-size: 22px;
  color: rgb(0, 0, 49);
  transition: transform 0.3s ease;
}

/* Color picker list */
#bg-color-picker {
  background: rgba(255, 255, 255, 0.95);
  padding: 10px 8px;
  border-radius: 12px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: all 0.3s ease;
  transform-origin: bottom center;
}

#bg-color-picker.hidden {
  display: none;
  opacity: 0;
  transform: scale(0.8);
}

.color-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #ddd;
  cursor: pointer;
  transition: all 0.2s ease;
  background-color: transparent;
}

.color-btn:hover {
  box-shadow: 0 0 8px rgba(0, 0, 0, 0.3);
  transform: scale(1.1);
  border-color: #999;
}

.color-btn[data-color="#ffffff"] { background-color: #ffffff; }
.color-btn[data-color="#eeeeee"] { background-color: #eeeeee; }
.color-btn[data-color="#d0e7ff"] { background-color: #d0e7ff; }
.color-btn[data-color="#f5f0e6"] { background-color: #f5f0e6; }
.color-btn[data-color="#e6f2e6"] { background-color: #e6f2e6; }
.color-btn[data-color="#f7f3ea"] { background-color: #f7f3ea; }
.color-btn[data-color="#f0e6f7"] { background-color: #f0e6f7; }
.color-btn[data-color="#f9f9f9"] { background-color: #f9f9f9; }

@media (max-width: 768px) {
  #bg-color-picker-container {
    bottom: 25px;
    left: 20px;
  }

  #bg-color-picker-container.shifted-up {
    bottom: 90px;
    left: 20px; /* Smaller shift on mobile */
  }

  #color-picker-toggle {
    width: 40px;
    height: 40px;
  }

  #color-picker-toggle i {
    font-size: 20px;
  }

  #bg-color-picker {
    padding: 8px 6px;
    gap: 8px;
    border-radius: 10px;
  }

  .color-btn {
    width: 26px;
    height: 26px;
  }
}


/* Custom Alert Overlay - HIGHEST Z-INDEX */
.alert-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000; /* VERY HIGH - Above everything */
  opacity: 1;
  transition: opacity 0.3s ease;
}

.alert-overlay.hidden {
  display: none;
  opacity: 0;
}

/* Alert Box */
.alert-box {
  background: white;
  border-radius: 24px;
  padding: 35px 30px;
  max-width: 350px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.4);
  text-align: center;
  animation: alertSlideIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
  transform-origin: center;
}

@keyframes alertSlideIn {
  from {
    transform: scale(0.5) translateY(-40px);
    opacity: 0;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

/* Alert Icon */
.alert-icon {
  width: 70px;
  height: 70px;
  margin: 0 auto 24px;
  background: linear-gradient(135deg, #09154b 0%, #050a49cb 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 16px rgba(6, 18, 71, 0.329);
}

.alert-icon i {
  font-size: 34px;
  color: white;
}

/* Alert Message */
.alert-message {
  font-size: 17px;
  color: #2c3e50;
  line-height: 1.7;
  margin-bottom: 28px;
  font-weight: 500;
}

/* OK Button */
.alert-ok-btn {
  background: linear-gradient(135deg, #090a0e 0%, #160c4e9a 100%);
  color: white;
  border: none;
  padding: 14px 48px;
  border-radius: 28px;
  font-size: 17px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 6px 20px rgba(4, 7, 24, 0.808);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.alert-ok-btn:hover {
  transform: translateY(-3px);
  box-shadow: 0 10px 30px rgba(1, 7, 32, 0.6);
}

.alert-ok-btn:active {
  transform: translateY(-1px);
}

/* Mobile Responsive */
@media (max-width: 768px) {
  .alert-box {
    max-width: 300px;
    width: 88%;
    padding: 28px 24px;
    border-radius: 20px;
  }

  .alert-icon {
    width: 60px;
    height: 60px;
    margin-bottom: 20px;
  }

  .alert-icon i {
    font-size: 28px;
  }

  .alert-message {
    font-size: 16px;
    margin-bottom: 24px;
    line-height: 1.6;
  }

  .alert-ok-btn {
    padding: 12px 40px;
    font-size: 16px;
    border-radius: 24px;
  }
}

/* Extra small phones */
@media (max-width: 480px) {
  .alert-box {
    max-width: 300px;
    padding: 24px 20px;
  }

  .alert-message {
    font-size: 15px;
  }
}