/*
 * ==========================================================
 * COMUNIK WHATSAPP TEMPLATES - UI styles
 * ==========================================================
 */

/* ----- Empty state ----- */
.sb-area-wa-templates .sb-wa-tpl-empty {
    padding: 28px 16px !important;
    text-align: center;
    color: #8b95a5;
    font-size: 13px;
}
.sb-area-wa-templates .sb-wa-tpl-empty-error { color: #e74c3c; }
.sb-area-wa-templates .sb-wa-tpl-meta-id {
    font-family: Menlo, Monaco, "Courier New", monospace;
    font-size: 11.5px;
    color: #8b95a5;
}
.sb-area-wa-templates .sb-wa-tpl-actions { white-space: nowrap; }

/* ----- Top bar ----- */
.sb-area-wa-templates .sb-top-bar { padding: 14px 22px; }
.sb-area-wa-templates .sb-top-bar > div:last-child { display: flex; gap: 8px; flex-wrap: wrap; }

.sb-area-wa-templates .sb-wa-tpl-credentials-warn {
    display: none;
    background: #fff8e1;
    border: 1px solid #ffc107;
    padding: 12px 16px;
    margin: 12px 22px;
    border-radius: 8px;
    color: #6b5300;
    font-size: 13px;
}
.sb-area-wa-templates .sb-wa-tpl-credentials-warn i { margin-right: 6px; }

/* ----- Liste / table ----- */
.sb-area-wa-templates .sb-wa-tpl-list { padding: 8px 22px 22px 22px; }
.sb-area-wa-templates .sb-wa-tpl-table {
    width: 100%;
    border-collapse: collapse;
    background: #fff;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0,0,0,.05);
}
.sb-area-wa-templates .sb-wa-tpl-table th {
    text-align: left;
    padding: 12px 16px;
    background: #f7f8fa;
    font-weight: 600;
    font-size: 12.5px;
    color: #455160;
    border-bottom: 1px solid #e7eaef;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.sb-area-wa-templates .sb-wa-tpl-table td {
    padding: 12px 16px;
    border-bottom: 1px solid #eef0f3;
    vertical-align: middle;
    font-size: 13.5px;
}
.sb-area-wa-templates .sb-wa-tpl-table tr:last-child td { border-bottom: none; }
.sb-area-wa-templates .sb-wa-tpl-table tr:hover { background: #fafbfc; }

.sb-wa-tpl-status {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.sb-wa-tpl-status-DRAFT { background: #e7eaef; color: #5a6470; }
.sb-wa-tpl-status-PENDING { background: #fff3cd; color: #856404; }
.sb-wa-tpl-status-APPROVED { background: #d4edda; color: #155724; }
.sb-wa-tpl-status-REJECTED { background: #f8d7da; color: #721c24; }
.sb-wa-tpl-status-PAUSED, .sb-wa-tpl-status-DISABLED { background: #e2e3e5; color: #383d41; }

.sb-area-wa-templates .sb-wa-tpl-table td .sb-btn-icon {
    padding: 6px;
    margin: 0 2px;
    transition: opacity 0.15s;
}
.sb-area-wa-templates .sb-wa-tpl-table td .sb-btn-icon:hover { opacity: 0.7; }

/* ----- Editor (slide-in panel) ----- */
.sb-wa-tpl-editor {
    display: none;
    position: fixed;
    top: 0; right: 0;
    width: 640px;
    max-width: 100vw;
    height: 100vh;
    background: #fff;
    box-shadow: -4px 0 24px rgba(0, 0, 0, 0.12);
    z-index: 100000;
    overflow-y: auto;
    animation: sb-wa-tpl-slide-in 0.22s ease-out;
}
@keyframes sb-wa-tpl-slide-in {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.sb-wa-tpl-editor-header {
    padding: 16px 22px;
    border-bottom: 1px solid #eef0f3;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: #fafbfc;
    position: sticky;
    top: 0;
    z-index: 2;
}
.sb-wa-tpl-editor-header h3 {
    margin: 0;
    font-size: 16px;
    font-weight: 600;
    color: #1a1f2c;
}
.sb-wa-tpl-editor-body { padding: 20px 22px 100px 22px; }

.sb-wa-tpl-field { margin-bottom: 18px; }
.sb-wa-tpl-field label {
    display: block;
    font-weight: 600;
    margin-bottom: 6px;
    font-size: 13px;
    color: #1a1f2c;
}
.sb-wa-tpl-field label small {
    color: #8b95a5;
    font-weight: 400;
    margin-left: 4px;
    font-size: 11.5px;
}
.sb-wa-tpl-field input[type=text],
.sb-wa-tpl-field select,
.sb-wa-tpl-field textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid #d8dde5;
    border-radius: 6px;
    font-family: inherit;
    font-size: 13.5px;
    background: #fff;
    transition: border-color 0.15s;
    box-sizing: border-box;
}
.sb-wa-tpl-field input[type=text]:focus,
.sb-wa-tpl-field select:focus,
.sb-wa-tpl-field textarea:focus {
    outline: none;
    border-color: #25d366;
    box-shadow: 0 0 0 3px rgba(37, 211, 102, 0.15);
}
.sb-wa-tpl-field input.sb-wa-tpl-input-valid {
    border-color: #25d366;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%2325d366' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='20 6 9 17 4 12'/></svg>");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
    padding-right: 32px;
}
.sb-wa-tpl-field textarea {
    min-height: 120px;
    resize: vertical;
    line-height: 1.5;
}

.sb-wa-tpl-name-error,
.sb-wa-tpl-body-error {
    display: none;
    color: #e74c3c;
    font-size: 12px;
    margin-top: 4px;
}

.sb-wa-tpl-body-counter {
    display: block;
    margin-top: 4px;
    font-size: 11.5px;
    color: #8b95a5;
    text-align: right;
}
.sb-wa-tpl-body-counter.sb-wa-tpl-counter-warn { color: #f59e0b; }
.sb-wa-tpl-body-counter.sb-wa-tpl-counter-over { color: #e74c3c; font-weight: 600; }

/* ----- Variables fillers (test values) ----- */
.sb-wa-tpl-vars {
    margin-bottom: 18px;
    padding: 12px 14px;
    background: #f7f8fa;
    border-radius: 8px;
    border: 1px dashed #d8dde5;
}
.sb-wa-tpl-vars-empty { display: none; }
.sb-wa-tpl-vars-title {
    font-size: 12px;
    font-weight: 600;
    color: #455160;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}
.sb-wa-tpl-vars-title::before {
    content: "";
    width: 6px;
    height: 6px;
    background: #25d366;
    border-radius: 50%;
}
.sb-wa-tpl-var-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.sb-wa-tpl-var-row:last-child { margin-bottom: 0; }
.sb-wa-tpl-var-label {
    font-size: 12px;
    font-weight: 600;
    color: #1a1f2c;
    background: #fef3c7;
    padding: 3px 8px;
    border-radius: 4px;
    min-width: 50px;
    text-align: center;
}
.sb-wa-tpl-var-input {
    flex: 1;
    padding: 6px 10px !important;
    font-size: 13px !important;
    border: 1px solid #d8dde5 !important;
    border-radius: 5px !important;
    background: #fff !important;
}

/* ----- WhatsApp realistic preview ----- */
.sb-wa-tpl-preview-wrap {
    margin-bottom: 20px;
    background: #e5ddd5;
    background-image:
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='100' height='100' viewBox='0 0 100 100'><circle cx='20' cy='20' r='1' fill='%23000' opacity='0.04'/><circle cx='60' cy='40' r='1' fill='%23000' opacity='0.04'/><circle cx='30' cy='70' r='1' fill='%23000' opacity='0.04'/><circle cx='80' cy='80' r='1' fill='%23000' opacity='0.04'/></svg>");
    border-radius: 12px;
    padding: 18px;
    border: 1px solid #d8dde5;
    position: relative;
}
.sb-wa-tpl-preview-label {
    position: absolute;
    top: 8px;
    right: 12px;
    font-size: 10px;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
    background: rgba(255,255,255,0.8);
    padding: 2px 7px;
    border-radius: 3px;
}
.sb-wa-tpl-preview-bubble {
    background: #dcf8c6;
    padding: 8px 10px 6px 10px;
    border-radius: 8px;
    box-shadow: 0 1px 0.5px rgba(0,0,0,.13);
    max-width: 85%;
    margin-left: auto;
    position: relative;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.4;
    color: #1a1f2c;
    word-wrap: break-word;
}
.sb-wa-tpl-preview-bubble::after {
    content: "";
    position: absolute;
    top: 0;
    right: -8px;
    border-top: 8px solid #dcf8c6;
    border-right: 8px solid transparent;
}
.sb-wa-tpl-preview-body {
    white-space: pre-wrap;
    word-wrap: break-word;
}
.sb-wa-tpl-preview-body em { color: inherit; font-style: italic; }
.sb-wa-tpl-preview-body strong { font-weight: 700; }
.sb-wa-tpl-preview-body code {
    font-family: Menlo, Monaco, monospace;
    font-size: 13px;
    background: rgba(0,0,0,0.04);
    padding: 1px 4px;
    border-radius: 3px;
}
.sb-wa-tpl-preview-var {
    background: #fef3c7;
    padding: 1px 5px;
    border-radius: 3px;
    font-weight: 600;
    color: #92400e;
}
.sb-wa-tpl-preview-meta {
    display: flex;
    align-items: center;
    gap: 4px;
    justify-content: flex-end;
    margin-top: 4px;
    font-size: 10.5px;
    color: #667781;
    line-height: 1;
}
.sb-wa-tpl-preview-meta-time { font-size: 10.5px; }
.sb-wa-tpl-preview-meta-checks {
    color: #53bdeb;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: -2px;
    margin-left: 2px;
}
.sb-wa-tpl-preview-empty {
    color: #94a3b8;
    font-style: italic;
    font-size: 13px;
}

/* ----- Rejection box ----- */
.sb-wa-tpl-rejection {
    display: none;
    margin-bottom: 18px;
    padding: 12px 14px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    border-radius: 8px;
    color: #991b1b;
    font-size: 13px;
}
.sb-wa-tpl-rejection strong { display: block; margin-bottom: 4px; font-size: 12.5px; }

/* ----- Footer (sticky bottom) ----- */
.sb-wa-tpl-editor-footer {
    position: sticky;
    bottom: 0;
    left: 0;
    right: 0;
    margin: 20px -22px -100px -22px;
    padding: 14px 22px;
    background: #fff;
    border-top: 1px solid #eef0f3;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.04);
}
.sb-wa-tpl-editor-footer .sb-btn { margin: 0; }
.sb-wa-tpl-editor-footer .sb-btn.sb-disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ----- Dark mode ----- */
.sb-dark-mode .sb-area-wa-templates .sb-wa-tpl-table { background: #1f1f1f; }
.sb-dark-mode .sb-area-wa-templates .sb-wa-tpl-table th { background: #2a2a2a; color: #b8c0c8; border-color: #3a3a3a; }
.sb-dark-mode .sb-area-wa-templates .sb-wa-tpl-table td { border-color: #3a3a3a; color: #d0d6dd; }
.sb-dark-mode .sb-area-wa-templates .sb-wa-tpl-table tr:hover { background: #262626; }
.sb-dark-mode .sb-wa-tpl-editor { background: #1a1a1a; color: #d0d6dd; }
.sb-dark-mode .sb-wa-tpl-editor-header { background: #1f1f1f; border-color: #3a3a3a; }
.sb-dark-mode .sb-wa-tpl-editor-header h3 { color: #fff; }
.sb-dark-mode .sb-wa-tpl-field label { color: #d0d6dd; }
.sb-dark-mode .sb-wa-tpl-field input[type=text],
.sb-dark-mode .sb-wa-tpl-field select,
.sb-dark-mode .sb-wa-tpl-field textarea { background: #2a2a2a; border-color: #3a3a3a; color: #d0d6dd; }
.sb-dark-mode .sb-wa-tpl-vars { background: #1f1f1f; border-color: #3a3a3a; }
.sb-dark-mode .sb-wa-tpl-vars-title { color: #b8c0c8; }
.sb-dark-mode .sb-wa-tpl-var-input { background: #2a2a2a !important; border-color: #3a3a3a !important; color: #d0d6dd !important; }
.sb-dark-mode .sb-wa-tpl-editor-footer { background: #1a1a1a; border-color: #3a3a3a; }

/* ----- Responsive ----- */
@media (max-width: 700px) {
    .sb-wa-tpl-editor { width: 100%; }
    .sb-area-wa-templates .sb-wa-tpl-list { padding: 8px 10px 16px 10px; }
    .sb-area-wa-templates .sb-wa-tpl-table th,
    .sb-area-wa-templates .sb-wa-tpl-table td { padding: 10px 8px; font-size: 12.5px; }
}
