﻿/* ===== WhatsApp-style thread UI ===== */

/* ── Topbar ── */
.wa-topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 10px;
    /* Wrap so the heading + action buttons stack onto a second line on narrow
       screens instead of pushing the last buttons off-screen. (MOB B-H1) */
    flex-wrap: wrap;
}

.wa-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap; /* keep every action tappable at phone widths (MOB B-H1) */
}

/* ── Back button ── */
.wa-back-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border-radius: 8px;
    background: rgba(0,0,0,0.06);
    color: inherit;
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
    transition: background 0.15s;
}

    .wa-back-btn:hover {
        background: rgba(0,0,0,0.13);
    }

/* ── Filter bar ── */
.wa-filter {
    margin-top: 0;
    padding: 10px 14px;
    border: 1px solid #ddd;
    border-radius: 10px;
    background: #fff;
    width: 100%;
}

.wa-filter-grid {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
}

    .wa-filter-grid > div {
        display: flex;
        flex-direction: column;
        gap: 4px;
        min-width: 150px;
    }

.wa-filter label {
    font-size: .82em;
    font-weight: 500;
    opacity: .7;
    margin: 0;
    white-space: nowrap;
}

.wa-filter input[type="date"],
.wa-filter input[type="number"],
.wa-filter input[type="text"] {
    padding: 6px 9px;
    border: 1px solid #d0d0d0;
    border-radius: 7px;
    font-size: 0.9rem;
    background: #fafafa;
    outline: none;
    transition: border-color 0.15s;
}

    .wa-filter input[type="date"]:focus,
    .wa-filter input[type="number"]:focus,
    .wa-filter input[type="text"]:focus {
        border-color: var(--wa-teal);
        background: #fff;
    }

/* Push refresh button to the far right */
.wa-filter-grid .wa-filter-actions {
    margin-left: auto !important;
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    min-width: unset !important;
}

    .wa-filter-actions button[type="submit"] {
        padding: 6px 12px;
        border: none;
        border-radius: 8px;
        background: #f0f0f0;
        font-weight: 500;
        font-size: 0.9rem;
        cursor: pointer;
        transition: background 0.2s, color 0.2s;
        white-space: nowrap;
    }

        .wa-filter-actions button[type="submit"]:hover {
            background: #e0e0e0;
        }

        .wa-filter-actions button[type="submit"].is-green {
            background: #22c55e;
            color: #fff;
        }

.wa-filter-error {
    color: #b00020;
    font-size: 0.88rem;
    align-self: center;
}

.wa-filter-flash {
    margin-top: 8px;
    font-size: 0.88rem;
    padding: 6px 10px;
    border-radius: 6px;
    background: #f0fdf4;
    color: #166534;
    border: 1px solid #bbf7d0;
}

    .wa-filter-flash.error {
        background: #fff1f2;
        color: #9f1239;
        border-color: #fecdd3;
    }

/* ── Thread wrapper ── */
.wa-thread-wrap {
    margin-top: 14px;
    width: 100%;
    max-width: none;
    border: 1px solid #e2e2e2;
    border-radius: 12px;
    overflow: hidden;
    background: #f6f6f6;
    position: relative;
}

/* ── Thread header ── */
.wa-thread-header {
    padding: 12px 14px;
    border-bottom: 1px solid #e5e5e5;
    background: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.wa-header-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.wa-header-text {
    min-width: 0;
}

.wa-recipient {
    font-weight: 600;
}

.wa-lastseen {
    font-size: .9em;
    opacity: .75;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wa-count {
    font-size: .9em;
    opacity: .75;
    white-space: nowrap;
}

/* ── Avatar ── */
.wa-avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--wa-teal);
    color: #fff;
    flex-shrink: 0;
}

/* ── Send Template button ── */
.wa-send-template-btn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px 6px 9px;
    border-radius: 8px;
    background: var(--wa-teal);
    color: var(--wa-btn-text);
    border: none;
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: background 0.15s;
}

    .wa-send-template-btn:hover {
        background: var(--wa-teal-deep);
    }

/* ── Messages pane ── */
.wa-messages {
    padding: 14px;
    padding-bottom: 110px;
    height: calc(100vh - 330px);
    min-height: 360px;
    overflow-y: auto;
    background: radial-gradient(circle at 20px 20px, rgba(0,0,0,0.035) 2px, transparent 3px) 0 0/44px 44px, radial-gradient(circle at 6px 32px, rgba(0,0,0,0.025) 1px, transparent 2px) 0 0/44px 44px, linear-gradient(to bottom, rgba(255,255,255,0.75), rgba(255,255,255,0.75));
}

