/* ============================================================================
   WHATSAPP MODULE – MODERN, MOBILE-FIRST UI (WH23)
   ----------------------------------------------------------------------------
   Toate stilurile noi sunt prefixate cu `wa-` pentru a fi izolate de restul
   aplicatiei (nu suprascriu clase globale precum .card / .form-input).
   Scris mobile-first: stilurile de baza vizeaza telefonul, iar media-query-urile
   `min-width` adauga imbunatatiri pentru ecrane mai mari.
   ============================================================================ */

:root {
    --wa-green: #25d366;
    --wa-green-strong: #128c7e;
    --wa-green-deep: #075e54;
    --wa-bg: #f0f2f5;
    --wa-surface: #ffffff;
    --wa-border: #e5e7eb;
    --wa-text: #111827;
    --wa-text-soft: #6b7280;
    --wa-text-faint: #9ca3af;
    --wa-radius: 14px;
    --wa-radius-sm: 10px;
    --wa-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --wa-shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.28);
    --wa-tap: 44px; /* touch target minim recomandat */
}

/* Evita overflow orizontal pe modulul WhatsApp */
.wa-page,
.wa-page * {
    box-sizing: border-box;
}
.wa-page {
    max-width: 100%;
    overflow-x: hidden;
}

/* ============================================================================
   HEADER PAGINA
   ============================================================================ */
.wa-page-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 18px;
}
.wa-page-header__icon {
    width: 46px;
    height: 46px;
    flex-shrink: 0;
    border-radius: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    color: #fff;
    background: linear-gradient(135deg, var(--wa-green) 0%, var(--wa-green-strong) 100%);
    box-shadow: 0 6px 16px rgba(18, 140, 126, 0.28);
}
.wa-page-header__text h1 {
    margin: 0;
    font-size: 20px;
    font-weight: 700;
    color: var(--wa-text);
    line-height: 1.2;
}
.wa-page-header__text p {
    margin: 2px 0 0;
    font-size: 13px;
    color: var(--wa-text-soft);
}

/* ============================================================================
   BUTOANE
   ============================================================================ */
.wa-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--wa-tap);
    padding: 10px 18px;
    border: 1px solid transparent;
    border-radius: var(--wa-radius-sm);
    font-size: 15px;
    font-weight: 600;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}
