/* ================= COMPONENT RESETS & BASE ================= */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  user-select: none;
}

section {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
}

/* ================= LEFT SIDEBAR PANEL (DESKTOP) ================= */
.left {
  width: 25%;
  min-width: 300px;
  max-width: 360px;
  background: var(--bg-secondary);
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border-right: 1px solid rgba(255, 30, 30, 0.2);
  box-shadow: 4px 0 25px rgba(0, 0, 0, 0.8);
  z-index: 10;
  overflow-y: auto;
}

.filters-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-md);
}

.left h2 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--text-primary);
  border-left: 3px solid var(--accent);
  padding-left: 10px;
  font-family: 'Orbitron', sans-serif;
  text-transform: uppercase;
}

.reset-link {
  background: transparent;
  border: none;
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
  transition: var(--transition);
}
.reset-link:hover {
  text-decoration: underline;
  color: var(--accent-hover);
}

/* FILTERS LIST */
#filters {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-grow: 1;
  overflow-y: auto;
  padding-right: 4px;
}

#filters::-webkit-scrollbar {
  width: 4px;
}
#filters::-webkit-scrollbar-track {
  background: transparent;
}
#filters::-webkit-scrollbar-thumb {
  background: rgba(255, 30, 30, 0.4);
  border-radius: 2px;
}

.filter {
  background: var(--bg-card);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  display: flex;
  flex-direction: column;
  gap: 5px;
  border: 1px solid rgba(255, 255, 255, 0.04);
  transition: var(--transition);
}

.filter:hover {
  border-color: rgba(255, 30, 30, 0.35);
  background: var(--bg-card-hover);
}

.filter-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  font-weight: 600;
  text-transform: capitalize;
  color: var(--text-secondary);
}

.filter-value {
  color: var(--accent);
  font-family: monospace;
  font-size: 11px;
  font-weight: bold;
  background: rgba(255, 30, 30, 0.1);
  padding: 1px 5px;
  border-radius: 3px;
}

.filter input[type="range"] {
  width: 100%;
  height: 6px;
  accent-color: var(--accent);
  cursor: pointer;
  background: #222634;
  border-radius: 3px;
  outline: none;
}

/* PRESETS PANEL */
.presets-panel {
  margin-top: var(--space-sm);
  padding-top: var(--space-sm);
  border-top: 1px solid rgba(255, 30, 30, 0.2);
}

.presets-panel h3 {
  font-size: 12px;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: var(--space-sm);
  font-family: 'Orbitron', sans-serif;
  letter-spacing: 0.8px;
}

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

.preset-btn {
  padding: 7px 4px;
  font-size: 11px;
  font-weight: 600;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text-primary);
  cursor: pointer;
  transition: var(--transition);
}
.preset-btn:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  box-shadow: 0 0 10px var(--accent-glow);
}
.preset-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}

/* SIGNATURE BRANDING */
.signature {
  margin-top: var(--space-sm);
  padding-top: var(--space-xs);
  border-top: 1px solid rgba(255, 30, 30, 0.15);
  text-align: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 1.5px;
  font-family: 'Orbitron', sans-serif;
  text-transform: uppercase;
  text-shadow: 0 0 10px rgba(255, 30, 30, 0.5);
}

/* ================= RIGHT WORKSPACE INTERFACE ================= */
.right {
  width: 75%;
  flex-grow: 1;
  padding: var(--space-lg);
  display: flex;
  flex-direction: column;
  gap: var(--space-md);
  background: var(--bg-primary);
  overflow: hidden;
}

.top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  background: var(--bg-secondary);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255, 30, 30, 0.2);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.5);
}

.btn {
  padding: 8px 12px;
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  transition: var(--transition);
  font-family: inherit;
  outline: none;
  white-space: nowrap;
}

.btn:hover {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 4px 14px var(--accent-glow);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

label.btn {
  background: rgba(255, 30, 30, 0.15);
  color: #ffffff;
  border-color: rgba(255, 30, 30, 0.4);
}
label.btn:hover {
  background: var(--accent);
  border-color: var(--accent);
}

.pdf-btn {
  background: linear-gradient(135deg, rgba(255, 42, 85, 0.25) 0%, rgba(255, 120, 0, 0.25) 100%);
  border-color: rgba(255, 42, 85, 0.4);
  color: #fff;
}
.pdf-btn:hover {
  background: linear-gradient(135deg, #ff2a55 0%, #ff6b00 100%);
  border-color: #ff2a55;
  box-shadow: 0 0 14px rgba(255, 42, 85, 0.6);
}

.download-btn {
  background: var(--accent);
  color: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 2px 10px var(--accent-glow);
}
.download-btn:hover {
  background: var(--accent-hover);
  box-shadow: 0 4px 18px var(--accent-glow);
}

#reset-image-btn:hover {
  background: var(--danger);
  border-color: var(--danger);
}

/* WATERMARK GROUP */
.watermark-group {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  background: var(--bg-card);
  padding: 4px 8px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 30, 30, 0.25);
}

.watermark-group input[type="text"] {
  background: transparent;
  border: none;
  color: #fff;
  outline: none;
  font-size: 12px;
  width: 95px;
  font-family: inherit;
}

.watermark-group input[type="color"] {
  border: none;
  background: transparent;
  cursor: pointer;
  width: 22px;
  height: 22px;
  border-radius: 4px;
}

.watermark-group button {
  padding: 4px 8px;
  font-size: 11px;
}

/* ================= CENTRAL STUDIO CANVAS ================= */
.bottom {
  flex: 1;
  background: var(--bg-secondary);
  border: 2px dashed rgba(255, 30, 30, 0.25);
  border-radius: var(--radius-md);
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
  background-color: #0c0d12;
  min-height: 200px;
}

