/* ============================================================
   HackTheJD — Chat Widget Styles
   Glassmorphic floating chat for the AI Career Agent
   ============================================================ */

/* --- Chat FAB (Floating Action Button) --- */
.chat-fab {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--gradient-primary);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 8px 32px rgba(0, 123, 255, 0.35);
    z-index: 999;
    transition: all 0.3s var(--ease-out);
    color: white;
}

.chat-fab:hover {
    transform: translateY(-3px) scale(1.05);
    box-shadow: 0 12px 40px rgba(0, 123, 255, 0.45);
}

.chat-fab:active {
    transform: translateY(0) scale(0.97);
}

.chat-fab .chat-fab-icon,
.chat-fab .chat-fab-close {
    position: absolute;
    transition: all 0.3s var(--ease-spring);
}

.chat-fab .chat-fab-close {
    opacity: 0;
    transform: rotate(-90deg) scale(0.5);
}

.chat-fab.open .chat-fab-icon {
    opacity: 0;
    transform: rotate(90deg) scale(0.5);
}

.chat-fab.open .chat-fab-close {
    opacity: 1;
    transform: rotate(0deg) scale(1);
}

/* Unread badge */
.chat-fab-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 20px;
    height: 20px;
    background: #ef4444;
    border-radius: 50%;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    display: none;
    align-items: center;
    justify-content: center;
    border: 2px solid white;
    font-family: var(--font-family);
}

.chat-fab-badge.visible {
    display: flex;
}

/* Pulsing animation when idle */
@keyframes chatPulse {
    0%, 100% { box-shadow: 0 8px 32px rgba(0, 123, 255, 0.35); }
    50% { box-shadow: 0 8px 32px rgba(0, 123, 255, 0.55), 0 0 0 8px rgba(0, 123, 255, 0.1); }
}

.chat-fab:not(.open) {
    animation: chatPulse 3s ease-in-out infinite;
}

.chat-fab:hover:not(.open) {
    animation: none;
}

/* --- Chat Window --- */
.chat-window {
    position: fixed;
    bottom: 6.5rem;
    right: 2rem;
    width: 420px;
    height: 600px;
    max-height: calc(100vh - 8rem);
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid rgba(11, 19, 43, 0.08);
    border-radius: 20px;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.12), 0 8px 24px rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    z-index: 998;
    overflow: hidden;
    
    /* Animation */
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.3s var(--ease-out), transform 0.3s var(--ease-spring);
}

.chat-window.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* --- Chat Header --- */
.chat-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    background: rgba(255, 255, 255, 0.98);
    border-bottom: 1px solid rgba(11, 19, 43, 0.06);
    flex-shrink: 0;
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 12px;
    background: var(--gradient-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.chat-avatar svg {
    color: white;
}

.chat-header-info {
    flex: 1;
    min-width: 0;
}

.chat-header-title {
    font-size: 0.95rem;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1.2;
}

.chat-header-status {
    font-size: 0.75rem;
    color: var(--accent-emerald);
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

.chat-status-dot {
    width: 6px;
    height: 6px;
    background: var(--accent-emerald);
    border-radius: 50%;
    display: inline-block;
    animation: statusPulse 2s ease-in-out infinite;
}

@keyframes statusPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.chat-header-actions {
    display: flex;
    gap: 0.25rem;
}

.chat-header-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
}

.chat-header-btn:hover {
    background: rgba(11, 19, 43, 0.05);
    color: var(--text-primary);
}

/* --- Chat Messages Area --- */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 1rem 1rem 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: rgba(11, 19, 43, 0.1);
    border-radius: 2px;
}

.chat-window ::-webkit-scrollbar-corner,
.chat-window ::-webkit-resizer {
    background: transparent;
    display: none;
}

/* Hide scrollbar gutter on the entire chat window */
.chat-window * {
    scrollbar-color: rgba(11, 19, 43, 0.1) transparent;
}

/* --- Chat Message Bubble --- */
.chat-msg {
    display: flex;
    gap: 0.5rem;
    max-width: 88%;
    animation: msgIn 0.3s var(--ease-out);
}

@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.chat-msg.user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.chat-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.7rem;
    font-weight: 700;
    margin-top: 2px;
}

