/**
 * RAG Pro v2 - Common Styles
 * Design Token System — single source of truth
 * Encoding: UTF-8
 */

/* ==========================================
   DESIGN TOKENS
   ========================================== */
:root {
    /* Brand */
    /* Éclairci le 2026-08-29 : #5b6ef5 ne donnait que 3,48:1 sur --surface-card,
     * sous le minimum AA de 4,5:1, alors qu'il sert 33 fois comme COULEUR DE TEXTE
     * et 18 fois en bordure. Les 5 usages en FOND emploient --color-primary-dark,
     * qui porte du blanc à 5,73:1 — l'ancien primaire n'y était qu'à 4,21:1, donc
     * le bouton primaire lui-même échouait sans que personne ne l'ait relevé. */
    --color-primary:        #7c8cf8;
    --color-primary-dark:   #4254e8;
    --color-primary-light:  #1e2a4a;
    --color-secondary:      #764ba2;
    --gradient-primary:     linear-gradient(135deg, #5b6ef5 0%, #764ba2 100%);

    /* Semantic */
    --color-success:        #22c55e;
    --color-success-bg:     #052e16;
    --color-danger:         #f87171;
    --color-danger-bg:      #2d0a0a;
    --color-warning:        #fbbf24;
    --color-warning-bg:     #2d1f02;
    --color-info:           #60a5fa;
    --color-info-bg:        #0d2044;

    /* Surfaces — Dark Slate */
    --surface-page:         #0f172a;
    --surface-card:         #1e293b;
    --surface-subtle:       #162032;
    --surface-border:       #334155;
    --surface-border-light: #1e293b;

    /* Text */
    --text-primary:         #f1f5f9;
    --text-secondary:       #94a3b8;
    /* Éclairci le 2026-08-29 : #64748b ne donnait que 3,07:1 sur --surface-card.
     * Le thème clair garde cette valeur, qui y atteint 4,8:1 sur blanc. */
    --text-muted:           #8b98ae;
    --text-white:           #ffffff;
    --text-on-primary:      #ffffff;

    /* Spacing */
    --sp-1: 4px;   --sp-2: 8px;   --sp-3: 12px;
    --sp-4: 16px;  --sp-5: 20px;  --sp-6: 24px;
    --sp-8: 32px;  --sp-10: 40px; --sp-12: 48px;

    /* Radius */
    --radius-sm:   6px;
    --radius-md:   10px;
    --radius-lg:   14px;
    --radius-xl:   20px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-xs:  0 1px 2px rgba(0,0,0,.3);
    --shadow-sm:  0 2px 4px rgba(0,0,0,.4);
    --shadow-md:  0 4px 12px rgba(0,0,0,.5);
    --shadow-lg:  0 8px 24px rgba(0,0,0,.6);
    --shadow-xl:  0 20px 40px rgba(0,0,0,.7);
    --shadow-primary: 0 4px 14px rgba(91,110,245,.4);

    /* Typography */
    --font-sans:  'Inter', 'Segoe UI', system-ui, sans-serif;
    --font-mono:  'JetBrains Mono', 'Fira Code', 'Courier New', monospace;

    /* Transitions */
    --ease-fast:   0.15s ease;
    --ease-normal: 0.25s ease;

    /* Layout */
    --sidebar-width:     220px;
    --header-height:     58px;
    --content-max-width: 1280px;
    --overlay-hover:        rgba(255,255,255,.08);
    --overlay-veil:         rgba(0,0,0,.7);
    --color-violet:         #a78bfa;
    --color-orange:         #fb923c;
    --color-teal:           #2dd4bf;

    /* --- Bloc de code (lot 6b, complété au lot E le 2026-08-30) ----------
     * Valeurs SOMBRES par défaut, donc valables pour `sombre` et `contraste`.
     * Le thème clair les redéfinit plus bas : `atom-one-light` est vendorée
     * depuis le lot E, la contrainte qui imposait un fond sombre partout est
     * levée. */
    --surface-code:         #21222c;
    --border-code:          #44475a;
    /* #6272a4 à l'origine, soit 3,36:1 sur le fond — sous le minimum AA.
     * Sert au libellé de langue et aux boutons copier / télécharger / exécuter. */
    --text-code-meta:       #7a8bc4;

}

/* ==========================================
   RESET
   ========================================== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html { font-size: 15px; -webkit-font-smoothing: antialiased; scroll-behavior: smooth; }
body {
    font-family: var(--font-sans);
    background: var(--surface-page);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}
h1,h2,h3,h4,h5,h6 { font-weight: 600; line-height: 1.3; color: var(--text-primary); }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 16px; } h4 { font-size: 14px; }
p { color: var(--text-secondary); line-height: 1.6; }
a { color: var(--color-primary); text-decoration: none; transition: color var(--ease-fast); }
a:hover { color: var(--color-primary-dark); }

/* ==========================================
   APP SHELL LAYOUT (sidebar + content)
   ========================================== */
.app-shell {
    display: flex;
    min-height: 100vh;
    flex-direction: column;
}

/* HEADER */
.app-header {
    position: fixed;
    top: 0; left: 0; right: 0;
    height: var(--header-height);
    background: var(--gradient-primary);
    color: var(--text-white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--sp-6);
    box-shadow: var(--shadow-md);
    z-index: 1000;
}
.app-header .logo {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    font-size: 17px;
    font-weight: 700;
    color: var(--text-white);
    text-decoration: none;
}
.app-header .logo svg { width: 22px; height: 22px; flex-shrink: 0; }
.header-right {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
}
/* Les voiles blancs qui suivent sont CORRECTS et volontairement non convertis :
 * l'en-tête a pour fond `--gradient-primary`, un dégradé coloré dans les trois
 * thèmes. Un voile blanc translucide y fonctionne partout ; un jeton de surface
 * le casserait. */
.user-chip {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    background: rgba(255,255,255,0.18);
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--radius-full);
    font-size: 13px;
}
.user-chip .avatar {
    width: 26px; height: 26px;
    background: rgba(255,255,255,0.4);
    border-radius: var(--radius-full);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 12px;
}
.user-chip .role-tag {
    background: rgba(255,215,0,0.25);
    color: var(--color-warning);
    padding: 1px 6px;
    border-radius: var(--radius-full);
    font-size: 10px; font-weight: 700;
}
.btn-logout {
    background: rgba(255,255,255,0.18);
    color: var(--text-white);
    border: 1px solid rgba(255,255,255,0.3);
    padding: var(--sp-2) var(--sp-4);
    border-radius: var(--radius-md);
    font-size: 13px; cursor: pointer;
    transition: all var(--ease-fast);
    font-family: inherit;
    font-weight: 500;
}
.btn-logout:hover { background: rgba(255,255,255,0.3); }

