/* ============================================
   CHERY CHAT WIDGET - STYLES v1.3
   ============================================ */

/* CSS varijable */
:root {
    --chery-primary: #c8102e;
    --chery-primary-dark: #a00d24;
    --chery-primary-light: #e02a45;
    --chery-white: #ffffff;
    --chery-bg: #f8f9fa;
    --chery-text: #212529;
    --chery-text-muted: #6c757d;
    --chery-border: #dee2e6;
    --chery-shadow: 0 5px 25px rgba(0, 0, 0, 0.15);
    --chery-shadow-lg: 0 10px 40px rgba(196, 30, 58, 0.25);
}

/* ============================================
   ADMIN BADGE
   ============================================ */
.chery-admin-badge-floating {
    position: fixed !important;
    top: 90px !important;
    right: 20px !important;
    background: linear-gradient(135deg, #ffc107, #ff9800) !important;
    color: #000 !important;
    padding: 8px 16px !important;
    border-radius: 20px !important;
    font-size: 12px !important;
    font-weight: 700 !important;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2) !important;
    z-index: 999998 !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif !important;
    animation: chery-pulse 2s infinite !important;
}

@keyframes chery-pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* ============================================
   CONTAINER - SVE SA !important da preglasi sajt CSS
   ============================================ */
#chery-chat-container {
    position: fixed !important;
    bottom: 20px !important;
    z-index: 999999 !important;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif !important;
    font-size: 14px !important;
    line-height: 1.5 !important;
    box-sizing: border-box !important;
}

#chery-chat-container *, 
#chery-chat-container *::before, 
#chery-chat-container *::after {
    box-sizing: border-box !important;
}

#chery-chat-container.chery-chat-right {
    right: 20px !important;
}

#chery-chat-container.chery-chat-left {
    left: 20px !important;
}

/* ============================================
   PLIVAJUCE DUGME
   ============================================ */
.chery-chat-toggle {
    width: 60px !important;
    height: 60px !important;
    border-radius: 50% !important;
    background: var(--chery-primary) !important;
    color: var(--chery-white) !important;
    border: none !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    box-shadow: var(--chery-shadow-lg) !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    position: relative !important;
    overflow: hidden !important;
    padding: 0 !important;
    margin: 0 !important;
    outline: none !important;
}

.chery-chat-toggle:hover {
    background: var(--chery-primary-dark) !important;
    transform: scale(1.1) !important;
}

/* SVG ikonice u dugmetu */
.chery-chat-toggle svg {
    width: 28px !important;
    height: 28px !important;
    transition: opacity 0.25s ease, transform 0.25s ease !important;
    color: var(--chery-white) !important;
    display: block !important;
}

.chery-chat-toggle .chery-icon-chat {
    fill: currentColor !important;
    stroke: none !important;
}

.chery-chat-toggle .chery-icon-chat path {
    fill: currentColor !important;
    stroke: none !important;
}

.chery-chat-toggle .chery-icon-close {
    fill: none !important;
    stroke: currentColor !important;
}

.chery-chat-toggle .chery-icon-close path {
    fill: none !important;
    stroke: var(--chery-white) !important;
}

.chery-icon-close {
    position: absolute !important;
    opacity: 0 !important;
    transform: rotate(-90deg) !important;
}

#chery-chat-container.is-open .chery-icon-chat {
    opacity: 0 !important;
    transform: rotate(90deg) !important;
}

#chery-chat-container.is-open .chery-icon-close {
    opacity: 1 !important;
    transform: rotate(0) !important;
}

.chery-chat-toggle.has-new-message::after {
    content: '' !important;
    position: absolute !important;
    top: 5px !important;
    right: 5px !important;
    width: 12px !important;
    height: 12px !important;
    background: #ff4757 !important;
    border: 2px solid var(--chery-white) !important;
    border-radius: 50% !important;
    animation: chery-bounce 1s infinite !important;
}

@keyframes chery-bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-5px); }
}

