/* writer_base.css - Variables, reset, layout principal */
/* Version 1.0 */

/* ==================== VARIABLES CSS ==================== */

:root {
    --primary-color: #007bff;
    --primary-hover: #0056b3;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --dark: #343a40;
    --light: #f8f9fa;
    --border: #dee2e6;
    --text-color: #333;
    --bg-page: white;
}

/* ==================== RESET ==================== */

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: #f5f5f5;
    color: #333;
    overflow: hidden;
}

/* ==================== MODE D'AFFICHAGE ==================== */
/* [MODIFIE 2026-07-26] integre dans toolbar claire */

.view-mode-toggle {
    display: inline-flex;
    border: 1px solid #c5c9d0;
    border-radius: 3px;
    overflow: hidden;
    align-self: center;
}

.view-mode-toggle .tb {
    border: none !important;
    border-radius: 0 !important;
    border-right: 1px solid #c5c9d0 !important;
}

.view-mode-toggle .tb:last-child {
    border-right: none !important;
}

.view-mode-toggle .tb.active {
    background: #dce8ff;
    color: #1a56db;
}

/* ==================== LAYOUT PRINCIPAL ==================== */

.editor-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background: white;
}

/* ==================== HEADER PRINCIPAL ==================== */
/* [MODIFIE 2026-07-26] Barre superieure unifiee sur fond bleu marque */

.editor-header {
    display: flex;
    align-items: center;
    padding: 0 1rem;
    background: #0803aa;
    color: white;
    box-shadow: 0 2px 8px rgba(0,0,0,.25);
    min-height: 50px;
    gap: 8px;
    overflow: hidden;
}

.header-left {
    display: flex;
    align-items: center;
    gap: .65rem;
    flex-shrink: 0;
    min-width: 0;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 3px;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    scrollbar-width: none;
}
.header-actions::-webkit-scrollbar { display: none; }

.header-right {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
    margin-left: auto;
}

.doc-name-display {
    font-size: .88rem;
    color: rgba(255,255,255,.85);
    max-width: 12ch;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    cursor: pointer;
    padding: .25rem .5rem;
    border-radius: 4px;
    border: 1px solid transparent;
    flex-shrink: 0;
}
.doc-name-display:hover {
    border-color: rgba(255,255,255,.25);
    background: rgba(255,255,255,.08);
}
.document-name-input {
    padding: .3rem .65rem;
    border: 1px solid rgba(255,255,255,.25);
    border-radius: 4px;
    font-size: .88rem;
    width: 14ch;
    max-width: 14ch;
    background: rgba(255,255,255,.1);
    color: white;
    flex-shrink: 0;
}
.document-name-input::placeholder { color: rgba(255,255,255,.4); }
.document-name-input:focus {
    outline: none;
    border-color: rgba(255,255,255,.55);
    background: rgba(255,255,255,.15);
}

