/* =====================================================================
   HomeOS Support Bubble — Floating "tech cloud" AI assistant
   Brand colors: orange #f1552a (CTA), cyan #25aae1 (info), dark blue #175e90 (primary)
   ===================================================================== */

#supportBubble {
    --sb-orange: #f1552a;
    --sb-cyan: #25aae1;
    --sb-blue: #175e90;
    --sb-orange-soft: rgba(241, 85, 42, 0.12);
    --sb-cyan-soft: rgba(37, 170, 225, 0.12);
    --sb-blue-soft: rgba(23, 94, 144, 0.12);
}

.sb-wrap {
    position: fixed;
    bottom: calc(20px + env(safe-area-inset-bottom, 0px));
    right: 20px;
    z-index: 9998;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* ── Floating bubble button ── */
.sb-bubble {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: linear-gradient(135deg, var(--sb-blue) 0%, var(--sb-cyan) 100%);
    color: #fff;
    box-shadow: 0 8px 24px rgba(23, 94, 144, 0.45);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    overflow: visible;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0;
    padding: 0;
}
.sb-bubble:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 32px rgba(23, 94, 144, 0.6);
}
.sb-bubble:active { transform: translateY(-1px) scale(0.98); }

.sb-bubble-icon {
    font-size: 24px;
    color: #fff;
    z-index: 2;
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.3));
}

/* ── Pulse ring ── */
.sb-bubble-pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--sb-orange);
    opacity: 0;
    animation: sbPulse 2.5s ease-out infinite;
    pointer-events: none;
}
@keyframes sbPulse {
    0% { opacity: 0.6; transform: scale(1); }
    80% { opacity: 0; transform: scale(1.6); }
    100% { opacity: 0; transform: scale(1.6); }
}

/* ── Tech cloud (dust) — animated dots floating around bubble ── */
.sb-cloud {
    position: absolute;
    inset: -10px;
    pointer-events: none;
    z-index: 1;
}
.sb-cloud-dot {
    position: absolute;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--sb-orange);
    box-shadow: 0 0 6px var(--sb-orange);
    opacity: 0.85;
    animation: sbCloudFloat 4s ease-in-out infinite;
}
.sb-cloud-dot.d1 { top: 8%; left: 50%; background: var(--sb-orange); animation-delay: 0s; }
.sb-cloud-dot.d2 { top: 30%; right: 5%; background: var(--sb-cyan); animation-delay: 0.5s; }
.sb-cloud-dot.d3 { bottom: 18%; right: 12%; background: var(--sb-orange); animation-delay: 1s; box-shadow: 0 0 6px var(--sb-orange); }
.sb-cloud-dot.d4 { bottom: 5%; left: 45%; background: var(--sb-cyan); animation-delay: 1.5s; box-shadow: 0 0 6px var(--sb-cyan); }
.sb-cloud-dot.d5 { bottom: 28%; left: 5%; background: var(--sb-orange); animation-delay: 2s; box-shadow: 0 0 6px var(--sb-orange); }
.sb-cloud-dot.d6 { top: 25%; left: 8%; background: var(--sb-cyan); animation-delay: 2.5s; box-shadow: 0 0 6px var(--sb-cyan); }

@keyframes sbCloudFloat {
    0%, 100% { transform: translate(0, 0) scale(1); opacity: 0.85; }
    25% { transform: translate(4px, -4px) scale(1.2); opacity: 1; }
    50% { transform: translate(-2px, 4px) scale(0.9); opacity: 0.6; }
    75% { transform: translate(-4px, -2px) scale(1.1); opacity: 0.9; }
}

/* ── Chat panel ── */
.sb-panel {
    position: absolute;
    bottom: 80px;
    right: 0;
    width: 400px;
    max-width: calc(100vw - 40px);
    height: 540px;
    max-height: calc(100vh - 140px);
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: sbPanelIn 0.25s ease-out;
}
.sb-panel[hidden] { display: none; }
@keyframes sbPanelIn {
    from { opacity: 0; transform: translateY(15px) scale(0.95); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ── Panel header ── */
.sb-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    background: linear-gradient(135deg, var(--sb-blue) 0%, var(--sb-cyan) 100%);
    color: #fff;
    flex-shrink: 0;
}
.sb-panel-title {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}
.sb-panel-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
}
.sb-panel-title strong {
    font-size: 13px;
    font-weight: 700;
    color: #fff;
    display: block;
    line-height: 1.2;
}
.sb-panel-sub {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.85);
    margin-top: 1px;
    line-height: 1.2;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 220px;
}
.sb-panel-sub i { margin-right: 3px; opacity: 0.85; }