/* SIDEBAR */
.app-sidebar {
    position: fixed;
    top: var(--header-height); left: 0;
    width: var(--sidebar-width);
    height: calc(100vh - var(--header-height));
    background: var(--surface-card);
    border-right: 1px solid var(--surface-border);
    overflow-y: auto;
    z-index: 900;
    padding: var(--sp-4) 0;
    display: flex;
    flex-direction: column;
}
.sidebar-section { margin-bottom: var(--sp-2); }
.sidebar-label {
    padding: var(--sp-2) var(--sp-5);
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
}
.sidebar-link {
    display: flex;
    align-items: center;
    gap: var(--sp-3);
    padding: var(--sp-2) var(--sp-5);
    font-size: 14px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: 0;
    transition: all var(--ease-fast);
    position: relative;
}
.sidebar-link:hover { background: var(--color-primary-light); color: var(--color-primary); }
.sidebar-link.active {
    background: var(--color-primary-light);
    color: var(--color-primary);
    font-weight: 600;
}
.sidebar-link.active::before {
    content: '';
    position: absolute;
    left: 0; top: 0; bottom: 0;
    width: 3px;
    background: var(--color-primary-dark);
    border-radius: 0 3px 3px 0;
}
.sidebar-link .nav-icon { width: 18px; height: 18px; flex-shrink: 0; opacity: .7; }
.sidebar-link.active .nav-icon { opacity: 1; }
.sidebar-footer {
    margin-top: auto;
    padding: var(--sp-4) var(--sp-5);
    border-top: 1px solid var(--surface-border);
    font-size: 11px;
    color: var(--text-muted);
}

