/* ===== VARIABLES ===== */
:root {
  --coral: #e71a65;
  --coral-dark: #c01455;
  --coral-light: #f04080;
  --cream: #ffe3db;
  --dark: #3d3d3d;
  --gray-light: #f7f7f7;
  --gray-mid: #e0e0e0;
  --gray-text: #888;
  --bleu: #48b7ec;
  --white: #fff;
  --sidebar-tabs-w: 72px;
  --sidebar-panel-w: 260px;
  --sidebar-w: calc(var(--sidebar-tabs-w) + var(--sidebar-panel-w));
  --props-w: 220px;
  --topbar-h: 52px;
  --bottombar-h: 48px;
  --radius: 8px;
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Open Sans', sans-serif;
  color: var(--dark);
  background: var(--gray-light);
  overflow: hidden;
  height: 100vh;
}

/* Editor app flex layout — critical for proper rendering */
#editor-app {
  flex-direction: column;
  height: 100vh;
  width: 100%;
  overflow: hidden;
  background: var(--gray-light);
}

button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: inherit; }
input, select { font-family: inherit; font-size: 13px; }

/* ===== TOP BAR ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--topbar-h);
  padding: 0 16px;
  background: var(--white);
  border-bottom: 1px solid var(--gray-mid);
  z-index: 100;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-logo { height: 32px; }
.topbar-client { font-size: 14px; color: var(--gray-text); }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.save-status { font-size: 12px; color: var(--gray-text); display: flex; align-items: center; gap: 4px; }
.save-status .dot { width: 8px; height: 8px; border-radius: 50%; background: #4caf50; display: inline-block; }
.save-status .dot.saving { background: #ff9800; }
.save-status .dot.error { background: #f44336; }

.format-select {
  padding: 4px 8px;
  border: 1px solid var(--gray-mid);
  border-radius: var(--radius);
  font-size: 13px;
  background: var(--white);
}

/* ===== MAIN LAYOUT ===== */
.editor-layout {
  display: flex;
  height: calc(100vh - var(--topbar-h) - var(--bottombar-h));
}

/* ===== LEFT SIDEBAR (Canva-style) ===== */
.sidebar {
  display: flex;
  flex-shrink: 0;
  height: 100%;
}

/* Tab icons strip */
.sidebar-tabs {
  width: var(--sidebar-tabs-w);
  background: #2c2c2c;
  display: flex;
  flex-direction: column;
  padding: 4px 0;
  overflow-y: auto;
}

.sidebar-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 4px;
  color: #aaa;
  transition: color 0.15s, background 0.15s;
  border-radius: 0;
  position: relative;
}

.sidebar-tab svg { width: 22px; height: 22px; }
.sidebar-tab span { font-size: 10px; white-space: nowrap; }

.sidebar-tab:hover { color: #fff; }
.sidebar-tab.active {
  color: #fff;
  background: #444;
}
.sidebar-tab.active::before {
  content: '';
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--coral);
  border-radius: 0 2px 2px 0;
}

/* Panel content */
.sidebar-content {
  width: var(--sidebar-panel-w);
  background: var(--white);
  border-right: 1px solid var(--gray-mid);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-panel {
  display: none;
  padding: 16px;
}

.sidebar-panel.active { display: block; }

.sidebar-panel h3 {
  font-family: 'Nunito', sans-serif;
  font-size: 16px;
  font-weight: 800;
  margin-bottom: 4px;
}

.panel-hint {
  font-size: 12px;
  color: var(--gray-text);
  margin-bottom: 12px;
}

.panel-section {
  margin-bottom: 20px;
}

.panel-section h4 {
  font-family: 'Nunito', sans-serif;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gray-text);
  margin-bottom: 8px;
}

