/* Agrovaru Live Chat — Widget CSS */

#alc-widget {
    position: fixed;
    bottom: 24px;
    z-index: 99999;
    font-family: 'DM Sans', 'Barlow', sans-serif;
    font-size: 16px;
    line-height: 1.45;
}

/* Ikoon */
.alc-icon-btn {
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(0,0,0,.22);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s, box-shadow .2s;
    position: relative;
}
.alc-icon-btn:hover { transform: scale(1.08); box-shadow: 0 6px 22px rgba(0,0,0,.28); }
.alc-icon-btn:active { transform: scale(.96); }

.alc-unread-dot {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 12px;
    height: 12px;
    background: #ca0101;
    border-radius: 50%;
    border: 2px solid #fff;
    animation: alc-pulse 1.4s infinite;
}
@keyframes alc-pulse {
    0%,100% { transform: scale(1); }
    50% { transform: scale(1.25); }
}

/* Tervitusmulli */
.alc-greeting {
    position: absolute;
    bottom: 70px;
    right: 0;
    background: #fff;
    border-radius: 14px;
    /* Paremal rohkem polstrit, et tekst sulgemisristi alla ei jookseks */
    padding: 22px 44px 22px 26px;
    box-shadow: 0 6px 26px rgba(0,0,0,.16);
    max-width: 380px;
    width: max-content;
    opacity: 0;
    transform: translateY(8px) scale(.95);
    pointer-events: none;
    transition: opacity .25s, transform .25s;
}
.alc-greeting.alc-visible { opacity: 1; transform: none; pointer-events: all; }
.alc-greeting p { margin: 0; font-size: 22px; line-height: 1.35; font-weight: 600; color: #1d2327; }
.alc-greeting-close {
    position: absolute;
    top: 8px;
    right: 10px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 20px;
    color: #aaa;
    line-height: 1;
    padding: 4px;
}
.alc-greeting-close:hover { color: #666; }
.alc-greeting-arrow {
    position: absolute;
    bottom: -7px;
    right: 22px;
    width: 14px;
    height: 14px;
    background: #fff;
    transform: rotate(45deg);
    box-shadow: 3px 3px 6px rgba(0,0,0,.08);
}

/* Chat aken */
.alc-window {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 420px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 40px rgba(0,0,0,.18);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    /* Vaikimisi kasvab aken sisu järgi — osakonna valikul ja nime küsimisel
       on sisu vaid paar nuppu ja täiskõrge aken jätaks suure tühja ala.
       118px = mulli kõrgus (58) + widgeti alumine serv (24) + aknavahe (12)
       + ülemine hingamisruum (24). */
    height: auto;
    max-height: calc(100vh - 118px);
    max-height: calc(100dvh - 118px);
}

/* Vestlusekraanil läheb aken täiskõrgeks — sõnumiloend vajab ruumi. */
.alc-window.alc-chatting {
    height: calc(100vh - 118px);
    height: calc(100dvh - 118px);
    min-height: 440px;
    max-height: 800px;
}

/* Päis */
.alc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    flex-shrink: 0;
}
.alc-header-info { display: flex; align-items: center; gap: 10px; }
.alc-header-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 18px;
    color: #3c464b;
}
.alc-header-name  { font-weight: 700; color: #fff; font-size: 18px; }
.alc-header-status { font-size: 14px; color: rgba(255,255,255,.8); display: flex; align-items: center; gap: 4px; }
.alc-dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.alc-dot.online { background: #4cde73; }
.alc-close-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,.8);
    padding: 4px;
    display: flex;
    align-items: center;
}
.alc-close-btn:hover { color: #fff; }

/* Ekraanid */
.alc-screen {
    padding: 16px;
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.alc-screen-title {
    font-weight: 600;
    color: #1d2327;
    margin: 0 0 4px;
    font-size: 17px;
}
.alc-screen-note {
    font-size: 13px;
    color: #aaa;
    margin: 4px 0 0;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Osakonna nupud */
.alc-dept-btn {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px 16px;
    border: 1px solid #eee;
    border-radius: 12px;
    background: #fff;
    cursor: pointer;
    text-align: left;
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
}
.alc-dept-btn:hover {
    border-color: var(--alc-accent, #ffb900);
    box-shadow: 0 2px 12px rgba(0,0,0,.08);
}
.alc-dept-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.alc-dept-text { flex: 1; }
.alc-dept-text strong { display: block; font-size: 16px; color: #1d2327; }
.alc-dept-text span   { display: block; font-size: 13.5px; color: #888; margin-top: 3px; line-height: 1.4; }
.alc-dept-arrow { color: #ccc; }

/* Nimi sisend */
.alc-back-link {
    background: none;
    border: none;
    cursor: pointer;
    color: #888;
    font-size: 14px;
    padding: 0;
    font-family: inherit;
    align-self: flex-start;
}
.alc-back-link:hover { color: #333; }
.alc-name-input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid #ddd;
    border-radius: 10px;
    font-size: 16px;
    font-family: inherit;
    outline: none;
    box-sizing: border-box;
    transition: border-color .15s;
}
.alc-name-input:focus { border-color: #3c464b; }
.alc-start-btn {
    padding: 13px 18px;
    border: none;
    border-radius: 10px;
    color: #ffb900;
    font-weight: 700;
    font-size: 16px;
    cursor: pointer;
    font-family: inherit;
    transition: opacity .15s;
}
.alc-start-btn:hover { opacity: .88; }
.alc-start-btn:disabled { opacity: .6; cursor: not-allowed; }

/* Vestlus ekraan */
#alc-screen-chat {
    padding: 0;
    gap: 0;
    flex: 1;
    overflow: hidden;
}

.alc-messages {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 14px 14px 8px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.alc-msg { display: flex; flex-direction: column; max-width: 82%; }
.alc-msg-agent   { align-self: flex-start; align-items: flex-start; }
.alc-msg-visitor { align-self: flex-end;   align-items: flex-end; }

.alc-bubble {
    padding: 11px 15px;
    border-radius: 14px;
    font-size: 16px;
    line-height: 1.5;
    word-break: break-word;
}
.alc-msg-agent   .alc-bubble { background: #f0f0f0; color: #1d2327; border-bottom-left-radius: 4px; }
.alc-msg-visitor .alc-bubble { background: #3c464b; color: #fff;    border-bottom-right-radius: 4px; }

.alc-msg-time { font-size: 12px; color: #bbb; margin-top: 4px; padding: 0 3px; }

/* Sisestamise indikaator */
.alc-typing-indicator {
    padding: 8px 14px;
    display: flex;
    gap: 4px;
    align-items: center;
}
.alc-typing-indicator span {
    width: 7px;
    height: 7px;
    background: #ccc;
    border-radius: 50%;
    animation: alc-bounce 1.2s infinite;
}
.alc-typing-indicator span:nth-child(2) { animation-delay: .2s; }
.alc-typing-indicator span:nth-child(3) { animation-delay: .4s; }
@keyframes alc-bounce { 0%,60%,100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }

/* Sisestusrida */
.alc-input-row {
    display: flex;
    align-items: flex-end;
    border-top: 1px solid #f0f0f0;
    padding: 8px;
    gap: 8px;
    flex-shrink: 0;
}
.alc-msg-input {
    flex: 1;
    border: 1px solid #e0e0e0;
    border-radius: 20px;
    padding: 11px 16px;
    font-size: 16px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 100px;
    overflow-y: auto;
    transition: border-color .15s;
    line-height: 1.4;
}
.alc-msg-input:focus { border-color: #3c464b; }
.alc-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #ffb900;
    flex-shrink: 0;
    transition: opacity .15s;
}
.alc-send-btn:hover { opacity: .85; }

/* Mobiil */
@media (max-width: 480px) {
    .alc-greeting {
        max-width: calc(100vw - 56px);
        padding: 18px 40px 18px 20px;
    }
    .alc-greeting p { font-size: 19px; }

    /* Avatud aken katab kogu ekraani — väike ujuv kast tundub kitsas ja
       "askeldava" tunde, täisekraan on tuttavam ja mugavam ka klaviatuuri
       avanedes. position:fixed+inset:0 eemaldab akna #alc-widget'i
       lokaalsest positsioneerimisest (bottom/right), nii et see ei sõltu
       enam nupu asukohast. */
    /* #alc-widget (mitte ainult .alc-window) peab siin olema kõrgemal kui
       Agrovaru päise mobiili kontaktiriba (.agrovaru-mobile-bar, z-index
       999999 !important) — muidu jääb täisekraanilise akna sisestusrida
       selle riba alla peitu. Kuna #alc-widget loob oma stacking context'i
       (position:fixed + z-index), ei aita .alc-window enda z-indexi
       tõstmine üksi — kogu vanema stacking context peab kõrgemale minema.
       !important on vajalik, sest kontaktiriba enda z-index on samuti
       !important — ilma selleta võidab tema, olenemata arvväärtusest. */
    #alc-widget { z-index: 1000000 !important; }

    .alc-window {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100vh;
        height: 100dvh;
        max-height: none;
        min-height: 0;
        border-radius: 0;
    }
    .alc-window.alc-chatting {
        height: 100vh;
        height: 100dvh;
        max-height: none;
    }
    .alc-header { padding-top: max(14px, env(safe-area-inset-top)); }
    .alc-input-row { padding-bottom: max(8px, env(safe-area-inset-bottom)); }
}

/* Agrovaru päise mobiili kontaktiriba (.agrovaru-mobile-bar, ~70px kõrge,
   z-index 999999) katab ekraani allosas ~900px laiuseni — nihutame chati
   nupu selle kohale, muidu jääb ta peaaegu täielikult riba alla peitu.
   .alc-greeting on #alc-widget suhtes absolute ja liigub nupuga kaasa.
   .alc-window on ≤480px täisekraaniline (position:fixed, oma kõrgem
   z-index) ega sõltu enam widgeti positsioonist — vt eelmist plokki. */
@media (max-width: 900px) {
    #alc-widget {
        bottom: 88px;
        right: 6px !important;
        left: auto !important;
    }
    /* Väiksem nupp mobiilis, samas stiilis mis teised ujuvad ikoonid
       (otsing/küpsised/ligipääsetavus) — servale kinnitatud. */
    .alc-icon-btn {
        width: 46px;
        height: 46px;
    }
    .alc-unread-dot {
        width: 10px;
        height: 10px;
    }
}