/* MAIN CONTENT AREA */
.app-content {
    margin-left: var(--sidebar-width);
    margin-top: var(--header-height);
    min-height: calc(100vh - var(--header-height));
    padding: var(--sp-8);
}
.page-container {
    max-width: var(--content-max-width);
    margin: 0 auto;
}

/* PAGE HEADER */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--sp-8);
    flex-wrap: wrap;
    gap: var(--sp-4);
}
.page-header h1 { font-size: 22px; }
.page-header p { font-size: 14px; color: var(--text-muted); margin-top: 2px; }

/* ==========================================
   CARDS
   ========================================== */
.card {
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--surface-border);
    box-shadow: var(--shadow-sm);
    padding: var(--sp-6);
    transition: box-shadow var(--ease-normal), transform var(--ease-normal);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-clickable { cursor: pointer; }
.card-clickable:hover { transform: translateY(-2px); }

.section {
    background: var(--surface-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--surface-border);
    box-shadow: var(--shadow-sm);
    padding: var(--sp-6);
    margin-bottom: var(--sp-6);
}
.section-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    padding-bottom: var(--sp-4);
    margin-bottom: var(--sp-5);
    border-bottom: 1px solid var(--surface-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--sp-5);
}

/* ==========================================
   STATS GRID
   ========================================== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: var(--sp-5);
    margin-bottom: var(--sp-8);
}
.stat-card {
    background: var(--surface-card);
    border: 1px solid var(--surface-border);
    border-radius: var(--radius-lg);
    padding: var(--sp-5);
    box-shadow: var(--shadow-sm);
}
.stat-card .stat-icon { font-size: 20px; margin-bottom: var(--sp-2); }
.stat-card .stat-value {
    font-size: 32px;
    font-weight: 700;
    color: var(--color-primary);
    margin-bottom: 2px;
    line-height: 1;
}
.stat-card .stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; }

/* ==========================================
   BUTTONS
   ========================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 8px 18px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: all var(--ease-normal);
    font-family: inherit;
    text-decoration: none;
    white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; pointer-events: none; }
.btn-primary { background: var(--gradient-primary); color: var(--text-white); }
.btn-primary:hover:not(:disabled) { transform: translateY(-1px); box-shadow: var(--shadow-primary); }
.btn-secondary { background: var(--surface-subtle); color: var(--text-secondary); border: 1px solid var(--surface-border); }
.btn-secondary:hover:not(:disabled) { background: var(--color-primary-light); color: var(--color-primary); border-color: var(--color-primary); }
.btn-danger { background: var(--color-danger); color: var(--text-white); }
.btn-danger:hover:not(:disabled) { background: var(--color-danger-bg); }
.btn-ghost { background: transparent; color: var(--text-secondary); border: 1px solid transparent; }
.btn-ghost:hover:not(:disabled) { background: var(--surface-subtle); border-color: var(--surface-border); }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 15px; }
.btn-block { width: 100%; }
.btn-icon { padding: 8px; border-radius: var(--radius-md); }
.btn-icon svg { width: 16px; height: 16px; }

/* ==========================================
   FORMS
   ========================================== */
