/* =============================================================
   Codicts Chat Widget - Frontend Styles v1.0.0
   ============================================================= */

/* --- 1. Container ------------------------------------------ */
.codicts-cw {
    position: fixed;
    z-index: 999999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    box-sizing: border-box;
}
.codicts-cw *, .codicts-cw *::before, .codicts-cw *::after { box-sizing: inherit; }

/* --- 2. Positioning ---------------------------------------- */
.codicts-cw--bottom-right { bottom: 24px; right: 24px; }
.codicts-cw--bottom-left  { bottom: 24px; left: 24px; align-items: flex-start; }

/* --- 3. Bubble button -------------------------------------- */
.codicts-cw__bubble {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--ccw-bubble, #ff6b35);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.22);
    animation: ccw-bubble-in 0.45s cubic-bezier(0.34, 1.56, 0.64, 1) both;
    transition: transform 0.2s ease, box-shadow 0.2s ease, background 0.28s ease, width 0.28s ease, height 0.28s ease;
    position: relative;
    flex-shrink: 0;
    order: 2;
}
.codicts-cw--bottom-left .codicts-cw__bubble { order: 1; }
.codicts-cw__bubble:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(0,0,0,.28); }
.codicts-cw__bubble:focus-visible { outline: 3px solid var(--ccw-primary, #ff6b35); outline-offset: 3px; }

.codicts-cw__bubble-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    opacity: 1;
    z-index: 1;
    transition: opacity 0.28s ease;
    pointer-events: none;
}
.codicts-cw__bubble-close {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #fff;
    stroke: #fff !important;
    opacity: 0;
    z-index: 2;
    transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
}
.codicts-cw--open .codicts-cw__bubble-icon {
    opacity: 0 !important;
}
.codicts-cw--open .codicts-cw__bubble-close {
    opacity: 1 !important;
    transform: translate(-50%, -50%) scale(1.35);
}
.codicts-cw__bubble:hover .codicts-cw__bubble-close {
    transform: translate(-50%, -50%) scale(1.5);
}

@keyframes ccw-bubble-in {
    from { opacity: 0; transform: scale(0.3) rotate(-20deg); }
    to   { opacity: 1; transform: scale(1) rotate(0deg); }
}

.codicts-cw__bubble--attention { animation: ccw-pulse 2.2s ease infinite; }
@keyframes ccw-pulse {
    0%, 100% { box-shadow: 0 4px 20px rgba(0,0,0,.22); }
    50%       { box-shadow: 0 4px 32px rgba(0,0,0,.3), 0 0 0 10px rgba(255,107,53,.18); }
}

/* Icon-only mode - strip the circle background */
.codicts-cw--icon-only .codicts-cw__bubble {
    background: transparent;
    box-shadow: none;
    width: auto;
    height: auto;
    min-width: 44px;
    min-height: 44px;
    padding: 4px;
}
.codicts-cw--icon-only .codicts-cw__bubble:hover { box-shadow: none; transform: scale(1.1); }
.codicts-cw--icon-only .codicts-cw__bubble--attention { animation: ccw-pulse-icon 2.2s ease infinite; }
/* When chat is open in icon-only mode, show the close button with background circle */
.codicts-cw--icon-only.codicts-cw--open .codicts-cw__bubble {
    background: var(--ccw-bubble, #ff6b35);
    width: var(--ccw-close-btn-size, 60px);
    height: var(--ccw-close-btn-size, 60px);
    border-radius: 50%;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.22);
    padding: 0;
    transition: background 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.28s ease, width 0.28s cubic-bezier(0.34, 1.56, 0.64, 1), height 0.28s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.codicts-cw--icon-only.codicts-cw--open .codicts-cw__bubble:hover {
    box-shadow: 0 6px 28px rgba(0,0,0,.28);
    transform: scale(1.08);
}
@keyframes ccw-pulse-icon {
    0%, 100% { filter: drop-shadow(0 0 0 transparent); }
    50%       { filter: drop-shadow(0 0 8px rgba(255,107,53,.5)); }
}
.codicts-cw--icon-only .codicts-cw__bubble-icon { color: var(--ccw-primary, #ff6b35); }
.codicts-cw--icon-only .codicts-cw__bubble-close {
    color: var(--ccw-text, #1f2937);
    stroke: var(--ccw-text, #1f2937) !important;
}

/* --- 4. Chat window --------------------------------------- */
.codicts-cw__window {
    width: var(--ccw-width, 380px);
    max-width: calc(100vw - 48px);
    height: var(--ccw-height, 520px);
    max-height: calc(100vh - 110px);
    background: var(--ccw-bg, #ffffff);
    border-radius: 18px;
    box-shadow: 0 8px 48px rgba(0,0,0,.18), 0 2px 8px rgba(0,0,0,.08);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    opacity: 0;
    transform: translateY(20px) scale(0.96);
    pointer-events: none;
    transition: opacity 0.28s ease, transform 0.28s cubic-bezier(0.34, 1.4, 0.64, 1);
    order: 1;
}
.codicts-cw__window[hidden] { display: flex !important; }
.codicts-cw--bottom-left .codicts-cw__window { order: 2; }
.codicts-cw--open .codicts-cw__window { opacity: 1; transform: translateY(0) scale(1); pointer-events: all; }

/* --- 5. Header -------------------------------------------- */
.codicts-cw__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 12px 13px 16px;
    background: var(--ccw-primary, #ff6b35);
    color: #fff;
    flex-shrink: 0;
    gap: 8px;
}
.codicts-cw__title {
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}
.codicts-cw__header-actions { display: flex; align-items: center; gap: 2px; flex-shrink: 0; }

.codicts-cw__header-btn {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: color 0.15s, background 0.15s;
    line-height: 0;
    flex-shrink: 0;
}
.codicts-cw__header-btn:hover { color: #fff; background: rgba(255,255,255,.15); }
.codicts-cw__header-btn:focus-visible { outline: 2px solid rgba(255,255,255,.7); outline-offset: -2px; }

/* --- 6. Messages area ------------------------------------- */
.codicts-cw__messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
    background: var(--ccw-bg, #ffffff);
    min-height: 0;
}
.codicts-cw__messages::-webkit-scrollbar { width: 4px; }
.codicts-cw__messages::-webkit-scrollbar-track { background: transparent; }
.codicts-cw__messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,.12); border-radius: 4px; }

/* --- 7. Messages ------------------------------------------ */
.codicts-cw__message {
    max-width: 80%;
    padding: 10px 14px;
    border-radius: 18px;
    font-size: 14px;
    line-height: 1.6;
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
    display: block;
    width: fit-content;
    animation: ccw-msg-in 0.22s ease both;
}
.codicts-cw__message--user {
    align-self: flex-end;
    background: var(--ccw-primary, #ff6b35);
    color: #fff;
    border-bottom-right-radius: 5px;
}
.codicts-cw__message--bot {
    align-self: flex-start;
    background: #f1f5f9;
    color: var(--ccw-text, #1f2937);
    border-bottom-left-radius: 5px;
}
.codicts-cw__message--error {
    align-self: flex-start;
    background: #fff1f1;
    color: #b91c1c;
    border-bottom-left-radius: 5px;
    font-size: 13px;
    border: 1px solid #fecaca;
}

@keyframes ccw-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* --- 8. Typing indicator ---------------------------------- */
.codicts-cw__typing {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 5px;
    padding: 12px 16px;
    background: #f1f5f9;
    border-radius: 18px;
    border-bottom-left-radius: 5px;
    align-self: flex-start;
    width: fit-content;
    animation: ccw-msg-in 0.2s ease both;
}
.codicts-cw__typing span {
    display: block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #94a3b8;
    flex-shrink: 0;
    animation: ccw-bounce 1.3s ease infinite;
}
.codicts-cw__typing span:nth-child(2) { animation-delay: 0.15s; }
.codicts-cw__typing span:nth-child(3) { animation-delay: 0.30s; }
@keyframes ccw-bounce {
    0%, 100% { transform: translateY(0); opacity: 0.6; }
    45%       { transform: translateY(-7px); opacity: 1; }
}

/* --- 9. Floating suggestion chips (inside messages div) --- */
/* Rendered as the last element in #codicts-cw-messages so they
   scroll naturally with the conversation and feel integrated. */
.codicts-cw__suggestion-row {
    align-self: stretch;   /* stretch to full width so chips can wrap freely */
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
    padding: 6px 0 2px;
    animation: ccw-msg-in 0.25s ease both;
}
.codicts-cw__suggestion {
    padding: 7px 16px;
    border-radius: 20px;
    border: 1.5px solid rgba(99, 102, 241, 0.35);
    background: transparent;
    color: var(--ccw-primary, #ff6b35);
    font-size: 13px;
    font-family: inherit;
    line-height: 1.4;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.12s ease;
    white-space: normal;
    max-width: 100%;
    word-break: break-word;
    text-align: left;
}
.codicts-cw__suggestion:hover {
    background: var(--ccw-primary, #ff6b35);
    border-color: var(--ccw-primary, #ff6b35);
    color: #fff;
    transform: translateY(-1px);
}
.codicts-cw__suggestion:active { transform: translateY(0); }

/* --- 10. Group selector - rendered as a bot message bubble - */
.codicts-cw__group-prompt {
    display: flex !important;
    flex-direction: column;
    gap: 10px;
    max-width: 90%;
    width: fit-content;
    white-space: normal;
}
.codicts-cw__group-question {
    margin: 0;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.5;
}
.codicts-cw__group-choices {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}
.codicts-cw__group-choice {
    padding: 6px 16px;
    border-radius: 20px;
    border: 1.5px solid var(--ccw-primary, #ff6b35);
    background: transparent;
    color: var(--ccw-primary, #ff6b35);
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: background 0.15s ease, color 0.15s ease, transform 0.1s ease;
    line-height: 1.4;
}
.codicts-cw__group-choice:hover {
    background: var(--ccw-primary, #ff6b35);
    color: #fff;
    transform: translateY(-1px);
}
.codicts-cw__group-choice:active { transform: translateY(0); }
.codicts-cw__group-chosen {
    font-size: 13px;
    font-weight: 600;
    color: var(--ccw-primary, #ff6b35);
}
.codicts-cw__group-chosen::before { content: '✓ '; }

/* --- 11. Footer / input ----------------------------------- */
.codicts-cw__footer {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.07);
    background: var(--ccw-bg, #ffffff);
    flex-shrink: 0;
}
.codicts-cw__input {
    flex: 1;
    min-width: 0;
    padding: 9px 14px;
    border-radius: 20px;
    border: 1.5px solid rgba(0, 0, 0, 0.12);
    background: #f8fafc;
    color: var(--ccw-text, #1f2937);
    font-size: 14px;
    font-family: inherit;
    line-height: 1.5;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    /* Textarea-specific: grows vertically, never stretches horizontally */
    resize: none;
    overflow-y: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
    min-height: 40px;
    max-height: 120px;
    display: block;
    word-break: break-word;
    overflow-wrap: break-word;
    white-space: pre-wrap;
}
.codicts-cw__input:focus { border-color: var(--ccw-primary, #ff6b35); box-shadow: 0 0 0 3px rgba(255,107,53,.1); }
.codicts-cw__input::placeholder { color: #9ca3af; }
.codicts-cw__input::-webkit-scrollbar { display: none; }
.codicts-cw__input:disabled { opacity: 0.6; cursor: not-allowed; }
/* Keep footer vertically centered when textarea grows */
.codicts-cw__footer { align-items: flex-end; }
.codicts-cw__send {
    width: 40px; height: 40px;
    border-radius: 50%;
    background: var(--ccw-primary, #ff6b35);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
    line-height: 0;
}
.codicts-cw__send:hover:not(:disabled) { transform: scale(1.08); box-shadow: 0 3px 10px rgba(255,107,53,.4); }
.codicts-cw__send:focus-visible { outline: 3px solid var(--ccw-primary, #ff6b35); outline-offset: 3px; }
.codicts-cw__send:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* --- 12. Mobile ------------------------------------------- */
@media (max-width: 480px) {
    .codicts-cw--bottom-right,
    .codicts-cw--bottom-left { bottom: 16px; right: 16px; left: 16px; align-items: flex-end; }
    .codicts-cw--bottom-left { align-items: flex-start; }
    .codicts-cw__window { width: calc(100vw - 32px); max-width: 100%; height: 70vh; max-height: 520px; }
}

/* --- 13. Reduced motion ----------------------------------- */
@media (prefers-reduced-motion: reduce) {
    .codicts-cw__bubble, .codicts-cw__bubble-icon, .codicts-cw__bubble-close,
    .codicts-cw__window, .codicts-cw__message, .codicts-cw__typing,
    .codicts-cw__typing span, .codicts-cw__suggestion, .codicts-cw__group-btn,
    .codicts-cw__suggestion-row {
        animation: none !important; transition: none !important;
    }
    .codicts-cw--open .codicts-cw__window { opacity: 1; transform: none; }
}
