:root {
    --bleu-fonce: #0b3d63;
    --bleu: #4aa8e0;
    --bleu-clair: #163150;
    --orange: #f2812e;
    --orange-fonce: #ffa15c;
    --fond: #0d1117;
    --surface: #161c26;
    --surface-clair: #202a38;
    --bordure: #2c3848;
    --texte: #e7ecf1;
    --texte-att: #93a1b3;
    --vert: #3ddc84;
    --rouge: #ff7474;
    --blanc: #ffffff;
    --radius: 10px;
    --ombre: 0 2px 12px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
}

* { box-sizing: border-box; }

html { background: var(--fond); }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--fond);
    color: var(--texte);
    line-height: 1.5;
}

a { color: var(--bleu); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Layout général ---------- */
.page { min-height: 100vh; display: flex; flex-direction: column; }
.contenu { flex: 1; max-width: 1100px; width: 100%; margin: 0 auto; padding: 24px 16px 60px; }

/* ---------- Header / navigation ---------- */
.topbar {
    background: linear-gradient(135deg, #082c47, var(--bleu-fonce));
    color: var(--blanc);
    box-shadow: var(--ombre);
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-inner {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    height: 60px;
}
.logo {
    font-weight: 700;
    font-size: 1.15rem;
    color: var(--blanc);
    display: flex;
    align-items: center;
    gap: 8px;
    white-space: nowrap;
}
.logo .pin {
    width: 10px; height: 10px;
    background: var(--orange);
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}
.nav-links {
    display: flex;
    gap: 4px;
    align-items: center;
}
.nav-links a {
    color: rgba(255,255,255,0.85);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.92rem;
    font-weight: 500;
}
.nav-links a:hover, .nav-links a.actif {
    background: rgba(255,255,255,0.15);
    color: var(--blanc);
    text-decoration: none;
}
.nav-user {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
}
.nav-user .role-badge {
    background: var(--orange);
    color: var(--blanc);
    padding: 2px 8px;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.burger {
    display: none;
    background: none;
    border: none;
    color: var(--blanc);
    font-size: 1.6rem;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
}

@media (max-width: 768px) {
    .topbar-inner { flex-wrap: wrap; height: auto; min-height: 60px; padding: 8px 16px; }
    .logo { font-size: 1rem; }
    .nav-links {
        display: none;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: #0a2030;
        flex-direction: column;
        padding: 8px;
        gap: 2px;
        box-shadow: var(--ombre);
    }
    .nav-links.ouvert { display: flex; }
    .nav-links a { padding: 14px 14px; font-size: 1rem; }
    .burger { display: block; }
    .nav-user span:first-child { display: none; }
}

/* ---------- Titres ---------- */
h1, h2, h3 { color: var(--texte); margin-top: 0; }
.page-titre {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}
.page-titre h1 { margin: 0; font-size: 1.5rem; }

/* ---------- Boutons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 11px 18px;
    min-height: 44px;
    border-radius: var(--radius);
    font-size: 0.95rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    text-decoration: none;
    transition: filter 0.15s, background 0.15s;
}
.btn:hover { text-decoration: none; filter: brightness(1.08); }
.btn-orange { background: var(--orange); color: var(--blanc); }
.btn-orange:hover { background: #ff9a4d; }
.btn-bleu { background: var(--bleu); color: #07202f; }
.btn-bleu:hover { background: #6bb8e8; }
.btn-gris { background: var(--surface-clair); color: var(--texte); border: 1px solid var(--bordure); }
.btn-gris:hover { background: #293544; }
.btn-rouge { background: var(--rouge); color: #2a0a0a; }
.btn-sm { padding: 8px 12px; min-height: 36px; font-size: 0.82rem; }
.btn-large { padding: 14px 24px; min-height: 50px; font-size: 1.05rem; }
.btn-bloc { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---------- Cartes ---------- */
.carte {
    background: var(--surface);
    border: 1px solid var(--bordure);
    border-radius: var(--radius);
    box-shadow: var(--ombre);
    padding: 20px;
    margin-bottom: 16px;
}

/* Dashboard stat cards */
.stats-grille {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}
.stat-carte {
    background: var(--surface);
    border: 1px solid var(--bordure);
    border-radius: var(--radius);
    box-shadow: var(--ombre);
    padding: 18px;
    border-left: 4px solid var(--bleu);
}
.stat-carte.alerte { border-left-color: var(--orange); }
.stat-carte .stat-valeur { font-size: 2rem; font-weight: 700; color: var(--texte); }
.stat-carte .stat-label { color: var(--texte-att); font-size: 0.85rem; }

.cta-signalement {
    background: linear-gradient(135deg, var(--orange), #c2570f);
    color: var(--blanc);
    border-radius: var(--radius);
    padding: 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 24px;
    box-shadow: var(--ombre);
}
.cta-signalement h2 { color: var(--blanc); margin: 0 0 4px; }
.cta-signalement p { margin: 0; opacity: 0.95; }
.cta-signalement .btn { background: var(--blanc); color: #c2570f; }

/* ---------- Formulaires ---------- */
.form-groupe { margin-bottom: 16px; }
.form-groupe label { display: block; font-weight: 600; margin-bottom: 6px; font-size: 0.9rem; color: var(--texte); }
.form-groupe .aide { font-size: 0.8rem; color: var(--texte-att); margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number],
input[type=file], select, textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid var(--bordure);
    border-radius: 8px;
    font-size: 16px;
    font-family: inherit;
    background: var(--surface-clair);
    color: var(--texte);
}
input::placeholder, textarea::placeholder { color: var(--texte-att); }
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--bleu);
    box-shadow: 0 0 0 3px rgba(74, 168, 224, 0.2);
}
textarea { resize: vertical; min-height: 90px; }

.radio-urgence { display: flex; gap: 8px; flex-wrap: wrap; }
.radio-urgence input { display: none; }
.radio-urgence label {
    padding: 11px 16px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    border-radius: 20px;
    border: 2px solid var(--bordure);
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    margin: 0;
    color: var(--texte-att);
}
.radio-urgence input:checked + label.urgence-basse { border-color: var(--vert); background: rgba(61,220,132,0.12); color: var(--vert); }
.radio-urgence input:checked + label.urgence-moyenne { border-color: var(--bleu); background: var(--bleu-clair); color: var(--bleu); }
.radio-urgence input:checked + label.urgence-haute { border-color: var(--orange); background: rgba(242,129,46,0.15); color: var(--orange); }

/* ---------- Case GMAO ---------- */
.case-gmao {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--texte);
    cursor: pointer;
    min-height: 44px;
}
.case-gmao input[type=checkbox] { width: 20px; height: 20px; accent-color: var(--orange); cursor: pointer; }
.case-gmao-compacte { font-size: 0.78rem; gap: 5px; min-height: auto; }
.case-gmao-compacte input[type=checkbox] { width: 16px; height: 16px; }
.badge-gmao { background: rgba(242,129,46,0.15); color: var(--orange); }

/* ---------- Badges ---------- */
.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.02em;
}
.urgence-basse { background: rgba(61,220,132,0.12); color: var(--vert); }
.urgence-moyenne { background: var(--bleu-clair); color: var(--bleu); }
.urgence-haute { background: rgba(242,129,46,0.15); color: var(--orange); }

.statut-planifie { background: var(--bleu-clair); color: var(--bleu); }
.statut-en-cours { background: rgba(242,129,46,0.15); color: var(--orange); }
.statut-termine { background: rgba(61,220,132,0.12); color: var(--vert); }

.statut-a_acheter { background: rgba(242,129,46,0.15); color: var(--orange); }
.statut-commande { background: var(--bleu-clair); color: var(--bleu); }
.statut-achete { background: rgba(61,220,132,0.12); color: var(--vert); }

.role-admin { background: var(--bleu-fonce); color: var(--blanc); }
.role-collaborateur { background: var(--surface-clair); color: var(--texte); }

/* ---------- Listes / tableaux ---------- */
.liste-item {
    background: var(--surface);
    border: 1px solid var(--bordure);
    border-radius: var(--radius);
    padding: 16px 18px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}
.liste-item:hover { border-color: var(--bleu); }
.liste-item .infos { flex: 1; min-width: 200px; }
.liste-item .infos h3 { margin: 0 0 4px; font-size: 1rem; color: var(--texte); }
.liste-item .meta { font-size: 0.8rem; color: var(--texte-att); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 6px; }
.liste-item .actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.filtres { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; }
.filtres a {
    padding: 9px 14px;
    min-height: 40px;
    display: inline-flex;
    align-items: center;
    border-radius: 20px;
    background: var(--surface);
    border: 1px solid var(--bordure);
    color: var(--texte-att);
    font-size: 0.85rem;
    font-weight: 600;
}
.filtres a.actif { background: var(--bleu); border-color: var(--bleu); color: #07202f; }

table { width: 100%; border-collapse: collapse; background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--radius); overflow: hidden; box-shadow: var(--ombre); }
table th, table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--bordure); font-size: 0.9rem; }
table th { background: var(--bleu-clair); color: var(--bleu); font-weight: 700; }
table tr:last-child td { border-bottom: none; }