/* ============================================
   CHAT PROZOR
   ============================================ */
.chery-chat-window {
    position: absolute !important;
    bottom: 80px !important;
    width: 400px !important;
    max-width: calc(100vw - 40px) !important;
    height: 600px !important;
    max-height: calc(100vh - 120px) !important;
    background: var(--chery-white) !important;
    border-radius: 16px !important;
    box-shadow: var(--chery-shadow) !important;
    display: flex !important;
    flex-direction: column !important;
    opacity: 0 !important;
    transform: translateY(20px) scale(0.95) !important;
    pointer-events: none !important;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1) !important;
    overflow: hidden !important;
    margin: 0 !important;
    padding: 0 !important;
}

#chery-chat-container.chery-chat-right .chery-chat-window {
    right: 0 !important;
}

#chery-chat-container.chery-chat-left .chery-chat-window {
    left: 0 !important;
}

#chery-chat-container.is-open .chery-chat-window {
    opacity: 1 !important;
    transform: translateY(0) scale(1) !important;
    pointer-events: auto !important;
}

/* ============================================
   HEADER
   ============================================ */
.chery-chat-header {
    background: linear-gradient(135deg, var(--chery-primary) 0%, var(--chery-primary-dark) 100%) !important;
    color: var(--chery-white) !important;
    padding: 16px 20px !important;
    display: flex !important;
    justify-content: space-between !important;
    align-items: center !important;
    flex-shrink: 0 !important;
}

.chery-chat-header-info {
    display: flex !important;
    align-items: center !important;
    gap: 12px !important;
    min-width: 0 !important;
}

.chery-chat-avatar {
    width: 40px !important;
    height: 40px !important;
    border-radius: 50% !important;
    background: rgba(255, 255, 255, 0.2) !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    color: var(--chery-white) !important;
    flex-shrink: 0 !important;
}

.chery-chat-avatar svg {
    width: 22px !important;
    height: 22px !important;
    color: var(--chery-white) !important;
    fill: none !important;
    stroke: currentColor !important;
}

.chery-chat-avatar svg path,
.chery-chat-avatar svg circle {
    stroke: var(--chery-white) !important;
}

.chery-chat-avatar svg circle {
    fill: var(--chery-white) !important;
}

.chery-chat-title {
    font-weight: 600 !important;
    font-size: 15px !important;
    line-height: 1.2 !important;
    color: var(--chery-white) !important;
    margin: 0 !important;
}

.chery-chat-status {
    font-size: 12px !important;
    opacity: 0.9 !important;
    display: flex !important;
    align-items: center !important;
    gap: 6px !important;
    margin-top: 2px !important;
    color: var(--chery-white) !important;
}

.chery-status-dot {
    width: 8px !important;
    height: 8px !important;
    background: #4caf50 !important;
    border-radius: 50% !important;
    box-shadow: 0 0 10px #4caf50 !important;
    animation: chery-pulse-dot 2s infinite !important;
}

@keyframes chery-pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* MINIMIZE / X DUGME - VAZNO ZA X DA SE VIDI */
.chery-chat-minimize {
    background: rgba(255, 255, 255, 0.15) !important;
    border: none !important;
    color: var(--chery-white) !important;
    width: 32px !important;
    height: 32px !important;
    border-radius: 50% !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: background 0.2s !important;
    flex-shrink: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    outline: none !important;
}

.chery-chat-minimize:hover {
    background: rgba(255, 255, 255, 0.25) !important;
}

.chery-chat-minimize svg {
    width: 18px !important;
    height: 18px !important;
    color: var(--chery-white) !important;
    fill: none !important;
    stroke: currentColor !important;
    display: block !important;
}

.chery-chat-minimize svg path {
    stroke: var(--chery-white) !important;
}

/* ============================================
   PORUKE
   ============================================ */
.chery-chat-messages {
    flex: 1 !important;
    overflow-y: auto !important;
    padding: 20px !important;
    background: var(--chery-bg) !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 12px !important;
    min-height: 0 !important;
}

