/* ============================================
   Outils MP2I - Plateforme d'outils
   ============================================ */

/* --- Variables CSS --- */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --secondary: #64748b;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --info: #0891b2;
    --info-light: #cffafe;
    --purple: #7c3aed;
    --purple-light: #ede9fe;

    --gray-50: #f8fafc;
    --gray-100: #f1f5f9;
    --gray-200: #e2e8f0;
    --gray-300: #cbd5e1;
    --gray-400: #94a3b8;
    --gray-500: #64748b;
    --gray-600: #475569;
    --gray-700: #334155;
    --gray-800: #1e293b;
    --gray-900: #0f172a;

    --sidebar-width: 260px;
    --sidebar-collapsed: 0px;
    --topbar-height: 60px;
    --radius: 8px;
    --radius-lg: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
    --transition: all 0.2s ease;

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

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

html { font-size: 14px; }

body {
    font-family: var(--font-family);
    color: var(--gray-800);
    background: var(--gray-50);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

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

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

code { background: var(--gray-100); padding: 2px 6px; border-radius: 4px; font-size: 0.85rem; }

.h-full { height: 100%; }

/* --- Login Page --- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 50%, #1e40af 100%);
    padding: 1rem;
}

.login-container { width: 100%; max-width: 420px; }

.login-card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
}

.login-header { text-align: center; margin-bottom: 2rem; }

.login-logo {
    width: 60px; height: 60px;
    background: var(--primary);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 1rem;
    font-size: 1.5rem; color: white;
}

.login-header h1 { font-size: 1.5rem; margin-bottom: 0.25rem; }
.login-header p { color: var(--gray-500); font-size: 0.9rem; }

.login-form { display: flex; flex-direction: column; gap: 1.25rem; }

.login-footer { text-align: center; margin-top: 2rem; color: var(--gray-400); font-size: 0.8rem; }

.password-wrapper { position: relative; }
.password-wrapper .form-input { padding-right: 3rem; }
.password-toggle {
    position: absolute; right: 10px; top: 50%; transform: translateY(-50%);
    background: none; border: none; cursor: pointer;
    color: var(--gray-400); font-size: 1.1rem;
}

/* --- App Layout --- */
.app-layout { display: flex; min-height: 100vh; }

/* --- Sidebar --- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--gray-900);
    color: white;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform 0.3s ease;
}

.sidebar-header {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.sidebar-brand {
    display: flex; align-items: center; gap: 0.75rem;
    color: white; font-size: 1.15rem; font-weight: 700;
    text-decoration: none;
}

.sidebar-brand i { font-size: 1.4rem; color: var(--primary); }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 1rem 0; }

.nav-section { margin-bottom: 1.5rem; }

.nav-section-title {
    display: block;
    padding: 0 1.5rem;
    margin-bottom: 0.5rem;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
}

.nav-link {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.6rem 1.5rem;
    color: var(--gray-400);
    transition: var(--transition);
    font-size: 0.9rem;
    border-left: 3px solid transparent;
}

.nav-link:hover {
    color: white;
    background: rgba(255,255,255,0.05);
}

.nav-link.active {
    color: white;
    background: rgba(37,99,235,0.15);
    border-left-color: var(--primary);
}

.nav-link i { font-size: 1.1rem; width: 20px; text-align: center; }

.sidebar-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,0.1);
    text-align: center;
}

.version { font-size: 0.75rem; color: var(--gray-600); }

/* --- Main Content --- */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    transition: margin-left 0.3s ease;
}

/* --- Top Bar --- */
.top-bar {
    height: var(--topbar-height);
    background: white;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    position: sticky;
    top: 0;
    z-index: 50;
}

.sidebar-toggle {
    display: none;
    background: none; border: none;
    font-size: 1.4rem; cursor: pointer;
    color: var(--gray-600);
}

.top-bar-right { display: flex; align-items: center; gap: 0.75rem; }

.user-name { font-weight: 500; display: flex; align-items: center; gap: 0.5rem; }
.user-name i { color: var(--gray-400); }

/* --- Content Area --- */
.content-area {
    flex: 1;
    padding: 2rem;
    max-width: 1400px;
    width: 100%;
}

/* --- Page Header --- */
.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 2rem;
    gap: 1rem;
}

.page-header h1 {
    font-size: 1.5rem;
    display: flex; align-items: center; gap: 0.5rem;
}

.page-header h1 i { color: var(--primary); }

