/* =====================================================
   ANASOF CHAT — TROKOLONSKI INTERFEJS
   ===================================================== */

.chat-layout {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
    height: min(77vh, 830px);
    min-height: 500px;
}

.chat-panel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    background: #fff;
    border: 1px solid #e1e8ef;
    border-bottom: 2px solid #2a7fc3;
    border-radius: 14px;
    box-shadow: 0 5px 18px rgba(33, 64, 96, .035);
}

.chat-tabs {
    display: flex;
    justify-content: space-around;
    padding: 12px 10px 0;
    border-bottom: 1px solid #e9eef4;
}

.chat-tabs button {
    padding: 10px 9px 13px;
    border: 0;
    border-bottom: 2px solid transparent;
    background: transparent;
    color: #44546a;
    font: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
}

.chat-tabs button.active {
    color: #1675ba;
    border-bottom-color: #1675ba;
}

.chat-sidebar-tools { padding: 14px 12px; display: grid; gap: 10px; }
.chat-new { border: 0; border-radius: 9px; background: #1977b9; color: white; padding: 11px 13px; cursor: pointer; font: inherit; font-size: 13px; font-weight: 600; }
.chat-sidebar-tools input, .chat-dialog input, .chat-dialog select { width: 100%; box-sizing: border-box; padding: 10px 12px; border: 1px solid #dfe6ed; border-radius: 9px; font: inherit; font-size: 13px; }
.chat-conversations { overflow-y: auto; flex: 1; }
.chat-conversation { display: flex; align-items: center; gap: 10px; width: 100%; padding: 14px 11px; text-align: left; background: #fff; border: 0; border-bottom: 1px solid #edf1f5; cursor: pointer; color: #293b48; }
.chat-conversation:hover, .chat-conversation.active { background: #eaf4ff; }
.chat-conversation-body { display: grid; gap: 5px; min-width: 0; flex: 1; }
.chat-conversation-body strong { font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-conversation-body small, .chat-conversation > small { font-size: 11px; color: #748397; }
.chat-avatar { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%; background: #e5f0ff; color: #2879b6; font-size: 21px; }
.chat-list-empty { padding: 20px 14px; color: #7b8797; font-size: 13px; }
.chat-heading { display: flex; align-items: center; gap: 12px; padding: 14px 17px; border-bottom: 1px solid #e8edf3; }
.chat-heading > div:last-child { display: grid; gap: 4px; }
.chat-heading strong { color: #223247; font-size: 15px; }
.chat-heading span { color: #78869a; font-size: 12px; }
.chat-messages { display: flex; flex-direction: column; gap: 14px; flex: 1; min-height: 0; overflow-y: auto; padding: 20px; background: #fcfdff; }
.chat-empty { margin: auto; text-align: center; color: #8794a4; font-size: 13px; }
.chat-bubble { align-self: flex-start; max-width: 78%; padding: 12px 15px; background: #edf0f5; border-radius: 15px 15px 15px 4px; font-size: 13px; color: #1c2938; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-bubble.chat-mine { align-self: flex-end; background: #dcecff; border-radius: 15px 15px 4px 15px; }
.chat-bubble small { display: block; margin-top: 8px; color: #64778d; font-size: 10px; }
.chat-compose { display: flex; gap: 9px; padding: 13px; border-top: 1px solid #e9edf2; }
.chat-compose input { flex: 1; min-width: 0; border: 1px solid #dfe6ef; border-radius: 10px; padding: 12px 13px; font: inherit; font-size: 13px; }
.chat-compose button { padding: 0 18px; border: 0; border-radius: 10px; color: #fff; background: #1977b9; cursor: pointer; }
.chat-compose button:disabled { opacity: .45; cursor: not-allowed; }
.chat-status { color: #a14343; font-size: 12px; padding: 0 16px; }
.chat-status:not(:empty) { padding-top: 8px; }
.chat-info-title { padding: 24px 17px 18px; font-weight: 700; border-bottom: 1px solid #e9edf2; font-size: 14px; }
.chat-info-body { padding: 17px; overflow-y: auto; color: #64758a; font-size: 13px; }
.chat-info-body h3 { color: #243347; font-size: 15px; margin: 0 0 10px; }
.chat-info-body h4 { color: #243347; font-size: 13px; margin: 24px 0 12px; }
.chat-person-line { padding: 12px 0; border-bottom: 1px solid #edf1f5; color: #344459; }
.chat-dialog-backdrop { position: fixed; inset: 0; z-index: 10020; background: rgba(16, 31, 52, .4); display: grid; place-items: center; padding: 15px; }
.chat-dialog-backdrop[hidden] { display: none !important; }
.chat-dialog { display: grid; gap: 15px; width: min(460px, 100%); max-height: 85vh; overflow: auto; padding: 22px; border-radius: 15px; border-bottom: 2px solid #1977b9; background: #fff; box-shadow: 0 18px 50px rgba(20, 37, 60, .18); }
.chat-dialog-head { display: flex; justify-content: space-between; align-items: center; }
.chat-dialog-head button { background: none; border: 0; cursor: pointer; font-size: 18px; }
.chat-dialog label { display: grid; gap: 8px; font-size: 12px; font-weight: 600; color: #43556a; }
.chat-dialog label[hidden] { display: none !important; }
.chat-people { max-height: 210px; overflow: auto; border: 1px solid #e8edf2; border-radius: 9px; }
.chat-person-option { display: flex !important; grid-template-columns: none; flex-direction: row; align-items: center; gap: 10px; padding: 11px; border-bottom: 1px solid #eef1f5; cursor: pointer; }
.chat-person-option input { width: auto; }
.chat-dialog-actions { display: flex; justify-content: flex-end; gap: 10px; }
.chat-dialog-actions > button:first-child { border: 1px solid #dfe6ee; background: #fff; border-radius: 9px; padding: 10px 15px; cursor: pointer; }
@media (max-width: 900px) { .chat-layout { grid-template-columns: minmax(230px, 1fr) minmax(0, 1fr); } .chat-info { display: none; } }
@media (max-width: 700px) { .chat-layout { grid-template-columns: 1fr; grid-template-rows: 235px minmax(360px, 1fr); height: 85vh; } }

/* =====================================================
   CHAT V4 — UPRAVLJANJE, REAKCIJE, BROJAČI
   ===================================================== */
.chat-unread, .chat-nav-unread {
    display: inline-grid;
    place-items: center;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    border-radius: 12px;
    background: #1977b9;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
}
.chat-nav-unread[hidden] { display: none; }
.chat-outline {
    width: 100%;
    margin-top: 15px;
    padding: 10px;
    border: 1px solid #a7c9eb;
    border-radius: 9px;
    color: #176eb1;
    background: #fff;
    cursor: pointer;
}
.chat-reactions { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 8px; }
.chat-reactions button { border: 0; background: transparent; cursor: pointer; font-size: 13px; opacity: .75; }
.chat-reactions button:hover { opacity: 1; transform: scale(1.12); }
.chat-person-option > span { flex: 1; }
.chat-person-option > button { padding: 5px 9px; border: 1px solid #d8e5f0; border-radius: 7px; background: #fff; color: #b53c3c; cursor: pointer; }

/* =====================================================
   ANASOF CHAT — KOMPAKTNE PORUKE
   Primjenjuje se samo na glavni Chat modul.
   ===================================================== */

.chat-message-search {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 13px;
    border-bottom: 1px solid #e8edf3;
    color: #64748b;
}

.chat-message-search input {
    width: 100%;
    min-width: 0;
    padding: 6px 8px;
    border: 0;
    outline: 0;
    background: transparent;
    font: inherit;
    font-size: 12px;
}

.chat-message-search button {
    border: 0;
    background: transparent;
    color: #7c8797;
    cursor: pointer;
    font-size: 17px;
}

.chat-main .chat-messages {
    gap: 7px;
    padding: 12px 16px;
    background: #fff;
}

.chat-day-separator {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 10px 0;
    color: #718096;
    font-size: 10px;
    text-align: center;
}

.chat-day-separator::before,
.chat-day-separator::after {
    content: "";
    height: 1px;
    flex: 1;
    background: #e9edf2;
}

.chat-day-separator span {
    padding: 5px 10px;
    border-radius: 15px;
    background: #f1f4f8;
}

.chat-message-row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    max-width: 79%;
    align-self: flex-start;
    gap: 3px;
}

.chat-message-row.chat-message-own {
    align-self: flex-end;
    align-items: flex-end;
}

.chat-message-meta {
    display: flex;
    align-items: baseline;
    gap: 8px;
    padding: 0 4px;
    color: #263548;
    font-size: 11px;
}

.chat-message-meta time {
    color: #8995a4;
    font-size: 10px;
}

.chat-message-box {
    max-width: 100%;
    padding: 9px 12px;
    border-radius: 13px 13px 13px 4px;
    background: #edf0f5;
    color: #253044;
    font-size: 12px;
    line-height: 1.42;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.chat-message-own .chat-message-box {
    background: #dcecff;
    border-radius: 13px 13px 4px 13px;
}

.chat-message-footer {
    display: flex;
    align-items: center;
    gap: 7px;
    min-height: 16px;
    width: 100%;
    padding: 0 4px;
    color: #8492a4;
    font-size: 11px;
}

.chat-message-spacer { flex: 1; }
.chat-reaction-summary[hidden],
.chat-emoji-picker[hidden] { display: none !important; }
.chat-reaction-summary { font-size: 11px; }
.chat-emoji-wrap { position: relative; }

.chat-emoji-trigger {
    padding: 0 3px;
    border: 0;
    background: transparent;
    color: #9aa7b7;
    cursor: pointer;
    font-size: 15px;
}

.chat-emoji-trigger:hover { color: #1977b9; }

.chat-emoji-picker {
    position: fixed;
    width: 220px;
    box-sizing: border-box;
    justify-content: center;
    display: flex;
    gap: 3px;
    z-index: 8;
    padding: 5px;
    border: 1px solid #e3e9f1;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 6px 20px rgba(27, 44, 64, .12);
}

.chat-emoji-picker button {
    border: 0;
    background: transparent;
    padding: 4px;
    cursor: pointer;
    font-size: 15px;
}

.chat-read-icon { color: #9ca8b7; font-weight: 700; }
.chat-read-icon.is-read { color: #1977b9; }

@media (max-width: 700px) {
    .chat-message-row { max-width: 92%; }
    .chat-main .chat-messages { padding: 10px; }
}

/* ===== SKRIVEN SCROLLBAR U GLAVNOM CHATU; SKROLOVANJE OSTAJE ===== */
.chat-messages, .chat-conversations, .chat-info-body { scrollbar-width: none; -ms-overflow-style: none; }
.chat-messages::-webkit-scrollbar, .chat-conversations::-webkit-scrollbar, .chat-info-body::-webkit-scrollbar { display: none; }

/* =====================================================
   GLAVNI CHAT — PROPORCIJE, VISINA I KOMPAKTNA LISTA
   ===================================================== */

.chat-layout {
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 1.15fr) minmax(0, .8fr);
    height: calc(100dvh - 150px);
    min-height: 420px;
    max-height: none;
}

.chat-sidebar .chat-conversations {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.chat-sidebar .chat-conversation {
    gap: 9px;
    padding: 8px 11px;
}

.chat-sidebar .chat-conversation-body { gap: 2px; }
.chat-sidebar .chat-avatar { width: 34px; height: 34px; font-size: 18px; }
.chat-sidebar .chat-sidebar-tools { padding: 10px 12px; gap: 7px; }
.chat-sidebar .chat-tabs { padding-top: 6px; }
.chat-sidebar .chat-tabs button { padding: 8px 7px 10px; }

/* Višeredni unos poruke, do 132px. */
.chat-compose { align-items: flex-end; }
.chat-compose textarea {
    display: block;
    flex: 1;
    min-width: 0;
    min-height: 42px;
    max-height: 132px;
    box-sizing: border-box;
    resize: none;
    overflow-y: auto;
    border: 1px solid #dfe6ef;
    border-radius: 10px;
    padding: 11px 13px;
    font: inherit;
    font-size: 13px;
    line-height: 19px;
    scrollbar-width: none;
}
.chat-compose textarea::-webkit-scrollbar { display: none; }
.chat-compose button { min-height: 42px; }

/* Opis ispod naslova razgovora tiketa, iz baze tiketa. */
.chat-info-body .chat-ticket-description-title { margin: 16px 0 8px; }
.chat-ticket-description {
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    line-height: 1.5;
    color: #415168;
    font-size: 12px;
}

@media (max-width: 900px) {
    .chat-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}

@media (max-width: 700px) {
    .chat-layout {
        grid-template-columns: 1fr;
        grid-template-rows: 220px minmax(300px, 1fr);
        height: calc(100dvh - 120px);
    }
}


/* =====================================================
   CHAT - MOBILNI PRIKAZ RAZGOVORA
   ===================================================== */

.chat-mobile-back {
    display: none;
}

.chat-action-icon {
    display: none;
}

@media (max-width: 700px) {
    .chat-layout {
        display: block;
        position: relative;
        width: 100%;
        height: calc(100dvh - 110px);
        min-height: 0;
        overflow: hidden;
    }

    .chat-layout .chat-sidebar,
    .chat-layout .chat-main {
        width: 100%;
        height: 100%;
        min-height: 0;
        box-sizing: border-box;
    }

    .chat-layout .chat-main {
        display: none;
    }

    .chat-layout.chat-mobile-open .chat-sidebar {
        display: none;
    }

    .chat-layout.chat-mobile-open .chat-main {
        display: flex;
    }

    .chat-layout .chat-info {
        display: none;
    }

    .chat-sidebar .chat-tabs {
        flex: none;
        padding: 4px 5px 0;
    }

    .chat-sidebar .chat-tabs button {
        padding: 9px 7px;
        font-size: 12px;
    }

    .chat-sidebar .chat-sidebar-tools {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 36px 36px;
        align-items: center;
        gap: 6px;
        padding: 8px 10px;
    }

    .chat-sidebar-tools [data-search] {
        grid-column: 1;
        grid-row: 1;
        min-width: 0;
        height: 36px;
        padding: 8px 10px;
        font-size: 12px;
    }

    .chat-sidebar-tools [data-new],
    .chat-sidebar-tools [data-external] {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 36px;
        height: 36px;
        min-height: 0;
        margin: 0;
        padding: 0;
        border: 1px solid #8ebcff;
        border-radius: 9px;
        background: #fff;
        color: #1977b9;
    }

    .chat-sidebar-tools [data-new] {
        grid-column: 2;
        grid-row: 1;
    }

    .chat-sidebar-tools [data-external] {
        grid-column: 3;
        grid-row: 1;
    }

    .chat-sidebar-tools .chat-action-icon {
        display: inline;
        font-size: 19px;
        line-height: 1;
    }

    .chat-sidebar-tools .chat-action-label {
        display: none;
    }

    .chat-sidebar .chat-conversations {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .chat-sidebar .chat-conversation {
        padding: 10px;
    }

    .chat-main .chat-heading {
        flex: none;
        gap: 8px;
        padding: 9px 10px;
    }

    .chat-main .chat-mobile-back {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        flex: 0 0 30px;
        width: 30px;
        height: 34px;
        border: 0;
        background: transparent;
        color: #1977b9;
        font-size: 24px;
        cursor: pointer;
    }

    .chat-main .chat-heading > div:last-child {
        min-width: 0;
    }

    .chat-main .chat-heading strong,
    .chat-main .chat-heading span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .chat-main .chat-message-search {
        flex: none;
        padding: 5px 9px;
    }

    .chat-main .chat-messages {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        overscroll-behavior: contain;
    }

    .chat-main .chat-compose {
        flex: none;
        padding: 8px;
        gap: 7px;
    }

    .chat-main .chat-compose textarea {
        min-height: 38px;
        padding: 8px 10px;
    }

    .chat-main .chat-compose button {
        min-height: 38px;
        padding: 0 13px;
    }
}
