/* Boreal Relay Chat Widget — v2.0.0 */
:root {
    --br-primary: #2563eb;
    --br-primary-dark: #1d4ed8;
    --br-primary-light: #3b82f6;
    --br-radius: 20px;
    --br-shadow: 0 12px 40px rgba(37,99,235,0.22), 0 2px 8px rgba(0,0,0,0.10);
    --br-font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

/* ── Widget container ── */
#boreal-relay-widget {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 999999;
    font-family: var(--br-font);
    font-size: 14px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
    box-sizing: border-box;
    max-width: calc(100vw - 24px);
}
#boreal-relay-widget *,
#boreal-relay-widget *::before,
#boreal-relay-widget *::after { box-sizing: border-box; }

/* ── Teaser label ── */
#boreal-relay-teaser {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border-radius: 24px;
    padding: 8px 16px 8px 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.12), 0 1px 4px rgba(0,0,0,0.06);
    font-size: 13.5px;
    font-weight: 600;
    color: #1e293b;
    cursor: pointer;
    white-space: nowrap;
    opacity: 0;
    transform: translateX(12px) scale(0.95);
    transition: opacity 0.35s ease, transform 0.35s ease;
    border: 1px solid rgba(37,99,235,0.10);
}
#boreal-relay-teaser.visible {
    opacity: 1;
    transform: translateX(0) scale(1);
}
#boreal-relay-teaser-dot {
    width: 8px;
    height: 8px;
    background: #22c55e;
    border-radius: 50%;
    flex-shrink: 0;
    box-shadow: 0 0 0 2px rgba(34,197,94,0.3);
    animation: br-pulse-dot 2s infinite;
}
@keyframes br-pulse-dot {
    0%, 100% { box-shadow: 0 0 0 2px rgba(34,197,94,0.3); }
    50%       { box-shadow: 0 0 0 5px rgba(34,197,94,0.12); }
}

/* ── Toggle button ── */
#boreal-relay-toggle {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--br-primary-light), var(--br-primary-dark));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    box-shadow: var(--br-shadow);
    transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1), box-shadow 0.2s;
    outline: none;
}
#boreal-relay-toggle:hover {
    transform: scale(1.08);
    box-shadow: 0 16px 48px rgba(37,99,235,0.32), 0 2px 8px rgba(0,0,0,0.12);
}
#boreal-relay-toggle:active { transform: scale(0.96); }
#boreal-relay-toggle svg { width: 26px; height: 26px; transition: transform 0.2s; }

/* ── Pulse ring (when badge is visible) ── */
#boreal-relay-toggle.has-badge::before {
    content: '';
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid var(--br-primary-light);
    animation: br-ring 1.8s ease-out infinite;
    opacity: 0;
}
@keyframes br-ring {
    0%   { transform: scale(1);   opacity: 0.7; }
    100% { transform: scale(1.5); opacity: 0; }
}

#boreal-relay-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    background: #ef4444;
    color: #fff;
    border-radius: 50%;
    width: 20px;
    height: 20px;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    box-shadow: 0 2px 6px rgba(239,68,68,0.5);
}

/* ── Panel ── */
#boreal-relay-panel {
    display: none;
    flex-direction: column;
    position: absolute;
    bottom: 76px;
    right: 0;
    width: 380px;
    max-width: calc(100vw - 32px);
    height: 540px;
    max-height: calc(100vh - 120px);
    box-sizing: border-box;
    background: #f8fafc;
    border-radius: var(--br-radius);
    box-shadow: 0 20px 60px rgba(0,0,0,0.18), 0 4px 16px rgba(37,99,235,0.12);
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.8);
}
#boreal-relay-panel.open {
    display: flex;
    animation: br-pop-in 0.3s cubic-bezier(0.34,1.56,0.64,1) both;
}
@keyframes br-pop-in {
    from { opacity: 0; transform: translateY(20px) scale(0.94); }
    to   { opacity: 1; transform: translateY(0)    scale(1); }
}

/* ── Header ── */
#boreal-relay-header {
    background: linear-gradient(135deg, var(--br-primary-light) 0%, var(--br-primary-dark) 100%);
    color: #fff;
    padding: 16px 16px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-shrink: 0;
    position: relative;
}
#boreal-relay-header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 12px;
    background: #f8fafc;
    border-radius: 14px 14px 0 0;
}

