:root {
  --primary-color: #ffde59; /* Bright Yellow */
  --secondary-color: #5ce1e6; /* Bright Blue */
  --accent-color: #ff5757; /* Bright Red */
  --bg-color: #f0f0f0;
  --dark-color: #333333;
  --border-width: 2px;
  --border-radius: 12px;
  --shadow-color: #0000001a;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Cairo', system-ui, sans-serif;
  background-color: var(--bg-color);
  color: var(--dark-color);
  min-height: 100vh;
  direction: rtl;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 8px;
  gap: 8px;
}

@media (max-width: 768px) {
  body {
    overflow-y: auto;
    height: auto;
  }
}

/* 3D Effects & Cartoon Style */
.card-3d {
  background: white;
  border: var(--border-width) solid var(--dark-color);
  border-radius: var(--border-radius);
  box-shadow: 6px 6px 0px var(--dark-color);
}

.3d-btn {
  border: var(--border-width) solid var(--dark-color) !important;
  box-shadow: 4px 4px 0px var(--dark-color);
  transition: transform 0.1s, box-shadow 0.1s;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  gap: 8px;
}

.3d-btn:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0px var(--dark-color);
}

.3d-btn:disabled {
  background: #ccc !important;
  box-shadow: 2px 2px 0px #888;
  transform: translate(2px, 2px);
  cursor: not-allowed;
}

/* Device Bar (top) */
.device-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  background: linear-gradient(90deg, #fffde7, #ffffff);
}

.device-field {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.device-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--dark-color);
  white-space: nowrap;
}

#deviceIdField {
  flex: 1;
  min-width: 0;
  border: var(--border-width) solid var(--dark-color);
  border-radius: 8px;
  padding: 4px 10px;
  font-family: 'Courier New', monospace;
  font-weight: 800;
  font-size: 14px;
  letter-spacing: 1px;
  text-align: center;
  background: #f8f9fa;
  color: var(--dark-color);
}

#activateBtn.activated {
  background: var(--secondary-color);
  color: var(--dark-color);
}

.device-status {
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  color: #999;
}

.device-status.active {
  color: #2e7d32;
}

.device-status.expired {
  color: var(--accent-color);
}

/* Activation Modal */
.act-hint {
  font-size: 12px;
  color: #666;
  margin: 4px 0 12px;
}

.act-row {
  display: flex;
  gap: 10px;
  margin-bottom: 10px;
}

.act-row .control-group { flex: 1; margin-bottom: 0; }

#actCode {
  width: 100%;
  border: var(--border-width) solid var(--dark-color);
  border-radius: 8px;
  padding: 8px;
  font-family: 'Courier New', monospace;
  font-weight: 800;
  font-size: 15px;
  letter-spacing: 1px;
  text-align: center;
  background: #f8f9fa;
  color: var(--dark-color);
}

.act-btn-row {
  display: flex;
  gap: 8px;
  margin-top: 14px;
}

.act-whatsapp {
  margin-top: 14px;
  padding: 10px;
  background: #e7f7e5;
  border: 1px solid #25d366;
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.act-whatsapp a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-weight: 700;
  color: #ffffff;
  background: #25d366;
  padding: 8px 14px;
  border-radius: 8px;
  text-decoration: none;
  font-size: 15px;
}
.act-whatsapp a:active { background: #1eb457; }

/* License watermark (when deactivated) */
.license-watermark {
  position: fixed;
  inset: 0;
  z-index: 9999;
  pointer-events: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  grid-template-rows: repeat(4, 1fr);
  overflow: hidden;
}

.license-watermark.hidden { display: none; }

.license-watermark .wword {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(18px, 4vw, 44px);
  font-weight: 900;
  color: var(--accent-color);
  opacity: 0.16;
  transform: rotate(-28deg);
  white-space: nowrap;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.08);
}

body.locked .main-actions { pointer-events: none; opacity: 0.45; }

@media (max-width: 768px) {
  .device-bar { flex-wrap: wrap; }
  .device-field { flex-basis: 100%; }
}