/* ---------- Alertes / flash messages ---------- */
.alerte { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px; font-size: 0.9rem; }
.alerte-succes { background: rgba(61,220,132,0.1); color: #6fe8a3; border: 1px solid rgba(61,220,132,0.3); }
.alerte-erreur { background: rgba(255,116,116,0.1); color: #ff9b9b; border: 1px solid rgba(255,116,116,0.3); }

/* ---------- Login ---------- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #061a2b, var(--bleu-fonce));
    padding: 16px;
}
.login-carte {
    background: var(--surface);
    border: 1px solid var(--bordure);
    border-radius: 16px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    padding: 36px 32px;
    width: 100%;
    max-width: 380px;
}
.login-carte .logo-login {
    text-align: center;
    margin-bottom: 24px;
}
.login-carte .logo-login .pin { background: var(--orange); width: 14px; height: 14px; }
.login-carte h1 { text-align: center; font-size: 1.3rem; margin-bottom: 4px; }
.login-carte .sous-titre { text-align: center; color: var(--texte-att); font-size: 0.88rem; margin-bottom: 24px; }

/* ---------- Photo preview / thumbnails ---------- */
.photo-vignette {
    width: 100%;
    max-height: 280px;
    object-fit: cover;
    border-radius: var(--radius);
    border: 1px solid var(--bordure);
    margin-bottom: 12px;
}
.photo-mini {
    width: 56px; height: 56px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--bordure);
}
.galerie-photos {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
    gap: 8px;
    margin-bottom: 12px;
}
.galerie-photos img {
    width: 100%;
    height: 90px;
    object-fit: cover;
    border-radius: 8px;
    border: 1px solid var(--bordure);
    cursor: pointer;
}

.empty-state {
    text-align: center;
    padding: 50px 20px;
    color: var(--texte-att);
}
.empty-state .icone { font-size: 2.5rem; margin-bottom: 10px; }

.detail-grille {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 16px;
}
@media (max-width: 768px) {
    .detail-grille { grid-template-columns: 1fr; }
}

/* ---------- Ajustements tactiles mobile ---------- */
@media (max-width: 480px) {
    .contenu { padding: 16px 12px 50px; }
    .page-titre h1 { font-size: 1.3rem; }
    .liste-item { padding: 14px; }
    table th, table td { padding: 10px 8px; font-size: 0.82rem; }
}