.wa-btn:active { transform: scale(0.98); }
.wa-btn--primary {
    background: linear-gradient(135deg, var(--wa-green) 0%, var(--wa-green-strong) 100%);
    color: #fff;
    box-shadow: 0 4px 14px rgba(18, 140, 126, 0.30);
}
.wa-btn--primary:hover { box-shadow: 0 6px 18px rgba(18, 140, 126, 0.42); }
.wa-btn--ghost {
    background: #fff;
    color: #374151;
    border-color: var(--wa-border);
}
.wa-btn--ghost:hover { background: #f9fafb; }
.wa-btn--warn {
    background: #fff7ed;
    color: #b45309;
    border-color: #fdba74;
}
.wa-btn--warn:hover { background: #ffedd5; }
.wa-btn--ok {
    background: #ecfdf5;
    color: #15803d;
    border-color: #86efac;
}
.wa-btn--ok:hover { background: #dcfce7; }
.wa-btn--block { width: 100%; }

/* ============================================================================
   TOOLBAR / FILTRE CONVERSATII
   ============================================================================ */
.wa-toolbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    background: var(--wa-surface);
    border: 1px solid var(--wa-border);
    border-radius: var(--wa-radius);
    padding: 14px;
    margin-bottom: 16px;
    box-shadow: var(--wa-shadow);
}
.wa-field { display: flex; flex-direction: column; gap: 6px; }
.wa-field > label {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--wa-text-soft);
}
.wa-input,
.wa-select,
textarea.wa-input {
    width: 100%;
    min-height: var(--wa-tap);
    padding: 10px 12px;
    border: 1px solid var(--wa-border);
    border-radius: var(--wa-radius-sm);
    font-size: 16px; /* >=16px evita zoom-ul automat pe iOS */
    color: var(--wa-text);
    background: #fff;
}
.wa-input:focus,
.wa-select:focus,
textarea.wa-input:focus {
    outline: none;
    border-color: var(--wa-green-strong);
    box-shadow: 0 0 0 3px rgba(18, 140, 126, 0.15);
}

@media (min-width: 640px) {
    .wa-toolbar {
        grid-template-columns: 1fr 1.4fr auto;
        align-items: end;
    }
    .wa-toolbar .wa-btn { height: var(--wa-tap); }
    .wa-toolbar--split {
        grid-template-columns: 1fr auto;
    }
}

/* ============================================================================
   LISTA CONVERSATII
   ============================================================================ */
.wa-conv-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.wa-conv-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    text-align: left;
    background: var(--wa-surface);
    border: 1px solid var(--wa-border);
    border-radius: var(--wa-radius);
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}
.wa-conv-item:hover {
    border-color: var(--wa-green);
    box-shadow: 0 6px 18px rgba(18, 140, 126, 0.12);
    transform: translateY(-1px);
}
.wa-conv-avatar {
    width: 46px;
    height: 46px;
    flex-shrink: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, var(--wa-green) 0%, var(--wa-green-strong) 100%);
}
.wa-conv-main { flex: 1; min-width: 0; }
.wa-conv-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 8px;
}
.wa-conv-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--wa-text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wa-conv-time {
    font-size: 12px;
    color: var(--wa-text-faint);
    flex-shrink: 0;
}
.wa-conv-phone {
    font-size: 12.5px;
    color: var(--wa-text-faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wa-conv-preview {
    font-size: 13.5px;
    color: var(--wa-text-soft);
    line-height: 1.4;
    margin-top: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wa-conv-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

/* ============================================================================
   BADGE-URI DE STARE
   ============================================================================ */
.wa-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    line-height: 1.4;
    white-space: nowrap;
}
.wa-badge--active { background: #dcfce7; color: #166534; }
.wa-badge--closed { background: #fee2e2; color: #991b1b; }
.wa-badge--ai { background: #dbeafe; color: #1e40af; }
.wa-badge--operator { background: #fef3c7; color: #92400e; }
.wa-badge--count { background: #f3f4f6; color: #4b5563; }
/* Task #246: conversație „de preluat" (fără lead legat / lead neasignat) */
.wa-badge--depreluat { background: #ede9fe; color: #5b21b6; }

/* Task #246: toggle „Doar conversațiile mele" din toolbar */
.wa-checkline {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
}
.wa-checkline input { cursor: pointer; }
.wa-hint {
    display: block;
    margin-top: 2px;
    font-size: 11px;
    color: var(--wa-text-soft);
}

/* ============================================================================
   STARI GOALE / LOADING / EROARE
   ============================================================================ */
.wa-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--wa-text-soft);
    background: var(--wa-surface);
    border: 1px dashed var(--wa-border);
    border-radius: var(--wa-radius);
}
.wa-state__icon { font-size: 40px; margin-bottom: 12px; }
.wa-state__title { font-size: 17px; font-weight: 700; color: var(--wa-text); margin: 0 0 6px; }
.wa-state__text { font-size: 14px; margin: 0 auto; max-width: 420px; line-height: 1.5; }
.wa-state--error { color: #dc2626; border-color: #fecaca; }

/* ============================================================================
   PAGINARE
   ============================================================================ */
.wa-pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin-top: 18px;
    flex-wrap: wrap;
}
.wa-pagination__info { font-size: 13px; color: var(--wa-text-soft); }

/* ============================================================================
   CHAT VIEW (modal tip aplicatie de mesagerie)
   ============================================================================ */
.wa-chat-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(3px);
    z-index: 10000;
    display: flex;
    align-items: stretch;
    justify-content: center;
    padding: 0;
}

.wa-chat {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: var(--wa-bg);
    overflow: hidden;
}

/* Header lipit sus */
.wa-chat-header {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    padding-top: max(10px, env(safe-area-inset-top));
    background: linear-gradient(135deg, var(--wa-green-deep) 0%, var(--wa-green-strong) 100%);
    color: #fff;
}
.wa-chat-back {
    flex-shrink: 0;
    width: var(--wa-tap);
    height: var(--wa-tap);
    border: none;
    background: transparent;
    color: #fff;
    font-size: 22px;
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}
.wa-chat-back:hover { background: rgba(255, 255, 255, 0.15); }
.wa-chat-avatar {
    width: 40px;
    height: 40px;
    flex-shrink: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.22);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 17px;
    font-weight: 700;
}
.wa-chat-titles { flex: 1; min-width: 0; }
.wa-chat-name {
    font-size: 16px;
    font-weight: 600;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wa-chat-phone {
    font-size: 12.5px;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Bara de status + control operator */
.wa-chat-control {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 10px 12px;
    background: #fff;
    border-bottom: 1px solid var(--wa-border);
}
.wa-chat-status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
}
.wa-chat-status--ai { color: #1e40af; }
.wa-chat-status--operator { color: #b45309; }
.wa-chat-control .wa-btn { padding: 8px 14px; min-height: 40px; font-size: 14px; }

/* Corp mesaje, scrollabil */
.wa-chat-body {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 16px 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background-color: #e5ddd5;
    background-image: linear-gradient(rgba(229, 221, 213, 0.92), rgba(229, 221, 213, 0.92));
}
.wa-msg { display: flex; max-width: 100%; }
.wa-msg--in { justify-content: flex-start; }
.wa-msg--out { justify-content: flex-end; }
.wa-bubble {
    max-width: 82%;
    padding: 8px 11px;
    border-radius: 12px;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.12);
    word-wrap: break-word;
    overflow-wrap: anywhere;
}
.wa-bubble--in {
    background: #fff;
    color: var(--wa-text);
    border-top-left-radius: 4px;
}
.wa-bubble--out {
    background: #d9fdd3;
    color: #0b3d2e;
    border-top-right-radius: 4px;
}
.wa-bubble--operator { background: #fff3cd; color: #7c5e10; }
/* Mesaj outgoing neacceptat de provider (external_message_id NULL) = NETRIMIS */
.wa-bubble--failed {
    background: #fee2e2;
    color: #7f1d1d;
    border-top-right-radius: 4px;
    border-left: 3px solid #dc2626;
}
.wa-msg-failed {
    color: #dc2626;
    font-weight: 700;
}
.wa-msg-ticks { opacity: 0.7; }
.wa-msg-ticks--read { color: #34b7f1; opacity: 1; }
.wa-msg-sender {
    font-size: 11px;
    font-weight: 700;
    opacity: 0.75;
    margin-bottom: 3px;
}
.wa-msg-text {
    font-size: 14.5px;
    line-height: 1.45;
    white-space: pre-wrap;
}
.wa-msg-time {
    display: block;
    text-align: right;
    font-size: 10.5px;
    opacity: 0.6;
    margin-top: 4px;
}

/* Composer lipit jos */
.wa-composer {
    flex-shrink: 0;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    background: #f0f2f5;
    border-top: 1px solid var(--wa-border);
}
.wa-composer__input {
    flex: 1;
    min-height: var(--wa-tap);
    max-height: 120px;
    padding: 11px 14px;
    border: 1px solid var(--wa-border);
    border-radius: 22px;
    font-size: 16px;
    line-height: 1.35;
    resize: none;
    background: #fff;
    color: var(--wa-text);
    font-family: inherit;
}
.wa-composer__input:focus {
    outline: none;
    border-color: var(--wa-green-strong);
}
.wa-composer__send {
    flex-shrink: 0;
    width: var(--wa-tap);
    height: var(--wa-tap);
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--wa-green) 0%, var(--wa-green-strong) 100%);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(18, 140, 126, 0.35);
}
.wa-composer__send:disabled { opacity: 0.5; cursor: not-allowed; }

.wa-composer--locked {
    justify-content: center;
    color: var(--wa-text-soft);
    font-size: 13px;
    text-align: center;
}

/* Footer cu statistici (ascuns pe mobil pentru spatiu) */
.wa-chat-foot {
    flex-shrink: 0;
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
    padding: 8px 14px;
    background: #fff;
    border-top: 1px solid var(--wa-border);
    font-size: 12.5px;
    color: var(--wa-text-soft);
}

/* Desktop: chat-ul devine o fereastra centrata */
@media (min-width: 768px) {
    .wa-chat-overlay {
        align-items: center;
        padding: 24px;
    }
    .wa-chat {
        width: 100%;
        max-width: 720px;
        height: min(86vh, 820px);
        border-radius: var(--wa-radius);
        box-shadow: var(--wa-shadow-lg);
    }
    .wa-chat-header { border-radius: var(--wa-radius) var(--wa-radius) 0 0; }
    .wa-chat-foot { display: flex; }
    .wa-chat-back { display: none; } /* pe desktop folosim X-ul dedicat */
    .wa-chat-close-x { display: flex; }
}

/* Buton X de inchidere (vizibil pe desktop, in header) */
.wa-chat-close-x {
    display: none;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}
.wa-chat-close-x:hover { background: rgba(255, 255, 255, 0.30); }

/* ============================================================================
   SECTIUNEA DE CONFIGURARE – panouri reutilizabile + imbunatatiri responsive
   ============================================================================ */
.wa-panel {
    background: var(--wa-surface);
    border: 1px solid var(--wa-border);
    border-radius: var(--wa-radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--wa-shadow);
}
.wa-panel--nested {
    background: var(--wa-bg);
    box-shadow: none;
    margin-bottom: 16px;
}
.wa-panel__title {
    margin: 0 0 12px;
    font-size: 16px;
    font-weight: 700;
    color: var(--wa-text);
}
.wa-panel__subtitle {
    margin: 0 0 14px;
    font-weight: 600;
    font-size: 14px;
    color: var(--wa-text);
}
.wa-panel__desc {
    margin: 0 0 12px;
    font-size: 14px;
    color: var(--wa-text-soft);
    line-height: 1.5;
}
.wa-panel__hint {
    display: block;
    margin-top: 6px;
    font-size: 12px;
    color: var(--wa-text-soft);
    line-height: 1.45;
}
.wa-panel .wa-field { margin-bottom: 12px; }
.wa-panel .wa-field:last-child { margin-bottom: 0; }

.wa-details { margin-top: 16px; }
.wa-details__summary {
    cursor: pointer;
    font-weight: 600;
    color: var(--wa-green-strong);
    padding: 10px 12px;
    background: #ecfdf5;
    border-radius: var(--wa-radius-sm);
    list-style: none;
}
.wa-details__summary::-webkit-details-marker { display: none; }
.wa-details__summary--accent {
    color: var(--wa-green-deep);
    background: #f0fdf4;
}
.wa-details__body { padding: 16px 0 0; }

.wa-config-hero {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
    background: linear-gradient(135deg, var(--wa-green-strong) 0%, var(--wa-green-deep) 100%);
    color: #fff;
    border-radius: var(--wa-radius);
    padding: 18px 20px;
    margin-bottom: 18px;
    box-shadow: 0 10px 28px rgba(7, 94, 84, 0.30);
}
.wa-config-hero h3 { margin: 0 0 6px; font-size: 18px; }
.wa-config-hero p { margin: 0; opacity: 0.92; font-size: 14px; }
.wa-config-hero__toggle { text-align: center; flex-shrink: 0; }
.wa-config-hero__toggle p { font-size: 12px; margin-top: 6px; }

/* Grid de statistici reutilizabil, responsive */
.wa-stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}
@media (min-width: 640px) {
    .wa-stats-grid { grid-template-columns: repeat(4, 1fr); }
}
.wa-stat {
    background: #f9fafb;
    border: 1px solid var(--wa-border);
    border-radius: var(--wa-radius-sm);
    padding: 16px 12px;
    text-align: center;
}
.wa-stat__value { font-size: 24px; font-weight: 700; color: var(--wa-green-strong); }
.wa-stat__label { font-size: 12px; color: var(--wa-text-soft); margin-top: 4px; }

/* Asigura ca formularele de config nu produc overflow pe mobil */
#whatsapp-aiSection .wa-input,
#whatsapp-aiSection .wa-select,
#whatsapp-aiSection textarea.wa-input,
#whatsapp-aiSection .form-input,
#whatsapp-aiSection input,
#whatsapp-aiSection select,
#whatsapp-aiSection textarea {
    max-width: 100%;
}
#whatsapp-aiSection code {
    word-break: break-all;
}

/* Pe mobil, randurile de butoane din config devin verticale ca sa nu se ingramadeasca */
@media (max-width: 600px) {
    #whatsapp-aiSection .wa-btn-row {
        flex-direction: column !important;
        align-items: stretch !important;
    }
    #whatsapp-aiSection .wa-btn-row > button {
        width: 100% !important;
    }
}

/* ============================================================================
   KB GRID (carduri responsive - mereu grid, 1 col pe mobil)
   ============================================================================ */
#whatsappKnowledgeBaseList {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
#whatsappKnowledgeBaseList > .wa-state,
#whatsappKnowledgeBaseList > .empty-state,
#whatsappKnowledgeBaseList > .loading { grid-column: 1 / -1; }

@media (max-width: 480px) {
    #whatsappKnowledgeBaseList { grid-template-columns: 1fr; }
}

/* ============================================================================
   WA KB CARDURI - redesign modern (prefix wa-kb-*)
   ============================================================================ */
.wa-kb-card {
    background: #fff !important;
    color: #1e293b !important;
    border-radius: 10px;
    border: 1px solid #e2e8f0 !important;
    box-shadow: 0 1px 4px rgba(0,0,0,.06) !important;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: box-shadow .15s, border-color .15s;
    cursor: pointer;
}
.wa-kb-card:hover {
    box-shadow: 0 4px 14px rgba(0,0,0,.10);
    border-color: #25D366;
}
.wa-kb-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.wa-kb-card-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.wa-kb-card-title {
    font-weight: 600;
    font-size: 15px;
    color: #1e293b !important;
    margin: 0;
    line-height: 1.4;
    word-break: break-word;
}
.wa-kb-card-preview {
    font-size: 13px;
    color: #64748b !important;
    line-height: 1.55;
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    word-break: break-word;
}
.wa-kb-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: auto;
    padding-top: 8px;
    border-top: 1px solid #f1f5f9;
}
.wa-kb-card-date {
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    color: #94a3b8;
}
.wa-kb-category-chip {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 500;
}
.wa-kb-actions {
    display: flex;
    gap: 6px;
}
.wa-kb-icon-btn {
    width: 30px;
    height: 30px;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    line-height: 1;
    transition: background .15s, border-color .15s, color .15s;
}
.wa-kb-icon-btn:hover {
    background: #e2e8f0;
}
.wa-kb-icon-btn--delete:hover {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #dc2626;
}