.chat-msg.assistant .chat-msg-avatar {
    background: var(--gradient-primary);
    color: white;
}

.chat-msg.user .chat-msg-avatar {
    background: rgba(11, 19, 43, 0.08);
    color: var(--text-secondary);
}

.chat-msg-content {
    padding: 0.75rem 1rem;
    border-radius: 16px;
    font-size: 0.875rem;
    line-height: 1.6;
    font-family: var(--font-family);
}

.chat-msg.assistant .chat-msg-content {
    background: rgba(0, 123, 255, 0.04);
    border: 1px solid rgba(0, 123, 255, 0.08);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.chat-msg.user .chat-msg-content {
    background: var(--gradient-primary);
    color: white;
    border-bottom-right-radius: 4px;
}

/* Markdown in assistant messages */
.chat-msg.assistant .chat-msg-content p {
    margin: 0;
}

.chat-msg.assistant .chat-msg-content p + p {
    margin-top: 0.5rem;
}

.chat-msg.assistant .chat-msg-content strong {
    font-weight: 600;
    color: var(--text-primary);
}

.chat-msg.assistant .chat-msg-content code {
    background: rgba(11, 19, 43, 0.06);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.82rem;
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.chat-msg.assistant .chat-msg-content ul,
.chat-msg.assistant .chat-msg-content ol {
    margin: 0.5rem 0;
    padding-left: 1.2rem;
}

.chat-msg.assistant .chat-msg-content li {
    margin-bottom: 0.25rem;
}

/* --- Typing Indicator --- */
.chat-typing {
    display: none;
    align-items: center;
    gap: 0.5rem;
    padding: 0 1rem 0.5rem;
    background: transparent;
}

.chat-typing.visible {
    display: flex;
}

.chat-typing-dots {
    display: flex;
    gap: 4px;
    padding: 0.75rem 1rem;
    background: rgba(0, 123, 255, 0.04);
    border: 1px solid rgba(0, 123, 255, 0.08);
    border-radius: 16px;
    border-bottom-left-radius: 4px;
}

.chat-typing-dots span {
    width: 7px;
    height: 7px;
    background: rgba(0, 123, 255, 0.4);
    border-radius: 50%;
    animation: typingBounce 1.4s ease-in-out infinite;
}

.chat-typing-dots span:nth-child(2) {
    animation-delay: 0.15s;
}

.chat-typing-dots span:nth-child(3) {
    animation-delay: 0.3s;
}

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-5px); opacity: 1; }
}

/* --- Chat Welcome Message --- */
.chat-welcome {
    text-align: center;
    padding: 2rem 1.5rem;
}

.chat-welcome-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 1rem;
    background: var(--gradient-glow);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-welcome-icon svg {
    color: var(--accent-blue);
}

.chat-welcome h4 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.chat-welcome p {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.6;
    max-width: 280px;
    margin: 0 auto 1rem;
}

.chat-quick-actions {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chat-quick-btn {
    width: 100%;
    padding: 0.6rem 1rem;
    background: rgba(0, 123, 255, 0.04);
    border: 1px solid rgba(0, 123, 255, 0.1);
    border-radius: 12px;
    font-family: var(--font-family);
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--accent-blue);
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
}

.chat-quick-btn:hover {
    background: rgba(0, 123, 255, 0.08);
    border-color: rgba(0, 123, 255, 0.2);
    transform: translateX(4px);
}

/* --- Chat Input Area --- */
.chat-input-area {
    padding: 0.75rem 1rem 1rem;
    background: rgba(255, 255, 255, 0.98);
    border-top: 1px solid rgba(11, 19, 43, 0.06);
    flex-shrink: 0;
}

.chat-input-row {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
}

.chat-input {
    flex: 1;
    min-height: 40px;
    max-height: 120px;
    padding: 0.6rem 1rem;
    background: rgba(11, 19, 43, 0.03);
    border: 1px solid rgba(11, 19, 43, 0.08);
    border-radius: 14px;
    font-family: var(--font-family);
    font-size: 0.875rem;
    color: var(--text-primary);
    line-height: 1.5;
    resize: none;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    overflow-y: auto;
}

.chat-input:focus {
    border-color: rgba(0, 123, 255, 0.4);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.06);
}

.chat-input::placeholder {
    color: var(--text-dim);
    opacity: 0.7;
}