/* --- Cards --- */
.card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
}

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

.card-header h2 {
    font-size: 1rem;
    display: flex; align-items: center; gap: 0.5rem;
}

.card-body { padding: 1.5rem; }

/* --- Stats Grid --- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    box-shadow: var(--shadow);
    transition: var(--transition);
}

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

.stat-icon {
    width: 50px; height: 50px;
    border-radius: var(--radius);
    display: flex; align-items: center; justify-content: center;
    font-size: 1.3rem;
}

.stat-card-blue .stat-icon { background: var(--primary-light); color: var(--primary); }
.stat-card-orange .stat-icon { background: var(--warning-light); color: var(--warning); }
.stat-card-green .stat-icon { background: var(--success-light); color: var(--success); }
.stat-card-purple .stat-icon { background: var(--purple-light); color: var(--purple); }

.stat-info { display: flex; flex-direction: column; }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.85rem; color: var(--gray-500); margin-top: 0.25rem; }

/* --- Tools Grid --- */
.tools-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1rem;
}

.tool-card {
    text-align: center;
    padding: 1.5rem 1rem;
    border-radius: var(--radius);
    border: 2px dashed var(--gray-300);
    transition: var(--transition);
}

.tool-card i { font-size: 2rem; color: var(--gray-400); display: block; margin-bottom: 0.75rem; }
.tool-card h3 { font-size: 0.95rem; margin-bottom: 0.25rem; }
.tool-card p { font-size: 0.8rem; color: var(--gray-500); margin-bottom: 0.5rem; }

.tool-card-coming { opacity: 0.7; }
.tool-card-coming:hover { opacity: 1; border-color: var(--primary); }

/* --- Tables --- */
.table-responsive { overflow-x: auto; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-100);
}

.table th {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--gray-500);
    background: var(--gray-50);
}

.table tbody tr:hover { background: var(--gray-50); }

.table-sm th, .table-sm td { padding: 0.5rem 0.75rem; font-size: 0.85rem; }

.text-nowrap { white-space: nowrap; }
.text-muted { color: var(--gray-500) !important; }

/* --- Badges --- */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.2rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 50px;
    white-space: nowrap;
}

.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-secondary { background: var(--gray-200); color: var(--gray-600); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: var(--font-family);
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.8rem; }
.btn-full { width: 100%; justify-content: center; }

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

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

.btn-success { background: var(--success); color: white; }
.btn-success:hover { background: #15803d; color: white; }

.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #b45309; color: white; }

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

.btn-ghost {
    background: transparent;
    color: var(--gray-600);
}
.btn-ghost:hover { background: var(--gray-100); color: var(--gray-800); }

/* --- Forms --- */
.form-group { display: flex; flex-direction: column; gap: 0.4rem; }

.form-label {
    font-weight: 500;
    font-size: 0.85rem;
    color: var(--gray-700);
    display: flex; align-items: center; gap: 0.3rem;
}

.form-input {
    width: 100%;
    padding: 0.6rem 0.85rem;
    font-size: 0.9rem;
    font-family: var(--font-family);
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    background: white;
    color: var(--gray-800);
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,0.15);
}

.form-input::placeholder { color: var(--gray-400); }

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

.form-grid { display: flex; flex-direction: column; gap: 1.25rem; }

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

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

.form-section-title {
    font-size: 1rem;
    color: var(--gray-700);
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--gray-200);
    display: flex; align-items: center; gap: 0.5rem;
    margin-top: 0.5rem;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding-top: 1rem;
    border-top: 1px solid var(--gray-200);
}

.checkbox-label {
    display: flex; align-items: center; gap: 0.5rem;
    font-weight: 500; cursor: pointer;
    height: 100%;
    padding-top: 0.5rem;
}

.checkbox-label input { width: 18px; height: 18px; accent-color: var(--primary); }

