/* ==========================================================================
   Plan B Co-Pilot — AI Assistant Design System
   Desktop Drawer & Mobile Bottom Sheet (Gemini-Style Interface)
   ========================================================================== */

/* ── Floating Mobile FAB ─────────────────────────────────────────────────── */
.copilot-fab-mobile {
    display: none;
    position: fixed;
    bottom: 24px;
    right: 20px;
    z-index: 9998;
    background: linear-gradient(135deg, #00d2ff, #7928ca);
    color: #ffffff;
    border: none;
    border-radius: 30px;
    padding: 10px 18px;
    font-size: 14px;
    font-weight: 700;
    box-shadow: 0 6px 20px rgba(121, 40, 202, 0.35);
    cursor: pointer;
    align-items: center;
    gap: 8px;
    transition: transform 0.2s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.copilot-fab-mobile:active {
    transform: scale(0.94);
}

.copilot-fab-mobile i {
    font-size: 16px;
    animation: sparkle-spin 3s ease-in-out infinite;
}

@keyframes sparkle-spin {
    0% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(15deg) scale(1.15); }
    100% { transform: rotate(0deg) scale(1); }
}

/* ── Backdrop Overlay ────────────────────────────────────────────────────── */
.copilot-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(2px);
    z-index: 10049;
    opacity: 0;
    transition: opacity 0.25s ease;
}

.copilot-backdrop.show {
    display: block;
    opacity: 1;
}

/* ── Co-Pilot Shell (Desktop Drawer) ─────────────────────────────────────── */
.copilot-drawer {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    height: 100dvh;
    max-height: 100dvh;
    background: var(--bg-surface);
    border-left: 1px solid var(--border-color);
    box-shadow: -8px 0 32px rgba(0, 0, 0, 0.15);
    z-index: 10050;
    display: flex;
    flex-direction: column;
    transform: translateX(100%);
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-sizing: border-box;
    overflow: hidden;
    color: var(--text-primary);
}

.copilot-drawer.open {
    transform: translateX(0);
}

/* Sheet drag handle (Visible on Mobile) */
.copilot-drag-handle {
    display: none;
    width: 40px;
    height: 4px;
    border-radius: 2px;
    background: var(--border-strong, #ccc);
    margin: 8px auto 2px;
    cursor: grab;
    flex-shrink: 0;
}

/* ── Header ──────────────────────────────────────────────────────────────── */
.copilot-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-surface);
    flex-shrink: 0;
    gap: 8px;
}

/* Gemini Model Selector Pill */
.copilot-model-dropdown {
    position: relative;
}

.model-pill-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    background: var(--bg-input);
    border: 1.5px solid var(--border-color);
    border-radius: 20px;
    padding: 5px 12px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

.model-pill-btn:hover {
    border-color: var(--color-primary);
    background: var(--bg-hover, rgba(0, 210, 255, 0.05));
}

