/* Swagy chat launcher + panel. Uses the app's theme tokens (css/theme-tokens.css),
   so light/dark follow [data-theme] automatically. Logic: js/swagy-chat.js.
   z-index 9000: above page content and the sidebar, below the app's modals (99999). */

.swagy-launcher, .swagy-panel, .swagy-panel * { box-sizing: border-box; }

.swagy-launcher {
    position: fixed;
    right: 22px;
    bottom: 30px;              /* keeps the version stamp (bottom:6px) visible underneath */
    width: 58px;
    height: 58px;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.14);
    background: linear-gradient(160deg, var(--sidebar-light, #1e293b) 0%, var(--sidebar-dark, #0f172a) 100%);
    box-shadow: 0 10px 28px rgba(15,23,42,0.35), 0 0 0 0 rgba(139,92,246,0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    z-index: 9000;
    transition: transform .18s ease, box-shadow .18s ease;
    animation: swagy-pulse 3.2s ease-out 1.2s 3;
}
.swagy-launcher:hover,
.swagy-launcher:focus-visible { transform: translateY(-2px) scale(1.04); box-shadow: 0 14px 32px rgba(15,23,42,0.42), 0 0 0 6px rgba(139,92,246,0.18); outline: none; }
.swagy-launcher.swagy-open { animation: none; }
.swagy-launcher .swagy-tess { width: 44px; height: 44px; filter: drop-shadow(0 0 8px rgba(120,80,255,0.55)); }
.swagy-launcher-dot {
    position: absolute; top: 6px; right: 6px; width: 10px; height: 10px; border-radius: 50%;
    background: #22c55e; border: 2px solid var(--sidebar-dark, #0f172a);
}
@keyframes swagy-pulse {
    0%   { box-shadow: 0 10px 28px rgba(15,23,42,0.35), 0 0 0 0 rgba(139,92,246,0.45); }
    60%  { box-shadow: 0 10px 28px rgba(15,23,42,0.35), 0 0 0 14px rgba(139,92,246,0); }
    100% { box-shadow: 0 10px 28px rgba(15,23,42,0.35), 0 0 0 0 rgba(139,92,246,0); }
}

/* Fallback glyph when canvas is unavailable */
.swagy-tess.swagy-tess-fallback {
    background: radial-gradient(circle at 50% 50%, #a78bfa 0 22%, transparent 24%),
                linear-gradient(135deg, #38bdf8, #8b5cf6);
    border-radius: 10px;
}

.swagy-panel {
    position: fixed;
    right: 22px;
    bottom: 100px;
    width: 390px;
    max-width: calc(100vw - 32px);
    height: 600px;
    max-height: calc(100vh - 130px);
    display: flex;
    flex-direction: column;
    background: var(--card-bg, #fff);
    color: var(--text-primary, #0f172a);
    border: 1px solid var(--border, #e2e8f0);
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(15,23,42,0.28);
    overflow: hidden;
    z-index: 9000;
    font-family: inherit;
}
.swagy-panel[hidden] { display: none; }

.swagy-head {
    display: flex; align-items: center; gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(160deg, var(--sidebar-light, #1e293b) 0%, var(--sidebar-dark, #0f172a) 100%);
    color: #fff;
}
.swagy-head-logo { width: 32px; height: 32px; filter: drop-shadow(0 0 6px rgba(120,80,255,0.5)); flex: none; }
.swagy-head-text { display: flex; flex-direction: column; flex: 1; min-width: 0; line-height: 1.2; }
.swagy-head-text strong { font-size: 1rem; letter-spacing: .01em; }
.swagy-head-text span { font-size: .72rem; opacity: .75; }
.swagy-close {
    background: rgba(255,255,255,0.08); border: 0; color: #fff; width: 30px; height: 30px; border-radius: 8px;
    font-size: 1.3rem; line-height: 1; cursor: pointer;
}
.swagy-close:hover { background: rgba(255,255,255,0.18); }

.swagy-msgs {
    flex: 1; overflow-y: auto; padding: 14px 14px 6px;
    display: flex; flex-direction: column; gap: 10px;
    background: var(--bg-secondary, #f8fafc);
    scroll-behavior: smooth;
}
.swagy-msg { display: flex; flex-direction: column; max-width: 92%; }
.swagy-user { align-self: flex-end; align-items: flex-end; }
.swagy-assistant { align-self: flex-start; align-items: flex-start; }
.swagy-bubble {
    padding: 9px 12px; border-radius: 14px; font-size: .9rem; line-height: 1.45; word-wrap: break-word; overflow-wrap: anywhere;
    background: var(--card-bg, #fff); border: 1px solid var(--border, #e2e8f0); color: var(--text-primary, #0f172a);
}
.swagy-user .swagy-bubble { background: var(--primary-gradient, linear-gradient(135deg,#0ea5e9,#06b6d4)); color: #fff; border: 0; border-bottom-right-radius: 4px; }
.swagy-assistant .swagy-bubble { border-bottom-left-radius: 4px; }
.swagy-error .swagy-bubble { border-color: #f59e0b; background: rgba(245,158,11,0.08); }
.swagy-blocked .swagy-bubble { border-style: dashed; color: var(--text-secondary, #475569); }
.swagy-bubble p { margin: 0 0 6px; }
.swagy-bubble p:last-child { margin-bottom: 0; }
.swagy-bubble ul, .swagy-bubble ol { margin: 4px 0 6px; padding-left: 20px; }
.swagy-bubble li { margin: 2px 0; }
.swagy-bubble code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82em; padding: 1px 5px; border-radius: 5px; background: rgba(15,23,42,0.07); }
[data-theme="dark"] .swagy-bubble code { background: rgba(255,255,255,0.1); }
.swagy-bubble .swagy-source { font-size: .76rem; color: var(--text-muted, #64748b); margin-top: 6px; }
.swagy-meta { font-size: .72rem; color: var(--text-muted, #64748b); margin: 4px 6px 0; }
.swagy-thinking .swagy-bubble { display: flex; align-items: center; gap: 8px; color: var(--text-secondary, #475569); }
.swagy-dots { letter-spacing: 2px; animation: swagy-blink 1.1s infinite; }
.swagy-thinking-text { font-size: .82rem; }
@keyframes swagy-blink { 0%, 100% { opacity: .25; } 50% { opacity: 1; } }

.swagy-chips { display: flex; flex-wrap: wrap; gap: 6px; padding: 4px 14px 8px; background: var(--bg-secondary, #f8fafc); }
.swagy-chips[hidden] { display: none; }
.swagy-chip {
    border: 1px solid var(--border, #e2e8f0); background: var(--card-bg, #fff); color: var(--text-secondary, #475569);
    border-radius: 999px; padding: 5px 11px; font-size: .78rem; cursor: pointer;
}
.swagy-chip:hover { border-color: var(--primary, #0ea5e9); color: var(--primary, #0ea5e9); }

.swagy-form {
    display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px;
    border-top: 1px solid var(--border, #e2e8f0); background: var(--card-bg, #fff);
}
.swagy-input {
    flex: 1; resize: none; min-height: 38px; max-height: 120px; padding: 9px 12px; font: inherit; font-size: .9rem; line-height: 1.35;
    border: 1px solid var(--border, #e2e8f0); border-radius: 12px; background: var(--input-bg, #fff); color: var(--text-primary, #0f172a);
}
.swagy-input:focus { outline: none; border-color: var(--primary, #0ea5e9); box-shadow: 0 0 0 3px rgba(14,165,233,0.15); }
.swagy-send {
    width: 40px; height: 40px; border-radius: 12px; border: 0; cursor: pointer; flex: none;
    background: var(--primary-gradient, linear-gradient(135deg,#0ea5e9,#06b6d4)); color: #fff;
    display: flex; align-items: center; justify-content: center;
}
.swagy-send:disabled, .swagy-input:disabled { opacity: .55; cursor: default; }
.swagy-foot { font-size: .7rem; color: var(--text-muted, #64748b); text-align: center; padding: 6px 12px 9px; background: var(--card-bg, #fff); }

@media (max-width: 560px) {
    .swagy-panel { right: 0; bottom: 0; width: 100vw; max-width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; border: 0; }
    .swagy-launcher { right: 14px; bottom: 22px; }
}
@media print { .swagy-launcher, .swagy-panel { display: none !important; } }