/* ===== ELEMENTS SEARCH ===== */
.elements-search {
  width: 100%;
  padding: 8px 12px 8px 32px;
  border: 1px solid var(--gray-mid);
  border-radius: var(--radius);
  font-size: 13px;
  margin-bottom: 12px;
  outline: none;
  background: var(--gray-light) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Ccircle cx='11' cy='11' r='8'/%3E%3Cline x1='21' y1='21' x2='16.65' y2='16.65'/%3E%3C/svg%3E") 10px center no-repeat;
  transition: border-color 0.15s;
}
.elements-search:focus { border-color: var(--coral); background-color: var(--white); }
.elements-search::placeholder { color: var(--gray-text); }
.panel-section.section-hidden { display: none; }

/* ===== ELEMENT GRID (stickers, shapes) ===== */
.element-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}

.element-item {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gray-light);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s, transform 0.15s, box-shadow 0.15s;
  padding: 8px;
}

.element-item:hover {
  background: var(--cream);
  transform: scale(1.05);
  box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

.element-item svg {
  width: 100%;
  height: 100%;
}

.element-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.element-item.item-hidden { display: none; }

/* Icon items (Iconify SVGs) — slightly larger for elegance */
.element-item--icon {
  padding: 10px;
  background: var(--white);
  border: 1px solid #f0f0f0;
}
.element-item--icon:hover {
  background: #f9f5f0;
  border-color: #d4c4a8;
}
.element-item--icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  opacity: 0.85;
  transition: opacity 0.15s;
}
.element-item--icon:hover img {
  opacity: 1;
}

/* ===== STICKERS IA CATEGORY TABS ===== */
.stickers-category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}
.sticker-cat-btn {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--gray-mid);
  border-radius: 20px;
  background: var(--white);
  color: var(--gray-text);
  cursor: pointer;
  transition: all 0.15s;
  text-transform: capitalize;
}
.sticker-cat-btn:hover {
  border-color: var(--coral);
  color: var(--coral);
}
.sticker-cat-btn.active {
  background: var(--coral);
  border-color: var(--coral);
  color: var(--white);
}

/* ===== WIDE ELEMENT GRID (background images) ===== */
.element-grid--wide {
  grid-template-columns: repeat(2, 1fr);
}
.element-item--wide {
  aspect-ratio: 16 / 10;
}
.element-item--wide img {
  object-fit: cover;
}

/* Background images category tabs — reuse sticker tab style */
.bg-images-category-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-bottom: 8px;
}
.bg-cat-btn {
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid var(--gray-mid);
  border-radius: 20px;
  background: var(--white);
  color: var(--gray-text);
  cursor: pointer;
  transition: all 0.15s;
  text-transform: capitalize;
}
.bg-cat-btn:hover {
  border-color: var(--coral);
  color: var(--coral);
}
.bg-cat-btn.active {
  background: var(--coral);
  border-color: var(--coral);
  color: var(--white);
}

/* ===== COLLAPSIBLE SECTION ===== */
.collapsible-section { margin-top: 8px; border-top: 1px solid var(--gray-mid); padding-top: 8px; }
.collapsible-section.section-hidden { display: none; }

.collapsible-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 4px;
  font-size: 13px;
  font-weight: 700;
  color: var(--gray-text);
  cursor: pointer;
  background: none;
  border: none;
  font-family: 'Nunito', sans-serif;
  transition: color 0.15s;
}
.collapsible-toggle:hover { color: var(--dark); }
.collapsible-arrow { width: 16px; height: 16px; transition: transform 0.2s; }
.collapsible-toggle.open .collapsible-arrow { transform: rotate(180deg); }

.collapsible-content { padding-top: 4px; }

