/**
 * ONE RESIZER — Tool 01: Image Resizer Stylesheet v3.6 (Mobile Responsive Hardened)
 * Studio Layout, 4-Unit Grid (PX, IN, CM, MM), 4-Format Selector (JPEG, JPG, PNG, WEBP),
 * Target Size Engine & Honest Result Card. 100% Fluid & Mobile-Ready (320px - 768px+).
 */

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

.resizer-view {
  display: block;
  width: 100%;
  box-sizing: border-box;
}
.resizer-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 / SINGLE-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 */
.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;
}

.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;
}
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%);
}

.stage-viewport canvas, .stage-viewport img {
  max-width: 100%;
  max-height: 440px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
  transition: transform 0.2s ease;
}

.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 BOX (ALWAYS ACTIVE) */
.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 84px;
  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;
}

/* PRESET BUTTONS */
.presets-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  width: 100%;
  box-sizing: border-box;
}
.preset-chip {
  background: var(--bg-subtle);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 2px;
  font-size: 11px;
  font-weight: 750;
  color: var(--text-muted);
  cursor: pointer;
  text-align: center;
  transition: var(--transition);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.preset-chip:hover, .preset-chip.active {
  background: var(--primary-cyan);
  border-color: var(--primary-cyan);
  color: #fff;
}

/* WARNING ALERT */
.enlarge-warning {
  display: none;
  background: rgba(255, 153, 0, 0.12);
  border: 1px solid rgba(255, 153, 0, 0.4);
  color: #b36200;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  font-size: 11.5px;
  font-weight: 700;
  align-items: center;
  gap: 6px;
  box-sizing: border-box;
}
html[data-theme="dark"] .enlarge-warning {
  color: #ffb84d;
}
.enlarge-warning.visible {
  display: flex;
}

/* 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: 280px;
  background: var(--bg-subtle);
  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: 250px;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
}

.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 (320px - 992px)
   ======================================================== */

/* TABLETS & SMALL DESKTOPS (< 992px) */
@media (max-width: 992px) {
  .editor-layout {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}

/* MOBILE DEVICES (< 768px) */
@media (max-width: 768px) {
  .preview-panel, .controls-panel {
    padding: 16px 14px;
    border-radius: var(--radius-lg);
  }

  .stage-viewport {
    min-height: 240px;
    max-height: 360px;
    padding: 8px;
  }

  .file-info-badge .file-name {
    max-width: 140px;
  }

  .result-card {
    padding: 20px 14px;
    border-radius: var(--radius-lg);
  }

  .result-heading {
    font-size: 20px;
  }

  .result-stats-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
  }
}

/* COMPACT MOBILE (< 480px) */
@media (max-width: 480px) {
  .upload-hero-card {
    padding: 32px 14px;
  }
  
  .upload-heading {
    font-size: 18px;
  }

  .file-info-badge .file-name {
    max-width: 110px;
  }

  .unit-toggle-group {
    width: 100%;
    justify-content: space-between;
  }
  .unit-tab {
    flex: 1;
    padding: 5px 4px;
    font-size: 11px;
  }

  .format-grid-4 {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .presets-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }

  .preview-meta-stats {
    grid-template-columns: repeat(3, 1fr);
    gap: 4px;
  }
  .meta-stat-box {
    padding: 6px 2px;
  }
  .meta-stat-box span {
    font-size: 9.5px;
  }
  .meta-stat-box strong {
    font-size: 11.5px;
  }

  .result-preview-box {
    max-height: 220px;
  }
}

/* ULTRA NARROW MOBILE (< 360px) */
@media (max-width: 360px) {
  .preview-panel, .controls-panel, .result-card {
    padding: 12px 10px;
  }

  .file-info-badge .file-name {
    max-width: 90px;
    font-size: 12px;
  }

  .dims-grid {
    grid-template-columns: 1fr 28px 1fr;
    gap: 4px;
  }
  .aspect-lock-btn {
    width: 28px;
    height: 28px;
    margin-top: 14px;
  }

  .target-size-inputs-grid {
    grid-template-columns: 1fr 70px;
    gap: 6px;
  }

  .btn-resize-execute {
    height: 42px;
    font-size: 13.5px;
  }

  .btn-download-final {
    height: 44px;
    font-size: 14px;
  }
}