.filters-form {
    display: flex;
    align-items: flex-end;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.filters-form .form-group { min-width: 200px; }

/* --- Alerts --- */
.alert {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.85rem 1.15rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.alert i { margin-top: 2px; }
.alert ul { margin: 0; padding-left: 1rem; }

.alert-success { background: var(--success-light); color: #166534; border: 1px solid #bbf7d0; }
.alert-danger { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: var(--info-light); color: #155e75; border: 1px solid #a5f3fc; }

/* --- Pagination --- */
.pagination {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    padding-top: 1.5rem;
}

.pagination-link {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 35px; height: 35px;
    border-radius: var(--radius);
    font-weight: 500;
    color: var(--gray-600);
    background: white;
    border: 1px solid var(--gray-200);
    transition: var(--transition);
}

.pagination-link:hover { border-color: var(--primary); color: var(--primary); }
.pagination-link.active { background: var(--primary); color: white; border-color: var(--primary); }

/* --- Empty State --- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-500);
}

.empty-state i { font-size: 3rem; display: block; margin-bottom: 1rem; color: var(--gray-300); }
.empty-state p { margin-bottom: 1rem; }

/* --- Utilities --- */
.mb-0 { margin-bottom: 0 !important; }
.mb-4 { margin-bottom: 1.5rem !important; }
.mt-4 { margin-top: 1.5rem !important; }

.inline-form { display: inline; }

.actions { white-space: nowrap; }
.actions .btn { margin-left: 0.25rem; }

/* --- Responsive --- */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }

    .sidebar-toggle { display: block; }

    .main-content { margin-left: 0; }

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

    .page-header { flex-direction: column; }

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

    .filters-form { flex-direction: column; }
    .filters-form .form-group { min-width: 100%; }

    .content-area { padding: 1rem; }

    .table th, .table td { padding: 0.5rem; font-size: 0.85rem; }
}

@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .tools-grid { grid-template-columns: 1fr 1fr; }

    .login-card { padding: 1.5rem; }
}

/* --- Overlay for mobile sidebar --- */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
}

.sidebar-overlay.active { display: block; }

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }

/* --- Install Page --- */
.install-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 50%, #1e40af 100%);
    padding: 1rem;
}

.install-card {
    background: white;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 2.5rem;
    width: 100%;
    max-width: 500px;
}

.install-card h1 {
    text-align: center;
    margin-bottom: 1.5rem;
    display: flex; align-items: center; justify-content: center; gap: 0.5rem;
}

.install-steps { margin: 1.5rem 0; }

.install-step {
    display: flex; align-items: center; gap: 0.75rem;
    padding: 0.5rem 0;
    font-size: 0.9rem;
}

.install-step.done { color: var(--success); }
.install-step.fail { color: var(--danger); }
.install-step.pending { color: var(--gray-400); }

/* ============================================
   Chat IA - Interface conversationnelle
   ============================================ */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--topbar-height) - 120px);
    min-height: 400px;
    background: var(--white, #fff);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1.5rem;
    scroll-behavior: smooth;
}

/* Message de bienvenue */
.chat-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 2rem;
}

.chat-welcome-icon {
    font-size: 3rem;
    color: var(--primary);
    margin-bottom: 1rem;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--primary-light);
    display: flex;
    align-items: center;
    justify-content: center;
}

.chat-welcome h3 {
    margin-bottom: 0.5rem;
    color: var(--gray-800);
}

.chat-welcome p {
    color: var(--gray-500);
    margin-bottom: 1.5rem;
    max-width: 500px;
}

.chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    max-width: 600px;
}

.chat-suggestion {
    padding: 0.6rem 1rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 20px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--gray-700);
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.chat-suggestion:hover {
    background: var(--primary-light);
    border-color: var(--primary);
    color: var(--primary-dark);
}

