/* Chat Widget Styles - isti kao prije, bez promjena */
.chat-widget-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 9999;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* NOVO: Skrivanje chat widgeta kada admini nisu dostupni */
.chat-widget-container.chat-hidden {
    display: none !important;
}

.chat-widget-button {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.4s ease;
    position: relative;
}

.chat-widget-button:hover {
    transform: scale(1.05);
    box-shadow: 0 6px 20px rgba(0,0,0,0.2);
}

.chat-widget-button:active {
    transform: scale(0.95);
}

/* Kada se otvara chat - pulse efekat */
.chat-widget-container.chat-window-open .chat-widget-button {
    border-radius: 10% 50% 50% 50%;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15), 0 0 0 0 rgba(102, 126, 234, 0.4);
    animation: buttonPulse 2s infinite;
}

@keyframes buttonPulse {
    0% {
        box-shadow: 0 4px 12px rgba(0,0,0,0.15), 0 0 0 0 rgba(102, 126, 234, 0.4);
    }
    50% {
        box-shadow: 0 4px 12px rgba(0,0,0,0.15), 0 0 0 8px rgba(102, 126, 234, 0);
    }
    100% {
        box-shadow: 0 4px 12px rgba(0,0,0,0.15), 0 0 0 0 rgba(102, 126, 234, 0);
    }
}

.chat-widget-button svg {
    width: 28px;
    height: 28px;
    fill: white;
}

.chat-unread-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    background: #ff3b30;
    color: white;
    border-radius: 12px;
    padding: 2px 8px;
    font-size: 12px;
    font-weight: bold;
    min-width: 20px;
    text-align: center;
    animation: pulse 2s infinite;
}

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

/* Chat Widget Window Animation */
@keyframes windowSlideIn {
    0% {
        transform: scale(0.3) translateY(30px);
        opacity: 0;
    }
    60% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

@keyframes windowSlideOut {
    0% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
    40% {
        transform: scale(1.05) translateY(-5px);
        opacity: 1;
    }
    100% {
        transform: scale(0.3) translateY(30px);
        opacity: 0;
    }
}

.chat-widget-window {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 380px;
    min-height: 600px;
    background: white;
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.15);
    display: none;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.3) translateY(30px);
    opacity: 0;
    transform-origin: bottom right;
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chat-widget-window.active {
    display: flex;
    position: fixed;
    bottom: 90px;
    right: 90px;
    transform: scale(1) translateY(0);
    opacity: 1;
    animation: windowSlideIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.chat-widget-window.closing {
    animation: windowSlideOut 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}

/* Chat Header */
.chat-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.chat-header-info h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
}

.chat-header-info p {
    margin: 4px 0 0 0;
    font-size: 14px;
    opacity: 0.9;
}

.chat-header-buttons {
    display: flex;
    gap: 8px;
}

.chat-minimize-btn,
.chat-close-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 6px;
    height: 36px !important;
    width: 36px !important;
    line-height: 1em !important;
    border-radius: 4px;
    transition: background 0.2s;
    background: rgba(255,255,255,0.05);
    
}

.chat-minimize-btn:hover,
.chat-close-btn:hover {
    background: rgba(255,255,255,0.2);
}

.chat-minimize-btn svg,
.chat-close-btn svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* Chat Messages Area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background: #f8f9fa;
    max-height: 435px !important;
}

/* NOVA STRUKTURA PORUKA - 2 dijela: avatar lijevo, ime+sadržaj desno */
.chat-message {
    margin-bottom: 16px;
    display: flex;
    align-items: flex-start;
    animation: fadeIn 0.2s ease;
    gap: 12px;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

/* User poruke - avatar i sadržaj desno */
.chat-message.user {
    flex-direction: row-reverse;
}

.chat-message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    flex-shrink: 0;
}

/* Desni dio - ime i sadržaj jedan ispod drugog */
.chat-message-right {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0; /* Omogućava shrinking */
}

/* Admin poruke - normalan flow */
.chat-message.admin .chat-message-right {
    align-items: flex-start;
}

/* User poruke - sve poravnano desno */
.chat-message.user .chat-message-right {
    align-items: flex-end;
}

/* Ime/prezime pošiljatelja */
.chat-message-sender {
    font-size: 12px;
    color: #666;
    font-weight: 600;
    line-height: 1.2;
    margin-bottom: 4px;
    word-wrap: break-word;
    max-width: fit-content;
}

/* User poruke - ime uz avatar desno */
.chat-message.user .chat-message-sender {
    text-align: right;
}

/* Admin poruke - ime uz avatar lijevo */  
.chat-message.admin .chat-message-sender {
    text-align: left;
}

