/**
 * Puzzle CAPTCHA Styles - New Design
 * 
 * Layout: Left Strip | Drop Zones | Right Strip
 * Pieces: Draggable below the puzzle area
 * 
 * V10.1 - Modal Window Support
 */

/* Modal Overlay */
.puzzle-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s ease;
}

.puzzle-modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

/* Modal Container */
.puzzle-modal {
  position: relative;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
  max-width: 95vw;
  max-height: 95vh;
  overflow: auto;
  transform: scale(0.9);
  transition: transform 0.3s ease;
}

.puzzle-modal-overlay.active .puzzle-modal {
  transform: scale(1);
}

/* Modal Close Button */
.puzzle-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.1);
  color: #666;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  transition: all 0.2s ease;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
}

.puzzle-modal-close:hover {
  background: rgba(0, 0, 0, 0.2);
  color: #333;
}

.puzzle-captcha {
  max-width: 900px;
  margin: 0;
  padding: 20px;
  background: #f9f9f9;
  border-radius: 8px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Header */
.puzzle-header {
  text-align: center;
}

.puzzle-header h3 {
  margin: 0 0 10px 0;
  color: #333;
  font-size: 18px;
  padding-right: 30px;
}

.puzzle-header p {
  margin: 0;
  color: #666;
  font-size: 14px;
}

/* Main Container - 3 columns layout */
.puzzle-container-new {
  display: flex;
  align-items: flex-start;
  margin-bottom: 10px;
  background: white;
  border: 1px solid #ccc;
  border-radius: 4px;
  padding: 0;
  /* height and width will be set by JavaScript */
  width: fit-content;
}

/* Left and Right Strips */
.puzzle-strip {
  /* flex-basis set dynamically by JavaScript */
  display: flex;
  align-items: stretch;
  justify-content: center;
  overflow: hidden;
  border: none;
  height: 100%;
}

.puzzle-strip img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

.puzzle-strip-left {
  order: 1;
}

.puzzle-strip-right {
  order: 3;
  position: relative;
}

/* Refresh button in right strip */
.puzzle-refresh-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 42px;
  height: 42px;
  font-size: 31px;
  line-height: 1;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  color: #2196F3;
  cursor: pointer;
  transition: all 0.3s ease;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
  padding-left: 4px;
  padding-top: 2px;
}

.puzzle-refresh-btn:hover {
  background: #2196F3;
  color: white;
  transform: rotate(180deg);
}

.puzzle-refresh-btn:active {
  transform: rotate(360deg);
}

/* Middle Section - Drop Zones */
.puzzle-middle {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0;
  order: 2;
  height: 100%;
}

.puzzle-drop-zone {
  flex: 1;
  background: #fff5f8;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
  position: relative;
  overflow: hidden;
}

.puzzle-drop-zone span {
  color: #999;
  font-size: 11px;
  text-align: center;
  pointer-events: none;
}

.puzzle-drop-zone.drag-over {
  background: #ffe0ed;
  box-shadow: 0 0 10px rgba(76, 175, 80, 0.3);
}

/* Draggable piece styling */
.puzzle-piece-draggable {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  cursor: grab;
  border-radius: 2px;
  transition: all 0.2s ease;
}

.puzzle-piece-draggable:hover {
  filter: brightness(1.3);
}

.puzzle-piece-draggable.dragging {
  opacity: 0.7;
  cursor: grabbing;
}

/* Info Section */
.puzzle-info {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  padding: 10px;
  background: #f9f9f9;
  border: 1px solid #ddd;
  border-radius: 4px;
  flex-shrink: 0;
  /* Ширината ще се определя от .puzzle-container-new чрез JavaScript */
}

#puzzle-status {
  margin: 0 0 8px 0;
  color: #333;
  font-weight: bold;
  text-align: center;
  font-size: 12px;
  word-wrap: break-word;
  white-space: normal;
  line-height: 1.4;
}