.chery-chat-messages::-webkit-scrollbar {
    width: 6px;
}

.chery-chat-messages::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}

.chery-message {
    max-width: 85% !important;
    padding: 12px 16px !important;
    border-radius: 18px !important;
    word-wrap: break-word !important;
    animation: chery-slide-in 0.3s ease-out !important;
    line-height: 1.5 !important;
    font-size: 14px !important;
}

@keyframes chery-slide-in {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.chery-message-bot {
    background: var(--chery-white) !important;
    color: var(--chery-text) !important;
    align-self: flex-start !important;
    border-bottom-left-radius: 4px !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05) !important;
}

.chery-message-user {
    background: var(--chery-primary) !important;
    color: var(--chery-white) !important;
    align-self: flex-end !important;
    border-bottom-right-radius: 4px !important;
}

.chery-message-bot strong {
    color: var(--chery-primary) !important;
    font-weight: 700 !important;
}

.chery-message-bot a {
    color: var(--chery-primary) !important;
    text-decoration: underline !important;
    word-break: break-word !important;
}

.chery-message-bot a:hover {
    color: var(--chery-primary-dark) !important;
}

.chery-message-bot ul, 
.chery-message-bot ol {
    margin: 8px 0 !important;
    padding-left: 20px !important;
}

.chery-message-bot li {
    margin: 4px 0 !important;
}

/* Typing dots */
.chery-typing-indicator {
    display: inline-flex !important;
    align-items: center !important;
    gap: 4px !important;
    padding: 14px 18px !important;
    background: var(--chery-white) !important;
    border-radius: 18px !important;
    border-bottom-left-radius: 4px !important;
    align-self: flex-start !important;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05) !important;
}

.chery-typing-dot {
    width: 8px !important;
    height: 8px !important;
    background: var(--chery-text-muted) !important;
    border-radius: 50% !important;
    animation: chery-typing 1.4s infinite !important;
}

.chery-typing-dot:nth-child(2) { animation-delay: 0.2s !important; }
.chery-typing-dot:nth-child(3) { animation-delay: 0.4s !important; }

@keyframes chery-typing {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-8px); opacity: 1; }
}

/* ============================================
   QUICK REPLIES
   ============================================ */
.chery-chat-quick-replies {
    padding: 10px 16px !important;
    background: var(--chery-white) !important;
    border-top: 1px solid var(--chery-border) !important;
    display: flex !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
    flex-shrink: 0 !important;
}

.chery-chat-quick-replies.is-hidden {
    display: none !important;
}

.chery-quick-reply {
    background: var(--chery-bg) !important;
    border: 1px solid var(--chery-border) !important;
    color: var(--chery-text) !important;
    padding: 6px 12px !important;
    border-radius: 16px !important;
    cursor: pointer !important;
    font-size: 12px !important;
    font-weight: 500 !important;
    transition: all 0.2s !important;
    white-space: nowrap !important;
    font-family: inherit !important;
    margin: 0 !important;
    outline: none !important;
}

.chery-quick-reply:hover {
    background: var(--chery-primary) !important;
    color: var(--chery-white) !important;
    border-color: var(--chery-primary) !important;
}

/* ============================================
   INPUT - SEND DUGME (VAZNO!)
   ============================================ */
.chery-chat-input-container {
    display: flex !important;
    gap: 8px !important;
    padding: 14px 16px !important;
    background: var(--chery-white) !important;
    border-top: 1px solid var(--chery-border) !important;
    flex-shrink: 0 !important;
    align-items: center !important;
}

.chery-chat-input {
    flex: 1 !important;
    padding: 10px 16px !important;
    border: 2px solid var(--chery-border) !important;
    border-radius: 24px !important;
    font-size: 14px !important;
    font-family: inherit !important;
    outline: none !important;
    transition: border-color 0.2s !important;
    background: var(--chery-bg) !important;
    color: var(--chery-text) !important;
    min-width: 0 !important;
    margin: 0 !important;
}