.form-group { margin-bottom: var(--sp-5); }
.form-group label {
    display: block;
    font-weight: 600;
    font-size: 13px;
    margin-bottom: var(--sp-2);
    color: var(--text-primary);
}
.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--surface-border);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-family: inherit;
    transition: all var(--ease-normal);
    background: var(--surface-card);
    color: var(--text-primary);
}
.form-control:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 12%, transparent); }
.form-control:disabled { background: var(--surface-subtle); cursor: not-allowed; color: var(--text-muted); }
textarea.form-control { resize: vertical; min-height: 90px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Toggle switch */
.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-3) 0;
    border-bottom: 1px solid var(--surface-border-light);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-info strong { font-size: 13px; font-weight: 600; display: block; }
.toggle-info span { font-size: 12px; color: var(--text-muted); }
.toggle-switch { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute; inset: 0;
    background: var(--text-muted); border-radius: 12px; cursor: pointer;
    transition: background var(--ease-fast);
}
.toggle-slider::before {
    content: '';
    position: absolute;
    height: 18px; width: 18px;
    left: 3px; bottom: 3px;
    background: white; border-radius: 50%;
    transition: transform var(--ease-fast);
    box-shadow: var(--shadow-xs);
}
.toggle-switch input:checked + .toggle-slider { background: var(--color-primary-dark); }
.toggle-switch input:checked + .toggle-slider::before { transform: translateX(20px); }
.toggle-switch input:disabled + .toggle-slider { opacity: .5; cursor: not-allowed; }

/* ==========================================
   TABLES
   ========================================== */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
    background: var(--surface-subtle);
    padding: 12px var(--sp-4);
    text-align: left;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--surface-border);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
}
.table td { padding: 13px var(--sp-4); border-bottom: 1px solid var(--surface-border-light); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--surface-subtle); }
.table-responsive { overflow-x: auto; }

/* ==========================================
   BADGES
   ========================================== */
