:root {
  --verde: #128c7e;
  --verde-oscuro: #075e54;
  --rojo: #d9534f;
  --fondo: #f0f2f5;
  --panel: #ffffff;
  --borde: #dde1e6;
  --texto: #24303c;
  --texto-suave: #66757f;
  --sombra: 0 1px 3px rgba(0, 0, 0, .08), 0 4px 14px rgba(0, 0, 0, .05);
  --radio: 12px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
  background: var(--fondo);
  color: var(--texto);
}

button { font: inherit; cursor: pointer; }

.cinta-demo {
  position: sticky;
  top: 0;
  z-index: 45;
  background: #b7791f;
  color: #fff;
  text-align: center;
  padding: 7px 14px;
  font-size: .8rem;
  font-weight: 600;
}

.topbar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 28px;
  background: linear-gradient(135deg, var(--verde-oscuro), var(--verde));
  color: #fff;
  box-shadow: var(--sombra);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}
.topbar__brand:hover h1 { text-decoration: underline; text-decoration-color: rgba(255,255,255,.5); text-underline-offset: 3px; }

.topbar__logo {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .15);
}

.topbar h1 { margin: 0; font-size: 1.05rem; font-weight: 600; }
.topbar p { margin: 2px 0 0; font-size: .78rem; opacity: .85; }

.topbar__right { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }

.nav {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  display: flex;
  gap: 6px;
}
.nav a {
  color: #fff;
  text-decoration: none;
  padding: 7px 15px;
  border-radius: 999px;
  font-size: .85rem;
  font-weight: 600;
  opacity: .8;
  transition: background .15s, opacity .15s;
}
.nav a i { margin-right: 7px; font-size: .82rem; }
.nav a:hover { opacity: 1; background: rgba(255, 255, 255, .12); }
.nav a.activo {
  background: #fff;
  color: var(--verde-oscuro);
  opacity: 1;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .15);
}

.hamburger {
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  width: 42px;
  height: 38px;
  border: none;
  border-radius: 9px;
  background: rgba(255, 255, 255, .15);
  cursor: pointer;
}
.hamburger span {
  width: 18px;
  height: 2px;
  border-radius: 2px;
  background: #fff;
  transition: transform .2s, opacity .2s;
}
.hamburger.abierto span:nth-child(1) { transform: translateY(6px) rotate(45deg); }
.hamburger.abierto span:nth-child(2) { opacity: 0; }
.hamburger.abierto span:nth-child(3) { transform: translateY(-6px) rotate(-45deg); }

@media (max-width: 760px) {
  .topbar { padding: 10px 14px; }
  .topbar p { display: none; }
  .topbar h1 { font-size: .95rem; }
  .badge--bd, select.badge--select { font-size: .68rem; padding: 4px 9px; }

  .hamburger { display: flex; }

  .nav {
    display: none;
    left: auto;
    right: 12px;
    top: calc(100% + 8px);
    bottom: auto;
    transform: none;
    flex-direction: column;
    gap: 3px;
    min-width: 210px;
    background: #fff;
    border-radius: 14px;
    padding: 8px;
    box-shadow: 0 14px 40px rgba(0, 0, 0, .22);
  }
  .nav.abierto { display: flex; }
  .nav a {
    color: var(--texto);
    opacity: 1;
    padding: 11px 14px;
    border-radius: 9px;
    font-size: .92rem;
  }
  .nav a:hover { background: #f2f7f6; }
  .nav a.activo { background: #e7f3f1; color: var(--verde-oscuro); }
}

.badge {
  padding: 5px 12px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 600;
}

select.badge--select {
  appearance: none;
  -webkit-appearance: none;
  border: none;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  background: var(--verde-oscuro);
  color: #fff;
  padding-right: 26px;
}
.badge--bd {
  background: rgba(255, 255, 255, .18);
  color: #fff;
  font-weight: 600;
  font-size: .72rem;
}

.layout {
  display: grid;
  grid-template-columns: 340px 1fr;
  gap: 20px;
  max-width: 1100px;
  margin: 24px auto;
  padding: 0 20px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--borde);
  border-radius: var(--radio);
  box-shadow: var(--sombra);
}

.panel--list { position: sticky; top: 20px; max-height: calc(100vh - 44px); display: flex; flex-direction: column; }

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--borde);
}

.panel__head h2 { margin: 0; font-size: 1rem; }
.panel__actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }

.tpl-list__aviso-sync { margin: 10px 18px 0; }

.searchbox {
  margin: 12px 14px 6px;
  padding: 8px 12px;
  border: 1px solid var(--borde);
  border-radius: 999px;
  background: #fafbfc;
}
.searchbox input {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  font: inherit;
  font-size: .9rem;
  color: var(--texto);
}
.searchbox:focus-within { border-color: var(--verde); }

.tpl-list {
  list-style: none;
  margin: 0;
  padding: 8px;
  overflow-y: auto;
}

