/* =========================================================
   Bazarak assistant + floating back button
   Local assets only; no CDN. Works light/dark via tokens.
   ========================================================= */

.bz-back {
    position: fixed;
    left: 18px;
    bottom: calc(var(--bottom-nav-h, 64px) + 86px);
    z-index: 68;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 9px 14px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--surface);
    color: var(--text-1);
    box-shadow: var(--shadow-card);
    font: inherit;
    font-size: 12.5px;
    font-weight: 700;
    cursor: pointer;
    transition: transform .18s ease, box-shadow .18s ease, background .18s ease;
}

.bz-back:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 26px -14px rgba(11, 16, 32, .35);
}

.bz-back:active { transform: translateY(0); }
.bz-back[hidden] { display: none !important; }
.bz-back svg { width: 15px; height: 15px; }

.bz-assistant-fab {
    position: fixed;
    left: 18px;
    bottom: calc(var(--bottom-nav-h, 64px) + 18px);
    z-index: 69;
    display: inline-flex;
    align-items: center;
    gap: 9px;
    padding: 11px 15px;
    border: 0;
    border-radius: 999px;
    background: var(--grad-primary);
    color: var(--on-primary);
    box-shadow: 0 12px 30px -12px rgba(61, 99, 240, .65);
    font: inherit;
    font-size: 12.5px;
    font-weight: 800;
    cursor: pointer;
    transition: transform .2s ease, box-shadow .2s ease;
}

.bz-assistant-fab:hover {
    transform: translateY(-2px);
    box-shadow: 0 16px 34px -12px rgba(61, 99, 240, .8);
}

.bz-assistant-fab .bz-fab-ico {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
}

.bz-assistant-fab .bz-fab-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 3px rgba(74, 222, 128, .22);
    animation: bz-pulse 2.4s ease-in-out infinite;
}

@keyframes bz-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(.72); opacity: .65; }
}

.bz-assistant {
    position: fixed;
    left: 18px;
    bottom: calc(var(--bottom-nav-h, 64px) + 82px);
    z-index: 70;
    display: flex;
    flex-direction: column;
    /* Reserve room for BOTH the left offset and a matching right gap, else
       (100vw - 24px) pushes this past the viewport edge → the stray
       horizontal scrollbar (Phase-0 review item 1). */
    width: min(390px, calc(100vw - 36px));
    max-height: min(640px, calc(100vh - 120px));
    border: 1px solid var(--border);
    border-radius: 22px;
    background: var(--surface);
    color: var(--text-1);
    box-shadow: 0 24px 70px -24px rgba(9, 18, 48, .42);
    overflow: hidden;
    opacity: 0;
    visibility: hidden;
    transform: translateY(14px) scale(.98);
    transform-origin: bottom left;
    transition: opacity .2s ease, transform .2s ease, visibility .2s;
}

.bz-assistant.open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.bz-assistant-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 13px 14px;
    background: var(--grad-primary);
    color: #fff;
}

.bz-assistant-avatar {
    width: 38px;
    height: 38px;
    border-radius: 13px;
    background: rgba(255, 255, 255, .18);
    border: 1px solid rgba(255, 255, 255, .28);
    display: grid;
    place-items: center;
    flex: 0 0 auto;
}

.bz-assistant-head h2 {
    margin: 0;
    font-size: 13.5px;
    font-weight: 800;
    line-height: 1.35;
}

.bz-assistant-head .sub {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
    font-size: 10.5px;
    opacity: .9;
}

.bz-assistant-head .sub .live {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #4ade80;
    box-shadow: 0 0 0 2px rgba(74, 222, 128, .25);
}

.bz-assistant-close {
    margin-inline-start: auto;
    width: 30px;
    height: 30px;
    border: 1px solid rgba(255, 255, 255, .3);
    border-radius: 10px;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    font: inherit;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
}

.bz-assistant-privacy {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 7px 13px;
    background: var(--surface-2);
    color: var(--text-2);
    font-size: 10px;
    line-height: 1.5;
    border-bottom: 1px solid var(--border);
}

.bz-assistant-privacy svg { width: 13px; height: 13px; flex: 0 0 auto; }

.bz-assistant-quick {
    display: flex;
    gap: 6px;
    padding: 9px 12px 3px;
    overflow-x: auto;
    scrollbar-width: none;
    flex: 0 0 auto;
}

