/* Crop Tool Styles */

.editor-section {
  background: #fff;
  border-radius: var(--border-radius);
  padding: 24px;
  margin-top: 20px;
  box-shadow: var(--shadow);
}

.editor-layout {
  display: flex;
  gap: 24px;
}

.crop-container {
  flex: 1;
  min-width: 0;
}

.crop-wrapper {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  background: var(--gray-100);
  border-radius: 8px;
  padding: 20px;
  min-height: 300px;
  overflow: auto;
}

.crop-area {
  position: relative;
  display: inline-block;
  cursor: crosshair;
  user-select: none;
  line-height: 0;
}

.crop-area canvas {
  display: block;
  max-width: 100%;
  height: auto;
  background-image:
    linear-gradient(45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(-45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e5e7eb 75%),
    linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

.crop-selection {
  position: absolute;
  border: 2px solid var(--primary);
  background: rgba(79, 70, 229, 0.1);
  cursor: move;
  display: none;
}

.crop-selection::before {
  content: '';
  position: absolute;
  inset: -1px;
  border: 1px dashed rgba(255, 255, 255, 0.7);
}

.crop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--primary);
  border: 2px solid #fff;
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.crop-handle-nw {
  top: -6px;
  left: -6px;
  cursor: nw-resize;
}

.crop-handle-ne {
  top: -6px;
  right: -6px;
  cursor: ne-resize;
}

.crop-handle-sw {
  bottom: -6px;
  left: -6px;
  cursor: sw-resize;
}

.crop-handle-se {
  bottom: -6px;
  right: -6px;
  cursor: se-resize;
}

.crop-handle-n {
  top: -6px;
  left: 50%;
  transform: translateX(-50%);
  cursor: n-resize;
}

.crop-handle-s {
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  cursor: s-resize;
}

.crop-handle-e {
  top: 50%;
  right: -6px;
  transform: translateY(-50%);
  cursor: e-resize;
}

.crop-handle-w {
  top: 50%;
  left: -6px;
  transform: translateY(-50%);
  cursor: w-resize;
}

.crop-grid {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.crop-grid-line {
  position: absolute;
  background: rgba(255, 255, 255, 0.4);
}

.crop-grid-h1 {
  top: 33.33%;
  left: 0;
  right: 0;
  height: 1px;
}

.crop-grid-h2 {
  top: 66.66%;
  left: 0;
  right: 0;
  height: 1px;
}

.crop-grid-v1 {
  left: 33.33%;
  top: 0;
  bottom: 0;
  width: 1px;
}

.crop-grid-v2 {
  left: 66.66%;
  top: 0;
  bottom: 0;
  width: 1px;
}

.crop-info {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
  font-size: 0.9rem;
  color: var(--gray-500);
}

.crop-actions {
  display: flex;
  gap: 8px;
}

/* Controls Container */
.controls-container {
  width: 320px;
  max-width: 100%;
  flex-shrink: 0;
}

.control-section {
  background: var(--gray-50);
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  padding: 16px;
  margin-bottom: 16px;
}

.control-section h3 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--gray-700);
  margin-bottom: 12px;
}

.control-group {
  margin-bottom: 12px;
}

.control-group:last-child {
  margin-bottom: 0;
}

.control-label {
  display: block;
  font-size: 0.85rem;
  color: var(--gray-600);
  margin-bottom: 6px;
}

/* Crop Mode Tabs */
.crop-mode-tabs {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.crop-mode-tab {
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  background: #fff;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}

.crop-mode-tab:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.crop-mode-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* Ratio Options */
.ratio-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.ratio-option {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.ratio-option:hover {
  border-color: var(--primary);
  background: #eef2ff;
}

.ratio-option input {
  display: none;
}

.ratio-option input:checked + span {
  color: var(--primary);
  font-weight: 600;
}

.ratio-option span {
  font-size: 0.9rem;
}

.custom-ratio-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
}

.ratio-input {
  width: 0;
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.9rem;
  text-align: center;
}

.ratio-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.ratio-separator {
  font-size: 1.2rem;
  color: var(--gray-500);
}

/* Custom Size Inputs */
.custom-size-inputs {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.size-input {
  width: 0;
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 0.9rem;
}

.size-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

.size-separator {
  color: var(--gray-400);
}

.size-unit {
  color: var(--gray-500);
  font-size: 0.85rem;
}

.lock-ratio {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.85rem;
  color: var(--gray-600);
}

.lock-ratio input {
  accent-color: var(--primary);
}

/* Preset Tabs */
.preset-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 12px;
  background: var(--gray-100);
  border-radius: 6px;
  padding: 4px;
}

.preset-tab {
  flex: 1;
  padding: 6px 8px;
  border: none;
  border-radius: 4px;
  background: transparent;
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--gray-600);
}

.preset-tab:hover {
  background: rgba(255, 255, 255, 0.5);
}

.preset-tab.active {
  background: #fff;
  color: var(--primary);
  font-weight: 500;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}

/* Preset Grid */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 6px;
}

.preset-btn {
  padding: 8px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  background: #fff;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s;
  color: var(--gray-600);
}

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

/* Format Options */
.format-options {
  display: flex;
  gap: 8px;
}

.format-option {
  flex: 1;
}

.format-option input {
  display: none;
}

.format-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border: 1px solid var(--gray-200);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
}

.format-option input:checked + .format-btn {
  border-color: var(--primary);
  background: #eef2ff;
}

.format-icon {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--gray-600);
}

.format-option input:checked + .format-btn .format-icon {
  color: var(--primary);
}

/* Range Slider */
.range-slider {
  width: 100%;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--gray-200);
  border-radius: 3px;
  outline: none;
}

.range-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--primary);
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.quality-hint {
  display: flex;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--gray-400);
  margin-top: 4px;
}

/* Download Section */
.download-section {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.download-section .btn {
  flex: 1;
  min-width: 120px;
}

/* Preview Modal */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-content {
  background: #fff;
  border-radius: var(--border-radius);
  max-width: 800px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--gray-200);
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--gray-400);
  padding: 4px;
}

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

.modal-body {
  padding: 20px;
}

.preview-modal-compare {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

.preview-modal-box {
  text-align: center;
}

.preview-modal-label {
  display: block;
  font-size: 0.85rem;
  color: var(--gray-500);
  margin-bottom: 8px;
}

.preview-modal-box img {
  max-width: 100%;
  max-height: 400px;
  border: 1px solid var(--gray-200);
  border-radius: 8px;
  background-image:
    linear-gradient(45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(-45deg, #e5e7eb 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #e5e7eb 75%),
    linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
}

.preview-modal-info {
  text-align: center;
  margin-top: 16px;
  font-size: 0.9rem;
  color: var(--gray-500);
}

/* Responsive */
@media (max-width: 768px) {
  .editor-layout {
    flex-direction: column;
  }

  .controls-container {
    width: 100%;
  }

  .crop-mode-tabs {
    grid-template-columns: repeat(4, 1fr);
  }

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

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

  .preview-modal-compare {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .editor-section {
    padding: 16px;
  }

  .control-section {
    padding: 12px;
  }

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

  .download-section {
    flex-direction: column;
  }

  .download-section .btn {
    width: 100%;
  }

  .custom-size-inputs {
    flex-wrap: wrap;
  }

  .size-input {
    width: 0;
    flex: 1 1 40%;
    min-width: 60px;
  }

  .size-separator,
  .size-unit {
    text-align: center;
    flex-shrink: 0;
  }
}
