/* ============================================================
   Чат асистентът (partials/chat_widget.html.twig + js/chat.js).
   Глобалните правила на сайта (body/p 18px !important, a {…}) се
   надделяват тук с .icb-… и !important само където е нужно.
   ============================================================ */

.icb-fab:hover { background: #d67530; transform: translateY(-2px); }
.icb-fab:active { transform: translateY(1px); }
.icb-fab:focus-visible { outline: 3px solid #2e5365; outline-offset: 3px; }
.icb-fab .icb-ico-close { display: none; }
.icb-fab[aria-expanded="true"] .icb-ico-chat,
.icb-fab[aria-expanded="true"] .icb-fab-label { display: none; }
.icb-fab[aria-expanded="true"] .icb-ico-close { display: block; }
.icb-fab[aria-expanded="true"] { width: 56px; padding: 0; justify-content: center; }
/* точка: има започнат разговор */
.icb-fab.icb-has-conv::after {
    content: '';
    position: absolute;
    top: 6px;
    right: 6px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: #2e5365;
    border: 2px solid #fff;
}
.icb-fab[aria-expanded="true"]::after { display: none; }

/* ---------- покана до бутона ---------- */
.icb-teaser {
    position: fixed;
    right: 18px;
    bottom: calc(86px + var(--icb-lift, 0px) + env(safe-area-inset-bottom));
    z-index: 1036;
    max-width: 250px;
    padding: 12px 34px 12px 14px;
    border-radius: 14px 14px 4px 14px;
    background: #fff;
    color: #1a1a1a;
    font-size: 15px !important;
    line-height: 1.4;
    box-shadow: 0 12px 32px -10px rgba(26, 58, 74, .45);
    cursor: pointer;
    animation: icb-pop .3s ease both;
    transition: bottom .35s ease;
}
.icb-teaser strong { display: block; color: #2e5365; font-weight: 700; }
.icb-teaser-x {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 28px;
    height: 28px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #6c757d;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}
.icb-teaser-x:hover { background: #f1f4f6; color: #1a1a1a; }

/* ---------- прозорецът ---------- */
.icb-panel {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    position: fixed;
    right: 18px;
    bottom: calc(86px + var(--icb-lift, 0px) + env(safe-area-inset-bottom));
    z-index: 1036;
    display: flex;
    flex-direction: column;
    width: 380px;
    max-width: calc(100vw - 36px);
    height: min(620px, calc(100vh - 140px - var(--icb-lift, 0px)));
    overflow: hidden;
    border-radius: 18px;
    background: #fff;
    color: #1a1a1a;
    font-size: 15px !important;
    line-height: 1.5;
    box-shadow: 0 24px 60px -18px rgba(26, 58, 74, .55), 0 0 0 1px rgba(26, 58, 74, .06);
    opacity: 0;
    transform: translateY(12px) scale(.98);
    transform-origin: bottom right;
    transition: opacity .22s ease, transform .22s ease, bottom .35s ease;
}
.icb-panel[hidden] { display: none; }
.icb-panel.is-open { opacity: 1; transform: none; }

.icb-head {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 12px 10px 12px 14px;
    background: linear-gradient(135deg, #2e5365, #1a3a4a);
    color: #fff;
    flex: 0 0 auto;
}
.icb-avatar {
    flex: 0 0 auto;
    margin-right: 4px;
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background: #fff url('../favicon/apple-touch-icon.png') center / cover no-repeat;
    box-shadow: 0 0 0 2px rgba(255, 255, 255, .25);
}
.icb-titles { flex: 1 1 auto; min-width: 0; }
.icb-titles strong,
.icb-titles span { display: block; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.icb-titles strong { font-size: 15.5px; font-weight: 700; line-height: 1.25; color: #fff; }
.icb-titles span { font-size: 12.5px; color: rgba(255, 255, 255, .72); }
.icb-titles span::before {
    content: '';
    display: inline-block;
    width: 7px;
    height: 7px;
    margin-right: 6px;
    border-radius: 50%;
    background: #5fd38d;
    vertical-align: 1px;
}
.icb-hbtn {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: #fff !important;
    text-decoration: none !important;
    cursor: pointer;
    transition: background-color .2s ease;
}
.icb-hbtn:hover { background: rgba(255, 255, 255, .14); }
.icb-hbtn:focus-visible { outline: 2px solid #fff; outline-offset: 1px; }
.icb-hbtn .mdi { font-size: 20px; line-height: 1; }
.icb-hbtn svg { width: 20px; height: 20px; }

.icb-body {
    flex: 1 1 auto;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 16px 14px 8px;
    background: #f7f9fa;
    -webkit-overflow-scrolling: touch;
}

.icb-msg { display: flex; margin: 0 0 10px; }
.icb-msg.icb-u { justify-content: flex-end; }
.icb-bubble {
    max-width: 86%;
    padding: 10px 13px;
    border-radius: 16px;
    font-size: 15px !important;
    line-height: 1.5;
    overflow-wrap: anywhere;
    word-break: normal;
}
.icb-a .icb-bubble {
    background: #fff;
    color: #1a1a1a;
    border-bottom-left-radius: 5px;
    box-shadow: 0 1px 2px rgba(26, 58, 74, .08), 0 0 0 1px rgba(26, 58, 74, .05);
}
.icb-u .icb-bubble {
    background: #2e5365;
    color: #fff;
    border-bottom-right-radius: 5px;
}
.icb-e .icb-bubble { background: #fff4ec; box-shadow: 0 0 0 1px #f6d2b8; }
.icb-bubble p,
.icb-bubble li {
    font-size: inherit !important;
    line-height: inherit;
    color: inherit;
}
.icb-bubble p { margin: 0 0 .55em !important; }
.icb-bubble p:last-child { margin-bottom: 0 !important; }
.icb-bubble ul,
.icb-bubble ol { margin: 0 0 .55em !important; padding-left: 1.25em !important; }
.icb-bubble ul { list-style: disc !important; }
.icb-bubble ol { list-style: decimal !important; }
.icb-bubble li { display: list-item !important; }
.icb-bubble ul:last-child,
.icb-bubble ol:last-child { margin-bottom: 0; }
.icb-bubble li { margin: 0 0 .2em; }
.icb-bubble strong { font-weight: 700; }
.icb-a .icb-bubble a {
    color: #c9621a !important;
    font-weight: 600;
    text-decoration: underline !important;
    text-underline-offset: 2px;
}
.icb-a .icb-bubble a:hover { color: #2e5365 !important; }

/* „пише…“ */
.icb-typing .icb-bubble { display: inline-flex; gap: 4px; padding: 14px 14px; }
.icb-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #9aa9b3;
    animation: icb-dot 1.1s infinite ease-in-out;
}
.icb-typing span:nth-child(2) { animation-delay: .15s; }
.icb-typing span:nth-child(3) { animation-delay: .3s; }

/* бързи въпроси */
.icb-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 2px 0 12px; }
.icb-chip {
    padding: 7px 12px;
    border: 1px solid #f0c9a8;
    border-radius: 999px;
    background: #fff;
    color: #b8571a;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.25;
    cursor: pointer;
    transition: background-color .2s ease, border-color .2s ease;
}
.icb-chip:hover { background: #fff4ec; border-color: #E78640; }
.icb-chip:focus-visible { outline: 2px solid #E78640; outline-offset: 1px; }

/* „говорете с човек“ */
.icb-card {
    margin: 0 0 12px;
    padding: 12px;
    border-radius: 14px;
    background: #fff;
    box-shadow: 0 0 0 1px rgba(26, 58, 74, .08);
    font-size: 14px;
}
.icb-card-title { display: block; margin-bottom: 8px; color: #2e5365; font-weight: 700; font-size: 14.5px; }
.icb-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.icb-act {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 8px 12px;
    border: 0;
    border-radius: 10px;
    background: #eef3f5;
    color: #2e5365 !important;
    font-size: 14px;
    font-weight: 600;
    line-height: 1.2;
    text-decoration: none !important;
    cursor: pointer;
}
.icb-act:hover { background: #e0eaee; }
.icb-act--main { background: #E78640; color: #fff !important; }
.icb-act--main:hover { background: #d67530; }
.icb-act .mdi { font-size: 17px; line-height: 1; }

/* форма за обратно обаждане в чата */
.icb-cb { display: grid; gap: 8px; }
.icb-cb input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d5dee3;
    border-radius: 10px;
    background: #fff;
    color: #1a1a1a;
    font: inherit;
    font-size: 16px;
}
.icb-cb input:focus { border-color: #E78640; outline: none; box-shadow: 0 0 0 3px rgba(231, 134, 64, .18); }
.icb-cb small { color: #6c757d; font-size: 12.5px; line-height: 1.4; }
.icb-cb .icb-err { color: #b42318; font-size: 13px; }
.icb-hp { position: absolute !important; left: -9999px !important; width: 1px; height: 1px; opacity: 0; }
.icb-ok { color: #1e7a46; font-weight: 600; }

/* поле за писане */
.icb-form {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 10px 10px 6px 12px;
    border-top: 1px solid #e6ecef;
    background: #fff;
    flex: 0 0 auto;
}
.icb-input {
    flex: 1 1 auto;
    min-height: 44px;
    max-height: 120px;
    padding: 11px 12px;
    border: 1px solid #d5dee3;
    border-radius: 12px;
    background: #fff;
    color: #1a1a1a;
    font: inherit;
    font-size: 16px; /* иначе iOS увеличава страницата при фокус */
    line-height: 1.35;
    resize: none;
}
.icb-input:focus { border-color: #E78640; outline: none; box-shadow: 0 0 0 3px rgba(231, 134, 64, .18); }
.icb-input:disabled { background: #f3f5f7; }
.icb-send {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 12px;
    background: #E78640;
    color: #fff;
    cursor: pointer;
    transition: background-color .2s ease, transform .15s ease;
}
.icb-send:hover { background: #d67530; }
.icb-send:active { transform: scale(.96); }
.icb-send:disabled { background: #f0c9a8; cursor: default; }
.icb-send svg { width: 20px; height: 20px; }
.icb-count { padding: 0 14px; color: #6c757d; font-size: 12px; text-align: right; background: #fff; }
.icb-count.is-over { color: #b42318; }

.icb-foot {
    padding: 4px 14px 10px;
    background: #fff;
    color: #7a8791;
    font-size: 11.5px;
    line-height: 1.4;
    flex: 0 0 auto;
}
.icb-foot a { color: #7a8791 !important; text-decoration: underline !important; }
.icb-foot a:hover { color: #2e5365 !important; }

.icb-new {
    display: block;
    margin: 4px auto 12px;
    padding: 7px 14px;
    border: 0;
    border-radius: 999px;
    background: #eef3f5;
    color: #2e5365;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
}
.icb-new:hover { background: #e0eaee; }

/* ---------- телефон (и телефон легнал настрани): на цял екран ----------
   Височината и отместването ги задава js/chat.js по видимата част над
   клавиатурата; 100dvh е само докато скриптът се включи. */
@media (max-width: 575.98px), (pointer: coarse) and (max-height: 500px) {
    .icb-panel {
        top: 0;
        right: 0;
        bottom: auto;
        left: 0;
        z-index: 1060;
        width: 100%;
        max-width: none;
        height: 100%;
        height: 100dvh;
        border-radius: 0;
        transform: translateY(16px);
    }
    .icb-head { padding-top: calc(12px + env(safe-area-inset-top)); }
    .icb-foot { padding-bottom: calc(10px + env(safe-area-inset-bottom)); }
    .icb-bubble { max-width: 90%; }
    /* докато се пише, всеки пиксел над клавиатурата е за разговора */
    .icb-panel.is-typing .icb-foot { display: none; }
    .icb-panel.is-typing .icb-head { padding-top: 8px; padding-bottom: 8px; }
    html.icb-open,
    html.icb-open body { overflow: hidden !important; }
    /* докато чатът е на цял екран, бутонът и поканата не трябват */
    html.icb-open .icb-fab,
    html.icb-open .icb-teaser { display: none !important; }
}

@keyframes icb-dot {
    0%, 80%, 100% { transform: translateY(0); opacity: .5; }
    40% { transform: translateY(-4px); opacity: 1; }
}
@keyframes icb-pop {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
    .icb-fab, .icb-panel, .icb-teaser { transition: none; animation: none; }
    .icb-typing span { animation: none; opacity: .7; }
}

/* резултатът от „Нова парола за Moodle“ в чата */
.icb-card .icb-ok,
.icb-card .icb-err { font-size: 14.5px; line-height: 1.5; font-weight: 500; }
.icb-card .icb-ok p,
.icb-card .icb-err p { margin: 0 !important; font-size: inherit !important; }
.icb-card .icb-ok a,
.icb-card .icb-err a { color: inherit !important; font-weight: 700; text-decoration: underline !important; }
