/* ==========================================================================
   LYVRE IA - CSS Global
   Design cohérent avec l'editeur et le builder, optimisé pour l'interface IA
   ========================================================================== */

/* Variables CSS pour cohérence avec l'editeur et le builder */
:root {
    /* Couleurs principales (cohérence avec l'editeur) */
    --primary: #f39c12;
    --primary-dark: #e67e22;
    --text-primary: #2c3e50;
    --text-secondary: #6c757d;
    --text-light: #adb5bd;
    
    /* Couleurs système */
    --success: #27ae60;
    --warning: #f39c12;
    --danger: #e74c3c;
    --info: #3498db;
    
    /* Couleurs fond */
    --bg-white: #ffffff;
    --bg-light: #f8f9fa;
    --bg-lighter: #e9ecef;
    --bg-dark: #343a40;
    
    /* Premium colors */
    --premium-gold: #ffd700;
    --premium-gradient: linear-gradient(135deg, #ffd700, #ffb347);
    
    /* Couleurs spécifiques IA */
    --ai-primary: #9b59b6;
    --ai-secondary: #8e44ad;
    --ai-accent: #e74c3c;
    --ai-gradient: linear-gradient(135deg, #9b59b6, #8e44ad);
    --ai-light: #f8f4ff;
    --ai-border: #e8d5f2;
    
    /* Espacements */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;
    
    /* Rayons */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;
    --radius-full: 9999px;
    
    /* Ombres */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 25px rgba(0,0,0,0.1);
    --shadow-inset: inset 0 2px 4px rgba(0,0,0,0.1);
    --shadow-ai: 0 8px 32px rgba(155, 89, 182, 0.15);
    
    /* Transitions */
    --transition: all 0.3s ease;
    --transition-fast: all 0.15s ease;
    --transition-slow: all 0.5s ease;
    
    /* Couleurs spécifiques au module IA */
    --prompt-bg: #f8f9fa;
    --prompt-border: #e9ecef;
    --generation-bg: #ffffff;
    --gallery-bg: #f8f9fa;
    --ai-toolbar-bg: #2c3e50;
    --ai-toolbar-text: #ffffff;
}

/* Reset et base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: var(--text-primary);
    background: var(--bg-white);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Layout principal du module IA */
.ia-app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background: linear-gradient(135deg, var(--bg-light) 0%, var(--ai-light) 100%);
}

/* Header IA */
.ia-header {
    background: var(--bg-white);
    border-bottom: 1px solid var(--ai-border);
    padding: var(--space-md) 0;
    box-shadow: var(--shadow-sm);
}

.ia-header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 var(--space-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.ia-logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--ai-primary);
    text-decoration: none;
}

.ia-logo-icon {
    width: 32px;
    height: 32px;
    background: var(--ai-gradient);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-weight: bold;
}

/* Container principal */
.ia-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: var(--space-xl) var(--space-md);
    flex: 1;
}

/* Section prompt */
.prompt-section {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    margin-bottom: var(--space-xl);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--ai-border);
}

.prompt-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-lg);
    color: var(--ai-primary);
    font-weight: 600;
}

.prompt-header-icon {
    width: 24px;
    height: 24px;
    background: var(--ai-gradient);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.875rem;
}

/* Formulaire de prompt */
.prompt-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.prompt-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.prompt-label {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.875rem;
}

.prompt-textarea {
    width: 100%;
    min-height: 120px;
    padding: var(--space-md);
    border: 2px solid var(--prompt-border);
    border-radius: var(--radius-md);
    font-family: inherit;
    font-size: 1rem;
    line-height: 1.5;
    resize: vertical;
    transition: var(--transition);
    background: var(--prompt-bg);
}

.prompt-textarea:focus {
    outline: none;
    border-color: var(--ai-primary);
    background: var(--bg-white);
    box-shadow: 0 0 0 3px rgba(155, 89, 182, 0.1);
}

/* Filtres de prompt */
.prompt-filters {
    display: flex;
    flex-direction: column;
    gap: var(--space-lg);
}

.filter-section {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.filter-title {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 1rem;
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.filter-title-icon {
    width: 20px;
    height: 20px;
    background: var(--ai-gradient);
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 0.75rem;
}

.filter-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: var(--space-sm);
}

.filter-card {
    background: var(--bg-light);
    border: 2px solid var(--prompt-border);
    border-radius: var(--radius-md);
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-primary);
    position: relative;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 60px;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.filter-card:hover {
    background: var(--ai-light);
    border-color: var(--ai-primary);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.filter-card.selected {
    background: var(--ai-gradient);
    border-color: var(--ai-primary);
    color: white;
    box-shadow: var(--shadow-ai);
}

.filter-card.selected::before {
    content: '✓';
    position: absolute;
    top: 4px;
    right: 8px;
    font-size: 0.75rem;
    font-weight: bold;
}

    .filter-card-icon {
        display: block;
        font-size: 1.25rem;
        margin-bottom: var(--space-xs);
    }
    
    /* Aperçu du prompt */
    .prompt-preview {
        background: var(--ai-light);
        border: 1px solid var(--ai-border);
        border-radius: var(--radius-md);
        padding: var(--space-md);
        margin-top: var(--space-sm);
    }
    
    .prompt-preview-label {
        font-size: 0.875rem;
        font-weight: 600;
        color: var(--ai-primary);
        margin-bottom: var(--space-xs);
    }
    
    .prompt-preview-text {
        font-size: 0.875rem;
        color: var(--text-primary);
        line-height: 1.4;
        font-style: italic;
    }

/* Options de génération */
.prompt-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-md);
}