@media (max-width: 640px) {
    .wa-messages {
        height: calc(100vh - 360px);
    }
}

/* ── Message rows ── */
.wa-row {
    display: flex;
    margin: 8px 0;
    align-items: flex-end;
}

    .wa-row.inbound {
        justify-content: flex-start;
    }

    .wa-row.outbound {
        justify-content: flex-end;
    }

/* ── Bubbles ── */
.wa-bubble {
    max-width: 100%;
    display: inline-block;
    padding: 10px 12px;
    border-radius: 14px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.06);
    line-height: 1.35;
    word-wrap: break-word;
    position: relative;
    border: 1px solid rgba(0,0,0,0.04);
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
}

    .wa-bubble.inbound {
        background: #fff;
        border-top-left-radius: 6px;
    }

    .wa-bubble.outbound {
        background: var(--wa-bubble-out);
        border-top-right-radius: 6px;
    }

    .wa-bubble.inbound::after {
        content: "";
        position: absolute;
        left: -7px;
        bottom: 10px;
        width: 0;
        height: 0;
        border-top: 7px solid transparent;
        border-bottom: 7px solid transparent;
        border-right: 7px solid #fff;
    }

    .wa-bubble.outbound::after {
        content: "";
        position: absolute;
        right: -7px;
        bottom: 10px;
        width: 0;
        height: 0;
        border-top: 7px solid transparent;
        border-bottom: 7px solid transparent;
        border-left: 7px solid var(--wa-bubble-out);
    }

/* ── Template quick-reply buttons (below bubble, full-width) ── */

/* Outbound row that carries template buttons stacks vertically, right-aligned */
.wa-row.outbound.wa-has-btns {
    flex-direction: column;
    align-items: flex-end;
    gap: 0;
}

/* Cancel the auto left-margin on the details when the row handles alignment */
.wa-row.outbound.wa-has-btns > .wa-details.outbound {
    margin-left: 0;
}

.wa-tpl-buttons {
    display: flex;
    flex-direction: column;
    border-top: 1px solid rgba(0,0,0,0.15);
    background: var(--wa-bubble-out);
    border-radius: 0 0 14px 14px;
    overflow: hidden;
    max-width: 55%;
    align-self: flex-end;
}

.wa-tpl-button {
    padding: 9px 12px;
    text-align: center;
    border: none;
    border-bottom: 1px solid rgba(0,0,0,0.06);
    color: var(--wa-navy-deep);
    font-size: .88em;
    font-weight: 500;
    background: none;
    cursor: default;
}

.wa-tpl-button:last-child {
    border-bottom: none;
}

/* ── Carousel bubble (shared by the chat thread and the Send preview) ──
   Rendered by _WaCarouselBubble. Kept as classes (not inline styles) so dark mode can
   theme the card surfaces — inline colours were unreadable on the dark bubble. The
   container caps its width and scrolls horizontally through cards like WhatsApp. */
.wa-carousel {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    max-width: min(100%, 540px);
    padding: 4px 0 6px;
}

.wa-carousel-card {
    min-width: 170px;
    max-width: 170px;
    flex-shrink: 0;
    background: #fff;
    border: 1px solid rgba(0,0,0,0.10);
    border-radius: 8px;
    overflow: hidden;
}

.wa-carousel-card-media {
    height: 96px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #c8e6c9;
    color: #4b5563;
    font-size: 1.6rem;
    overflow: hidden;
}

.wa-carousel-card-media img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.wa-carousel-card-body {
    padding: 6px 8px;
    font-size: .8rem;
    white-space: pre-wrap;
    color: var(--wa-text);
}

.wa-carousel-card-btns {
    border-top: 1px solid rgba(0,0,0,0.06);
    padding: 4px 8px 6px;
}

.wa-carousel-card-btn {
    font-size: .75rem;
    color: var(--wa-navy-deep);
    padding: 2px 0;
}

.wa-carousel-card-nomedia {
    color: #dc3545;
    font-size: .72rem;
    padding: 0 8px 6px;
}

/* Compact variant used inside the Send-template modal preview strip. */
.wa-carousel--sm .wa-carousel-card {
    min-width: 130px;
    max-width: 130px;
}

.wa-carousel--sm .wa-carousel-card-media {
    height: 44px;
    font-size: 1rem;
}

/* Compact preview truncates card body to one line (overrides the pre-wrap above so
   Bootstrap's .text-truncate ellipsis works). */