/* Controls */
.puzzle-controls {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.puzzle-btn {
  padding: 6px 10px;
  border: none;
  border-radius: 4px;
  background: #2196F3;
  color: white;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: bold;
  white-space: nowrap;
}

.puzzle-btn:hover:not(:disabled) {
  background: #0b7dda;
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
}

.puzzle-btn:disabled {
  background: #ccc;
  cursor: not-allowed;
  opacity: 0.6;
}

.puzzle-btn:active:not(:disabled) {
  transform: translateY(0);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Hidden puzzle pieces section - kept for backward compatibility but hidden */
.puzzle-pieces-section {
  display: none;
}

.puzzle-piece-draggable:hover {
  /* transform: translateY(-1px); */
}

.puzzle-piece-draggable.dragging {
  opacity: 0.5;
  cursor: grabbing;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.3);
}

/* Touch drag clone for mobile */
.puzzle-drag-clone {
  border-radius: 4px;
  background: white;
}

/* Touch action to prevent page scrolling on mobile during drag */
.puzzle-drop-zone,
.puzzle-piece-draggable {
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

.puzzle-piece-draggable img {
  display: block;
  max-width: 100%;
  height: auto;
}

/* Error message */
.puzzle-error {
  padding: 12px 15px;
  background: #ffebee;
  color: #c62828;
  border: 1px solid #ef5350;
  border-radius: 4px;
  margin-bottom: 15px;
  font-size: 14px;
  animation: slideIn 0.3s ease;
}

/* Success message */
.puzzle-success {
  padding: 12px 15px;
  background: #e8f5e9;
  color: #2e7d32;
  border: 1px solid #66bb6a;
  border-radius: 4px;
  margin-bottom: 15px;
  font-size: 14px;
  animation: slideIn 0.3s ease;
  font-weight: bold;
}

/* Clickable phone number link in success message */
.puzzle-success .phone-callable {
  color: #1b5e20;
  background: #c8e6c9;
  padding: 4px 10px;
  border-radius: 4px;
  display: inline-block;
  text-decoration: none;
  transition: all 0.2s ease;
  font-size: 16px;
  letter-spacing: 0.5px;
}

.puzzle-success .phone-callable:hover {
  background: #a5d6a7;
  text-decoration: none;
  transform: scale(1.02);
}

.puzzle-success .phone-callable:active {
  transform: scale(0.98);
}

/* Animations */
@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.7;
  }
}

/* Loading state */
.puzzle-captcha.loading {
  opacity: 0.6;
  pointer-events: none;
}

/* Mobile responsive */
@media (max-width: 768px) {
  .puzzle-modal {
    max-width: 98vw;
    max-height: 98vh;
    margin: 5px;
    border-radius: 8px;
  }
  
  .puzzle-modal-close {
    top: 5px;
    right: 5px;
    width: 28px;
    height: 28px;
    font-size: 18px;
  }

  .puzzle-captcha {
     margin: 0;
  }

  .puzzle-header h3 {
    font-size: 16px;
  }

  .puzzle-header p {
    font-size: 12px;
  }

  .puzzle-drop-zone {
    min-height: 70px;
  }

  .puzzle-pieces-container {
    gap: 10px;
    padding: 10px;
  }

  .puzzle-piece-draggable img {
    max-width: 80px;
  }

  .puzzle-btn {
    padding: 7px 10px;
  }
}

@media (max-width: 480px) {
  .puzzle-modal {
    max-width: 100vw;
    max-height: 100vh;
    margin: 0;
    border-radius: 0;
  }

  .puzzle-captcha {
    margin: 0;
  }

  .puzzle-header h3 {
    font-size: 14px;
  }

  .puzzle-drop-zone {
    min-height: 60px;
    font-size: 10px;
  }

  .puzzle-piece-draggable img {
    max-width: 60px;
  }

  .puzzle-info {
    padding: 10px;
  }

  .puzzle-controls {
    gap: 6px;
  }

  #puzzle-status {
    font-size: 12px;
    margin-bottom: 8px;
  }
}

/* Accessibility */
.puzzle-piece-draggable:focus-visible,
.puzzle-drop-zone:focus-visible,
.puzzle-btn:focus-visible {
}

/* Print styles */
@media print {
  .puzzle-captcha {
    border: none;
    box-shadow: none;
  }

  .puzzle-btn {
    display: none;
  }
}

/* Loading state - hide elements until puzzle images are loaded */
.puzzle-loading .puzzle-header h3,
.puzzle-loading .puzzle-container-new,
.puzzle-loading .puzzle-controls,
.puzzle-loading .puzzle-refresh-btn {
  display: none !important;
}

.puzzle-loading .puzzle-info {
  text-align: center;
  padding: 40px 20px;
}

.puzzle-loading #puzzle-status {
  font-size: 16px;
  color: #666;
}