.format-select {
    height: 28px;
    padding: 0 7px;
    border: 1px solid rgba(255,255,255,.22);
    border-radius: 4px;
    font-size: .78rem;
    background: rgba(255,255,255,.1);
    color: white;
    cursor: pointer;
}
.format-select option { background: #0a09b0; color: white; }

/* Bouton unifie du header */
.hbtn {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    height: 30px;
    padding: 0 9px;
    border: 1px solid rgba(255,255,255,.15);
    border-radius: 4px;
    background: rgba(255,255,255,.08);
    cursor: pointer;
    font-size: .82rem;
    color: rgba(255,255,255,.9);
    white-space: nowrap;
    text-decoration: none;
    transition: background .1s, border-color .1s;
    -webkit-user-select: none;
    user-select: none;
    flex-shrink: 0;
    box-sizing: border-box;
}
.hbtn:hover {
    background: rgba(255,255,255,.18);
    border-color: rgba(255,255,255,.28);
    color: white;
    text-decoration: none;
}
.hbtn:active { background: rgba(255,255,255,.06); }
.hbtn-save {
    background: #16a34a;
    border-color: transparent;
    color: white;
}
.hbtn-save:hover { background: #15803d; color: white; }
.hbtn-ai {
    background: rgba(255,255,255,.16);
    border-color: rgba(255,255,255,.28);
}
.hbtn-formation { background: rgba(56,161,105,.3); border-color: rgba(56,161,105,.5); }
.hbtn-generate  { background: rgba(221,107,32,.35); border-color: rgba(221,107,32,.6); }
.hbtn-view      { background: rgba(37,99,235,.45); border-color: rgba(37,99,235,.65); }
.hbtn-pres      { background: rgba(124,58,237,.45); border-color: rgba(124,58,237,.65); }
/* Variantes toolbar pour boutons ex-header */
.tb-save { background: #16a34a; color: white; border-color: transparent; }
.tb-save:hover { background: #15803d; color: white; }
.tb-ai  { background: #e8f0ff; color: #1a3a8f; border-color: #c0d0f0; }
.tb-ai:hover { background: #d0e0ff; }

/* Separateur vertical dans le header */
.hbtn-sep {
    width: 1px;
    height: 20px;
    background: rgba(255,255,255,.22);
    margin: 0 2px;
    flex-shrink: 0;
    align-self: center;
}

/* ==================== TOOLBAR ==================== */
/* [MODIFIE 2026-07-26] Barre outils unifiee — style traitement de texte */

.editor-menubar {
    display: flex;
    gap: 3px;
    padding: 4px 10px;
    background: #e8ecf5;
    border-bottom: 1px solid #c5cad8;
    align-items: center;
    min-height: 38px;
    flex-wrap: wrap;
    flex-shrink: 0;
    overflow: visible;
    position: relative;
}

.editor-toolbar {
    display: flex;
    gap: 2px;
    padding: 5px 10px;
    background: #f3f4f6;
    border-bottom: 1px solid #d8dce4;
    flex-wrap: wrap;
    align-items: center;
    min-height: 40px;
}

.toolbar-separator {
    width: 1px;
    height: 20px;
    background: #c5c9d0;
    margin: 0 3px;
    flex-shrink: 0;
    align-self: center;
}

.word-count {
    margin-left: auto;
    font-size: 0.8rem;
    color: #666;
    padding: 0 6px;
    white-space: nowrap;
}

.tts-status {
    font-size: 0.8rem;
    color: #888;
    padding: 0.3rem 0.6rem;
    white-space: nowrap;
}

/* Bouton unifie de la toolbar */
.tb {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 28px;
    padding: 0 5px;
    border: 1px solid transparent;
    border-radius: 3px;
    background: transparent;
    cursor: pointer;
    font-size: 13px;
    color: #333;
    text-decoration: none;
    transition: background 0.1s, border-color 0.1s;
    white-space: nowrap;
    flex-shrink: 0;
    -webkit-user-select: none;
    user-select: none;
    line-height: 1;
    box-sizing: border-box;
}
.tb:hover {
    background: #e2e5ea;
    border-color: #c5c9d0;
}
.tb:active {
    background: #d0d7e3;
    border-color: #b0b8c9;
}
.tb.active {
    background: #dce8ff;
    border-color: #aac0f0;
    color: #1a56db;
}
#btnTTS.active,
#btnDictation.active {
    background: #fde8e8;
    border-color: #f5a5a5;
    color: #c0392b;
    animation: tb-pulse 1s infinite;
}

@keyframes tb-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .6; }
}
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: .6; }
}

/* Select integre dans la toolbar */
.tb-select {
    height: 28px;
    padding: 0 8px;
    border: 1px solid #c5c9d0;
    border-radius: 3px;
    font-size: 13px;
    background: white;
    cursor: pointer;
    color: #333;
    align-self: center;
}
.tb-select:hover { border-color: #aac0f0; }
.tb-select:focus {
    outline: none;
    border-color: #4a90d9;
    box-shadow: 0 0 0 2px rgba(74,144,217,.2);
}

/* ==================== MAIN LAYOUT ==================== */

.editor-main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ==================== TABLE DES MATIÈRES (SIDEBAR) ==================== */

.toc-panel {
    width: 250px;
    background: #f8f9fa;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 1rem;
    transition: all 0.3s;
}

.toc-panel.hidden {
    width: 0;
    padding: 0;
    overflow: hidden;
}

.toc-panel h3 {
    margin-bottom: 1rem;
    font-size: 1.1rem;
    color: var(--dark);
}

#tocContent {
    font-size: 0.9rem;
}

.toc-item {
    margin: 2px 0;
}

.toc-item a {
    display: inline;
    padding: 0.4rem 0.5rem;
    color: #666;
    text-decoration: none;
    border-radius: 4px;
    transition: all 0.2s;
    cursor: pointer;
}

.toc-item a:hover {
    background: white;
    color: var(--primary-color);
}

.toc-toggle {
    display: inline-block;
    width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    font-size: 12px;
    font-weight: bold;
    cursor: pointer;
    color: #999;
    border-radius: 3px;
    user-select: none;
    margin-right: 2px;
    vertical-align: middle;
}

.toc-toggle:hover {
    background: #e9ecef;
    color: var(--dark);
}

.toc-children {
    margin-left: 1rem;
}

.toc-item.toc-h1 {
    font-weight: 600;
    margin-top: 0.5rem;
}

.toc-item.toc-h2 {
    padding-left: 0;
    font-weight: 500;
}

.toc-item.toc-h3 {
    padding-left: 0;
    font-size: 0.85rem;
}

 /* NOUVEAU : Numéros de page dans le sommaire */
 
#tocContent .toc-page-number {
    float: right;
    color: #999;
    font-size: 0.85rem;
    font-weight: normal;
}

