/* Match site/admin font (Vazir) */
@font-face {
    font-family: "Vazir";
    src: url("../fonts/Vazir.woff") format("woff");
    font-display: swap;
}

:root {
    --im-bg: #efeae2;
    --im-sidebar: #fff;
    --im-bubble-in: #ffffff;
    --im-bubble-out: #d9fdd3;
    --im-bubble-out-text: #111b21;
    --im-text: #111b21;
    --im-muted: #667781;
    --im-border: rgba(0, 0, 0, 0.08);
    --im-accent: #00a884;
    --im-danger: #ea4335;
    --im-top: #008069;
    --im-safe-bottom: env(safe-area-inset-bottom, 0px);
    --im-safe-top: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body.wa-body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: #111b21;
    font-family: "Vazir", Tahoma, sans-serif;
    color: var(--im-text);
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
}

.wa-app {
    min-height: 100dvh;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: var(--im-bg);
    max-width: 720px;
    margin: 0 auto;
    position: relative;
}

.wa-list-page { padding-bottom: calc(64px + var(--im-safe-bottom)); }
.wa-room-page { height: 100dvh; height: 100vh; overflow: hidden; }

.wa-top {
    background: var(--im-top);
    color: #fff;
    padding: calc(0.85rem + var(--im-safe-top)) 1rem 0.75rem;
    position: sticky;
    top: 0;
    z-index: 20;
}

.wa-top-title {
    font-size: 1.25rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
}

.wa-filters {
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    padding-bottom: 0.15rem;
}