.prompt-option {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.prompt-select {
    padding: var(--space-sm) var(--space-md);
    border: 2px solid var(--prompt-border);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    background: var(--bg-white);
    transition: var(--transition);
}

.prompt-select:focus {
    outline: none;
    border-color: var(--ai-primary);
    box-shadow: 0 0 0 3px rgba(155, 89, 182, 0.1);
}

/* Boutons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-md);
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    min-height: 44px;
}

.btn-primary {
    background: var(--ai-gradient);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: var(--shadow-ai);
}

.btn-secondary {
    background: var(--bg-light);
    color: var(--text-primary);
    border: 1px solid var(--prompt-border);
}

.btn-secondary:hover {
    background: var(--bg-lighter);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-success:hover {
    background: #229954;
    transform: translateY(-1px);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #c0392b;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.btn-lg {
    padding: var(--space-md) var(--space-lg);
    font-size: 1rem;
}

.btn-group {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
    align-items: center;
}

.btn-full {
    width: 100%;
    justify-content: center;
}

/* Section génération */
.generation-section {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    margin-bottom: var(--space-xl);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--ai-border);
}

.generation-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-lg);
}

.generation-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.generation-status {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.875rem;
    font-weight: 500;
}

.status-loading {
    color: var(--ai-primary);
}

.status-success {
    color: var(--success);
}

.status-error {
    color: var(--danger);
}

/* Loader */
.loader {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--ai-border);
    border-radius: 50%;
    border-top-color: var(--ai-primary);
    animation: spin 1s ease-in-out infinite;
}

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

/* Galerie d'images */
.image-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: var(--space-lg);
    margin-top: var(--space-lg);
}

.image-card {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--ai-border);
    transition: var(--transition);
}

.image-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.image-container {
    position: relative;
    aspect-ratio: 1;
    background: var(--bg-light);
    overflow: hidden;
}

.image-container img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: var(--transition);
}

.image-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--transition);
}

.image-card:hover .image-overlay {
    opacity: 1;
}

.image-actions {
    display: flex;
    gap: var(--space-sm);
}

.image-card-footer {
    padding: var(--space-md);
}

.image-info {
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-sm);
}

.image-prompt {
    font-size: 0.875rem;
    color: var(--text-primary);
    font-weight: 500;
    line-height: 1.4;
}

/* Historique */
.history-section {
    background: var(--bg-white);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--ai-border);
}

.history-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-lg);
}

.history-title {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.history-item {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    padding: var(--space-md);
    background: var(--bg-light);
    border-radius: var(--radius-md);
    border: 1px solid var(--ai-border);
    transition: var(--transition);
}

.history-item:hover {
    background: var(--ai-light);
}

.history-thumbnail {
    width: 60px;
    height: 60px;
    border-radius: var(--radius-md);
    object-fit: cover;
    flex-shrink: 0;
}

.history-content {
    flex: 1;
    min-width: 0;
}

.history-prompt {
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: var(--space-xs);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.history-meta {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.history-actions {
    display: flex;
    gap: var(--space-sm);
}

/* Messages */
.message {
    padding: var(--space-md);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-md);
    font-size: 0.875rem;
}

.message-success {
    background: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.message-error {
    background: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

.message-warning {
    background: #fff3cd;
    color: #856404;
    border: 1px solid #ffeaa7;
}

.message-info {
    background: #d1ecf1;
    color: #0c5460;
    border: 1px solid #bee5eb;
}

/* Responsive Design */
@media (max-width: 1200px) {
    .ia-container {
        max-width: 95%;
    }
    
    .filter-grid {
        grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    }
    
    .image-gallery {
        grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    }
}

@media (max-width: 992px) {
    .ia-container {
        padding: var(--space-lg);
    }
    
    .prompt-options {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-md);
    }
    
    .filter-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    }
    
    .image-gallery {
        grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    }
}

@media (max-width: 768px) {
    .ia-container {
        padding: var(--space-lg) var(--space-md);
    }
    
    .prompt-section,
    .generation-section,
    .history-section {
        padding: var(--space-lg);
    }
    
    .ia-header-content {
        flex-direction: column;
        gap: var(--space-md);
        text-align: center;
    }
    
    .ia-header h1 {
        font-size: 1.75rem;
    }
    
    .ia-header p {
        font-size: 0.95rem;
    }
    
    .prompt-options {
        grid-template-columns: 1fr;
        gap: var(--space-sm);
    }
    
    .filter-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: var(--space-xs);
    }
    
    .filter-card {
        min-height: 50px;
        padding: var(--space-xs) var(--space-sm);
        font-size: 0.8rem;
    }
    
    .filter-card-icon {
        font-size: 1rem;
    }
    
    .image-gallery {
        grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
        gap: var(--space-md);
    }
    
    .history-item {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-sm);
    }
    
    .history-thumbnail {
        width: 100%;
        height: 120px;
    }
    
    .btn {
        padding: var(--space-sm) var(--space-md);
        font-size: 0.9rem;
    }
    
    .btn-lg {
        padding: var(--space-md) var(--space-lg);
        font-size: 1rem;
    }
}