/* Messages */
.chat-message {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
    animation: fadeInUp 0.3s ease;
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.chat-message-user {
    flex-direction: row-reverse;
}

.chat-message-avatar {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
}

.chat-message-user .chat-message-avatar {
    background: var(--primary);
    color: #fff;
}

.chat-message-assistant .chat-message-avatar {
    background: var(--gray-100);
    color: var(--gray-700);
}

.chat-message-error .chat-message-avatar {
    background: var(--danger-light);
    color: var(--danger);
}

.chat-message-content {
    max-width: 75%;
    min-width: 60px;
}

.chat-message-text {
    padding: 0.75rem 1rem;
    border-radius: var(--radius-lg);
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-message-user .chat-message-text {
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.chat-message-assistant .chat-message-text {
    background: var(--gray-50);
    color: var(--gray-800);
    border: 1px solid var(--gray-200);
    border-bottom-left-radius: 4px;
}

.chat-message-error .chat-message-text {
    background: var(--danger-light);
    color: var(--danger);
    border: 1px solid #fca5a5;
    border-bottom-left-radius: 4px;
}

/* Markdown dans les réponses */
.markdown-body h2, .markdown-body h3, .markdown-body h4 {
    margin: 0.75rem 0 0.25rem;
    font-weight: 600;
}

.markdown-body h2 { font-size: 1.15rem; }
.markdown-body h3 { font-size: 1.05rem; }
.markdown-body h4 { font-size: 0.95rem; }

.markdown-body ul {
    padding-left: 1.25rem;
    margin: 0.5rem 0;
}

.markdown-body li {
    margin-bottom: 0.2rem;
}

.markdown-body code {
    background: rgba(0,0,0,0.06);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.9em;
    font-family: 'Fira Code', monospace;
}

.markdown-body pre {
    background: var(--gray-800);
    color: #e2e8f0;
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin: 0.5rem 0;
}

.markdown-body pre code {
    background: none;
    padding: 0;
    color: inherit;
}

.markdown-body a {
    color: var(--primary);
    text-decoration: underline;
}

.markdown-body strong { font-weight: 600; }

/* Animation typing */
.chat-typing {
    display: flex;
    gap: 4px;
    padding: 0.75rem 1rem;
}

.typing-dot {
    width: 8px;
    height: 8px;
    background: var(--gray-400);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

/* Zone de saisie */
.chat-input-area {
    border-top: 1px solid var(--gray-200);
    padding: 1rem 1.5rem;
    background: #fff;
}

.chat-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: 0.5rem;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 0.5rem 0.5rem 0.5rem 1rem;
    transition: var(--transition);
}

.chat-input-wrapper:focus-within {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.chat-input {
    flex: 1;
    border: none;
    background: none;
    resize: none;
    outline: none;
    font-family: var(--font-family);
    font-size: 0.95rem;
    line-height: 1.5;
    max-height: 150px;
    padding: 0.25rem 0;
}

.chat-send-btn {
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    transition: var(--transition);
}

.chat-send-btn:hover:not(:disabled) {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.chat-send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.chat-input-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.75rem;
    padding-top: 0.35rem;
}

/* Page header pour IA */
.page-header-left {
    flex: 1;
}

.page-header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Paramètres IA */
.ai-settings-info ol {
    padding-left: 1.25rem;
    margin: 0.5rem 0;
}

.ai-settings-info li {
    margin-bottom: 0.3rem;
}

.ai-settings-info code {
    background: rgba(0,0,0,0.06);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.9em;
}

.ml-2 { margin-left: 0.5rem; }
.mb-4 { margin-bottom: 1rem; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }

/* Tool card active */
.tool-card-active {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    padding: 1.5rem;
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    color: inherit;
    background: var(--primary-light);
    border: 2px solid var(--primary);
}

.tool-card-active:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.tool-card-active i:first-child {
    font-size: 2rem;
    margin-bottom: 0.75rem;
    color: var(--primary);
}

.tool-card-active h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.25rem;
}

.tool-card-active p {
    font-size: 0.85rem;
    color: var(--gray-600);
    margin-bottom: 0.5rem;
}

/* Responsive chat */
@media (max-width: 768px) {
    .chat-container {
        height: calc(100vh - var(--topbar-height) - 160px);
    }

    .chat-message-content {
        max-width: 85%;
    }

    .chat-suggestions {
        flex-direction: column;
    }

    .page-header-actions {
        flex-wrap: wrap;
    }
}

/* ===========================================
   AUDIT TOOLS
   =========================================== */

/* Onglets de type d'audit */
.audit-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.audit-tab {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1.2rem;
    border-radius: 0.5rem;
    background: var(--bg-light);
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 0.9rem;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.audit-tab:hover {
    background: var(--primary-light);
    color: var(--primary);
}

.audit-tab.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

/* Formulaire d'audit */
.audit-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 1rem;
    align-items: end;
}

.audit-form-submit {
    padding-bottom: 0;
}

.btn-full {
    width: 100%;
    white-space: nowrap;
}

/* Score */
.audit-score-container {
    display: flex;
    align-items: center;
    gap: 2rem;
    padding: 1rem 0;
}

.audit-score {
    width: 100px;
    height: 100px;
    border-radius: 50%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    border: 6px solid;
}

.audit-score-good {
    border-color: var(--success);
    color: var(--success);
    background: rgba(16, 185, 129, 0.08);
}

.audit-score-average {
    border-color: var(--warning);
    color: var(--warning);
    background: rgba(245, 158, 11, 0.08);
}

.audit-score-bad {
    border-color: var(--danger);
    color: var(--danger);
    background: rgba(239, 68, 68, 0.08);
}

.audit-score-value {
    font-size: 2rem;
    font-weight: 800;
    line-height: 1;
}

.audit-score-label {
    font-size: 0.85rem;
    font-weight: 600;
    opacity: 0.7;
}

.audit-score-text strong {
    font-size: 1.1rem;
}

.audit-score-text p {
    margin: 0.25rem 0 0;
    color: var(--text-secondary);
}

/* Checks */
.audit-checks {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 1rem;
}

.audit-check {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border-radius: 0.5rem;
    border-left: 4px solid;
}

.audit-check-pass {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.04);
}

.audit-check-fail {
    border-color: var(--danger);
    background: rgba(239, 68, 68, 0.04);
}

.audit-check-icon {
    font-size: 1.15rem;
    padding-top: 0.1rem;
}

.audit-check-pass .audit-check-icon {
    color: var(--success);
}

.audit-check-fail .audit-check-icon {
    color: var(--danger);
}

.audit-check-info strong {
    display: block;
    font-size: 0.92rem;
    margin-bottom: 0.15rem;
}

.audit-check-info p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.audit-checks-summary {
    font-size: 0.9rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
}

/* Analyse IA dans les audits */
.audit-ai-analysis h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    color: var(--primary);
}

.audit-ai-content {
    background: var(--bg-light);
    padding: 1.25rem;
    border-radius: 0.5rem;
    line-height: 1.7;
    font-size: 0.92rem;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Detail meta */
.audit-detail-meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.25rem;
}

.audit-detail-meta-grid > div strong {
    display: block;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.audit-url-link {
    color: var(--primary);
    text-decoration: none;
}

.audit-url-link:hover {
    text-decoration: underline;
}

/* Filtre historique */
.audit-filter-row {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr auto;
    gap: 1rem;
    align-items: end;
}

.audit-filter-submit {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

/* Pagination */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
}

.pagination-info {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Audit result card */
.audit-result .card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.audit-result .card-header h2 {
    margin: 0;
}

/* Text colors */
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }
.text-danger { color: var(--danger); }

/* Badge variants */
.badge-light {
    background: var(--bg-light);
    color: var(--text-secondary);
    font-size: 0.78rem;
}

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary);
}

