/* === VARIABLES & THÈME === */
:root {
    --bg-color: #fcfbf9;
    --panel-bg: #ffffff;
    --ink-dark: #2c3e50;
    --ink-light: #596a7b;
    --gold: #c5a059;
    --gold-hover: #b08d4a;
    --border-color: #e2dcd0;
}

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--ink-dark);
    height: 100vh;
    display: flex;
    flex-direction: column;
}

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

.logo {
    font-family: "Georgia", serif;
    font-size: 1.5rem;
    color: var(--gold);
    font-weight: bold;
    font-style: italic;
}

main {
    display: flex;
    flex: 1;
    overflow: hidden;
}

.pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    overflow-y: auto;
}

/* === PANNEAU GAUCHE === */
.viewer-pane {
    border-right: 2px solid var(--border-color);
    background-color: #eef0f2;
    position: relative;
}

#drop-zone {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    border: 3px dashed var(--ink-light);
    border-radius: 12px;
    background-color: rgba(255, 255, 255, 0.5);
    transition: all 0.3s ease;
    cursor: pointer;
    text-align: center;
    padding: 40px;
}

#drop-zone.dragover {
    background-color: rgba(197, 160, 89, 0.1);
    border-color: var(--gold);
}

#drop-zone:hover {
    background-color: #ffffff;
}

#drop-zone h2 {
    color: var(--ink-dark);
    margin-bottom: 10px;
}

#drop-zone p {
    color: var(--ink-light);
}

#file-input {
    display: none;
}

#viewer-toolbar {
    display: none;
    justify-content: space-between;
    margin-bottom: 15px;
}

.secondary-btn {
    background-color: var(--panel-bg);
    border: 1px solid var(--border-color);
    padding: 8px 15px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--ink-dark);
    transition: all 0.2s;
}

.secondary-btn:hover {
    border-color: var(--gold);
    background-color: #faf9f7;
}

.btn-danger:hover {
    border-color: #e74c3c;
    color: #e74c3c;
}

#document-viewer {
    display: none;
    flex-direction: column;
    height: 100%;
}

#main-image-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    margin-bottom: 15px;
}

#main-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* Galerie et Miniatures */
#thumbnails {
    display: flex;
    gap: 15px;
    overflow-x: auto;
    padding: 10px 0;
    min-height: 110px;
}

.thumbnail-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 60px;
    position: relative;
    cursor: grab;
    margin-bottom: 5px;
}

.thumbnail {
    height: 80px;
    width: 60px;
    object-fit: cover;
    border: 2px solid transparent;
    border-radius: 4px;
    opacity: 0.6;
    transition: all 0.2s;
}

.thumbnail.active,
.thumbnail:hover {
    opacity: 1;
    border-color: var(--gold);
}

.file-name {
    font-size: 0.65rem;
    color: var(--ink-light);
    margin-top: 5px;
    text-align: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
}

/* === PANNEAU DROIT === */
.workspace-pane {
    background-color: var(--panel-bg);
}

.tabs {
    display: flex;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 20px;
}

.tab-btn {
    background: none;
    border: none;
    padding: 10px 20px;
    font-size: 1rem;
    font-weight: bold;
    color: var(--ink-light);
    cursor: pointer;
    border-bottom: 3px solid transparent;
    margin-bottom: -2px;
}

.tab-btn.active {
    color: var(--ink-dark);
    border-bottom-color: var(--gold);
}

.tab-content {
    display: none;
    flex: 1;
    flex-direction: column;
}

.tab-content.active {
    display: flex;
}

/* Boîte de Métadonnées */
#metadata-box {
    display: none;
    background: #fff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 15px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.02);
}

.meta-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    font-size: 0.95rem;
}

.meta-item strong {
    color: var(--gold);
    display: block;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 3px;
}

/* Editeur */
.transcription-editor {
    flex: 1;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 20px;
    font-family: "Georgia", serif;
    font-size: 1.1rem;
    line-height: 1.6;
    resize: none;
    outline: none;
    background-color: #faf9f7;
    min-height: 300px;
}

.transcription-editor:focus {
    border-color: var(--gold);
}

