.pages-grid {
  display: flex;
  flex-direction: column;
  gap: 30px;
  margin-top: 20px;
  margin-bottom: 20px;
  align-items: center;
}

@media (max-width: 1024px) {
  .pages-grid {
    gap: 25px;
  }
}

@media (max-width: 600px) {
  .pages-grid {
    gap: 20px;
  }
}

.page-card {
  position: relative;
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  padding: 20px;
  margin-bottom: 2px;
  width: fit-content;
  max-width: 100%;
  transition: all 0.3s ease;
}

.page-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.page-card.out-of-range {
  opacity: 0.4;
  pointer-events: none;
}

.page-card canvas {
  display: block;
  border-radius: 8px;
  border: 1px solid #e5e7eb;
  /* Show at actual size but constrain to screen */
  max-width: min(100%, 800px) !important;
  height: auto !important;
  width: auto !important;
}

.page-number-badge {
  position: absolute;
  top: -8px;
  left: 8px;
  background: #4f46e5;
  color: white;
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  z-index: 5;
}

.watermark-preview {
  position: absolute;
  cursor: move;
  user-select: none;
  white-space: nowrap;
  pointer-events: auto;
  z-index: 10;
  /* CRITICAL: Remove line-height that was causing vertical offset */
  line-height: normal;
  touch-action: none;
}

.watermark-preview img {
  pointer-events: none;
  display: block;
  user-select: none;
}

.watermark-preview.has-image {
  display: flex;
  align-items: center;
  justify-content: center;
}

.watermark-preview .resize-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: #4f46e5;
  border: 2px solid white;
  border-radius: 50%;
  pointer-events: all;
  z-index: 20;
  touch-action: none;
}

.resize-handle-tl {
  top: -6px;
  left: -6px;
  cursor: nwse-resize;
}

.resize-handle-tr {
  top: -6px;
  right: -6px;
  cursor: nesw-resize;
}

.resize-handle-bl {
  bottom: -6px;
  left: -6px;
  cursor: nesw-resize;
}

.resize-handle-br {
  bottom: -6px;
  right: -6px;
  cursor: nwse-resize;
}

.page-apply-btn {
  position: absolute;
  bottom: -15px;
  left: 50%;
  transform: translateX(-50%);
  background: #f59e0b;
  color: white;
  border: none;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 11px;
  transition: all 0.2s;
  display: none;
  z-index: 50;
  white-space: nowrap;
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
}

.page-apply-btn:hover {
  background: #d97706;
  transform: translateX(-50%) translateY(-2px);
  box-shadow: 0 6px 16px rgba(245, 158, 11, 0.5);
}

.page-apply-btn.show {
  display: block;
}

.note-box {
  background: #f0f9ff;
  border-left: 4px solid #3b82f6;
  padding: 12px 16px;
  margin-top: 15px;
  font-size: 14px;
  border-radius: 4px;
}

.file-list i {
  color: red;
  cursor: pointer;
  margin-left: 8px;
}

#wmOptions label {
  font-weight: 600;
  margin-top: 0;
  margin-bottom: 4px;
  display: block;
  color: #1e3a8a;
  font-size: 11px;
}

/* ===== STICKY CONTROLS AT BOTTOM ===== */
#wmOptions {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: white;
  border-top: 3px solid #4f46e5;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  max-height: 180px;
  overflow-y: auto;
  padding: 8px 12px 10px;
  display: none;
  transition: max-height 0.3s ease;
}

#wmOptions.show {
  display: block;
}

.options-container {
  max-width: 1600px;
  margin: 0 auto;
  text-align: left;
}

.watermark-type-row {
  display: flex;
  align-items: center;
  gap: 15px;
  margin-bottom: 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid #e5e7eb;
}

.watermark-type-row > label {
  font-size: 12px;
  font-weight: 700;
  color: #1e3a8a;
  margin: 0;
}

#textControls {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: flex-end;
  margin-bottom: 8px;
}

#textControls > div {
  display: flex;
  flex-direction: column;
}

#textControls input[type="text"] {
  padding: 5px 8px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 12px;
  min-width: 180px;
}

.text-style-row {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.options-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 8px;
  margin-top: 0;
}

.option-group {
  display: flex;
  flex-direction: column;
}

.option-group input,
.option-group select {
  padding: 5px 7px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 12px;
  transition: border-color 0.2s;
}

.option-group input:focus,
.option-group select:focus {
  outline: none;
  border-color: #4f46e5;
}

.color-input-wrapper {
  display: flex;
  gap: 5px;
  align-items: center;
}

.color-input-wrapper input[type="color"] {
  width: 35px;
  height: 28px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  cursor: pointer;
  padding: 2px;
}

.color-input-wrapper input[type="text"] {
  width: 70px;
  padding: 5px 6px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 11px;
}

.text-style-buttons {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
  align-items: center;
}

.text-style-buttons button {
  padding: 5px 9px;
  border: 1px solid #e5e7eb;
  background: white;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s;
  font-size: 12px;
}