#tocContent .toc-page-number::before {
    content: ' ';
    display: inline-block;
    width: 100%;
    max-width: 200px;
    border-bottom: 1px dotted #ddd;
    margin: 0 0.5rem;
    vertical-align: middle;
}

/* ==================== EDITOR CONTENT ==================== */

.editor-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.preview-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ==================== DOCUMENT PREVIEW ==================== */

.document-preview {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    background: #e9ecef;
}

/* ==================== CODE SECTION ==================== */

.code-section {
    border-top: 1px solid var(--border);
    background: #f8f9fa;
    padding: 1rem 2rem;
    max-height: 300px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

/* ==================== MODES D'AFFICHAGE ==================== */

/* Par défaut : code caché (évite le flash avant l'init JS) */
.code-section {
    display: none;
}

.editor-content.mode-visual .code-section {
    display: none;
}

/* Source : preview caché, code plein écran */
.editor-content.mode-source .preview-section {
    display: none;
}
.editor-content.mode-source .code-section {
    display: flex;
    flex: 1;
    flex-direction: column;
    max-height: none;
    border-top: none;
    padding: 1rem 2rem;
}
.editor-content.mode-source .markdown-editor {
    flex: 1;
    min-height: 300px;
}

/* Partagé : côte à côte vertical */
.editor-content.mode-split {
    flex-direction: row;
}
.editor-content.mode-split .preview-section {
    flex: 1;
    min-width: 0;
}
.editor-content.mode-split .code-section {
    display: flex;
    flex: 1;
    flex-direction: column;
    max-height: none;
    border-top: none;
    border-left: 1px solid var(--border);
    padding: 1rem 2rem;
    width: 50%;
    min-width: 0;
}
.editor-content.mode-split .markdown-editor {
    flex: 1;
    min-height: 200px;
}

.code-section label {
    font-weight: 600;
    margin-bottom: 0.5rem;
    display: block;
}

.markdown-editor {
    flex: 1;
    width: 100%;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-size: 0.9rem;
    resize: vertical;
    min-height: 200px;
}

/* ==================== STATUS MESSAGE ==================== */

.status-message {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 1rem 1.5rem;
    background: var(--success-color);
    color: white;
    border-radius: 4px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    opacity: 0;
    transform: translateY(20px);
    transition: all 0.3s;
    z-index: 3000;
    max-width: 400px;
    pointer-events: none; /* invisible par defaut : ne doit jamais intercepter de clics (corrige 2026-08-28 : bloquait la sidebar chat IA en bas a droite) */
}

.status-message.show {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto; /* redevient cliquable seulement quand visible (ex: lien dans le message) */
}

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

.status-message a {
    color: white;
    text-decoration: underline;
}

/* ==================== SÉLECTEUR DE FORMAT ==================== */
.format-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.format-select {
    padding: 0.4rem 0.8rem;
    border: 1px solid rgba(255,255,255,0.3);
    border-radius: 4px;
    background: rgba(255,255,255,0.1);
    color: white;
    font-size: 0.9rem;
    cursor: pointer;
    min-width: 200px;
}

.format-select:hover {
    background: rgba(255,255,255,0.2);
}

.format-description {
    font-size: 0.85rem;
    color: rgba(255,255,255,0.7);
    max-width: 300px;
}

/* ==================== INDICATEUR DE PAGE ==================== */
.page-indicator {
    margin-left: 1rem;
    font-size: 0.9rem;
    color: #666;
    padding: 0.5rem 1rem;
    background: var(--light);
    border-radius: 4px;
}

/* ================== Catégories Quick Actions ================ */
.ai-category {
    margin: 0.25rem 0;
}

.ai-category-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1rem;
    background: #f5f5f5;
    border-radius: 4px;
    cursor: pointer;
    user-select: none;
    transition: background 0.2s;
    font-weight: 500;
}

