/* ==============================
   RESET & BASE
   ============================== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #22263a;
  --border: #2e3347;
  --accent: #6c63ff;
  --accent2: #a78bfa;
  --text: #e8eaf0;
  --text-muted: #7a7f99;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 10px;
  --radius-sm: 6px;
  --transition: .18s ease;
  --shadow: 0 4px 24px rgba(0,0,0,.45);
}
html, body { height: 100%; font-family: 'Inter', sans-serif; font-size: 14px; background: var(--bg); color: var(--text); }
input, textarea, select, button { font-family: inherit; font-size: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ==============================
   SCROLLBAR
   ============================== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 99px; }

/* ==============================
   LAYOUT
   ============================== */
#app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  flex-shrink: 0;
  z-index: 10;
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; max-width: 100%;
}
.header-brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 1.2rem; font-weight: 700; color: var(--accent2);
}
.header-brand i { color: var(--accent); font-size: 1.3rem; }
.header-actions { display: flex; gap: 10px; align-items: center; }

.app-body {
  display: flex; flex: 1; overflow: hidden;
}

.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 0;
}

.canvas-area {
  flex: 1; display: flex; flex-direction: column;
  background: var(--bg); overflow: hidden;
}

.editor {
  width: 300px; flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}

/* ==============================
   PANELS
   ============================== */
.panel { border-bottom: 1px solid var(--border); }
.panel-header {
  padding: 12px 16px; font-size: .8rem; font-weight: 600;
  text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted);
  display: flex; align-items: center; gap: 8px;
}
.panel-header .badge {
  margin-left: auto; background: var(--accent); color: #fff;
  font-size: .7rem; border-radius: 99px; padding: 1px 7px; font-weight: 600;
}
.panel-body { padding: 0 16px 14px; }

/* ==============================
   TEMPLATES GRID
   ============================== */
.template-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 8px; padding: 8px 16px 14px;
}
.template-thumb {
  background: var(--surface2); border: 2px solid transparent;
  border-radius: var(--radius-sm); cursor: pointer;
  display: flex; flex-direction: column; align-items: center;
  gap: 5px; padding: 10px 6px 8px; transition: var(--transition);
  font-size: .75rem; color: var(--text-muted);
}
.template-thumb:hover { border-color: var(--accent2); color: var(--text); }
.template-thumb.active { border-color: var(--accent); color: var(--accent); }
.thumb-preview { font-size: 1.6rem; color: var(--text-muted); }
.template-thumb.active .thumb-preview { color: var(--accent); }

/* ==============================
   VARIABLES
   ============================== */
.hint { font-size: .75rem; color: var(--text-muted); margin-bottom: 8px; line-height: 1.5; }
.vars-textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); padding: 8px;
  resize: vertical; line-height: 1.6; font-size: .8rem;
}
.vars-textarea::placeholder { color: var(--text-muted); }
.vars-preview { margin-top: 10px; }
.vars-preview label { font-size: .75rem; color: var(--text-muted); }
.var-nav {
  display: flex; align-items: center; gap: 8px; margin-top: 6px;
  font-size: .85rem;
}
.dim-grid { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; }
.dim-grid label { color: var(--text-muted); font-size: .8rem; }

/* ==============================
   CANVAS AREA
   ============================== */
.canvas-toolbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px; border-bottom: 1px solid var(--border);
  background: var(--surface); flex-shrink: 0;
}
.canvas-size-label { font-size: .75rem; color: var(--text-muted); margin-right: auto; }

.canvas-wrapper {
  flex: 1; overflow: auto; display: flex;
  align-items: flex-start; justify-content: center; padding: 24px;
  position: relative;
}
.canvas-wrapper canvas {
  display: block; max-width: 100%;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
  cursor: crosshair;
  background-color:#222222;
}
.canvas-hint {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
  color: var(--text-muted); pointer-events: none;
}

/* ==============================
   EDITOR TABS
   ============================== */