.bz-assistant-quick::-webkit-scrollbar { display: none; }

.bz-quick-chip {
    flex: 0 0 auto;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-1);
    color: var(--text-2);
    font: inherit;
    font-size: 10.5px;
    font-weight: 700;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color .15s ease, color .15s ease, background .15s ease;
}

.bz-quick-chip:hover {
    border-color: var(--primary);
    color: var(--primary);
    background: var(--surface-2);
}

.bz-assistant-messages {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 11px 12px 13px;
    overflow-y: auto;
    min-height: 150px;
    flex: 1 1 auto;
    overscroll-behavior: contain;
}

.bz-msg {
    max-width: 88%;
    padding: 9px 11px;
    border-radius: 15px;
    font-size: 11.5px;
    line-height: 1.75;
    word-break: break-word;
    white-space: pre-wrap;
}

.bz-msg a {
    color: var(--link);
    font-weight: 700;
    text-decoration: underline;
    text-underline-offset: 2px;
}

.bz-msg-bot {
    align-self: flex-start;
    background: var(--surface-2);
    color: var(--text-1);
    border-end-start-radius: 5px;
}

.bz-msg-user {
    align-self: flex-end;
    background: var(--primary);
    color: var(--on-primary);
    border-end-end-radius: 5px;
}

.bz-msg-user a { color: #fff; }

.bz-msg-typing {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    min-width: 48px;
}

.bz-msg-typing i {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--text-3);
    animation: bz-typing 1.1s infinite ease-in-out;
}

.bz-msg-typing i:nth-child(2) { animation-delay: .15s; }
.bz-msg-typing i:nth-child(3) { animation-delay: .3s; }

@keyframes bz-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: .45; }
    30% { transform: translateY(-4px); opacity: 1; }
}

.bz-assistant-form {
    display: flex;
    align-items: flex-end;
    gap: 7px;
    padding: 9px 11px;
    border-top: 1px solid var(--border);
    background: var(--surface);
    flex: 0 0 auto;
}

.bz-assistant-form textarea {
    flex: 1 1 auto;
    min-height: 38px;
    max-height: 96px;
    resize: none;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-1);
    color: var(--text-1);
    font: inherit;
    font-size: 11.5px;
    line-height: 1.6;
    outline: none;
}

.bz-assistant-form textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(61, 99, 240, .13);
}

.bz-assistant-send {
    flex: 0 0 auto;
    width: 38px;
    height: 38px;
    border: 0;
    border-radius: 12px;
    background: var(--grad-primary);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
}

.bz-assistant-send:disabled { opacity: .55; cursor: wait; }
.bz-assistant-send svg { width: 17px; height: 17px; }

.bz-assistant-foot {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 7px 12px 9px;
    border-top: 1px solid var(--border);
    background: var(--bg-1);
    color: var(--text-3);
    font-size: 9.5px;
}

.bz-assistant-foot a {
    color: var(--link);
    font-weight: 700;
    text-decoration: none;
}

@media (max-width: 575.98px) {
    .bz-assistant {
        left: 10px;
        right: 10px;
        width: auto;
        bottom: calc(var(--bottom-nav-h, 64px) + 76px);
        max-height: min(72vh, 620px);
        border-radius: 18px;
    }

    .bz-assistant-fab {
        left: 12px;
        bottom: calc(var(--bottom-nav-h, 64px) + 14px);
        padding: 10px 13px;
    }

    .bz-assistant-fab .bz-fab-label { display: none; }
    .bz-back { left: 12px; bottom: calc(var(--bottom-nav-h, 64px) + 76px); }
}

@media (min-width: 992px) {
    .bz-assistant-fab { bottom: 20px; left: 22px; }
    /* Match the larger 22px offset so the panel never crosses the edge. */
    .bz-assistant { bottom: 82px; left: 22px; width: min(390px, calc(100vw - 44px)); }
    .bz-back { bottom: 82px; left: 140px; }
}

@media (prefers-reduced-motion: reduce) {
    .bz-assistant,
    .bz-assistant-fab,
    .bz-back,
    .bz-msg-typing i,
    .bz-assistant-fab .bz-fab-dot { transition: none; animation: none; }
    .bz-dock-tab,
    .bz-dock-menu,
    .bz-voice,
    .bz-voice-orb { transition: none; animation: none; }
}