.wa-carousel--sm .wa-carousel-card-body {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* When a bubble has buttons below it: flatten the bottom corners and hide the
   directional tail — the tail sits at bubble bottom-right which looks wrong
   when a button strip is directly attached underneath */
.wa-bubble.wa-bubble-has-btns {
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
}

.wa-bubble.wa-bubble-has-btns::after {
    display: none;
}

/* ── Message meta (time / ticks) ── */
.wa-meta {
    margin-top: 6px;
    font-size: .82em;
    opacity: .75;
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    align-items: center;
    white-space: nowrap;
}

    .wa-meta .wa-icon {
        opacity: .85;
        margin-left: 2px;
        margin-right: 2px;
    }

.wa-ticks {
    font-size: 1em;
    letter-spacing: -1px;
}

    .wa-ticks.read {
        color: #0b57d0;
    }

/* ── Details / expand ── */
.wa-details {
    flex: 0 0 auto;
    max-width: 55%;
    display: inline-flex;
    flex-direction: column;
    width: fit-content;
}

.wa-row.inbound .wa-details {
    margin-right: auto;
    align-items: flex-start;
}

.wa-row.outbound .wa-details {
    margin-left: auto;
    align-items: flex-end;
}

.wa-details > summary {
    list-style: none;
    cursor: pointer;
    margin: 0;
    width: fit-content;
    max-width: 100%;
}

    .wa-details > summary::-webkit-details-marker {
        display: none;
    }

    .wa-details > summary::marker {
        content: "";
    }

/* ── Media (images) ── */
.wa-media {
    margin: 6px 0 2px;
}

.wa-media img {
    display: block;
    max-width: 260px;
    max-height: 300px;
    border-radius: 8px;
    cursor: zoom-in;
    object-fit: contain;
}

.wa-expand {
    margin-top: 6px;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(0,0,0,0.08);
    background: rgba(255,255,255,0.9);
    font-size: 0.92em;
    line-height: 1.35;
}

/* ── Date pills ── */
.wa-date {
    margin: 12px 0;
    display: flex;
    justify-content: center;
    pointer-events: none;
}

    .wa-date > div {
        font-size: .85em;
        padding: 6px 10px;
        border-radius: 999px;
        background: rgba(0,0,0,0.08);
        opacity: .85;
    }

.wa-sticky-date {
    position: sticky;
    top: 10px;
    z-index: 10;
    display: flex;
    justify-content: center;
    pointer-events: none;
    margin: 10px 0;
}

    .wa-sticky-date > div {
        font-size: .85em;
        padding: 6px 10px;
        border-radius: 999px;
        background: rgba(0,0,0,0.10);
        opacity: .9;
    }

/* ── Empty state ── */
.wa-empty {
    padding: 18px;
    opacity: .75;
    background: #fff;
}

/* ── Compose bar ── */
.wa-compose {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    padding: 12px;
    background: rgba(255,255,255,0.98);
    border-top: 1px solid rgba(0,0,0,0.08);
    display: flex;
    gap: 10px;
    align-items: center;
}

    .wa-compose input[type="text"] {
        flex: 1 1 auto;
        padding: 12px 14px;
        border-radius: 999px;
        border: 1px solid rgba(0,0,0,0.14);
        outline: none;
    }

    .wa-compose button[type="submit"] {
        flex-shrink: 0;
        border: none;
        border-radius: 999px;
        padding: 12px 14px;
        cursor: pointer;
        box-shadow: 0 6px 16px rgba(0,0,0,0.12);
    }

.wa-attach-btn {
    flex-shrink: 0;
    background: transparent;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    padding: 6px;
    border-radius: 50%;
    line-height: 1;
    opacity: .6;
    transition: opacity .15s, background .15s;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}
.wa-attach-btn:hover { opacity: 1; background: rgba(0,0,0,0.06); }
.wa-attach-btn.has-file { opacity: 1; color: #0078d4; }

.wa-media-preview {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: .82rem;
    padding: 5px 12px;
    background: #f0f4ff;
    border-radius: 999px;
    border: 1px solid #c7d3f5;
    color: #333;
    max-width: 280px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.10);
}
.wa-media-preview span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.wa-media-preview button { background: none; border: none; cursor: pointer; font-size: .85rem; padding: 0 2px; opacity: .6; flex-shrink: 0; }
.wa-media-preview button:hover { opacity: 1; }

/* ── Re-open FAB ── */
.wa-fab {
    position: absolute;
    right: 16px;
    bottom: 16px;
    z-index: 20;
}

    .wa-fab button {
        border: none;
        border-radius: 999px;
        padding: 12px 14px;
        cursor: pointer;
        box-shadow: 0 6px 16px rgba(0,0,0,0.18);
    }

        .wa-fab button:hover {
            transform: translateY(-1px);
        }

/* ── Modal backdrop ── */
.wa-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Modal box ── */
.wa-modal {
    background: #fff;
    border-radius: 12px;
    width: min(560px, 95vw);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 32px rgba(0,0,0,0.22);
    overflow: hidden;
}

.wa-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
}

