/* ==========================================================================
   GUFO AGENDA - MÓDULO PLANTILLAS DE EMAIL
   ========================================================================== */

.plantillas-header {
    position: relative !important;
    top: auto !important;
    z-index: 50;
    padding: 10px 18px 12px !important;
}

.header-main {
    width: min(1180px, 100%);
    margin: 0 auto;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 14px;
}

.brand {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    min-width: 0;
}

.brand img {
    width: 86px !important;
    max-width: 86px !important;
    height: auto !important;
    display: block !important;
    object-fit: contain !important;
    flex: 0 0 auto;
}

.brand h1 {
    margin: 0 !important;
    line-height: 1.05 !important;
    font-size: clamp(1.25rem, 2.4vw, 2rem) !important;
}

.brand p {
    margin: 4px 0 0 !important;
    line-height: 1.2 !important;
    font-size: .92rem !important;
}

.mini-dashboard {
    width: min(1180px, 100%);
    margin: 10px auto 0 !important;
}

.main-nav {
    width: min(1180px, 100%);
    margin: 12px auto 0 !important;
    padding-top: 4px !important;
}

.main-nav a {
    min-height: 42px !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    line-height: 1.1 !important;
}

.main-nav a.active {
    transform: none !important;
}

.main-content.page-plantillas {
    padding-top: 18px !important;
}

.panel {
    width: min(1180px, calc(100% - 28px));
    margin: 22px auto;
    background: rgba(8, 24, 48, 0.88);
    border: 1px solid rgba(105, 180, 255, 0.20);
    border-radius: 22px;
    padding: 22px;
    box-shadow: 0 18px 45px rgba(0,0,0,.25);
    backdrop-filter: blur(12px);
}

.section-title {
    margin-bottom: 18px;
}

.section-title h2 {
    margin: 0 0 6px;
    color: #ffffff;
    font-size: 1.35rem;
}

.section-title p {
    margin: 0;
    color: #a9c7e8;
    font-size: .95rem;
}

.variables-box {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    background: rgba(2, 12, 28, .48);
    border: 1px solid rgba(150, 210, 255, .18);
    border-radius: 16px;
    padding: 12px;
    margin-bottom: 18px;
    color: #d8ecff;
}

.var-btn {
    border: 1px solid rgba(61,169,255,.35);
    background: rgba(61,169,255,.13);
    color: #dff4ff;
    border-radius: 999px;
    padding: 7px 11px;
    cursor: pointer;
    font-weight: 800;
}

.var-btn:hover {
    background: rgba(61,169,255,.22);
}

.form-grid {
    display: grid;
    grid-template-columns: 150px 1fr 150px;
    gap: 16px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 7px;
}

.form-group.full,
.form-actions.full {
    grid-column: 1 / -1;
}

.form-group label {
    color: #d8ecff;
    font-weight: 600;
    font-size: .95rem;
}

.form-group small {
    color: #9fc1e3;
}

.form-group input,
.form-group select,
.form-group textarea,
.search-row input,
.search-row select {
    width: 100%;
    min-height: 46px;
    border: 1px solid rgba(150, 210, 255, 0.25);
    background: rgba(2, 12, 28, 0.72);
    color: #ffffff;
    border-radius: 14px;
    padding: 12px 14px;
    outline: none;
    font-size: 1rem;
}

.form-group textarea {
    resize: vertical;
    font-family: Consolas, Monaco, monospace;
    line-height: 1.45;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus,
.search-row input:focus,
.search-row select:focus {
    border-color: rgba(61, 169, 255, 0.85);
    box-shadow: 0 0 0 3px rgba(61, 169, 255, 0.15);
}

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

.search-row {
    display: grid;
    grid-template-columns: 1fr 170px auto auto;
    gap: 12px;
    align-items: center;
}

.alert {
    width: min(1180px, calc(100% - 28px));
    margin: 18px auto;
    border-radius: 16px;
    padding: 14px 16px;
    font-weight: 700;
}

.alert.success {
    background: rgba(10, 132, 84, .18);
    border: 1px solid rgba(44, 220, 141, .35);
    color: #b7ffd9;
}

.alert.error {
    background: rgba(170, 30, 45, .20);
    border: 1px solid rgba(255, 110, 125, .35);
    color: #ffd4d9;
}

.plantillas-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.plantilla-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 14px;
    border: 1px solid rgba(120, 190, 255, .18);
    background: linear-gradient(145deg, rgba(5, 18, 38, .92), rgba(10, 42, 82, .78));
    border-radius: 16px;
    padding: 13px 16px;
}

.plantilla-row.is-inactive {
    opacity: .72;
    border-color: rgba(255, 205, 90, .35);
}

.plantilla-info {
    display: grid;
    grid-template-columns: 80px 1fr auto;
    align-items: center;
    gap: 14px;
    min-width: 0;
}

.code {
    display: inline-flex;
    justify-content: center;
    border-radius: 999px;
    padding: 6px 10px;
    background: rgba(61,169,255,.14);
    border: 1px solid rgba(61,169,255,.28);
    color: #d8f0ff;
    font-weight: 900;
}

.plantilla-info h3 {
    margin: 0 0 4px;
    color: #ffffff;
    font-size: 1rem;
}

.plantilla-info p {
    margin: 0;
    color: #cfe6ff;
    overflow-wrap: anywhere;
}

.status {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: .82rem;
    font-weight: 800;
}

.status.on {
    background: rgba(40, 220, 140, .16);
    color: #b9ffd9;
    border: 1px solid rgba(40, 220, 140, .28);
}

.status.off {
    background: rgba(255, 205, 90, .14);
    color: #ffe5a3;
    border: 1px solid rgba(255, 205, 90, .30);
}