/* ===== BALLOON LETTERS ===== */
.balloon-color-strip { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.balloon-color-btn {
  width: 28px; height: 28px; border-radius: 50%;
  border: 2px solid transparent; cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.balloon-color-btn:hover { transform: scale(1.15); }
.balloon-color-btn.active { border-color: var(--dark); box-shadow: 0 0 0 2px white, 0 0 0 4px var(--dark); }

.balloon-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.balloon-letter-item {
  aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  font-family: 'Nunito', sans-serif; font-size: 18px; font-weight: 900;
  color: white; text-shadow: 0 1px 3px rgba(0,0,0,0.3);
  border-radius: var(--radius); cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s;
}
.balloon-letter-item:hover { transform: scale(1.1); box-shadow: 0 2px 8px rgba(0,0,0,0.2); }
.balloon-letter-item.item-hidden { display: none; }

/* ===== EFFECT BUTTONS ===== */
.effect-btn {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 10px 14px; background: var(--gray-light);
  border: 1px solid var(--gray-mid); border-radius: var(--radius);
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}
.effect-btn:hover { border-color: var(--coral); background: rgba(231,26,101,0.03); }

/* ===== TEXT PRESETS ===== */
.text-preset {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  margin-bottom: 8px;
  border: 1px solid var(--gray-mid);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.text-preset:hover {
  border-color: var(--coral);
  background: rgba(231,26,101,0.03);
}

.text-preset--title {
  font-family: 'Nunito', sans-serif;
  font-size: 20px;
  font-weight: 800;
}

.text-preset--subtitle {
  font-family: 'Nunito', sans-serif;
  font-size: 15px;
  font-weight: 700;
  color: #555;
}

.text-preset--body {
  font-family: 'Open Sans', sans-serif;
  font-size: 13px;
  color: var(--gray-text);
}

/* Text style cards */
.text-styles-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.text-style-card {
  padding: 14px 10px;
  text-align: center;
  border: 1px solid var(--gray-mid);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
  overflow: hidden;
}

.text-style-card:hover {
  border-color: var(--coral);
  transform: translateY(-2px);
}

.text-style-card .preview-text {
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===== BACKGROUNDS ===== */
.color-input-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.color-input-wrap input[type="color"] {
  width: 32px;
  height: 32px;
  border: 1px solid var(--gray-mid);
  border-radius: 4px;
  padding: 2px;
  cursor: pointer;
}

.color-input-wrap input[type="text"] {
  width: 80px;
  padding: 4px 6px;
  border: 1px solid var(--gray-mid);
  border-radius: 4px;
}

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

.color-swatch {
  aspect-ratio: 1;
  border-radius: 6px;
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
}

.color-swatch:hover {
  border-color: var(--dark);
  transform: scale(1.1);
}

.gradient-grid, .pattern-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.gradient-item, .pattern-item {
  aspect-ratio: 1;
  border-radius: var(--radius);
  cursor: pointer;
  border: 2px solid transparent;
  transition: border-color 0.15s, transform 0.15s;
}

.gradient-item:hover, .pattern-item:hover {
  border-color: var(--coral);
  transform: scale(1.05);
}

/* ===== UPLOAD BUTTON ===== */
.upload-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 14px;
  border: 2px dashed var(--gray-mid);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  color: var(--dark);
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 8px;
}

.upload-btn:hover {
  border-color: var(--coral);
  background: rgba(231,26,101,0.03);
}

/* ===== TEMPLATES GRID ===== */
.templates-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.template-card {
  border: 2px solid var(--gray-mid);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}

.template-card:hover {
  border-color: var(--coral);
  transform: translateY(-2px);
}

.template-card img {
  width: 100%;
  aspect-ratio: 2/3;
  object-fit: cover;
  display: block;
}

.template-card .template-name {
  padding: 4px 6px;
  font-size: 11px;
  text-align: center;
  background: var(--gray-light);
}

.template-card--blank {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  aspect-ratio: 2/3;
  color: var(--gray-text);
  font-size: 12px;
  gap: 4px;
}

.template-card--blank svg { width: 32px; height: 32px; }

/* ===== CANVAS AREA ===== */
.canvas-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e8e8e8;
  background-image:
    linear-gradient(45deg, #d0d0d0 25%, transparent 25%),
    linear-gradient(-45deg, #d0d0d0 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d0d0d0 75%),
    linear-gradient(-45deg, transparent 75%, #d0d0d0 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  overflow: hidden;
  position: relative;
}

.canvas-wrapper {
  position: relative;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

/* ===== RIGHT PROPERTIES PANEL ===== */
.properties {
  width: var(--props-w);
  background: var(--white);
  border-left: 1px solid var(--gray-mid);
  overflow-y: auto;
  flex-shrink: 0;
}

.prop-section {
  padding: 12px;
  border-bottom: 1px solid var(--gray-mid);
}

.prop-section h3 {
  font-family: 'Nunito', sans-serif;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--gray-text);
  margin-bottom: 8px;
}

.prop-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.prop-row label { font-size: 12px; color: var(--gray-text); width: 55px; flex-shrink: 0; }
.prop-row input, .prop-row select { flex: 1; padding: 4px 6px; border: 1px solid var(--gray-mid); border-radius: 4px; min-width: 0; }
.prop-row input[type="number"] { width: 60px; flex: none; }
.prop-row input[type="range"] { flex: 1; }

/* Layer list */
.layer-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 8px;
  border-radius: 4px;
  font-size: 12px;
  cursor: pointer;
  transition: background 0.15s;
  border-top: 2px solid transparent;
  border-bottom: 2px solid transparent;
}

.layer-item:hover { background: var(--gray-light); }
.layer-item.selected { background: var(--cream); }
.layer-item .layer-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }

.layer-drag-handle {
  cursor: grab;
  color: var(--gray-text);
  font-size: 14px;
  line-height: 1;
  flex-shrink: 0;
  user-select: none;
}
.layer-drag-handle:active { cursor: grabbing; }

.layer-item.dragging { opacity: 0.4; }
.layer-item.drag-over-top { border-top-color: var(--coral); }
.layer-item.drag-over-bottom { border-bottom-color: var(--coral); }

.no-selection {
  padding: 20px 12px;
  text-align: center;
  color: var(--gray-text);
  font-size: 13px;
}

/* ===== BOTTOM BAR ===== */
.bottombar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--bottombar-h);
  padding: 0 16px;
  background: var(--white);
  border-top: 1px solid var(--gray-mid);
  z-index: 100;
}

.bottombar-left, .bottombar-center, .bottombar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Bottom bar buttons */
.bb-btn {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, color 0.15s;
}

.bb-btn--ghost { color: var(--dark); }
.bb-btn--ghost:hover { background: var(--gray-light); }

.bb-btn--outline { border: 1px solid var(--gray-mid); color: var(--dark); }
.bb-btn--outline:hover { border-color: var(--coral); color: var(--coral); }

.bb-btn--primary { background: var(--coral); color: var(--white); }
.bb-btn--primary:hover { background: var(--coral-dark); }
.bb-btn--primary:disabled { background: var(--gray-mid); color: var(--gray-text); cursor: not-allowed; }

.zoom-display { font-size: 12px; color: var(--gray-text); min-width: 40px; text-align: center; }

/* ===== MODAL / OVERLAY ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.visible { opacity: 1; pointer-events: all; }

.modal {
  background: var(--white);
  border-radius: 12px;
  padding: 32px;
  max-width: 440px;
  width: 90%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}

.modal h2 { font-family: 'Nunito', sans-serif; font-size: 20px; margin-bottom: 12px; }
.modal p { font-size: 14px; color: var(--gray-text); margin-bottom: 20px; line-height: 1.5; }
.modal-actions { display: flex; gap: 12px; justify-content: center; }

/* ===== SPINNER ===== */
.spinner {
  display: inline-block;
  width: 18px;
  height: 18px;
  border: 2px solid var(--gray-mid);
  border-top-color: var(--coral);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== ERROR / LOADING PAGES ===== */
.error-page, .loading-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  text-align: center;
  padding: 24px;
}

.error-page h1 { font-family: 'Nunito', sans-serif; font-size: 24px; margin-bottom: 12px; }
.error-page p { color: var(--gray-text); max-width: 400px; line-height: 1.5; }
.loading-page { gap: 16px; }
.loading-page p { color: var(--gray-text); font-size: 14px; }

/* ===== RESPONSIVE ===== */
@media (max-width: 1100px) {
  :root {
    --sidebar-panel-w: 220px;
    --props-w: 180px;
  }
}

@media (max-width: 900px) {
  :root {
    --sidebar-panel-w: 200px;
    --props-w: 0px;
  }
  .properties { display: none; }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .topbar-client { display: none; }
  .bb-btn { font-size: 12px; padding: 5px 10px; }
}
