/* Advisor Chat - Cross-Platform Component */
/* Colors via CSS custom properties - each platform sets its own */

/* Signal dark mode to browsers and darkening tools (Noir, Dark Reader, etc.) */
#advisor-chat-panel,
#advisor-chat-btn,
.advisor-backdrop {
    color-scheme: dark;
}

:root {
    /* Defaults (stein.investments) */
    --ac-bg: #12121a;
    --ac-bg-elevated: rgba(255, 255, 255, 0.06);
    --ac-bg-hover: rgba(255, 255, 255, 0.1);
    --ac-border: rgba(255, 255, 255, 0.08);
    --ac-text: #e2e2e9;
    --ac-text-muted: rgba(255, 255, 255, 0.5);
    --ac-text-dim: rgba(255, 255, 255, 0.35);
    --ac-text-placeholder: rgba(255, 255, 255, 0.25);
    --ac-accent: rgb(44, 114, 199);
    --ac-accent-hover: rgba(44, 114, 199, 0.08);
    --ac-accent-border: rgba(44, 114, 199, 0.25);
    --ac-accent-focus: rgba(44, 114, 199, 0.5);
    --ac-user-bubble: rgb(44, 114, 199);
    --ac-radius: 12px;
    --ac-radius-lg: 16px;
    --ac-font: inherit;
}

/* REVDEN theme override */
.advisor-theme-revden {
    --ac-bg: #152535;
    --ac-bg-elevated: #1E3345;
    --ac-bg-hover: #3A5165;
    --ac-border: #2A4155;
    --ac-text: #E2E8F2;
    --ac-text-muted: rgba(226, 232, 242, 0.55);
    --ac-text-dim: rgba(226, 232, 242, 0.35);
    --ac-text-placeholder: rgba(226, 232, 242, 0.3);
    --ac-accent: #14B8A6;
    --ac-accent-hover: rgba(20, 184, 166, 0.1);
    --ac-accent-border: rgba(20, 184, 166, 0.3);
    --ac-accent-focus: rgba(20, 184, 166, 0.5);
    --ac-user-bubble: #0D9488;
    --ac-font: 'DM Sans', system-ui, sans-serif;
}

/* AlgoCheck theme override */
.advisor-theme-algocheck {
    --ac-bg: #0f1117;
    --ac-bg-elevated: #1a1c25;
    --ac-bg-hover: #252830;
    --ac-border: rgba(255, 255, 255, 0.1);
    --ac-accent: #6366f1;
    --ac-accent-hover: rgba(99, 102, 241, 0.1);
    --ac-accent-border: rgba(99, 102, 241, 0.3);
    --ac-accent-focus: rgba(99, 102, 241, 0.5);
    --ac-user-bubble: #4f46e5;
}

#advisor-chat-btn {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--ac-accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
    z-index: 9998;
    transition: transform 0.15s ease, filter 0.15s ease;
}

#advisor-chat-btn:hover {
    transform: scale(1.08);
    filter: brightness(1.12);
}

#advisor-chat-panel {
    position: fixed;
    background: var(--ac-bg);
    border: 1px solid var(--ac-border);
    display: flex;
    flex-direction: column;
    z-index: 9999;
    overflow: hidden;
    font-family: var(--ac-font);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

#advisor-chat-panel.advisor-panel-hidden {
    opacity: 0;
    transform: translateY(16px) scale(0.95);
    pointer-events: none;
}

#advisor-chat-panel.advisor-compact {
    bottom: 88px;
    right: 24px;
    width: 420px;
    max-width: calc(100vw - 32px);
    height: 580px;
    max-height: calc(100vh - 120px);
    border-radius: var(--ac-radius);
    box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
}

#advisor-chat-panel.advisor-expanded {
    top: 3vh;
    left: 3vw;
    right: 3vw;
    bottom: 3vh;
    width: auto;
    max-width: none;
    height: auto;
    max-height: none;
    border-radius: var(--ac-radius-lg);
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.7);
}

.advisor-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 9998;
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.advisor-backdrop.advisor-visible {
    opacity: 1;
    pointer-events: auto;
}

/* Header */
.advisor-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    border-bottom: 1px solid var(--ac-border);
    flex-shrink: 0;
}

.advisor-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--ac-text);
}

.advisor-header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.advisor-daily-badge,
.advisor-credit-badge {
    font-size: 12px;
    font-weight: 500;
    color: var(--ac-text-muted);
    background: var(--ac-bg-elevated);
    padding: 4px 10px;
    border-radius: 999px;
    font-variant-numeric: tabular-nums;
}

