/**
 * FastPress - Styles
 * Design System moderne et responsive
 */

/* ============================================
   Variables CSS (Design Tokens)
   ============================================ */
:root {
    /* Couleurs principales */
    --color-primary: #6366f1;
    --color-primary-hover: #4f46e5;
    --color-primary-light: rgba(99, 102, 241, 0.1);

    /* Couleurs secondaires */
    --color-secondary: #64748b;
    --color-secondary-hover: #475569;

    /* Couleurs d'état */
    --color-success: #10b981;
    --color-success-light: rgba(16, 185, 129, 0.1);
    --color-error: #ef4444;
    --color-error-light: rgba(239, 68, 68, 0.1);
    --color-warning: #f59e0b;
    --color-info: #3b82f6;

    /* Fond et surfaces */
    --color-bg: #0f172a;
    --color-bg-elevated: #1e293b;
    --color-bg-card: #1e293b;
    --color-bg-input: #0f172a;

    /* Texte */
    --color-text: #f1f5f9;
    --color-text-muted: #94a3b8;
    --color-text-placeholder: #64748b;

    /* Bordures */
    --color-border: #334155;
    --color-border-focus: #6366f1;

    /* Typographie */
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-size-xs: 0.75rem;
    --font-size-sm: 0.875rem;
    --font-size-base: 1rem;
    --font-size-lg: 1.125rem;
    --font-size-xl: 1.25rem;
    --font-size-2xl: 1.5rem;
    --font-size-3xl: 2rem;

    /* Espacements */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.25rem;
    --space-6: 1.5rem;
    --space-8: 2rem;
    --space-10: 2.5rem;
    --space-12: 3rem;

    /* Rayons */
    --radius-sm: 0.375rem;
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --radius-full: 9999px;

    /* Ombres */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.3), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.3), 0 4px 6px -4px rgba(0, 0, 0, 0.3);
    --shadow-glow: 0 0 20px rgba(99, 102, 241, 0.3);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 350ms ease;
}

/* ============================================
   Reset et Base
   ============================================ */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

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

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1.6;
    color: var(--color-text);
    background: var(--color-bg);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================================
   Layout Principal
   ============================================ */
.app-container {
    max-width: 800px;
    margin: 0 auto;
    padding: var(--space-4) var(--space-4) var(--space-8);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--space-6);
}

/* ============================================
   Header Actions
   ============================================ */
.header {
    display: flex;
    flex-direction: column;
    align-items: center;
    /* Relative pour le positionnement absolu si besoin */
    position: relative;
    padding: var(--space-8) 0 var(--space-6);
}

.header__title {
    font-size: var(--font-size-3xl);
    font-weight: 700;
    background: linear-gradient(135deg, var(--color-primary), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: var(--space-2);
}

.header__subtitle {
    font-size: var(--font-size-lg);
    color: var(--color-text-muted);
    font-weight: 400;
}

.header__actions {
    position: absolute;
    right: 0;
    top: var(--space-8);
}

.btn--ghost {
    background: transparent;
    border: 1px solid transparent;
    color: var(--color-text-muted);
}

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

/* ============================================
   Sidebar (Historique)
   ============================================ */
.sidebar {
    position: fixed;
    top: 0;
    right: -400px;
    /* Caché par défaut */
    width: 350px;
    height: 100vh;
    background: var(--color-bg-card);
    border-left: 1px solid var(--color-border);
    z-index: 2000;
    transition: right var(--transition-normal);
    display: flex;
    flex-direction: column;
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.5);
}

.sidebar.open {
    right: 0;
}

.sidebar__header {
    padding: var(--space-4);
    border-bottom: 1px solid var(--color-border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar__title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--color-text);
}

.sidebar__content {
    flex: 1;
    overflow-y: auto;
    padding: var(--space-4);
}

.sidebar__empty {
    text-align: center;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    margin-top: var(--space-8);
}

.history-item {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    padding: var(--space-3);
    margin-bottom: var(--space-3);
    /* cursor: pointer; géré sur content maintenant */
    transition: all var(--transition-fast);
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: var(--space-2);
}

.history-item:hover {
    border-color: var(--color-primary);
    transform: translateX(-2px);
}

.history-item__content {
    flex: 1;
    cursor: pointer;
}

