/* Plantillas page. Reuses the cards, editor bar and WhatsApp bubble from automations.css */

.tpl-title { font-size: 18px; font-weight: 600; margin: 0; word-break: break-all; }

/* Cards show the start of the message, faded at the bottom */
.tpl-card-preview {
    font-size: 12px;
    max-height: 200px;
    overflow: hidden;
    position: relative;
}
.tpl-card-preview::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 36px;
    background: linear-gradient(rgba(255, 255, 255, 0), #fff);
}

/* Card chat: bubble + buttons on a WhatsApp-like background */
.tpl-card-chat {
    background: #e7ddd3;
    background-image: radial-gradient(rgba(0, 0, 0, 0.04) 1px, transparent 1px);
    background-size: 12px 12px;
    border-radius: 10px;
    padding: 10px;
}
.tpl-card-chat .wa-bubble { background: #fff; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08); }
.tpl-card-chat .wa-buttons { background: #fff; border-color: transparent; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08); }
.tpl-card-chat .wa-button { padding: 7px 10px; font-size: 12px; }
.tpl-card-chat .wa-media { height: 120px; overflow: hidden; padding: 0; }
.tpl-card-chat .wa-media img,
.tpl-card-chat .wa-media video { width: 100%; height: 100%; object-fit: cover; }
/* With an image/video, crop it like WhatsApp does (wide, about 1.91:1) instead of a fixed height */
.tpl-card-chat .wa-media:has(img, video) { height: auto; aspect-ratio: 1.91 / 1; }

/* Editor: preview on the left, settings on the right */
.tpl-editor {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 400px;
    gap: 16px;
    align-items: start;
}
.tpl-canvas {
    display: flex;
    justify-content: center;
    min-height: 520px;
}
.tpl-phone { width: 340px; }
.tpl-phone-label {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-align: center;
    margin-bottom: 10px;
}
.tpl-message {
    background: #e7ddd3;
    background-image: radial-gradient(rgba(0, 0, 0, 0.04) 1px, transparent 1px);
    background-size: 12px 12px;
    border-radius: 12px;
    padding: 16px 14px;
    box-shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
}
.tpl-message .wa-bubble { background: #fff; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08); }
.tpl-message .wa-buttons { background: #fff; border-color: transparent; box-shadow: 0 1px 1px rgba(0, 0, 0, 0.08); }
.tpl-message .wa-media { height: 150px; overflow: hidden; padding: 0; }
.tpl-message .wa-media img,
.tpl-message .wa-media video { width: 100%; height: 100%; object-fit: cover; }
/* With an image/video, crop it like WhatsApp does (wide, about 1.91:1) instead of a fixed height */
.tpl-message .wa-media:has(img, video) { height: auto; aspect-ratio: 1.91 / 1; }
.tpl-message .wa-media.missing { background: var(--warning-soft); color: var(--warning); font-weight: 600; cursor: pointer; }

/* Variables as chips; the empty ones in red */
.wa-var.var-empty { background: #ef4444; }
.wa-var.clickable { cursor: pointer; }
.wa-var.flash { box-shadow: 0 0 0 3px rgba(29, 155, 240, 0.35); }

/* Settings panel */
.tpl-panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px 18px 18px;
}
.tpl-panel .drawer-section-title:first-child { margin-top: 14px; }
.var-row {
    display: grid;
    grid-template-columns: 52px 1fr;
    gap: 10px;
    align-items: center;
    padding: 8px 10px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    margin-bottom: 8px;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.var-row.focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
.var-row.missing { border-color: #fca5a5; }
.var-key { font-family: ui-monospace, Menlo, monospace; font-size: 12px; font-weight: 700; color: #1d9bf0; }
.var-row select {
    width: 100%;
    height: 34px;
    padding: 0 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 13px;
}
.var-example { grid-column: 2; font-size: 11px; color: var(--text-subtle); margin-top: -4px; }

.tpl-panel .header-media-grid { grid-template-columns: repeat(3, 1fr); }

/* Delete button: red outline, filled on hover */
.btn.tpl-btn-delete { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.tpl-btn-delete:hover { background: var(--danger); border-color: var(--danger); color: #fff; }

/* Delete modal */
.tpl-delete-modal { max-width: 480px; }
.tpl-delete-text { font-size: 14px; line-height: 1.55; color: var(--text-secondary); margin: 0 0 8px; }
.tpl-delete-text strong { color: var(--text); }
.btn.tpl-btn-delete-solid, .btn.tpl-btn-delete-solid:hover { background: var(--danger); border-color: var(--danger); color: #fff; }

/* Add modal */
.tpl-add-modal {
    max-width: 680px;
    max-height: 94vh;
    display: flex;
    flex-direction: column;
}
.add-preview { margin-top: 12px; }

@media (max-width: 1100px) {
    .tpl-editor { grid-template-columns: 1fr; }
}

/* ---------- Ajustar encuadre (crop of the header image to WhatsApp's 1.91:1) ---------- */
.header-media-crop { margin-top: 10px; }
.crop-modal { max-width: 640px; width: 100%; }
.crop-help { margin: 0 0 12px; }
.crop-frame {
    position: relative;
    width: 100%;
    aspect-ratio: 1.91 / 1;
    overflow: hidden;
    border-radius: 8px;
    background: #fff;
    border: 1px solid var(--border);
    cursor: grab;
    touch-action: none;
    user-select: none;
}
.crop-frame.dragging { cursor: grabbing; }
.crop-frame img { position: absolute; top: 0; left: 0; max-width: none; transform-origin: 0 0; pointer-events: none; }
.crop-zoom { display: flex; align-items: center; gap: 10px; margin: 14px 0 6px; font-size: 16px; color: var(--text-muted); }
.crop-zoom input[type="range"] { flex: 1; accent-color: var(--brand); height: auto; padding: 0; border: none; background: none; box-shadow: none; }
.crop-reset { background: none; border: 1px solid var(--border); border-radius: 6px; padding: 4px 10px; font-size: 12px; color: var(--text); cursor: pointer; white-space: nowrap; }
.crop-reset:hover { border-color: var(--brand); color: var(--brand-text); }