.editor-tabs {
  display: flex; border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.editor-tab {
  flex: 1; padding: 12px 6px; background: transparent; border: none;
  color: var(--text-muted); cursor: pointer; font-size: .8rem;
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: var(--transition); border-bottom: 2px solid transparent;
}
.editor-tab i { font-size: 1rem; }
.editor-tab:hover { color: var(--text); background: var(--surface2); }
.editor-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-content { flex: 1; overflow-y: auto; display: flex; flex-direction: column; }

/* ==============================
   LAYERS
   ============================== */
.layer-list {
  padding: 10px; display: flex; flex-direction: column; gap: 4px;
  border-bottom: 1px solid var(--border);
}
.layer-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  cursor: pointer; transition: var(--transition);
  background: transparent; border: 1px solid transparent;
}
.layer-item:hover { background: var(--surface2); }
.layer-item.active { background: var(--surface2); border-color: var(--accent); }
.layer-icon { color: var(--text-muted); font-size: .9rem; width: 16px; }
.layer-name { flex: 1; font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.layer-del { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.layer-del:hover { color: var(--danger); background: rgba(239,68,68,.12); }

/* ==============================
   PROPERTY PANELS
   ============================== */
.prop-panel { padding: 12px; display: flex; flex-direction: column; gap: 0; flex: 1; overflow-y: auto; }
.prop-section { margin-bottom: 14px; }
.prop-title {
  font-size: .72rem; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-muted); font-weight: 600; margin-bottom: 8px;
}
.coord-grid { display: grid; grid-template-columns: 24px 1fr 24px 1fr; gap: 6px; align-items: center; }
.coord-grid label { color: var(--text-muted); text-align: right; font-size: .8rem; }
.font-controls { display: flex; flex-direction: column; gap: 8px; }
.font-size-row { display: flex; align-items: center; gap: 8px; }
.font-size-row label { color: var(--text-muted); font-size: .8rem; min-width: 40px; }
.style-btns, .align-btns { display: flex; gap: 4px; }
.style-btn, .align-btn {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text-muted); border-radius: var(--radius-sm);
  padding: 5px 10px; cursor: pointer; transition: var(--transition);
}
.style-btn:hover, .align-btn:hover { border-color: var(--accent2); color: var(--text); }
.style-btn.active, .align-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.color-row { display: flex; align-items: center; gap: 10px; }
.color-row label { color: var(--text-muted); font-size: .8rem; min-width: 60px; }
.color-row span { font-size: .8rem; color: var(--text-muted); }
.img-source-btns { display: flex; gap: 8px; flex-direction: column; margin-bottom: 8px; }
.qr-preview-url { margin-top: 6px; padding: 8px; background: var(--surface2); border-radius: var(--radius-sm); }
.qr-preview-url .hint { word-break: break-all; }

/* ==============================
   INPUTS
   ============================== */
.input-sm {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm); padding: 5px 8px;
  width: 100%; transition: var(--transition);
}
.input-sm:focus { border-color: var(--accent); }
.input-url {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm); padding: 6px 8px;
  width: 100%; font-size: .8rem;
}
.input-url:focus { border-color: var(--accent); outline: none; }
.input-textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm); padding: 7px;
  resize: vertical; line-height: 1.6;
}
.input-textarea:focus { border-color: var(--accent); outline: none; }
.input-font {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm); padding: 6px 8px; width: 100%;
}
.input-font:focus { border-color: var(--accent); outline: none; }
.input-select {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm); padding: 6px 8px; width: 100%;
}
.slider { flex: 1; accent-color: var(--accent); }
.color-picker {
  width: 36px; height: 36px; border-radius: 50%; border: 2px solid var(--border);
  padding: 0; cursor: pointer; background: none; overflow: hidden;
}
.toggle-row {
  display: flex; align-items: center; gap: 8px;
  font-size: .82rem; color: var(--text-muted); cursor: pointer; margin-top: 6px;
}
.toggle-row input[type=checkbox] { accent-color: var(--accent); }

/* ==============================
   BUTTONS
   ============================== */
