/**
 * Cleotalk Chat Widget Styles
 * 
 * Frontend widget with floating bubble, slide-up chat panel,
 * smooth animations, and responsive design.
 */

/* ─────────────────────────────────────────────
   VARIABLES
   ───────────────────────────────────────────── */

#cleotalk-widget-root {
    --ct-w-primary: #6366F1;
    --ct-w-bg: #ffffff;
    --ct-w-text: #0F172A;
    --ct-w-text-muted: #94A3B8;
    --ct-w-border: #E5E7EB;
    --ct-w-radius: 16px;
    --ct-w-shadow: 0 12px 40px rgba(15, 23, 42, 0.12);

    position: fixed;
    z-index: 99999;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* Position variants */
#cleotalk-widget-root[data-position="bottom-right"] { bottom: 24px; right: 24px; }
#cleotalk-widget-root[data-position="bottom-left"] { bottom: 24px; left: 24px; }
#cleotalk-widget-root[data-position="top-right"] { top: 24px; right: 24px; }
#cleotalk-widget-root[data-position="top-left"] { top: 24px; left: 24px; }

/* ─────────────────────────────────────────────
   TRIGGER BUTTON
   ───────────────────────────────────────────── */

.cleotalk-trigger {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--ct-w-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
    transition: transform 250ms ease, box-shadow 250ms ease;
    position: relative;
    overflow: visible;
}

.cleotalk-trigger::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 30% 30%, rgba(255,255,255,0.2), transparent 70%);
    border-radius: 50%;
    pointer-events: none;
}

.cleotalk-trigger:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px rgba(99, 102, 241, 0.5);
}

.cleotalk-trigger:active {
    transform: scale(0.95);
}

.cleotalk-trigger img {
    width: 28px;
    height: 28px;
    object-fit: contain;
    filter: brightness(0) invert(1);
    position: relative;
    z-index: 1;
}

.cleotalk-trigger-close {
    display: none;
}

.cleotalk-trigger.open .cleotalk-trigger-icon {
    display: none;
}

.cleotalk-trigger.open .cleotalk-trigger-close {
    display: block;
    font-size: 24px;
    color: #fff;
    line-height: 1;
    font-weight: 300;
    position: relative;
    z-index: 1;
}

/* Notification dot */
.cleotalk-trigger-dot {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 16px;
    height: 16px;
    background: #EF4444;
    border-radius: 50%;
    border: 3px solid #fff;
    z-index: 10;
    animation: cleotalk-pulse 2s infinite;
    box-shadow: 0 2px 6px rgba(239, 68, 68, 0.4);
}

@keyframes cleotalk-pulse {
    0%, 100% { transform: scale(1); opacity: 1; }
    50% { transform: scale(1.2); opacity: 0.8; }
}

/* ─────────────────────────────────────────────
   CHAT PANEL
   ───────────────────────────────────────────── */

.cleotalk-panel {
    position: absolute;
    width: 380px;
    height: 520px;
    max-height: 80vh;
    background: var(--ct-w-bg);
    border-radius: var(--ct-w-radius);
    box-shadow: var(--ct-w-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
    transition: opacity 250ms ease, transform 250ms ease;
}

/* Position the panel relative to trigger */
#cleotalk-widget-root[data-position="bottom-right"] .cleotalk-panel {
    bottom: 72px;
    right: 0;
    transform: translateY(12px);
    transform-origin: bottom right;
}

#cleotalk-widget-root[data-position="bottom-left"] .cleotalk-panel {
    bottom: 72px;
    left: 0;
    transform: translateY(12px);
    transform-origin: bottom left;
}

#cleotalk-widget-root[data-position="top-right"] .cleotalk-panel {
    top: 72px;
    right: 0;
    transform: translateY(-12px);
    transform-origin: top right;
}

#cleotalk-widget-root[data-position="top-left"] .cleotalk-panel {
    top: 72px;
    left: 0;
    transform: translateY(-12px);
    transform-origin: top left;
}

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

