/* ══ Templates panel — tabs + Configs pane (2026-05-28) ══ */

/* Tab strip — mirrors .pos-tabs visually so the editor reads consistently. */
.tpl-tabs {
  display: flex; gap: 4px;
  background: #0c1018; border: 1px solid #1f2733; border-radius: 8px;
  padding: 3px; margin: 4px 0 10px;
}
.tpl-tab {
  flex: 1; background: transparent; border: 0; cursor: pointer;
  color: #8b97a9; font-size: 12px; font-weight: 600;
  padding: 7px 10px; border-radius: 6px;
  transition: background .12s, color .12s;
}
.tpl-tab:hover { color: #cdd6e4; }
.tpl-tab.is-active { background: #1f293a; color: #fff; }

.tpl-pane { display: none; }
.tpl-pane.is-active { display: block; }

/* Configs pane: header (client picker + Blank) + vertical list of rows. */
.tpl-configs-head {
  display: flex; align-items: center; gap: 6px; margin-bottom: 8px;
}
.tpl-configs-head .cfg-client-select { flex: 1; margin: 0; }

/* Custom client-picker button — looks like a select, opens an in-list picker
   showing each client as a card (templates-rail style). */
.tpl-cfg-picker-btn {
  flex: 1; text-align: left;
  background: #0c1018; color: #e8edf6;
  border: 1px solid #2a3242; border-radius: 8px;
  padding: 9px 28px 9px 12px; font-size: 13px;
  cursor: pointer; position: relative;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tpl-cfg-picker-btn:hover { border-color: #364152; }
.tpl-cfg-picker-btn.is-active { border-color: #2563eb; color: #fff; }
.tpl-cfg-picker-btn::after {
  content: ''; position: absolute; right: 12px; top: 50%;
  width: 0; height: 0; margin-top: -2px;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid #8b97a9;
}

/* "Back" link shown at the top of picker / filtered modes. */
.tpl-cfg-back {
  font-size: 12px; color: #8b97a9; padding: 4px 2px; cursor: pointer;
  margin-bottom: 6px;
}
.tpl-cfg-back:hover { color: #cdd6e4; }

/* Blank-flow client picker modal */
.blank-pick-modal {
  position: fixed; inset: 0; z-index: 9100;
  display: none; align-items: center; justify-content: center;
  background: rgba(8, 12, 22, .62);
}
.blank-pick-modal.open { display: flex; }
.blank-pick-modal-inner {
  width: min(440px, 92vw); max-height: 80vh;
  display: flex; flex-direction: column;
  background: #11151f; color: #e8edf6;
  border: 1px solid #2a3242; border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .55); overflow: hidden;
}
.blank-pick-modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid #232c3b;
  font-weight: 700; font-size: 14px;
}
.blank-pick-modal-head .cg-modal-close {
  background: none; border: 0; color: #9aa6b8; font-size: 18px; cursor: pointer; line-height: 1;
}
.blank-pick-modal-head .cg-modal-close:hover { color: #fff; }
.blank-pick-modal-body { padding: 12px 14px; overflow-y: auto; flex: 1; }
.blank-pick-modal-body .tpl-client-card { margin-bottom: 6px; }

/* "+ New" flow — Step 1 grid of starting points (Blank + T1-T10). */
.tpl-new-card {
  display: flex; align-items: center; gap: 10px;
  background: #161c28; border: 1px solid #28313f; border-radius: 8px;
  padding: 8px; margin-bottom: 6px; cursor: pointer; width: 100%;
  color: #e8edf6; font: inherit; text-align: left;
  transition: background .12s, border-color .12s;
}
.tpl-new-card:hover { background: #1d2532; border-color: #2563eb; }
.tpl-new-card-thumb {
  width: 56px; height: 56px; flex-shrink: 0;
  border-radius: 6px; object-fit: cover;
  background: #0c1018; border: 1px solid #28313f;
  display: flex; align-items: center; justify-content: center;
}
.tpl-new-card-thumb--blank {
  background: #fff; color: #9ca3af; font-size: 24px; font-weight: 300;
}
.tpl-new-card-name { font-size: 13px; font-weight: 600; color: #e8edf6; }

/* Autosave indicator is owned by the existing #saveStatus element (campaign.js
   setSaveStatus). We no longer add our own. */

/* Grouped-by-client section (mode 'all') and client header (mode 'filtered'). */
.tpl-cfg-group { margin-bottom: 14px; }
.tpl-cfg-group-head {
  display: flex; align-items: center; gap: 8px;
  padding: 4px 2px 6px; margin-bottom: 6px;
  font-size: 12px; font-weight: 700; color: #cdd6e4;
  border-bottom: 1px solid #1f2733;
}
.tpl-cfg-group-logo {
  width: 22px; height: 22px; flex-shrink: 0;
  border-radius: 4px; object-fit: contain;
  background: #cbd5e1; border: 1px solid rgba(255, 255, 255, .08);
}
.tpl-cfg-group-logo--fallback {
  display: flex; align-items: center; justify-content: center;
  font-size: 11px; color: #4b5563; font-weight: 700;
}
.tpl-cfg-group-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl-cfg-group-count {
  font-size: 10px; color: #8b97a9; background: #1f2733;
  padding: 2px 8px; border-radius: 8px; flex-shrink: 0;
}

/* Client cards in the picker (mode 'picker'). */
.tpl-client-card {
  display: flex; align-items: center; gap: 10px;
  background: #161c28; border: 1px solid #28313f; border-radius: 8px;
  padding: 8px; cursor: pointer; margin-bottom: 6px;
  transition: background .12s, border-color .12s;
}
.tpl-client-card:hover { background: #1d2532; border-color: #2563eb; }
.tpl-client-card-logo {
  width: 44px; height: 44px; flex-shrink: 0;
  border-radius: 6px; object-fit: contain;
  background: #cbd5e1; border: 1px solid rgba(255, 255, 255, .08);
}
.tpl-client-card-logo--fallback {
  display: flex; align-items: center; justify-content: center;
  color: #4b5563; font-weight: 700; font-size: 16px;
}
.tpl-client-card-info { min-width: 0; flex: 1; }
.tpl-client-card-name { font-size: 13px; font-weight: 600; color: #e8edf6;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl-client-card-sub { font-size: 11px; color: #8b97a9; margin-top: 2px; }

/* Editable configuration-name field in the Save-config client picker. */
.tpl-cfg-name-field { display: block; margin: 4px 0 12px; }
.tpl-cfg-name-label {
  display: block; font-size: 11px; font-weight: 600; color: #8b97a9;
  text-transform: uppercase; letter-spacing: .04em; margin-bottom: 5px;
}
.tpl-cfg-name-input {
  width: 100%; box-sizing: border-box; background: #11161f; color: #e8edf6;
  border: 1px solid #2a3242; border-radius: 8px; padding: 9px 11px; font-size: 13px;
  outline: none; transition: border-color .15s ease;
}
.tpl-cfg-name-input:focus { border-color: #0170b9; }
.tpl-cfg-name-input::placeholder { color: #5d6b7e; }
/* "Save as global template" modal — wider, with both-format previews. */
.blank-pick-modal-inner.is-wide { width: min(760px, 95vw); }

.stp-previews {
  display: flex; gap: 18px; justify-content: center; align-items: flex-end;
  background: #11161f; border: 1px solid #28313f; border-radius: 10px;
  padding: 16px; margin: 2px 0 12px;
}
.stp-fmt { display: flex; flex-direction: column; align-items: center; gap: 7px; }
.stp-fmt--clickable { cursor: zoom-in; }
.stp-fmt--clickable .stp-box { transition: border-color .12s, box-shadow .12s; }
.stp-fmt--clickable:hover .stp-box { border-color: #0170b9; box-shadow: 0 0 0 1px rgba(1,112,185,.5); }
.stp-label { font-size: 11px; color: #8b97a9; font-weight: 600; letter-spacing: .02em; }
.stp-box { overflow: hidden; border-radius: 8px; background: #0c1018; border: 1px solid #2a3242; }
.stp-box--11 { width: 190px; height: 190px; }
.stp-box--916 { width: 124px; height: 220px; }
.stp-box--empty { display: flex; align-items: center; justify-content: center; color: #475063; font-size: 30px; }
/* !important + box-scoped to beat .ad.f11/.f916's built-in transform:scale(). */
.stp-box--11 .stp-ad-11 { transform: scale(.1759) !important; transform-origin: top left; pointer-events: none; }   /* 190/1080 */
.stp-box--916 .stp-ad-916 { transform: scale(.1148) !important; transform-origin: top left; pointer-events: none; }  /* 124/1080 */

.save-tpl-note { min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.save-tpl-note--row { flex-direction: row; align-items: center; gap: 10px; margin-bottom: 14px; }
.save-tpl-badge {
  display: inline-flex; align-items: center; gap: 5px; flex-shrink: 0;
  background: rgba(1, 112, 185, 0.16); color: #4ea8e0;
  border: 1px solid rgba(1, 112, 185, 0.4); border-radius: 999px;
  padding: 3px 9px; font-size: 11px; font-weight: 700; letter-spacing: .02em;
}
.save-tpl-note-txt { font-size: 12.5px; color: #9aa6b6; line-height: 1.45; }
.save-tpl-note-txt strong { color: #d7deea; font-weight: 600; }
.save-tpl-hint { color: #5d6b7e; }

/* Expand lightbox — ONE format, with a zoom control to inspect detail. */
.stp-lightbox {
  position: fixed; inset: 0; z-index: 13000;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  background: rgba(0,0,0,.82); padding: 24px; gap: 14px;
}
.stp-lb-stage {
  flex: 1; min-height: 0; width: 100%;
  display: flex; align-items: center; justify-content: center;
  overflow: auto;                       /* scroll when zoomed in */
}
.stp-lb-zoomwrap { transform-origin: center center; transition: transform .08s linear; }
.stp-lb-box { overflow: hidden; border-radius: 12px; background: #0c1018; border: 1px solid #2a3242; box-shadow: 0 20px 60px rgba(0,0,0,.5); }
/* Base (zoom 1) sizes — the zoomwrap multiplies on top. */
.stp-lb-box--11 { width: 480px; height: 480px; }
.stp-lb-box--916 { width: 300px; height: 533px; }
/* Override .ad.f11/.f916 built-in scale (2-class + !important). */
.stp-lb-box--11 .stp-ad-lb11 { transform: scale(.4444) !important; transform-origin: top left; pointer-events: none; }  /* 480/1080 */
.stp-lb-box--916 .stp-ad-lb916 { transform: scale(.2778) !important; transform-origin: top left; pointer-events: none; } /* 300/1080 */
.stp-lb-controls {
  display: flex; align-items: center; gap: 12px;
  background: #11151f; border: 1px solid #2a3242; border-radius: 999px;
  padding: 8px 16px; color: #cdd6e4; font-size: 13px;
}
.stp-lb-controls .stp-lb-fmt { font-weight: 700; color: #4ea8e0; }
.stp-lb-controls input[type=range] { width: 180px; accent-color: #0170b9; cursor: pointer; }
.stp-lb-zoomval { min-width: 46px; text-align: right; color: #9aa6b6; font-variant-numeric: tabular-nums; }
.stp-lb-zoombtn {
  width: 28px; height: 28px; border-radius: 6px; border: 1px solid #2a3242;
  background: #1b2230; color: #cdd6e4; font-size: 16px; line-height: 1; cursor: pointer;
}
.stp-lb-zoombtn:hover { background: #232c3c; }
.stp-lightbox-close {
  position: absolute; top: 18px; right: 22px;
  background: rgba(255,255,255,.08); color: #fff; border: none; border-radius: 50%;
  width: 38px; height: 38px; font-size: 18px; cursor: pointer;
}
.stp-lightbox-close:hover { background: rgba(255,255,255,.18); }

/* CUSTOM template hover popup reuses the t1–t10 .tpl-hover-popup chrome
   (header + side-by-side previews); only the previews are LIVE (no static
   image). Match the t1–t10 image sizes exactly (240×240 / 135×240). */
.tpl-hover-popup .thp-imgs--live { align-items: flex-end; }
.tpl-hover-popup .thp-live { display: block; overflow: hidden; border-radius: 6px; background: #000; }
.tpl-hover-popup .thp-live-11 { width: 240px; height: 240px; }
.tpl-hover-popup .thp-live-916 { width: 135px; height: 240px; }
.tpl-hover-popup .thp-live-11 .stp-ad-pop11 { transform: scale(.2222) !important; transform-origin: top left; pointer-events: none; }  /* 240/1080 */
.tpl-hover-popup .thp-live-916 .stp-ad-pop916 { transform: scale(.125) !important; transform-origin: top left; pointer-events: none; }  /* 135/1080 */

.tpl-cfg-name-actions { display: flex; justify-content: flex-end; margin-top: 4px; }
.tpl-cfg-name-save {
  background: #0170b9; color: #fff; border: none; border-radius: 8px;
  padding: 9px 16px; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s ease;
}
.tpl-cfg-name-save:hover { background: #0a86d6; }

.cg-open-btn {
  background: #1b2230; color: #cdd6e4; border: 1px solid #2a3242; border-radius: 8px;
  padding: 7px 12px; font-size: 13px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
}
.cg-open-btn:hover { background: #232c3b; color: #fff; }
.cg-open-btn--compact { padding: 7px 10px; font-size: 12px; flex-shrink: 0; }

/* No inner overflow — the parent .panel already scrolls. An inner scroll
   chops the list at 60vh when there are many clients (see Triferto/Tuwi/
   WastePartners getting cut off in the picker). */
.tpl-configs-list {
  display: flex; flex-direction: column; gap: 6px;
}
.tpl-configs-list .hint { color: #8b97a9; font-size: 12px; padding: 8px 4px; margin: 0; }

.tpl-cfg-row {
  display: flex; align-items: center; gap: 10px;
  background: #161c28; border: 1px solid #28313f; border-radius: 8px;
  padding: 6px; cursor: pointer;
  transition: background .12s, border-color .12s;
}
.tpl-cfg-row:hover { background: #1d2532; border-color: #364152; }
.tpl-cfg-row.is-active { border-color: #2563eb; background: #1f293a; }
.tpl-cfg-row.is-disabled { opacity: .5; cursor: not-allowed; }
.tpl-cfg-row.is-disabled:hover { background: #161c28; border-color: #28313f; }

.tpl-cfg-thumb {
  width: 80px; height: 80px; flex-shrink: 0;
  border-radius: 6px; overflow: hidden;
  background: #0c1018; border: 1px solid #28313f;
}
.tpl-cfg-thumb .cg-ad { transform: scale(.074); transform-origin: top left; }
.tpl-cfg-thumb--empty {
  display: flex; align-items: center; justify-content: center;
  color: #6b7689; font-size: 16px;
}

.tpl-cfg-info { min-width: 0; flex: 1; }
.tpl-cfg-title-row { display: flex; align-items: center; gap: 4px; min-width: 0; }
.tpl-cfg-title { font-size: 13px; font-weight: 600; color: #e8edf6;
  flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl-cfg-rename {
  background: none; border: 0; color: #6b7689; cursor: pointer;
  padding: 0 4px; font-size: 13px; line-height: 1;
  opacity: 0; transition: opacity .12s, color .12s; flex-shrink: 0;
}
.tpl-cfg-row:hover .tpl-cfg-rename { opacity: 1; }
.tpl-cfg-rename:hover { color: #fff; }
.tpl-cfg-del {
  background: none; border: 0; color: #6b7689; cursor: pointer;
  padding: 0 4px; font-size: 13px; line-height: 1;
  opacity: 0; transition: opacity .12s, color .12s; flex-shrink: 0;
}
.tpl-cfg-row:hover .tpl-cfg-del { opacity: 1; }
.tpl-cfg-del:hover { color: #f87171; }

/* Right-click context menu on a config card (Usar / Editar / Renombrar / Borrar) */
.cfg-ctx-menu {
  position: fixed; z-index: 1100; min-width: 150px;
  background: #1b2230; border: 1px solid #2a3242; border-radius: 8px;
  padding: 4px; box-shadow: 0 12px 40px rgba(0,0,0,.5);
}
.cfg-ctx-item {
  display: block; width: 100%; text-align: left;
  background: none; border: 0; color: #cdd6e4; font: inherit; font-size: 13px;
  padding: 8px 12px; border-radius: 6px; cursor: pointer;
}
.cfg-ctx-item:hover { background: #2563eb; color: #fff; }
.cfg-ctx-item.is-danger:hover { background: #b91c1c; color: #fff; }
.tpl-cfg-title-input {
  flex: 1; min-width: 0;
  background: #0c1018; color: #e8edf6;
  border: 1px solid #2563eb; border-radius: 4px;
  padding: 2px 6px; font: inherit; font-size: 13px; font-weight: 600;
  box-sizing: border-box;
}
.tpl-cfg-title-input:focus { outline: none; }
.tpl-cfg-sub { font-size: 11px; color: #8b97a9; margin-top: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ── Client picker reused in the Save-config modal ── */
.cfg-client-select {
  width: 100%;
  background: #0c1018; color: #e8edf6;
  border: 1px solid #2a3242; border-radius: 8px;
  padding: 9px 12px; font-size: 13px;
  margin-top: 4px;
}
.cfg-client-select:focus { outline: none; border-color: #2563eb; }
.cfg-client-select--err { border-color: #ef4444; animation: cfgShake .35s ease; }
@keyframes cfgShake { 0%,100%{transform:translateX(0)} 25%{transform:translateX(-3px)} 75%{transform:translateX(3px)} }

/* ══ Save popover (top-bar) ══
   One trigger → Canva-style popup with three round icon options.
   Icons live as CSS ::before pseudo-elements so existing JS that mutates
   .textContent on #downloadBtn / #saveBtn doesn't strip them. */
.save-pop-wrap { position: relative; display: inline-block; }
.save-pop-caret { margin-left: 2px; opacity: .8; }
.save-pop {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 5000;
  min-width: 320px;
  background: #11151f; color: #e8edf6;
  border: 1px solid #2a3242; border-radius: 12px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  padding: 16px 18px 18px;
}
.save-pop[hidden] { display: none; }
.save-pop-title { font-weight: 700; color: #e8edf6; font-size: 14px; margin-bottom: 14px; }
.save-pop-row { display: flex; gap: 14px; justify-content: space-between; }

.save-pop-item {
  position: relative;
  padding-top: 56px;
  background: transparent; border: 0; color: #cdd6e4;
  cursor: pointer; text-align: center;
  font-size: 12px; font-weight: 500; line-height: 1.25;
  min-width: 92px; max-width: 110px; flex: 1;
  word-break: normal; white-space: normal;
}
.save-pop-item::before {
  content: '';
  position: absolute;
  top: 0; left: 50%;
  transform: translateX(-50%);
  width: 48px; height: 48px;
  border-radius: 50%;
  background-color: #2a3242;
  background-position: center;
  background-repeat: no-repeat;
  background-size: 22px 22px;
  transition: background-color .15s;
}
.save-pop-item:hover::before { background-color: #374152; }
.save-pop-item:disabled, .save-pop-item.is-disabled { opacity: .45; cursor: not-allowed; }
.save-pop-item:disabled:hover::before, .save-pop-item.is-disabled:hover::before { background-color: #2a3242; }

.save-pop-item--download::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 24 24' fill='none' stroke='%23cdd6e4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4'/><polyline points='7 10 12 15 17 10'/><line x1='12' y1='15' x2='12' y2='3'/></svg>");
}
.save-pop-item--airtable::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 24 24' fill='none' stroke='%23cdd6e4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M19 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11l5 5v11a2 2 0 0 1-2 2z'/><polyline points='17 21 17 13 7 13 7 21'/><polyline points='7 3 7 8 15 8'/></svg>");
}
.save-pop-item--config::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 24 24' fill='none' stroke='%23cdd6e4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><path d='M19 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z'/></svg>");
}
/* Template = grid/layout icon (a shared system template). */
.save-pop-item--template::before {
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='22' height='22' viewBox='0 0 24 24' fill='none' stroke='%23cdd6e4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='3' y='3' width='18' height='18' rx='2'/><line x1='3' y1='9' x2='21' y2='9'/><line x1='9' y1='21' x2='9' y2='9'/></svg>");
}