@media (max-width: 576px) {
    .ia-container {
        padding: var(--space-sm);
    }
    
    .ia-header {
        padding: var(--space-md) 0;
    }
    
    .ia-header h1 {
        font-size: 1.5rem;
    }
    
    .ia-header p {
        font-size: 0.9rem;
    }
    
    .prompt-textarea {
        min-height: 100px;
        font-size: 0.9rem;
    }
    
    .filter-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--space-xs);
    }
    
    .filter-card {
        min-height: 45px;
        padding: var(--space-xs);
        font-size: 0.75rem;
    }
    
    .filter-title {
        font-size: 0.9rem;
    }
    
    .filter-title-icon {
        width: 16px;
        height: 16px;
        font-size: 0.7rem;
    }
    
    .image-gallery {
        grid-template-columns: 1fr;
        gap: var(--space-sm);
    }
    
    .image-card {
        margin-bottom: var(--space-sm);
    }
    
    .image-container img {
        max-height: 250px;
    }
    
    .btn {
        width: 100%;
        justify-content: center;
        margin-bottom: var(--space-xs);
    }
    
    .btn-group {
        flex-direction: column;
        gap: var(--space-xs);
    }
    
    .history-item {
        padding: var(--space-sm);
    }
    
    .history-thumbnail {
        height: 100px;
    }
}

@media (max-width: 480px) {
    .ia-container {
        padding: var(--space-xs);
    }
    
    .ia-header-content {
        gap: var(--space-sm);
    }
    
    .ia-header h1 {
        font-size: 1.25rem;
    }
    
    .ia-header p {
        font-size: 0.85rem;
    }
    
    .prompt-textarea {
        min-height: 80px;
        font-size: 0.85rem;
        padding: var(--space-sm);
    }
    
    .filter-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 4px;
    }
    
    .filter-card {
        min-height: 40px;
        padding: 6px 8px;
        font-size: 0.7rem;
    }
    
    .filter-card-icon {
        font-size: 0.9rem;
    }
    
    .filter-title {
        font-size: 0.85rem;
        margin-bottom: var(--space-xs);
    }
    
    .filter-title-icon {
        width: 14px;
        height: 14px;
        font-size: 0.6rem;
    }
    
    .prompt-options {
        gap: var(--space-xs);
    }
    
    .prompt-select {
        font-size: 0.85rem;
        padding: var(--space-xs) var(--space-sm);
    }
    
    .image-container img {
        max-height: 200px;
    }
    
    .image-card-footer {
        padding: var(--space-xs);
        font-size: 0.8rem;
    }
    
    .history-item {
        padding: var(--space-xs);
        font-size: 0.8rem;
    }
    
    .history-thumbnail {
        height: 80px;
    }
}

/* Orientation landscape sur mobile */
@media (max-width: 768px) and (orientation: landscape) {
    .ia-header {
        padding: var(--space-sm) 0;
    }
    
    .ia-header h1 {
        font-size: 1.25rem;
    }
    
    .filter-grid {
        grid-template-columns: repeat(4, 1fr);
    }
    
    .prompt-options {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.fade-in {
    animation: fadeIn 0.3s ease-out;
}

/* Utilitaires */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: var(--space-xs); }
.mb-2 { margin-bottom: var(--space-sm); }
.mb-3 { margin-bottom: var(--space-md); }
.mb-4 { margin-bottom: var(--space-lg); }
.mb-5 { margin-bottom: var(--space-xl); }

.mt-0 { margin-top: 0; }
.mt-1 { margin-top: var(--space-xs); }
.mt-2 { margin-top: var(--space-sm); }
.mt-3 { margin-top: var(--space-md); }
.mt-4 { margin-top: var(--space-lg); }
.mt-5 { margin-top: var(--space-xl); }

.hidden { display: none; }
.visible { display: block; }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-center { justify-content: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: var(--space-xs); }
.gap-2 { gap: var(--space-sm); }
.gap-3 { gap: var(--space-md); }
.gap-4 { gap: var(--space-lg); }