/* ─────────────────────────────────────────────
   HEADER
   ───────────────────────────────────────────── */

.cleotalk-panel-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--ct-w-primary);
    flex-shrink: 0;
}

.cleotalk-panel-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    object-fit: cover;
}

.cleotalk-panel-name {
    color: #ffffff;
    font-size: 15px;
    font-weight: 600;
}

.cleotalk-panel-status {
    color: rgba(255, 255, 255, 0.7);
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.cleotalk-online-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #10B981;
}

/* ─────────────────────────────────────────────
   MESSAGES
   ───────────────────────────────────────────── */

.cleotalk-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

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

.cleotalk-messages::-webkit-scrollbar-track {
    background: transparent;
}

.cleotalk-messages::-webkit-scrollbar-thumb {
    background: #CBD5E1;
    border-radius: 2px;
}

.cleotalk-msg {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: cleotalk-msg-in 300ms ease;
}

@keyframes cleotalk-msg-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.cleotalk-msg-bot {
    align-self: flex-start;
}

.cleotalk-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.cleotalk-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 4px;
}

.cleotalk-msg-bubble {
    padding: 10px 14px;
    font-size: 14px;
    line-height: 1.5;
    word-break: break-word;
}

/* Markdown lists, paragraph and code styles in bubbles */
.cleotalk-msg-bubble ul.cleotalk-ul, 
.cleotalk-msg-bubble ol.cleotalk-ol {
    margin: 4px 0 4px 20px;
    padding: 0;
}

.cleotalk-msg-bubble ul.cleotalk-ul {
    list-style-type: disc;
}

.cleotalk-msg-bubble ol.cleotalk-ol {
    list-style-type: decimal;
}

.cleotalk-msg-bubble li {
    margin: 4px 0;
}

.cleotalk-msg-bubble p.cleotalk-p {
    margin: 0 0 6px 0;
}

.cleotalk-msg-bubble p.cleotalk-p:last-child {
    margin-bottom: 0;
}

.cleotalk-msg-bubble code.cleotalk-code {
    background: rgba(0, 0, 0, 0.05);
    padding: 2px 4px;
    border-radius: 4px;
    font-family: monospace;
    font-size: 13px;
}

.cleotalk-msg-user .cleotalk-msg-bubble code.cleotalk-code {
    background: rgba(255, 255, 255, 0.2);
    color: #ffffff;
}

.cleotalk-msg-bot .cleotalk-msg-bubble {
    background: #F1F5F9;
    color: var(--ct-w-text);
    border-radius: 4px 14px 14px 14px;
}

.cleotalk-msg-user .cleotalk-msg-bubble {
    background: var(--ct-w-primary);
    color: #ffffff;
    border-radius: 14px 4px 14px 14px;
}

.cleotalk-msg-time {
    font-size: 10px;
    color: var(--ct-w-text-muted);
    margin-top: 4px;
    padding: 0 4px;
}

/* Typing indicator */
.cleotalk-typing {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 10px 16px;
    background: #F1F5F9;
    border-radius: 4px 14px 14px 14px;
    width: fit-content;
}

.cleotalk-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94A3B8;
    animation: cleotalk-typing-bounce 1.4s ease-in-out infinite;
}

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

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

@keyframes cleotalk-typing-bounce {
    0%, 60%, 100% {
        transform: translateY(0);
    }
    30% {
        transform: translateY(-5px);
    }
}

/* ─────────────────────────────────────────────
   INPUT AREA
   ───────────────────────────────────────────── */

.cleotalk-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--ct-w-border);
    background: var(--ct-w-bg);
    flex-shrink: 0;
}

.cleotalk-input-field {
    flex: 1;
    border: 1px solid var(--ct-w-border);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    color: var(--ct-w-text);
    background: transparent;
    outline: none;
    transition: border-color 200ms ease;
    resize: none;
    max-height: 80px;
    overflow-y: auto;
}