.empty-state p {
    margin: 1rem 0;
}

/* Responsive audit */
@media (max-width: 768px) {
    .audit-form-row {
        grid-template-columns: 1fr;
    }

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

    .audit-score-container {
        flex-direction: column;
        text-align: center;
    }

    .audit-detail-meta-grid {
        grid-template-columns: 1fr;
    }

    .audit-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
    }
}

/* AI client selector */
.ai-client-selector {
    display: inline-block;
}

.ai-client-selector select {
    max-width: 250px;
    font-size: 0.85rem;
    padding: 0.35rem 0.7rem;
}

.form-input-sm {
    padding: 0.35rem 0.7rem;
    font-size: 0.85rem;
}

/* ============================================
   Nouvelles fonctionnalités Audit
   ============================================ */

/* --- Barre de progression AJAX --- */
.progress-bar-container {
    width: 100%;
    height: 8px;
    background: var(--gray-200);
    border-radius: 4px;
    overflow: hidden;
    margin: 1rem 0;
}

.progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--info));
    border-radius: 4px;
    transition: width 0.4s ease;
    width: 0%;
}

/* --- Spinner audit --- */
.audit-spinner {
    display: inline-block;
    animation: spin 1s linear infinite;
}

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

/* --- Steps progression audit complet --- */
.audit-progress-steps {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    margin: 1rem 0;
}

.audit-progress-steps .step {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.8rem;
    border-radius: var(--radius);
    font-size: 0.85rem;
    font-weight: 500;
    background: var(--gray-100);
    color: var(--gray-500);
    transition: var(--transition);
}

.audit-progress-steps .step.active {
    background: var(--primary-light);
    color: var(--primary);
}

.audit-progress-steps .step.done {
    background: var(--success-light);
    color: var(--success);
}

.audit-progress-steps .step.error {
    background: var(--danger-light);
    color: var(--danger);
}

/* --- Grille résultats audit complet --- */
.audit-full-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.audit-full-card {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1.2rem;
    transition: var(--transition);
}

.audit-full-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.audit-full-card h4 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: var(--gray-800);
}