/* ============================================================================
   KB DETAIL MODAL (prefix wa-kb-detail-*)
   ============================================================================ */
@keyframes waKbFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes waKbSlideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.wa-kb-detail-modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 10000 !important;
    display: flex !important;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: waKbFadeIn 0.2s ease;
    overflow-y: auto;
}
.wa-kb-detail-container {
    background: var(--wa-surface);
    border-radius: var(--wa-radius);
    width: 100%;
    max-width: 900px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--wa-shadow-lg);
    animation: waKbSlideUp 0.3s ease;
}
.wa-kb-detail-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    padding: 20px 20px 16px;
    border-bottom: 1px solid var(--wa-border);
}
.wa-kb-detail-header-left {
    display: flex;
    gap: 14px;
    flex: 1;
    min-width: 0;
}
.wa-kb-detail-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    flex-shrink: 0;
}
.wa-kb-detail-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--wa-text);
    margin: 0 0 8px;
    line-height: 1.3;
    outline: none;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.2s ease;
}
.wa-kb-detail-title:hover { background: var(--wa-bg); }
.wa-kb-detail-title:focus { background: #f3f4f6; }
.wa-kb-detail-meta {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.wa-kb-detail-badge {
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}
.wa-kb-detail-date {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--wa-text-faint);
}
.wa-kb-detail-close {
    width: var(--wa-tap);
    height: var(--wa-tap);
    border-radius: var(--wa-radius-sm);
    border: none;
    background: var(--wa-bg);
    color: var(--wa-text-soft);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s ease, color 0.2s ease;
    flex-shrink: 0;
}
.wa-kb-detail-close:hover {
    background: var(--wa-border);
    color: var(--wa-text);
}
.wa-kb-detail-content-wrapper {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}
.wa-kb-detail-content {
    font-size: 15px;
    line-height: 1.75;
    color: var(--wa-text);
    outline: none;
    padding: 12px;
    border-radius: var(--wa-radius-sm);
    transition: background 0.2s ease;
    white-space: pre-wrap;
    word-break: break-word;
    min-height: 180px;
}
.wa-kb-detail-content:hover { background: var(--wa-bg); }
.wa-kb-detail-content:focus { background: #f3f4f6; }
.wa-kb-detail-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--wa-border);
    background: var(--wa-bg);
    border-radius: 0 0 var(--wa-radius) var(--wa-radius);
}
.wa-kb-detail-footer-left { flex: 1; }
.wa-kb-detail-hint {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--wa-text-faint);
}
.wa-kb-detail-actions {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}
.wa-kb-detail-btn {
    min-height: 40px;
    padding: 10px 18px;
    border-radius: var(--wa-radius-sm);
    border: none;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.wa-kb-detail-btn-delete {
    background: #fee2e2;
    color: #dc2626;
}
.wa-kb-detail-btn-delete:hover {
    background: #fecaca;
    transform: translateY(-1px);
}
.wa-kb-detail-btn-save {
    background: linear-gradient(135deg, var(--wa-green) 0%, var(--wa-green-strong) 100%);
    color: #fff;
    box-shadow: 0 4px 12px rgba(18, 140, 126, 0.28);
}
.wa-kb-detail-btn-save:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(18, 140, 126, 0.36);
}

