/* ============================================
   Volt'R Chatbot Widget - LivreConnect
   Prefixe .voltr-* pour eviter conflits Bulma/Bootstrap
   ============================================ */

:root {
    --voltr-primary: #2196F3;
    --voltr-primary-dark: #1976D2;
    --voltr-primary-light: #BBDEFB;
    --voltr-bg: #ffffff;
    --voltr-bg-secondary: #f8f9fa;
    --voltr-msg-bot-bg: #f1f3f5;
    --voltr-msg-user-bg: #2196F3;
    --voltr-msg-user-color: #ffffff;
    --voltr-border: #e0e0e0;
    --voltr-text: #333333;
    --voltr-text-light: #666666;
    --voltr-radius: 12px;
    --voltr-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
    --voltr-transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Container principal */
.voltr-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    z-index: 10000;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--voltr-text);
}

/* Bouton flottant (FAB) */
.voltr-fab {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--voltr-primary), var(--voltr-primary-dark));
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(33, 150, 243, 0.4);
    transition: all var(--voltr-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.voltr-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 24px rgba(33, 150, 243, 0.5);
}

.voltr-fab img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.voltr-fab-icon {
    color: white;
    font-size: 28px;
}

.voltr-fab-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 18px;
    height: 18px;
    background: #f44336;
    border-radius: 50%;
    border: 2px solid white;
    display: none;
}

.voltr-fab.voltr-open {
    transform: rotate(90deg);
}

/* Fenetre de chat */
.voltr-window {
    position: fixed;
    bottom: 96px;
    right: 20px;
    width: 380px;
    height: 560px;
    background: var(--voltr-bg);
    border-radius: var(--voltr-radius);
    box-shadow: var(--voltr-shadow);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: voltr-slideUp 0.3s ease-out;
}

.voltr-window.voltr-visible {
    display: flex;
}

@keyframes voltr-slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Header */
.voltr-header {
    background: linear-gradient(135deg, var(--voltr-primary), var(--voltr-primary-dark));
    color: white;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.voltr-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.voltr-header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.voltr-header-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.voltr-header-info h4 {
    margin: 0;
    font-size: 14px;
    font-weight: 600;
}

.voltr-header-info span {
    font-size: 11px;
    opacity: 0.8;
}

.voltr-header-actions {
    display: flex;
    gap: 8px;
}

.voltr-header-btn {
    background: none;
    border: none;
    color: white;
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    font-size: 16px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.voltr-header-btn:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
}

/* Barre d'onglets des modes */
.voltr-tabs {
    display: flex;
    background: var(--voltr-bg-secondary);
    border-bottom: 1px solid var(--voltr-border);
    flex-shrink: 0;
    overflow-x: auto;
    scrollbar-width: none;
}

.voltr-tabs::-webkit-scrollbar {
    display: none;
}

.voltr-tab {
    flex: 1;
    padding: 8px 4px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    font-size: 11px;
    color: var(--voltr-text-light);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    transition: all 0.2s;
    position: relative;
    min-width: 0;
    white-space: nowrap;
}

.voltr-tab i {
    font-size: 14px;
}

.voltr-tab:hover:not(.voltr-tab-locked) {
    color: var(--voltr-primary);
    background: rgba(33, 150, 243, 0.05);
}

.voltr-tab.voltr-tab-active {
    color: var(--voltr-primary);
    border-bottom-color: var(--voltr-primary);
    font-weight: 600;
}

.voltr-tab.voltr-tab-locked {
    opacity: 0.4;
    cursor: not-allowed;
}

.voltr-tab-lock {
    position: absolute;
    top: 2px;
    right: 4px;
    font-size: 8px;
    color: #999;
}

/* Zone de messages */
.voltr-messages {
    flex: 1;
    padding: 12px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}

.voltr-messages::-webkit-scrollbar {
    width: 4px;
}

.voltr-messages::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 2px;
}

/* Message */
.voltr-msg {
    display: flex;
    gap: 8px;
    max-width: 85%;
    animation: voltr-fadeIn 0.3s ease-out;
}

@keyframes voltr-fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.voltr-msg-bot {
    align-self: flex-start;
}

.voltr-msg-user {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.voltr-msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: 600;
}

.voltr-msg-bot .voltr-msg-avatar {
    background: var(--voltr-primary-light);
    color: var(--voltr-primary-dark);
}

.voltr-msg-user .voltr-msg-avatar {
    background: var(--voltr-primary);
    color: white;
}