/* Header */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: white;
  padding: 6px 12px;
  border: var(--border-width) solid var(--dark-color);
  border-radius: var(--border-radius);
  box-shadow: 4px 4px 0px var(--dark-color);
}

.logo-area {
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-icon {
  font-size: 20px;
}

.logo-area h1 {
  font-size: 16px;
  color: var(--dark-color);
}

.main-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.export-group {
  display: flex;
  gap: 4px;
  align-items: center;
}

#exportFormat {
  height: 34px;
  padding: 0 8px;
  background: white;
  border-radius: 8px;
}

/* Buttons */
.btn {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
}

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

.btn-xs {
  padding: 2px 6px;
  font-size: 10px;
}

.btn-lg-tool {
  padding: 8px 16px;
  font-size: 18px; /* 50% larger than 12px standard */
  min-width: 44px;
  min-height: 44px;
}

.btn.primary { background-color: var(--primary-color); color: var(--dark-color); }
.btn.secondary { background-color: var(--secondary-color); color: var(--dark-color); }
.btn.danger { background-color: var(--accent-color); color: white; }
.btn.accent { background-color: #a29bfe; color: var(--dark-color); }

/* Main Layout */
.main-layout {
  display: flex;
  flex: 1;
  gap: 12px;
  overflow: hidden;
}

.sidebar {
  width: 220px;
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 12px;
  overflow-y: auto;
}

.compact-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.custom-paper-dimensions {
  grid-column: 1 / -1;
}

.custom-paper-dimensions .control-group {
  margin-bottom: 0;
}

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

.image-adjustment {
  min-width: 0;
  padding: 5px 6px;
  border: 1px solid #e6e6e6;
  border-radius: 7px;
  background: #fafafa;
}

.image-adjustment label {
  gap: 4px;
}

.image-adjustment output {
  color: #6d5bd0;
  font-size: 10px;
  font-variant-numeric: tabular-nums;
}

.image-adjustment input[type="range"] {
  width: 100%;
  height: 18px;
  direction: ltr;
  accent-color: #6d5bd0;
  cursor: pointer;
}

.control-section h3 {
  font-size: 13px;
  margin-bottom: 8px;
  border-bottom: 1px dashed #ddd;
  padding-bottom: 2px;
}

.control-group {
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.control-group label {
  font-size: 11px;
  font-weight: bold;
  display: flex;
  justify-content: space-between;
  align-items: center;
  white-space: nowrap;
}

.input-with-action {
  display: flex;
  gap: 4px;
  align-items: center;
}

.input-with-action select {
  flex: 1;
}

.size-hint {
  font-size: 11px;
  color: var(--accent-color);
  font-weight: normal;
}

.poster-hint {
  font-size: 12px;
  color: var(--muted, #888);
  margin: 2px 0 0;
  line-height: 1.5;
}

select, input[type="number"], input[type="text"] {
  border: 1.5px solid var(--dark-color);
  border-radius: 6px;
  padding: 4px 6px;
  font-family: inherit;
  font-weight: 600;
  outline: none;
  font-size: 12px;
  width: 100%;
}

/* Content Area */
.content-area {
  flex: 1;
  background: #fff;
  border: var(--border-width) solid var(--dark-color);
  border-radius: var(--border-radius);
  box-shadow: 6px 6px 0px var(--dark-color);
  overflow-y: auto;
  position: relative;
  padding: 16px;
  background-image: radial-gradient(#ddd 1px, transparent 1px);
  background-size: 20px 20px;
}

.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 16px;
}

.empty-placeholder {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: #888;
}

.bounce-icon {
  font-size: 60px;
  margin-bottom: 10px;
  animation: bounce 2s infinite;
}

@keyframes bounce {
  0%, 20%, 50%, 80%, 100% {transform: translateY(0);}
  40% {transform: translateY(-20px);}
  60% {transform: translateY(-10px);}
}

/* Thumbnails */
.thumb {
  position: relative;
  border: 2px solid var(--dark-color);
  border-radius: 12px;
  overflow: hidden;
  background: white;
  aspect-ratio: 1/1;
  box-shadow: 4px 4px 0 var(--dark-color);
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: var(--primary-color);
  border: 2px solid var(--dark-color);
  border-radius: 50%;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: bold;
  z-index: 2;
}

.thumb-info {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.9);
  border-top: 2px solid var(--dark-color);
  padding: 4px;
  font-size: 10px;
  text-align: center;
  font-weight: bold;
  pointer-events: none;
  transform: translateY(100%);
  transition: transform 0.2s;
}

.thumb:hover .thumb-info {
  transform: translateY(0);
}

.preview-modal-content, .editor-modal-content {
  max-width: 900px;
  width: 98%;
  height: auto;
  max-height: 98vh;
  display: flex;
  flex-direction: column;
  padding: 10px !important;
  overflow-y: auto;
}

.camera-wrapper, .cropper-container {
  flex: 1;
  min-height: 250px;
  max-height: 60vh;
  background: #000;
  border: 2px solid var(--dark-color);
  border-radius: 8px;
  margin: 5px 0;
  overflow: hidden;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

.camera-wrapper video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.camera-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  border: 3px solid var(--primary-color);
  box-shadow: 0 0 0 1000px rgba(0,0,0,0.5);
  pointer-events: none;
  z-index: 5;
  transition: all 0.3s ease;
}

.capture-preview-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: none;
  align-items: flex-start; /* Move content to top */
  justify-content: center;
  z-index: 20;
  padding: 10px;
  overflow-y: auto; /* Allow scrolling if image is still too big */
}

.capture-preview-overlay.active {
  display: flex;
}

.preview-box {
  background: white;
  padding: 10px;
  max-width: 90%;
  max-height: 90%;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#capturedImgPreview {
  max-width: 100%;
  max-height: 65vh; /* Reduced height to ensure buttons fit above */
  object-fit: contain;
  border-radius: 4px;
  border: 1px solid #ddd;
}

.preview-actions {
  display: flex;
  gap: 10px;
}

.camera-header, .editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 5px;
}