.advisor-daily-badge.advisor-at-limit {
    color: rgb(220, 120, 60);
    background: rgba(220, 120, 60, 0.12);
}

.advisor-header-btn {
    background: none;
    border: none;
    color: var(--ac-text-muted);
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: color 0.15s ease, background 0.15s ease;
}

.advisor-header-btn:hover {
    color: var(--ac-text);
    background: var(--ac-bg-elevated);
}

/* History panel */
.advisor-history {
    border-bottom: 1px solid var(--ac-border);
    max-height: 240px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--ac-border) transparent;
}

.advisor-history.advisor-hidden {
    display: none;
}

.advisor-history-list {
    display: flex;
    flex-direction: column;
}

.advisor-history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 20px;
    background: none;
    border: none;
    border-bottom: 1px solid var(--ac-border);
    cursor: pointer;
    text-align: left;
    font-family: var(--ac-font);
    color: var(--ac-text-muted);
    transition: background 0.12s ease, color 0.12s ease;
    gap: 12px;
}

.advisor-history-item:last-child {
    border-bottom: none;
}

.advisor-history-item:hover {
    background: var(--ac-bg-elevated);
    color: var(--ac-text);
}

.advisor-history-item.active {
    background: var(--ac-accent-hover);
    color: var(--ac-text);
}

.advisor-history-title {
    flex: 1;
    font-size: 13px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.advisor-history-date {
    font-size: 11px;
    color: var(--ac-text-dim);
    flex-shrink: 0;
}

.advisor-history-loading,
.advisor-history-empty {
    padding: 20px;
    text-align: center;
    font-size: 13px;
    color: var(--ac-text-dim);
}

/* Messages */
.advisor-messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    scrollbar-width: thin;
    scrollbar-color: var(--ac-border) transparent;
}

.advisor-expanded .advisor-messages {
    padding: 24px;
    gap: 16px;
}

.advisor-expanded .advisor-msg {
    max-width: 720px;
}

.advisor-expanded .advisor-msg-user {
    margin-left: auto;
}

.advisor-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.advisor-empty p {
    color: var(--ac-text-dim);
    font-size: 14px;
    line-height: 1.6;
    max-width: 300px;
    margin-bottom: 20px;
}

.advisor-prompts {
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
    max-width: 360px;
}

.advisor-expanded .advisor-prompts {
    flex-direction: row;
    flex-wrap: wrap;
    max-width: 600px;
    justify-content: center;
}

.advisor-prompt-chip {
    background: var(--ac-bg-elevated);
    border: 1px solid var(--ac-border);
    border-radius: 8px;
    padding: 11px 16px;
    font-size: 13px;
    color: var(--ac-text-muted);
    cursor: pointer;
    text-align: left;
    font-family: var(--ac-font);
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
    line-height: 1.4;
}

.advisor-expanded .advisor-prompt-chip {
    flex: 1 1 calc(50% - 4px);
    min-width: 200px;
    text-align: center;
}

.advisor-prompt-chip:hover {
    background: var(--ac-accent-hover);
    border-color: var(--ac-accent-border);
    color: var(--ac-text);
}

/* Message bubbles */
.advisor-msg {
    max-width: 85%;
}

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

.advisor-msg-assistant {
    align-self: flex-start;
}

.advisor-bubble {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.6;
    color: var(--ac-text);
    word-break: break-word;
}

.advisor-msg-user .advisor-bubble {
    background: var(--ac-user-bubble);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.advisor-msg-assistant .advisor-bubble {
    background: var(--ac-bg-elevated);
    border-bottom-left-radius: 4px;
}

.advisor-msg-assistant .advisor-bubble strong {
    color: #fff;
}

.advisor-msg-assistant .advisor-bubble code {
    background: var(--ac-bg-hover);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.advisor-msg-assistant .advisor-bubble a {
    color: var(--ac-accent);
    text-decoration: underline;
}

/* Typing indicator */
.advisor-typing {
    display: flex;
    gap: 5px;
    padding: 6px 0;
}

.advisor-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--ac-text-dim);
    animation: advisor-bounce 1.2s ease-in-out infinite;
}

.advisor-typing span:nth-child(2) { animation-delay: 0.15s; }
.advisor-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes advisor-bounce {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-6px); }
}

/* Credit opt-in */
.advisor-credit-optin {
    padding: 20px;
    background: var(--ac-bg-elevated);
    border-top: 1px solid var(--ac-border);
}

.advisor-credit-optin.advisor-hidden {
    display: none;
}

.advisor-optin-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--ac-text);
    margin: 0 0 6px 0;
}