.chat-send-btn {
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 12px;
    background: var(--gradient-primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
    box-shadow: 0 4px 12px rgba(0, 123, 255, 0.25);
}

.chat-send-btn:hover:not(:disabled) {
    transform: scale(1.05);
    box-shadow: 0 6px 16px rgba(0, 123, 255, 0.35);
}

.chat-send-btn:active:not(:disabled) {
    transform: scale(0.95);
}

.chat-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    box-shadow: none;
}

.chat-input-hint {
    font-size: 0.68rem;
    color: var(--text-dim);
    text-align: center;
    margin-top: 0.4rem;
    opacity: 0.7;
}

/* --- Error State --- */
.chat-error {
    display: none;
    padding: 0.6rem 1rem;
    margin: 0 0.5rem;
    background: rgba(239, 68, 68, 0.06);
    border: 1px solid rgba(239, 68, 68, 0.15);
    border-radius: 10px;
    font-size: 0.78rem;
    color: #dc2626;
    text-align: center;
    animation: msgIn 0.3s var(--ease-out);
}

.chat-error.visible {
    display: block;
}

/* --- Function Calling: Action Cards --- */
.chat-action-status {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.85rem;
    background: rgba(0, 123, 255, 0.06);
    border: 1px solid rgba(0, 123, 255, 0.15);
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--accent-blue);
    animation: actionPulse 1.5s ease-in-out infinite;
    margin-bottom: 0.5rem;
}

@keyframes actionPulse {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 1; }
}

.chat-action-result {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.85rem;
    border-radius: 10px;
    font-size: 0.8rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
    animation: msgIn 0.3s var(--ease-out);
}

.chat-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(0, 123, 255, 0.2);
    border-radius: 50%;
    border-top-color: var(--accent-blue);
    animation: spin 1s ease-in-out infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.chat-action-result.success {
    background: rgba(16, 185, 129, 0.06);
    border: 1px solid rgba(16, 185, 129, 0.2);
    color: #059669;
}

.chat-action-result.error {
    background: rgba(239, 68, 68, 0.06);
    border: 1px solid rgba(239, 68, 68, 0.15);
    color: #dc2626;
}

.chat-download-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-blue);
    color: white;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
    border: none;
    font-size: 0.8rem;
    font-weight: 500;
    font-family: inherit;
    text-decoration: none;
    margin-top: 0.5rem;
    cursor: pointer;
    transition: background 0.2s;
}

.chat-download-btn:hover {
    background: var(--accent-blue-hover, #1d4ed8);
}

.chat-download-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* --- Mobile Responsive --- */
@media (max-width: 768px) {
    .chat-fab {
        bottom: 1.25rem;
        right: 1.25rem;
        width: 54px;
        height: 54px;
    }

    .chat-window {
        bottom: 0;
        right: 0;
        left: 0;
        width: 100%;
        height: 100%;
        max-height: 100vh;
        border-radius: 0;
    }

    .chat-window.open {
        border-radius: 0;
    }
}

@media (max-width: 480px) {
    .chat-fab {
        bottom: 1rem;
        right: 1rem;
        width: 50px;
        height: 50px;
    }
}

/* ── Chat Skeleton Loader ────────────────────────────────── */
.chat-skeleton {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    animation: chatSkeletonFadeIn 0.3s ease;
}

@keyframes chatSkeletonFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.chat-skeleton-msg {
    display: flex;
    gap: 10px;
    align-items: flex-start;
}

.chat-skeleton-msg.right {
    flex-direction: row-reverse;
}

.chat-skeleton-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    background: linear-gradient(90deg, rgba(0,0,0,0.04) 25%, rgba(0,0,0,0.08) 50%, rgba(0,0,0,0.04) 75%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s ease-in-out infinite;
}

.chat-skeleton-bubble {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
    max-width: 75%;
}

.chat-skeleton-line {
    height: 12px;
    border-radius: 6px;
    background: linear-gradient(90deg, rgba(0,0,0,0.04) 25%, rgba(0,0,0,0.08) 50%, rgba(0,0,0,0.04) 75%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.5s ease-in-out infinite;
}

.chat-skeleton-msg.right .chat-skeleton-bubble {
    align-items: flex-end;
}
