/* ── Widget container ─────────────────────────────────────────────────────── */
#sc-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 9999;
    font-family: Arial, sans-serif;
    font-size: 14px;
}

/* ── Toggle button ────────────────────────────────────────────────────────── */
.sc-toggle-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    background: #5b8dee;
    color: #fff;
    border: none;
    border-radius: 28px;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(91,141,238,.35);
    font-size: 14px;
    font-family: inherit;
    white-space: nowrap;
    transition: background .2s, box-shadow .2s, transform .1s;
    position: relative;
}

.sc-toggle-btn:hover {
    background: #4a7de0;
    box-shadow: 0 6px 20px rgba(91,141,238,.45);
}

.sc-toggle-btn:active {
    transform: scale(.97);
}

.sc-unread-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #e74c3c;
    color: #fff;
    border-radius: 50%;
    min-width: 18px;
    height: 18px;
    font-size: 11px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
}

/* ── Chat window ──────────────────────────────────────────────────────────── */
.sc-window {
    position: absolute;
    bottom: 54px;
    right: 0;
    width: 340px;
    max-width: calc(100vw - 24px);
    height: 480px;
    max-height: calc(100vh - 100px);
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0,0,0,.15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: sc-slide-up .2s ease;
}

@keyframes sc-slide-up {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── Header ───────────────────────────────────────────────────────────────── */
.sc-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    background: linear-gradient(135deg, #5b8dee 0%, #7ba7f0 100%);
    color: #fff;
    flex-shrink: 0;
}

.sc-header-title {
    font-weight: 600;
    font-size: 15px;
}

.sc-close-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,.8);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 2px 6px;
    border-radius: 4px;
    transition: color .15s, background .15s;
}

.sc-close-btn:hover {
    color: #fff;
    background: rgba(255,255,255,.15);
}

/* ── Messages area ────────────────────────────────────────────────────────── */
.sc-messages {
    flex: 1;
    overflow-y: auto;
    padding: 12px 12px 6px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}

.sc-messages::-webkit-scrollbar { width: 4px; }
.sc-messages::-webkit-scrollbar-thumb { background: #ddd; border-radius: 4px; }

/* ── Message bubbles ──────────────────────────────────────────────────────── */
.sc-msg {
    display: flex;
    flex-direction: column;
}

.sc-msg--user {
    align-items: flex-end;
}

.sc-msg--admin {
    align-items: flex-start;
}

.sc-msg--system {
    align-items: center;
}

.sc-bubble {
    max-width: 85%;
    padding: 8px 12px;
    border-radius: 12px;
    line-height: 1.45;
    word-break: break-word;
}

.sc-msg--user .sc-bubble {
    background: #5b8dee;
    color: #fff;
    border-bottom-right-radius: 4px;
}

.sc-msg--admin .sc-bubble {
    background: #f0f4ff;
    color: #222;
    border-bottom-left-radius: 4px;
}

.sc-msg--system .sc-bubble {
    background: #fef9e7;
    color: #7d6608;
    font-size: 12px;
    border-radius: 8px;
    text-align: center;
    padding: 6px 12px;
}

.sc-bubble p {
    margin: 0 0 4px;
}

.sc-bubble p:last-child {
    margin: 0;
}

.sc-time {
    font-size: 11px;
    opacity: .65;
    margin-top: 2px;
    display: block;
    text-align: right;
}

.sc-msg--admin .sc-time {
    text-align: left;
}

.sc-msg--system .sc-time {
    text-align: center;
}

.sc-attachment-link {
    display: block;
    font-size: 12px;
    color: inherit;
    text-decoration: underline;
    margin-top: 4px;
    opacity: .85;
}

.sc-attachment-link:hover {
    opacity: 1;
}

/* ── Input area ───────────────────────────────────────────────────────────── */
.sc-input-area {
    padding: 10px 12px;
    border-top: 1px solid #eee;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sc-input-area--first {
    padding: 16px;
}

.sc-textarea {
    width: 100%;
    border: 1px solid #dde4f0;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    outline: none;
    transition: border-color .2s;
    box-sizing: border-box;
    line-height: 1.4;
}

.sc-textarea:focus {
    border-color: #5b8dee;
}

.sc-input-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.sc-attach-label {
    cursor: pointer;
    color: #888;
    display: flex;
    align-items: center;
    padding: 4px;
    border-radius: 6px;
    transition: color .15s, background .15s;
}

.sc-attach-label:hover {
    color: #5b8dee;
    background: #f0f4ff;
}

.sc-send-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    background: #5b8dee;
    color: #fff;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
    font-weight: 600;
    transition: background .2s, transform .1s;
}

.sc-send-btn:hover:not(:disabled) {
    background: #4a7de0;
}

.sc-send-btn:active:not(:disabled) {
    transform: scale(.97);
}

.sc-send-btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* ── File preview ─────────────────────────────────────────────────────────── */
.sc-file-preview {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 0 12px 6px;
}

.sc-file-tag {
    background: #f0f4ff;
    color: #5b8dee;
    border: 1px solid #d0dcf8;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 11px;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ── Mobile ───────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
    #sc-widget {
        bottom: 16px;
        right: 16px;
    }

    .sc-window {
        position: fixed;
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 80vh;
        border-radius: 16px 16px 0 0;
    }

    .sc-toggle-label {
        display: none;
    }

    .sc-toggle-btn {
        width: 50px;
        height: 50px;
        border-radius: 50%;
        padding: 0;
        justify-content: center;
    }
}