#boreal-relay-avatar {
    width: 42px;
    height: 42px;
    background: rgba(255,255,255,0.22);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.35);
    backdrop-filter: blur(4px);
    position: relative;
    z-index: 1;
}
#boreal-relay-avatar svg { width: 22px; height: 22px; }

#boreal-relay-avatar-status {
    position: absolute;
    bottom: 1px;
    right: 1px;
    width: 11px;
    height: 11px;
    background: #4ade80;
    border-radius: 50%;
    border: 2px solid #fff;
}

#boreal-relay-header-info {
    flex: 1;
    position: relative;
    z-index: 1;
}
#boreal-relay-header-info strong {
    display: block;
    font-size: 15.5px;
    font-weight: 700;
    letter-spacing: -0.01em;
}
#boreal-relay-header-info span {
    font-size: 11.5px;
    opacity: 0.82;
    display: flex;
    align-items: center;
    gap: 5px;
}
#boreal-relay-header-info span::before {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: #4ade80;
    border-radius: 50%;
    flex-shrink: 0;
}

#boreal-relay-minimize {
    background: rgba(255,255,255,0.15);
    border: none;
    color: #fff;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    transition: background 0.15s;
    position: relative;
    z-index: 1;
    flex-shrink: 0;
    padding: 0;
}
#boreal-relay-minimize:hover { background: rgba(255,255,255,0.28); }

/* ── Messages ── */
#boreal-relay-messages {
    flex: 1;
    min-width: 0;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 8px 14px 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    scroll-behavior: smooth;
    background: #f8fafc;
}
#boreal-relay-messages::-webkit-scrollbar { width: 4px; }
#boreal-relay-messages::-webkit-scrollbar-track { background: transparent; }
#boreal-relay-messages::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 4px; }

.br-msg {
    display: flex;
    flex-direction: column;
    max-width: 82%;
    min-width: 0;
    gap: 3px;
    animation: br-msg-in 0.22s ease both;
}
@keyframes br-msg-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.br-msg.bot  { align-self: flex-start; }
.br-msg.user { align-self: flex-end; }

.br-bubble {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.55;
    word-break: break-word;
    overflow-wrap: anywhere;
    max-width: 100%;
}
.br-msg.bot .br-bubble {
    background: #fff;
    color: #1e293b;
    border-bottom-left-radius: 4px;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07), 0 0 0 1px rgba(0,0,0,0.04);
}
.br-msg.user .br-bubble {
    background: linear-gradient(135deg, var(--br-primary-light), var(--br-primary-dark));
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(37,99,235,0.3);
}
.br-bubble a {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    opacity: 0.9;
}

.br-time {
    font-size: 10px;
    color: #94a3b8;
    padding: 0 4px;
}
.br-msg.user .br-time { text-align: right; }

