/**
 * ONE RESIZER — Tool 02: Signature Resizer Stylesheet (Image-Resizer Architecture)
 * Unified Universal Layout: 4-Unit Grid (PX, IN, CM, MM), Single Target Size (KB, MB, BYTES),
 * 4-Format Selector (JPEG, JPG, PNG, WEBP), Optional Crop Stage, and Honest Result Card.
 */

/* ========================================================
   CONTAINER & WORKSPACE VIEWS
   ======================================================== */
.sig-container {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
}

.sig-view {
  display: block;
  width: 100%;
  box-sizing: border-box;
}
.sig-view.hidden {
  display: none !important;
}

/* ========================================================
   INITIAL UPLOAD SCREEN
   ======================================================== */
.upload-hero-card {
  background: var(--bg-card);
  border: 2px dashed var(--primary-cyan);
  border-radius: var(--radius-xl);
  padding: 48px 20px;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
  box-sizing: border-box;
}
.upload-hero-card:hover, .upload-hero-card.dragover {
  background: rgba(22, 135, 245, 0.08);
  border-color: var(--primary-blue);
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.upload-icon-wrapper {
  width: 68px;
  height: 68px;
  margin: 0 auto 14px;
  border-radius: 18px;
  background: rgba(22, 135, 245, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--primary-cyan);
}
.upload-icon-wrapper svg {
  width: 36px;
  height: 36px;
  stroke: currentColor;
  fill: none;
}

.upload-heading {
  font-size: 20px;
  font-weight: 850;
  color: var(--text-heading);
  margin-bottom: 6px;
}
.upload-subheading {
  font-size: 13.5px;
  color: var(--text-muted);
  margin-bottom: 16px;
}
.upload-btn-fake {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-cyan);
  color: #fff;
  font-weight: 800;
  font-size: 13.5px;
  padding: 9px 22px;
  border-radius: var(--radius-full);
  box-shadow: 0 4px 14px var(--primary-glow);
  margin-bottom: 14px;
}
.upload-formats-badge {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  padding: 6px 12px;
  border-radius: var(--radius-full);
  max-width: 100%;
}

/* ========================================================
   TWO-COLUMN STUDIO EDITOR
   ======================================================== */
.editor-layout {
  display: grid;
  grid-template-columns: 1fr 440px;
  gap: 24px;
  align-items: start;
  width: 100%;
  box-sizing: border-box;
}

/* LEFT COLUMN: PREVIEW PANEL & OPTIONAL CROPPER */
.preview-panel {
  background: var(--bg-card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 20px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  width: 100%;
  overflow: hidden;
}

.preview-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
  gap: 8px;
  flex-wrap: wrap;
}
.file-info-badge {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1 1 auto;
}
.file-info-badge .file-name {
  font-size: 13.5px;
  font-weight: 800;
  color: var(--text-heading);
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-info-badge .file-size-orig {
  font-size: 11.5px;
  font-weight: 750;
  color: var(--text-muted);
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  padding: 2px 7px;
  border-radius: var(--radius-sm);
  white-space: nowrap;
  flex-shrink: 0;
}

.top-bar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

/* VIEWPORT STAGE */
.stage-viewport {
  position: relative;
  width: 100%;
  min-height: 320px;
  max-height: 480px;
  background-color: var(--bg-subtle);
  background-image: 
    linear-gradient(45deg, rgba(0,0,0,0.06) 25%, transparent 25%), 
    linear-gradient(-45deg, rgba(0,0,0,0.06) 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, rgba(0,0,0,0.06) 75%), 
    linear-gradient(-45deg, transparent 75%, rgba(0,0,0,0.06) 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 12px;
  box-sizing: border-box;
  user-select: none;
}
html[data-theme="dark"] .stage-viewport {
  background-image: 
    linear-gradient(45deg, rgba(255,255,255,0.04) 25%, transparent 25%), 
    linear-gradient(-45deg, rgba(255,255,255,0.04) 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, rgba(255,255,255,0.04) 75%), 
    linear-gradient(-45deg, transparent 75%, rgba(255,255,255,0.04) 75%);
}

#cropperContainer {
  position: relative;
  display: inline-block;
  max-width: 100%;
  max-height: 440px;
}
#cropperImg {
  display: block;
  max-width: 100%;
  max-height: 440px;
  object-fit: contain;
  pointer-events: none;
}

