/* =====================================================================
   K2 GRÁFICA DIGITAL — Editor visual (Canva-style)
   ===================================================================== */

:root {
  --k2-deep:   #0B3B5C;
  --k2-accent: #019FCE;
  --k2-mist:   #F4F1EC;
  --k2-ink:    #0E1116;
  --k2-moss:   #019FCE;
  --k2-gold:   #D7A86E;
  --line:      rgba(14,17,22,.08);
  --line-2:    rgba(14,17,22,.14);
  --bg-app:    #fafafa;
  --bg-canvas: #e9eaed;
  --topbar-h:  60px;
  --bottom-h:  40px;
  --rail-w:    72px;
  --panel-w:   260px;
  --right-w:   280px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  color: var(--k2-ink);
  background: var(--bg-app);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; font: inherit; }

/* ====== APP SHELL ====================================================== */
.editor {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr var(--bottom-h);
  height: 100vh;
}

/* ====== TOPBAR ========================================================= */
.ed-topbar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 16px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  z-index: 30;
}
.ed-topbar__left  {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 12px;
  min-width: 0;
  overflow: hidden;
}
.ed-topbar__center{ display: flex; align-items: center; flex-wrap: nowrap; gap: 6px; }
.ed-topbar__right { display: flex; align-items: center; flex-wrap: nowrap; gap: 8px; justify-self: end; }

.ed-back {
  width: 36px; height: 36px;
  flex: 0 0 36px;          /* nunca se encoge ni se envuelve debajo */
  display: grid; place-items: center;
  border-radius: 8px;
  color: var(--k2-ink);
  transition: background .2s;
  text-decoration: none;
}
.ed-back:hover { background: var(--bg-canvas); color: var(--k2-accent); }

.ed-brand {
  height: 40px;
  flex: 0 0 auto;          /* ocupa solo lo que necesita el logo */
  display: inline-flex;
  align-items: center;
  padding: 4px 6px;
  border-radius: 8px;
  color: var(--k2-ink);
  text-decoration: none;
  transition: background .2s;
}
.ed-brand:hover { background: var(--bg-canvas); }
.ed-brand img {
  height: 28px;            /* el ancho se calcula según el aspecto real */
  width: auto;
  max-width: 110px;        /* tope por si el logo cambia */
  object-fit: contain;
  display: block;
}

.ed-project {
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-left: 1px solid var(--line);
  padding-left: 12px;
  line-height: 1.15;
  min-width: 0;
  flex: 1 1 auto;          /* ocupa el espacio restante y permite truncar */
  overflow: hidden;
}
.ed-project__label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .15em;
  color: rgba(14,17,22,.5);
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ed-project__label > span { flex: 0 0 auto; }
.ed-project__label-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 0 1 auto;
}
.ed-project__chip {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #019FCE15;
  color: #019FCE;
  font-weight: 700;
  font-size: 10px;
  white-space: nowrap;
}
.ed-project__name {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 700;
  font-size: 14px;
  outline: none;
  margin-top: 2px;
  padding: 2px 6px;
  border-radius: 4px;
  display: block;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ed-project__name:hover    { background: var(--bg-canvas); }
.ed-project__name:focus    { background: var(--bg-canvas); box-shadow: inset 0 0 0 1px var(--k2-accent); }

/* ====== BOTONES TOPBAR ================================================ */
.ed-btn, .ed-btn-ico {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--line-2);
  background: #fff;
  color: var(--k2-ink);
  font-size: 13px;
  font-weight: 600;
  transition: background .15s, border-color .15s, transform .1s;
}
.ed-btn:hover, .ed-btn-ico:hover { background: var(--bg-canvas); border-color: var(--k2-ink); }
.ed-btn:active { transform: translateY(1px); }

.ed-btn-ico {
  width: 36px; height: 36px;
  padding: 0; justify-content: center;
  color: var(--k2-ink);
}
.ed-btn-ico:disabled { opacity: .35; cursor: not-allowed; }

.ed-btn--primary {
  background: var(--k2-ink);
  color: #fff;
  border-color: var(--k2-ink);
}
.ed-btn--primary:hover { background: var(--k2-accent); border-color: var(--k2-accent); }

.ed-divider {
  width: 1px; height: 22px;
  background: var(--line);
  margin: 0 4px;
}