#btn-analyser {
    background-color: var(--gold);
    color: white;
    border: none;
    padding: 15px;
    font-size: 1.1rem;
    font-weight: bold;
    border-radius: 8px;
    cursor: pointer;
    margin-bottom: 20px;
    display: none;
    transition: background 0.2s;
}

#btn-analyser:hover:not(:disabled) {
    background-color: var(--gold-hover);
}

#btn-analyser:disabled {
    cursor: not-allowed;
    opacity: 0.8;
}

.disclaimer {
    font-size: 0.85rem;
    color: var(--ink-light);
    margin-top: 10px;
    font-style: italic;
}

/* Chat UI */
#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#chat-input-container {
    display: none;
    display: flex;
    gap: 10px;
    margin-top: 10px;
    border-top: 1px solid var(--border-color);
    padding-top: 15px;
}

#chat-input {
    flex: 1;
    padding: 12px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    outline: none;
    font-size: 1rem;
    resize: none;
    /* Empêche l'utilisateur d'étirer la boîte à la souris */
    overflow: hidden;
    /* Cache l'ascenseur inutile */
    min-height: 45px;
    max-height: 150px;
    /* Taille maximum avant de bloquer */
    box-sizing: border-box;
    font-family: inherit;
    line-height: 1.5;
}

#chat-input:focus {
    border-color: var(--gold);
}

#btn-send-chat {
    background-color: var(--ink-dark);
    color: white;
    border: none;
    padding: 0 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}

#btn-send-chat:hover {
    background-color: var(--gold);
}

/* Design du Chat et de l'Avatar de Pompy */
.chat-message {
    display: flex;
    gap: 12px;
    margin-bottom: 15px;
    align-items: flex-start;
}

.chat-avatar {
    width: 45px;
    height: 45px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--gold);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    flex-shrink: 0;
}

.chat-bubble {
    padding: 12px 18px;
    border-radius: 12px;
    max-width: 80%;
    font-size: 0.95rem;
    line-height: 1.5;
}

.pompy-msg .chat-bubble {
    background-color: #f0f4f8;
    border: 1px solid var(--border-color);
    color: var(--ink-dark);
    border-top-left-radius: 2px;
}

.user-msg {
    flex-direction: row-reverse;
}

.user-msg .chat-bubble {
    background-color: var(--ink-dark);
    color: white;
    border-top-right-radius: 2px;
}

/* ========================================== */
/* STYLE DU RENDU MARKDOWN (RICH TEXT)        */
/* ========================================== */
.rich-text-container {
    font-family: 'system-ui', -apple-system, sans-serif;
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--ink-dark);
}

/* Les titres générés par Pompy (### État Civil) */
.rich-text-container h3 {
    color: var(--gold);
    border-bottom: 1px dashed var(--border-color);
    padding-bottom: 5px;
    margin-top: 25px;
    font-size: 1.2rem;
    font-family: 'Georgia', serif;
    font-style: italic;
}

/* Le design des tableaux (Recensements, Cadastre...) */
.rich-text-container table {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    background-color: white;
    font-size: 0.85rem;
}

.rich-text-container th, 
.rich-text-container td {
    border: 1px solid var(--border-color);
    padding: 10px 12px;
    text-align: left;
}

.rich-text-container th {
    background-color: #f4f1ea;
    color: var(--gold);
    font-weight: bold;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.rich-text-container tr:nth-child(even) {
    background-color: #faf9f7;
}

.rich-text-container tr:hover {
    background-color: #f0eedf;
}

/* Fix pour forcer l'apparition d'un ascenseur horizontal si le tableau est trop large */
.rich-text-container {
    overflow-x: auto;
}

.info-tooltip {
    cursor: help;
    color: var(--gold);
    font-size: 0.9rem;
    display: inline-block;
    width: 18px;
    height: 18px;
    line-height: 18px;
    text-align: center;
    border: 1px solid var(--gold);
    border-radius: 50%;
    font-weight: bold;
    transition: all 0.2s;
}

.info-tooltip:hover {
    background-color: var(--gold);
    color: white;
}