/* GŁÓWNY KONTENER CZATU */
#crmChatContainer {
    position: fixed;
    bottom: 0;
    right: 0;
    z-index: 9999; /* nad resztą strony */
    font-size: 13px;
    font-family: inherit;
    color: #fff;
}

/* Tryb zminimalizowany vs otwarty */
.crm-chat-minimized #crmChatPanel {
    display: none;
}

.crm-chat-open #crmChatPanel {
    display: block;
}

/* Pasek zminimalizowany (zawsze widoczny w prawym dolnym rogu) */
.crm-chat-bar {
    background: #24384c;
    border-radius: 8px 8px 0 0;
    padding: 4px 8px;
    min-width: 260px;
    display: flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 0 6px rgba(0,0,0,0.4);
}

.crm-chat-bar-title {
    font-weight: 600;
    margin-right: 4px;
}

.crm-chat-bar-tabs {
    flex: 1;
    display: flex;
    gap: 4px;
    overflow-x: auto;
}

.crm-chat-bar-tab {
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    padding: 2px 4px;
    white-space: nowrap;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 2px;
    font-size: 11px;
}

.crm-chat-bar-tab-name {
    max-width: 90px;
    text-overflow: ellipsis;
    overflow: hidden;
}

.crm-chat-bar-tab-unread {
    min-width: 16px;
    text-align: center;
    border-radius: 8px;
    padding: 0 3px;
    font-size: 10px;
    background: #c0392b;
    display: none;
}

.crm-chat-bar-tab-unread.has-unread {
    display: inline-block;
}

.crm-chat-bar-toggle {
    cursor: pointer;
    padding: 0 4px;
}

/* PANEL ROZWINIĘTY */
.crm-chat-panel {
    background: #34495e;
    border-radius: 8px 8px 0 0;
    width: 360px;
    height: 420px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
}

/* Nagłówek z zakładkami */
.crm-chat-header {
    display: flex;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding: 4px;
}

.crm-chat-add {
    border: none;
    background: rgba(255,255,255,0.15);
    color: #fff;
    cursor: pointer;
    font-size: 16px;
    padding: 0 6px;
    margin-right: 4px;
    border-radius: 4px;
}
.crm-chat-add:hover {
    background: rgba(255,255,255,0.3);
}

.crm-chat-tabs {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex: 1;
    overflow-x: auto;
    gap: 4px;
}

.crm-chat-tab {
    background: rgba(255,255,255,0.1);
    border-radius: 4px;
    padding: 2px 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    white-space: nowrap;
}

.crm-chat-tab.active {
    background: #1abc9c;
    color: #fff;
}

.crm-chat-tab-name {
    max-width: 120px;
    text-overflow: ellipsis;
    overflow: hidden;
}

.crm-chat-tab-unread {
    min-width: 16px;
    text-align: center;
    border-radius: 8px;
    padding: 0 3px;
    font-size: 10px;
    background: #c0392b;
    display: none;
}

.crm-chat-tab-unread.has-unread {
    display: inline-block;
}

.crm-chat-tab-close {
    cursor: pointer;
    font-weight: bold;
}

.crm-chat-close {
    border: none;
    background: transparent;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    padding: 0 4px;
}

/* ŚRODEK – wiadomości */
.crm-chat-body {
    flex: 1;
    overflow: hidden;
}

.crm-chat-messages {
    height: 100%;
    padding: 6px;
    overflow-y: auto;
}

/* Wiadomości */
.crm-chat-message {
    margin-bottom: 6px;
    max-width: 90%;
}

.crm-chat-message-own {
    margin-left: auto;
    text-align: right;
}

.crm-chat-message-other {
    margin-right: auto;
}

.crm-chat-message-header {
    font-size: 11px;
    opacity: 0.8;
    margin-bottom: 2px;
}

.crm-chat-message-username {
    font-weight: 600;
}

.crm-chat-role-badge {
    margin-left: 4px;
    padding: 0 4px;
    border-radius: 4px;
    font-size: 10px;
}

.crm-chat-role-admin {
    background: #e67e22;
}

.crm-chat-role-director {
    background: #9b59b6;
}

.crm-chat-message-time {
    margin-left: 6px;
}

.crm-chat-message-content {
    background: rgba(0,0,0,0.15);
    border-radius: 6px;
    padding: 4px 6px;
    font-size: 13px;
}

.crm-chat-message-own .crm-chat-message-content {
    background: #1abc9c;
}

/* Wiadomości systemowe */
.crm-chat-message-system {
    text-align: center;
    font-size: 11px;
    opacity: 0.8;
}

.crm-chat-message-system-text {
    font-style: italic;
}