.chery-chat-input:focus {
    border-color: var(--chery-primary) !important;
    background: var(--chery-white) !important;
}

/* SEND DUGME - SVG MORA DA SE VIDI */
.chery-chat-send {
    background: var(--chery-primary) !important;
    color: var(--chery-white) !important;
    border: none !important;
    width: 44px !important;
    height: 44px !important;
    border-radius: 50% !important;
    cursor: pointer !important;
    display: flex !important;
    align-items: center !important;
    justify-content: center !important;
    transition: all 0.2s !important;
    flex-shrink: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    outline: none !important;
}

.chery-chat-send:hover:not(:disabled) {
    background: var(--chery-primary-dark) !important;
    transform: scale(1.05) !important;
}

.chery-chat-send:disabled {
    opacity: 0.5 !important;
    cursor: not-allowed !important;
}

.chery-chat-send svg {
    width: 18px !important;
    height: 18px !important;
    color: var(--chery-white) !important;
    fill: none !important;
    stroke: currentColor !important;
    display: block !important;
}

.chery-chat-send svg path {
    stroke: var(--chery-white) !important;
}

/* ============================================
   FOOTER
   ============================================ */
.chery-chat-footer {
    padding: 6px 16px !important;
    background: var(--chery-bg) !important;
    text-align: center !important;
    font-size: 10px !important;
    color: var(--chery-text-muted) !important;
    border-top: 1px solid var(--chery-border) !important;
    flex-shrink: 0 !important;
}

/* ============================================
   RESPONSIVE
   ============================================ */
/* ============================================
   MOBILNI PRIKAZ - full screen sheet
   ============================================ */
@media (max-width: 600px) {

    /* Chat prozor postaje full-screen panel */
    .chery-chat-window {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        max-width: 100% !important;
        height: 100% !important;
        height: 100dvh !important;   /* ne racuna URL traku browsera */
        max-height: none !important;
        border-radius: 0 !important;
        opacity: 1 !important;
        transform: translateY(100%) !important;
        transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1) !important;
    }

    #chery-chat-container.chery-chat-right .chery-chat-window,
    #chery-chat-container.chery-chat-left .chery-chat-window {
        left: 0 !important;
        right: 0 !important;
    }

    #chery-chat-container.is-open .chery-chat-window {
        transform: translateY(0) !important;
        opacity: 1 !important;
        pointer-events: auto !important;
    }

    /* Plivajuce dugme - safe area za iPhone home indicator */
    #chery-chat-container {
        bottom: 16px !important;
        bottom: calc(16px + env(safe-area-inset-bottom)) !important;
    }

    #chery-chat-container.chery-chat-right {
        right: 16px !important;
    }

    #chery-chat-container.chery-chat-left {
        left: 16px !important;
    }

    .chery-chat-toggle {
        width: 58px !important;
        height: 58px !important;
        -webkit-tap-highlight-color: transparent !important;
    }

    /* Kad je chat otvoren, sakrij plivajuce dugme (imamo X u headeru) */
    #chery-chat-container.is-open .chery-chat-toggle {
        opacity: 0 !important;
        pointer-events: none !important;
    }

    /* Header - prostor za notch */
    .chery-chat-header {
        padding: 14px 16px !important;
        padding-top: calc(14px + env(safe-area-inset-top)) !important;
    }

    .chery-chat-title {
        font-size: 16px !important;
    }

    /* Veci X, lakse se pogadja prstom */
    .chery-chat-minimize {
        width: 40px !important;
        height: 40px !important;
        -webkit-tap-highlight-color: transparent !important;
    }

    .chery-chat-minimize svg {
        width: 22px !important;
        height: 22px !important;
    }

    /* Poruke - citljivije, bez scroll chaining-a na body */
    .chery-chat-messages {
        padding: 16px 14px !important;
        gap: 10px !important;
        overscroll-behavior: contain !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .chery-message {
        max-width: 88% !important;
        font-size: 15px !important;
        padding: 11px 15px !important;
    }

    /* Quick replies - jedan red koji se skroluje horizontalno */
    .chery-chat-quick-replies {
        flex-wrap: nowrap !important;
        overflow-x: auto !important;
        overscroll-behavior-x: contain !important;
        -webkit-overflow-scrolling: touch !important;
        scrollbar-width: none !important;
        padding: 10px 14px !important;
        gap: 8px !important;
    }

    .chery-chat-quick-replies::-webkit-scrollbar {
        display: none !important;
    }

    .chery-quick-reply {
        flex: 0 0 auto !important;
        font-size: 13px !important;
        padding: 9px 15px !important;
        -webkit-tap-highlight-color: transparent !important;
    }

    /* Input - 16px OBAVEZNO, inace iOS Safari zumira stranicu na fokus */
    .chery-chat-input-container {
        padding: 12px 14px !important;
        padding-bottom: calc(12px + env(safe-area-inset-bottom)) !important;
        gap: 10px !important;
    }

    .chery-chat-input {
        font-size: 16px !important;
        padding: 12px 16px !important;
    }

    .chery-chat-send {
        width: 46px !important;
        height: 46px !important;
        -webkit-tap-highlight-color: transparent !important;
    }

    .chery-chat-send svg {
        width: 20px !important;
        height: 20px !important;
    }

    /* Footer zauzima previse prostora na malom ekranu */
    .chery-chat-footer {
        display: none !important;
    }

    .chery-admin-badge-floating {
        top: 70px !important;
        right: 10px !important;
        font-size: 10px !important;
        padding: 6px 12px !important;
    }
}

