/* ============================================================
   UNIS — Urgences Nationales Interservices de Secours
   Feuille de style principale
   ============================================================ */

:root {
    --unis-navy: #0B1F33;
    --unis-navy-2: #102A44;
    --unis-blue: #155EEF;
    --unis-red: #D92D20;
    --unis-green: #12B76A;
    --unis-orange: #F79009;
    --unis-gray: #F2F4F7;
    --unis-white: #FFFFFF;
    --text-primary: #101828;
    --text-secondary: #475467;
    --text-muted: #667085;
    --border: #E4E7EC;
    --bg-body: #F5F7FA;
    --bg-card: #FFFFFF;
    --bg-sidebar: #0B1F33;
    --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .06);
    --shadow-lg: 0 12px 24px -8px rgba(16, 24, 40, .18);
    --radius: 10px;
    --radius-sm: 6px;
    --font: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    --mono: "JetBrains Mono", "Fira Code", Consolas, monospace;
}

[data-theme="dark"] {
    --text-primary: #F2F4F7;
    --text-secondary: #CBD5E1;
    --text-muted: #98A2B3;
    --border: #1E3A5C;
    --bg-body: #0B1F33;
    --bg-card: #102A44;
    --bg-sidebar: #081829;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
}

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

html { scroll-behavior: smooth; }

body {
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.55;
    color: var(--text-primary);
    background: var(--bg-body);
    transition: background .2s;
}

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