.wa-modal-close {
    background: none;
    border: none;
    font-size: 1.1rem;
    cursor: pointer;
    opacity: 0.5;
    line-height: 1;
    padding: 4px 6px;
    border-radius: 6px;
    transition: opacity 0.15s, background 0.15s;
}

    .wa-modal-close:hover {
        opacity: 1;
        background: rgba(0,0,0,0.07);
    }

.wa-modal-body {
    padding: 20px;
    overflow-y: auto;
}

.wa-modal-cancel {
    padding: 7px 16px;
    border-radius: 8px;
    border: 1px solid #ccc;
    background: #f5f5f5;
    cursor: pointer;
    font-size: 0.9rem;
}

    .wa-modal-cancel:hover {
        background: #eaeaea;
    }

/* ── Refresh countdown badge ── */
.wa-refresh-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 0.78rem;
    opacity: 0.55;
    user-select: none;
}

/* ── ChatLog table ── */
.wa-dash-table-wrap {
    margin-top: 14px;
    border: 1px solid #e2e2e2;
    border-radius: 12px;
    /* overflow-x:auto (was hidden) so a wide table scrolls sideways on mobile instead of being
       clipped; the page body itself never scrolls horizontally. (AU2) */
    overflow-x: auto;
    background: #fff;
}

.wa-dash-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92em;
}

    .wa-dash-table thead tr {
        background: #f5f5f5;
    }

    .wa-dash-table th {
        text-align: left;
        padding: 9px 10px;
        border-bottom: 2px solid #e0e0e0;
        font-weight: 600;
        white-space: nowrap;
    }

    .wa-dash-table td {
        padding: 7px 10px;
        border-bottom: 1px solid #ececec;
        vertical-align: middle;
    }

    .wa-dash-table tbody tr:last-child td {
        border-bottom: none;
    }

    .wa-dash-table tbody tr:hover {
        filter: brightness(0.97);
    }

.wa-dash-nowrap {
    white-space: nowrap;
}

.wa-dash-center {
    text-align: center;
    font-size: 1.1em;
}

.wa-dash-sub {
    font-size: 0.85em;
    opacity: 0.65;
}

.wa-dash-preview {
    max-width: 320px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.wa-dash-action {
    white-space: nowrap;
}

.wa-thread-link {
    display: inline-block;
    padding: 3px 10px;
    background: #0078d4;
    color: #fff;
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.82em;
    white-space: nowrap;
    transition: background 0.15s;
}

    .wa-thread-link:hover {
        background: #005fa3;
    }

/* ── Filter select (shared) ── */
.wa-filter-select {
    padding: 6px 9px;
    border: 1px solid #d0d0d0;
    border-radius: 7px;
    font-size: 0.9rem;
    background: #fafafa;
    outline: none;
    transition: border-color 0.15s;
    width: 100%;
}

    .wa-filter-select:focus {
        border-color: var(--wa-teal);
        background: #fff;
    }

/* ── Templates grid (card) view ── */
.wa-tpl-card {
    width: 320px;
}

    /* The card body is the WhatsApp chat wallpaper; mirrors the EditTemplate preview. */
    .wa-tpl-card .wa-tpl-wallpaper {
        --wa-wallpaper-fade: rgba(255,255,255,0.9);
        background: radial-gradient(circle at 20px 20px, rgba(0,0,0,0.035) 2px, transparent 3px) 0 0/44px 44px, radial-gradient(circle at 6px 32px, rgba(0,0,0,0.025) 1px, transparent 2px) 0 0/44px 44px, linear-gradient(to bottom, rgba(255,255,255,0.75), rgba(255,255,255,0.75));
    }

/* Clamp tall bubbles so cards stay roughly even; fade the clipped bottom edge. */
.wa-tpl-preview-clip {
    position: relative;
    max-height: 230px;
    overflow: hidden;
    padding: 14px 18px 14px 14px;
}

    .wa-tpl-preview-clip::after {
        content: "";
        position: absolute;
        left: 0;
        right: 0;
        bottom: 0;
        height: 32px;
        background: linear-gradient(to bottom, transparent, var(--wa-wallpaper-fade));
        pointer-events: none;
    }

.wa-tpl-empty {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 90px;
    padding: 14px;
    color: #999;
    font-size: .9rem;
    text-align: center;
}