/* ============================================
   VARIABLES - THEME SOMBRE
   ============================================ */
:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --secondary: #22d3ee;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #6366f1;

    /* Fonds sombres */
    --bg-main: #0f1117;
    --bg-card: #1a1d27;
    --bg-panel: #1e2130;
    --bg-sidebar: #13151f;
    --bg-input: #252836;
    --bg-hover: #2a2d3e;
    --bg-nav: #0d0f18;

    /* Textes */
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --text-heading: #f1f5f9;

    /* Bordures */
    --border: #2d3148;
    --border-light: #252840;
    --border-focus: #6366f1;

    /* Gris (compatibilité) */
    --gray-100: #1a1d27;
    --gray-200: #252836;
    --gray-300: #2d3148;
    --gray-400: #3d4166;
    --gray-500: #64748b;
    --gray-600: #94a3b8;
    --gray-700: #cbd5e1;
    --gray-800: #e2e8f0;
    --gray-900: #f1f5f9;

    --radius: 10px;
    --radius-sm: 6px;
    --radius-lg: 16px;
    --shadow: 0 4px 20px rgba(0, 0, 0, .4);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, .3);
    --transition: .2s ease;
}

/* ============================================
   BASE
   ============================================ */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', system-ui, sans-serif;
    background: var(--bg-main);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

a {
    color: var(--primary-light);
    text-decoration: none;
}

a:hover {
    color: var(--secondary);
}

h1,
h2,
h3,
h4 {
    color: var(--text-heading);
    font-weight: 600;
}

/* ============================================
   NAV
   ============================================ */
.main-nav {
    background: var(--bg-nav);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 2rem;
    height: 60px;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(10px);
}

.nav-brand {
    font-size: 1.2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary-light), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.nav-links a {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .4rem .85rem;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    color: var(--text-secondary);
    transition: var(--transition);
}

.nav-links a:hover,
.nav-links a.active {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.nav-badge {
    background: var(--primary);
    color: #fff;
    font-size: .7rem;
    padding: .1rem .4rem;
    border-radius: 20px;
    font-weight: 600;
}

/* ============================================
   LAYOUT
   ============================================ */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1.5rem;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.page-title {
    font-size: 1.5rem;
}

.page-subtitle {
    color: var(--text-muted);
    font-size: .875rem;
    margin-top: .25rem;
}

/* ============================================
   CARDS
   ============================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

.card:hover {
    border-color: var(--border-focus);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.25rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.card-title {
    font-size: 1.1rem;
    font-weight: 600;
}

/* ============================================
   BOUTONS
   ============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .6rem 1.2rem;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-dark);
    color: #fff;
}

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

.btn-secondary:hover {
    background: var(--gray-300);
}

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

.btn-success:hover {
    background: #059669;
    color: #fff;
}

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

.btn-danger:hover {
    background: #dc2626;
    color: #fff;
}

.btn-warning {
    background: var(--warning);
    color: #fff;
}

.btn-warning:hover {
    background: #d97706;
    color: #fff;
}

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

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

.btn-sm {
    padding: .35rem .75rem;
    font-size: .8rem;
}

.btn-lg {
    padding: .85rem 1.75rem;
    font-size: 1rem;
}

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

/* ============================================
   FORMULAIRES
   ============================================ */
.form-group {
    margin-bottom: 1.25rem;
}

label {
    display: block;
    font-size: .875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: .4rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
input[type="number"],
select,
textarea {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .6rem .9rem;
    font-size: .875rem;
    color: var(--text-primary);
    transition: var(--transition);
    outline: none;
    font-family: inherit;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .15);
    background: var(--bg-panel);
}

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

textarea {
    resize: vertical;
    min-height: 100px;
}

select option {
    background: var(--bg-input);
    color: var(--text-primary);
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.form-hint {
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: .3rem;
}

/* ============================================
   COLORS GRID
   ============================================ */
.colors-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: .75rem;
}

.color-item label {
    font-size: .8rem;
    margin-bottom: .3rem;
}

.color-preview {
    display: flex;
    align-items: center;
    gap: .5rem;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .4rem .6rem;
    transition: var(--transition);
}

.color-preview:focus-within {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, .15);
}

input[type="color"] {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    background: none;
    padding: 0;
}

.color-preview input[type="text"] {
    border: none;
    background: none;
    padding: 0;
    font-size: .85rem;
    font-family: monospace;
    box-shadow: none;
}

.color-preview input[type="text"]:focus {
    box-shadow: none;
    background: none;
}

/* ============================================
   ALERTS & FLASH
   ============================================ */