.history-item__title {
    font-weight: 600;
    font-size: var(--font-size-sm);
    color: var(--color-text);
    margin-bottom: var(--space-1);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.history-item__meta {
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    display: flex;
    justify-content: space-between;
}

.sidebar-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1500;
    opacity: 0;
    visibility: hidden;
    transition: all var(--transition-normal);
    backdrop-filter: blur(2px);
}

.sidebar-overlay.open {
    opacity: 1;
    visibility: visible;
}

/* ============================================
   Cards
   ============================================ */
.card {
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-xl);
    padding: var(--space-6);
    transition: border-color var(--transition-normal), box-shadow var(--transition-normal);
}

.card:hover {
    border-color: rgba(99, 102, 241, 0.3);
}

.card__header {
    margin-bottom: var(--space-4);
}

.card__title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: var(--space-4);
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.card__hint {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    display: block;
    margin-top: var(--space-1);
}

.card--result {
    background: linear-gradient(135deg, var(--color-bg-card), rgba(99, 102, 241, 0.05));
    border-color: var(--color-primary);
}

/* ============================================
   Formulaires
   ============================================ */
.form-group {
    margin-bottom: var(--space-4);
}

.form-group:last-child {
    margin-bottom: 0;
}

.form-group--inline {
    margin-bottom: var(--space-3);
}

.form-label {
    display: block;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text);
    margin-bottom: var(--space-2);
}

.form-label .optional {
    color: var(--color-text-muted);
    font-weight: 400;
}

.input-group {
    display: flex;
    gap: var(--space-2);
}

.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: var(--space-3) var(--space-4);
    font-family: inherit;
    font-size: var(--font-size-base);
    color: var(--color-text);
    background: var(--color-bg-input);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    outline: none;
    border-color: var(--color-border-focus);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-input::placeholder,
.form-textarea::placeholder {
    color: var(--color-text-placeholder);
}

.form-select {
    cursor: pointer;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 24 24' stroke='%2394a3b8'%3E%3Cpath stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M19 9l-7 7-7-7'%3E%3C/path%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right var(--space-3) center;
    background-size: 1.25rem;
    padding-right: var(--space-10);
}

.form-textarea {
    resize: vertical;
    min-height: 120px;
}

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

.char-counter {
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
}

.char-counter--warning {
    color: var(--color-warning);
    font-weight: 500;
}

/* ============================================
   Boutons
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-2);
    padding: var(--space-3) var(--space-5);
    font-family: inherit;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--color-text);
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
}

.btn:hover:not(:disabled) {
    background: var(--color-secondary);
    border-color: var(--color-secondary);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

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

.btn--primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
}

.btn--secondary {
    background: transparent;
    border-color: var(--color-border);
}

.btn--secondary:hover:not(:disabled) {
    background: var(--color-bg-elevated);
    border-color: var(--color-text-muted);
}

.btn--icon {
    padding: var(--space-3);
    min-width: 44px;
}

.btn--danger {
    color: var(--color-error);
    border-color: transparent;
    background: transparent;
}

.btn--danger:hover:not(:disabled) {
    background: var(--color-error-light);
    border-color: transparent;
}

.btn--full {
    width: 100%;
}

.btn--sm {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-xs);
}

.btn--generate {
    width: 100%;
    padding: var(--space-4) var(--space-6);
    font-size: var(--font-size-lg);
    font-weight: 600;
    background: linear-gradient(135deg, var(--color-primary), #a855f7);
    border: none;
    border-radius: var(--radius-lg);
    color: white;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

.btn--generate:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg), 0 0 30px rgba(99, 102, 241, 0.4);
}

.btn--generate:active:not(:disabled) {
    transform: translateY(0);
}

.generate-wrapper {
    padding: var(--space-2) 0;
}

/* ============================================
   Backlinks
   ============================================ */
.backlink-item {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    padding: var(--space-4);
    margin-bottom: var(--space-4);
    animation: slideIn var(--transition-normal);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

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

.backlink-label {
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-primary);
}

.backlink-fields {
    display: grid;
    gap: var(--space-2);
}