/* Sadržaj poruke */
.chat-message-content {
    background: white;
    padding: 8px 12px;
    border-radius: 16px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.08);
    word-wrap: break-word;
    max-width: 100%;
}

.chat-message.user .chat-message-content {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.chat-message-text {
    margin: 0;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-message-time {
    font-size: 11px;
    opacity: 0.7;
    margin-top: 4px;
}

/* System poruke - poseban stil */
.chat-message.system {
    justify-content: center;
    text-align: center;
    margin: 16px 0;
    opacity: 0.8;
}

.chat-message.system .chat-message-content {
    background: #f0f0f0;
    color: #666;
    font-style: italic;
    font-size: 13px;
    max-width: 100%;
}

.chat-message.system .chat-message-right {
    align-items: center;
}

/* Chat Form */
.chat-form-container {
    border-top: 1px solid #e9ecef;
    padding: 16px;
    background: white;
}

.chat-start-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chat-form-input {
    padding: 12px 16px;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.2s;
}

.chat-form-input:focus {
    outline: none;
    border-color: #667eea;
}

.chat-form-input:disabled {
    background-color: #f8f9fa;
    cursor: not-allowed;
}

.chat-form-submit {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
}

.chat-form-submit:hover {
    transform: translateY(-1px);
}

.chat-form-submit:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

/* User info display for logged in users */
.chat-user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 12px;
}

.chat-user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    flex-shrink: 0;
}

.chat-user-details {
    flex: 1;
}

.chat-user-name {
    font-weight: 600;
    font-size: 14px;
    color: #333;
    margin: 0;
}

.chat-user-email {
    font-size: 12px;
    color: #666;
    margin: 2px 0 0 0;
}

.chat-user-label {
    font-style: italic;
    color: #666;
    font-size: 12px;
    margin-top: 4px;
}

/* Chat Input */
.chat-input-container {
    display: flex;
    gap: 8px;
    align-items: center;
}

.chat-input {
    flex: 1;
    padding: 12px 16px;
    border: 1px solid #e9ecef;
    border-radius: 24px;
    font-size: 14px;
    resize: none;
    max-height: 100px;
}

.chat-input:focus {
    outline: none;
    border-color: #667eea;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.chat-send-btn:hover {
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.chat-send-btn svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* Attachment Button */
.chat-attach-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.chat-attach-btn:hover {
    transform: scale(1.05);
}

.chat-attach-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.chat-attach-btn svg {
    width: 20px;
    height: 20px;
    fill: white;
}

/* Typing Indicator */
.chat-typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    color: #6c757d;
    font-size: 13px;
}

.typing-dots {
    display: flex;
    gap: 4px;
}

.typing-dot {
    width: 6px;
    height: 6px;
    background: #6c757d;
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

.typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-4px);
    }
}

/* Loading State */
.chat-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: #6c757d;
}

.chat-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid #f3f4f6;
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Confirmation Modal */
.chat-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
    z-index: 10000;
}

.chat-modal-overlay.active {
    display: flex;
}

.chat-modal {
    background: white;
    padding: 24px;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    max-width: 320px;
    width: 90%;
    text-align: center;
}

.chat-modal h3 {
    margin: 0 0 12px 0;
    font-size: 18px;
    color: #333;
}

.chat-modal p {
    margin: 0 0 20px 0;
    color: #666;
    font-size: 14px;
}

.chat-modal-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

.chat-modal-btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.2s;
}

.chat-modal-btn:hover {
    transform: translateY(-1px);
}

.chat-modal-btn-cancel {
    background: #e9ecef;
    color: #495057;
}

.chat-modal-btn-cancel:hover {
    background: #dee2e6;
}

.chat-modal-btn-confirm {
    background: #dc3545;
    color: white;
}

.chat-modal-btn-confirm:hover {
    background: #c82333;
}

/* Responsive */
@media (max-width: 480px) {
    .chat-widget-container {
        bottom: 10px;
        right: 10px;
    }
    
    .chat-widget-window,
    .chat-widget-window.active {
        width: 100%;
        height: 100%;
        bottom: 0;
        right: 0;
        border-radius: 0;
        position: fixed;
        transform-origin: bottom right;
    }
    
    .chat-widget-window {
        transform: scale(0.8) translateY(100%);
    }
    
    .chat-widget-window.active {
        transform: scale(1) translateY(0);
        animation: windowSlideInMobile 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    }
    
    .chat-widget-window.closing {
        animation: windowSlideOutMobile 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    }
    
    .chat-message {
        gap: 8px;
    }
    
    .chat-message-avatar {
        width: 32px;
        height: 32px;
    }
}