.br-feedback {
    display: flex;
    max-width: 100%;
    flex-wrap: wrap;
    gap: 5px;
    padding: 2px 2px 0;
}
.br-feedback button {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 20px;
    padding: 3px 10px;
    font-size: 11px;
    cursor: pointer;
    color: #64748b;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    gap: 3px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
}
.br-feedback button:hover { background: #f1f5f9; border-color: #94a3b8; }
.br-feedback button.active { background: #eff6ff; border-color: #93c5fd; color: #1d4ed8; font-weight: 600; }
.br-feedback button:disabled { opacity: 0.55; cursor: not-allowed; }

/* ── Typing indicator ── */
.br-typing {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 12px 14px;
    background: #fff;
    border-radius: 16px;
    border-bottom-left-radius: 4px;
    width: fit-content;
    box-shadow: 0 1px 4px rgba(0,0,0,0.07), 0 0 0 1px rgba(0,0,0,0.04);
}
.br-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: br-bounce 1.2s infinite ease-in-out;
}
.br-typing span:nth-child(2) { animation-delay: 0.18s; }
.br-typing span:nth-child(3) { animation-delay: 0.36s; }
@keyframes br-bounce {
    0%, 60%, 100% { transform: translateY(0);   opacity: 0.6; }
    30%            { transform: translateY(-6px); opacity: 1; }
}

/* ── Contact / escalation form ── */
#boreal-relay-contact-form {
    background: #fff;
    border-top: 1px solid #e2e8f0;
    padding: 14px 16px;
    flex-shrink: 0;
}
#boreal-relay-contact-form > * { margin-bottom: 8px; }
#boreal-relay-contact-form > *:last-child { margin-bottom: 0; }
#boreal-relay-contact-intro {
    margin: 0 0 2px;
    font-size: 12.5px;
    font-weight: 600;
    color: #374151;
    display: flex;
    align-items: center;
    gap: 6px;
}
#boreal-relay-contact-intro::before {
    content: '💬';
    font-size: 14px;
}
#boreal-relay-contact-form input {
    width: 100%;
    box-sizing: border-box;
    border: 1.5px solid #e2e8f0;
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 13px;
    font-family: var(--br-font);
    background: #f8fafc;
    color: #1e293b;
    outline: none;
    transition: border-color 0.15s, background 0.15s;
}
#boreal-relay-contact-form input:focus {
    border-color: var(--br-primary);
    background: #fff;
}
#boreal-relay-contact-form input::placeholder { color: #94a3b8; }
#boreal-relay-contact-submit {
    background: linear-gradient(135deg, var(--br-primary-light), var(--br-primary-dark));
    color: #fff;
    border: none;
    border-radius: 10px;
    padding: 9px 14px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.15s;
    font-family: var(--br-font);
    box-shadow: 0 2px 8px rgba(37,99,235,0.3);
    margin-top: 2px;
}
#boreal-relay-contact-submit:hover  { opacity: 0.92; transform: translateY(-1px); }
#boreal-relay-contact-submit:active { transform: translateY(0); }
#boreal-relay-contact-submit:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
#boreal-relay-contact-thanks {
    margin: 0;
    font-size: 13px;
    font-weight: 600;
    color: #16a34a;
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 4px 0;
}

/* ── Input area ── */
#boreal-relay-input-area {
    padding: 12px 14px;
    border-top: 1px solid #e9eef5;
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
    min-width: 0;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: #fff;
}

#boreal-relay-input {
    flex: 1;
    min-width: 0;
    border: 1.5px solid #e2e8f0;
    border-radius: 22px;
    padding: 9px 16px;
    font-size: 13.5px;
    font-family: var(--br-font);
    resize: none;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
    max-height: 80px;
    overflow-y: auto;
    line-height: 1.45;
    color: #1e293b;
    background: #f8fafc;
}
#boreal-relay-input:focus {
    border-color: var(--br-primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(37,99,235,0.10);
}
#boreal-relay-input::placeholder { color: #94a3b8; }

#boreal-relay-send {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--br-primary-light), var(--br-primary-dark));
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    flex-shrink: 0;
    transition: transform 0.2s cubic-bezier(0.34,1.56,0.64,1), opacity 0.15s;
    outline: none;
    box-shadow: 0 2px 8px rgba(37,99,235,0.35);
}
#boreal-relay-send:hover   { transform: scale(1.1); }
#boreal-relay-send:active  { transform: scale(0.94); }
#boreal-relay-send:disabled { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }
#boreal-relay-send svg { width: 16px; height: 16px; margin-left: 2px; }

/* ── Responsive ── */
@media (max-width: 480px) {
    #boreal-relay-widget {
        bottom: max(12px, env(safe-area-inset-bottom));
        right: max(12px, env(safe-area-inset-right));
        width: calc(100vw - 24px);
        max-width: calc(100vw - 24px);
    }
    #boreal-relay-panel {
        right: 0;
        bottom: calc(72px + env(safe-area-inset-bottom));
        width: 100%;
        max-width: 100%;
        height: min(540px, calc(var(--br-viewport-height, 100vh) - 96px));
        max-height: calc(var(--br-viewport-height, 100vh) - 96px);
        border-radius: 18px;
    }
    #boreal-relay-teaser  { display: none; }
    #boreal-relay-header { padding: 14px 14px 18px; }
    #boreal-relay-messages { padding: 8px 10px 12px; }
    .br-msg { max-width: 90%; }
    .br-feedback button { padding: 7px 10px; min-height: 36px; }
    #boreal-relay-input-area { padding-left: 10px; padding-right: 10px; }
}