.cleotalk-input-field:focus {
    border-color: var(--ct-w-primary);
}

.cleotalk-input-field::placeholder {
    color: var(--ct-w-text-muted);
}

.cleotalk-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: none;
    background: var(--ct-w-primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 200ms ease, transform 200ms ease;
    flex-shrink: 0;
}

.cleotalk-send-btn:hover {
    background: #5558e6;
    transform: scale(1.05);
}

.cleotalk-send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

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

/* ─────────────────────────────────────────────
   FOOTER
   ───────────────────────────────────────────── */

.cleotalk-powered-by {
    text-align: center;
    padding: 6px;
    font-size: 10px;
    color: var(--ct-w-text-muted);
    border-top: 1px solid #F1F5F9;
}

.cleotalk-powered-by a {
    color: var(--ct-w-primary);
    text-decoration: none;
    font-weight: 500;
}

/* ─────────────────────────────────────────────
   SATISFACTION RATING
   ───────────────────────────────────────────── */

.cleotalk-rating {
    display: flex;
    justify-content: center;
    gap: 8px;
    padding: 12px;
    animation: cleotalk-msg-in 300ms ease;
}

.cleotalk-rating-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--ct-w-border);
    background: var(--ct-w-bg);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--ct-w-text-muted);
    transition: all 200ms ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cleotalk-rating-btn:hover,
.cleotalk-rating-btn.selected {
    border-color: var(--ct-w-primary);
    background: var(--ct-w-primary);
    color: #ffffff;
}

/* ─────────────────────────────────────────────
   RESPONSIVE
   ───────────────────────────────────────────── */

@media (max-width: 480px) {
    .cleotalk-panel {
        width: calc(100vw - 32px);
        height: calc(100vh - 120px);
        max-height: none;
    }

    #cleotalk-widget-root[data-position="bottom-right"],
    #cleotalk-widget-root[data-position="bottom-left"] {
        left: 16px;
        right: 16px;
    }

    #cleotalk-widget-root[data-position="bottom-right"] .cleotalk-panel,
    #cleotalk-widget-root[data-position="bottom-left"] .cleotalk-panel {
        right: 0;
        left: 0;
    }

    .cleotalk-trigger {
        width: 52px;
        height: 52px;
    }
}

/* ─────────────────────────────────────────────
   PRE-CHAT FORM
   ───────────────────────────────────────────── */

.cleotalk-prechat {
    flex: 1;
    padding: 24px 20px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.cleotalk-prechat-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--ct-w-text);
    margin: 0 0 6px;
}

.cleotalk-prechat-subtitle {
    font-size: 13px;
    color: var(--ct-w-text-muted);
    margin: 0 0 20px;
    line-height: 1.5;
}

.cleotalk-prechat-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex: 1;
}

.cleotalk-prechat-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.cleotalk-prechat-group label {
    font-size: 12px;
    font-weight: 500;
    color: var(--ct-w-text);
}

.cleotalk-prechat-required {
    color: #EF4444;
}

.cleotalk-prechat-input {
    padding: 9px 12px;
    border: 1px solid var(--ct-w-border);
    border-radius: 8px;
    font-size: 14px;
    font-family: inherit;
    color: var(--ct-w-text);
    background: var(--ct-w-bg);
    outline: none;
    transition: border-color 200ms ease, box-shadow 200ms ease;
    resize: none;
}

.cleotalk-prechat-input:focus {
    border-color: var(--ct-w-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.12);
}

.cleotalk-prechat-input::placeholder {
    color: var(--ct-w-text-muted);
}

.cleotalk-prechat-submit {
    width: 100%;
    padding: 11px 20px;
    border: none;
    border-radius: 10px;
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: opacity 200ms ease, transform 200ms ease;
    margin-top: auto;
}

.cleotalk-prechat-submit:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.cleotalk-prechat-submit:active {
    transform: translateY(0);
}