/* ---------- App shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 248px;
    min-height: 100vh;
    background: var(--bg-sidebar);
    color: #CBD5E1;
    display: flex;
    flex-direction: column;
    position: fixed;
    inset: 0 auto 0 0;
    z-index: 50;
    transition: transform .25s ease;
}

.brand {
    display: flex; align-items: center; gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}
.brand-logo {
    width: 40px; height: 40px; flex: 0 0 40px;
    background: linear-gradient(135deg, var(--unis-blue), #4A90F8);
    border-radius: 10px;
    display: grid; place-items: center;
    color: #fff; font-weight: 800; font-size: 16px; letter-spacing: .5px;
}
.brand-name { font-size: 20px; font-weight: 800; color: #fff; letter-spacing: 1.5px; }
.brand-sub { font-size: 10px; color: #7A8FA8; line-height: 1.25; }

.nav { flex: 1; overflow-y: auto; padding: 14px 10px 24px; }
.nav-section { font-size: 10px; text-transform: uppercase; letter-spacing: 1.2px; color: #5D7391; padding: 14px 10px 6px; }
.nav a.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 12px; margin: 1px 0;
    border-radius: 8px;
    color: #B4C4D8; font-weight: 500; font-size: 13px;
    transition: background .15s, color .15s;
}
.nav a.nav-link:hover { background: rgba(255, 255, 255, .06); color: #fff; text-decoration: none; }
.nav a.nav-link.active { background: var(--unis-blue); color: #fff; }
.nav-link .ico { width: 18px; text-align: center; font-size: 15px; flex: 0 0 18px; }
.nav-badge {
    margin-left: auto; font-size: 10px; font-weight: 700;
    background: var(--unis-red); color: #fff; border-radius: 20px; padding: 2px 7px;
}

.sidebar-footer {
    padding: 14px 18px; font-size: 10.5px; color: #5D7391;
    border-top: 1px solid rgba(255, 255, 255, .08); line-height: 1.6;
}

.main { flex: 1; margin-left: 248px; display: flex; flex-direction: column; min-height: 100vh; }

.topbar {
    height: 60px; background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 16px;
    padding: 0 24px; position: sticky; top: 0; z-index: 40;
}
.topbar-title { font-size: 16px; font-weight: 700; }
.topbar-spacer { flex: 1; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }

.content { padding: 24px; flex: 1; }

/* ---------- Boutons ---------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 8px 16px; border-radius: 8px; border: 1px solid transparent;
    font-size: 13px; font-weight: 600; cursor: pointer; font-family: var(--font);
    transition: filter .15s, background .15s, transform .05s;
    white-space: nowrap;
}
.btn:active { transform: scale(.98); }
.btn-primary { background: var(--unis-blue); color: #fff; }
.btn-primary:hover { filter: brightness(1.1); }
.btn-danger { background: var(--unis-red); color: #fff; }
.btn-success { background: var(--unis-green); color: #fff; }
.btn-warning { background: var(--unis-orange); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-secondary); border-color: var(--border); }
.btn-ghost:hover { background: var(--bg-body); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }

/* ---------- Cartes ---------- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.card-header {
    padding: 14px 20px; border-bottom: 1px solid var(--border);
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.card-title { font-size: 14px; font-weight: 700; flex: 1; }
.card-body { padding: 20px; }
.card-footer { padding: 12px 20px; border-top: 1px solid var(--border); display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Stats ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.stat-card .stat-label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--text-muted); font-weight: 600; }
.stat-card .stat-value { font-size: 26px; font-weight: 800; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-card .stat-icon { position: absolute; right: 14px; top: 14px; font-size: 22px; opacity: .18; }
.stat-card.alert { border-left: 4px solid var(--unis-red); }
.stat-card.warn { border-left: 4px solid var(--unis-orange); }
.stat-card.ok { border-left: 4px solid var(--unis-green); }
.stat-card.info { border-left: 4px solid var(--unis-blue); }

/* ---------- Tableaux ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th {
    text-align: left; padding: 10px 14px; font-size: 11px; text-transform: uppercase;
    letter-spacing: .6px; color: var(--text-muted); border-bottom: 1px solid var(--border);
    background: var(--bg-body); white-space: nowrap;
}
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:hover { background: rgba(21, 94, 239, .04); }
.table .actions { display: flex; gap: 6px; white-space: nowrap; }

/* ---------- Badges / puces ---------- */
.badge {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 10px; border-radius: 20px;
    font-size: 11px; font-weight: 700; white-space: nowrap;
}
.badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .85; }
.badge-red { background: rgba(217, 45, 32, .12); color: var(--unis-red); }
.badge-orange { background: rgba(247, 144, 9, .14); color: #B54708; }
[data-theme="dark"] .badge-orange { color: #F79009; }
.badge-blue { background: rgba(21, 94, 239, .12); color: var(--unis-blue); }
.badge-green { background: rgba(18, 183, 106, .14); color: #027A48; }
[data-theme="dark"] .badge-green { color: #32D583; }
.badge-gray { background: var(--unis-gray); color: var(--text-muted); }
.badge-purple { background: rgba(122, 90, 248, .14); color: #7A5AF8; }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; }

/* ---------- Formulaires ---------- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.form-control, .form-select, .form-textarea {
    width: 100%; padding: 9px 12px;
    border: 1px solid var(--border); border-radius: 8px;
    font-size: 13px; font-family: var(--font);
    background: var(--bg-card); color: var(--text-primary);
    transition: border-color .15s, box-shadow .15s;
}
.form-control:focus, .form-select:focus, .form-textarea:focus {
    outline: none; border-color: var(--unis-blue);
    box-shadow: 0 0 0 3px rgba(21, 94, 239, .18);
}
.form-textarea { min-height: 90px; resize: vertical; }
.form-check { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ---------- Alertes / flash ---------- */
.alert {
    padding: 11px 16px; border-radius: 8px; margin-bottom: 16px;
    font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 10px;
}
.alert-success { background: rgba(18, 183, 106, .12); color: #027A48; border: 1px solid rgba(18, 183, 106, .3); }
.alert-error { background: rgba(217, 45, 32, .1); color: var(--unis-red); border: 1px solid rgba(217, 45, 32, .3); }
[data-theme="dark"] .alert-success { color: #32D583; }

/* ---------- Barre de recherche / filtres ---------- */
.filters {
    display: flex; gap: 10px; flex-wrap: wrap; align-items: center;
    padding: 14px 20px; border-bottom: 1px solid var(--border);
}
.filters .form-control, .filters .form-select { width: auto; min-width: 140px; }

/* ---------- Pagination ---------- */
.pagination { display: flex; gap: 6px; align-items: center; justify-content: flex-end; padding: 12px 20px; font-size: 12px; }
.pagination a, .pagination span {
    padding: 5px 11px; border-radius: 6px; border: 1px solid var(--border);
    color: var(--text-secondary); background: var(--bg-card);
}
.pagination a:hover { border-color: var(--unis-blue); color: var(--unis-blue); text-decoration: none; }
.pagination .current { background: var(--unis-blue); color: #fff; border-color: var(--unis-blue); }

/* ---------- Chronologie ---------- */
.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 16px; }
.timeline-item::before {
    content: ""; position: absolute; left: -22px; top: 4px;
    width: 12px; height: 12px; border-radius: 50%;
    background: var(--bg-card); border: 3px solid var(--unis-blue);
}
.timeline-item.warn::before { border-color: var(--unis-orange); }
.timeline-item.danger::before { border-color: var(--unis-red); }
.timeline-item.ok::before { border-color: var(--unis-green); }
.timeline-time { font-size: 11px; color: var(--text-muted); font-family: var(--mono); }
.timeline-action { font-weight: 700; font-size: 12.5px; }

/* ---------- Messages ---------- */
.chat { display: flex; flex-direction: column; max-height: 500px; overflow-y: auto; padding: 16px; gap: 10px; }
.chat-msg { max-width: 78%; padding: 10px 14px; border-radius: 12px; font-size: 13px; }
.chat-msg.mine { align-self: flex-end; background: var(--unis-blue); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg.theirs { align-self: flex-start; background: var(--bg-body); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.chat-msg .meta { font-size: 10.5px; opacity: .75; margin-top: 5px; display: flex; gap: 8px; align-items: center; }

/* ---------- Carte ---------- */
#unis-map { width: 100%; height: 560px; border-radius: var(--radius); z-index: 1; }
.map-toolbar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.leaflet-container { font-family: var(--font); }
.unis-marker { display: grid; place-items: center; width: 26px; height: 26px; border-radius: 50% 50% 50% 4px; transform: rotate(-45deg); color: #fff; font-weight: 800; font-size: 12px; box-shadow: 0 2px 6px rgba(0,0,0,.35); border: 2px solid #fff; }
.unis-marker > span { transform: rotate(45deg); }

/* ---------- Login ---------- */
.auth-body { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(160deg, var(--unis-navy) 0%, #0E2E52 60%, #155EEF 160%); padding: 20px; }
.auth-card { width: 100%; max-width: 420px; }
.auth-logo { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-bottom: 24px; color: #fff; text-align: center; }
.auth-logo .brand-logo { width: 56px; height: 56px; flex-basis: 56px; font-size: 22px; }
.auth-title { font-size: 22px; font-weight: 800; letter-spacing: 1px; }
.auth-sub { font-size: 12px; color: #9FB4CC; max-width: 320px; line-height: 1.5; }
.auth-footer { text-align: center; margin-top: 18px; font-size: 11px; color: #7A8FA8; line-height: 1.7; }

/* ---------- Divers ---------- */
.text-muted { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-red { color: var(--unis-red); }
.text-green { color: var(--unis-green); }
.text-blue { color: var(--unis-blue); }
.text-orange { color: var(--unis-orange); }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.font-bold { font-weight: 700; }
.mono { font-family: var(--mono); font-size: 12px; }
.flex { display: flex; gap: 10px; align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.between { justify-content: space-between; }
.end { justify-content: flex-end; }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 6px; } .mt-2 { margin-top: 12px; } .mt-3 { margin-top: 18px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 6px; } .mb-2 { margin-bottom: 12px; } .mb-3 { margin-bottom: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
@media (max-width: 1100px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

.demo-banner {
    background: linear-gradient(90deg, rgba(247, 144, 9, .16), rgba(217, 45, 32, .12));
    border: 1px solid rgba(247, 144, 9, .35);
    color: var(--text-secondary);
    padding: 10px 16px; border-radius: 8px; font-size: 12px; margin-bottom: 18px;
}

/* ---------- Mode sombre bascule ---------- */
.theme-toggle {
    width: 38px; height: 38px; border-radius: 8px; border: 1px solid var(--border);
    background: var(--bg-card); cursor: pointer; font-size: 16px; color: var(--text-primary);
    display: grid; place-items: center;
}
.theme-toggle:hover { border-color: var(--unis-blue); }

/* ---------- Responsive ---------- */
.menu-toggle { display: none; width: 40px; height: 40px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg-card); font-size: 18px; cursor: pointer; }

@media (max-width: 960px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .main { margin-left: 0; }
    .menu-toggle { display: grid; place-items: center; }
    .content { padding: 16px; }
    .topbar { padding: 0 14px; }
    .hide-mobile { display: none; }
}

/* ---------- Avatar ---------- */
.avatar {
    width: 34px; height: 34px; border-radius: 50%;
    display: grid; place-items: center; font-size: 12px; font-weight: 800;
    color: #fff; background: linear-gradient(135deg, var(--unis-blue), #4A90F8);
}
.avatar-sm { width: 26px; height: 26px; font-size: 10px; }

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #C3CBD9; border-radius: 8px; }
[data-theme="dark"] ::-webkit-scrollbar-thumb { background: #2A4A6E; }