/* ============================================
   CV EDITOR PRO — AI Assistant Chat Widget
   Floating chat panel with provider config
   ============================================ */

/* ===== Floating Button ===== */
.ai-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: var(--text-inverse);
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    box-shadow: var(--shadow-lg);
    transition: var(--transition);
    z-index: 9000;
}
.ai-fab:hover {
    transform: scale(1.08);
    box-shadow: var(--shadow-xl);
}
.ai-fab .fa-times { display: none; }
.ai-fab.open .fa-robot { display: none; }
.ai-fab.open .fa-times { display: inline; }

/* Unread badge */
.ai-fab-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #ef4444;
    color: #fff;
    font-size: 0.65rem;
    display: none;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

/* ===== Chat Panel ===== */
.ai-panel {
    position: fixed;
    bottom: 92px;
    right: 24px;
    width: 380px;
    max-height: 560px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    display: flex;
    flex-direction: column;
    z-index: 9000;
    opacity: 0;
    transform: translateY(20px) scale(0.95);
    pointer-events: none;
    transition: opacity 0.25s ease, transform 0.25s ease;
    border: 1px solid var(--border);
}
.ai-panel.open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* Header */
.ai-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--accent);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    color: var(--text-inverse);
}
.ai-panel-header h3 {
    font-size: 0.95rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 8px;
}
.ai-panel-header-actions {
    display: flex;
    gap: 6px;
}
.ai-panel-header-actions button {
    background: rgba(255,255,255,0.15);
    border: none;
    color: var(--text-inverse);
    width: 30px;
    height: 30px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 0.8rem;
    transition: var(--transition);
}
.ai-panel-header-actions button:hover {
    background: rgba(255,255,255,0.3);
}

/* Rate limit indicator */
.ai-rate-bar {
    padding: 6px 16px;
    background: var(--bg-tertiary);
    font-size: 0.72rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--border);
}
.ai-rate-bar-fill {
    flex: 1;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}
.ai-rate-bar-fill span {
    display: block;
    height: 100%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.3s ease;
}
.ai-rate-bar-fill.warn span { background: #f59e0b; }
.ai-rate-bar-fill.danger span { background: #ef4444; }

/* Quick Actions */
.ai-quick-actions {
    padding: 10px 12px;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    border-bottom: 1px solid var(--border);
}
.ai-quick-btn {
    font-size: 0.75rem;
    padding: 5px 10px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}
.ai-quick-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-bg);
}

/* Messages Area */
.ai-messages {
    flex: 1;
    overflow-y: auto;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 180px;
    max-height: 300px;
}
.ai-msg {
    max-width: 88%;
    padding: 10px 14px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    line-height: 1.5;
    word-break: break-word;
}
.ai-msg.user {
    align-self: flex-end;
    background: var(--accent);
    color: var(--text-inverse);
    border-bottom-right-radius: 4px;
}
.ai-msg.assistant {
    align-self: flex-start;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}
.ai-msg.system {
    align-self: center;
    background: transparent;
    color: var(--text-tertiary);
    font-size: 0.78rem;
    text-align: center;
    padding: 4px 8px;
}
.ai-msg.error {
    align-self: center;
    background: #fef2f2;
    color: #dc2626;
    font-size: 0.8rem;
    border: 1px solid #fecaca;
}

/* Typing indicator */
.ai-typing {
    display: none;
    align-self: flex-start;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-md);
    border-bottom-left-radius: 4px;
    gap: 4px;
    align-items: center;
}
.ai-typing.visible { display: flex; }
.ai-typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-tertiary);
    animation: aiBounce 1.4s infinite ease-in-out;
}
.ai-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.ai-typing-dot:nth-child(3) { animation-delay: 0.4s; }
@keyframes aiBounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

/* Input Area */
.ai-input-area {
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
    align-items: flex-end;
}
.ai-input-area textarea {
    flex: 1;
    resize: none;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 8px 12px;
    font-family: var(--font-sans);
    font-size: 0.85rem;
    min-height: 38px;
    max-height: 100px;
    outline: none;
    transition: var(--transition);
    color: var(--text-primary);
    background: var(--bg-primary);
}
.ai-input-area textarea:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.ai-send-btn {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: none;
    background: var(--accent);
    color: var(--text-inverse);
    cursor: pointer;
    font-size: 0.9rem;
    transition: var(--transition);
    flex-shrink: 0;
}
.ai-send-btn:hover { background: var(--accent-dark); }
.ai-send-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ===== Settings View (inside panel) ===== */
.ai-settings {
    display: none;
    flex-direction: column;
    padding: 16px;
    gap: 14px;
    overflow-y: auto;
    max-height: 420px;
}
.ai-panel.settings-view .ai-settings { display: flex; }
.ai-panel.settings-view .ai-quick-actions,
.ai-panel.settings-view .ai-messages,
.ai-panel.settings-view .ai-typing,
.ai-panel.settings-view .ai-input-area,
.ai-panel.settings-view .ai-rate-bar { display: none; }

.ai-settings label {
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-primary);
}
.ai-settings select,
.ai-settings input[type="password"],
.ai-settings input[type="text"] {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: var(--font-sans);
    outline: none;
    transition: var(--transition);
    color: var(--text-primary);
    background: var(--bg-primary);
}
.ai-settings select:focus,
.ai-settings input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.1);
}
.ai-settings .field-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.ai-settings .field-hint {
    font-size: 0.72rem;
    color: var(--text-tertiary);
}
.ai-settings .field-hint a {
    color: var(--accent);
    text-decoration: none;
}
.ai-settings .field-hint a:hover {
    text-decoration: underline;
}
.ai-settings-save {
    padding: 10px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: var(--text-inverse);
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
}
.ai-settings-save:hover {
    background: var(--accent-dark);
}

/* Limit settings group */
.ai-limit-group {
    display: flex;
    gap: 10px;
    align-items: flex-end;
}
.ai-limit-group .field-group { flex: 1; }
.ai-limit-group input[type="number"] {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: var(--font-sans);
    outline: none;
    color: var(--text-primary);
    background: var(--bg-primary);
}

/* ===== Responsive ===== */
@media (max-width: 480px) {
    .ai-panel {
        width: calc(100vw - 24px);
        right: 12px;
        bottom: 80px;
        max-height: 70vh;
    }
    .ai-fab {
        bottom: 16px;
        right: 16px;
        width: 50px;
        height: 50px;
        font-size: 1.3rem;
    }
}
