/* ============================================
   KODA Software - Chat Widget Styles
   Matches the editorial / brutalist theme of softkoda
   Light bg (#F5F2EC), dark ink (#0A0A0A), acid accent (#C8FF00)
   ============================================ */

/* === Variables === */
.chat-bubble,
.chat-panel,
.chat-peek {
    --chat-accent: #0A0A0A;
    --chat-accent-hover: #222;
    --chat-accent-text: #C8FF00;
    --chat-bg: #F5F2EC;
    --chat-bg-card: #fff;
    --chat-bg-secondary: #EDE9E1;
    --chat-bg-tertiary: #E8E4DC;
    --chat-text: #0A0A0A;
    --chat-text-muted: #8A8880;
    --chat-border: rgba(10,10,10,0.12);
    --chat-danger: #ef4444;
    --chat-info: #3b82f6;
    --chat-acid: #C8FF00;
    --chat-radius-sm: 0px;
    --chat-radius-md: 0px;
    --chat-radius-lg: 0px;
    --chat-radius-full: 0px;
    --chat-font: 'Epilogue', system-ui, -apple-system, sans-serif;
    --chat-shadow-xl: 0 20px 60px rgba(10,10,10,0.18), 0 0 0 1px rgba(10,10,10,0.08);
    --chat-transition: 0.2s ease;
    --chat-transition-fast: 0.15s ease;
}

/* === Burbuja flotante === */
.chat-bubble {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 52px;
    height: 52px;
    border-radius: 0;
    background: var(--chat-accent);
    color: var(--chat-accent-text);
    border: 1px solid var(--chat-accent);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 4px 4px 0 rgba(10,10,10,0.15);
    z-index: 9998;
    transition: transform var(--chat-transition-fast), box-shadow var(--chat-transition-fast), background var(--chat-transition-fast);
    animation: none;
    font-family: var(--chat-font);
}

.chat-bubble:hover {
    transform: translate(-2px, -2px);
    box-shadow: 6px 6px 0 rgba(10,10,10,0.2);
    background: var(--chat-accent-hover);
}

.chat-bubble.open {
    background: var(--chat-acid);
    color: var(--chat-accent);
    border-color: var(--chat-accent);
}

.chat-bubble svg {
    width: 26px;
    height: 26px;
    transition: transform var(--chat-transition);
}

.chat-bubble.open svg {
    transform: rotate(90deg);
}

/* Badge */
.chat-bubble-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 20px;
    height: 20px;
    border-radius: 0;
    background: var(--chat-acid);
    color: var(--chat-accent);
    font-size: 10px;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    border: 1px solid var(--chat-accent);
    font-family: var(--chat-font);
    letter-spacing: 0.02em;
}

.chat-bubble-badge.visible {
    display: flex;
}

/* === Peek message === */
.chat-peek {
    position: fixed;
    bottom: 92px;
    right: 24px;
    background: var(--chat-bg-card);
    color: var(--chat-text);
    border: 1px solid var(--chat-accent);
    border-radius: 0;
    padding: 0;
    box-shadow: 4px 4px 0 rgba(10,10,10,0.1);
    z-index: 9997;
    cursor: pointer;
    max-width: 300px;
    min-width: 200px;
    opacity: 0;
    transform: translateY(10px);
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    overflow: hidden;
    font-family: var(--chat-font);
}

.chat-peek.visible {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

.chat-peek::after {
    content: '';
    position: absolute;
    bottom: -7px;
    right: 20px;
    width: 12px;
    height: 12px;
    background: var(--chat-bg-card);
    border-right: 1px solid var(--chat-accent);
    border-bottom: 1px solid var(--chat-accent);
    transform: rotate(45deg);
}

.chat-peek-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 14px 20px;
}

.chat-peek-typing .chat-typing-dot {
    width: 7px;
    height: 7px;
}

.chat-peek-content {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
}

.chat-peek-avatar {
    flex-shrink: 0;
    margin-top: 2px;
}

.chat-peek-avatar .chat-online-dot {
    width: 9px;
    height: 9px;
}

.chat-peek-text {
    font-size: 12px;
    font-weight: 400;
    line-height: 1.5;
    flex: 1;
    letter-spacing: 0.01em;
}