.alert {
    padding: .85rem 1.1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    font-size: .875rem;
    border: 1px solid transparent;
}

.alert-success {
    background: rgba(16, 185, 129, .1);
    border-color: rgba(16, 185, 129, .3);
    color: #6ee7b7;
}

.alert-error {
    background: rgba(239, 68, 68, .1);
    border-color: rgba(239, 68, 68, .3);
    color: #fca5a5;
}

.alert-info {
    background: rgba(99, 102, 241, .1);
    border-color: rgba(99, 102, 241, .3);
    color: #a5b4fc;
}

.alert-warning {
    background: rgba(245, 158, 11, .1);
    border-color: rgba(245, 158, 11, .3);
    color: #fcd34d;
}

/* ============================================
   BADGES
   ============================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: .2rem .6rem;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 600;
}

.badge-primary {
    background: rgba(99, 102, 241, .2);
    color: #a5b4fc;
}

.badge-success {
    background: rgba(16, 185, 129, .2);
    color: #6ee7b7;
}

.badge-warning {
    background: rgba(245, 158, 11, .2);
    color: #fcd34d;
}

.badge-danger {
    background: rgba(239, 68, 68, .2);
    color: #fca5a5;
}

.badge-gray {
    background: rgba(100, 116, 139, .2);
    color: #94a3b8;
}

/* ============================================
   DASHBOARD - PROJECTS GRID
   ============================================ */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.25rem;
}

.project-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.project-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--secondary));
    opacity: 0;
    transition: var(--transition);
}

.project-card:hover {
    border-color: var(--primary);
    transform: translateY(-2px);
    box-shadow: 0 8px 30px rgba(99, 102, 241, .2);
}

.project-card:hover::before {
    opacity: 1;
}

.project-card-title {
    font-size: 1.05rem;
    font-weight: 600;
    margin-bottom: .35rem;
    color: var(--text-heading);
}

.project-card-url {
    font-size: .8rem;
    color: var(--text-muted);
    margin-bottom: .75rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.project-card-meta {
    display: flex;
    align-items: center;
    gap: .5rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

.project-card-colors {
    display: flex;
    gap: .3rem;
    margin-bottom: 1rem;
}

.color-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--border);
}

.project-card-actions {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

/* ============================================
   SECTIONS PAGE - LAYOUT
   ============================================ */
.sections-layout {
    display: grid;
    grid-template-columns: 260px 1fr;
    min-height: calc(100vh - 60px);
}

.sections-sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    padding: 1.5rem;
    position: sticky;
    top: 60px;
    height: calc(100vh - 60px);
    overflow-y: auto;
}

.sections-sidebar h3 {
    font-size: .8rem;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    margin-bottom: .75rem;
}

.sidebar-section-list {
    list-style: none;
}

.sidebar-section-list li a {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .5rem .75rem;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    color: var(--text-secondary);
    transition: var(--transition);
    margin-bottom: .2rem;
}

.sidebar-section-list li a:hover,
.sidebar-section-list li a.active {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.sections-content {
    padding: 2rem;
}

/* ============================================
   SECTION CARDS
   ============================================ */
.section-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 1.5rem;
    overflow: hidden;
    transition: var(--transition);
}

.section-card:hover {
    border-color: var(--border-focus);
}

.section-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
    gap: .5rem;
}

.section-card-title {
    font-size: 1rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.section-card-body {
    padding: 1.5rem;
}

/* ============================================
   PROMPT BOX
   ============================================ */
.prompt-box {
    background: var(--bg-sidebar);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 1rem;
    font-size: .85rem;
    line-height: 1.7;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
    font-family: 'Courier New', monospace;
}

.prompt-box::-webkit-scrollbar {
    width: 4px;
}

.prompt-box::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

/* ============================================
   VIEWER
   ============================================ */
.viewer-layout {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem;
}

.viewer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: .75rem;
}

.viewer-breadcrumb {
    font-size: .875rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: .4rem;
}

.viewer-breadcrumb a {
    color: var(--primary-light);
}

.viewer-controls {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

.viewer-meta {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: .75rem;
    margin-bottom: 1.5rem;
}

.viewer-meta-item {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: .75rem 1rem;
}

.meta-label {
    font-size: .7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    display: block;
}

.meta-value {
    font-size: .9rem;
    font-weight: 600;
    color: var(--text-heading);
}

.viewer-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 1.5rem;
    overflow: hidden;
}

.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.5rem;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
}

.panel-body {
    padding: 1.5rem;
}

/* Rendu visuel IA */
.preview-content {
    font-size: .95rem;
    line-height: 1.8;
    color: var(--text-primary);
}