/* ============================================================
   Docked edge tab (فاز ۱۴) — collapsed «<» on the wall edge
   ============================================================ */
.bz-dock {
    position: fixed;
    right: 0;
    bottom: calc(var(--bottom-nav-h, 64px) + 20px);
    z-index: 1080;
    display: flex;
    flex-direction: row-reverse;
    align-items: flex-start;
    pointer-events: none;
}

.bz-dock > * { pointer-events: auto; }

/* The collapsed tab: only a chevron, hugging the right edge. */
.bz-dock-tab {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border: 1px solid var(--border);
    border-right: 0;
    border-radius: 14px 0 0 14px;
    background: var(--primary, #3D63F0);
    color: #fff;
    padding: 12px 8px 12px 10px;
    cursor: pointer;
    box-shadow: -2px 4px 16px rgba(0, 0, 0, .18);
    transition: padding .2s ease, background .2s ease;
}

.bz-dock-chev {
    display: grid;
    place-items: center;
    transform: rotate(180deg); /* «<» points into the wall */
    transition: transform .2s ease;
}

.bz-dock-tab[aria-expanded="true"] .bz-dock-chev { transform: rotate(0deg); }

.bz-dock-tip {
    font-size: 12.5px;
    font-weight: 700;
    white-space: nowrap;
}

/* Expanded: three actions slide out to the left of the tab. */
.bz-dock-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-inline-end: 8px;
    padding: 10px;
    min-width: 190px;
    background: var(--surface, #fff);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .22);
    transform-origin: right center;
    animation: bz-dock-pop .18s ease;
}

.bz-dock-menu[hidden] { display: none; }

@keyframes bz-dock-pop {
    from { opacity: 0; transform: translateX(10px) scale(.96); }
    to { opacity: 1; transform: none; }
}

.bz-dock-item {
    display: flex;
    align-items: center;
    gap: 9px;
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--surface-2, #f5f6fa);
    color: inherit;
    padding: 10px 12px;
    font: inherit;
    font-size: 13.5px;
    cursor: pointer;
    text-align: start;
    transition: background .15s ease, border-color .15s ease;
}

.bz-dock-item:hover,
.bz-dock-item:focus-visible {
    background: rgba(61, 99, 240, .12);
    border-color: var(--primary, #3D63F0);
}

/* ============================================================
   Voice assistant — two-way Persian
   ============================================================ */
.bz-voice {
    position: fixed;
    inset-inline: 0;
    bottom: 0;
    z-index: 1100;
    max-width: 460px;
    margin: 0 auto;
    background: var(--surface, #fff);
    border: 1px solid var(--border);
    border-radius: 22px 22px 0 0;
    box-shadow: 0 -14px 50px rgba(0, 0, 0, .3);
    padding: 16px 16px calc(16px + var(--bottom-nav-h, 64px));
    transform: translateY(110%);
    transition: transform .28s cubic-bezier(.32, .72, 0, 1);
}

.bz-voice.open { transform: none; }

.bz-voice[aria-hidden="true"] { pointer-events: none; }

.bz-voice-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.bz-voice-head h2 {
    font-size: 1.05rem;
    margin: 0;
}

.bz-voice-head .sub {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted-2, #69738d);
}

.bz-voice-close {
    border: 1px solid var(--border);
    background: var(--surface-2, #f5f6fa);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    cursor: pointer;
    font-size: 17px;
    color: inherit;
}

.bz-voice-stage {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    padding: 14px 0 6px;
}

/* The orb pulses while listening; turns green while speaking. */
.bz-voice-orb {
    width: 96px;
    height: 96px;
    border-radius: 50%;
    border: 0;
    background: var(--primary, #3D63F0);
    color: #fff;
    display: grid;
    place-items: center;
    cursor: pointer;
    box-shadow: 0 0 0 0 rgba(61, 99, 240, .5);
    transition: background .2s ease;
}

.bz-voice-orb.listening { animation: bz-orb 1.4s ease-out infinite; }

.bz-voice-orb.speaking {
    background: var(--success, #12B76A);
    animation: bz-orb 1s ease-out infinite;
}

@keyframes bz-orb {
    0% { box-shadow: 0 0 0 0 rgba(61, 99, 240, .45); }
    70% { box-shadow: 0 0 0 26px rgba(61, 99, 240, 0); }
    100% { box-shadow: 0 0 0 0 rgba(61, 99, 240, 0); }
}

.bz-voice-status {
    font-size: 13.5px;
    text-align: center;
    min-height: 20px;
    color: var(--text-muted-2, #69738d);
}

.bz-voice-transcript {
    min-height: 76px;
    max-height: 190px;
    overflow-y: auto;
    border: 1px dashed var(--border);
    border-radius: 14px;
    padding: 10px 12px;
    font-size: 14px;
    line-height: 1.9;
}

.bz-voice-transcript:empty::before {
    content: "گفت‌وگوی صوتی اینجا نمایش داده می‌شود…";
    color: var(--text-muted-2, #69738d);
    font-size: 13px;
}

.bz-voice-transcript .v-who {
    display: block;
    font-size: 11.5px;
    font-weight: 700;
    color: var(--primary, #3D63F0);
    margin-top: 6px;
}

.bz-voice-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-top: 12px;
    font-size: 12px;
}

.bz-voice-stop {
    border: 1px solid var(--danger, #E5484D);
    background: transparent;
    color: var(--danger, #E5484D);
    border-radius: 10px;
    padding: 6px 12px;
    font: inherit;
    font-size: 12.5px;
    cursor: pointer;
}

@media (prefers-reduced-motion: reduce) {
    .bz-voice { transition: none; }
    .bz-voice-orb.listening,
    .bz-voice-orb.speaking { animation: none; }
    .bz-dock-menu { animation: none; }
}

@media print {
    .bz-dock,
    .bz-voice,
    .bz-popup-overlay,
    .bz-loading { display: none !important; }
}

/* ============================================================
   Page loading indicator (فاز ۱۴) — thin top progress bar
   ============================================================ */
.bz-loading {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    z-index: 3000;
    pointer-events: none;
    background: transparent;
    overflow: hidden;
    opacity: 0;
    transition: opacity .2s ease;
}

.bz-loading.is-active { opacity: 1; }

.bz-loading::after {
    content: '';
    position: absolute;
    inset: 0;
    width: 40%;
    background: linear-gradient(90deg, transparent, var(--primary, #3D63F0), transparent);
    animation: bz-load-slide 1s ease-in-out infinite;
}

.bz-loading.is-done {
    opacity: 1;
    transition: opacity .3s ease .1s;
}

.bz-loading.is-done::after {
    width: 100%;
    background: var(--success, #12B76A);
    animation: none;
}

@keyframes bz-load-slide {
    from { transform: translateX(-120%); }
    to { transform: translateX(320%); }
}

@media (prefers-reduced-motion: reduce) {
    .bz-loading::after { animation: none; width: 100%; }
}

/* ============================================================
   Quick-start / welcome popup (فاز ۱۴)
   ============================================================ */
.bz-popup-overlay {
    position: fixed;
    inset: 0;
    z-index: 1200;
    background: rgba(15, 20, 40, .55);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding: 16px;
    backdrop-filter: blur(2px);
}

.bz-popup-overlay[hidden] { display: none; }

.bz-popup {
    position: relative;
    width: 100%;
    max-width: 440px;
    border-radius: 20px;
    padding: 18px 18px 20px;
    background: var(--surface, #fff);
    border: 1px solid var(--border);
    box-shadow: 0 -10px 50px rgba(0, 0, 0, .35);
    animation: bz-pop-in .24s cubic-bezier(.32, .72, 0, 1);
    max-height: 88vh;
    overflow-y: auto;
}

@keyframes bz-pop-in {
    from { opacity: 0; transform: translateY(24px) scale(.97); }
    to { opacity: 1; transform: none; }
}

.bz-popup-close {
    position: absolute;
    inset-inline-start: 12px;
    top: 12px;
    width: 34px;
    height: 34px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--surface-2, #f5f6fa);
    color: inherit;
    cursor: pointer;
    font-size: 16px;
    z-index: 2;
}

.bz-popup-body .qi-icon {
    width: 52px;
    height: 52px;
    border-radius: 16px;
    background: var(--surface-2, #f5f6fa);
    color: var(--primary, #3D63F0);
    display: grid;
    place-items: center;
}

@media (min-width: 768px) {
    .bz-popup-overlay { align-items: center; }
}

@media (prefers-reduced-motion: reduce) {
    .bz-popup { animation: none; }
}

@media print {
    .bz-assistant,
    .bz-assistant-fab,
    .bz-back { display: none !important; }
}