.editor-nav-top {
  display: flex;
  gap: 5px;
}

.id-card-status {
  background: var(--accent-color);
  color: white;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: bold;
  animation: pulse 1.5s infinite;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: 0.5; }
  100% { opacity: 1; }
}

.camera-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 8px;
}

.camera-row-layout {
  grid-template-columns: repeat(3, 1fr) !important;
}

@media (max-width: 480px) {
  .camera-controls {
    grid-template-columns: 1fr;
    gap: 4px;
  }
  .camera-row-layout {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 4px;
  }
  .camera-row-layout label {
    font-size: 10px;
  }
  .camera-row-layout select {
    font-size: 10px;
    padding: 2px 4px;
  }
}

.editor-tools {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 6px;
  background: #f8f8f8;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid #ddd;
}

.editor-filter-tools {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
  gap: 6px;
  padding: 7px;
  background: #fff;
  border: 1px solid #e2e2e2;
  border-radius: 7px;
}

.editor-filter-select {
  grid-column: span 2;
  margin-bottom: 0;
}

.editor-filter-tools select {
  width: 100%;
  min-height: 34px;
  padding: 3px 6px;
}

.editor-filter-tools .image-adjustment {
  margin-bottom: 0;
}

@media (max-width: 600px) {
  .editor-filter-tools {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .editor-filter-select {
    grid-column: 1 / -1;
  }
}

.tool-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: center;
  margin-bottom: 4px;
}

.shape-picker-content {
  max-width: 450px;
  width: 95%;
  padding: 15px !important;
  max-height: 85vh;
}

#shapePickerModal {
  z-index: 2000; /* Higher than editor modal */
}

.picker-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.btn-close-minimal {
  background: none;
  border: none;
  font-size: 24px;
  cursor: pointer;
  color: #666;
}

.category-tabs {
  display: flex;
  gap: 5px;
  overflow-x: auto;
  padding-bottom: 10px;
  margin-bottom: 15px;
  border-bottom: 1px solid #eee;
}

.tab-btn {
  padding: 6px 12px;
  border: 1px solid #ddd;
  background: #f9f9f9;
  border-radius: 20px;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  font-weight: bold;
}