/* OPTIONAL CROP BOX OVERLAY */
.crop-box {
  position: absolute;
  border: 2px solid var(--primary-cyan);
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.5);
  cursor: move;
  box-sizing: border-box;
}
.crop-handle {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--primary-cyan);
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 2px 6px rgba(0,0,0,0.4);
}
.crop-handle.tl { top: -6px; left: -6px; cursor: nwse-resize; }
.crop-handle.tr { top: -6px; right: -6px; cursor: nesw-resize; }
.crop-handle.bl { bottom: -6px; left: -6px; cursor: nesw-resize; }
.crop-handle.br { bottom: -6px; right: -6px; cursor: nwse-resize; }

.crop-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

/* PREVIEW STATS */
.preview-meta-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-top: 14px;
  width: 100%;
  box-sizing: border-box;
}
.meta-stat-box {
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 8px 6px;
  text-align: center;
  min-width: 0;
  overflow: hidden;
}
.meta-stat-box span {
  display: block;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 2px;
  white-space: nowrap;
}
.meta-stat-box strong {
  display: block;
  font-size: 12.5px;
  font-weight: 850;
  color: var(--text-heading);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* RIGHT COLUMN: CONTROLS PANEL */
.controls-panel {
  background: var(--bg-card);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 20px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-sizing: border-box;
  width: 100%;
}

.control-section-header {
  font-size: 13px;
  font-weight: 850;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-heading);
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  flex-wrap: wrap;
  gap: 6px;
}

/* 4-UNIT TABS (PX, IN, CM, MM) */
.unit-toggle-group {
  display: flex;
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-full);
  padding: 2px;
  gap: 2px;
}
.unit-tab {
  background: transparent;
  border: 0;
  padding: 5px 9px;
  font-size: 11.5px;
  font-weight: 800;
  color: var(--text-muted);
  border-radius: var(--radius-full);
  cursor: pointer;
  transition: var(--transition);
  text-align: center;
}
.unit-tab.active {
  background: var(--primary-cyan);
  color: #ffffff;
  box-shadow: 0 2px 6px var(--primary-glow);
}

/* DIMENSION INPUTS GRID */
.dims-grid {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
}
.dim-input-wrapper {
  position: relative;
  min-width: 0;
}
.dim-input-wrapper label {
  display: block;
  font-size: 11px;
  font-weight: 750;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.dim-input-wrapper input {
  width: 100%;
  height: 40px;
  background: var(--bg-input);
  border: 1.5px solid var(--input-border);
  border-radius: var(--radius-md);
  padding: 0 10px;
  font-size: 13.5px;
  font-weight: 800;
  color: var(--text);
  outline: none;
  transition: var(--transition);
  box-sizing: border-box;
}
.dim-input-wrapper input:focus {
  border-color: var(--primary-cyan);
  box-shadow: 0 0 0 3px var(--primary-glow);
}

.aspect-lock-btn {
  margin-top: 16px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 1.5px solid var(--line);
  background: var(--bg-subtle);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
}
.aspect-lock-btn.locked {
  background: rgba(22, 135, 245, 0.12);
  border-color: var(--primary-cyan);
  color: var(--primary-cyan);
}

/* TARGET FILE SIZE (ONE TARGET SIZE: KB / MB / BYTES) */
.target-size-box-always {
  background: var(--bg-subtle);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  box-sizing: border-box;
  width: 100%;
}
.target-size-inputs-grid {
  display: grid;
  grid-template-columns: 1fr 90px;
  gap: 8px;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
}
.target-input-col {
  min-width: 0;
}
.target-input-col input {
  width: 100%;
  height: 40px;
  background: var(--bg-input);
  border: 1.5px solid var(--input-border);
  border-radius: var(--radius-md);
  padding: 0 10px;
  font-size: 13.5px;
  font-weight: 800;
  color: var(--text);
  outline: none;
  transition: var(--transition);
  box-sizing: border-box;
}
.target-input-col input:focus {
  border-color: var(--primary-cyan);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.target-unit-col select {
  width: 100%;
  height: 40px;
  background: var(--bg-input);
  border: 1.5px solid var(--input-border);
  border-radius: var(--radius-md);
  padding: 0 8px;
  font-size: 13px;
  font-weight: 800;
  color: var(--text);
  outline: none;
  cursor: pointer;
  box-sizing: border-box;
}

/* 4-FORMAT GRID (JPEG, JPG, PNG, WEBP) */
.format-grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  width: 100%;
  box-sizing: border-box;
}
.format-btn {
  background: var(--bg-subtle);
  border: 1.5px solid var(--line);
  border-radius: var(--radius-md);
  padding: 9px 2px;
  font-size: 12px;
  font-weight: 800;
  color: var(--text);
  cursor: pointer;
  text-align: center;
  transition: var(--transition);
}
.format-btn:hover {
  border-color: var(--primary-cyan);
}
.format-btn.active {
  background: var(--primary-cyan);
  border-color: var(--primary-cyan);
  color: #fff;
  box-shadow: 0 3px 10px var(--primary-glow);
}

.quality-slider-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
  box-sizing: border-box;
}
.quality-header {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 750;
  color: var(--text-muted);
}
.quality-slider {
  width: 100%;
  accent-color: var(--primary-cyan);
  cursor: pointer;
}