.plantilla-actions {
    display: flex;
    flex-direction: row;
    gap: 7px;
    align-items: center;
}

.icon-btn {
    width: 34px;
    height: 34px;
    min-width: 34px;
    border-radius: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    font-size: 15px;
    line-height: 1;
    border: 1px solid rgba(255,255,255,.16);
    background: rgba(255,255,255,.08);
    transition: transform .18s ease, background .18s ease, border-color .18s ease;
}

.icon-btn:hover {
    transform: translateY(-1px);
}

.icon-btn.preview {
    background: rgba(183, 120, 255, .16);
    border-color: rgba(183, 120, 255, .34);
}

.icon-btn.edit {
    background: rgba(61,169,255,.16);
    border-color: rgba(61,169,255,.34);
}

.icon-btn.hide {
    background: rgba(255,205,90,.14);
    border-color: rgba(255,205,90,.32);
}

.icon-btn.show {
    background: rgba(40,220,140,.14);
    border-color: rgba(40,220,140,.32);
}

.icon-btn.delete {
    background: rgba(255, 70, 90, .15);
    border-color: rgba(255, 100, 120, .32);
}

.empty-state {
    padding: 28px;
    text-align: center;
    color: #bcd7f2;
    border: 1px dashed rgba(150, 210, 255, .28);
    border-radius: 16px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    border-radius: 14px;
    padding: 11px 16px;
    text-decoration: none;
    border: 0;
    cursor: pointer;
    font-weight: 800;
    transition: transform .18s ease, box-shadow .18s ease, opacity .18s ease;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn.primary {
    background: linear-gradient(135deg, #1d8cff, #2de2ff);
    color: #031122;
    box-shadow: 0 12px 24px rgba(29, 140, 255, .22);
}

.btn.secondary {
    background: rgba(255,255,255,.10);
    color: #eaf6ff;
    border: 1px solid rgba(255,255,255,.16);
}

.email-preview {
    background: #ffffff;
    color: #1a1a1a;
    border-radius: 16px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,.2);
}

.email-subject {
    padding: 14px 16px;
    border-bottom: 1px solid #e4e4e4;
    background: #f3f7fb;
}

.email-body {
    padding: 18px;
    line-height: 1.5;
}

.email-body h1,
.email-body h2,
.email-body h3,
.email-body p {
    color: #1a1a1a;
}

#buscar-plantillas,
#listado,
#preview {
    scroll-margin-top: 24px;
}

/* PC: header sube con toda la página */
@media (min-width: 901px) {
    .plantillas-header,
    header.plantillas-header,
    .app-header.plantillas-header,
    body .app-header.plantillas-header {
        position: static !important;
        top: auto !important;
    }
}

/* Móvil: header sticky */
@media (max-width: 900px) {
    .plantillas-header,
    header.plantillas-header,
    .app-header.plantillas-header,
    body .app-header.plantillas-header {
        position: sticky !important;
        top: 0 !important;
        z-index: 1000 !important;
        padding: 9px 12px 11px !important;
    }

    .brand img {
        width: 72px !important;
        max-width: 72px !important;
    }

    .brand h1 {
        font-size: 1.3rem !important;
    }

    .brand p {
        font-size: .82rem !important;
    }

    .mini-dashboard {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px !important;
    }

    .dash-card {
        padding: 8px 7px !important;
        min-height: auto !important;
    }

    .dash-card strong {
        font-size: .9rem !important;
        line-height: 1.1 !important;
    }

    .dash-card small {
        font-size: .72rem !important;
    }

    .main-nav {
        margin-top: 10px !important;
    }

    .main-nav a {
        width: 100% !important;
        justify-content: flex-start !important;
        min-height: 44px !important;
    }

    .main-content.page-plantillas {
        padding-top: 14px !important;
    }

    .panel {
        width: min(100% - 20px, 720px);
        padding: 17px;
        border-radius: 18px;
        margin: 16px auto;
    }

    .form-grid,
    .search-row {
        grid-template-columns: 1fr;
    }

    .plantilla-row {
        grid-template-columns: 1fr auto;
        align-items: flex-start;
        padding: 13px;
    }

    .plantilla-info {
        grid-template-columns: 1fr;
        gap: 7px;
    }

    .plantilla-actions {
        flex-direction: column;
    }

    .icon-btn {
        width: 31px;
        height: 31px;
        min-width: 31px;
        border-radius: 10px;
        font-size: 14px;
    }

    #buscar-plantillas,
    #listado,
    #preview {
        scroll-margin-top: 210px;
    }
}

@media (max-width: 430px) {
    .brand img {
        width: 62px !important;
        max-width: 62px !important;
    }

    .brand h1 {
        font-size: 1.08rem !important;
    }

    .brand p {
        display: none !important;
    }

    .section-title h2 {
        font-size: 1.18rem;
    }
}


/* ==========================================================================
   V2 - TEXTO SIMPLE AUTOMÁTICO
   ========================================================================== */

.plain-preview {
    margin-top: 14px;
    background: rgba(255,255,255,.08);
    border: 1px solid rgba(255,255,255,.14);
    border-radius: 14px;
    padding: 12px 14px;
    color: #dff4ff;
}

.plain-preview summary {
    cursor: pointer;
    font-weight: 800;
}

.plain-preview pre {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    margin: 12px 0 0;
    color: #eef8ff;
    font-family: Consolas, Monaco, monospace;
    line-height: 1.45;
}

.form-group textarea[name="contenido_html"] {
    min-height: 260px;
}

@media (max-width: 900px) {
    .form-group textarea[name="contenido_html"] {
        min-height: 310px;
    }
}