/* ============================================
   Badges
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--space-1) var(--space-2);
    font-size: var(--font-size-xs);
    font-weight: 500;
    background: var(--color-primary-light);
    color: var(--color-primary);
    border-radius: var(--radius-full);
}

.status-badge {
    display: inline-flex;
    align-items: center;
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-size-sm);
    border-radius: var(--radius-md);
    margin-top: var(--space-3);
}

.status-badge--hidden {
    display: none;
}

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

.status-badge--error {
    background: var(--color-error-light);
    color: var(--color-error);
}

/* ============================================
   Zone de Résultat avec Quill
   ============================================ */
.result-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
}

.result-header .card__title {
    margin-bottom: 0;
}

.result-actions {
    display: flex;
    gap: var(--space-2);
    flex-wrap: wrap;
}

#editor-container {
    background: var(--color-bg);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

/* Quill Theme Override - Dark Mode */
.ql-toolbar.ql-snow {
    background: var(--color-bg-elevated);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding: var(--space-2) var(--space-3);
}

.ql-toolbar.ql-snow .ql-stroke {
    stroke: var(--color-text-muted);
}

.ql-toolbar.ql-snow .ql-fill {
    fill: var(--color-text-muted);
}

.ql-toolbar.ql-snow .ql-picker {
    color: var(--color-text-muted);
}

.ql-toolbar.ql-snow .ql-picker-options {
    background: var(--color-bg-elevated);
    border-color: var(--color-border);
}

.ql-toolbar.ql-snow .ql-picker-item:hover {
    color: var(--color-primary);
}

.ql-toolbar.ql-snow button:hover .ql-stroke,
.ql-toolbar.ql-snow button.ql-active .ql-stroke {
    stroke: var(--color-primary);
}

.ql-toolbar.ql-snow button:hover .ql-fill,
.ql-toolbar.ql-snow button.ql-active .ql-fill {
    fill: var(--color-primary);
}

.ql-container.ql-snow {
    border: 1px solid var(--color-border);
    border-top: none;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
    font-family: var(--font-family);
    font-size: var(--font-size-base);
}

.ql-editor {
    min-height: 250px;
    max-height: 500px;
    overflow-y: auto;
    color: var(--color-text);
    line-height: 1.8;
    padding: var(--space-4);
}

.ql-editor.ql-blank::before {
    color: var(--color-text-placeholder);
    font-style: normal;
}

.ql-editor h1 {
    font-size: var(--font-size-2xl);
    font-weight: 700;
    margin-bottom: var(--space-4);
    color: var(--color-text);
}

.ql-editor h2 {
    font-size: var(--font-size-xl);
    font-weight: 600;
    margin-top: var(--space-6);
    margin-bottom: var(--space-3);
    color: var(--color-text);
}

.ql-editor h3 {
    font-size: var(--font-size-lg);
    font-weight: 600;
    margin-top: var(--space-4);
    margin-bottom: var(--space-2);
    color: var(--color-text);
}

.ql-editor p {
    margin-bottom: var(--space-4);
}

.ql-editor ul,
.ql-editor ol {
    margin-bottom: var(--space-4);
    padding-left: var(--space-6);
}

.ql-editor li {
    margin-bottom: var(--space-2);
}