.badge {
    display: inline-flex; align-items: center; gap: 4px;
    padding: 3px 10px;
    border-radius: var(--radius-full);
    font-size: 11px; font-weight: 600;
}
.badge-primary   { background: var(--color-primary-light); color: var(--color-primary); }
.badge-success   { background: var(--color-success-bg);    color: var(--color-success); }
.badge-danger    { background: var(--color-danger-bg);     color: var(--color-danger); }
.badge-warning   { background: var(--color-warning-bg);    color: var(--color-warning); }
.badge-info      { background: var(--color-info-bg);       color: var(--color-info); }
.badge-neutral   { background: var(--surface-subtle);      color: var(--text-secondary); border: 1px solid var(--surface-border); }
.badge-admin     { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-user      { background: var(--color-primary-light); color: var(--color-primary); }
.badge-readonly  { background: var(--surface-subtle); color: var(--text-muted); }

/* Project badges */
.badge-agent    { background: color-mix(in srgb, var(--color-violet) 22%, var(--surface-card)); color: var(--color-violet); }
.badge-shared   { background: var(--color-info-bg); color: var(--color-info); }

/* Status dot */
.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.online, .status-dot.enabled { background: var(--color-success); }
.status-dot.offline, .status-dot.disabled { background: var(--color-danger); }
.status-dot.warning { background: var(--color-warning); }

/* ==========================================
   MODALS
   ========================================== */
.modal-overlay {
    position: fixed; inset: 0;
    background: var(--overlay-veil);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center; justify-content: center;
    z-index: 2000; padding: var(--sp-5);
}
.modal-overlay.visible { display: flex; }
.modal {
    background: var(--surface-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    max-width: 520px; width: 100%;
    max-height: 90vh; overflow-y: auto;
    animation: modal-in .2s ease;
}
@keyframes modal-in { from { opacity: 0; transform: translateY(-12px) scale(.98); } to { opacity: 1; transform: none; } }
.modal-header {
    padding: var(--sp-5) var(--sp-6);
    border-bottom: 1px solid var(--surface-border);
    display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 16px; }
.modal-close {
    background: none; border: none;
    width: 30px; height: 30px;
    border-radius: var(--radius-md);
    cursor: pointer; font-size: 18px;
    color: var(--text-muted);
    display: flex; align-items: center; justify-content: center;
    transition: all var(--ease-fast);
}
.modal-close:hover { background: var(--surface-subtle); color: var(--text-primary); }
.modal-body { padding: var(--sp-6); }
.modal-footer { padding: var(--sp-4) var(--sp-6); border-top: 1px solid var(--surface-border); display: flex; justify-content: flex-end; gap: var(--sp-3); }

/* ==========================================
   TOAST
   ========================================== */
.toast {
    position: fixed; bottom: 24px; right: 24px;
    padding: 12px 20px;
    border-radius: var(--radius-lg);
    font-size: 14px; font-weight: 500;
    box-shadow: var(--shadow-lg);
    color: var(--text-white);
    animation: toast-in .25s ease;
    z-index: 3000; max-width: 360px;
}
@keyframes toast-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }
.toast.success { background: var(--color-success); }
.toast.error   { background: var(--color-danger); }
.toast.warning { background: var(--color-warning); }
.toast.info    { background: var(--color-info); }

/* ==========================================
   LOADING / SPINNER
   ========================================== */
.loading { display: none; text-align: center; padding: var(--sp-10); color: var(--text-muted); }
.loading.visible { display: block; }
.spinner {
    border: 3px solid var(--surface-border);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    width: 36px; height: 36px;
    animation: spin 0.8s linear infinite;
    margin: 0 auto var(--sp-4);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ==========================================
   EMPTY STATE
   ========================================== */
.empty-state { text-align: center; padding: var(--sp-12) var(--sp-5); color: var(--text-muted); }
.empty-state .empty-icon { font-size: 48px; margin-bottom: var(--sp-4); opacity: .5; }
.empty-state h3 { color: var(--text-primary); margin-bottom: var(--sp-2); }
.empty-state p { font-size: 14px; max-width: 320px; margin: 0 auto var(--sp-5); }

/* ==========================================
   UPLOAD AREA
   ========================================== */
.upload-area {
    border: 2px dashed var(--surface-border);
    border-radius: var(--radius-lg);
    padding: var(--sp-10);
    text-align: center;
    cursor: pointer;
    transition: all var(--ease-normal);
}
.upload-area:hover,
.upload-area.dragover { border-color: var(--color-primary); background: var(--color-primary-light); }
.upload-area .upload-icon { font-size: 42px; margin-bottom: var(--sp-3); }
.upload-area p { font-size: 14px; }
.upload-area .browse { color: var(--color-primary); font-weight: 600; }
.progress-bar { width: 100%; height: 6px; background: var(--surface-border); border-radius: 3px; overflow: hidden; margin-top: var(--sp-4); display: none; }
.progress-bar.visible { display: block; }
.progress-fill { height: 100%; background: var(--gradient-primary); transition: width .3s ease; width: 0; }

/* ==========================================
   GRIDS
   ========================================== */
.grid      { display: grid; gap: var(--sp-5); }
.grid-2    { grid-template-columns: repeat(2, 1fr); }
.grid-3    { grid-template-columns: repeat(3, 1fr); }
.grid-4    { grid-template-columns: repeat(4, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

/* ==========================================
   UTILITIES
   ========================================== */
.d-none    { display: none !important; }
.d-block   { display: block !important; }
.d-flex    { display: flex !important; }
.align-center { align-items: center !important; }
.gap-2     { gap: var(--sp-2) !important; }
.gap-3     { gap: var(--sp-3) !important; }
.gap-4     { gap: var(--sp-4) !important; }
.text-center { text-align: center !important; }
.text-right  { text-align: right !important; }
.text-muted  { color: var(--text-muted) !important; }
.text-danger { color: var(--color-danger) !important; }
.text-success{ color: var(--color-success) !important; }
.text-sm     { font-size: 12px !important; }
.text-xs     { font-size: 11px !important; }
.font-mono   { font-family: var(--font-mono) !important; }
.mt-2 { margin-top: var(--sp-2) !important; } .mt-3 { margin-top: var(--sp-3) !important; }
.mt-4 { margin-top: var(--sp-4) !important; } .mt-6 { margin-top: var(--sp-6) !important; }
.mb-2 { margin-bottom: var(--sp-2) !important; } .mb-3 { margin-bottom: var(--sp-3) !important; }
.mb-4 { margin-bottom: var(--sp-4) !important; } .mb-6 { margin-bottom: var(--sp-6) !important; }
.w-100 { width: 100% !important; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.break-all { word-break: break-all; }
.divider { border: none; border-top: 1px solid var(--surface-border); margin: var(--sp-5) 0; }

/* Code inline */
code {
    font-family: var(--font-mono);
    background: var(--surface-subtle);
    border: 1px solid var(--surface-border);
    padding: 1px 5px;
    border-radius: var(--radius-sm);
    font-size: 12px;
}

/* Scrollbar */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--surface-subtle); }
::-webkit-scrollbar-thumb { background: var(--surface-subtle); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--surface-border); }

/* Animations */
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.fade-in { animation: fadeIn .25s ease; }

/* ==========================================
   RESPONSIVE
   ========================================== */
@media (max-width: 900px) {
    .app-sidebar { transform: translateX(-100%); transition: transform var(--ease-normal); }
    .app-sidebar.open { transform: none; }
    .app-content { margin-left: 0; padding: var(--sp-5); }
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
    .app-header { padding: 0 var(--sp-4); }
    .app-content { padding: var(--sp-4); }
    .stats-grid { grid-template-columns: 1fr; }
}

/* ===========================================================================
 * Modales natives <dialog> — lot 3, 2026-08-29
 * ===========================================================================
 * Le navigateur fournit gratuitement ce qu'il fallait écrire à la main et qui
 * ne l'était pas : fermeture par Échap, piège de focus (la tabulation ne sort
 * plus derrière la fenêtre), retour du focus au bouton d'origine à la
 * fermeture, inertie du fond, et annonce correcte aux lecteurs d'écran.
 *
 * On conserve l'apparence existante : le <dialog> porte lui-même le voile
 * sombre et centre sa boîte, exactement comme le faisait `.modal-overlay`.
 * Le ::backdrop natif est donc rendu transparent — sans quoi le fond serait
 * assombri deux fois.
 *
 * Les règles `.modal-overlay` (div + classe `.visible`) restent en place :
 * la conversion se fait page par page, les deux mécanismes cohabitent.
 * ======================================================================== */
dialog.modal-overlay {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    margin: 0;
    border: 0;
    padding: var(--sp-5);
    background: var(--overlay-veil);
    backdrop-filter: blur(4px);
    color: inherit;
    display: none;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}
dialog.modal-overlay[open]   { display: flex; }
dialog.modal-overlay::backdrop { background: transparent; }


/* ===========================================================================
 * Accessibilité — lot 4, 2026-08-29
 * ======================================================================== */

/* Contenu destiné aux LECTEURS D'ÉCRAN uniquement : présent dans l'arbre
 * d'accessibilité, invisible à l'écran. `display:none` ne conviendrait pas —
 * il retirerait l'élément de cet arbre, donc de ce qui est annoncé. */
.sr-only {
    position: absolute;
    width: 1px; height: 1px;
    margin: -1px; padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* ===========================================================================
 * THÈMES — lot 6, 2026-08-29
 * ===========================================================================
 * Le thème est rendu CÔTÉ SERVEUR : `_tpl()` (src/main.py) lit un cookie et
 * Jinja pose `data-theme` sur <html>. Aucun scintillement, et aucun script
 * inline — que notre CSP interdit.
 *
 * Seuls les jetons de COULEUR sont surchargés. Espacements, rayons, polices,
 * transitions et gabarit restent communs : un thème change l'apparence, pas
 * la mise en page.
 *
 * Dark Slate reste le défaut, INCHANGÉ (absence de `data-theme`). On ne suit
 * volontairement PAS `prefers-color-scheme` : un utilisateur en clair verrait
 * son interface changer sans l'avoir demandé. Pour l'activer, il suffirait
 * d'ajouter un bloc `@media (prefers-color-scheme: light) :root:not([data-theme])`.
 * ======================================================================== */

/* --- Clair — usage diurne, bureau éclairé, impression ------------------- */
[data-theme="clair"] {
    /* Neutres inspirés de GitHub Primer (canvas.subtle / canvas.default /
     * border.default), qui séparent la PAGE de la CARTE. La première version
     * mettait les deux à quasi-blanc : aucune séparation, et un écran
     * entièrement lumineux — d'où l'impression de violence.
     * Le texte n'est pas en noir pur, la page pas en blanc pur : l'écart
     * maximal de luminosité est ce qui fatigue le plus l'œil. */
    --color-primary:        #5560d3;
    --color-primary-dark:   #4048b8;
    --color-primary-light:  #e6e8fb;
    --color-secondary:      #7c5cbf;
    --gradient-primary:     linear-gradient(135deg, #5560d3 0%, #7c5cbf 100%);

    --color-success:        #1a7f42;
    --color-success-bg:     #e6f4ec;
    --color-danger:         #c0392f;
    --color-danger-bg:      #fbeceb;
    --color-warning:        #92670a;
    --color-warning-bg:     #fdf4e0;
    --color-info:           #2563c9;
    --color-info-bg:        #e7effb;

    --surface-page:         #eef1f5;
    --surface-card:         #fbfcfd;
    --surface-subtle:       #e4e9f0;
    --surface-border:       #d3dae3;
    --surface-border-light: #e8ecf2;

    --text-primary:         #1f2733;
    --text-secondary:       #55606e;
    /* Assombri le 2026-08-29 : #67717f passait sur la carte (4,82) mais
     * échouait sur --surface-subtle (4,05), plus foncée. Vérifier un jeton
     * sur la SEULE surface principale ne suffit pas. */
    --text-muted:           #5d6673;
    --text-white:           #ffffff;
    --text-on-primary:      #ffffff;
    --overlay-hover:        rgba(15,23,51,.06);
    --overlay-veil:         rgba(31,39,51,.45);
    --color-violet:         #7048c4;
    --color-orange:         #b45309;
    --color-teal:           #0f766e;

    /* Bloc de code clair (lot E). Le fond reprend exactement celui d'atom-one-light
     * (#fafafa) : sans quoi la zone colorée par la feuille et le cadre autour
     * n'auraient pas le même fond. */
    --surface-code:         #fafafa;
    --border-code:          #d3dae3;
    --text-code-meta:       #4b5563;   /* 7,24:1 sur #fafafa — AAA */

}

/* --- Contraste élevé — accessibilité, atelier, écran en plein jour ------ */
/* Cible WCAG AAA (7:1) sur le texte courant comme sur le texte secondaire. */
[data-theme="contraste"] {
    /* Calqué sur le thème « dark high contrast » de GitHub, qui vise 7:1.
     * Point important appris de lui : un thème contrasté n'empile PAS du noir
     * pur et du blanc pur — il utilise un quasi-noir et des BORDURES
     * renforcées. Des bordures blanches partout créent un quadrillage
     * éblouissant, ce que faisait la première version. */
    --color-primary:        #79c0ff;
    /* Volontairement CLAIR : c'est un fond de bouton, et le texte posé
     * dessus est le quasi-noir --text-on-primary. 7,75:1, donc AAA. */
    --color-primary-dark:   #58a6ff;
    --color-primary-light:  #0c2d6b;
    --color-secondary:      #d2a8ff;
    --gradient-primary:     linear-gradient(135deg, #79c0ff 0%, #d2a8ff 100%);

    --color-success:        #56d364;
    --color-success-bg:     #0c2d19;
    --color-danger:         #ff7b72;
    --color-danger-bg:      #3c1113;
    --color-warning:        #e3b341;
    --color-warning-bg:     #341a00;
    --color-info:           #79c0ff;
    --color-info-bg:        #0c2d6b;

    --surface-page:         #0a0c10;
    --surface-card:         #12161c;
    --surface-subtle:       #1a1f26;
    --surface-border:       #7d8590;
    --surface-border-light: #464e58;

    --text-primary:         #ffffff;
    --text-secondary:       #e6edf3;
    --text-muted:           #c9d1d9;
    --text-white:           #ffffff;
    --text-on-primary:      #0a0c10;
    --overlay-hover:        rgba(255,255,255,.16);
    --overlay-veil:         rgba(0,0,0,.85);
    --color-violet:         #d2a8ff;
    --color-orange:         #ffa657;
    --color-teal:           #5eead4;

}

/* --- Sélecteur de thème (page profil) ---------------------------------- */
.theme-choix { border: 0; margin: 0; padding: 0; display: grid; gap: var(--sp-2); }
.theme-option {
    display: flex; align-items: center; gap: var(--sp-3);
    padding: var(--sp-3); border-radius: var(--radius-md);
    border: 1px solid var(--surface-border);
    cursor: pointer; color: var(--text-primary);
}
.theme-option:hover { background: var(--surface-subtle); }
/* Le focus doit rester VISIBLE : c'est le seul repère au clavier. */
.theme-option:focus-within { outline: 2px solid var(--color-primary); outline-offset: 2px; }
.theme-option em { color: var(--text-muted); font-style: normal; font-size: 12px; }
.theme-pastille {
    width: 20px; height: 20px; border-radius: 50%;
    border: 2px solid; flex-shrink: 0;
}

/* Étiquette d'instance — visible seulement si RAGPRO_INSTANCE_LABEL est définie
 * côté serveur. Inerte en production, qui ne la définit pas. */
.etiquette-instance {
    position: fixed; left: 0; bottom: 0; z-index: 2147483647;
    padding: 6px 14px;
    font: 700 12px/1.4 var(--font-mono, monospace);
    letter-spacing: .3px; color: #1a1a00;
    background: repeating-linear-gradient(45deg, #fde047 0 12px, #facc15 12px 24px);
    border-top: 2px solid #a16207; border-right: 2px solid #a16207;
    border-top-right-radius: 8px; pointer-events: none;
}

/* ---------------------------------------------------------------------------
 * `[hidden]` doit TOUJOURS l'emporter — lot 7e, 2026-08-29.
 *
 * La règle `[hidden] { display: none }` vient de la feuille du NAVIGATEUR, dont
 * la priorité est inférieure à celle de nos feuilles. Toute règle à nous posant
 * un `display` (`.btn`, `#btnStop`, `.pipeline-stats-bar`… 24 cas recensés)
 * rendait donc visible un élément censé être masqué.
 *
 * `!important` est indispensable ici, et sans effet de bord : les révélations
 * passent toutes par `afficher()`, qui retire `hidden` AVANT de poser un style.
 * ------------------------------------------------------------------------- */
[hidden] { display: none !important; }

/* ---------------------------------------------------------------------------
 * Lot E, 2026-08-30 — seule retouche apportée à atom-one-light.
 * Son gris de commentaire (#a0a1a7) donne 2,47:1 sur son propre fond #fafafa,
 * bien en dessous du minimum AA. Un commentaire de code est du contenu, pas de
 * la décoration. #6b7280 donne 4,63:1. Corrigé ICI et non dans le fichier
 * vendoré, qui reste fidèle à l'amont (sa somme SHA-256 est notée en tête).
 * ------------------------------------------------------------------------ */
[data-theme="clair"] .hljs-comment,
[data-theme="clair"] .hljs-quote { color: #6b7280; }