.model-pill-sparkle {
    background: linear-gradient(135deg, #00d2ff, #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    font-size: 13px;
}

.model-pill-arrow {
    font-size: 10px;
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.copilot-model-dropdown.active .model-pill-arrow {
    transform: rotate(180deg);
}

/* Model Popover Dropdown Card */
.model-menu-popover {
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    width: 330px;
    max-width: 90vw;
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.25);
    padding: 8px;
    z-index: 10060;
    display: none;
    flex-direction: column;
    gap: 4px;
    animation: copilot-pop-in 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.model-menu-popover.show {
    display: flex;
}

@keyframes copilot-pop-in {
    from { opacity: 0; transform: translateY(-8px) scale(0.97); }
    to { opacity: 1; transform: translateY(0) scale(1); }
}

.model-menu-header {
    font-size: 11px;
    font-weight: 800;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    padding: 6px 8px 4px;
}

.model-option {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 10px;
    border-radius: 10px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s, border-color 0.15s;
}

.model-option:hover {
    background: var(--bg-hover, rgba(0, 0, 0, 0.04));
}

.model-option.active {
    background: rgba(0, 210, 255, 0.08);
    border-color: rgba(0, 210, 255, 0.3);
}

.model-opt-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
    flex: 1;
    min-width: 0;
}

.model-opt-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.model-opt-desc {
    font-size: 11px;
    color: var(--text-secondary);
    line-height: 1.35;
}

.model-opt-check {
    color: var(--color-primary);
    font-size: 13px;
    opacity: 0;
    margin-left: 8px;
    flex-shrink: 0;
}

.model-option.active .model-opt-check {
    opacity: 1;
}

.badge-model-new {
    background: linear-gradient(135deg, #ff007a, #7928ca);
    color: #ffffff;
    font-size: 9px;
    font-weight: 800;
    padding: 1px 6px;
    border-radius: 4px;
    letter-spacing: 0.4px;
}

.badge-model-pro {
    background: linear-gradient(135deg, #a855f7, #6366f1);
    color: #ffffff;
    font-size: 9px;
    font-weight: 800;
    padding: 1px 6px;
    border-radius: 4px;
}

.model-menu-footer {
    border-top: 1px solid var(--border-color);
    margin-top: 4px;
    padding-top: 6px;
}

.btn-refresh-models {
    width: 100%;
    background: none;
    border: none;
    padding: 8px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700;
    color: var(--color-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: background 0.15s;
    font-family: inherit;
}

.btn-refresh-models:hover {
    background: var(--bg-hover, rgba(0, 210, 255, 0.08));
}

/* Header Actions */
.copilot-header-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.btn-copilot-hdr {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
}

.btn-copilot-hdr:hover {
    color: var(--text-primary);
    border-color: var(--border-strong);
    background: var(--bg-input);
}

/* ── Context Bar ─────────────────────────────────────────────────────────── */
.copilot-context-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 16px;
    background: var(--bg-input);
    border-bottom: 1px solid var(--border-color);
    font-size: 11px;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.context-badge {
    display: flex;
    align-items: center;
    gap: 6px;
    font-weight: 700;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.context-pulse-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--color-success);
    box-shadow: 0 0 6px var(--color-success);
    flex-shrink: 0;
}

/* ── Chat Messages Container ─────────────────────────────────────────────── */
.copilot-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    -webkit-overflow-scrolling: touch;
}

.copilot-msg {
    display: flex;
    flex-direction: column;
    max-width: 88%;
    animation: msg-in 0.2s ease-out;
}

@keyframes msg-in {
    from { opacity: 0; transform: translateY(6px); }
    to { opacity: 1; transform: translateY(0); }
}

.copilot-msg.user {
    align-self: flex-end;
}

.copilot-msg.user .msg-bubble {
    background: var(--color-primary);
    color: var(--text-on-primary, #ffffff);
    border-radius: 16px 16px 4px 16px;
    padding: 10px 14px;
    font-size: 13px;
    line-height: 1.45;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.copilot-msg.bot {
    align-self: flex-start;
    max-width: 94%;
}

.copilot-msg.bot .msg-bubble {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    border-radius: 16px 16px 16px 4px;
    padding: 12px 14px;
    font-size: 13px;
    line-height: 1.5;
}

.msg-bubble code {
    font-family: Consolas, Monaco, monospace;
    font-size: 12px;
    background: rgba(0, 0, 0, 0.08);
    padding: 2px 5px;
    border-radius: 4px;
}

html[data-theme="dark"] .msg-bubble code {
    background: rgba(255, 255, 255, 0.1);
}

.msg-bubble pre {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 12px;
}

.msg-meta {
    font-size: 10px;
    color: var(--text-secondary);
    margin-top: 4px;
    padding: 0 4px;
}

/* Typing loading indicator */
.copilot-typing-dots {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 6px;
}

.copilot-typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--color-primary);
    animation: typing-bounce 1.4s infinite ease-in-out both;
}

.copilot-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.copilot-typing-dots span:nth-child(2) { animation-delay: -0.16s; }

@keyframes typing-bounce {
    0%, 80%, 100% { transform: scale(0); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* ── Action Chips Carousel ───────────────────────────────────────────────── */
.copilot-chips-carousel {
    padding: 6px 12px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 6px;
    overflow-x: auto;
    white-space: nowrap;
    scrollbar-width: none;
    flex-shrink: 0;
}

.copilot-chips-carousel::-webkit-scrollbar {
    display: none;
}

.copilot-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: 14px;
    padding: 6px 11px;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-primary);
    cursor: pointer;
    flex-shrink: 0;
    transition: all 0.15s ease;
    font-family: inherit;
    -webkit-tap-highlight-color: transparent;
}

.copilot-chip:hover {
    background: var(--color-primary);
    color: #ffffff;
    border-color: var(--color-primary);
    transform: translateY(-1px);
}

.copilot-chip:active {
    transform: scale(0.96);
}

/* ── Input Bar ───────────────────────────────────────────────────────────── */
.copilot-input-bar {
    padding: 10px 14px 16px;
    background: var(--bg-surface);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: flex-end;
    gap: 8px;
    flex-shrink: 0;
    box-sizing: border-box;
}

.copilot-input-wrap {
    flex: 1;
    display: flex;
    align-items: center;
    background: var(--bg-input);
    border: 1.5px solid var(--border-color);
    border-radius: 20px;
    padding: 4px 12px;
    transition: border-color 0.2s;
}

.copilot-input-wrap:focus-within {
    border-color: var(--color-primary);
}

.copilot-textarea {
    flex: 1;
    border: none;
    background: transparent;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 13px;
    line-height: 1.4;
    resize: none;
    max-height: 100px;
    min-height: 22px;
    outline: none;
    padding: 6px 0;
}

.btn-copilot-mic {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    padding: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s;
}

.btn-copilot-mic:hover {
    color: var(--color-primary);
}

.btn-copilot-mic.listening {
    color: #ef4444;
    animation: mic-pulse 1s infinite alternate;
}

@keyframes mic-pulse {
    from { transform: scale(1); filter: drop-shadow(0 0 2px #ef4444); }
    to { transform: scale(1.25); filter: drop-shadow(0 0 6px #ef4444); }
}

.btn-copilot-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: var(--color-primary);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    font-size: 14px;
    flex-shrink: 0;
    transition: transform 0.15s, opacity 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn-copilot-send:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.btn-copilot-send:not(:disabled):active {
    transform: scale(0.92);
}

/* ── Mobile Responsive Mode (Smartphone Bottom Sheet) ───────────────────── */
@media (max-width: 768px) {
    .copilot-fab-mobile {
        display: inline-flex;
    }

    .copilot-drawer {
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100% !important;
        max-width: 100% !important;
        border-radius: 20px 20px 0 0;
        border-left: none;
        border-top: 1px solid var(--border-color);
        box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.2);
        transform: translateY(100%);
        height: 52dvh; /* default half sheet */
        transition: transform 0.28s cubic-bezier(0.16, 1, 0.3, 1), height 0.24s cubic-bezier(0.16, 1, 0.3, 1);
    }

    .copilot-drag-handle {
        display: block;
    }

    .copilot-drawer.open {
        transform: translateY(0);
    }

    .copilot-drawer.full-sheet {
        height: 92dvh !important;
    }

    .copilot-drawer.half-sheet {
        height: 52dvh !important;
    }

    .model-menu-popover {
        position: fixed;
        bottom: 20px;
        left: 12px;
        right: 12px;
        width: auto;
        max-width: 100%;
        top: auto;
        border-radius: 18px;
        box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.35);
    }

    .copilot-input-bar {
        padding-bottom: max(16px, env(safe-area-inset-bottom));
    }
}