@media (max-width: 768px) {
    .wa-kb-detail-modal {
        padding: 0 !important;
        align-items: flex-start !important;
    }
    .wa-kb-detail-container {
        max-width: 100% !important;
        max-height: 100vh !important;
        height: 100vh !important;
        border-radius: 0 !important;
        width: 100vw !important;
    }
    .wa-kb-detail-header { padding: 16px; }
    .wa-kb-detail-header-left { flex-direction: column; gap: 10px; }
    .wa-kb-detail-icon { width: 44px; height: 44px; font-size: 22px; }
    .wa-kb-detail-title { font-size: 18px; }
    .wa-kb-detail-content-wrapper { padding: 16px; }
    .wa-kb-detail-footer {
        flex-direction: column;
        align-items: stretch;
    }
    .wa-kb-detail-actions { width: 100%; }
    .wa-kb-detail-btn { flex: 1; justify-content: center; }
}

/* Modal formular KB (add/edit) */
.wa-kb-form-modal .modal-content {
    max-width: 700px;
    max-height: 95vh;
    overflow-y: auto;
    border-radius: var(--wa-radius);
}
.wa-kb-form-modal__head {
    position: sticky;
    top: 0;
    background: var(--wa-surface);
    z-index: 10;
    padding-bottom: 12px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--wa-border);
}
.wa-kb-form-modal__head h2 {
    margin: 0;
    font-size: 20px;
    color: var(--wa-text);
}
.wa-kb-form-modal__head p {
    margin: 6px 0 0;
    font-size: 14px;
    color: var(--wa-text-soft);
}
.wa-kb-form-modal__actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--wa-border);
}