/* STOPKA – input + toolbar */
.crm-chat-footer {
    border-top: 1px solid rgba(255,255,255,0.1);
    padding: 4px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.crm-chat-toolbar {
    display: flex;
    gap: 4px;
}

.crm-chat-btn {
    border: none;
    background: rgba(255,255,255,0.1);
    color: #fff;
    border-radius: 4px;
    padding: 2px 4px;
    cursor: pointer;
    font-size: 12px;
}

.crm-chat-input {
    width: 100%;
    resize: none;
    border-radius: 4px;
    border: 1px solid rgba(0,0,0,0.2);
    padding: 4px;
    font-size: 13px;
    color: #000;
}

.crm-chat-send-btn {
    align-self: flex-end;
    margin-top: 2px;
    padding: 2px 8px;
    font-size: 12px;
    border-radius: 4px;
    border: none;
    background: #1abc9c;
    color: #fff;
    cursor: pointer;
}

/* FULLSCREEN NA MOBILE */
.crm-chat-fullscreen {
    left: 0;
    right: 0;
    bottom: 0;
    top: 0;
}

.crm-chat-fullscreen .crm-chat-panel {
    width: 100vw;
    height: calc(100vh - 32px); /* pasek + panel */
}

/* Prostszą wersję można wymusić na mniejszych ekranach */
@media (max-width: 768px) {
    #crmChatContainer.crm-chat-open {
        left: 0;
        right: 0;
        bottom: 0;
    }

    .crm-chat-panel {
        width: 100vw;
        height: calc(100vh - 32px);
        border-radius: 0;
    }

    .crm-chat-bar {
        width: 100vw;
        border-radius: 0;
    }
}

#crmChatContainer.crm-chat-minimized .crm-chat-bar {
    display: flex;
}

#crmChatContainer.crm-chat-minimized #crmChatPanel {
    display: none;
}

/* po otwarciu: chowamy bar, pokazujemy panel */
#crmChatContainer.crm-chat-open .crm-chat-bar {
    display: none;
}

#crmChatContainer.crm-chat-open #crmChatPanel {
    display: flex; /* zamiast block, bo panel ma flex-direction: column */
}

/* MODAL NOWEGO CZATU */
.crm-chat-modal {
    position: absolute;
    inset: 0;                  /* top:0; right:0; bottom:0; left:0; */
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 20;               /* wyżej niż treść chatu */
}

.crm-chat-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.4);
}

.crm-chat-modal-dialog {
    position: relative;
    background: #2c3e50;
    color: #fff;
    border-radius: 8px;
    min-width: 280px;
    max-width: 95%;
    max-height: 90%;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 10px rgba(0,0,0,0.6);
    z-index: 1;
}

.crm-chat-modal-header {
    padding: 8px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-weight: 600;
}

.crm-chat-modal-close {
    border: none;
    background: transparent;
    color: #fff;
    cursor: pointer;
    font-size: 18px;
}

.crm-chat-modal-body {
    padding: 10px;
    overflow-y: auto;
    font-size: 13px;
}

.crm-chat-modal-row {
    margin-bottom: 10px;
}

.crm-chat-modal-input {
    width: 100%;
    border-radius: 4px;
    border: 1px solid rgba(0,0,0,0.3);
    padding: 4px 6px;
    font-size: 13px;
    color: #000;
}

.crm-chat-users-list {
    max-height: 260px;
    overflow-y: auto;
    border-radius: 4px;
    border: 1px solid rgba(255,255,255,0.2);
    padding: 4px;
    background: rgba(0,0,0,0.1);
}

.crm-chat-user-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 2px 4px;
    border-radius: 4px;
    cursor: pointer;
}

.crm-chat-user-item:hover {
    background: rgba(255,255,255,0.08);
}

.crm-chat-user-checkbox {
    margin: 0;
}

.crm-chat-user-label-main {
    font-weight: 600;
}

.crm-chat-user-label-meta {
    font-size: 11px;
    opacity: 0.8;
}

.crm-chat-modal-footer {
    padding: 8px 10px;
    border-top: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.crm-chat-modal-btn {
    border-radius: 4px;
    border: none;
    padding: 4px 10px;
    font-size: 13px;
    cursor: pointer;
}

.crm-chat-modal-btn-primary {
    background: #1abc9c;
    color: #fff;
}

.crm-chat-modal-btn:not(.crm-chat-modal-btn-primary) {
    background: #7f8c8d;
    color: #fff;
}

.crm-chat-panel {
    position: relative;          /* NOWE */
    background: #34495e;
    border-radius: 8px 8px 0 0;
    width: 360px;
    height: 420px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 0 10px rgba(0,0,0,0.5);
}