.wa-filter {
    flex: 0 0 auto;
    text-decoration: none;
    color: rgba(255, 255, 255, 0.85);
    background: rgba(255, 255, 255, 0.12);
    border-radius: 999px;
    padding: 0.35rem 0.8rem;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.wa-filter.is-active {
    background: #fff;
    color: var(--im-top);
    font-weight: 700;
}

.wa-badge {
    background: #25d366;
    color: #fff;
    border-radius: 999px;
    min-width: 1.25rem;
    text-align: center;
    font-size: 0.72rem;
    padding: 0.05rem 0.35rem;
    font-weight: 700;
}

.wa-filter.is-active .wa-badge { background: var(--im-top); }
.wa-badge-muted { background: rgba(255,255,255,0.35); }
.wa-filter.is-active .wa-badge-muted { background: rgba(0,128,105,0.25); color: var(--im-top); }

.wa-search-wrap { padding: 0.65rem 0.85rem; background: #fff; border-bottom: 1px solid var(--im-border); }
.wa-search {
    width: 100%;
    border: none;
    background: #f0f2f5;
    border-radius: 10px;
    padding: 0.7rem 0.9rem;
    font-size: 0.95rem;
    outline: none;
}

.wa-contact-list {
    flex: 1;
    overflow-y: auto;
    background: #fff;
    -webkit-overflow-scrolling: touch;
}

.wa-contact {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    padding: 0.85rem 1rem;
    text-decoration: none;
    color: inherit;
    border-bottom: 1px solid var(--im-border);
}

.wa-contact:active { background: #f5f6f6; }

.wa-avatar {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background: linear-gradient(135deg, #00a884, #008069);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.15rem;
    flex-shrink: 0;
    text-transform: uppercase;
}

.wa-avatar-sm { width: 2.35rem; height: 2.35rem; font-size: 0.95rem; }

.wa-contact-body { flex: 1; min-width: 0; }
.wa-contact-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.5rem;
}
.wa-contact-row + .wa-contact-row { margin-top: 0.2rem; }
.wa-contact-time, .wa-contact-preview {
    color: var(--im-muted);
    font-size: 0.82rem;
}
.wa-contact-preview {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}
.wa-unread {
    background: #25d366;
    color: #fff;
    border-radius: 999px;
    min-width: 1.3rem;
    text-align: center;
    font-size: 0.72rem;
    font-weight: 700;
    padding: 0.1rem 0.4rem;
}

.wa-empty {
    text-align: center;
    color: var(--im-muted);
    padding: 3rem 1rem;
}
.wa-empty i { font-size: 2.4rem; display: block; margin-bottom: 0.6rem; opacity: 0.5; }

.wa-footer {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    justify-content: space-around;
    gap: 0.5rem;
    background: #fff;
    border-top: 1px solid var(--im-border);
    padding: 0.45rem 0.75rem calc(0.45rem + var(--im-safe-bottom));
    max-width: 720px;
    margin: 0 auto;
}

.wa-footer-btn {
    flex: 1;
    text-decoration: none;
    color: var(--im-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    font-size: 0.72rem;
    font-weight: 600;
    padding: 0.35rem;
}
.wa-footer-btn i { font-size: 1.25rem; color: var(--im-accent); }

.wa-room-top {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    background: var(--im-top);
    color: #fff;
    padding: calc(0.55rem + var(--im-safe-top)) 0.65rem 0.55rem;
    flex-shrink: 0;
}

.wa-back {
    color: #fff;
    text-decoration: none;
    font-size: 1.45rem;
    width: 2.2rem;
    height: 2.2rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.wa-room-peer {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    flex: 1;
    min-width: 0;
}
.wa-room-peer strong {
    display: block;
    font-size: 0.98rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wa-room-sub {
    font-size: 0.75rem;
    opacity: 0.85;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.wa-icon-btn {
    border: none;
    background: transparent;
    color: #fff;
    width: 2.2rem;
    height: 2.2rem;
    border-radius: 50%;
    font-size: 1.05rem;
}

.wa-messages {
    flex: 1;
    overflow-y: auto;
    padding: 0.75rem 0.65rem 0.85rem;
    -webkit-overflow-scrolling: touch;
    background:
        linear-gradient(rgba(239, 234, 226, 0.92), rgba(239, 234, 226, 0.92)),
        repeating-linear-gradient(45deg, transparent, transparent 12px, rgba(0,0,0,0.015) 12px, rgba(0,0,0,0.015) 24px);
}

.wa-composer-wrap {
    flex-shrink: 0;
    padding: 0.45rem 0.55rem calc(0.45rem + 58px + var(--im-safe-bottom));
    background: #f0f2f5;
    border-top: 1px solid var(--im-border);
}

.wa-readonly {
    text-align: center;
    padding: 0.75rem;
    color: var(--im-muted);
    background: #fff;
    border-top: 1px solid var(--im-border);
    margin-bottom: calc(58px + var(--im-safe-bottom));
}

.chat-composer {
    display: flex;
    gap: 0.4rem;
    align-items: center;
}

.chat-text-input {
    flex: 1;
    border: none;
    background: #fff;
    border-radius: 24px;
    padding: 0.7rem 0.95rem;
    font-size: 1rem;
    outline: none;
    min-width: 0;
}

.chat-icon-btn,
.chat-send-btn {
    border: none;
    width: 2.6rem;
    height: 2.6rem;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-icon-btn { background: #fff; color: var(--im-muted); }
.chat-send-btn { background: var(--im-accent); color: #fff; }
.chat-icon-btn.is-recording {
    background: var(--im-danger);
    color: #fff;
    animation: chatPulse 1.1s ease-in-out infinite;
}

.chat-row {
    display: flex;
    width: 100%;
    margin-bottom: 0.35rem;
}
.chat-row.is-mine { justify-content: flex-start; }
.chat-row:not(.is-mine) { justify-content: flex-end; }

.chat-bubble {
    position: relative;
    max-width: min(86%, 420px);
    padding: 0.45rem 0.65rem 0.3rem;
    border-radius: 10px;
    background: var(--im-bubble-in);
    color: var(--im-text);
    box-shadow: 0 1px 0.5px rgba(0, 0, 0, 0.08);
    word-break: break-word;
}
.chat-row.is-mine .chat-bubble {
    background: var(--im-bubble-out);
    color: var(--im-bubble-out-text);
    border-bottom-right-radius: 2px;
}
.chat-row:not(.is-mine) .chat-bubble { border-bottom-left-radius: 2px; }

.chat-bubble-text { font-size: 0.98rem; line-height: 1.45; }
.chat-thumb {
    display: block;
    width: 160px;
    max-width: 70vw;
    height: 160px;
    object-fit: cover;
    border-radius: 8px;
    cursor: zoom-in;
}
.chat-voice { display: flex; align-items: center; gap: 0.45rem; min-width: 170px; }
.chat-voice audio { width: 170px; max-width: 100%; height: 34px; }
.chat-bubble-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.55rem;
    margin-top: 0.2rem;
}
.chat-bubble-time { font-size: 0.68rem; opacity: 0.7; }
.chat-ticks {
    display: inline-flex;
    align-items: center;
    margin-inline-start: 0.15rem;
    font-size: 0.85rem;
    line-height: 1;
    opacity: 0.75;
    position: relative;
    width: 1.05rem;
    height: 0.9rem;
}
.chat-ticks i {
    position: absolute;
    top: 0;
}
.chat-ticks i:first-child { left: 0; }
.chat-ticks i:last-child:not(:only-child) { left: 0.28rem; }
.chat-ticks.is-sent { opacity: 0.65; }
.chat-ticks.is-delivered { opacity: 0.8; }
.chat-ticks.is-read { color: #53bdeb; opacity: 1; }
.chat-ticks.is-sending { opacity: 0.55; width: 0.85rem; }
.chat-ticks.is-sending i { position: static; font-size: 0.72rem; }
.chat-ticks.is-failed { color: var(--im-danger); opacity: 1; width: 0.85rem; }
.chat-ticks.is-failed i { position: static; }

.chat-row.is-pending .chat-bubble { opacity: 0.92; }
.chat-row.is-failed .chat-bubble { outline: 1px solid rgba(234, 67, 53, 0.35); }

.chat-media-wrap { position: relative; display: inline-block; }
.chat-send-overlay {
    position: absolute;
    inset: 0;
    border-radius: 8px;
    background: rgba(17, 27, 33, 0.55);
    color: #fff;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-size: 0.78rem;
    font-weight: 600;
    pointer-events: none;
}
.chat-pending-label {
    font-size: 0.72rem;
    opacity: 0.7;
    margin-top: 0.25rem;
}
.chat-spinner {
    width: 1.15rem;
    height: 1.15rem;
    border-radius: 50%;
    border: 2px solid rgba(255,255,255,0.35);
    border-top-color: #fff;
    animation: chatSpin 0.7s linear infinite;
    display: inline-block;
}
.chat-voice .chat-spinner {
    border-color: rgba(0,0,0,0.15);
    border-top-color: var(--im-accent);
}
.chat-row.is-mine .chat-voice .chat-spinner {
    border-color: rgba(0,0,0,0.12);
    border-top-color: #008069;
}
@keyframes chatSpin {
    to { transform: rotate(360deg); }
}

.wa-room-page.is-sending .chat-composer { opacity: 0.85; }

.chat-del-btn {
    border: none;
    background: transparent;
    color: inherit;
    opacity: 0.5;
    font-size: 0.78rem;
    padding: 0;
    cursor: pointer;
}

.chat-rec-bar {
    display: none;
    align-items: center;
    gap: 0.65rem;
    margin-top: 0.45rem;
    padding: 0.5rem 0.65rem;
    border-radius: 14px;
    background: rgba(234, 67, 53, 0.08);
    color: var(--im-danger);
}
.chat-rec-bar.is-on { display: flex; }
.chat-rec-waves { display: flex; align-items: flex-end; gap: 3px; height: 22px; }
.chat-rec-waves span {
    width: 3px;
    border-radius: 99px;
    background: var(--im-danger);
    animation: chatWave 0.9s ease-in-out infinite;
}
.chat-rec-waves span:nth-child(1) { height: 8px; }
.chat-rec-waves span:nth-child(2) { height: 16px; animation-delay: 0.1s; }
.chat-rec-waves span:nth-child(3) { height: 22px; animation-delay: 0.2s; }
.chat-rec-waves span:nth-child(4) { height: 12px; animation-delay: 0.3s; }
.chat-rec-waves span:nth-child(5) { height: 18px; animation-delay: 0.15s; }
.chat-rec-timer { font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3rem; }
.chat-rec-cancel, .chat-rec-send {
    border: none;
    border-radius: 999px;
    padding: 0.35rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
}
.chat-rec-cancel { background: transparent; color: var(--im-muted); margin-inline-start: auto; }
.chat-rec-send { background: var(--im-danger); color: #fff; }

.chat-lightbox {
    position: fixed;
    inset: 0;
    z-index: 4000;
    background: rgba(0, 0, 0, 0.9);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}
.chat-lightbox.is-open { display: flex; }
.chat-lightbox img {
    max-width: 96vw;
    max-height: 90vh;
    border-radius: 10px;
    object-fit: contain;
}
.chat-lightbox-close {
    position: absolute;
    top: calc(0.75rem + var(--im-safe-top));
    left: 0.75rem;
    border: none;
    width: 2.5rem;
    height: 2.5rem;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
}

.virtual-visit-fab {
    position: fixed;
    left: 1rem;
    bottom: calc(1.1rem + var(--im-safe-bottom));
    z-index: 1200;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.8rem 1.05rem;
    border-radius: 999px;
    background: linear-gradient(135deg, #00a884, #008069);
    color: #fff !important;
    text-decoration: none !important;
    font-weight: 700;
    box-shadow: 0 10px 28px rgba(0, 168, 132, 0.35);
}
.virtual-visit-fab i { font-size: 1.25rem; }

.wa-gate {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    justify-content: center;
    padding: 1.5rem 1.25rem 5.5rem;
    background: #fff;
    text-align: center;
    gap: 0.65rem;
}
.wa-gate-icon {
    width: 3.5rem;
    height: 3.5rem;
    margin: 0 auto 0.35rem;
    border-radius: 50%;
    background: linear-gradient(135deg, #00a884, #008069);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
}
.wa-gate h2 {
    margin: 0;
    font-size: 1.15rem;
    color: var(--im-text);
}
.wa-gate p {
    margin: 0;
    color: var(--im-muted);
    font-size: 0.92rem;
    line-height: 1.7;
}
.wa-gate-muted {
    display: block;
    margin-top: 0.35rem;
    font-size: 0.82rem;
    color: var(--im-muted);
}
.wa-gate-alert {
    background: #fdecea;
    color: #c5221f;
    border-radius: 10px;
    padding: 0.65rem 0.8rem;
    font-size: 0.88rem;
    text-align: right;
}
.wa-gate-alert-ok {
    background: #e6f4ea;
    color: #137333;
}
.wa-gate-form {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    text-align: right;
    margin-top: 0.5rem;
}
.wa-gate-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--im-text);
}
.wa-phone-row {
    display: flex;
    direction: ltr;
    border: 1px solid var(--im-border);
    border-radius: 12px;
    overflow: hidden;
    background: #f0f2f5;
}
.wa-phone-prefix {
    display: inline-flex;
    align-items: center;
    padding: 0 0.75rem;
    color: var(--im-muted);
    font-weight: 600;
    background: #e9eef2;
}
.wa-gate-input {
    width: 100%;
    border: 1px solid var(--im-border);
    border-radius: 12px;
    padding: 0.85rem 0.9rem;
    font-size: 1rem;
    font-family: inherit;
    outline: none;
    background: #f0f2f5;
}
.wa-phone-row .wa-gate-input {
    border: none;
    border-radius: 0;
    background: transparent;
}
.wa-gate-otp {
    letter-spacing: 0.35em;
    text-align: center;
    font-size: 1.35rem;
    direction: ltr;
}
.wa-gate-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-top: 0.35rem;
    padding: 0.9rem 1rem;
    border: none;
    border-radius: 12px;
    background: var(--im-top);
    color: #fff !important;
    font-weight: 700;
    font-size: 0.98rem;
    font-family: inherit;
    text-decoration: none !important;
    cursor: pointer;
}
.wa-gate-btn-ghost {
    background: #fff;
    color: var(--im-top) !important;
    border: 1px solid var(--im-top);
}
.wa-gate-link {
    margin-top: 0.75rem;
    color: var(--im-accent);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
}

@keyframes chatPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(234, 67, 53, 0.45); }
    50% { box-shadow: 0 0 0 10px rgba(234, 67, 53, 0); }
}
@keyframes chatWave {
    0%, 100% { transform: scaleY(0.45); opacity: 0.65; }
    50% { transform: scaleY(1); opacity: 1; }
}

/* Desktop: keep centered phone-like column */
@media (min-width: 768px) {
    body.wa-body { background: #0b141a; }
    .wa-app {
        box-shadow: 0 0 0 1px rgba(255,255,255,0.04), 0 20px 60px rgba(0,0,0,0.35);
        min-height: min(100dvh, 900px);
        height: min(100dvh, 900px);
        margin-top: 0;
        border-radius: 0;
    }
    .wa-list-page { height: min(100dvh, 900px); }
}