@media (max-width: 640px) {
    .wa-kb-form-modal__actions {
        flex-direction: column;
    }
    .wa-kb-form-modal__actions .wa-btn { width: 100%; }
}

/* ============================================================================
   ADMIN MULTI-USER – carduri responsive
   ============================================================================ */
.wa-user-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding: 14px;
    border: 1px solid var(--wa-border);
    border-radius: var(--wa-radius-sm);
    margin-bottom: 10px;
    background: #fff;
}
.wa-user-card--on { background: #f0fdf4; border-color: #bbf7d0; }
.wa-user-card__info { min-width: 0; flex: 1; }
.wa-user-card__name { font-weight: 600; font-size: 15px; color: var(--wa-text); }
.wa-user-card__sub { font-size: 13px; color: var(--wa-text-soft); }
.wa-user-card__stats { font-size: 12px; color: var(--wa-text-faint); margin-top: 4px; }
.wa-user-card__actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }

/* ============================================================================
   MESAJE PREDEFINITE (WH23) — editor + listă + aprobare
   ============================================================================ */
.wa-tpl-editor {
    background: var(--wa-surface);
    border: 1px solid var(--wa-border);
    border-radius: var(--wa-radius);
    padding: 16px;
    margin-bottom: 16px;
    box-shadow: var(--wa-shadow);
}
.wa-tpl-editor__title {
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--wa-text-soft);
    margin-bottom: 12px;
}
.wa-tpl-editor .wa-field { margin-bottom: 12px; }
.wa-tpl-editor__actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    flex-wrap: wrap;
}