.audit-full-card .score {
    font-size: 1.8rem;
    font-weight: 700;
}

.audit-full-card .score.good { color: var(--success); }
.audit-full-card .score.average { color: var(--warning); }
.audit-full-card .score.bad { color: var(--danger); }

/* --- Tab audit complet --- */
.audit-tab-full {
    background: linear-gradient(135deg, var(--primary), var(--purple)) !important;
    color: #fff !important;
    border-color: transparent !important;
}

.audit-tab-full:hover {
    opacity: 0.9;
}

/* --- Score évolution chart --- */
.score-history-chart {
    display: flex;
    align-items: flex-end;
    gap: 0.6rem;
    height: 120px;
    padding: 1rem 0;
}

.score-history-bar-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    min-width: 40px;
    height: 100%;
    justify-content: flex-end;
}

.score-history-bar {
    width: 100%;
    max-width: 40px;
    border-radius: 4px 4px 0 0;
    transition: height 0.4s ease;
    min-height: 4px;
}

.score-history-bar.good { background: var(--success); }
.score-history-bar.average { background: var(--warning); }
.score-history-bar.bad { background: var(--danger); }

.score-history-value {
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
    color: var(--gray-700);
}

.score-history-date {
    font-size: 0.65rem;
    color: var(--gray-400);
    margin-top: 0.3rem;
    white-space: nowrap;
}

/* --- Évolution du score (±pts) --- */
.audit-score-evolution {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.2rem 0.6rem;
    border-radius: var(--radius);
}

.audit-score-evolution.positive {
    color: var(--success);
    background: var(--success-light);
}

.audit-score-evolution.negative {
    color: var(--danger);
    background: var(--danger-light);
}

.audit-score-evolution.neutral {
    color: var(--gray-500);
    background: var(--gray-100);
}

/* --- Stat card rouge (pour score faible) --- */
.stat-card-red {
    border-left: 4px solid var(--danger);
}

.stat-card-red .stat-icon {
    background: var(--danger-light);
    color: var(--danger);
}

/* --- Print media query --- */
@media print {
    .sidebar, .topbar, .audit-tabs, .btn, .page-header a {
        display: none !important;
    }

    .main-content {
        margin-left: 0 !important;
        padding: 0 !important;
    }

    .card {
        box-shadow: none !important;
        border: 1px solid #ddd !important;
        break-inside: avoid;
    }

    .audit-check-item {
        break-inside: avoid;
    }
}

/* --- Responsive audit complet --- */
@media (max-width: 768px) {
    .audit-full-grid {
        grid-template-columns: 1fr;
    }

    .audit-progress-steps {
        flex-direction: column;
    }

    .score-history-chart {
        height: 80px;
    }
}

/* ============================================
   API Usage Tracker
   ============================================ */

.api-usage-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
}

.api-usage-stat {
    text-align: center;
    padding: 1rem;
    background: var(--gray-50);
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
}

.api-usage-value {
    display: block;
    font-size: 1.6rem;
    font-weight: 700;
    color: var(--gray-800);
    line-height: 1.2;
}

.api-usage-label {
    display: block;
    font-size: 0.78rem;
    color: var(--gray-500);
    margin-top: 0.25rem;
}

.api-usage-detail h4 {
    font-size: 0.9rem;
    color: var(--gray-600);
    margin-bottom: 0.5rem;
}

/* Daily activity chart */
.api-usage-chart {
    display: flex;
    align-items: flex-end;
    gap: 4px;
    height: 100px;
    padding: 0.5rem 0;
}

.api-usage-bar-wrap {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    min-width: 24px;
    height: 100%;
    justify-content: flex-end;
}

.api-usage-bar {
    width: 100%;
    max-width: 32px;
    background: linear-gradient(180deg, var(--primary), var(--info));
    border-radius: 3px 3px 0 0;
    min-height: 3px;
    transition: height 0.3s ease;
}

.api-usage-bar-value {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--gray-600);
    margin-bottom: 2px;
}

.api-usage-bar-date {
    font-size: 0.6rem;
    color: var(--gray-400);
    margin-top: 3px;
    white-space: nowrap;
}

/* API counter badge in header */
.api-counter {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--primary);
}

.table-sm td, .table-sm th {
    padding: 0.4rem 0.6rem;
    font-size: 0.85rem;
}

@media (max-width: 768px) {
    .api-usage-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .api-usage-chart {
        height: 60px;
    }
}
