:root {
    --navy: #1a2744;
    --navy-light: #24335a;
    --orange-start: #e8590c;
    --orange-end: #f7931e;
    /* Variante plus foncée : garantit un contraste AA (>=4.5:1) pour le texte blanc
       ou les petits libellés sur fond orange — orange-start/end restent réservés
       aux éléments décoratifs larges (logo, bordures) sans texte par-dessus. */
    --orange-deep: #c4470a;
    --bg-warm: #faf6f0;
    --bg-white: #ffffff;
    --text-dark: #1a2744;
    --text-muted: #6b7280;
    --border-light: #e8e2d8;
    --font-sans: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    --font-serif: Georgia, 'Times New Roman', serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font-sans);
    background: var(--bg-warm);
    color: var(--text-dark);
}

.btn-orange {
    background: var(--orange-deep);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
}
.btn-orange:hover { opacity: 0.92; }

.btn-navy {
    background: var(--navy);
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 10px 18px;
    font-size: 0.95rem;
    cursor: pointer;
}

input[type=text], input[type=email], input[type=password], input[type=search], select {
    font-family: var(--font-sans);
    border: 1px solid var(--border-light);
    border-radius: 6px;
    padding: 9px 12px;
    font-size: 0.9rem;
    width: 100%;
}

/* ===== App shell : 3 colonnes ===== */
.app-shell {
    display: grid;
    grid-template-columns: 260px 380px 1fr;
    height: 100vh;
}

