:root {
    --bg: #0a0e13;
    --bg2: #10161d;
    --bg3: #16202b;
    --line: #22303e;
    --txt: #dbe7f1;
    --muted: #6f8aa0;
    --accent: #2ee6a8;
    --accent2: #4db8ff;
    --warn: #ffb454;
    --danger: #ff5b7f;
    --red: #e6484f;
    --red-bg: #2a1215;
    --mono: 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
    background: radial-gradient(1200px 600px at 80% -10%, #0e1a26 0%, var(--bg) 60%) fixed;
    color: var(--txt);
    font: 14px/1.5 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
a { color: var(--accent2); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--mono); background: var(--bg3); padding: 1px 5px; border-radius: 4px; }

/* ---------- Topbar ---------- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 20px;
    background: var(--bg2);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 50;
}
.logo {
    font-size: 20px;
    font-weight: 800;
    letter-spacing: .04em;
    color: var(--accent2);
    display: flex;
    align-items: baseline;
    gap: 10px;
}
.logo small {
    font-size: 11px;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: .12em;
    text-transform: uppercase;
}
.top-actions {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
}
.navlink { color: var(--txt); font-size: 13px; opacity: .85; }
.navlink:hover { opacity: 1; }
.chip {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: .14em;
    padding: 3px 9px;
    border: 1px solid var(--warn);
    color: var(--warn);
    border-radius: 3px;
    white-space: nowrap;
}
.chip.admin { border-color: var(--accent2); color: var(--accent2); }

/* ---------- Layout ---------- */
.layout {
    width: 100%;
    max-width: 1080px;
    margin: 22px auto;
    padding: 0 16px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
}
.foot {
    text-align: center;
    color: var(--muted);
    font-size: 11px;
    padding: 14px;
    border-top: 1px solid var(--line);
}

/* ---------- Panels ---------- */
.panel {
    background: var(--bg2);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}
.panel-head {
    padding: 10px 16px;
    background: var(--bg3);
    border-bottom: 1px solid var(--line);
    font-weight: 700;
    font-size: 13px;
    letter-spacing: .03em;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.panel-body { padding: 16px; }
.count {
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 20px;
    padding: 1px 9px;
}
.empty {
    color: var(--muted);
    padding: 18px 0;
    text-align: center;
}
.hint { color: var(--muted); font-size: 12px; }
.hint-box {
    color: var(--muted);
    padding: 10px 14px;
    line-height: 1.7;
}

/* ---------- Search ---------- */
.search-row { display: flex; gap: 10px; }
.search-row input[type="search"] {
    flex: 1;
    background: var(--bg);
    border: 1px solid var(--line);
    color: var(--txt);
    padding: 11px 14px;
    font-size: 15px;
    border-radius: 6px;
    outline: none;
    font-family: var(--mono);
    letter-spacing: .02em;
}
.search-row input[type="search"]:focus { border-color: var(--accent2); }
.btn {
    display: inline-block;
    background: var(--bg3);
    color: var(--txt);
    border: 1px solid var(--line);
    padding: 9px 16px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { border-color: var(--accent2); text-decoration: none; }
.btn.primary { background: var(--accent2); border-color: var(--accent2); color: #06121c; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.danger { color: var(--danger); border-color: #4a222b; }
.btn.mini { padding: 3px 9px; font-size: 12px; border-radius: 4px; }

.filters { margin-top: 12px; }
.filters summary {
    cursor: pointer;
    color: var(--muted);
    font-size: 12px;
    user-select: none;
}
.filters summary:hover { color: var(--txt); }
.filter-grid {
    margin-top: 10px;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    padding: 12px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
}
.filter-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.filter-grid label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; color: var(--txt); }
.filter-grid input, .filter-grid select {
    background: var(--bg2);
    border: 1px solid var(--line);
    color: var(--txt);
    padding: 7px 9px;
    border-radius: 5px;
    font-size: 13px;
    outline: none;
}
.filter-grid input:focus, .filter-grid select:focus { border-color: var(--accent2); }

/* ---------- Results ---------- */
.results { display: flex; flex-direction: column; }
.result {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px;
    border-bottom: 1px solid var(--line);
    color: var(--txt);
}
.result:hover { background: var(--bg3); text-decoration: none; }
.result:last-child { border-bottom: none; }
.avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 2px solid var(--line);
    flex-shrink: 0;
}
.avatar.big { width: 92px; height: 92px; border-width: 3px; }
.res-main { flex: 1; min-width: 0; }
.res-name { font-weight: 700; font-size: 15px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.res-meta {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 12px;
    margin-top: 3px;
}
.res-reason { color: var(--warn); font-size: 12px; margin-top: 3px; }
.res-ref { color: var(--muted); font-family: var(--mono); font-size: 12px; white-space: nowrap; }

.tag {
    font-size: 11px;
    padding: 1px 8px;
    border: 1px solid var(--line);
    border-radius: 20px;
    color: var(--muted);
}
.tag.red { color: var(--danger); border-color: #4a222b; }

/* ---------- Badges ---------- */
.badge {
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .1em;
    padding: 2px 8px;
    border-radius: 3px;
    white-space: nowrap;
}
.badge.wanted { background: var(--red); color: #fff; }
.badge.closed { background: #2c3a2f; color: #9fe8a8; }
.badge.open { background: #22364a; color: var(--accent2); }
.badge.crime { background: var(--red); color: #fff; }
.badge.delit { background: #7a5222; color: #ffe2ae; }
.badge.contrav { background: #31404d; color: #b8ccda; }
.badge.rne { background: #0b3d2e; color: #6ee7b7; }
.badge.jeu { background: #3b2c0f; color: #fbbf24; }
.src-filter { min-width: 230px; }

/* ---------- Registre sociétés (grand volume) ---------- */
.pager { display: flex; justify-content: flex-end; gap: 10px; margin-top: 12px; }

/* ---------- Fiche société enrichie ---------- */
.estab-card {
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent2);
    border-radius: 6px;
    margin-bottom: 10px;
    overflow: hidden;
}
.estab-head {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px;
    background: rgba(255, 255, 255, .03);
    font-size: 13px;
}
.estab-body { padding: 8px 12px; font-size: 13px; line-height: 1.5; }
.rne-section { margin: 12px 0; }
.rne-title {
    font-size: 11px; font-weight: 800; letter-spacing: .08em;
    color: var(--accent2); margin-bottom: 6px; text-transform: uppercase;
}
.rne-line { display: flex; gap: 14px; align-items: baseline; padding: 3px 0; font-size: 13px; flex-wrap: wrap; }
.rne-line .mono { color: var(--muted); }

/* ---------- Fiche ---------- */
.fiche-toolbar { display: flex; gap: 10px; align-items: center; }
.spacer { flex: 1; }
.wanted-banner {
    background: var(--red-bg);
    border: 1px solid var(--red);
    border-radius: 8px;
    padding: 14px 18px;
    text-align: center;
}
.wanted-title { color: var(--red); font-weight: 900; letter-spacing: .16em; font-size: 15px; }
.wanted-reason { color: var(--txt); margin-top: 5px; font-size: 14px; }
.wanted-since { color: var(--muted); font-size: 12px; margin-top: 3px; }

.identity {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 18px;
    background: var(--bg2);
    border: 1px solid var(--line);
    border-radius: 8px;
    flex-wrap: wrap;
}
.id-main { flex: 1; min-width: 240px; }
.id-name { font-size: 22px; font-weight: 800; letter-spacing: .02em; }
.id-aliases { color: var(--warn); font-size: 13px; margin-top: 2px; font-style: italic; }
.id-ref { color: var(--muted); font-size: 13px; margin-top: 6px; }
.id-signal {
    display: flex;
    gap: 26px;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 18px;
}
.id-signal div { text-align: center; }
.id-signal span { display: block; font-size: 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; }
.id-signal b { font-size: 16px; }

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

table.kv { width: 100%; border-collapse: collapse; }
table.kv th, table.kv td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
    font-size: 13px;
}
table.kv th { color: var(--muted); font-weight: 600; width: 42%; text-align: left; }
table.kv tr:last-child th, table.kv tr:last-child td { border-bottom: none; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th {
    text-align: left;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .08em;
    padding: 8px 12px;
    border-bottom: 1px solid var(--line);
    background: var(--bg);
}
table.data td { padding: 9px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data tbody tr:hover { background: var(--bg3); }
.mono { font-family: var(--mono); }
.plate { font-weight: 800; color: var(--warn); letter-spacing: .06em; }
.note { color: var(--muted); font-size: 12px; margin-top: 2px; }
.notes {
    font-family: var(--mono);
    white-space: pre-wrap;
    font-size: 13px;
    color: var(--txt);
    line-height: 1.6;
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 12px;
}

/* ---------- Login ---------- */
.login-wrap { flex: 1; display: flex; align-items: center; justify-content: center; padding: 30px 16px; }
.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--bg2);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 30px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    text-align: center;
}
.login-logo { font-size: 40px; }
.login-card h1 { font-size: 17px; }
.login-sub { color: var(--muted); font-size: 12px; }
.login-card label { text-align: left; color: var(--muted); font-size: 12px; }
.login-card input {
    background: var(--bg);
    border: 1px solid var(--line);
    color: var(--txt);
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
}
.login-card input:focus { border-color: var(--accent2); }
.login-back { margin-top: 6px; font-size: 12px; color: var(--muted); }
.login-back:hover { color: var(--txt); }

/* ---------- Admin ---------- */
.admin-actions { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; flex-wrap: wrap; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 12px;
    padding: 16px;
}
.form-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-grid label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 13px; color: var(--txt); }
.form-grid label.span2 { grid-column: span 2; }
.form-grid input, .form-grid select, .form-grid textarea {
    background: var(--bg);
    border: 1px solid var(--line);
    color: var(--txt);
    padding: 8px 10px;
    border-radius: 5px;
    font-size: 13px;
    outline: none;
    width: 100%;
}
.form-grid textarea { resize: vertical; font-family: var(--mono); }
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus { border-color: var(--accent2); }
.form-actions { padding: 0 16px 16px; }
.alert {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
}
.alert.danger { background: var(--red-bg); border: 1px solid var(--red); color: #ffb8bd; }
.alert.ok { background: #0f231b; border: 1px solid var(--accent); color: #a3f5d3; }

.inline-edit { border: 1px solid var(--line); border-radius: 6px; margin-bottom: 8px; }
.inline-edit summary { padding: 9px 12px; cursor: pointer; display: flex; align-items: center; gap: 8px; }
.inline-edit summary:hover { background: var(--bg3); }
.inline-edit[open] summary { border-bottom: 1px solid var(--line); background: var(--bg3); }
.inline-edit form { padding: 0 0 12px; }

/* ---------- Print ---------- */
@media print {
    .topbar, .foot, .fiche-toolbar, .btn, .row-actions { display: none !important; }
    body { background: #fff; color: #000; }
    .layout { max-width: 100%; margin: 0; padding: 0; }
    .panel, .identity, .wanted-banner {
        border-color: #999;
        background: #fff;
        color: #000;
        break-inside: avoid;
    }
    .panel-head { background: #eee; color: #000; border-color: #999; }
    table.kv th { color: #333; }
    table.data th { background: #eee; color: #333; border-color: #999; }
    .empty, .note, .res-meta, .id-ref { color: #555; }
    .badge.wanted { background: #000; color: #fff; }
}

/* ============================================================
   FONCTIONNALITÉS AJOUTÉES : dashboard, téléphonie, caméras,
   finance, sociétés, portraits, utilisateurs
   ============================================================ */

/* ---------- Nav ---------- */
.nav-links { display: flex; gap: 4px; flex-wrap: wrap; }
.nav-links .navlink {
    padding: 5px 10px;
    border-radius: 5px;
    font-size: 13px;
    color: var(--muted);
}
.nav-links .navlink:hover { color: var(--txt); background: var(--bg3); text-decoration: none; }
.nav-links .navlink.active { color: var(--accent2); background: var(--bg3); font-weight: 700; }

/* ---------- Dashboard ---------- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
}
.stat {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 14px;
    text-align: center;
    color: var(--txt);
    transition: border-color .15s;
}
.stat:hover { border-color: var(--accent2); text-decoration: none; }
.stat-icon { font-size: 22px; }
.stat-nb { font-size: 26px; font-weight: 800; margin-top: 4px; }
.stat-label { font-size: 11px; color: var(--muted); margin-top: 2px; }
.log-line {
    display: flex;
    gap: 10px;
    align-items: baseline;
    padding: 6px 0;
    border-bottom: 1px solid var(--line);
    font-size: 12px;
}
.log-line:last-child { border-bottom: none; }
.log-who { color: var(--accent2); font-weight: 700; white-space: nowrap; }
.log-what { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.log-when { color: var(--muted); white-space: nowrap; font-size: 11px; }
.alert-list { list-style: none; }
.alert-list li { padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; }
.alert-list li:last-child { border-bottom: none; }

/* ---------- Téléphonie ---------- */
.phone-card, .vehicle-card, .account-card {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 12px;
}
.phone-card:last-child, .vehicle-card:last-child, .account-card:last-child { margin-bottom: 0; }
.phone-head, .vehicle-head, .account-head {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}
.phone-note { color: var(--warn); font-size: 12px; margin-top: 6px; }
.phone-cp { margin-top: 8px; display: flex; flex-direction: column; }
.cp-row {
    display: flex;
    gap: 10px;
    align-items: baseline;
    padding: 5px 0;
    border-bottom: 1px dashed var(--line);
    color: var(--txt);
    font-size: 13px;
    flex-wrap: wrap;
}
.cp-row:hover { background: var(--bg3); text-decoration: none; }
.cp-owner { color: var(--txt); }
.cp-owner.unknown { color: var(--danger); font-style: italic; }
.cp-nb { color: var(--muted); font-size: 12px; }
.cp-last { color: var(--muted); font-size: 11px; margin-left: auto; }

.cp-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
    gap: 10px;
    margin: 12px 0;
}
.cp-card {
    background: var(--bg3);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 10px 12px;
    color: var(--txt);
}
.cp-card:hover { border-color: var(--accent2); text-decoration: none; }
.cp-num { font-size: 15px; }
.cp-stats { color: var(--muted); font-size: 11px; margin-top: 4px; }
.kv-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }

.call-table { font-size: 12.5px; }
.call-table td { padding: 6px 10px; }

/* ---------- Caméras ---------- */
.hits-mini { margin-top: 8px; display: flex; flex-direction: column; gap: 3px; }
.hit-mini { display: flex; gap: 10px; font-size: 12px; align-items: baseline; }
.hit-mini .mono { color: var(--muted); white-space: nowrap; }

/* ---------- Finance ---------- */
.account-balance {
    margin-left: auto;
    font-weight: 800;
    font-family: var(--mono);
    color: var(--accent);
}
.account-balance.neg { color: var(--danger); }
.account-iban { color: var(--muted); font-size: 12px; margin-top: 4px; }
.tx-table { margin-top: 8px; font-size: 12.5px; }
.tx-table td { padding: 6px 10px; }
.mono.neg { color: var(--danger); }
.mono.pos { color: var(--accent); }

/* ---------- Portraits ---------- */
.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
}
.photo-card {
    background: var(--bg);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    text-align: center;
    color: var(--txt);
    padding-bottom: 10px;
}
.photo-card:hover { border-color: var(--accent2); text-decoration: none; }
.photo-card img {
    width: 100%;
    aspect-ratio: 3/4;
    object-fit: cover;
    display: block;
    background: var(--bg3);
}
.photo-name { font-size: 13px; font-weight: 700; padding: 8px 6px 2px; }
.photo-id {
    width: 92px;
    height: 115px;
    object-fit: cover;
    border-radius: 6px;
    border: 2px solid var(--line);
    flex-shrink: 0;
}
.photo-preview { display: flex; gap: 10px; align-items: center; margin-top: 6px; }
.photo-preview img { border-radius: 5px; border: 1px solid var(--line); }

/* ---------- Divers ---------- */
.inline-row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    padding: 8px 0;
    border-bottom: 1px solid var(--line);
    font-size: 13px;
}
.inline-row:last-child { border-bottom: none; }
.btn.danger:hover { border-color: var(--danger); }

#hits-map { z-index: 1; }
.leaflet-container { font: 12px/1.5 system-ui, sans-serif; }

@media print {
    .nav-links, .stats-grid, .log-line, .cp-grid { display: none !important; }
    .phone-card, .vehicle-card, .account-card { border-color: #999; background: #fff; }
    .cp-owner.unknown { color: #333; }
}