.canvas-container {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  max-width: 92%;
  max-height: 88%;
}

#image {
  display: none;
  max-width: 100%;
  max-height: 72vh;
  object-fit: contain;
  border-radius: var(--radius-sm);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.9);
  image-rendering: -webkit-optimize-contrast;
  image-rendering: crisp-edges;
  transition: filter 0.05s linear;
}

/* WORKSPACE STATE MODES */
.picker-active #image {
  cursor: crosshair !important;
}

.watermark-placement-active #image {
  cursor: cell !important;
}

.empty-icon {
  font-size: 56px;
  color: rgba(255, 30, 30, 0.3);
  position: absolute;
  top: 45%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.p {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-secondary);
  position: absolute;
  top: 57%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-family: 'Orbitron', sans-serif;
  letter-spacing: 0.5px;
}

/* ================= HIGH-PRECISION CROP OVERLAY ================= */
#crop-box {
  position: absolute;
  border: 2px dashed var(--accent);
  display: none;
  cursor: move;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.75);
  z-index: 20;
  touch-action: none;
}

.resize {
  width: 12px;
  height: 12px;
  background: #ffffff;
  border: 2px solid var(--accent);
  position: absolute;
  border-radius: 50%;
  box-shadow: 0 0 4px rgba(0, 0, 0, 0.8);
}

/* Larger invisible touch area for mobile fingers */
.resize::before {
  content: '';
  position: absolute;
  top: -10px;
  left: -10px;
  right: -10px;
  bottom: -10px;
}

.handle-tl { top: -6px; left: -6px; cursor: nwse-resize; }
.handle-tr { top: -6px; right: -6px; cursor: nesw-resize; }
.handle-bl { bottom: -6px; left: -6px; cursor: nesw-resize; }
.handle-br { bottom: -6px; right: -6px; cursor: nwse-resize; }

input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 1px solid rgba(255,255,255,0.25); border-radius: 3px; }

/* ================= MODALS & POPUPS ================= */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(0, 0, 0, 0.85);
  backdrop-filter: blur(8px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal-overlay.open {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  border: 1px solid rgba(255, 30, 30, 0.3);
  border-radius: var(--radius-md);
  width: 100%;
  max-width: 440px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.9);
  overflow: hidden;
  animation: modal-appear 0.2s ease;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

@keyframes modal-appear {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 14px 18px;
  background: var(--bg-card);
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.modal-header h3 {
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}
.modal-close:hover {
  color: #fff;
}

.modal-body {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
}

.form-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.form-row label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-secondary);
}

.modal-input, .modal-select {
  background: var(--bg-card);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: #fff;
  font-size: 12.5px;
  font-family: inherit;
  outline: none;
}
.modal-input:focus, .modal-select:focus {
  border-color: var(--accent);
}

.modal-footer {
  padding: 12px 18px;
  background: var(--bg-card);
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ========================================================================= */
/* ==================== COMPLETE RESPONSIVE MEDIA QUERIES ==================== */
/* ========================================================================= */

/* TABLETS & MEDIUM SCREENS (Under 1024px) */
@media (max-width: 1024px) {
  .left {
    width: 32%;
    min-width: 260px;
    padding: var(--space-md);
  }
  .right {
    width: 68%;
    padding: var(--space-md);
  }
}

/* MOBILE PHONES & SMALL TABLETS (Under 850px) */
@media (max-width: 850px) {
  html, body {
    overflow-y: auto;
    height: auto;
    min-height: 100vh;
  }

  section {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    overflow-y: visible;
  }

  /* Right Canvas & Top Bar on Top */
  .right {
    width: 100%;
    order: 1;
    padding: 10px;
    gap: 10px;
    height: auto;
  }

  /* Top Toolbar: Smooth Horizontal Touch Carousel */
  .top {
    flex-wrap: nowrap;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding: 8px 10px;
    gap: 6px;
    scrollbar-width: none;
  }
  .top::-webkit-scrollbar {
    display: none;
  }

  .top .btn {
    padding: 8px 12px;
    font-size: 11.5px;
    flex-shrink: 0;
  }

  .watermark-group {
    flex-shrink: 0;
  }

  /* Center Canvas Stage */
  .bottom {
    min-height: 300px;
    max-height: 48vh;
    border-radius: var(--radius-sm);
  }

  #image {
    max-height: 44vh;
  }

  /* Left Panel moves below canvas on mobile */
  .left {
    width: 100%;
    max-width: 100%;
    min-width: 100%;
    order: 2;
    padding: 14px 12px;
    border-right: none;
    border-top: 1px solid rgba(255, 30, 30, 0.25);
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.8);
    height: auto;
  }

  .filters-header {
    margin-bottom: 10px;
  }

  #filters {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    max-height: none;
    overflow-y: visible;
  }

  .filter {
    padding: 8px 10px;
  }

  .filter input[type="range"] {
    height: 8px;
  }

  .presets-panel {
    margin-top: 14px;
    padding-top: 10px;
  }

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

  .preset-btn {
    padding: 8px 4px;
    font-size: 11px;
  }

  .signature {
    margin-top: 14px;
    padding-top: 8px;
    font-size: 10.5px;
  }
}

/* SMALL MOBILE PHONES (Under 480px) */
@media (max-width: 480px) {
  #filters {
    grid-template-columns: 1fr;
  }

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

  .bottom {
    min-height: 250px;
    max-height: 42vh;
  }

  #image {
    max-height: 38vh;
  }

  .top .btn {
    padding: 7px 10px;
    font-size: 11px;
  }
}