.tpl-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: none;
  border-radius: 10px;
  padding: 10px 12px;
  transition: background .15s;
}
.tpl-item:hover { background: #f2f7f6; }
.tpl-item--activa { background: #e7f3f1; border-color: var(--verde); }
.tpl-item__nombre { display: block; font-weight: 600; font-size: .92rem; }
.tpl-item__vista { display: block; margin-top: 3px; color: var(--texto-suave); font-size: .8rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpl-list__vacio { padding: 22px 14px; text-align: center; color: var(--texto-suave); font-size: .88rem; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: none;
  border-radius: 9px;
  padding: 9px 15px;
  font-weight: 600;
  font-size: .87rem;
  transition: filter .15s, background .15s;
}
.btn:hover { filter: brightness(1.06); }
.btn--lg { padding: 12px 22px; font-size: .95rem; }
.btn--primary { background: var(--verde); color: #fff; }
.btn--ghost { background: transparent; color: var(--texto-suave); border: 1px solid var(--borde); }
.btn--ghost:hover { background: #f4f6f8; }
.btn--danger { background: var(--rojo); color: #fff; }
.btn--danger-ghost { background: transparent; color: var(--rojo); border: 1px solid #eec2c1; }
.btn--danger-ghost:hover { background: #fdf3f3; }

.panel--editor { min-height: 60vh; }
.panel--editor form { padding: 20px 24px 26px; }

.field { margin-bottom: 18px; }
.field label { display: block; margin-bottom: 6px; font-weight: 600; font-size: .9rem; }
.field input[type="text"],
.field textarea,
.field select {
  width: 100%;
  border: 1.5px solid var(--borde);
  border-radius: 10px;
  padding: 11px 13px;
  font: inherit;
  font-size: .93rem;
  color: var(--texto);
  background: #fbfcfd;
  resize: vertical;
}
.field input:focus,
.field textarea:focus,
.field select:focus { border-color: var(--verde); outline: none; }
.field input.invalido, .field textarea.invalido { border-color: var(--rojo); }
.field input:disabled,
.field textarea:disabled,
.field select:disabled {
  background: #eceff2;
  color: var(--texto-suave);
  cursor: not-allowed;
  border-style: dashed;
}

.field__foot {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}
.field__hint { margin: 6px 0 0; font-size: .78rem; color: var(--texto-suave); }
.field__hint.atajos { margin-top: 14px; text-align: center; }
.char-count { font-size: .78rem; color: var(--texto-suave); white-space: nowrap; }
.char-count--limite { color: var(--rojo); font-weight: 700; }

.warn {
  margin: -6px 0 14px;
  padding: 10px 13px;
  border-radius: 8px;
  background: #fdf6e7;
  border: 1px solid #ecd9ac;
  color: #8a6410;
  font-size: .84rem;
}
.warn--nombre { margin: 8px 0 0; }

.preview-wrap { margin-bottom: 22px; }
.preview-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 10px; flex-wrap: wrap; }
.preview-head h3 { margin: 0; font-size: .92rem; }
.preview-note { font-size: .78rem; color: var(--texto-suave); }

.phone {
  background:
    linear-gradient(rgba(7, 94, 84, .06), rgba(7, 94, 84, .06)),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='60' height='60' viewBox='0 0 60 60'%3E%3Cg fill='%23128c7e' fill-opacity='.05'%3E%3Ccircle cx='15' cy='15' r='2'/%3E%3Ccircle cx='45' cy='40' r='2.5'/%3E%3Cpath d='M30 25l4 4M52 10l3 3' stroke='%23128c7e' stroke-opacity='.08'/%3E%3C/g%3E%3C/svg%3E");
  background-color: #ece5dd;
  border: 1px solid var(--borde);
  border-radius: 14px;
  padding: 18px;
  min-height: 120px;
}

.chat { display: flex; flex-direction: column; }

.bubble {
  position: relative;
  align-self: flex-start;
  max-width: 85%;
  background: #dcf8c6;
  border-radius: 10px;
  border-top-left-radius: 2px;
  padding: 10px 34px 12px 12px;
  font-size: .92rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  box-shadow: 0 1px 1px rgba(0, 0, 0, .1);
}
.bubble--vacia { color: #97a3ad; font-style: italic; }
.bubble code {
  background: rgba(0, 0, 0, .06);
  border-radius: 4px;
  padding: 1px 5px;
  font-family: Consolas, "SFMono-Regular", monospace;
  font-size: .88em;
}

.bubble__time {
  position: absolute;
  right: 9px;
  bottom: 5px;
  font-size: .68rem;
  color: #5a7a56;
}
.bubble__time::after {
  content: " ✓✓";
  color: #53bdeb;
  letter-spacing: -2px;
}

.wildcards {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: #f4faf8;
  border: 1px dashed #bcd9d2;
  border-radius: 10px;
}
.wildcards__label { font-size: .82rem; font-weight: 600; color: var(--verde-oscuro); }

.chip {
  border: 1px solid var(--verde);
  color: var(--verde-oscuro);
  background: #fff;
  border-radius: 999px;
  padding: 5px 13px;
  font-family: Consolas, monospace;
  font-size: .82rem;
  transition: all .15s;
}
.chip:hover { background: var(--verde); color: #fff; }

.form-actions { display: flex; gap: 12px; }

.empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  text-align: center;
  padding: 70px 24px;
  color: var(--texto-suave);
}
.empty-state h3 { margin: 0; color: var(--texto); }

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(20, 30, 35, .55);
  z-index: 50;
  padding: 20px;
}
.modal[hidden] { display: none; }

.modal__card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border-radius: 14px;
  padding: 24px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .25);
}
.modal__card h3 { margin: 0 0 20px; }
.modal__actions { display: flex; justify-content: flex-end; gap: 10px; }

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #22343c;
  color: #fff;
  padding: 12px 20px;
  border-radius: 10px;
  font-size: .9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3);
  opacity: 0;
  transition: opacity .25s, transform .25s;
  z-index: 60;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast--error { background: var(--rojo); }
.toast--ok { background: var(--verde-oscuro); }

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255, 255, 255, .4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .panel--list { position: static; max-height: none; }
  .tpl-list { max-height: 260px; }
}