.wa-tpl-list { display: flex; flex-direction: column; gap: 10px; }
.wa-tpl-empty {
    text-align: center;
    color: var(--wa-text-soft);
    padding: 28px 16px;
    background: var(--wa-surface);
    border: 1px dashed var(--wa-border);
    border-radius: var(--wa-radius);
    font-size: 14px;
}

.wa-tpl-card {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    background: var(--wa-surface);
    border: 1px solid var(--wa-border);
    border-radius: var(--wa-radius);
    padding: 14px;
    box-shadow: var(--wa-shadow);
}
.wa-tpl-card--inactive { opacity: 0.62; }
.wa-tpl-card__main { flex: 1; min-width: 0; }
.wa-tpl-card__head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}
.wa-tpl-card__title { font-size: 15px; color: var(--wa-text); }
.wa-tpl-card__key {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    color: var(--wa-text-faint);
}
.wa-tpl-card__body {
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--wa-text-soft);
    font-size: 13px;
    line-height: 1.45;
}
.wa-tpl-card__tools { display: flex; flex-direction: column; gap: 8px; flex-shrink: 0; }
.wa-tpl-card__tools .wa-btn { padding: 8px 12px; min-height: 38px; }

.wa-tpl-badge {
    display: inline-flex;
    align-items: center;
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 999px;
    line-height: 1.6;
}
.wa-tpl-badge--draft    { background: #f1f5f9; color: #475569; }
.wa-tpl-badge--pending  { background: #fef3c7; color: #b45309; }
.wa-tpl-badge--approved { background: #dcfce7; color: #15803d; }
.wa-tpl-badge--rejected { background: #fee2e2; color: #b91c1c; }
.wa-tpl-badge--off      { background: #fee2e2; color: #b91c1c; }

.wa-tpl-actions-row {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 10px;
}
.wa-tpl-cat { width: auto; min-height: 40px; min-width: 180px; font-size: 14px; }
.wa-tpl-note { font-size: 12px; color: var(--wa-text-soft); margin-top: 8px; }
.wa-tpl-note--ok { color: #15803d; }
.wa-tpl-note--err { color: #b91c1c; }

@media (max-width: 640px) {
    .wa-tpl-card { flex-direction: column; }
    .wa-tpl-card__tools { flex-direction: row; }
    .wa-tpl-cat { width: 100%; min-width: 0; }
    .wa-tpl-actions-row > .wa-btn { width: 100%; }
}

/* ============================================================================
   RESURSE RAPIDE CRM — wa-resources-panel (în conversația WhatsApp)
   ============================================================================ */
.wa-resources-panel {
    border-top: 1px solid var(--wa-border);
    background: var(--wa-surface);
    flex-shrink: 0;
}

.wa-resources-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    padding: 8px 14px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    color: var(--wa-text-soft);
    text-align: left;
    letter-spacing: 0.3px;
    transition: background 0.15s;
}
.wa-resources-toggle:hover { background: var(--wa-bg); }

.wa-resources-toggle__arrow {
    margin-left: auto;
    font-size: 10px;
    color: var(--wa-text-faint);
}

.wa-resources-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 14px 10px;
}

.wa-resource-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    background: #f1f5f9;
    border: 1px solid #cbd5e1;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    color: var(--wa-text);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wa-resource-chip:hover {
    background: #e2e8f0;
    border-color: #94a3b8;
    transform: translateY(-1px);
}
.wa-resource-chip:active { transform: translateY(0); }

@media (max-width: 480px) {
    .wa-resource-chip { max-width: 160px; }
}

/* ============================================================================
   RESURSE PROGRAM CRM — .cpr-* (în modalul de editare program)
   ============================================================================ */
.cpr-item {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    padding: 10px;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    margin-bottom: 8px;
    background: #fff;
    box-sizing: border-box;
    transition: opacity 0.2s;
}
.cpr-item--inactive { opacity: 0.6; }

.cpr-icon {
    font-size: 18px;
    flex-shrink: 0;
    line-height: 1.4;
    margin-top: 1px;
}

.cpr-body {
    flex: 1 1 0;
    min-width: 0;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.cpr-title {
    font-size: 13px;
    font-weight: 600;
    color: #1e293b;
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 3px;
}

.cpr-var-badge {
    font-size: 11px;
    background: #eff6ff;
    color: #1d4ed8;
    padding: 1px 6px;
    border-radius: 5px;
    font-weight: 500;
}

.cpr-badge-off {
    font-size: 10px;
    background: #fee2e2;
    color: #b91c1c;
    padding: 1px 6px;
    border-radius: 5px;
    font-weight: 600;
}

.cpr-url {
    font-size: 11px;
    color: #64748b;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cpr-quick-msg {
    font-size: 11px;
    color: #475569;
    margin-top: 4px;
    font-style: italic;
}

.cpr-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

/* =============================================================================
   CRM CALL OVERLAY — WhatsApp Quick-Send Panel
   ============================================================================= */

.crm-call-wa-panel {
    border-top: 1px solid #e0e0e0;
    margin-top: 12px;
    padding-top: 8px;
}

.crm-call-wa-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 13px;
    font-weight: 600;
    color: #555;
    cursor: pointer;
    user-select: none;
}

.crm-call-wa-toggle {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    color: #888;
    padding: 0 4px;
    line-height: 1;
}

.crm-call-wa-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 8px 0;
}

.crm-call-wa-chip {
    padding: 4px 10px;
    border-radius: 14px;
    background: #e8f5e9;
    border: 1px solid #a5d6a7;
    font-size: 12px;
    cursor: pointer;
    transition: background 0.15s;
}

.crm-call-wa-chip:hover {
    background: #c8e6c9;
}

.crm-call-wa-chip--resource {
    background: #e3f2fd;
    border-color: #90caf9;
}

.crm-call-wa-chip--resource:hover {
    background: #bbdefb;
}

.crm-call-wa-chip--selected {
    background: #a5d6a7 !important;
    border-color: #66bb6a !important;
}

.crm-call-wa-textarea {
    width: 100%;
    box-sizing: border-box;
    font-size: 13px;
    margin-top: 6px;
    border: 1px solid #ccc;
    border-radius: 6px;
    padding: 6px;
    resize: vertical;
    font-family: inherit;
}

#crm-call-wa-send {
    margin-top: 6px;
    width: 100%;
    background: #25D366;
    color: white;
    border: none;
    border-radius: 6px;
    padding: 7px;
    cursor: pointer;
    font-size: 13px;
    font-weight: 600;
    transition: background 0.15s;
}

#crm-call-wa-send:hover:not(:disabled) {
    background: #1da851;
}

#crm-call-wa-send:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.crm-call-wa-status {
    font-size: 11px;
    color: #666;
    margin-top: 4px;
    min-height: 16px;
}