.sb-panel-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.sb-iconbtn {
    width: 26px;
    height: 26px;
    border-radius: 5px;
    border: none;
    background: rgba(255, 255, 255, 0.18);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    transition: background 0.15s;
}
.sb-iconbtn:hover { background: rgba(255, 255, 255, 0.32); }

/* ── Messages ── */
.sb-panel-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 10px 12px;
    background: var(--bg-secondary, #f9fafb);
    display: flex;
    flex-direction: column;
    gap: 8px;
    min-height: 0;
}
.sb-panel-msgs::-webkit-scrollbar { width: 5px; }
.sb-panel-msgs::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 3px; }
[data-theme="dark"] .sb-panel-msgs::-webkit-scrollbar-thumb { background: #4b5563; }

.sb-empty {
    text-align: center;
    padding: 30px 14px;
    color: var(--text-secondary, #6b7280);
}
.sb-empty i {
    font-size: 36px;
    color: var(--sb-orange);
    opacity: 0.65;
    display: block;
    margin-bottom: 10px;
}
.sb-empty p {
    font-size: 11.5px;
    margin: 0 0 12px 0;
    line-height: 1.45;
}
.sb-empty strong { color: var(--sb-blue); }
.sb-suggs {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: center;
}
.sb-sugg {
    background: var(--sb-orange-soft);
    color: var(--sb-orange);
    border: 1px solid rgba(241, 85, 42, 0.3);
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 10.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.sb-sugg:hover {
    background: var(--sb-orange);
    color: #fff;
    border-color: var(--sb-orange);
}

/* ── Message bubble ── */
.sb-msg {
    display: flex;
    gap: 6px;
    width: 100%;
    min-width: 0;
}
.sb-msg-avatar {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 13px;
    border: 1px solid var(--border-color, #e5e7eb);
}
.sb-msg-avatar-ai {
    background: var(--sb-orange-soft);
    color: var(--sb-orange);
    border-color: var(--sb-orange);
}
.sb-msg-avatar-user {
    background: var(--sb-blue);
    color: #fff;
    border-color: var(--sb-blue);
    font-size: 10px;
}
.sb-msg-body {
    flex: 1 1 0;
    min-width: 0;
    padding: 6px 9px;
    border-radius: 9px;
    background: var(--bg-primary, #fff);
    border: 1px solid var(--border-color, #e5e7eb);
    color: var(--text-primary, #111827);
    font-size: 11.5px;
    line-height: 1.4;
    overflow: hidden;
    overflow-wrap: break-word;
    word-break: break-word;
}
.sb-msg-user { flex-direction: row-reverse; }
.sb-msg-user .sb-msg-body {
    background: var(--sb-blue);
    color: #fff;
    border-color: var(--sb-blue);
}
.sb-msg-error .sb-msg-body {
    background: rgba(239, 68, 68, 0.12);
    color: #ef4444;
    border-color: #ef4444;
}

/* Markdown body inside bubble */
.sb-msg-body > *:first-child { margin-top: 0 !important; }
.sb-msg-body > *:last-child { margin-bottom: 0 !important; }
.sb-msg-body p { margin: 0 0 4px 0; }
.sb-msg-body p:last-child { margin-bottom: 0; }
.sb-msg-body h1, .sb-msg-body h2, .sb-msg-body h3, .sb-msg-body h4 {
    margin: 6px 0 3px 0;
    font-weight: 700;
    line-height: 1.25;
}
.sb-msg-body h1 { font-size: 13px; }
.sb-msg-body h2 { font-size: 12.5px; }
.sb-msg-body h3 { font-size: 12px; }
.sb-msg-body strong { font-weight: 700; }
.sb-msg-body code {
    background: rgba(241, 85, 42, 0.1);
    color: var(--sb-orange);
    padding: 0 4px;
    border-radius: 3px;
    font-family: 'Consolas', monospace;
    font-size: 10.5px;
    word-break: break-all;
}
.sb-msg-user .sb-msg-body code {
    background: rgba(255, 255, 255, 0.2);
    color: #fff;
}
.sb-msg-body pre {
    background: var(--bg-secondary, #f3f4f6);
    border-radius: 5px;
    padding: 5px 8px;
    overflow-x: auto;
    margin: 4px 0;
    font-size: 10.5px;
}
.sb-msg-body pre code {
    background: none;
    color: var(--text-primary, #111827);
    padding: 0;
}
.sb-msg-body ul, .sb-msg-body ol {
    margin: 2px 0 4px 0;
    padding-left: 18px;
}
.sb-msg-body li { margin-bottom: 1px; line-height: 1.4; }
.sb-msg-body a {
    color: var(--sb-cyan);
    text-decoration: none;
    font-weight: 600;
}
.sb-msg-body a:hover { text-decoration: underline; }
.sb-msg-body a.sb-nav-link {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    margin: 2px 3px 2px 0;
    background: var(--sb-orange);
    color: #fff !important;
    border-radius: 10px;
    font-size: 10.5px;
    font-weight: 700;
}
.sb-msg-body a.sb-nav-link:hover { background: #ff6e3d; }
.sb-msg-body a.sb-nav-link::before { content: '\f0a9'; font-family: 'Font Awesome 5 Free'; font-weight: 900; }

/* Typing indicator */
.sb-typing { color: var(--text-secondary, #6b7280); font-style: italic; font-size: 11px; }
.sb-typing span {
    display: inline-block;
    animation: sbDots 1.4s infinite;
    margin-left: 1px;
}
.sb-typing span:nth-child(2) { animation-delay: 0.2s; }
.sb-typing span:nth-child(3) { animation-delay: 0.4s; }
@keyframes sbDots {
    0%, 60%, 100% { opacity: 0.3; }
    30% { opacity: 1; }
}

/* ── Input ── */
.sb-panel-input {
    display: flex;
    gap: 6px;
    padding: 8px 10px;
    border-top: 1px solid var(--border-color, #e5e7eb);
    background: var(--bg-primary, #fff);
    flex-shrink: 0;
}
.sb-panel-input textarea {
    flex: 1;
    min-height: 32px;
    max-height: 120px;
    padding: 6px 10px;
    border: 1px solid var(--border-color, #e5e7eb);
    border-radius: 6px;
    background: var(--bg-secondary, #f9fafb);
    color: var(--text-primary, #111827);
    font-size: 12px;
    font-family: inherit;
    resize: none;
    line-height: 1.4;
}
.sb-panel-input textarea:focus { outline: none; border-color: var(--sb-orange); }
.sb-panel-input button {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    background: var(--sb-orange);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    flex-shrink: 0;
    transition: background 0.15s;
}
.sb-panel-input button:hover { background: #ff6e3d; }
.sb-panel-input button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Footer ── */
.sb-panel-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 6px 10px;
    border-top: 1px solid var(--border-color, #e5e7eb);
    background: var(--bg-secondary, #f9fafb);
    font-size: 10.5px;
    flex-shrink: 0;
}
.sb-panel-footer a {
    color: var(--sb-cyan);
    text-decoration: none;
    font-weight: 600;
    cursor: pointer;
}
.sb-panel-footer a:hover { color: var(--sb-blue); text-decoration: underline; }
.sb-panel-footer a i { margin-right: 3px; }
.sb-footer-sep { color: var(--text-muted, #9ca3af); }

/* ── Mobile ── */
@media (max-width: 640px) {
    .sb-wrap { bottom: calc(70px + env(safe-area-inset-bottom, 0px)); right: 12px; }
    .sb-bubble { width: 52px; height: 52px; }
    .sb-bubble-icon { font-size: 20px; }
    .sb-panel {
        bottom: 70px;
        right: -12px;
        left: auto;
        width: calc(100vw - 8px);
        max-width: calc(100vw - 8px);
        height: calc(100vh - 180px);
        max-height: 70vh;
    }
}

/* ── Dark mode ── */
[data-theme="dark"] .sb-msg-body {
    background: rgba(51, 65, 85, 0.5);
}
[data-theme="dark"] .sb-msg-body code {
    background: rgba(241, 85, 42, 0.18);
}
[data-theme="dark"] .sb-msg-body pre {
    background: #1f2937;
}