.voltr-msg-content {
    padding: 10px 14px;
    border-radius: var(--voltr-radius);
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.voltr-msg-bot .voltr-msg-content {
    background: var(--voltr-msg-bot-bg);
    border-bottom-left-radius: 4px;
}

.voltr-msg-user .voltr-msg-content {
    background: var(--voltr-msg-user-bg);
    color: var(--voltr-msg-user-color);
    border-bottom-right-radius: 4px;
}

/* Markdown dans les reponses */
.voltr-msg-content p {
    margin: 0 0 8px 0;
}

.voltr-msg-content p:last-child {
    margin-bottom: 0;
}

.voltr-msg-content strong {
    font-weight: 600;
}

.voltr-msg-content em {
    font-style: italic;
}

.voltr-msg-content ul,
.voltr-msg-content ol {
    margin: 4px 0;
    padding-left: 20px;
}

.voltr-msg-content li {
    margin-bottom: 2px;
}

.voltr-msg-content code {
    background: rgba(0, 0, 0, 0.06);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 13px;
    font-family: 'Courier New', monospace;
}

.voltr-msg-content pre {
    background: #1e1e1e;
    color: #d4d4d4;
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    margin: 6px 0;
    font-size: 12px;
}

.voltr-msg-content pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.voltr-msg-content a {
    color: var(--voltr-primary);
    text-decoration: underline;
}

.voltr-msg-user .voltr-msg-content a {
    color: white;
}

/* Indicateur de frappe */
.voltr-typing {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 0;
    align-self: flex-start;
}

.voltr-typing-dots {
    display: flex;
    gap: 4px;
    padding: 10px 14px;
    background: var(--voltr-msg-bot-bg);
    border-radius: var(--voltr-radius);
    border-bottom-left-radius: 4px;
}

.voltr-typing-dots span {
    width: 7px;
    height: 7px;
    background: #999;
    border-radius: 50%;
    animation: voltr-bounce 1.2s infinite;
}

.voltr-typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.voltr-typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes voltr-bounce {
    0%, 80%, 100% { transform: translateY(0); }
    40% { transform: translateY(-6px); }
}

/* Zone de saisie */
.voltr-input-area {
    padding: 12px;
    border-top: 1px solid var(--voltr-border);
    background: var(--voltr-bg);
    flex-shrink: 0;
}

.voltr-input-row {
    display: flex;
    gap: 8px;
    align-items: flex-end;
}

.voltr-input-field {
    flex: 1;
    resize: none;
    border: 1px solid var(--voltr-border);
    border-radius: 20px;
    padding: 8px 16px;
    font-size: 14px;
    font-family: inherit;
    outline: none;
    max-height: 100px;
    min-height: 36px;
    line-height: 1.4;
    transition: border-color 0.2s;
}

.voltr-input-field:focus {
    border-color: var(--voltr-primary);
}

.voltr-input-field::placeholder {
    color: #aaa;
}

.voltr-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--voltr-primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    flex-shrink: 0;
    transition: all 0.2s;
}

.voltr-send-btn:hover {
    background: var(--voltr-primary-dark);
    transform: scale(1.05);
}

.voltr-send-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
    transform: none;
}

/* Textarea pour analyse/redaction */
.voltr-textarea-area {
    display: none;
    padding: 12px;
    border-top: 1px solid var(--voltr-border);
    background: var(--voltr-bg);
    flex-shrink: 0;
}

.voltr-textarea-area.voltr-visible {
    display: block;
}

.voltr-textarea {
    width: 100%;
    min-height: 80px;
    max-height: 150px;
    border: 1px solid var(--voltr-border);
    border-radius: 8px;
    padding: 10px;
    font-size: 13px;
    font-family: inherit;
    resize: vertical;
    outline: none;
    margin-bottom: 8px;
}

.voltr-textarea:focus {
    border-color: var(--voltr-primary);
}

.voltr-textarea-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.voltr-action-btn {
    padding: 6px 12px;
    border: 1px solid var(--voltr-border);
    border-radius: 16px;
    background: var(--voltr-bg);
    cursor: pointer;
    font-size: 12px;
    color: var(--voltr-text);
    transition: all 0.2s;
}

.voltr-action-btn:hover {
    border-color: var(--voltr-primary);
    color: var(--voltr-primary);
    background: rgba(33, 150, 243, 0.05);
}

.voltr-action-btn.voltr-action-primary {
    background: var(--voltr-primary);
    color: white;
    border-color: var(--voltr-primary);
}

