/* ==========================================================================
   DESIGN SYSTEM & VARIABLES
   ========================================================================== */
:root {
  /* HSL Colors - Futuristic Dark/Cyber Theme */
  --bg-base: #08080c;
  --bg-card: rgba(18, 18, 28, 0.75);
  --bg-sidebar: rgba(13, 13, 21, 0.85);
  --border-color: rgba(255, 255, 255, 0.07);
  --border-focus: rgba(99, 102, 241, 0.5);
  
  --primary: #6366f1; /* Indigo Neon */
  --primary-glow: rgba(99, 102, 241, 0.35);
  --accent: #00f5ff; /* Cyber Cyan */
  --accent-glow: rgba(0, 245, 255, 0.2);
  --danger: #ff2a5f; /* Neon Pink/Red */
  --success: #00ff88; /* Neon Green */
  
  --text-main: #f3f4f6;
  --text-muted: #8e95a5;
  --text-inverse: #050508;
  
  /* Fonts */
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'Space Mono', monospace;
  
  /* Layout */
  --header-height: 70px;
  --sidebar-width: 380px;
  --glass-blur: 16px;
  
  /* Zoom Factor (controlled via JS) */
  --zoom-factor: 1.0;
}

/* ==========================================================================
   RESET & BASE STYLES
   ========================================================================== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-base);
  color: var(--text-main);
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  background-image: 
    radial-gradient(at 10% 20%, rgba(99, 102, 241, 0.05) 0px, transparent 50%),
    radial-gradient(at 90% 80%, rgba(0, 245, 255, 0.03) 0px, transparent 50%);
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.02);
}
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.1);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--primary);
}

/* ==========================================================================
   LAYOUT STRUCTURE
   ========================================================================== */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  width: 100vw;
}

.main-header {
  height: var(--header-height);
  border-bottom: 1px solid var(--border-color);
  background: rgba(8, 8, 12, 0.8);
  backdrop-filter: blur(var(--glass-blur));
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 24px;
  z-index: 100;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}
.logo svg {
  color: var(--primary);
  filter: drop-shadow(0 0 5px var(--primary-glow));
}
.logo .highlight {
  color: var(--accent);
  text-shadow: 0 0 8px var(--accent-glow);
}

.main-layout {
  display: flex;
  flex: 1;
  height: calc(100vh - var(--header-height));
  overflow: hidden;
}

/* ==========================================================================
   SIDEBAR & TABS PANEL
   ========================================================================== */
.sidebar {
  width: var(--sidebar-width);
  border-right: 1px solid var(--border-color);
  background: var(--bg-sidebar);
  backdrop-filter: blur(var(--glass-blur));
  display: flex;
  flex-direction: row;
  height: 100%;
  z-index: 90;
}

.sidebar-nav {
  width: 76px;
  border-right: 1px solid var(--border-color);
  background: rgba(5, 5, 8, 0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 12px;
}

.nav-tab {
  background: none;
  border: none;
  width: 56px;
  height: 56px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  font-size: 0.65rem;
  font-weight: 500;
}
.nav-tab svg {
  transition: transform 0.2s ease;
}
.nav-tab:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}
.nav-tab:hover svg {
  transform: translateY(-2px);
}
.nav-tab.active {
  color: var(--primary);
  background: rgba(99, 102, 241, 0.12);
  border: 1px solid rgba(99, 102, 241, 0.2);
  box-shadow: 0 0 15px rgba(99, 102, 241, 0.08);
}

.sidebar-panels {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  height: 100%;
}

.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
  animation: fadeIn 0.3s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateX(-5px); }
  to { opacity: 1; transform: translateX(0); }
}

.tab-panel h2 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 20px;
  letter-spacing: -0.3px;
}

/* ==========================================================================
   FORM COMPONENTS
   ========================================================================== */
.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

select, input[type="text"], input[type="number"], textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--text-main);
  font-size: 0.95rem;
  outline: none;
  transition: all 0.2s ease;
}
select option {
  background-color: #0f0f15;
  color: #f3f4f6;
}
select:focus, input:focus, textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 10px var(--primary-glow);
  background: rgba(255, 255, 255, 0.06);
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.form-section-title {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--accent);
  margin: 20px 0 12px 0;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.w-full {
  width: 100%;
}