/* ====== BODY GRID ====================================================== */
.ed-body {
  display: grid;
  grid-template-columns: calc(var(--rail-w) + var(--panel-w)) 1fr var(--right-w);
  min-height: 0;
}

/* ====== LEFT SIDEBAR ================================================== */
.ed-left {
  display: grid;
  grid-template-columns: var(--rail-w) var(--panel-w);
  border-right: 1px solid var(--line);
  background: #fff;
  min-height: 0;
}
.ed-rail {
  background: #f5f6f8;
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  padding: 8px 0;
  gap: 2px;
}
.ed-rail__btn {
  background: none;
  border: 0;
  padding: 12px 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  color: rgba(14,17,22,.65);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: .02em;
  position: relative;
  border-radius: 0;
  transition: color .15s, background .15s;
}
.ed-rail__btn:hover { color: var(--k2-ink); background: #fff; }
.ed-rail__btn.is-active {
  color: var(--k2-accent);
  background: #fff;
}
.ed-rail__btn.is-active::before {
  content: '';
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  border-radius: 2px;
  background: var(--k2-accent);
}

.ed-panels { position: relative; overflow: hidden; }
.ed-panel {
  position: absolute; inset: 0;
  padding: 18px 16px;
  overflow-y: auto;
  display: none;
}
.ed-panel.is-active { display: block; }
.ed-panel__title {
  margin: 0 0 14px;
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: rgba(14,17,22,.8);
}
.ed-hint {
  margin-top: 12px;
  font-size: 11px;
  color: rgba(14,17,22,.55);
  line-height: 1.5;
}

/* ===== Templates grid ===== */
.ed-tpl-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.ed-tpl-card {
  position: relative;
  background: #fff;
  border: 1.5px solid var(--line-2);
  border-radius: 10px;
  overflow: hidden;
  aspect-ratio: 1 / 1.2;
  cursor: pointer;
  transition: border-color .2s, transform .2s, box-shadow .2s;
}
.ed-tpl-card:hover {
  border-color: var(--k2-accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px -4px rgba(11,59,92,.15);
}
.ed-tpl-card.is-active {
  border-color: var(--k2-accent);
  border-width: 2.5px;
}
.ed-tpl-card svg { width: 100%; height: 100%; display: block; }
.ed-tpl-card__name {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  padding: 6px 8px;
  background: linear-gradient(0deg, rgba(255,255,255,.95), transparent);
  font-size: 11px;
  font-weight: 700;
  color: var(--k2-ink);
}

/* ===== Text presets ===== */
.ed-add-text {
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1.5px solid var(--line-2);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 10px;
  transition: border-color .15s, background .15s;
}
.ed-add-text:hover { border-color: var(--k2-accent); background: #fffbf8; }
.ed-add-text .t-1 { font-family: 'Plus Jakarta Sans'; font-weight: 900; font-size: 22px; line-height: 1.1; }
.ed-add-text .t-2 { font-family: 'Plus Jakarta Sans'; font-weight: 700; font-size: 15px; }
.ed-add-text .t-3 { font-family: 'Inter'; font-size: 13px; color: rgba(14,17,22,.7); }
.ed-add-text span {
  display: block;
  margin-top: 6px;
  font-size: 11px;
  color: rgba(14,17,22,.5);
}

/* ===== Shapes ===== */
.ed-shape-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}
.ed-shape-grid button {
  background: #fff;
  border: 1.5px solid var(--line-2);
  border-radius: 10px;
  padding: 14px 6px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  font-size: 10px; font-weight: 600;
  color: rgba(14,17,22,.7);
  transition: border-color .15s, color .15s;
}
.ed-shape-grid button:hover { border-color: var(--k2-accent); color: var(--k2-ink); }
.sh {
  width: 36px; height: 36px;
  display: grid; place-items: center;
}
.sh-rect   { background: var(--k2-ink); border-radius: 4px; }
.sh-circle { background: var(--k2-ink); border-radius: 50%; }
.sh-tri    { width: 0; height: 0;
             border-left: 18px solid transparent;
             border-right: 18px solid transparent;
             border-bottom: 32px solid var(--k2-ink); }
.sh-line   { background: var(--k2-ink); height: 3px; border-radius: 2px; }
.sh-star, .sh-arrow {
  font-size: 30px; color: var(--k2-ink);
  line-height: 1;
}

/* ===== Palettes ===== */
.ed-pal-grid { display: grid; gap: 8px; }
.ed-pal-card {
  background: #fff;
  border: 1.5px solid var(--line-2);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex; align-items: center; gap: 10px;
  transition: border-color .15s;
}
.ed-pal-card:hover { border-color: var(--k2-accent); }
.ed-pal-card.is-active { border-color: var(--k2-accent); border-width: 2.5px; }
.ed-pal-card .swatches { display: flex; gap: 4px; }
.ed-pal-card .swatches span {
  width: 18px; height: 18px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.06);
}
.ed-pal-card .name {
  font-size: 13px;
  font-weight: 600;
}

/* ===== Upload ===== */
.ed-upload {
  display: flex; flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 24px 16px;
  border: 2px dashed var(--line-2);
  border-radius: 12px;
  cursor: pointer;
  background: #fff;
  transition: border-color .15s, background .15s;
  color: var(--k2-ink);
  text-align: center;
}
.ed-upload:hover { border-color: var(--k2-accent); background: #fffbf8; }
.ed-upload span { font-weight: 700; font-size: 13px; }
.ed-upload small { font-size: 11px; color: rgba(14,17,22,.55); }

/* ===== Layers ===== */
.ed-layers { display: flex; flex-direction: column; gap: 4px; }
.ed-layer {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: background .15s, border-color .15s;
  font-size: 12px;
}
.ed-layer:hover { background: #fffbf8; }
.ed-layer.is-active { border-color: var(--k2-accent); background: #fffbf8; }
.ed-layer__ico { font-size: 14px; opacity: .7; }
.ed-layer__name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ed-layer__vis  { opacity: .5; background: none; border: 0; padding: 2px; }
.ed-layer__vis:hover { opacity: 1; }

/* ====== STAGE / CANVAS ================================================ */
.ed-stage {
  background: var(--bg-canvas);
  position: relative;
  min-width: 0; min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background-image:
    radial-gradient(rgba(14,17,22,.04) 1px, transparent 1px);
  background-size: 24px 24px;
}
.ed-canvas-wrap {
  position: relative;
  box-shadow: 0 30px 80px -20px rgba(11,59,92,.35),
              0 2px 6px rgba(0,0,0,.08);
  background: #fff;
  transition: transform .2s ease-out;
  transform-origin: center center;
}
.ed-canvas-wrap canvas { display: block; }

/* ====== MINI TOOLBAR ================================================== */
.ed-mini-toolbar {
  position: absolute;
  display: none;
  align-items: center;
  gap: 4px;
  padding: 6px;
  background: var(--k2-ink);
  color: #fff;
  border-radius: 10px;
  box-shadow: 0 12px 28px -6px rgba(0,0,0,.4);
  z-index: 20;
  transition: opacity .15s;
}
.ed-mini-toolbar.is-visible { display: flex; }
.ed-mini-toolbar button {
  background: none;
  border: 0;
  color: rgba(255,255,255,.85);
  padding: 6px 8px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  min-width: 26px;
  transition: background .12s, color .12s;
}
.ed-mini-toolbar button:hover  { background: rgba(255,255,255,.12); color: #fff; }
.ed-mini-toolbar button.is-on  { background: var(--k2-accent); color: #fff; }
.ed-mini-toolbar .ed-divider   { width: 1px; height: 18px; background: rgba(255,255,255,.18); }
.ed-mini-toolbar::after {
  content: '';
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%) rotate(45deg);
  width: 10px; height: 10px;
  background: var(--k2-ink);
  border-radius: 2px;
}

/* ====== RIGHT PANEL (properties) ====================================== */
.ed-right {
  background: #fff;
  border-left: 1px solid var(--line);
  overflow-y: auto;
  min-height: 0;
}
.ed-empty {
  padding: 40px 24px;
  text-align: center;
  color: rgba(14,17,22,.6);
}
.ed-empty__ico { font-size: 36px; }
.ed-empty h4 {
  margin: 12px 0 6px;
  font-size: 14px;
  color: var(--k2-ink);
}
.ed-empty p { font-size: 12px; line-height: 1.5; margin: 0; }

.ed-props { padding: 16px; }
.ed-props__title {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: rgba(14,17,22,.8);
  margin: 0 0 14px;
  display: flex; align-items: center; gap: 8px;
}
.ed-props__group {
  background: #f7f8fa;
  border-radius: 10px;
  padding: 12px;
  margin-bottom: 10px;
}
.ed-props__group h5 {
  margin: 0 0 10px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: rgba(14,17,22,.55);
}
.ed-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ed-row:last-child { margin-bottom: 0; }
.ed-row label {
  font-size: 11px;
  font-weight: 600;
  color: rgba(14,17,22,.7);
  min-width: 56px;
}
.ed-row select, .ed-row input[type=number], .ed-row input[type=text] {
  flex: 1;
  background: #fff;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  outline: none;
  transition: border-color .15s;
  min-width: 0;
}
.ed-row select:focus, .ed-row input:focus { border-color: var(--k2-accent); }
.ed-row input[type=color] {
  width: 36px; height: 28px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  padding: 0;
  background: #fff;
  cursor: pointer;
}
.ed-row input[type=range] { flex: 1; }

.ed-btn-block {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--line-2);
  background: #fff;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  text-align: center;
  margin-top: 6px;
  transition: border-color .15s, background .15s;
}
.ed-btn-block:hover { border-color: var(--k2-accent); }
.ed-btn-block.danger { color: #c43a1f; }
.ed-btn-block.danger:hover { border-color: #c43a1f; background: #fff5f2; }

.ed-btn-group { display: flex; gap: 4px; }
.ed-btn-group button {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--line-2);
  background: #fff;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  color: rgba(14,17,22,.7);
}
.ed-btn-group button:hover { border-color: var(--k2-accent); color: var(--k2-ink); }
.ed-btn-group button.is-on { background: var(--k2-ink); color: #fff; border-color: var(--k2-ink); }

/* Swatches inline para fondo */
.swatch-row { display: flex; flex-wrap: wrap; gap: 6px; }
.swatch {
  width: 24px; height: 24px;
  border-radius: 6px;
  border: 1.5px solid rgba(0,0,0,.06);
  cursor: pointer;
  transition: transform .12s, border-color .15s;
}
.swatch:hover { transform: scale(1.1); }
.swatch.is-on { border-color: var(--k2-ink); border-width: 2.5px; }

/* ====== BOTTOM BAR ==================================================== */
.ed-bottombar {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 16px;
  background: #fff;
  border-top: 1px solid var(--line);
  font-size: 12px;
  color: rgba(14,17,22,.65);
}
.ed-zoom {
  display: flex; align-items: center; gap: 6px;
  justify-self: start;
}
.ed-zoom button {
  width: 26px; height: 26px;
  border: 1px solid var(--line-2);
  background: #fff;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  display: grid; place-items: center;
}
.ed-zoom button:hover { border-color: var(--k2-accent); color: var(--k2-accent); }
#zoomLabel { min-width: 50px; text-align: center; font-weight: 600; color: var(--k2-ink); }
.ed-btn-text {
  width: auto !important;
  padding: 0 10px !important;
  font-size: 12px !important;
  background: none !important;
}
.ed-status { justify-self: center; opacity: .65; }
.ed-canvas-info { justify-self: end; }

/* ====== SCROLLBARS ==================================================== */
.ed-panel::-webkit-scrollbar,
.ed-right::-webkit-scrollbar { width: 8px; }
.ed-panel::-webkit-scrollbar-thumb,
.ed-right::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 4px; }
.ed-panel::-webkit-scrollbar-thumb:hover,
.ed-right::-webkit-scrollbar-thumb:hover { background: rgba(0,0,0,.3); }

/* ====== TOAST ========================================================= */
.ed-toast {
  position: fixed;
  bottom: 60px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--k2-ink);
  color: #fff;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transition: opacity .25s, transform .25s;
  z-index: 100;
  pointer-events: none;
  box-shadow: 0 12px 32px -8px rgba(0,0,0,.4);
}
.ed-toast.is-visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ====== RESPONSIVE (estrechar paneles en pantallas chicas) ============ */
@media (max-width: 1100px) {
  :root { --panel-w: 220px; --right-w: 240px; }
  .ed-project__chip { display: none; }      /* deja respirar al nombre */
}
@media (max-width: 900px) {
  .ed-rail__btn span { display: none; }
  :root { --rail-w: 52px; }
  .ed-back { display: none; }               /* mantiene logo + nombre lado a lado */
  .ed-project__label-text { display: none; }
  .ed-project { padding-left: 8px; }
}