.text-style-buttons button.active {
  background: #4f46e5;
  color: white;
  border-color: #4f46e5;
}

.text-style-buttons button:hover {
  border-color: #4f46e5;
}

.text-style-buttons .option-group {
  min-width: 90px;
}

.text-style-buttons .option-group select,
.text-style-buttons .option-group input {
  padding: 5px 6px;
  font-size: 12px;
}

.radio-group {
  display: flex;
  gap: 12px;
  margin: 0;
  flex-wrap: wrap;
}

.radio-group label {
  display: flex;
  align-items: center;
  gap: 5px;
  margin: 0;
  font-weight: 500;
  cursor: pointer;
  color: #374151;
  font-size: 12px;
}

.radio-group input[type="radio"] {
  cursor: pointer;
}

.page-range-input {
  display: flex;
  gap: 5px;
}

.page-range-input input {
  flex: 1;
  padding: 5px 6px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 12px;
}

#imageControls input[type="file"] {
  padding: 5px 8px;
  border: 1px solid #e5e7eb;
  border-radius: 6px;
  font-size: 12px;
  margin-bottom: 5px;
}

.success-message {
  background: #d1fae5;
  border-left: 4px solid #059669;
  padding: 12px 16px;
  margin-top: 15px;
  font-size: 14px;
  border-radius: 4px;
  color: #065f46;
  display: none;
}

.success-message.show {
  display: block;
}

.btn-loading .btn-spinner {
  display: inline-block;
  margin-right: 8px;
}

.btn-spinner {
  display: none;
}

/* Scrollbar styling for options panel */
#wmOptions::-webkit-scrollbar {
  width: 5px;
}

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

#wmOptions::-webkit-scrollbar-thumb {
  background: #4f46e5;
  border-radius: 4px;
}

#wmOptions::-webkit-scrollbar-thumb:hover {
  background: #4338ca;
}

.watermarkBtn-container {
  position: fixed;
  bottom: 130px;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}

#errorMsg {
  display: block;
  position: absolute;
  top: -35px;
}

/* Responsive breakpoints */
@media (max-width: 1400px) {
  .options-grid {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  }
}

@media (max-width: 1298px) {
  .watermarkBtn-container {
    bottom: 143px;
  }
}

@media (max-width: 1200px) {
  #wmOptions {
    max-height: 200px;
  }

  .options-grid {
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  }

  #textControls input[type="text"] {
    min-width: 150px;
  }
}

@media (max-width: 900px) {
  .watermarkBtn-container {
    bottom: 193px;
  }
  #wmOptions {
    max-height: 220px;
  }

  .options-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  #textControls {
    flex-direction: column;
    align-items: stretch;
  }

  .text-style-row {
    width: 100%;
  }
}

@media (max-width: 768px) {
  .watermarkBtn-container {
    bottom: 223px;
  }
  #wmOptions {
    max-height: 250px;
    padding: 8px 10px;
  }

  .watermark-type-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .options-grid {
    grid-template-columns: 1fr 1fr;
    gap: 6px;
  }

  .text-style-buttons .option-group {
    min-width: 75px;
  }
}

@media (max-width: 600px) {
  .watermarkBtn-container {
    bottom: 217px;
  }
  #wmOptions {
    max-height: 260px;
    padding: 6px 8px;
  }

  #wmOptions label {
    font-size: 10px;
  }

  .watermark-type-row > label {
    font-size: 11px;
  }

  .option-group input,
  .option-group select {
    font-size: 11px;
    padding: 4px 6px;
  }

  .radio-group label {
    font-size: 11px;
  }

  .text-style-buttons button {
    padding: 4px 8px;
    font-size: 11px;
  }

  .text-style-buttons .option-group select,
  .text-style-buttons .option-group input {
    font-size: 11px;
  }

  #textControls input[type="text"] {
    font-size: 11px;
    padding: 4px 6px;
  }

  .color-input-wrapper input[type="text"] {
    font-size: 10px;
    width: 65px;
  }

  .options-grid {
    gap: 5px;
  }
}

@media (max-width: 506px) {
  .watermarkBtn-container {
    bottom: 227px;
  }
}

@media (max-width: 480px) {
  .watermarkBtn-container {
    bottom: 119px;
  }
  #wmOptions {
    max-height: 150px;
  }

  .text-style-buttons {
    gap: 4px;
  }

  .text-style-buttons .option-group {
    min-width: auto;
  }

  .page-range-input {
    gap: 4px;
  }

  .page-range-input input {
    width: 40px;
  }
}

@media (max-width: 450px) {
  .watermarkBtn-container {
    bottom: 127px;
  }
  #watermarkBtn {
    padding: 9px 14px;
    font-size: 14px;
  }
}
@media (max-width: 350px) {
  #wmOptions {
    padding-top: 20px;
  }
  .watermarkBtn-container {
    bottom: 140px;
  }
}