/* Custom Model Maker Styling */
.custom-model-form {
  margin-top: 15px;
  padding: 15px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px dashed var(--border-color);
}
.custom-model-form h3 {
  font-size: 0.95rem;
  margin-bottom: 12px;
  color: var(--text-main);
}
.hidden {
  display: none !important;
}

/* Info Cards */
.model-info-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px;
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.info-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}
.info-label {
  color: var(--text-muted);
}
.info-value {
  font-family: var(--font-mono);
  font-weight: 600;
}

/* Button Styling */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  border: 1px solid transparent;
}
.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: #5254de;
  transform: translateY(-1px);
}
.btn-glow:hover {
  box-shadow: 0 0 20px var(--primary-glow);
}
.btn-secondary {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border-color);
  color: var(--text-main);
}
.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: var(--text-muted);
}
.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover {
  background: #e01f50;
  box-shadow: 0 0 15px rgba(255, 42, 95, 0.3);
}

/* ==========================================================================
   WORKSPACE BACKGROUND PANEL
   ========================================================================== */
.bg-section {
  margin-bottom: 24px;
}
.bg-section h3 {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.color-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-bottom: 15px;
}
.color-swatch {
  aspect-ratio: 1;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.2s ease, border-color 0.2s ease;
}
.color-swatch:hover {
  transform: scale(1.1);
}
.color-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

.gradient-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.gradient-swatch {
  height: 50px;
  border-radius: 8px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: transform 0.2s ease, border-color 0.2s ease;
}
.gradient-swatch:hover {
  transform: translateY(-2px);
}
.gradient-swatch.active {
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

.custom-color-picker {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(0, 0, 0, 0.15);
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}
.color-picker-wrapper {
  display: flex;
  align-items: center;
  gap: 10px;
}
input[type="color"] {
  -webkit-appearance: none;
  border: none;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  background: none;
}
input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}
input[type="color"]::-webkit-color-swatch {
  border: 2px solid var(--border-color);
  border-radius: 50%;
}
#bg-color-hex {
  font-family: var(--font-mono);
  font-size: 0.85rem;
}

/* ==========================================================================
   IMAGES UPLOAD & HISTORY
   ========================================================================== */
.upload-area {
  border: 2px dashed rgba(99, 102, 241, 0.3);
  background: rgba(99, 102, 241, 0.02);
  border-radius: 12px;
  padding: 30px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.upload-area svg {
  color: var(--primary);
  transition: transform 0.2s ease;
}
.upload-area:hover {
  background: rgba(99, 102, 241, 0.05);
  border-color: var(--primary);
}
.upload-area:hover svg {
  transform: translateY(-3px);
}
.upload-area p {
  font-size: 0.9rem;
  font-weight: 500;
}
.upload-area p span {
  color: var(--accent);
  text-decoration: underline;
}
.upload-tip {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.uploaded-history {
  margin-top: 24px;
}
.uploaded-history h3 {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.uploaded-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.uploaded-item {
  aspect-ratio: 1;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border-color);
  cursor: pointer;
  position: relative;
  background: #111;
}
.uploaded-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.2s ease;
}
.uploaded-item:hover img {
  transform: scale(1.1);
}

/* ==========================================================================
   TEXT LAYERS TAB
   ========================================================================== */
.alignment-buttons {
  display: flex;
  gap: 4px;
  background: rgba(0, 0, 0, 0.2);
  padding: 4px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}
.btn-align {
  flex: 1;
  background: none;
  border: none;
  padding: 6px 0;
  font-weight: 600;
  font-size: 0.8rem;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.15s ease;
}
.btn-align:hover {
  color: var(--text-main);
  background: rgba(255, 255, 255, 0.04);
}
.btn-align.active {
  color: var(--text-inverse);
  background: var(--accent);
}

/* ==========================================================================
   STICKERS TAB
   ========================================================================== */
.sticker-section {
  margin-bottom: 24px;
}
.sticker-section h3 {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}
.shape-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}
.btn-add-shape {
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-main);
  transition: all 0.2s ease;
}
.btn-add-shape:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--accent);
  transform: translateY(-1px);
}

.sticker-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.sticker-thumb {
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  cursor: pointer;
  padding: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.sticker-thumb svg {
  width: 100%;
  height: 100%;
  transition: transform 0.2s ease;
}
.sticker-thumb:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: translateY(-2px);
}
.sticker-thumb:hover svg {
  transform: scale(1.1);
}