.advisor-optin-desc {
    font-size: 14px;
    color: var(--ac-text-muted);
    margin: 0 0 14px 0;
    line-height: 1.5;
}

.advisor-optin-actions {
    display: flex;
    gap: 10px;
}

.advisor-optin-yes,
.advisor-optin-no {
    flex: 1;
    padding: 10px 14px;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--ac-font);
    border-radius: 8px;
    border: none;
    cursor: pointer;
}

.advisor-optin-yes {
    background: var(--ac-accent);
    color: #fff;
}

.advisor-optin-no {
    background: var(--ac-bg-elevated);
    color: var(--ac-text-muted);
    border: 1px solid var(--ac-border);
}

/* Input */
.advisor-input-wrap {
    display: flex;
    align-items: flex-end;
    padding: 14px 20px;
    border-top: 1px solid var(--ac-border);
    gap: 10px;
    flex-shrink: 0;
}

.advisor-expanded .advisor-input-wrap {
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
    box-sizing: border-box;
}

.advisor-input {
    flex: 1;
    background: var(--ac-bg-elevated);
    border: 1px solid var(--ac-border);
    border-radius: 10px;
    padding: 12px 14px;
    font-size: 15px;
    font-family: var(--ac-font);
    color: var(--ac-text);
    resize: none;
    outline: none;
    max-height: 140px;
    line-height: 1.45;
}

.advisor-input::placeholder {
    color: var(--ac-text-placeholder);
}

.advisor-input:focus {
    border-color: var(--ac-accent-focus);
}

.advisor-mic-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--ac-bg-elevated);
    color: var(--ac-text-muted);
    border: 1px solid var(--ac-border);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s ease;
}

.advisor-mic-btn:hover:not(:disabled) {
    color: var(--ac-accent);
    border-color: var(--ac-accent-border);
}

.advisor-mic-btn.advisor-recording {
    background: #dc2626;
    color: #fff;
    border-color: #dc2626;
    animation: advisor-pulse 1.2s ease-in-out infinite;
}

.advisor-mic-btn.advisor-transcribing {
    background: var(--ac-bg-elevated);
    color: var(--ac-accent);
    cursor: wait;
}

.advisor-mic-btn:disabled {
    cursor: wait;
}

@keyframes advisor-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(220, 38, 38, 0.5); }
    50% { box-shadow: 0 0 0 8px rgba(220, 38, 38, 0); }
}

.advisor-spin {
    animation: advisor-rotate 1s linear infinite;
}

@keyframes advisor-rotate {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.advisor-send-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--ac-accent);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: filter 0.15s ease;
}

.advisor-send-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.advisor-send-btn:not(:disabled):hover {
    filter: brightness(1.15);
}

/* Mobile: Compact = Bottom Sheet (~75% height), Expanded = fullscreen */
@media (max-width: 640px) {
    /* Compact: Bottom sheet with rounded top corners */
    #advisor-chat-panel.advisor-compact {
        top: auto;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        max-width: 100vw;
        height: 75dvh;
        max-height: 75dvh;
        border-radius: 16px 16px 0 0;
        border-bottom: none;
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* Expanded: true fullscreen, using dynamic viewport height */
    #advisor-chat-panel.advisor-expanded {
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw;
        max-width: 100vw;
        height: 100dvh;
        max-height: 100dvh;
        border-radius: 0;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }

    /* Hide expand button on mobile - bottom sheet is already the right size */
    #advisor-expand-btn {
        display: none;
    }

    /* Bigger touch targets on mobile (Apple HIG: min 44x44) */
    .advisor-header-btn {
        min-width: 36px;
        min-height: 36px;
        padding: 8px;
    }

    .advisor-header-btn svg {
        width: 18px;
        height: 18px;
    }

    .advisor-mic-btn,
    .advisor-send-btn {
        width: 44px;
        height: 44px;
    }

    /* Slightly smaller badges on mobile to save space */
    .advisor-daily-badge,
    .advisor-credit-badge {
        font-size: 11px;
        padding: 3px 8px;
    }

    /* Input area respects safe area, padding adjusted */
    .advisor-input-wrap {
        padding: 10px 14px;
    }

    /* Floating button positioned above iOS bottom bar */
    #advisor-chat-btn {
        bottom: calc(16px + env(safe-area-inset-bottom));
        right: 16px;
    }

    /* Header slimmer on mobile */
    .advisor-header {
        padding: 12px 16px;
    }

    /* Messages padding reduced on mobile */
    .advisor-messages {
        padding: 16px;
    }
}