.voltr-action-btn.voltr-action-primary:hover {
    background: var(--voltr-primary-dark);
}

/* Banniere d'upgrade */
.voltr-upgrade-banner {
    padding: 16px;
    background: linear-gradient(135deg, #fff3e0, #ffe0b2);
    text-align: center;
    display: none;
}

.voltr-upgrade-banner.voltr-visible {
    display: block;
}

.voltr-upgrade-banner p {
    margin: 0 0 8px;
    font-size: 13px;
    color: #e65100;
}

.voltr-upgrade-btn {
    padding: 6px 16px;
    background: #ff9800;
    color: white;
    border: none;
    border-radius: 16px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: background 0.2s;
}

.voltr-upgrade-btn:hover {
    background: #f57c00;
}

/* Message rate limit avec Plumes CTA */
.voltr-rate-limit-msg {
    background: linear-gradient(135deg, #fef3f2, #fef9f0);
    border: 1px solid #fecaca;
    border-radius: 10px;
    padding: 14px;
    margin: -4px;
}

.voltr-rl-header {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #dc2626;
    font-size: 14px;
    margin-bottom: 6px;
}

.voltr-rl-header i {
    font-size: 16px;
}

.voltr-rl-desc {
    font-size: 13px;
    color: #555;
    margin: 0 0 10px;
    line-height: 1.4;
}

.voltr-rl-plumes {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
    font-size: 12px;
    color: #92400e;
    line-height: 1.4;
}

.voltr-rl-plumes i {
    color: #d97706;
    font-size: 14px;
    margin-top: 1px;
    flex-shrink: 0;
}

.voltr-rl-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.voltr-rl-btn {
    padding: 7px 14px;
    border-radius: 8px;
    border: none;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: all 0.2s;
    flex: 1;
    justify-content: center;
    min-width: 0;
}

.voltr-rl-btn-primary {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    box-shadow: 0 2px 8px rgba(217, 119, 6, 0.3);
}
.voltr-rl-btn-primary:hover {
    background: linear-gradient(135deg, #d97706, #b45309);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(217, 119, 6, 0.4);
}

.voltr-rl-btn-secondary {
    background: #f3f4f6;
    color: #374151;
    border: 1px solid #d1d5db;
}
.voltr-rl-btn-secondary:hover {
    background: #e5e7eb;
}

/* Section boost avec Plumes */
.voltr-rl-boost-section {
    background: #f0fdf4;
    border: 1px solid #bbf7d0;
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 12px;
}

.voltr-rl-boost-title {
    font-size: 12px;
    font-weight: 700;
    color: #166534;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.voltr-rl-boost-title i {
    color: #f59e0b;
}

.voltr-rl-balance {
    font-weight: 400;
    color: #6b7280;
    font-size: 11px;
}

.voltr-rl-boost-options {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.voltr-boost-btn {
    flex: 1;
    min-width: 80px;
    padding: 8px 6px;
    border-radius: 8px;
    border: 2px solid #86efac;
    background: white;
    cursor: pointer;
    text-align: center;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.voltr-boost-btn:hover {
    border-color: #22c55e;
    background: #f0fdf4;
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(34, 197, 94, 0.2);
}

.voltr-boost-tokens {
    font-size: 12px;
    font-weight: 700;
    color: #166534;
}

.voltr-boost-cost {
    font-size: 10px;
    color: #d97706;
    font-weight: 600;
}

.voltr-boost-cost i {
    font-size: 9px;
}

.voltr-boost-disabled {
    opacity: 0.4;
    cursor: not-allowed;
    border-color: #d1d5db;
}
.voltr-boost-disabled:hover {
    transform: none;
    box-shadow: none;
    background: white;
    border-color: #d1d5db;
}

.voltr-boost-loading {
    opacity: 0.7;
    border-color: #22c55e;
    background: #f0fdf4;
}
.voltr-boost-loading .voltr-boost-tokens {
    color: #6b7280;
}

/* Etat succes apres recharge */
.voltr-rl-success {
    background: linear-gradient(135deg, #f0fdf4, #ecfdf5) !important;
    border-color: #86efac !important;
}
.voltr-rl-success .voltr-rl-desc {
    color: #166534;
}

/* Boutons d'action contextuels dans les reponses */
.voltr-action-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 8px 0 4px;
    padding: 8px 16px;
    background: linear-gradient(135deg, #6366f1, #4f46e5);
    color: #fff !important;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    text-decoration: none !important;
    transition: all 0.2s;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}
.voltr-action-btn:hover {
    background: linear-gradient(135deg, #4f46e5, #4338ca);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.4);
    color: #fff !important;
}
.voltr-action-btn i {
    font-size: 12px;
}

/* Message systeme (bienvenue, erreur) */
.voltr-system-msg {
    text-align: center;
    padding: 8px 16px;
    font-size: 12px;
    color: var(--voltr-text-light);
    font-style: italic;
}

/* Panneau historique */
.voltr-history-panel {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--voltr-bg);
    z-index: 10;
    display: none;
    flex-direction: column;
}

.voltr-history-panel.voltr-visible {
    display: flex;
}

.voltr-history-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--voltr-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.voltr-history-header h4 {
    margin: 0;
    font-size: 14px;
}

.voltr-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.voltr-history-item {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 4px;
    transition: background 0.2s;
}

.voltr-history-item:hover {
    background: var(--voltr-bg-secondary);
}

.voltr-history-item-title {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.voltr-history-item-meta {
    font-size: 11px;
    color: var(--voltr-text-light);
    margin-top: 2px;
}

.voltr-history-empty {
    padding: 20px;
    text-align: center;
    color: var(--voltr-text-light);
    font-size: 13px;
}

/* ============================================
   File Upload - Bouton trombone & zone de drop
   ============================================ */

.voltr-attach-btn {
    width: 32px;
    height: 32px;
    min-width: 32px;
    border-radius: 50%;
    background: none;
    border: 1px solid #ddd;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 15px;
    color: #999;
    flex-shrink: 0;
    transition: all 0.2s;
    padding: 0;
}

.voltr-attach-btn:hover {
    border-color: #2196F3;
    color: #2196F3;
    background: rgba(33, 150, 243, 0.05);
}

/* Zone de drop (modes textarea) */
.voltr-file-dropzone {
    border: 2px dashed #ddd;
    border-radius: 8px;
    padding: 14px 12px;
    text-align: center;
    color: #999;
    font-size: 12px;
    margin-bottom: 8px;
    transition: all 0.2s;
    cursor: pointer;
}

.voltr-file-dropzone i {
    font-size: 22px;
    display: block;
    margin-bottom: 4px;
    color: #90caf9;
}

.voltr-file-dropzone.voltr-drag-over {
    border-color: #2196F3;
    background: rgba(33, 150, 243, 0.05);
    color: #2196F3;
}

.voltr-file-dropzone small {
    display: block;
    margin-top: 4px;
    color: #aaa;
    font-size: 10px;
}

.voltr-file-browse {
    color: #2196F3;
    cursor: pointer;
    text-decoration: underline;
}

/* Liste des fichiers en attente */
.voltr-file-list {
    max-height: 100px;
    overflow-y: auto;
    margin-bottom: 6px;
    padding: 4px;
    background: #f8f9fa;
    border-radius: 6px;
    border: 1px solid #eee;
}

.voltr-file-item {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 3px 6px;
    font-size: 11px;
    border-radius: 4px;
}

.voltr-file-item:hover {
    background: rgba(0, 0, 0, 0.03);
}

.voltr-file-item i {
    color: #2196F3;
    font-size: 13px;
    flex-shrink: 0;
}

.voltr-file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.voltr-file-size {
    color: #999;
    font-size: 10px;
    flex-shrink: 0;
}

.voltr-file-remove {
    background: none;
    border: none;
    cursor: pointer;
    color: #999;
    padding: 2px 4px;
    font-size: 10px;
    border-radius: 3px;
    line-height: 1;
}

.voltr-file-remove:hover {
    color: #f44336;
    background: rgba(244, 67, 54, 0.1);
}

/* Badges fichiers dans les messages utilisateur */
.voltr-msg-files {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
}

.voltr-msg-file {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 10px;
}

.voltr-msg-user .voltr-msg-file {
    background: rgba(255, 255, 255, 0.2);
}

.voltr-msg-bot .voltr-msg-file {
    background: rgba(0, 0, 0, 0.05);
}

/* Upload en cours */
.voltr-upload-progress {
    font-size: 11px;
    color: #2196F3;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.voltr-upload-progress .fa-spinner {
    animation: fa-spin 1s linear infinite;
}

/* Responsive - Plein ecran mobile */
@media (max-width: 576px) {
    .voltr-window {
        bottom: 0;
        right: 0;
        left: 0;
        top: 0;
        width: 100%;
        height: 100%;
        border-radius: 0;
    }

    .voltr-fab {
        width: 56px;
        height: 56px;
        bottom: 16px;
        right: 16px;
    }
}
