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

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f0f2f5;
    color: #333;
}

.header {
    background: linear-gradient(135deg, #1a3a5c, #2d6a9f);
    color: white;
    padding: 1.2rem 2rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.header .brand { display: flex; align-items: center; gap: 0.8rem; }
.header .brand img { height: 38px; background: white; border-radius: 4px; padding: 3px; }
.header h1 { font-size: 1.4rem; font-weight: 600; }
.header .subtitle { font-size: 0.8rem; opacity: 0.85; }

.header-menu {
    flex: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.header-user { color: white; font-size: 0.85rem; display: flex; align-items: center; gap: 0.8rem; margin-left: auto; }
.header-user a { color: white; }

/* Bouton menu : visible uniquement sur mobile (voir plus bas). */
.nav-toggle {
    display: none;
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    font-size: 1.3rem;
    width: 44px;
    height: 44px;
    border-radius: 8px;
    cursor: pointer;
}

.nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.nav a {
    color: white;
    text-decoration: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.9rem;
    transition: background 0.2s;
}

.nav a:hover, .nav a.active { background: rgba(255,255,255,0.18); }

.container { max-width: 1300px; margin: 0 auto; padding: 2rem; }

.card {
    background: white;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.06);
    padding: 1.8rem;
    margin-bottom: 2rem;
}

.card h2 {
    font-size: 1.2rem;
    color: #1a3a5c;
    margin-bottom: 1.3rem;
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.card h2 i { color: #2d6a9f; }

.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 1.2rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    padding: 1.3rem;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.06);
    text-align: center;
}

.stat-card .number { font-size: 2rem; font-weight: 700; color: #1a3a5c; }
.stat-card .label { color: #777; font-size: 0.82rem; margin-top: 0.2rem; }
.stat-card.warn .number { color: #e08e0b; }
.stat-card.danger .number { color: #c0392b; }

table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table thead { background: #1a3a5c; color: white; }
table th { padding: 0.7rem 0.9rem; text-align: left; font-weight: 600; }
table td { padding: 0.7rem 0.9rem; border-bottom: 1px solid #eef2f7; }
table tbody tr:hover { background: #f8f9fa; }

.badge { padding: 0.2rem 0.7rem; border-radius: 20px; font-size: 0.75rem; font-weight: 600; display: inline-block; white-space: nowrap; }
.badge-a_jour { background: #d4edda; color: #155724; }
.badge-bientot { background: #fff3cd; color: #856404; }
.badge-expire { background: #f8d7da; color: #721c24; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1.2rem; }
.form-group { display: flex; flex-direction: column; gap: 0.3rem; min-width: 0; max-width: 100%; }
.form-group label { font-weight: 600; font-size: 0.82rem; color: #555; }
.form-group label .required { color: #e74c3c; }
.form-group input, .form-group select {
    max-width: 100%;
    padding: 0.6rem 0.9rem; border: 2px solid #e0e4e8; border-radius: 8px;
    font-size: 0.9rem; background: #fafbfc;
}
.form-group input:focus, .form-group select:focus { outline: none; border-color: #2d6a9f; background: white; }

.btn {
    padding: 0.7rem 1.6rem; border: none; border-radius: 8px; font-size: 0.95rem;
    font-weight: 600; cursor: pointer; display: inline-flex; align-items: center; gap: 0.5rem;
    text-decoration: none;
}
.btn-primary { background: linear-gradient(135deg, #1a3a5c, #2d6a9f); color: white; }
.btn-primary:hover { opacity: 0.92; }
.btn-outline { background: transparent; border: 2px solid #2d6a9f; color: #2d6a9f; }
.btn-danger { background: #e74c3c; color: white; }
.btn-warning { background: #e08e0b; color: white; }
.btn-warning:hover { opacity: 0.92; }
.btn-success { background: #27ae60; color: white; }
.btn-success:hover { opacity: 0.92; }
.btn-sm { padding: 0.35rem 0.7rem; font-size: 0.78rem; }

.search-bar { position: relative; margin-bottom: 1.2rem; max-width: 420px; }
.search-bar i { position: absolute; left: 0.9rem; top: 50%; transform: translateY(-50%); color: #999; }
.search-bar input {
    width: 100%; padding: 0.65rem 0.9rem 0.65rem 2.4rem; border: 2px solid #e0e4e8;
    border-radius: 8px; font-size: 0.9rem; background: #fafbfc;
}
.search-bar input:focus { outline: none; border-color: #2d6a9f; background: white; }

.client-picker { position: relative; }
.client-suggestions {
    position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 20;
    background: white; border: 2px solid #e0e4e8; border-radius: 8px;
    max-height: 220px; overflow-y: auto; box-shadow: 0 8px 20px rgba(0,0,0,0.1);
    display: none;
}
.client-suggestions.visible { display: block; }
.client-suggestions .suggestion { padding: 0.6rem 0.9rem; cursor: pointer; font-size: 0.9rem; }
.client-suggestions .suggestion:hover, .client-suggestions .suggestion.active { background: #eef2f7; }
.client-suggestions .aucun-resultat { padding: 0.6rem 0.9rem; color: #999; font-size: 0.85rem; }
.client-picker .erreur-client { color: #c0392b; font-size: 0.8rem; margin-top: 0.3rem; display: none; }
.client-picker .erreur-client.visible { display: block; }

.alert { padding: 0.9rem 1.3rem; border-radius: 8px; margin-bottom: 1.5rem; font-size: 0.9rem; }
.alert-success { background: #d4edda; color: #155724; }
.alert-error { background: #f8d7da; color: #721c24; }

.section-title { color: #1a3a5c; font-size: 0.95rem; margin: 1.2rem 0 0.8rem; font-weight: 600; }

.garanties-row { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr auto; gap: 0.6rem; margin-bottom: 0.6rem; align-items: end; }

/* ------------------------------------------------------------------
   Mobile / tablette
   ------------------------------------------------------------------ */
@media (max-width: 900px) {
    .header { padding: 0.8rem 1rem; }
    .header .brand img { height: 32px; }
    .header h1 { font-size: 1.15rem; }
    .nav-toggle { display: inline-flex; align-items: center; justify-content: center; }

    /* Menu replié par défaut, déplié par le bouton ☰. */
    .header-menu { display: none; flex-basis: 100%; flex-direction: column; align-items: stretch; gap: 0; }
    .header.menu-ouvert .header-menu { display: flex; }
    .nav { flex-direction: column; gap: 0.2rem; padding-top: 0.5rem; }
    .nav a { padding: 0.75rem 0.9rem; font-size: 1rem; }
    .header-user {
        justify-content: space-between;
        margin-left: 0; margin-top: 0.5rem; padding: 0.8rem 0.9rem 0.2rem;
        border-top: 1px solid rgba(255,255,255,0.25);
        font-size: 0.95rem;
    }
}

@media (max-width: 600px) {
    /* Jamais de défilement horizontal de la page sur téléphone (les grands
       tableaux défilent dans leur propre cadre). */
    html, body { overflow-x: hidden; }
    .container { padding: 1rem; }
    .form-grid { grid-template-columns: 1fr; }

    /* Garanties (Nouvelle police) : nature du risque sur toute la largeur,
       puis les montants deux par deux. */
    .garanties-row {
        grid-template-columns: 1fr 1fr; align-items: end;
        padding-bottom: 0.8rem; border-bottom: 1px solid #eef2f7;
    }
    .garanties-row > * { min-width: 0; }
    .garanties-row .form-group:first-child { grid-column: 1 / -1; }
    .garanties-row input { width: 100%; }
    .card { padding: 1.1rem; border-radius: 10px; margin-bottom: 1.2rem; }
    .stats { grid-template-columns: repeat(2, 1fr); gap: 0.7rem; margin-bottom: 1.2rem; }
    .stat-card { padding: 0.9rem 0.6rem; }
    .stat-card .number { font-size: 1.6rem; }
    .search-bar { max-width: none; }
}

/* Tableau affiché en cartes sur mobile (une carte par ligne) : chaque
   cellule porte son intitulé dans data-label. */
@media (max-width: 760px) {
    .table-cartes thead { display: none; }
    .table-cartes, .table-cartes tbody, .table-cartes tr, .table-cartes td { display: block; width: 100%; }
    .table-cartes tr {
        background: white; border: 1px solid #e3e8ef; border-radius: 10px;
        margin-bottom: 0.9rem; padding: 0.4rem 0.9rem;
        box-shadow: 0 1px 4px rgba(0,0,0,0.05);
    }
    .table-cartes tbody tr:hover { background: white; }
    .table-cartes td {
        display: flex; justify-content: space-between; align-items: center; gap: 1rem;
        padding: 0.5rem 0; border-bottom: 1px solid #f0f2f5; text-align: right;
    }
    .table-cartes td::before { content: attr(data-label); font-weight: 600; color: #666; text-align: left; flex-shrink: 0; }
    .table-cartes td:last-child { border-bottom: none; }
    .table-cartes td.actions { flex-wrap: wrap; justify-content: flex-start; gap: 0.4rem; text-align: left; padding-top: 0.7rem; }
    .table-cartes td.actions::before { width: 100%; }
    .table-cartes td.actions br { display: none; }
    .table-cartes td.actions .btn { margin-top: 0 !important; }
}

/* Note de l'assureur (formulaire client) */
.form-group textarea {
    max-width: 100%; min-height: 4.5rem; resize: vertical;
    padding: 0.6rem 0.9rem; border: 2px solid #e0e4e8; border-radius: 8px;
    font-size: 0.9rem; font-family: inherit; background: #fafbfc;
}
.form-group textarea:focus { outline: none; border-color: #2d6a9f; background: white; }
.form-group.pleine-largeur { grid-column: 1 / -1; }

/* Fenêtre "fiche client" (includes/fiche-client.js) */
.lien-fiche { background: none; border: none; padding: 0; font: inherit; color: #1a3a5c; cursor: pointer; text-align: left; }
.lien-fiche:hover { text-decoration: underline; }
dialog.fiche-client {
    width: min(520px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow-y: auto;
    margin: auto; border: none; border-radius: 12px; padding: 1.4rem 1.5rem;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3); color: #333;
}
dialog.fiche-client::backdrop { background: rgba(26,58,92,0.45); }
.fiche-client-entete { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1rem; }
.fiche-client-entete h3 { color: #1a3a5c; font-size: 1.15rem; overflow-wrap: anywhere; }
.fiche-client-entete .fiche-client-fermer { background: none; border: none; font-size: 1.3rem; color: #888; cursor: pointer; line-height: 1; padding: 0.2rem; }
.fiche-client-entete .fiche-client-fermer:hover { color: #333; }
.fiche-client-infos { display: grid; grid-template-columns: max-content 1fr; gap: 0.45rem 1rem; font-size: 0.92rem; }
.fiche-client-infos dt { font-weight: 600; color: #555; }
.fiche-client-infos dd { overflow-wrap: anywhere; }
.fiche-client-note-titre { margin-top: 1.2rem; font-weight: 600; color: #1a3a5c; font-size: 0.92rem; }
.fiche-client-note {
    margin-top: 0.4rem; padding: 0.8rem 1rem; background: #fff8e1; border-left: 4px solid #f0b429;
    border-radius: 6px; white-space: pre-wrap; overflow-wrap: anywhere; font-size: 0.92rem;
}
.fiche-client-note.vide { background: #f5f6f8; border-left-color: #ccd4de; color: #888; font-style: italic; }
.fiche-client-pied { margin-top: 1.2rem; text-align: right; }
@media (max-width: 600px) {
    .fiche-client-infos { grid-template-columns: 1fr; gap: 0.1rem; }
    .fiche-client-infos dd { margin-bottom: 0.5rem; }
}

/* Compteurs du tableau de bord cliquables (includes/stats-polices.php) */
button.stat-card { border: none; font: inherit; width: 100%; cursor: pointer; transition: transform 0.15s, box-shadow 0.15s; }
button.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(0,0,0,0.12); }
dialog.liste-stats { width: min(900px, calc(100% - 32px)); }
dialog.liste-stats table { font-size: 0.85rem; }
dialog.liste-stats td, dialog.liste-stats th { white-space: nowrap; }
.liste-stats-vide { color: #999; text-align: center; padding: 1.5rem 0; }
