/* ─── MYSEAK Chat Widget ─────────────────────────────────────────── */

:root {
    --seak-primary: #6366f1;
    --seak-bg: #ffffff;
    --seak-bg-msg: #f3f4f6;
    --seak-text: #1f2937;
    --seak-text-light: #6b7280;
    --seak-radius: 16px;
    --seak-shadow: 0 10px 40px rgba(0, 0, 0, 0.12);
}

/* ─── Toggle Button ───────────────────────────────────────── */
#seak-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--seak-primary) !important;
    color: #fff !important;
    border: none !important;
    cursor: pointer;
    box-shadow: var(--seak-shadow);
    z-index: 99998;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 1 !important;
    transition: transform 0.2s ease, filter 0.2s ease;
}

#seak-toggle:hover,
#seak-toggle:focus,
#seak-toggle:active {
    transform: scale(1.1);
    background: var(--seak-primary) !important;
    opacity: 1 !important;
    filter: brightness(1.2);
}

#seak-toggle svg {
    width: 28px;
    height: 28px;
}

/* ─── Chat Container (Desktop) ────────────────────────────── */
#seak-chat {
    position: fixed;
    bottom: 96px;
    right: 24px;
    width: 380px;
    max-height: 520px;
    background: var(--seak-bg);
    border-radius: var(--seak-radius);
    box-shadow: var(--seak-shadow);
    z-index: 99999;
    display: none;
    flex-direction: column;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    color: var(--seak-text);
}

#seak-chat.open {
    display: flex;
}

/* ─── Header ──────────────────────────────────────────────── */
.seak-header {
    background: var(--seak-primary);
    color: #fff;
    padding: 16px 20px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.seak-header-dot {
    width: 10px;
    height: 10px;
    background: #4ade80;
    border-radius: 50%;
    flex-shrink: 0;
}

.seak-header-title {
    font-weight: 600;
    font-size: 15px;
    flex-grow: 1;
}

.seak-header-close {
    background: none;
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    opacity: 0.8;
}

.seak-header-close:hover {
    opacity: 1;
}

/* ─── Messages Area ───────────────────────────────────────── */
.seak-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    max-height: 350px;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.seak-msg {
    max-width: 85%;
    padding: 10px 14px;
    border-radius: 12px;
    line-height: 1.5;
    word-wrap: break-word;
    overflow-wrap: break-word;
    word-break: break-word;
}

.seak-msg-bot {
    background: var(--seak-bg-msg);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.seak-msg-user {
    background: var(--seak-primary);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

/* Sources */
.seak-sources {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #e5e7eb;
    font-size: 12px;
    color: var(--seak-text-light);
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
}

.seak-sources-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--seak-text-light);
    margin-right: 2px;
    flex-shrink: 0;
}

.seak-sources a {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    background: color-mix(in srgb, var(--seak-primary) 10%, transparent);
    color: var(--seak-primary);
    text-decoration: none;
    font-size: 11px;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
    word-break: break-word;
}

.seak-sources a:hover {
    background: color-mix(in srgb, var(--seak-primary) 20%, transparent);
    text-decoration: none;
}

.seak-source-text {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    background: #f3f4f6;
    color: #6b7280;
    font-size: 11px;
    font-weight: 500;
}

.seak-msg-bot a {
    color: var(--seak-primary);
    text-decoration: none;
    font-weight: 700;
    word-break: break-all;
}

.seak-msg-bot a:hover {
    text-decoration: underline;
}

/* Typing indicator */
.seak-typing {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    align-self: flex-start;
}

.seak-typing span {
    width: 8px;
    height: 8px;
    background: #d1d5db;
    border-radius: 50%;
    animation: seak-bounce 1.2s infinite;
}

.seak-typing span:nth-child(2) { animation-delay: 0.2s; }
.seak-typing span:nth-child(3) { animation-delay: 0.4s; }

@keyframes seak-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

/* ─── Input Area ──────────────────────────────────────────── */
.seak-input-area {
    padding: 12px 16px;
    border-top: 1px solid #e5e7eb;
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.seak-input-area input {
    flex: 1;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    min-width: 0;
}

.seak-input-area input:focus {
    border-color: var(--seak-primary);
}

.seak-input-area button {
    background: var(--seak-primary) !important;
    color: #fff !important;
    border: none !important;
    border-radius: 8px;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
    opacity: 1 !important;
    transition: filter 0.15s;
    flex-shrink: 0;
}

.seak-input-area button:hover,
.seak-input-area button:focus {
    background: var(--seak-primary) !important;
    color: #fff !important;
    opacity: 1 !important;
    filter: brightness(1.25);
}

.seak-input-area button:active {
    filter: brightness(0.9);
}

.seak-input-area button:disabled {
    background: color-mix(in srgb, var(--seak-primary) 50%, #fff) !important;
    cursor: not-allowed;
    filter: none;
}

/* ─── Mobile — fullscreen chat ────────────────────────────── */
@media (max-width: 600px) {
    /*
     * Mobile strategy:
     *  - inset:0 fills the screen, NO explicit height
     *  - flexbox column distributes space naturally
     *  - NO transitions on the container (keyboard resize must be instant)
     *  - overscroll-behavior prevents background page scroll
     *  - JS uses visualViewport only to adjust height when keyboard opens
     */
    #seak-chat {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: auto;
        max-width: none;
        max-height: none;
        border-radius: 0;
        z-index: 999999;
    }

    #seak-chat .seak-messages {
        flex: 1;
        max-height: none;
        min-height: 0;
    }

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

    /* 16px prevents iOS Safari auto-zoom on input focus */
    #seak-chat .seak-input-area input {
        font-size: 16px;
    }

    #seak-chat .seak-input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}