/* ============================================================================
   ISTORICUL WHATSAPP ÎN FIȘA LEAD (secțiune colapsată în modalul CRM)
   ============================================================================ */
.lead-wa-history-container {
    max-height: 420px;
    overflow-y: auto;
    padding: 8px 8px 0;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.lead-wa-empty,
.lead-wa-error,
.lead-wa-loading {
    color: #888;
    font-size: 13px;
    text-align: center;
    padding: 12px;
}

.lead-wa-error {
    color: #dc2626;
}

/* ============================================================================
   LEAD WA COMPOSER — compositor mesaj liber + chipuri template-uri
   (afișat în secțiunea #lead-wa-history-section din fereastra detalii lead)
   ============================================================================ */

.lead-wa-composer {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 8px 8px 4px;
    border-top: 1px solid #e2e8f0;
    margin-top: 6px;
}

.lead-wa-composer__input {
    flex: 1;
    min-height: 36px;
    max-height: 100px;
    padding: 7px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 16px;
    font-size: 13px;
    line-height: 1.4;
    resize: none;
    font-family: inherit;
    background: #fff;
    color: #1e293b;
    transition: border-color 0.15s;
}

.lead-wa-composer__input:focus {
    outline: none;
    border-color: #25d366;
}

.lead-wa-composer__btn {
    flex-shrink: 0;
    padding: 7px 14px;
    background: linear-gradient(135deg, #25d366 0%, #128c7e 100%);
    color: #fff;
    border: none;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: opacity 0.15s, transform 0.1s;
}

.lead-wa-composer__btn:hover:not(:disabled) {
    opacity: 0.9;
    transform: translateY(-1px);
}

.lead-wa-composer__btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.lead-wa-composer--locked {
    width: 100%;
    font-size: 12px;
    color: #64748b;
    text-align: center;
    padding: 6px 4px;
    line-height: 1.5;
}

/* Selector program CRM — apare între compositor și chipuri */
.lead-wa-program-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 5px 8px 4px;
    border-top: 1px solid #e2e8f0;
}

.lead-wa-program-label {
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    flex-shrink: 0;
}

.lead-wa-program-select {
    flex: 1;
    min-width: 0;
    padding: 3px 8px;
    border: 1px solid #cbd5e1;
    border-radius: 6px;
    font-size: 12px;
    background: #fff;
    color: #1e293b;
    cursor: pointer;
}

.lead-wa-program-select:focus {
    outline: none;
    border-color: #25d366;
    box-shadow: 0 0 0 2px rgba(37, 211, 102, 0.15);
}

/* Container chipuri template-uri aprobate */
.lead-wa-tpl-chips {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    padding: 4px 8px 8px;
}

.lead-wa-tpl-label {
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    width: 100%;
    margin-bottom: 2px;
}

.lead-wa-tpl-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: #f0fdf4;
    border: 1px solid #86efac;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 500;
    color: #15803d;
    cursor: pointer;
    white-space: nowrap;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}