.preview-content h1 {
    font-size: 1.8rem;
    margin: 1.5rem 0 .75rem;
    border-bottom: 2px solid var(--primary);
    padding-bottom: .5rem;
}

.preview-content h2 {
    font-size: 1.4rem;
    margin: 1.25rem 0 .6rem;
    color: var(--primary-light);
}

.preview-content h3 {
    font-size: 1.15rem;
    margin: 1rem 0 .5rem;
    color: var(--secondary);
}

.preview-content p {
    margin-bottom: 1rem;
}

.preview-content ul,
.preview-content ol {
    margin: .75rem 0 1rem 1.5rem;
}

.preview-content li {
    margin-bottom: .35rem;
}

.preview-content strong {
    color: var(--text-heading);
    font-weight: 600;
}

.preview-content em {
    color: var(--text-secondary);
    font-style: italic;
}

.preview-content hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 1.5rem 0;
}

.preview-content blockquote {
    border-left: 3px solid var(--primary);
    padding: .75rem 1rem;
    background: var(--bg-panel);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
    margin: 1rem 0;
}

/* Zone texte brut */
#rawContent {
    background: var(--bg-sidebar);
    border-radius: var(--radius-sm);
    padding: 1rem;
    font-size: .85rem;
    line-height: 1.7;
    white-space: pre-wrap;
    color: var(--text-secondary);
    font-family: 'Courier New', monospace;
    max-height: 500px;
    overflow-y: auto;
}

.viewer-notes {
    background: rgba(245, 158, 11, .08);
    border: 1px solid rgba(245, 158, 11, .25);
    border-radius: var(--radius-sm);
    padding: 1rem 1.25rem;
    margin-bottom: 1.5rem;
}

.viewer-notes h4 {
    color: #fcd34d;
    margin-bottom: .5rem;
}

/* ============================================
   AUTH
   ============================================ */
.auth-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at 50% 0%, rgba(99, 102, 241, .15) 0%, transparent 60%), var(--bg-main);
    padding: 2rem;
}

.auth-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 420px;
    box-shadow: var(--shadow);
}

.auth-logo {
    text-align: center;
    font-size: 1.75rem;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary-light), var(--secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 1.75rem;
}

.auth-title {
    font-size: 1.3rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--text-heading);
}

.auth-footer {
    text-align: center;
    margin-top: 1.25rem;
    font-size: .875rem;
    color: var(--text-muted);
}

/* ============================================
   EMPTY STATE
   ============================================ */
.empty-state {
    text-align: center;
    padding: 3rem 2rem;
    color: var(--text-muted);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: .5;
}

.empty-state h3 {
    color: var(--text-secondary);
    margin-bottom: .5rem;
}

.empty-state p {
    font-size: .875rem;
    margin-bottom: 1.5rem;
}

/* ============================================
   STATS
   ============================================ */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.stat-icon {
    font-size: 1.75rem;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(99, 102, 241, .1);
    border-radius: var(--radius-sm);
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-heading);
}

.stat-label {
    font-size: .8rem;
    color: var(--text-muted);
}

/* ============================================
   UTILITY
   ============================================ */
.mt-1 {
    margin-top: .5rem;
}

.mt-2 {
    margin-top: 1rem;
}

.mt-3 {
    margin-top: 1.5rem;
}

.mb-1 {
    margin-bottom: .5rem;
}

.mb-2 {
    margin-bottom: 1rem;
}

.mb-3 {
    margin-bottom: 1.5rem;
}

.text-muted {
    color: var(--text-muted);
    font-size: .875rem;
}

.text-center {
    text-align: center;
}

.d-flex {
    display: flex;
}

.align-center {
    align-items: center;
}

.gap-1 {
    gap: .5rem;
}

.gap-2 {
    gap: 1rem;
}

/* ============================================
   SCROLLBAR
   ============================================ */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--gray-400);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 768px) {
    .sections-layout {
        grid-template-columns: 1fr;
    }

    .sections-sidebar {
        position: static;
        height: auto;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .form-row {
        grid-template-columns: 1fr;
    }

    .colors-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .nav-links a span:not(.nav-badge) {
        display: none;
    }

    .main-nav {
        padding: 0 1rem;
        gap: 1rem;
    }

    .projects-grid {
        grid-template-columns: 1fr;
    }

    .viewer-layout {
        padding: 1rem;
    }

    .section-card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .page-header {
        flex-direction: column;
    }

    .colors-grid {
        grid-template-columns: 1fr;
    }

    .auth-card {
        padding: 1.5rem;
    }

    .stats-row {
        grid-template-columns: 1fr;
    }
}