.sidebar {
    background: var(--navy);
    color: #fff;
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; margin-bottom: 20px; }
.sidebar .brand img { height: 36px; }
.sidebar .brand-name { font-weight: 700; font-size: 1.1rem; }
.sidebar .brand-sub { font-size: 0.7rem; opacity: 0.7; letter-spacing: 0.05em; }
.sidebar nav ul { list-style: none; padding: 0; margin: 16px 0; }
.sidebar nav li a {
    display: flex; justify-content: space-between; align-items: center;
    color: #d7dce8; text-decoration: none; padding: 9px 10px; border-radius: 8px;
    font-size: 0.92rem; margin-bottom: 2px;
}
.sidebar nav li a.active, .sidebar nav li a:hover { background: var(--navy-light); color: #fff; }
.sidebar nav li a .count {
    background: var(--orange-deep); color: #fff; font-size: 0.72rem;
    border-radius: 10px; padding: 1px 7px;
}
.sidebar .tags-section { margin-top: 12px; }
.sidebar .tags-section h4 { font-size: 0.7rem; text-transform: uppercase; opacity: 0.6; margin: 0 0 8px 4px; }
.sidebar .tag-item { display: flex; align-items: center; gap: 8px; padding: 6px 10px; font-size: 0.88rem; color: #d7dce8; }
.sidebar .tag-dot { width: 8px; height: 8px; border-radius: 50%; }
.sidebar .profile-footer {
    margin-top: auto; display: flex; align-items: center; gap: 10px;
    padding-top: 14px; border-top: 1px solid rgba(255,255,255,0.12);
}
.avatar-circle {
    width: 34px; height: 34px; border-radius: 50%; background: var(--orange-deep);
    color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 700; flex-shrink: 0;
}

/* ===== Liste des messages ===== */
.message-list-col { background: var(--bg-warm); border-right: 1px solid var(--border-light); display: flex; flex-direction: column; overflow: hidden; }
.message-list-header { padding: 20px; }
.message-list-header h1 { font-size: 1.3rem; margin: 0 0 12px; }
.message-list { overflow-y: auto; flex: 1; }
.message-row { padding: 14px 20px; border-bottom: 1px solid var(--border-light); cursor: pointer; position: relative; }
.message-row.unread { background: #fff7f0; }
.message-row.active { background: #fdece0; border-left: 3px solid var(--orange-start); }
.message-row .top-line { display: flex; justify-content: space-between; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 3px; }
.message-row .subject { font-weight: 600; font-size: 0.92rem; margin-bottom: 3px; }
.message-row .snippet { font-size: 0.85rem; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.unread-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--orange-start); display: inline-block; margin-right: 6px; }
.tag-chip { display: inline-block; font-size: 0.7rem; font-weight: 600; padding: 2px 8px; border-radius: 10px; margin-top: 4px; }

/* ===== Volet de lecture ===== */
.reading-pane { display: flex; flex-direction: column; background: var(--bg-white); overflow: hidden; position: relative; }
.reading-toolbar { display: flex; justify-content: space-between; align-items: center; padding: 14px 24px; border-bottom: 1px solid var(--border-light); flex-wrap: wrap; gap: 10px; }
.reading-toolbar .icon-btn { background: none; border: 1px solid var(--border-light); border-radius: 8px; width: 36px; height: 36px; cursor: pointer; margin-right: 8px; }
.reading-body { padding: 24px; overflow-y: auto; flex: 1; }
.reading-body .subject-serif { font-family: var(--font-serif); font-size: 1.6rem; font-weight: 700; margin: 6px 0 18px; }
.reading-body .sender-line { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; }
.reading-body .sender-name { font-weight: 600; }
.reading-body .sender-email { color: var(--text-muted); font-size: 0.85rem; }
.attachment-chip {
    display: inline-flex; align-items: center; gap: 8px; background: var(--bg-warm);
    border: 1px solid var(--border-light); border-radius: 10px; padding: 8px 14px; margin: 4px 8px 4px 0;
    text-decoration: none; color: var(--text-dark); font-size: 0.85rem;
}
.attachment-remove {
    color: var(--text-muted); cursor: pointer; font-size: 0.8rem; margin-left: 2px;
}
.attachment-remove:hover { color: #c0392b; }
.reply-box { border: 1px solid var(--border-light); border-radius: 10px; padding: 18px; margin-top: 24px; background: var(--bg-warm); }
.signature-block { border-left: 3px solid var(--orange-start); padding-left: 14px; margin-top: 16px; }
.signature-block .sig-name { color: var(--orange-deep); font-weight: 700; }

/* ===== Login ===== */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--navy); }
.login-card { background: #fff; border-radius: 14px; padding: 36px 32px; width: 340px; box-shadow: 0 20px 50px rgba(0,0,0,0.3); }
.login-card img { height: 44px; display: block; margin: 0 auto 18px; }
.login-card h1 { font-size: 1.2rem; text-align: center; margin: 0 0 24px; }
.login-card label { font-size: 0.85rem; font-weight: 600; display: block; margin: 14px 0 6px; }
.login-card .btn-orange { width: 100%; margin-top: 20px; }
.login-error { color: #c0392b; font-size: 0.85rem; margin-top: 10px; text-align: center; }

/* ===== Sélecteur d'étiquette ===== */
.tag-picker {
    position: absolute; top: 60px; right: 24px; background: #fff; border: 1px solid var(--border-light);
    border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.12); padding: 10px; z-index: 20; min-width: 180px;
}
.tag-picker-item { display: flex; align-items: center; gap: 8px; padding: 6px 4px; font-size: 0.85rem; cursor: pointer; }
.tag-picker-item input { margin: 0; }
.tag-picker-dot { width: 8px; height: 8px; border-radius: 50%; }
.sidebar .tag-item { cursor: pointer; border-radius: 6px; }
.sidebar .tag-item:hover, .sidebar .tag-item.active { background: var(--navy-light); }

/* ===== Composeur ===== */
.compose-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.45);
    z-index: 100; align-items: center; justify-content: center;
}
.compose-overlay.open { display: flex; }
.compose-modal {
    background: #fff; border-radius: 14px; width: 560px; max-width: 94vw; max-height: 88vh;
    display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 30px 70px rgba(0,0,0,0.3);
    position: relative; border: 2px dashed transparent; transition: border-color 0.15s ease;
}
.compose-modal.drag-active { border-color: var(--orange-start); }
.compose-modal.drag-active::after {
    content: "Dépose le fichier pour le joindre"; position: absolute; inset: 0; z-index: 5;
    background: rgba(232, 89, 12, 0.08); backdrop-filter: blur(1px);
    display: flex; align-items: center; justify-content: center;
    font-size: 1rem; font-weight: 600; color: var(--orange-deep); pointer-events: none;
}
.compose-header { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--border-light); }
.compose-header h3 { margin: 0; font-size: 1rem; }
.compose-fields { padding: 10px 18px; border-bottom: 1px solid var(--border-light); }
.compose-field { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
.compose-field label { width: 50px; font-size: 0.82rem; color: var(--text-muted); flex-shrink: 0; }
.compose-field input { border: none; padding: 4px 0; font-size: 0.92rem; }
.compose-field input:focus { outline: none; }
.compose-field-row { text-align: right; }
.cc-toggle { background: none; border: none; color: var(--text-muted); font-size: 0.8rem; cursor: pointer; }
.compose-body {
    flex: 1; min-height: 200px; padding: 16px 18px; overflow-y: auto; font-size: 0.92rem; line-height: 1.5;
}
.compose-body:focus { outline: none; }
.compose-attachments { padding: 0 18px; display: flex; flex-wrap: wrap; gap: 8px; }
.compose-footer { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-top: 1px solid var(--border-light); }
.compose-status { padding: 10px 18px; font-size: 0.85rem; }
.compose-status.err { color: #c0392b; }
.compose-status.ok { color: #1e7e34; }
.quoted-original { border-left: 2px solid var(--border-light); padding-left: 12px; margin-top: 16px; color: var(--text-muted); }

@media (max-width: 640px) {
    .compose-modal { width: 100vw; max-width: 100vw; height: 100vh; max-height: 100vh; border-radius: 0; }
}

/* ===== Responsive ===== */
@media (max-width: 1023px) {
    .app-shell { grid-template-columns: 0 380px 1fr; }
    .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform 0.2s ease; }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 40; }
    .sidebar-overlay.open { display: block; }
    .mobile-menu-btn { display: inline-flex; }
}

@media (min-width: 1024px) {
    .mobile-menu-btn { display: none; }
    .sidebar-overlay { display: none; }
}

@media (max-width: 640px) {
    .app-shell { grid-template-columns: 1fr; height: calc(100vh - 60px); padding-bottom: 60px; position: relative; }
    .message-list-col, .reading-pane { display: none; }
    .message-list-col.mobile-active, .reading-pane.mobile-active { display: flex; }
    .bottom-tab-bar {
        display: flex; position: fixed; bottom: 0; left: 0; right: 0; height: 60px;
        background: var(--navy); z-index: 30;
    }
    .bottom-tab-bar button {
        flex: 1; background: none; border: none; color: #d7dce8; font-size: 0.7rem;
        display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    }
    .bottom-tab-bar button.active { color: var(--orange-start); }
    .back-btn { display: inline-flex; }

    /* Barre d'outils de lecture : icônes seules, les libellés prennent trop de place */
    .reading-toolbar { padding: 10px 12px; flex-wrap: wrap; gap: 8px; }
    .reading-toolbar .btn-label { display: none; }
    .reading-toolbar .btn-navy { padding: 8px 10px; }
    .reading-body { padding: 16px; }
    .reading-body .subject-serif { font-size: 1.25rem; margin: 4px 0 14px; }
    .message-list-header h1 { font-size: 1.1rem; }
    .tag-picker { right: 12px; left: 12px; top: 54px; }
}

@media (min-width: 641px) {
    .bottom-tab-bar { display: none; }
    .back-btn { display: none; }
}