/* ==========================================================================
   CENTER WORKSPACE
   ========================================================================== */
.workspace-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: #0c0c14;
  background-image: 
    radial-gradient(rgba(255, 255, 255, 0.02) 1px, transparent 1px),
    radial-gradient(rgba(255, 255, 255, 0.015) 1px, transparent 1px);
  background-size: 20px 20px;
  background-position: 0 0, 10px 10px;
  position: relative;
}

.workspace-controls {
  height: 56px;
  border-bottom: 1px solid var(--border-color);
  background: rgba(13, 13, 21, 0.6);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 10;
}

.zoom-controls {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 2px;
}
.zoom-controls button {
  background: none;
  border: none;
  width: 28px;
  height: 28px;
  cursor: pointer;
  font-weight: 700;
  font-size: 1.1rem;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease;
}
.zoom-controls button:hover {
  background: rgba(255, 255, 255, 0.06);
}
#zoom-value {
  padding: 0 10px;
  font-size: 0.85rem;
  font-family: var(--font-mono);
  min-width: 50px;
  text-align: center;
}

/* Selected Layer Control Bar */
.selection-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  animation: slideDown 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes slideDown {
  from { transform: translateY(-10px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.selection-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.actions-group {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 4px;
  gap: 4px;
}
.actions-group button {
  background: none;
  border: none;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.actions-group button:hover {
  background: rgba(255, 255, 255, 0.06);
  color: var(--accent);
}
.actions-group button.btn-danger:hover {
  background: var(--danger);
  color: white;
}
.divider {
  width: 1px;
  height: 20px;
  background: var(--border-color);
  margin: 0 4px;
}
.prop-control {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 8px;
}
.prop-control label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
}
.prop-control input[type="range"] {
  width: 80px;
  accent-color: var(--primary);
  height: 4px;
  cursor: pointer;
}

.btn-size-step {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-color);
  width: 26px;
  height: 26px;
  border-radius: 4px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
}
.btn-size-step:hover {
  background: rgba(255, 255, 255, 0.12);
  color: var(--accent);
}
.size-inputs {
  display: flex;
  align-items: center;
  gap: 4px;
}
.size-inputs input {
  width: 48px;
  height: 26px;
  padding: 0 4px;
  text-align: center;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  color: var(--text-main);
  outline: none;
}
.size-inputs input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 8px var(--primary-glow);
}
.size-inputs input::-webkit-outer-spin-button,
.size-inputs input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.size-inputs input[type=number] {
  -moz-appearance: textfield;
}
.size-inputs span {
  font-size: 0.8rem;
  color: var(--text-muted);
}
.size-inputs span.unit {
  font-size: 0.7rem;
  margin-left: 2px;
}

/* ==========================================================================
   CANVAS CONTAINER & VIEWPORT
   ========================================================================== */
.canvas-viewport {
  flex: 1;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
  perspective: 1000px;
}

.canvas-zoom-container {
  transform: scale(var(--zoom-factor));
  transform-origin: center center;
  transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

.phone-canvas-outer {
  background: #000;
  border-top-left-radius: calc(var(--canvas-radius-tl, var(--canvas-radius, 12mm)) + 4px);
  border-top-right-radius: calc(var(--canvas-radius-tr, var(--canvas-radius, 12mm)) + 4px);
  border-bottom-left-radius: calc(var(--canvas-radius-bl, var(--canvas-radius, 12mm)) + 4px);
  border-bottom-right-radius: calc(var(--canvas-radius-br, var(--canvas-radius, 12mm)) + 4px);
  padding: 14px; /* phone case bezel look */
  box-shadow: 
    0 25px 50px -12px rgba(0, 0, 0, 0.7),
    0 0 40px rgba(99, 102, 241, 0.15),
    inset 0 0 2px rgba(255, 255, 255, 0.15);
  border: 1px solid rgba(255, 255, 255, 0.1);
  position: relative;
  transition: all 0.3s ease;
}

.phone-canvas {
  width: var(--canvas-width, 71.6mm);
  height: var(--canvas-height, 147.6mm);
  border-top-left-radius: var(--canvas-radius-tl, var(--canvas-radius, 11.5mm));
  border-top-right-radius: var(--canvas-radius-tr, var(--canvas-radius, 11.5mm));
  border-bottom-left-radius: var(--canvas-radius-bl, var(--canvas-radius, 11.5mm));
  border-bottom-right-radius: var(--canvas-radius-br, var(--canvas-radius, 11.5mm));
  position: relative;
  overflow: hidden;
  background-color: #121216;
  background-image: 
    linear-gradient(45deg, #181820 25%, transparent 25%), 
    linear-gradient(-45deg, #181820 25%, transparent 25%), 
    linear-gradient(45deg, transparent 75%, #181820 75%), 
    linear-gradient(-45deg, transparent 75%, #181820 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px; /* Transparent Grid pattern */
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.8);
}

/* Layers Container */
.canvas-layers {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}

/* Individual Interactive Layer */
.canvas-layer {
  position: absolute;
  transform-origin: center center;
  touch-action: none;
  cursor: move;
}

.canvas-layer img {
  width: 100%;
  height: 100%;
  object-fit: fill;
  pointer-events: none;
}

.canvas-layer.text-layer {
  white-space: pre-wrap;
  user-select: none;
  display: flex;
  align-items: center;
  line-height: 1.2;
}

.canvas-layer.shape-layer svg {
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* Guideline overlays */
.guidelines-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  border: 1px solid rgba(255, 255, 255, 0.25);
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.5);
  pointer-events: none;
  z-index: 10;
}

/* Camera Cutout Display */
.camera-cutout {
  position: absolute;
  background: rgba(8, 8, 12, 0.85);
  border: 1.5px dashed rgba(255, 255, 255, 0.4);
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  box-sizing: border-box;
  pointer-events: none;
  box-shadow: 0 0 5px rgba(0,0,0,0.5);
}
.camera-lens {
  opacity: 0.3;
  color: white;
}

/* Transform Control Box Overlay (drawn over selected layer) */
.transform-handle-box {
  position: absolute;
  border: 1.5px solid var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  z-index: 20;
  pointer-events: none; /* Let clicks pass through, JS handles dragging */
  transform-origin: center center;
}

/* Box buttons (Delete, Duplicate) and Handles styling */
.box-btn {
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  pointer-events: auto; /* Active for clicks */
  cursor: pointer;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease, background 0.2s ease;
  z-index: 21;
}

.box-btn:hover {
  transform: scale(1.15);
}

.box-delete-btn {
  top: -10px;
  left: -10px;
  background: var(--danger);
  border: 1.5px solid white;
}

.box-delete-btn:hover {
  background: #ff0044;
}

.box-duplicate-btn {
  top: -10px;
  right: -10px;
  background: var(--primary);
  border: 1.5px solid white;
}

.box-duplicate-btn:hover {
  background: #5254de;
}

/* Premium Resize Handle (Bottom-Right) */
.premium-resize-handle {
  position: absolute;
  width: 20px;
  height: 20px;
  background: var(--accent);
  border: 1.5px solid white;
  border-radius: 50%;
  bottom: -10px;
  right: -10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-inverse);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  cursor: nwse-resize;
  transition: transform 0.2s ease, background 0.2s ease;
  z-index: 21;
  pointer-events: auto;
}

.premium-resize-handle:hover {
  transform: scale(1.15);
  background: #00e1eb;
}

/* Other standard corner handles (e.g. bl) */
.resize-handle.handle-bl {
  width: 10px;
  height: 10px;
  background: white;
  border: 2px solid var(--accent);
  border-radius: 50%;
  bottom: -5px;
  left: -5px;
  cursor: nesw-resize;
  position: absolute;
  pointer-events: auto;
  z-index: 21;
}

/* Premium Rotate Handle */
.rotate-handle {
  position: absolute;
  top: -28px;
  left: calc(50% - 10px);
  width: 20px;
  height: 20px;
  background: var(--accent);
  border: 1.5px solid white;
  border-radius: 50%;
  cursor: grab;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-inverse);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
  transition: transform 0.2s ease, background 0.2s ease;
  z-index: 21;
}
.rotate-handle:hover {
  transform: scale(1.15);
  background: #00e1eb;
}
.rotate-handle-line {
  position: absolute;
  top: -12px;
  left: calc(50% - 0.75px);
  width: 1.5px;
  height: 16px;
  background: var(--accent);
}

.workspace-tip {
  height: 40px;
  background: rgba(13, 13, 21, 0.4);
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.workspace-tip svg {
  color: var(--accent);
}

/* ==========================================================================
   MODAL DIALOG (PRINT OPTIONS)
   ========================================================================== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(5, 5, 8, 0.85);
  backdrop-filter: blur(8px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.25s ease-out;
}

.modal-card {
  width: 960px;
  max-width: 95vw;
  max-height: 90vh;
  background: #11111a;
  border: 1px solid var(--border-color);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.6);
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h2 {
  font-size: 1.3rem;
  font-weight: 700;
}
.btn-close {
  background: none;
  border: none;
  font-size: 1.8rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: color 0.2s ease;
}
.btn-close:hover {
  color: var(--text-main);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  max-height: 70vh;
}

.modal-grid {
  display: grid;
  grid-template-columns: 1fr 1.3fr;
  gap: 28px;
  align-items: start;
}

/* Custom Checkbox */
.checkbox-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-top: 8px;
}
.checkbox-container {
  display: flex;
  align-items: center;
  position: relative;
  padding-left: 28px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-main);
  user-select: none;
}
.checkbox-container input {
  position: absolute;
  opacity: 0;
  cursor: pointer;
  height: 0;
  width: 0;
}
.checkmark {
  position: absolute;
  top: 0;
  left: 0;
  height: 18px;
  width: 18px;
  background-color: rgba(255,255,255,0.05);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  transition: all 0.2s ease;
}
.checkbox-container:hover input ~ .checkmark {
  background-color: rgba(255,255,255,0.1);
}
.checkbox-container input:checked ~ .checkmark {
  background-color: var(--primary);
  border-color: var(--primary);
}
.checkmark:after {
  content: "";
  position: absolute;
  display: none;
}
.checkbox-container input:checked ~ .checkmark:after {
  display: block;
}
.checkbox-container .checkmark:after {
  left: 5px;
  top: 2px;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

/* Warning block inside modal */
.alert-info {
  background: rgba(255, 42, 95, 0.06);
  border: 1px solid rgba(255, 42, 95, 0.15);
  padding: 14px;
  border-radius: 10px;
  display: flex;
  gap: 12px;
  margin-top: 20px;
  color: #ffa3b1;
}
.alert-info svg {
  flex-shrink: 0;
  color: var(--danger);
  margin-top: 2px;
}
.alert-info strong {
  display: block;
  font-size: 0.85rem;
  margin-bottom: 3px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.alert-info p {
  font-size: 0.8rem;
  line-height: 1.4;
}

/* Live Iframe Print Preview */
.paper-layout-preview {
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.paper-layout-preview h3 {
  font-size: 0.95rem;
  margin-bottom: 10px;
}

/* Wrapper uses aspect-ratio of A5 (148:210 ≈ 0.705) */
.print-iframe-wrapper {
  position: relative;
  width: 100%;
  aspect-ratio: 148 / 210;   /* A5 portrait — JS overrides for A4 */
  background: #18181f;
  border: 1px solid var(--border-color);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,0.04);
}

#print-preview-iframe {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  border: none;
  /* iframe renders at 148mm wide; scale it down to fit */
  transform-origin: top left;
  background: #fff;
}

.calibration-tip {
  margin-top: 10px;
  font-size: 0.75rem;
  color: var(--text-muted);
  line-height: 1.5;
}
.calibration-tip strong {
  color: var(--accent);
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* MagSafe Ring Guide Overlay (Screen) */
.magsafe-ring-guide {
  position: absolute;
  width: 54mm;
  height: 54mm;
  border: 1.5mm double rgba(255, 255, 255, 0.25);
  border-radius: 50%;
  left: calc(50% - 27mm);
  top: calc(50% - 27mm);
  z-index: 8;
  pointer-events: none;
  box-sizing: border-box;
  box-shadow: inset 0 0 10px rgba(0, 0, 0, 0.3);
}
.magsafe-ring-guide::after {
  content: '';
  position: absolute;
  width: 4mm;
  height: 11mm;
  background: rgba(255, 255, 255, 0.15);
  border: 0.5mm dashed rgba(255, 255, 255, 0.3);
  left: calc(50% - 2mm);
  top: 51mm;
  border-radius: 1mm;
}

/* Camera Lens Circle (Samsung Individual Lenses - Screen) */
.camera-lens-circle {
  position: absolute;
  border: 1.5px dashed rgba(255, 255, 255, 0.45);
  background: rgba(8, 8, 12, 0.85);
  border-radius: 50%;
  pointer-events: none;
  box-shadow: 0 0 4px rgba(0,0,0,0.5);
  box-sizing: border-box;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
}
.camera-lens-circle::after {
  content: '';
  width: 40%;
  height: 40%;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
}

/* ==========================================================================
   PRINT DIRECTIVE (PHYSICAL PAPER LAYOUT STYLE)
   ========================================================================== */
.print-sheet-root {
  display: none;
}

@media print {
  /* Hide every screen element */
  body, html, .app-container, .modal-overlay, .no-print {
    display: none !important;
    background: transparent !important;
  }
  
  .print-sheet-root {
    display: block !important;
    background: #ffffff !important;
    margin: 0 !important;
    padding: 0 !important;
    width: 100% !important;
    height: 100% !important;
  }

  .print-page {
    display: flex !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    background: #ffffff !important;
    box-sizing: border-box !important;
    position: relative !important;
    page-break-after: always !important;
    overflow: hidden !important;
  }

  /* Paper specific absolute physical sizing */
  /* These will match the size of paper sheets exactly */
  .print-page.a5-size {
    width: 148mm !important;
    height: 210mm !important;
  }
  .print-page.a4-size {
    width: 210mm !important;
    height: 297mm !important;
  }

  /* Phone Case Print Area - Exactly 1:1 Scale */
  .phone-print-cutout {
    position: absolute !important;
    box-sizing: border-box !important;
    /* width, height, border-radius set in inline styles in mm by JS */
  }

  /* Thin border around the phone cover so user can see where to cut */
  .phone-print-cutout.show-cut-border {
    border: 0.2mm dashed #333333 !important;
  }

  .phone-print-layers {
    position: absolute !important;
    top: 0 !important;
    left: 0 !important;
    width: 100% !important;
    height: 100% !important;
    z-index: 1 !important;
    overflow: hidden !important;
    border-radius: inherit !important;
  }

  /* Draw crop guides outside the phone frame */
  .print-crop-marks {
    position: absolute !important;
    width: 100% !important;
    height: 100% !important;
    top: 0 !important;
    left: 0 !important;
    pointer-events: none !important;
    z-index: 10 !important;
  }

  /* Draw camera cutout boundary */
  .print-camera-cutout {
    position: absolute !important;
    border: 0.2mm dashed #ff2a5f !important; /* dashed red guide line for cutting camera hole */
    background: transparent !important;
    z-index: 5 !important;
  }

  /* Ruler for calibration check */
  .print-calibration-bar {
    position: absolute !important;
    bottom: 12mm !important;
    left: calc(50% - 25mm) !important;
    width: 50mm !important;
    height: 3mm !important;
    background: #000000 !important;
    display: flex !important;
    flex-direction: column !important;
    align-items: center !important;
    color: #000000 !important;
  }
  .print-calibration-bar::after {
    content: "CALIBRATION BAR: MUST MEASURE EXACTLY 50MM ON PRINTED PAPER" !important;
    display: block !important;
    font-family: Arial, sans-serif !important;
    font-size: 5pt !important;
    font-weight: bold !important;
    margin-top: 4mm !important;
    white-space: nowrap !important;
    text-align: center !important;
  }

  /* Printable MagSafe Ring Guide */
  .print-magsafe-ring-guide {
    position: absolute !important;
    width: 54mm !important;
    height: 54mm !important;
    border: 0.3mm dashed #333333 !important;
    border-radius: 50% !important;
    left: calc(50% - 27mm) !important;
    top: calc(50% - 27mm) !important;
    z-index: 8 !important;
    box-sizing: border-box !important;
  }
  .print-magsafe-ring-guide::after {
    content: '' !important;
    position: absolute !important;
    width: 4mm !important;
    height: 11mm !important;
    border: 0.3mm dashed #333333 !important;
    left: calc(50% - 2mm) !important;
    top: 51mm !important;
    border-radius: 1px !important;
  }

  /* Printable Camera Lens Circle */
  .print-camera-lens-circle {
    position: absolute !important;
    border: 0.2mm dashed #ff2a5f !important;
    background: transparent !important;
    border-radius: 50% !important;
    z-index: 5 !important;
    box-sizing: border-box !important;
  }
}