@keyframes windowSlideInMobile {
    0% {
        transform: scale(0.8) translateY(100%);
        opacity: 0;
    }
    100% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
}

@keyframes windowSlideOutMobile {
    0% {
        transform: scale(1) translateY(0);
        opacity: 1;
    }
    100% {
        transform: scale(0.8) translateY(100%);
        opacity: 0;
    }
}

/* Attachment preview - POPRAVI IZGLED */
.chat-attachment {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: rgba(0,0,0,0.05);
    border-radius: 8px;
    margin-top: 8px;
    font-size: 13px;
}

.chat-message.user .chat-attachment {
    background: rgba(255,255,255,0.1);
}

.chat-attachment-icon {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.1);
    border-radius: 4px;
    flex-shrink: 0;
}

.chat-message.user .chat-attachment-icon {
    background: rgba(255,255,255,0.2);
}

.chat-attachment-icon svg {
    width: 20px;
    height: 20px;
    fill: #495057;
}

.chat-message.user .chat-attachment-icon svg {
    fill: white;
}

.chat-attachment-info {
    flex: 1;
    overflow: hidden;
}

.chat-attachment-name {
    font-weight: 500;
    word-break: break-all;
    color: #333;
    margin-bottom: 2px;
}

.chat-message.user .chat-attachment-name {
    color: white;
}

.chat-attachment-size {
    font-size: 12px;
    opacity: 0.7;
    color: #666;
}

.chat-message.user .chat-attachment-size {
    color: white;
    opacity: 0.8;
}

/* Upload indicator */
.chat-upload-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px;
    background: rgba(0,0,0,0.05);
    border-radius: 8px;
    margin-top: 8px;
    font-size: 13px;
}

.chat-message.user .chat-upload-indicator {
    background: rgba(255,255,255,0.1);
    color: white;
}

.upload-spinner {
    width: 16px;
    height: 16px;
    border: 2px solid rgba(0,0,0,0.1);
    border-top-color: #667eea;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

.chat-message.user .upload-spinner {
    border-color: rgba(255,255,255,0.2);
    border-top-color: white;
}

/* Link stil za attachment */
.chat-attachment a {
    text-decoration: none;
    color: inherit;
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
}

.chat-attachment a:hover .chat-attachment-name {
    text-decoration: underline;
}

/* Attachment Preview Section */
.chat-attachment-preview {
    margin-bottom: 15px;
    background: #f8f9fa;
}

.attachment-preview-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 8px 12px;
    background: white;
    border: 1px solid #e9ecef;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.attachment-name {
    font-size: 12px;
    color: #495057;
    flex: 1;
    word-break: break-all;
    line-height: 1.3;
}

.attachment-remove {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
    font-size: 16px;
    font-weight: bold;
    flex-shrink: 0;
    line-height: 1em !important;
    padding-bottom: 2px !important;
}

.attachment-remove:hover {
    transform: scale(1.1);
}

/* Rating Modal */
.chat-rating-modal {
    text-align: center;
}

.chat-rating-stars {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin: 20px 0;
}

.chat-rating-star {
    font-size: 32px;
    color: #ddd;
    cursor: pointer;
    transition: color 0.2s;
}

.chat-rating-star:hover,
.chat-rating-star.active {
    color: #ffc107;
}

.chat-rating-comment {
    width: 100%;
    padding: 12px;
    border: 1px solid #e9ecef;
    border-radius: 8px;
    font-size: 14px;
    resize: vertical;
    min-height: 80px;
    margin-bottom: 16px;
}

#chatWidgetWindow h3 { color: #fff; }
#chatConfirmModal h3 { color: #333; }
#chatRatingModal h3 { color: #333; }

/* Login user section */
.chat-login-user-section {
    padding: 12px;
    background: #f8f9fa;
    border-radius: 8px;
    margin-bottom: 12px;
}

.chat-users-container {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Animacija za rating error */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
    20%, 40%, 60%, 80% { transform: translateX(5px); }
}

.rating-error-message {
    color: #dc3545;
    font-size: 14px;
    margin-top: 10px;
    text-align: center;
    animation: shake 0.5s;
    font-weight: 500;
}

/* Highlight rating stars kada treba odabrati ocjenu */
.rating-stars.highlight {
    border: 2px solid #dc3545;
    border-radius: 8px;
    padding: 5px;
    animation: pulse 1s ease-in-out;
}

/* Indikator za editovane poruke */
.chat-message-edited {
    font-size: 10px;
    opacity: 0.7;
    font-style: italic;
    margin-left: 8px;
}

/* Animacija za editovane poruke */
.edit-animation {
    animation: editPulse 0.5s ease-in-out;
}

@keyframes editPulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.02); }
    100% { transform: scale(1); }
}