/* ═══════════════════════════════════════
   AI Companion — Scoped Styles
   ═══════════════════════════════════════ */

/* ── FAB ── */
.ai-companion-fab {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: #6366f1;
    color: #fff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 900;
    box-shadow: 0 4px 14px rgba(99,102,241,0.4);
    transition: transform 0.2s, box-shadow 0.2s;
    font-family: inherit;
}
.ai-companion-fab:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 20px rgba(99,102,241,0.5);
}
.ai-companion-fab:active { transform: scale(0.96); }
.ai-companion-fab .material-symbols-outlined { font-size: 22px; }

/* Pulse ring (hidden by default, activated via JS) */
.ai-companion-fab__pulse {
    position: absolute;
    inset: -4px;
    border-radius: 50%;
    border: 2px solid #6366f1;
    opacity: 0;
    animation: none;
    pointer-events: none;
}
.ai-companion-fab--alert .ai-companion-fab__pulse {
    animation: companionPulse 2s ease-in-out infinite;
}
@keyframes companionPulse {
    0%   { transform: scale(1);   opacity: 0.6; }
    100% { transform: scale(1.5); opacity: 0; }
}

/* Hide FAB when panel is open */
.ai-companion-fab--hidden { display: none !important; }

/* ── Nudge notification ── */
.ai-companion-nudge {
    position: fixed;
    bottom: 76px;
    right: 20px;
    max-width: 280px;
    padding: 10px 32px 10px 14px;
    background: #1a1835;
    color: #e0e0f0;
    border: 1px solid rgba(99,102,241,0.2);
    border-radius: 14px 14px 4px 14px;
    font-size: 13px;
    font-weight: 500;
    line-height: 1.4;
    box-shadow: 0 8px 24px rgba(0,0,0,0.3);
    z-index: 899;
    animation: nudgeIn 0.3s ease;
    font-family: inherit;
}
.ai-companion-nudge[hidden] { display: none; }
@keyframes nudgeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ai-companion-nudge__close {
    position: absolute;
    top: 4px;
    right: 8px;
    background: none;
    border: none;
    color: #8b8fa3;
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
    padding: 2px;
}
.ai-companion-nudge__close:hover { color: #e0e0f0; }

/* ── Panel ── */
.ai-companion-panel {
    position: fixed;
    bottom: 0;
    right: 0;
    width: 100%;
    height: 70vh;
    background: #0c0a1a;
    border-top: 1px solid rgba(99,102,241,0.1);
    border-radius: 20px 20px 0 0;
    display: flex;
    flex-direction: column;
    z-index: 1000;
    animation: panelSlideUp 0.3s ease;
    font-family: 'DM Sans', 'Plus Jakarta Sans', system-ui, sans-serif;
}
.ai-companion-panel[hidden] { display: none !important; }
@keyframes panelSlideUp {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

/* Desktop: side panel */
@media (min-width: 768px) {
    .ai-companion-panel {
        width: 380px;
        height: calc(100vh - 80px);
        bottom: 20px;
        right: 20px;
        border-radius: 20px;
        border: 1px solid rgba(99,102,241,0.1);
        box-shadow: 0 20px 60px rgba(0,0,0,0.4);
    }
}

/* Panel header */
.ai-companion-panel__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid rgba(99,102,241,0.08);
    flex-shrink: 0;
}
.ai-companion-panel__header-left {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #e0e0f0;
}
.ai-companion-panel__close {
    background: none;
    border: none;
    color: #8b8fa3;
    cursor: pointer;
    padding: 4px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.ai-companion-panel__close:hover { background: rgba(255,255,255,0.06); color: #e0e0f0; }

/* Messages area */
.ai-companion-panel__messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.ai-companion-panel__messages::-webkit-scrollbar { width: 4px; }
.ai-companion-panel__messages::-webkit-scrollbar-thumb { background: rgba(99,102,241,0.2); border-radius: 4px; }

/* Individual message */
.ai-companion-msg {
    display: flex;
    max-width: 88%;
}
.ai-companion-msg--user {
    align-self: flex-end;
}
.ai-companion-msg--bot {
    align-self: flex-start;
}
.ai-companion-msg__content {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 13px;
    line-height: 1.5;
    word-break: break-word;
}
.ai-companion-msg--user .ai-companion-msg__content {
    background: #6366f1;
    color: #fff;
    border-bottom-right-radius: 4px;
}
.ai-companion-msg--bot .ai-companion-msg__content {
    background: #1a1835;
    color: #e0e0f0;
    border-bottom-left-radius: 4px;
}
/* Code blocks inside messages */
.ai-companion-msg__content pre {
    background: rgba(0,0,0,0.3);
    padding: 8px 10px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 6px 0;
    font-size: 12px;
    font-family: 'JetBrains Mono', monospace;
}
.ai-companion-msg__content code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
}
.ai-companion-msg__content p { margin: 0 0 6px; }
.ai-companion-msg__content p:last-child { margin-bottom: 0; }
.ai-companion-msg__content ul, .ai-companion-msg__content ol {
    margin: 4px 0;
    padding-left: 18px;
}
.ai-companion-msg__content strong { font-weight: 600; }

/* Typing indicator */
.ai-companion-typing {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    align-self: flex-start;
}
.ai-companion-typing__dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #6366f1;
    animation: typingBounce 1.2s ease-in-out infinite;
}
.ai-companion-typing__dot:nth-child(2) { animation-delay: 0.15s; }
.ai-companion-typing__dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* Input area */
.ai-companion-panel__input {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid rgba(99,102,241,0.08);
    flex-shrink: 0;
}
.ai-companion-panel__input textarea {
    flex: 1;
    background: #1a1835;
    color: #e0e0f0;
    border: 1px solid rgba(99,102,241,0.15);
    border-radius: 12px;
    padding: 10px 14px;
    font-size: 13px;
    font-family: inherit;
    resize: none;
    line-height: 1.4;
    max-height: 100px;
    outline: none;
    transition: border-color 0.2s;
}
.ai-companion-panel__input textarea::placeholder { color: #6b6b8a; }
.ai-companion-panel__input textarea:focus { border-color: rgba(99,102,241,0.4); }
.ai-companion-panel__input button {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: #6366f1;
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s;
}
.ai-companion-panel__input button:hover { background: #5558e6; }
.ai-companion-panel__input button:disabled { opacity: 0.5; cursor: not-allowed; }
.ai-companion-panel__input button .material-symbols-outlined { font-size: 18px; }

/* ── Light mode overrides ── */
[data-theme="light"] .ai-companion-nudge {
    background: #fff;
    color: #1a1625;
    border-color: #e5e1f0;
    box-shadow: 0 8px 24px rgba(0,0,0,0.1);
}
[data-theme="light"] .ai-companion-nudge__close { color: #999; }
[data-theme="light"] .ai-companion-nudge__close:hover { color: #333; }

[data-theme="light"] .ai-companion-panel {
    background: #fff;
    border-color: #e5e1f0;
}
[data-theme="light"] .ai-companion-panel__header {
    border-bottom-color: #eee;
}
[data-theme="light"] .ai-companion-panel__header-left { color: #1a1625; }
[data-theme="light"] .ai-companion-panel__close { color: #888; }
[data-theme="light"] .ai-companion-panel__close:hover { background: rgba(0,0,0,0.04); color: #333; }

[data-theme="light"] .ai-companion-msg--bot .ai-companion-msg__content {
    background: #f3f0ff;
    color: #1a1625;
}
[data-theme="light"] .ai-companion-msg__content pre {
    background: #eee;
}
[data-theme="light"] .ai-companion-panel__input textarea {
    background: #f5f3fa;
    color: #1a1625;
    border-color: #e0dce8;
}
[data-theme="light"] .ai-companion-panel__input textarea::placeholder { color: #999; }
[data-theme="light"] .ai-companion-panel__input textarea:focus { border-color: #6366f1; }

[data-theme="light"] .ai-companion-panel__messages::-webkit-scrollbar-thumb { background: rgba(99,102,241,0.15); }
[data-theme="light"] .ai-companion-panel__input { border-top-color: #eee; }

/* ── Labs shell compat: labs don't use [data-theme] for light ── */
/* Labs start light without [data-theme], so re-apply dark overrides only for dark */

/* ── Reduce motion ── */
@media (prefers-reduced-motion: reduce) {
    .ai-companion-fab__pulse { animation: none !important; }
    .ai-companion-panel { animation: none !important; }
    .ai-companion-nudge { animation: none !important; }
    .ai-companion-typing__dot { animation: none !important; opacity: 0.6; }
}