.ai-category-header:hover {
    background: #e8e8e8;
}

.ai-category-arrow {
    font-size: 0.7em;
    color: #666;
    transition: transform 0.2s;
}

.ai-category-content {
    padding-left: 0.5rem;
    margin-top: 0.25rem;
}

.ai-submenu-item {
    font-size: 0.9em;
    padding-left: 2rem !important;
}

/* --------------- */

/* Menu déroulant IA - scrollable */
#aiDropdownMenu {
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid #ddd;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    min-width: 280px;
    max-width: 350px;
    z-index: 1000;
    
    /* AJOUT : Limitation hauteur et scroll */
    max-height: 70vh; /* 70% de la hauteur de l'écran */
    overflow-y: auto;
    overflow-x: hidden;
}

/* Style du scrollbar (optionnel, pour que ce soit joli) */
#aiDropdownMenu::-webkit-scrollbar {
    width: 8px;
}

#aiDropdownMenu::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

#aiDropdownMenu::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

#aiDropdownMenu::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* ==================== MERMAID BLOCK [AJOUTE 2026-07-26] ==================== */
.mermaid-block {
    position: relative;
    display: block;
    margin: 1.2em 0;
    padding: 12px 16px;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
    text-align: center;
}
.mermaid-block pre.mermaid {
    background: transparent !important;
    border: none !important;
    margin: 0;
    padding: 0;
    text-align: center;
}
.mermaid-block pre.mermaid svg {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 0 auto;
}
/* bouton crayon affiché au survol */
.mermaid-edit-btn {
    position: absolute;
    top: 6px; right: 8px;
    background: rgba(255,255,255,.9);
    border: 1px solid #c5c9d0;
    border-radius: 6px;
    padding: 2px 7px;
    font-size: 13px;
    cursor: pointer;
    opacity: 0;
    transition: opacity .15s;
    z-index: 10;
}
.mermaid-block:hover .mermaid-edit-btn { opacity: 1; }

/* éditeur inline */
.mermaid-editor-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
    text-align: left;
}
.mermaid-editor-label {
    font-size: 11px;
    font-weight: 600;
    color: #64748b;
    text-transform: uppercase;
    letter-spacing: .05em;
}
.mermaid-editor-ta {
    width: 100%;
    font-family: 'Fira Mono', 'Consolas', monospace;
    font-size: 13px;
    line-height: 1.5;
    background: #1e1e2e;
    color: #cdd6f4;
    border: 1px solid #45475a;
    border-radius: 6px;
    padding: 10px 12px;
    resize: vertical;
    box-sizing: border-box;
    outline: none;
}
.mermaid-editor-ta:focus { border-color: #89b4fa; }
.mermaid-editor-toolbar {
    display: flex;
    gap: 8px;
}
.mermaid-btn-ok {
    background: #16a34a; color: #fff;
    border: none; border-radius: 6px;
    padding: 5px 14px; font-size: 13px;
    font-weight: 600; cursor: pointer;
}
.mermaid-btn-ok:hover { background: #15803d; }
.mermaid-btn-cancel {
    background: #f1f5f9; color: #475569;
    border: 1px solid #cbd5e1; border-radius: 6px;
    padding: 5px 14px; font-size: 13px;
    cursor: pointer;
}
.mermaid-btn-cancel:hover { background: #e2e8f0; }

