/* ═══════════════════════════════════════════════════════════════
   WhatsApp Module — Zen Design System
   ═══════════════════════════════════════════════════════════════ */

/* ── Tabs ────────────────────────────────────────────────────── */
.zen-wa-tabs {
    display: flex;
    gap: 0.25rem;
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-radius: var(--zen-radius-xl, 1rem);
    padding: 0.375rem;
    border: 1px solid rgba(0, 0, 0, 0.04);
}

.zen-wa-tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    border: none;
    background: transparent;
    border-radius: var(--zen-radius, 0.75rem);
    cursor: pointer;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--zen-text-muted, #6b7280);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    font-family: var(--zen-font-body, 'Inter', sans-serif);
}

.zen-wa-tab:hover {
    background: rgba(62, 109, 102, 0.06);
    color: var(--zen-text, #1a2332);
}

.zen-wa-tab.active {
    background: #fff;
    color: var(--zen-primary, #3E6D66);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
    font-weight: 600;
}

.zen-wa-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.375rem;
    border-radius: 9999px;
    background: #25d366;
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 700;
    line-height: 1;
}

/* ── Main Layout: Conversations ──────────────────────────────── */
.zen-wa-layout {
    display: flex;
    gap: 1.25rem;
    min-height: 600px;
    max-height: calc(100vh - 280px);
}

.zen-wa-sidebar {
    width: 360px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.zen-wa-chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ── Search ──────────────────────────────────────────────────── */
.zen-wa-search {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

.zen-wa-search-input {
    flex: 1;
    border: none;
    outline: none;
    background: transparent;
    font-size: 0.875rem;
    font-family: var(--zen-font-body, 'Inter', sans-serif);
    color: var(--zen-text, #1a2332);
}

.zen-wa-search-input::placeholder {
    color: var(--zen-text-muted, #6b7280);
}

/* ── Contact List ────────────────────────────────────────────── */
.zen-wa-contact-list {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.08) transparent;
}

.zen-wa-contact-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border-bottom: 1px solid rgba(0, 0, 0, 0.03);
}

.zen-wa-contact-item:hover {
    background: rgba(62, 109, 102, 0.04);
}

.zen-wa-contact-item.active {
    background: rgba(62, 109, 102, 0.08);
    border-left: 3px solid var(--zen-primary, #3E6D66);
}

.zen-wa-contact-avatar {
    background: linear-gradient(135deg, #25d366, #128c7e) !important;
    color: #fff !important;
    font-family: var(--zen-font-display, 'Playfair Display'), serif !important;
    font-weight: 600 !important;
    font-size: 1rem !important;
}

.zen-wa-contact-info {
    flex: 1;
    min-width: 0;
}

.zen-wa-contact-name {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--zen-text, #1a2332);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.zen-wa-patient-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    background: rgba(62, 109, 102, 0.1);
    color: var(--zen-primary, #3E6D66);
    font-size: 0.6875rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.zen-wa-contact-preview {
    font-size: 0.8125rem;
    color: var(--zen-text-muted, #6b7280);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 0.125rem;
    margin-top: 0.125rem;
}

.zen-wa-contact-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.375rem;
    flex-shrink: 0;
}

.zen-wa-contact-time {
    font-size: 0.6875rem;
    color: var(--zen-text-muted, #6b7280);
    white-space: nowrap;
}

.zen-wa-unread-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.25rem;
    height: 1.25rem;
    padding: 0 0.375rem;
    border-radius: 9999px;
    background: #25d366;
    color: #fff;
    font-size: 0.6875rem;
    font-weight: 700;
}

.zen-wa-empty-contacts {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    padding: 3rem 2rem;
    color: var(--zen-text-muted, #6b7280);
    font-size: 0.875rem;
}

/* ── Chat Header ─────────────────────────────────────────────── */
.zen-wa-chat-header {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 0.875rem 1.25rem;
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
    background: rgba(255, 255, 255, 0.5);
}

.zen-wa-chat-header-info {
    flex: 1;
}

.zen-wa-chat-header-name {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--zen-text, #1a2332);
    display: block;
}

.zen-wa-chat-header-phone {
    font-size: 0.75rem;
    color: var(--zen-text-muted, #6b7280);
}

.zen-wa-chat-header-actions {
    display: flex;
    gap: 0.25rem;
}

/* ── Messages Area ───────────────────────────────────────────── */
.zen-wa-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.375rem;
    background: linear-gradient(135deg, #f5f3ee 0%, #f0ede6 100%);
    scrollbar-width: thin;
}

.zen-wa-msg {
    display: flex;
    max-width: 75%;
}

.zen-wa-msg.outbound {
    align-self: flex-end;
}

.zen-wa-msg.inbound {
    align-self: flex-start;
}

.zen-wa-msg-bubble {
    padding: 0.5rem 0.75rem;
    border-radius: 0.75rem;
    position: relative;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.zen-wa-msg.outbound .zen-wa-msg-bubble {
    background: #dcf8c6;
    border-bottom-right-radius: 0.25rem;
}

.zen-wa-msg.inbound .zen-wa-msg-bubble {
    background: #fff;
    border-bottom-left-radius: 0.25rem;
}

.zen-wa-msg-text {
    margin: 0;
    font-size: 0.875rem;
    line-height: 1.45;
    color: var(--zen-text, #1a2332);
    word-wrap: break-word;
}

.zen-wa-msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 0.25rem;
    margin-top: 0.125rem;
}

.zen-wa-msg-time {
    font-size: 0.6875rem;
    color: rgba(0, 0, 0, 0.4);
}

.zen-wa-msg-status {
    color: rgba(0, 0, 0, 0.3) !important;
}

.zen-wa-msg.outbound .zen-wa-msg-status {
    color: #53bdeb !important;
}

.zen-wa-bot-label {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--zen-primary, #3E6D66);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.zen-wa-no-messages {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    height: 100%;
    color: var(--zen-text-muted, #6b7280);
    text-align: center;
}

.zen-wa-no-messages p {
    font-size: 0.9375rem;
    font-weight: 500;
    margin: 0;
}

.zen-wa-no-messages span {
    font-size: 0.8125rem;
}

/* ── Input Area ──────────────────────────────────────────────── */
.zen-wa-input-area {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1.25rem;
    border-top: 1px solid rgba(0, 0, 0, 0.04);
    background: rgba(255, 255, 255, 0.8);
}

.zen-wa-message-input {
    flex: 1;
    border: 1px solid rgba(0, 0, 0, 0.08);
    border-radius: 1.5rem;
    padding: 0.625rem 1rem;
    font-size: 0.875rem;
    font-family: var(--zen-font-body, 'Inter', sans-serif);
    color: var(--zen-text, #1a2332);
    background: #fff;
    outline: none;
    transition: border-color 0.2s;
}

.zen-wa-message-input:focus {
    border-color: var(--zen-primary, #3E6D66);
}

.zen-wa-message-input::placeholder {
    color: var(--zen-text-muted, #6b7280);
}

.zen-wa-send-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    border: none;
    background: #e5e7eb;
    color: #9ca3af;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.zen-wa-send-btn.active {
    background: #25d366;
    color: #fff;
}

.zen-wa-send-btn.active:hover {
    background: #1da851;
    transform: scale(1.05);
}

.zen-wa-send-btn:disabled {
    cursor: not-allowed;
    opacity: 0.5;
}

/* ── No Chat Selected ────────────────────────────────────────── */
.zen-wa-no-chat {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    height: 100%;
    text-align: center;
    padding: 3rem;
}

.zen-wa-no-chat h3 {
    font-family: var(--zen-font-display, 'Playfair Display'), serif;
    font-size: 1.375rem;
    font-weight: 600;
    color: var(--zen-text, #1a2332);
    margin: 0;
}

.zen-wa-no-chat p {
    font-size: 0.875rem;
    color: var(--zen-text-muted, #6b7280);
    margin: 0;
}

.zen-wa-no-chat-icon {
    opacity: 0.6;
}

/* ── Bots Grid ───────────────────────────────────────────────── */
.zen-wa-bots-grid,
.zen-wa-auto-grid {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.zen-wa-bots-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.zen-wa-section-title {
    font-family: var(--zen-font-display, 'Playfair Display'), serif;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--zen-text, #1a2332);
    margin: 0;
}

.zen-wa-section-desc {
    font-size: 0.8125rem;
    color: var(--zen-text-muted, #6b7280);
    margin: 0.25rem 0 0;
}

/* ── Bot Card ────────────────────────────────────────────────── */
.zen-wa-bot-card,
.zen-wa-auto-card {
    padding: 0;
    overflow: hidden;
}

.zen-wa-bot-header,
.zen-wa-auto-header {
    display: flex;
    align-items: center;
    gap: 0.875rem;
    padding: 1.25rem;
}

.zen-wa-bot-icon,
.zen-wa-auto-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 3rem;
    height: 3rem;
    border-radius: var(--zen-radius, 0.75rem);
    background: rgba(0, 0, 0, 0.04);
    color: var(--zen-text-muted, #6b7280);
    flex-shrink: 0;
    transition: all 0.25s ease;
}

.zen-wa-bot-icon.active,
.zen-wa-auto-icon.active {
    background: rgba(37, 211, 102, 0.1);
    color: #25d366;
}

.zen-wa-bot-info,
.zen-wa-auto-info {
    flex: 1;
    min-width: 0;
}

.zen-wa-bot-name,
.zen-wa-auto-name {
    font-size: 0.9375rem;
    font-weight: 600;
    color: var(--zen-text, #1a2332);
    display: block;
}

.zen-wa-bot-desc,
.zen-wa-auto-trigger {
    font-size: 0.8125rem;
    color: var(--zen-text-muted, #6b7280);
    display: block;
    margin-top: 0.125rem;
}

.zen-wa-bot-actions {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-shrink: 0;
}

/* ── Bot Rules ───────────────────────────────────────────────── */
.zen-wa-bot-rules {
    padding: 0 1.25rem 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.zen-wa-rules-label {
    font-size: 0.6875rem;
    font-weight: 700;
    color: var(--zen-text-muted, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.zen-wa-rule-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    background: rgba(0, 0, 0, 0.02);
    border-radius: var(--zen-radius, 0.75rem);
}

.zen-wa-rule-keywords {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    flex-shrink: 0;
}

.zen-wa-keyword-chip {
    display: inline-flex;
    align-items: center;
    padding: 0.125rem 0.5rem;
    border-radius: 9999px;
    background: rgba(62, 109, 102, 0.1);
    color: var(--zen-primary, #3E6D66);
    font-size: 0.75rem;
    font-weight: 500;
}

.zen-wa-rule-response {
    flex: 1;
    font-size: 0.8125rem;
    color: var(--zen-text, #1a2332);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.zen-wa-bot-empty-rules {
    padding: 0 1.25rem 1.25rem;
    font-size: 0.8125rem;
    color: var(--zen-text-muted, #6b7280);
}

.zen-wa-ai-badge {
    display: flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 1.25rem;
    border-top: 1px solid rgba(0, 0, 0, 0.04);
    font-size: 0.75rem;
    font-weight: 600;
    color: #D4AF37;
}

/* ── Auto Message Card ───────────────────────────────────────── */
.zen-wa-auto-preview {
    padding: 0 1.25rem 1rem;
}

.zen-wa-auto-preview-label {
    font-size: 0.6875rem;
    font-weight: 700;
    color: var(--zen-text-muted, #6b7280);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: block;
    margin-bottom: 0.375rem;
}

.zen-wa-auto-preview p {
    font-size: 0.8125rem;
    color: var(--zen-text, #1a2332);
    margin: 0;
    line-height: 1.5;
    background: rgba(0, 0, 0, 0.02);
    padding: 0.625rem 0.875rem;
    border-radius: var(--zen-radius, 0.75rem);
    border-left: 3px solid var(--zen-primary, #3E6D66);
}

.zen-wa-auto-offset {
    padding: 0.5rem 1.25rem;
    border-top: 1px solid rgba(0, 0, 0, 0.04);
    font-size: 0.75rem;
    color: var(--zen-text-muted, #6b7280);
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

/* ── Rules Editor ────────────────────────────────────────────── */
.zen-wa-rules-editor {
    margin-top: 1.5rem;
    padding-top: 1.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.zen-wa-rules-editor-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
}

.zen-wa-rule-editor-row {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 1rem;
    background: rgba(0, 0, 0, 0.02);
    border-radius: var(--zen-radius, 0.75rem);
    margin-bottom: 0.75rem;
}

.zen-wa-rule-editor-fields {
    flex: 1;
    display: flex;
    gap: 0.75rem;
}

/* ── Settings ────────────────────────────────────────────────── */
.zen-wa-settings-section {
    margin-bottom: 1.25rem;
}

.zen-wa-settings-title {
    font-family: var(--zen-font-display, 'Playfair Display'), serif;
    font-size: 1rem;
    font-weight: 600;
    color: var(--zen-text, #1a2332);
    margin: 0 0 0.25rem;
}

.zen-wa-settings-desc {
    font-size: 0.8125rem;
    color: var(--zen-text-muted, #6b7280);
    margin: 0;
}

.zen-wa-webhook-url {
    padding: 0.625rem 0.875rem;
    background: rgba(0, 0, 0, 0.03);
    border-radius: var(--zen-radius, 0.75rem);
    margin: 0.5rem 0;
}

.zen-wa-webhook-url code {
    font-size: 0.8125rem;
    color: var(--zen-primary, #3E6D66);
    word-break: break-all;
}

/* ── Placeholders ────────────────────────────────────────────── */
.zen-wa-placeholders {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.5rem;
}

.zen-wa-placeholder-label {
    font-size: 0.75rem;
    color: var(--zen-text-muted, #6b7280);
}

/* ── Mobile Chat ─────────────────────────────────────────────── */
.zen-wa-mobile-chat {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
}

.zen-wa-mobile-chat-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid rgba(0, 0, 0, 0.04);
}

/* ── Drawer Form Elements ────────────────────────────────────── */
.zen-drawer-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.zen-drawer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 1.5rem 0;
}

.zen-drawer-header h3 {
    font-family: var(--zen-font-display, 'Playfair Display'), serif;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--zen-text, #1a2332);
    margin: 0;
}

.zen-drawer-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
}

.zen-drawer-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(0, 0, 0, 0.06);
}

.zen-form-group {
    margin-bottom: 1.25rem;
}

.zen-form-label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--zen-text, #1a2332);
    margin-bottom: 0.375rem;
}

.zen-form-label-sm {
    display: block;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--zen-text-muted, #6b7280);
    margin-bottom: 0.25rem;
}

.zen-btn-sm {
    padding: 0.375rem 0.75rem !important;
    font-size: 0.8125rem !important;
}

.zen-btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border: none;
    background: transparent;
    border-radius: var(--zen-radius, 0.75rem);
    cursor: pointer;
    color: var(--zen-text-muted, #6b7280);
    transition: all 0.2s ease;
}

.zen-btn-icon:hover {
    background: rgba(0, 0, 0, 0.05);
    color: var(--zen-text, #1a2332);
}

/* ── Dark Theme ──────────────────────────────────────────────── */
.dark-theme .zen-wa-tabs {
    background: rgba(30, 30, 30, 0.7);
    border-color: rgba(255, 255, 255, 0.06);
}

.dark-theme .zen-wa-tab {
    color: #9ca3af;
}

.dark-theme .zen-wa-tab:hover {
    background: rgba(255, 255, 255, 0.05);
    color: #e5e7eb;
}

.dark-theme .zen-wa-tab.active {
    background: rgba(255, 255, 255, 0.08);
    color: #5a9e95;
}

.dark-theme .zen-wa-contact-item:hover {
    background: rgba(255, 255, 255, 0.04);
}

.dark-theme .zen-wa-contact-item.active {
    background: rgba(62, 109, 102, 0.12);
    border-left-color: #5a9e95;
}

.dark-theme .zen-wa-contact-name,
.dark-theme .zen-wa-chat-header-name,
.dark-theme .zen-wa-bot-name,
.dark-theme .zen-wa-auto-name,
.dark-theme .zen-wa-section-title,
.dark-theme .zen-wa-no-chat h3,
.dark-theme .zen-wa-settings-title,
.dark-theme .zen-drawer-header h3,
.dark-theme .zen-form-label {
    color: #f7fafc;
}

.dark-theme .zen-wa-messages {
    background: linear-gradient(135deg, #1a1a1a 0%, #222 100%);
}

.dark-theme .zen-wa-msg.outbound .zen-wa-msg-bubble {
    background: #005c4b;
}

.dark-theme .zen-wa-msg.inbound .zen-wa-msg-bubble {
    background: #2a2a2a;
}

.dark-theme .zen-wa-msg-text {
    color: #e5e7eb;
}

.dark-theme .zen-wa-msg-time {
    color: rgba(255, 255, 255, 0.4);
}

.dark-theme .zen-wa-message-input {
    background: #2a2a2a;
    border-color: rgba(255, 255, 255, 0.08);
    color: #e5e7eb;
}

.dark-theme .zen-wa-send-btn {
    background: #333;
    color: #6b7280;
}

.dark-theme .zen-wa-chat-header,
.dark-theme .zen-wa-input-area {
    background: rgba(30, 30, 30, 0.8);
    border-color: rgba(255, 255, 255, 0.04);
}

.dark-theme .zen-wa-search {
    border-color: rgba(255, 255, 255, 0.04);
}

.dark-theme .zen-wa-search-input {
    color: #e5e7eb;
}

.dark-theme .zen-wa-rule-row,
.zen-wa-rule-editor-row {
    background: rgba(255, 255, 255, 0.03);
}

.dark-theme .zen-wa-bot-icon,
.dark-theme .zen-wa-auto-icon {
    background: rgba(255, 255, 255, 0.06);
}

.dark-theme .zen-wa-mobile-chat-header {
    background: rgba(30, 30, 30, 0.9);
    border-color: rgba(255, 255, 255, 0.04);
}

.dark-theme .zen-wa-webhook-url {
    background: rgba(255, 255, 255, 0.04);
}

.dark-theme .zen-wa-auto-preview p {
    background: rgba(255, 255, 255, 0.03);
    color: #e5e7eb;
    border-left-color: #5a9e95;
}

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 1024px) {
    .zen-wa-layout {
        flex-direction: column;
        max-height: none;
    }

    .zen-wa-sidebar {
        width: 100%;
        max-height: 350px;
    }

    .zen-wa-chat-area {
        min-height: 500px;
    }

    .zen-wa-rule-editor-fields {
        flex-direction: column;
    }
}