/* ACTION BUTTONS */
.action-buttons-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 4px;
  width: 100%;
}
.btn-resize-execute {
  width: 100%;
  height: 46px;
  background: var(--primary-cyan);
  border: 0;
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 14.5px;
  font-weight: 850;
  cursor: pointer;
  box-shadow: 0 4px 16px var(--primary-glow);
  transition: var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn-resize-execute:hover:not(:disabled) {
  background: var(--primary-blue);
  transform: translateY(-1px);
}
.btn-resize-execute:disabled {
  opacity: 0.7;
  cursor: wait;
}

.btn-secondary-action {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 750;
  cursor: pointer;
  padding: 5px 10px;
  transition: var(--transition);
  white-space: nowrap;
}
.btn-secondary-action:hover {
  background: var(--bg-subtle);
  color: var(--text-heading);
  border-color: var(--line-light);
}

/* ========================================================
   RESULT & DOWNLOAD CARD (HONEST 4-BOX STATS)
   ======================================================== */
.result-card {
  background: var(--bg-card);
  border: 2px solid rgba(16, 168, 88, 0.4);
  border-radius: var(--radius-xl);
  padding: 28px 20px;
  text-align: center;
  box-shadow: var(--shadow-lg);
  max-width: 640px;
  margin: 0 auto;
  box-sizing: border-box;
  width: 100%;
}
.result-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(16, 168, 88, 0.12);
  color: #10a858;
  border: 1px solid rgba(16, 168, 88, 0.3);
  padding: 5px 14px;
  border-radius: var(--radius-full);
  font-size: 12.5px;
  font-weight: 800;
  margin-bottom: 14px;
}
.result-heading {
  font-size: 22px;
  font-weight: 900;
  color: var(--text-heading);
  margin-bottom: 4px;
}
.result-subheading {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.result-preview-box {
  width: 100%;
  max-height: 200px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px;
  margin-bottom: 18px;
  overflow: hidden;
  box-sizing: border-box;
}
.result-preview-box img {
  max-width: 100%;
  max-height: 180px;
  object-fit: contain;
  border-radius: var(--radius-xs);
}

.result-stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 20px;
  width: 100%;
  box-sizing: border-box;
}
.result-stat-item {
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 8px 4px;
  text-align: center;
  min-width: 0;
  overflow: hidden;
}
.result-stat-item span {
  display: block;
  font-size: 10.5px;
  color: var(--text-muted);
  font-weight: 700;
  margin-bottom: 2px;
  white-space: nowrap;
}
.result-stat-item strong {
  display: block;
  font-size: 13px;
  font-weight: 850;
  color: var(--text-heading);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-download-final {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 48px;
  background: #10a858;
  border: 0;
  border-radius: var(--radius-md);
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(16, 168, 88, 0.35);
  transition: var(--transition);
  margin-bottom: 10px;
}
.btn-download-final:hover {
  background: #0d8a47;
  transform: translateY(-1px);
}

/* ========================================================
   RESPONSIVE MEDIA QUERIES
   ======================================================== */
@media (max-width: 992px) {
  .editor-layout {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}
@media (max-width: 768px) {
  .preview-panel, .controls-panel, .result-card {
    padding: 16px 14px;
  }
  .stage-viewport {
    min-height: 240px;
    max-height: 360px;
  }
  .result-stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
@media (max-width: 480px) {
  .format-grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}