.tab-btn.active {
  background: var(--primary-color);
  border-color: var(--dark-color);
  box-shadow: 2px 2px 0 var(--dark-color);
}

.shape-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  max-height: 400px;
  overflow-y: auto;
  padding: 5px;
}

.shape-item {
  aspect-ratio: 1/1;
  border: 2px solid #ddd;
  border-radius: 12px;
  background: #fff;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 10px;
  transition: all 0.2s;
}

.shape-item:hover {
  border-color: var(--secondary-color);
  background: #f0fbff;
}

.shape-item.active {
  border-color: var(--accent-color);
  background: #fffde7;
  transform: scale(0.98);
  box-shadow: inset 0 2px 5px rgba(0,0,0,0.1);
}

.shape-item svg {
  width: 100%;
  height: 60px;
  margin-bottom: 5px;
}

.shape-item span {
  font-size: 10px;
  font-weight: bold;
  color: #555;
  text-align: center;
}

.picker-footer {
  margin-top: 15px;
  padding-top: 10px;
  border-top: 1px solid #eee;
  display: flex;
  justify-content: center;
}

/* ===== Collage Layout Shape Picker (professional dark template picker) ===== */
.cl-panel {
  max-width: 720px;
  width: 96%;
  max-height: 94vh;
  padding: 0 !important;
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #1f2226;
  border: 1px solid #2c3036;
  box-shadow: 0 24px 70px rgba(0,0,0,0.55);
}

#collageLayoutModal {
  z-index: 2100; /* above collage editor */
  background: rgba(9,10,12,0.6);
  backdrop-filter: blur(3px);
}

/* Top navigation bar */
.cl-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: #22252a;
  border-bottom: 1px solid #2d3239;
  flex: none;
}

.cl-tabs {
  display: flex;
  gap: 2px;
  align-items: center;
}

.cl-tab {
  background: transparent;
  border: none;
  color: #8e949d;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  padding: 13px 14px;
  margin-top: -2px;
  cursor: pointer;
  position: relative;
  transition: color 0.15s;
}