.lead-wa-tpl-chip:hover:not(:disabled) {
    background: #dcfce7;
    border-color: #4ade80;
    transform: translateY(-1px);
}

.lead-wa-tpl-chip:active {
    transform: translateY(0);
}

.lead-wa-tpl-chip:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.lead-wa-tpl-chip--approved {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
}

.lead-wa-tpl-chip--approved:hover:not(:disabled) {
    background: #dbeafe;
    border-color: #60a5fa;
}

/* Lead modal WhatsApp panel — layout stabil pe mobil */
#lead-details-modal .lead-tab-panel[data-panel="whatsapp"] {
    height: 100%;
}

#lead-details-modal #lead-wa-history-section {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
}

#lead-details-modal .lead-wa-history-container {
    flex: 1;
    min-height: 0;
    max-height: none;
    padding-bottom: 6px;
}

#lead-details-modal .lead-wa-composer {
    position: sticky;
    bottom: 0;
    z-index: 2;
    background: #ffffff;
}

@media (max-width: 767px) {
    #lead-details-modal .lead-wa-composer {
        padding: 8px 4px 6px;
    }

    #lead-details-modal .lead-wa-composer__btn {
        min-height: 38px;
        padding: 8px 12px;
    }

    #lead-details-modal .lead-wa-tpl-chips {
        padding: 6px 4px 10px;
    }
}