.chat-peek-close {
    background: none;
    border: none;
    color: var(--chat-text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.15s;
}

.chat-peek-close:hover {
    color: var(--chat-text);
}

/* === Quick reply chips === */
.chat-quick-replies {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 6px 0;
    animation: chatMsgIn 0.25s ease;
}

.chat-quick-reply-btn {
    background: transparent;
    border: 1px solid var(--chat-accent);
    color: var(--chat-text);
    border-radius: 0;
    padding: 5px 12px;
    font-size: 11px;
    font-family: var(--chat-font);
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.chat-quick-reply-btn:hover {
    background: var(--chat-accent);
    color: var(--chat-acid);
}

/* === Animations === */
@keyframes chatNudge {
    0%, 100% { transform: rotate(0deg); }
    15%      { transform: rotate(-8deg); }
    30%      { transform: rotate(6deg); }
    45%      { transform: rotate(-4deg); }
    60%      { transform: rotate(2deg); }
}

.chat-nudge {
    animation: chatNudge 0.5s ease-in-out !important;
}

.chat-bubble-glow {
    animation: chatBubbleGlow 2s ease-in-out infinite;
}

@keyframes chatBubbleGlow {
    0%, 100% {
        box-shadow: 4px 4px 0 rgba(10,10,10,0.15);
    }
    50% {
        box-shadow: 4px 4px 0 rgba(10,10,10,0.15), 0 0 0 4px rgba(200,255,0,0.4);
    }
}

/* === Panel === */
.chat-panel {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 380px;
    height: 520px;
    max-height: calc(100vh - 120px);
    background: var(--chat-bg-card);
    border: 1px solid var(--chat-accent);
    border-radius: 0;
    box-shadow: var(--chat-shadow-xl);
    z-index: 9999;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(16px);
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    font-family: var(--chat-font);
}

.chat-panel.open {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto;
}

/* Header */
.chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    background: var(--chat-accent);
    color: var(--chat-accent-text);
    flex-shrink: 0;
    border-bottom: 1px solid var(--chat-accent);
}

.chat-header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 0;
    background: rgba(200,255,0,0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 1px solid rgba(200,255,0,0.3);
}

.chat-header-avatar svg {
    width: 18px;
    height: 18px;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-title {
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

.chat-header-status {
    font-size: 10px;
    opacity: 0.7;
    display: flex;
    align-items: center;
    gap: 5px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.chat-header-status .chat-online-dot {
    width: 6px;
    height: 6px;
    background: var(--chat-acid);
    border-radius: 50%;
}

.chat-close-btn {
    background: none;
    border: none;
    color: var(--chat-accent-text);
    cursor: pointer;
    padding: 4px;
    opacity: 0.7;
    transition: opacity var(--chat-transition-fast);
    flex-shrink: 0;
}

.chat-close-btn:hover {
    opacity: 1;
}

/* Messages area */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
    background: var(--chat-bg);
}

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

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(10,10,10,0.15);
    border-radius: 2px;
}

/* Message bubbles */
.chat-msg {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 0;
    font-size: 13px;
    line-height: 1.55;
    word-wrap: break-word;
    animation: chatMsgIn 0.2s ease;
}

@keyframes chatMsgIn {
    from {
        opacity: 0;
        transform: translateY(6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-msg-bot {
    align-self: flex-start;
    background: var(--chat-bg-secondary);
    color: var(--chat-text);
    border: 1px solid var(--chat-border);
}

.chat-msg-visitante {
    align-self: flex-end;
    background: var(--chat-accent);
    color: var(--chat-accent-text);
    border: 1px solid var(--chat-accent);
}

.chat-msg-admin {
    align-self: flex-start;
    background: var(--chat-info);
    color: #fff;
}

.chat-msg-time {
    font-size: 9px;
    opacity: 0.5;
    margin-top: 3px;
    display: block;
    letter-spacing: 0.03em;
}

.chat-msg-visitante .chat-msg-time {
    text-align: right;
}

/* System message */
.chat-system-msg {
    align-self: center;
    font-size: 10px;
    color: var(--chat-text-muted);
    background: var(--chat-bg-secondary);
    border: 1px solid var(--chat-border);
    padding: 3px 12px;
    border-radius: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    animation: chatMsgIn 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-weight: 500;
}

.chat-online-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #1DB954;
    display: inline-block;
    flex-shrink: 0;
    animation: chatOnlinePulse 2.5s ease-in-out infinite;
}

@keyframes chatOnlinePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Typing indicator */
.chat-typing {
    align-self: flex-start;
    padding: 8px 14px;
    background: var(--chat-bg-secondary);
    border: 1px solid var(--chat-border);
    border-radius: 0;
    display: none;
    gap: 5px;
    align-items: center;
}

.chat-typing.visible {
    display: flex;
}

.chat-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--chat-text-muted);
    animation: chatTypingBounce 1.4s ease-in-out infinite;
}

.chat-typing-dot:nth-child(2) {
    animation-delay: 0.2s;
}

.chat-typing-dot:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes chatTypingBounce {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.3;
    }
    30% {
        transform: translateY(-5px);
        opacity: 1;
    }
}

/* Input area */
.chat-input-area {
    display: flex;
    gap: 0;
    padding: 0;
    border-top: 1px solid var(--chat-accent);
    background: var(--chat-bg-card);
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    border: none;
    border-radius: 0;
    padding: 10px 14px;
    font-family: var(--chat-font);
    font-size: 13px;
    background: var(--chat-bg-card);
    color: var(--chat-text);
    outline: none;
    resize: none;
    min-height: 40px;
    max-height: 80px;
    line-height: 1.4;
    border-right: 1px solid var(--chat-border);
}

.chat-input:focus {
    background: var(--chat-bg);
}

.chat-input::placeholder {
    color: var(--chat-text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.chat-send-btn {
    width: 44px;
    min-height: 40px;
    border-radius: 0;
    border: none;
    background: var(--chat-accent);
    color: var(--chat-accent-text);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background var(--chat-transition-fast);
}

.chat-send-btn:hover {
    background: var(--chat-accent-hover);
}

.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.chat-send-btn svg {
    width: 18px;
    height: 18px;
}

/* Footer */
.chat-footer {
    text-align: center;
    padding: 4px;
    font-size: 9px;
    color: var(--chat-text-muted);
    background: var(--chat-bg-card);
    border-top: 1px solid var(--chat-border);
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

/* === Responsive === */
@media (max-width: 480px) {
    .chat-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        max-height: 100dvh;
        border-radius: 0;
        border: none;
    }

    .chat-panel.open {
        display: flex;
        flex-direction: column;
    }

    .chat-header {
        flex-shrink: 0;
    }

    .chat-messages {
        flex: 1;
        min-height: 0;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }

    .chat-input-area {
        flex-shrink: 0;
        position: sticky;
        bottom: 0;
        z-index: 10;
        padding: 6px 8px;
        gap: 6px;
        background: var(--chat-bg-card);
        border-top: 1px solid var(--chat-accent);
    }

    .chat-input {
        flex: 1;
        min-width: 0;
        min-height: 36px;
        max-height: 60px;
        font-size: 16px; /* prevents iOS zoom on focus */
        padding: 8px 10px;
        border-right: none;
    }

    .chat-send-btn {
        width: 42px;
        height: 36px;
        flex-shrink: 0;
    }

    .chat-footer {
        flex-shrink: 0;
    }

    .chat-bubble {
        bottom: 16px;
        right: 16px;
        width: 48px;
        height: 48px;
    }

    .chat-bubble svg {
        width: 22px;
        height: 22px;
    }

    .chat-peek {
        right: 12px;
        bottom: 76px;
        max-width: calc(100vw - 24px);
    }
    .chat-peek::after {
        right: 16px;
    }
    .chat-quick-reply-btn {
        font-size: 10px;
        padding: 4px 10px;
    }

    .chat-msg {
        max-width: 90%;
    }

    .chat-quick-replies {
        padding: 4px 0;
    }
}

/* Keyboard open fix — visualViewport resize */
@supports (height: 100dvh) {
    @media (max-width: 480px) {
        .chat-panel {
            height: 100dvh;
            max-height: 100dvh;
        }
    }
}