.btn-primary {
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--radius-sm); padding: 8px 16px;
  font-weight: 600; cursor: pointer; display: flex;
  align-items: center; gap: 7px; transition: var(--transition);
  font-size: .85rem;
}
.btn-primary:hover { background: var(--accent2); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; }
.btn-icon {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text-muted); border-radius: var(--radius-sm);
  padding: 7px 12px; cursor: pointer; display: flex;
  align-items: center; gap: 6px; transition: var(--transition); font-size: .82rem;
}
.btn-icon:hover { border-color: var(--accent2); color: var(--text); }
.btn-add {
  background: transparent; border: 1px dashed var(--border);
  color: var(--text-muted); border-radius: var(--radius-sm);
  padding: 7px 10px; cursor: pointer; font-size: .8rem;
  display: flex; align-items: center; gap: 6px; transition: var(--transition);
  width: 100%; margin-top: 4px;
}
.btn-add:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text-muted); border-radius: var(--radius-sm);
  padding: 4px 8px; cursor: pointer; font-size: .78rem; transition: var(--transition);
}
.btn-sm:hover { border-color: var(--accent2); color: var(--text); }
.btn-source {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm); padding: 7px 12px;
  cursor: pointer; display: flex; align-items: center; gap: 6px;
  font-size: .82rem; transition: var(--transition);
}
.btn-source:hover { border-color: var(--accent); color: var(--accent); }

/* ==============================
   TOAST
   ============================== */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); padding: 10px 20px; border-radius: 99px;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 8px;
  font-size: .85rem; z-index: 1000;
}
.toast-fade-enter-active, .toast-fade-leave-active { transition: all .3s ease; }
.toast-fade-enter, .toast-fade-leave-to { opacity: 0; transform: translateX(-50%) translateY(16px); }

/* ==============================
   RESPONSIVE
   ============================== */
@media (max-width: 900px) {
  .sidebar { display: none; }
  .editor { width: 260px; }
}
@media (max-width: 640px) {
  .app-body { flex-direction: column; }
  .editor { width: 100%; height: 45vh; border-left: none; border-top: 1px solid var(--border); }
  .canvas-area { height: 55vh; }
}

/* ==============================
   SLIDERS DE POSITION
   ============================== */
.slider-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}
.slider-row label {
  color: var(--text-muted);
  font-size: .8rem;
  /*width: 14px;*/
  flex-shrink: 0;
  text-align: right;
}
.slider-row .slider { flex: 1; accent-color: var(--accent); }
.input-num {
  width: 64px !important;
  flex-shrink: 0;
  text-align: center;
}

/* ==============================
   CALQUES — DRAG & DROP
   ============================== */
.layer-handle {
  color: var(--text-muted);
  cursor: grab;
  padding: 0 4px;
  font-size: .85rem;
  opacity: .5;
  transition: opacity var(--transition);
}
.layer-item:hover .layer-handle { opacity: 1; }
.layer-handle:active { cursor: grabbing; }

.layer-z {
  font-size: .68rem;
  font-weight: 700;
  color: var(--accent);
  background: rgba(108, 99, 255, .15);
  border-radius: 4px;
  padding: 1px 5px;
  min-width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.layer-move-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px 4px;
  border-radius: 4px;
  font-size: .75rem;
  transition: var(--transition);
  line-height: 1;
}
.layer-move-btn:hover:not(:disabled) {
  color: var(--accent2);
  background: rgba(167, 139, 250, .12);
}
.layer-move-btn:disabled { opacity: .2; cursor: not-allowed; }

/* Feedback visuel pendant le drag */
.layer-dragging {
  opacity: .4;
  border-color: var(--accent) !important;
  background: rgba(108, 99, 255, .08) !important;
}

.layer-drop-zone {
  height: 4px;
  border-radius: 2px;
  margin: 2px 4px;
  background: transparent;
  transition: background var(--transition);
}
.layer-drop-zone.active {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent);
}

/* Indicateur de survol entre calques */
.layer-item.layer-drag-over-before {
  border-top: 2px solid var(--accent);
}
.layer-item.layer-drag-over-after {
  border-bottom: 2px solid var(--accent);
}

/* ==============================
   FONT SELECTOR
   ============================== */
.font-selector-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.font-select {
  width: 100%;
}

/* Aperçu de la police */
.font-preview {
  padding: 10px 12px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1.1rem;
  line-height: 1.5;
  min-height: 44px;
  transition: font-family var(--transition);
  /* Affiche les accents et les caractères spéciaux */
  letter-spacing: 0.02em;
}