.cl-tab:hover { color: #d3d8df; }

.cl-tab.active {
  color: #ffffff;
}
.cl-tab.active::after {
  content: '';
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 0;
  height: 2px;
  background: #3b82f6;
  border-radius: 2px;
}

.cl-close {
  background: transparent;
  border: none;
  color: #8e949d;
  font-size: 18px;
  line-height: 1;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  cursor: pointer;
}
.cl-close:hover { background: #2c3036; color: #fff; }

/* Options panel shown for ratio / border / background tabs */
.cl-options {
  display: none;
  flex: none;
  padding: 12px 16px;
  background: #22252a;
  border-bottom: 1px solid #2d3239;
}
.cl-options .cl-opt-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cl-options .cl-opt-label { color: #9aa0a8; font-size: 13px; font-weight: 600; margin-inline-end: 4px; }
.cl-swatch {
  background: #2a2e34;
  border: 1px solid #3a3f47;
  color: #e6e9ed;
  font-size: 12.5px;
  font-family: inherit;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  min-width: 40px;
  text-align: center;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.cl-swatch:hover { background: #33383f; border-color: #4b525c; }
.cl-swatch.active { background: #3b82f6; border-color: #3b82f6; color: #fff; }
/* Grid of templates */
.cl-grid {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 9px;
  background: #1f2226;
  align-content: start;
}

.cl-grid::-webkit-scrollbar { width: 8px; }
.cl-grid::-webkit-scrollbar-thumb { background: #3a3f47; border-radius: 4px; }
.cl-grid::-webkit-scrollbar-track { background: transparent; }

.layout-item {
  background: #26292e;
  border: 2px solid #2e333a;
  border-radius: 8px;
  cursor: pointer;
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  transition: border-color 0.14s, transform 0.14s;
}
.layout-item:hover { border-color: #4b525c; transform: translateY(-1px); }
.layout-item.active {
  border-color: #3b82f6;
  box-shadow: 0 0 0 1px #3b82f6 inset, 0 3px 12px rgba(59,130,246,0.25);
}

.layout-thumb {
  width: 100%;
  height: 78px;
  border-radius: 5px;
  background: #2f3339;
  border: 1px solid #33383f;
}

.layout-item span {
  font-size: 10px;
  font-weight: 600;
  color: #b6bcc6;
  text-align: center;
  margin-top: 4px;
  line-height: 1.3;
}

/* Footer */
.cl-footer {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 16px;
  background: #22252a;
  border-top: 1px solid #2d3239;
}

.layout-hint {
  font-size: 12px;
  color: #9aa0a8;
}

.cl-shuffle {
  background: #2a2e34;
  border: 1px solid #3a3f47;
  color: #e6e9ed;
  font-size: 13px;
  font-family: inherit;
  font-weight: 600;
  padding: 7px 14px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.cl-shuffle:hover { background: #33383f; border-color: #4b525c; color: #fff; }

.mask-layer {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: auto;
  z-index: 100;
  cursor: move;
  touch-action: none;
}

.mask-overlay-active .cropper-drag-box,
.mask-overlay-active .cropper-crop-box {
  display: none !important;
}

.repeat-inline-tool {
  display: flex;
  align-items: center;
  gap: 4px;
  background: #fff9c4;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid #ccc;
}

.tool-tag {
  font-size: 11px;
  font-weight: bold;
  color: #666;
  min-width: 55px;
}

.modal-footer {
  display: flex;
  gap: 10px;
  justify-content: stretch;
}

.modal-footer button {
  flex: 1;
}

.editor-main-footer {
  gap: 6px;
  flex-wrap: wrap;
}

.editor-main-footer button {
  padding: 6px 4px;
  font-size: 11px;
  min-height: 36px;
  flex: 1 1 45%; /* Allow two buttons per row on small screens */
}

.thumb-edit-btn {
  position: absolute;
  top: 4px;
  left: 4px;
  background: var(--secondary-color);
  border: 2px solid var(--dark-color);
  border-radius: 4px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  z-index: 2;
  box-shadow: 2px 2px 0 var(--dark-color);
}

.thumb-copy-btn {
  position: absolute;
  top: 36px;
  left: 4px;
  background: #a29bfe;
  border: 2px solid var(--dark-color);
  border-radius: 4px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  z-index: 2;
  box-shadow: 2px 2px 0 var(--dark-color);
}

.thumb-cut-btn {
  position: absolute;
  top: 68px;
  left: 4px;
  background: #ffcc00;
  border: 2px solid var(--dark-color);
  border-radius: 4px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  z-index: 2;
  box-shadow: 2px 2px 0 var(--dark-color);
}

.thumb-delete-btn {
  position: absolute;
  top: 36px;
  right: 4px;
  background: var(--accent-color);
  border: 2px solid var(--dark-color);
  border-radius: 4px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  z-index: 2;
  box-shadow: 2px 2px 0 var(--dark-color);
  color: white;
}

.thumb-retake-btn {
  position: absolute;
  top: 68px;
  right: 4px;
  background: var(--secondary-color);
  border: 2px solid var(--dark-color);
  border-radius: 4px;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  z-index: 2;
  box-shadow: 2px 2px 0 var(--dark-color);
}

.color-picker {
  width: 30px;
  height: 30px;
  border: 2px solid var(--dark-color);
  border-radius: 4px;
  padding: 0;
  cursor: pointer;
  background: none;
}

/* Drawing Overlay */
.cropper-container canvas.drawing-layer {
  position: absolute;
  top: 0;
  left: 0;
  pointer-events: none;
  z-index: 10;
}

.drawing-active .cropper-drag-box,
.drawing-active .cropper-crop-box {
  pointer-events: none !important;
}

.drawing-active .drawing-layer {
  pointer-events: auto !important;
  cursor: crosshair;
  touch-action: none;
}

.pdf-viewer {
  flex: 1;
  background: #eee;
  border: 2px solid var(--dark-color);
  border-radius: 8px;
  margin: 15px 0;
  overflow-y: auto;
}

.pdf-viewer iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.pdf-viewer:has(.collage-export-state) {
  align-items: center;
  justify-content: center;
}
.collage-export-state {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 180px;
  padding: 24px;
  color: #444;
  text-align: center;
  font-weight: 700;
}
.collage-export-spinner {
  width: 38px;
  height: 38px;
  border: 4px solid #d9d9d9;
  border-top-color: #ffb800;
  border-radius: 50%;
  animation: collage-export-spin 0.8s linear infinite;
}
@keyframes collage-export-spin {
  to { transform: rotate(360deg); }
}

.mobile-preview-msg {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 20px;
  text-align: center;
  gap: 15px;
}

.stats-box {
  background: #f9f9f9;
  border: 1.5px solid var(--dark-color);
  border-radius: 8px;
  padding: 6px;
  font-size: 12px;
  line-height: 1.4;
}

.compact-stats {
  text-align: center;
  font-weight: bold;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-overlay.active { display: flex; }

/* Preview sits above any open editor modal */
#previewModal { z-index: 1200; }
#collageProjectsModal { z-index: 1100; }
.collage-projects-content {
  width: min(92vw, 520px);
  max-width: 520px;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  overflow: hidden;
}
.collage-projects-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.collage-projects-header h3 { margin: 0; }
.collage-project-save-row {
  display: flex;
  gap: 8px;
}
.collage-project-save-row input {
  flex: 1;
  min-width: 0;
  padding: 9px 10px;
  border: 2px solid var(--dark-color);
  border-radius: 8px;
  font: inherit;
}
.collage-projects-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow-y: auto;
  min-height: 40px;
}
.collage-project-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: #fff;
}
.collage-project-info {
  flex: 1;
  min-width: 0;
}
.collage-project-name {
  overflow-wrap: anywhere;
  font-weight: 700;
}
.collage-project-date {
  margin-top: 2px;
  color: #777;
  font-size: 11px;
}
.collage-project-empty {
  margin: 0;
  padding: 12px;
  color: #777;
  text-align: center;
}
.collage-modal-content .preview-btn-row { border: none; margin: 0; }
.preview-btn-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  margin-top: 14px;
}
.preview-btn-row .btn { flex: 1; }

.modal-content {
  width: 90%;
  max-width: 340px;
  padding: 24px;
}

.size-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 20px 0;
}

.input-field { flex: 1; display: flex; flex-direction: column; gap: 5px; text-align: right; }

/* Collage (تابلوه) editor — full-screen with floating panels */
.collage-modal-content {
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  margin: 0;
  border-radius: 0;
  padding: 12px;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}
.collage-header {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 12;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 8px 12px;
  background: rgba(255,255,255,0.92);
  border-radius: 10px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.18);
  backdrop-filter: blur(4px);
}
.collage-hint { font-size: 12px; color: #666; }

/* Floating toggle buttons (always visible, fixed in header) */
.collage-float-toggles {
  display: inline-flex;
  gap: 8px;
}
.collage-float-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: #ffde59;
  color: #333;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 4px 12px rgba(0,0,0,0.25);
  transition: transform 0.15s ease, background 0.15s ease;
}
.collage-float-btn:hover { transform: scale(1.08); }
.collage-float-btn.active { background: #ff9800; color: #fff; }

/* Floating collapsible panels */
.collage-panel {
  position: absolute;
  z-index: 11;
  left: auto;
  right: 12px;
  width: min(340px, calc(100vw - 24px));
  box-sizing: border-box;
  background: rgba(255,255,255,0.96);
  border: 1px solid rgba(55, 65, 81, 0.12);
  border-radius: 12px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.24);
  padding: 12px;
  backdrop-filter: blur(6px);
  display: none;
  max-height: calc(100% - 84px);
  overflow-x: hidden;
  overflow-y: auto;
}
.collage-panel.open { display: flex; }
.collage-toolbar {
  top: 66px;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.collage-toolbar > button { width: 100%; }
.collage-settings {
  top: 66px;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  flex-wrap: nowrap;
  font-size: 13px;
  align-content: flex-start;
}
.collage-settings > label {
  flex-direction: column;
  align-items: stretch;
}
.collage-settings > label input[type="range"] { width: 100%; }
.collage-settings.slider-active > :not(.active-slider-path):not(.active-slider-label) {
  display: none !important;
}
.collage-settings.slider-active .active-slider-path {
  display: flex !important;
}
.collage-settings.slider-active .active-slider-path > :not(.active-slider-path):not(.active-slider-label) {
  display: none !important;
}
.collage-settings.slider-active .active-slider-label {
  display: flex !important;
  flex-direction: column;
  align-items: stretch;
  width: 100%;
  padding: 8px;
  box-sizing: border-box;
  border-radius: 8px;
  background: #fffde7;
}
.collage-settings.slider-active .active-slider-label input[type="range"] { width: 100%; }
.collage-settings-actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
}
.collage-settings-actions .btn { white-space: nowrap; }
.collage-toolbar-sep { width: 100%; height: 1px; background: #ddd; margin: 2px 0; }

/* Solo (single-tool) mode: collapse the toolbar to show only the chosen button */
.collage-solo {
  display: flex;
  align-items: center;
  gap: 8px;
}
.collage-solo[hidden] { display: none; }
.collage-solo .solo-btn {
  font-size: 15px;
  box-shadow: 0 3px 10px rgba(0,0,0,0.2);
}
.collage-solo-close {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #fff;
  background: #f44336;
  color: #fff;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0,0,0,0.25);
  transition: transform 0.15s ease, background 0.15s ease;
}
.collage-solo-close:hover { transform: scale(1.1); background: #d32f2f; }
.collage-settings label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.collage-random-frame-settings {
  width: 100%;
  box-sizing: border-box;
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: center;
  gap: 8px 14px;
  padding: 9px 10px;
  border: 1px dashed #a29bfe;
  border-radius: 8px;
  background: #f7f5ff;
}
.collage-random-frame-settings[hidden] { display: none !important; }
.collage-random-frame-settings label {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  min-width: 0;
  font-weight: 700;
}
.collage-random-frame-settings .collage-random-frame-toggle {
  flex-direction: row;
  align-items: center;
  justify-content: flex-start;
}
.collage-random-frame-settings input[type="checkbox"] {
  width: 17px;
  height: 17px;
  accent-color: #6d5bd0;
}
.collage-random-frame-settings select { width: 100%; }
.collage-random-frame-settings input[type="range"] { width: 100%; }
.collage-random-frame-settings label > span {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  white-space: nowrap;
}
.collage-random-frame-settings output {
  min-width: 20px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.collage-random-frame-settings input[type="color"] { align-self: flex-start; }
.collage-random-frame-remove { grid-column: 1 / -1; justify-self: stretch; }
@media (max-width: 620px) {
  .collage-random-frame-settings {
    grid-template-columns: minmax(0, 1fr);
  }
}
.collage-background-image {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  max-width: 100%;
}
.collage-bg-image-name {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: #666;
  font-size: 11px;
}
.collage-settings .btn[hidden] { display: none; }
.collage-settings .btn.active { outline: 2px solid #ff9800; }
.collage-settings input[type="number"] { width: 64px; padding: 4px 6px; border: 1px solid #bbb; border-radius: 6px; }
.collage-settings select { padding: 4px 8px; border: 1px solid #bbb; border-radius: 6px; }
.collage-settings .collage-frame-chk { gap: 8px; }
.collage-settings .collage-frame-chk input { width: 16px; height: 16px; }

/* Full-screen stage */
.collage-stage {
  position: absolute;
  inset: 0;
  background: #222;
  overflow: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 22px;
}
#collageCanvas {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  background: #fff;
  display: block;
  border: 8px solid #fff;
  border-radius: 8px;
  box-shadow: 0 4px 22px rgba(0,0,0,0.38);
  touch-action: none;
  cursor: grab;
}

.collage-settings input[type="color"] { width: 40px; height: 30px; border: 1px solid #ccc; border-radius: 6px; background: #fff; padding: 0; }
.collage-settings input[type="range"] { width: 90px; }

/* Collage text panel */
.collage-text {
  top: 66px;
  flex-direction: column;
  gap: 10px;
  font-size: 13px;
}
.collage-text .text-panel-row { flex-direction: column; align-items: stretch; }
.collage-text .text-panel-textarea textarea { min-width: 0; width: 100%; box-sizing: border-box; }
.collage-text .text-font-select { max-width: none; width: 100%; }
.collage-text .text-panel-row { display: flex; flex-direction: column; align-items: stretch; gap: 8px; flex-wrap: wrap; }
.collage-text .text-lbl { font-size: 12px; font-weight: bold; color: #555; white-space: nowrap; }
.collage-text .text-chk { display: inline-flex; align-items: center; gap: 5px; }
.collage-text .text-chk input { width: 16px; height: 16px; }
.collage-text .text-panel-textarea textarea { flex: 1; min-width: 160px; padding: 6px; border: 1px solid #bbb; border-radius: 6px; font-size: 14px; resize: vertical; }
.collage-text .text-size-input { width: 64px; padding: 4px 6px; border: 1px solid #bbb; border-radius: 6px; }
.collage-text .text-color-input { width: 44px; height: 30px; border: 1px solid #ccc; border-radius: 6px; background: #fff; padding: 0; }
.collage-text .text-font-select { max-width: none; width: 100%; box-sizing: border-box; padding: 4px 6px; border: 1px solid #bbb; border-radius: 6px; font-size: 13px; }
.collage-text .text-panel-actions { justify-content: space-between; align-items: center; }
.collage-text .text-panel-hint { font-size: 11px; color: #888; }
.collage-text .btn.active { box-shadow: 0 0 0 3px #ff9800; outline: none; }

@media (max-width: 768px) {
  .collage-header { flex-wrap: nowrap; gap: 6px; padding: 6px 8px; }
  .collage-header h3 { margin: 0; font-size: 15px; white-space: nowrap; }
  .collage-hint { display: none; }
  .collage-float-toggles { gap: 5px; }
  .collage-float-btn { width: 36px; height: 36px; }
  .collage-panel { width: min(300px, calc(100vw - 24px)); max-height: calc(100% - 78px); }
  .main-layout { flex-direction: column; overflow-y: auto; }
  .sidebar { width: 100%; height: auto; display: block; flex: none; }
  .content-area { min-height: 300px; flex: none; }
  #app { height: auto; overflow: visible; }
  .top-bar { flex-direction: column; gap: 8px; }
  .main-actions { width: 100%; justify-content: space-around; }
  .compact-grid { grid-template-columns: 1fr 1fr 1fr; }
}

/* ===== Collage project save / restore + zoom preview ===== */
#collageZoomModal { z-index: 2200; background: rgba(0,0,0,0.55); }

.collage-zoom-content { position: relative; display: flex; flex-direction: column; height: 92vh; width: min(96vw, 1100px); max-width: 96vw; padding: 16px; gap: 12px; }
.collage-zoom-header { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; }
.collage-zoom-controls { display: flex; align-items: center; gap: 8px; }
.collage-zoom-pct { font-weight: 700; font-size: 14px; color: var(--dark-color); min-width: 48px; text-align: center; }
.collage-zoom-hint { flex-basis: 100%; margin: 0; font-size: 12px; color: #666; text-align: center; }
.collage-zoom-stage {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: repeating-conic-gradient(#eee 0 25%, #f8f8f8 0 50%) 0 0 / 24px 24px;
  border: 2px solid var(--dark-color);
  border-radius: 12px;
  cursor: grab;
}
.collage-zoom-stage.dragging { cursor: grabbing; }
.collage-zoom-stage::-webkit-scrollbar { width: 12px; height: 12px; }
.collage-zoom-stage::-webkit-scrollbar-thumb { background: #cfd8dc; border-radius: 6px; }
#collageZoomImg {
  display: block;
  margin: 0 auto;
  width: 100%;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
  transform-origin: top left;
  box-shadow: 0 0 0 1px #ccc;
}