.ql-editor a {
    color: var(--color-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.ql-editor a:hover {
    color: var(--color-primary-hover);
}

.ql-editor:focus {
    outline: none;
}

/* Legacy result-area (keep for fallback) */
.result-area {
    min-height: 200px;
    max-height: 500px;
    overflow-y: auto;
    padding: var(--space-4);
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-base);
    line-height: 1.8;
    color: var(--color-text);
}

.result-area:focus {
    outline: none;
    border-color: var(--color-border-focus);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.result-area:empty::before {
    content: attr(data-placeholder);
    color: var(--color-text-placeholder);
}

.result-area a {
    color: var(--color-primary);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.result-area a:hover {
    color: var(--color-primary-hover);
}

/* ============================================
   Spinner de Chargement
   ============================================ */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.btn__loader {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

/* ============================================
   Toast Notifications
   ============================================ */
.toast-container {
    position: fixed;
    bottom: var(--space-6);
    right: var(--space-6);
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.toast {
    padding: var(--space-3) var(--space-5);
    border-radius: var(--radius-lg);
    font-size: var(--font-size-sm);
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    transform: translateX(100%);
    opacity: 0;
    transition: all var(--transition-normal);
}

.toast--visible {
    transform: translateX(0);
    opacity: 1;
}

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

.toast--error {
    background: var(--color-error);
    color: white;
}

.toast--info {
    background: var(--color-info);
    color: white;
}

/* ============================================
   Footer
   ============================================ */
.footer {
    text-align: center;
    padding: var(--space-8) 0 var(--space-4);
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
}

/* ============================================
   Utilitaires
   ============================================ */
.hidden {
    display: none !important;
}

/* ============================================
   Responsive Design
   ============================================ */
@media (max-width: 640px) {
    .header__actions {
        position: static;
        margin-top: var(--space-4);
    }

    .sidebar {
        width: 100%;
        /* Pleine largeur sur mobile */
        right: -100%;
    }

    .app-container {
        padding: var(--space-3) var(--space-3) var(--space-6);
    }

    .header {
        padding: var(--space-6) 0 var(--space-4);
    }

    .header__title {
        font-size: var(--font-size-2xl);
    }

    .card {
        padding: var(--space-4);
        border-radius: var(--radius-lg);
    }

    .input-group {
        flex-direction: column;
    }

    .input-group .btn {
        width: 100%;
    }

    .result-actions {
        flex-direction: column;
    }

    .result-actions .btn {
        width: 100%;
    }

    .toast-container {
        left: var(--space-4);
        right: var(--space-4);
        bottom: var(--space-4);
    }

    .toast {
        transform: translateY(100%);
    }

    .toast--visible {
        transform: translateY(0);
    }
}

/* ============================================
   Accessibilité
   ============================================ */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus visible pour navigation clavier */
:focus-visible {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
}

/* Scrollbar personnalisée */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--color-bg);
}

::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: var(--radius-full);
}

/* ============================================
   SEO Tools (Phase 2)
   ============================================ */
.seo-tools {
    margin-top: var(--space-6);
    padding-top: var(--space-6);
    border-top: 1px solid var(--color-border);
    animation: fadeIn var(--transition-normal);
}

.seo-tools__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--space-4);
}

.seo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: var(--space-4);
    margin-top: var(--space-4);
    animation: slideIn var(--transition-normal);
}

.seo-card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

.seo-card__header {
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-elevated);
    border-bottom: 1px solid var(--color-border);
    font-size: var(--font-size-sm);
    font-weight: 600;
    color: var(--color-text-muted);
    display: flex;
    justify-content: space-between;
    align-items: center;
    align-items: center;
}

.word-counter {
    text-align: right;
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    margin-top: var(--space-2);
    font-variant-numeric: tabular-nums;
}


.seo-card__content {
    padding: var(--space-4);
    font-size: var(--font-size-sm);
    color: var(--color-text);
    word-break: break-word;
    /* Pour les URL longues */
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.seo-card__content ul {
    list-style: none;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2);
}

.seo-card__tag {
    background: var(--color-bg-elevated);
    color: var(--color-primary);
    padding: var(--space-1) var(--space-2);
    border-radius: var(--radius-sm);
    font-size: var(--font-size-xs);
    border: 1px solid var(--color-border);
}

.seo-copy-btn {
    background: transparent;
    border: none;
    color: var(--color-primary);
    cursor: pointer;
    font-size: var(--font-size-xs);
    font-weight: 500;
    transition: color var(--transition-fast);
}

.seo-copy-btn:hover {
    color: var(--color-primary-hover);
    text-decoration: underline;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--color-text-muted);
}

/* ============================================
   FAQ Module (Phase 3)
   ============================================ */
.faq-container {
    margin-top: var(--space-4);
    animation: fadeIn var(--transition-normal);
}

.faq-actions {
    display: flex;
    gap: var(--space-3);
    margin-bottom: var(--space-4);
    justify-content: flex-end;
}

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

.faq-item {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    overflow: hidden;
}

.faq-question {
    padding: var(--space-3) var(--space-4);
    background: var(--color-bg-elevated);
    font-weight: 600;
    font-size: var(--font-size-sm);
    color: var(--color-text);
    border-bottom: 1px solid var(--color-border);
}

.faq-answer {
    padding: var(--space-3) var(--space-4);
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    line-height: 1.5;
}

.faq-answer p:last-child {
    margin-bottom: 0;
}