/* Telefon u landscape rezimu - header nizi da ostane mesta za poruke */
@media (max-width: 900px) and (max-height: 480px) and (orientation: landscape) {
    .chery-chat-header {
        padding: 8px 16px !important;
    }

    .chery-chat-avatar {
        width: 32px !important;
        height: 32px !important;
    }

    .chery-chat-quick-replies {
        display: none !important;
    }
}

/* Kad je chat otvoren na mobilnom - zakljucaj pozadinu */
body.chery-chat-locked {
    position: fixed !important;
    width: 100% !important;
    overflow: hidden !important;
}

/* chat rich content */
.chery-message-bot {
    max-width: min(92%, 420px) !important;
}
.chery-message-bot .chat-p {
    margin: 0 0 8px !important;
    line-height: 1.45 !important;
}
.chery-message-bot .chat-p:last-child {
    margin-bottom: 0 !important;
}
.chery-message-bot .chat-hr {
    border: 0 !important;
    border-top: 1px solid rgba(0,0,0,.12) !important;
    margin: 10px 0 !important;
}
.chery-message-bot .chat-list {
    margin: 6px 0 10px !important;
    padding-left: 18px !important;
    list-style: disc !important;
}
.chery-message-bot .chat-list li {
    margin: 4px 0 !important;
    line-height: 1.45 !important;
}
.chery-message-bot del {
    opacity: .65 !important;
    text-decoration: line-through !important;
}
.chery-message-bot .chat-table-wrap {
    width: 100% !important;
    overflow-x: auto !important;
    margin: 8px 0 10px !important;
    -webkit-overflow-scrolling: touch !important;
}
.chery-message-bot .chat-table {
    width: 100% !important;
    border-collapse: collapse !important;
    font-size: 12px !important;
    min-width: 280px !important;
}
.chery-message-bot .chat-table th,
.chery-message-bot .chat-table td {
    border: 1px solid rgba(0,0,0,.1) !important;
    padding: 6px 8px !important;
    text-align: left !important;
    vertical-align: top !important;
    white-space: nowrap !important;
}
.chery-message-bot .chat-table th {
    background: rgba(0,0,0,.04) !important;
    font-weight: 700 !important;
}
.chery-message-bot .chat-table td:nth-child(n+3) {
    white-space: nowrap !important;
}
