/* ==========================================================================
   SENTINELLE — Système de design 2026
   Outil professionnel de l'État — sobre, lisible, tactile.
   ========================================================================== */

@font-face {
    font-family: 'Montserrat';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('../assets/fonts/montserrat-latin.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122;
}
@font-face {
    font-family: 'Montserrat';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('../assets/fonts/montserrat-latin-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+1E00-1E9F, U+2020, U+20A0-20AB, U+20AD-20C0;
}

:root {
    --marine: #000051;
    --marine-700: #1a2472;
    --marine-600: #27339b;
    --marine-100: #e7e9f6;
    --bg: #eef0f5;
    --card: #ffffff;
    --border: #d5d9e6;
    --border-strong: #aab1c9;
    --text: #1a1d29;
    --text-muted: #5a6072;
    --danger: #c62828;
    --danger-bg: #fdecea;
    --success: #1b7a3d;
    --success-bg: #e6f4ea;
    --warning: #9a6a00;
    --warning-bg: #fdf3d7;
    --radius: 10px;
    --radius-sm: 8px;
    --shadow: 0 1px 3px rgba(13, 18, 60, .08), 0 4px 14px rgba(13, 18, 60, .06);
    --focus: 0 0 0 3px rgba(39, 51, 155, .35);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    font-family: 'Montserrat', system-ui, -apple-system, 'Segoe UI', sans-serif;
    background-color: var(--bg);
    color: var(--text);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    line-height: 1.5;
}

/* ==========================================================================
   Barre supérieure
   ========================================================================== */

.topbar {
    background: var(--marine);
    color: #fff;
    padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 12px;
    display: flex;
    align-items: center;
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 900;
    box-shadow: 0 2px 8px rgba(0, 0, 30, .25);
}

.topbar .brand {
    flex: 1;
    min-width: 0;
    text-align: center;
}

.topbar .brand .title {
    font-size: 17px;
    font-weight: 700;
    letter-spacing: .12em;
    margin: 0;
    line-height: 1.2;
}

.topbar .brand .subtitle {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: .18em;
    margin: 0;
    color: rgba(255, 255, 255, .75);
    text-transform: uppercase;
}

.topbar-btn {
    background: rgba(255, 255, 255, .1);
    border: 1px solid rgba(255, 255, 255, .25);
    color: #fff;
    width: 40px;
    height: 40px;
    min-width: 40px;
    border-radius: var(--radius-sm);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    text-decoration: none;
    transition: background .15s;
}
.topbar-btn:hover { background: rgba(255, 255, 255, .2); }
.topbar-btn svg { width: 20px; height: 20px; }
.topbar-btn.danger { border-color: rgba(255, 120, 120, .6); color: #ffb4b4; }

/* ==========================================================================
   Conteneurs et cartes
   ========================================================================== */

.page {
    max-width: 720px;
    margin: 0 auto;
    padding: 20px 16px calc(env(safe-area-inset-bottom, 0px) + 32px);
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 16px;
}

.card-title {
    font-weight: 700;
    font-size: 15px;
    color: var(--marine);
    margin: 0 0 14px;
    text-transform: uppercase;
    letter-spacing: .06em;
    display: flex;
    align-items: center;
    gap: 8px;
}
.card-title svg { width: 18px; height: 18px; opacity: .8; }

.hint {
    font-size: 13px;
    color: var(--text-muted);
    margin: 4px 0 10px;
}

/* ==========================================================================
   Formulaires
   ========================================================================== */

.input-field,
.select-field,
.input-field-contexte,
.input-inline {
    width: 100%;
    min-height: 46px;
    padding: 11px 12px;
    margin-bottom: 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    font-size: 16px;
    font-family: inherit;
    color: var(--text);
    background: #fff;
    appearance: none;
    -webkit-appearance: none;
}

.select-field {
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235a6072' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 38px;
}

.input-field::placeholder,
.input-field-contexte::placeholder {
    color: #8b91a5;
    font-style: normal;
}

.input-field:focus,
.select-field:focus,
.input-field-contexte:focus,
.input-inline:focus {
    outline: none;
    border-color: var(--marine-600);
    box-shadow: var(--focus);
}

.input-field-contexte {
    min-height: 140px;
    resize: vertical;
    line-height: 1.5;
}

.field-label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 5px;
}

/* ==========================================================================
   Boutons
   ========================================================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 46px;
    padding: 11px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    width: 100%;
    transition: background .15s, border-color .15s;
}
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.btn-primary { background: var(--marine); color: #fff; }
.btn-primary:hover { background: var(--marine-700); }

.btn-secondary {
    background: #fff;
    color: var(--marine);
    border-color: var(--border-strong);
}
.btn-secondary:hover { background: var(--marine-100); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger-outline {
    background: #fff;
    color: var(--danger);
    border-color: var(--danger);
}
.btn-danger-outline:hover { background: var(--danger-bg); }

.btn-validate {
    background: var(--marine);
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: .05em;
    min-height: 54px;
    box-shadow: var(--shadow);
}
.btn-validate:hover { background: var(--marine-700); }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1; min-width: 130px; width: auto; }

/* Espace entre le bouton « Retirer » d'une entrée dynamique et le bouton « Ajouter » qui suit */
.agent-entry .btn-danger-outline,
.contrevenant-entry .btn-danger-outline,
.infractions-entry .btn-danger-outline,
.apprehension-entry .btn-danger-outline,
.scelles-entry .btn-danger-outline {
    margin-top: 4px;
    margin-bottom: 14px;
}

/* ==========================================================================
   Interrupteurs et cases
   ========================================================================== */

.toggle-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 10px;
    font-weight: 600;
    font-size: 14px;
    color: var(--text-muted);
}

.switch { position: relative; display: inline-block; width: 54px; height: 30px; }
.switch input { display: none; }

.slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background: #cdd2e0;
    border-radius: 30px;
    transition: .25s;
}
.slider:before {
    position: absolute;
    content: "";
    height: 24px;
    width: 24px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: .25s;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
}
input:checked + .slider { background: var(--marine-600); }
input:checked + .slider:before { transform: translateX(24px); }

.attestation {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    background: var(--marine-100);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 14px;
    margin-bottom: 12px;
}
.attestation input[type="checkbox"] {
    width: 24px;
    height: 24px;
    min-width: 24px;
    margin-top: 2px;
    accent-color: var(--marine);
}
.attestation label { font-size: 14.5px; font-weight: 600; color: var(--marine); }

.radio-list label {
    display: grid;
    grid-template-columns: 22px 1fr;
    column-gap: 12px;
    align-items: start;
    padding: 10px 4px;
    font-size: 15px;
    line-height: 1.5;
}
.radio-list input[type="radio"] {
    width: 20px;
    height: 20px;
    margin: 0;
    accent-color: var(--marine);
    transform: translateY(2px);
}
.input-inline { display: block; width: 100%; margin: 6px 0; }

/* ==========================================================================
   Grille d'accueil
   ========================================================================== */

.grid-container {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 14px;
}
.grid-container a { text-decoration: none; display: block; }
.grid-container a:has(.grid-item.wide) { grid-column: 1 / -1; }

.grid-item {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 26px 12px;
    text-align: center;
    color: var(--marine);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    min-height: 128px;
    height: 100%;
    box-sizing: border-box;
    justify-content: center;
    transition: border-color .15s, transform .1s;
    position: relative;
}
.grid-item:hover { border-color: var(--marine-600); }
.grid-item:active { transform: scale(.98); }
.grid-item svg { width: 34px; height: 34px; }
.grid-item .grid-text {
    font-weight: 700;
    font-size: 13.5px;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.grid-item.wide { grid-column: 1 / -1; min-height: 100px; }

.badge {
    position: absolute;
    top: 10px;
    right: 10px;
    background: var(--danger);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    min-width: 22px;
    height: 22px;
    border-radius: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
}

/* ==========================================================================
   Connexion
   ========================================================================== */

body.login-page {
    background: var(--marine);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-form {
    background: var(--card);
    border-radius: 14px;
    padding: 36px 28px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 40px rgba(0, 0, 20, .45);
    text-align: center;
}
.login-logo { width: 96px; height: auto; margin-bottom: 8px; }
.login-form .title {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: .14em;
    color: var(--marine);
    margin: 0;
}
.login-form .subtitle {
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .2em;
    color: var(--text-muted);
    margin: 2px 0 24px;
    text-transform: uppercase;
}

.alert {
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 14px;
    text-align: left;
}
.alert-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #f0b8b4; }
.alert-success { background: var(--success-bg); color: var(--success); border: 1px solid #b7dfc4; }
.alert-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid #ecd9a0; }

/* ==========================================================================
   Résultats de recherche
   ========================================================================== */

.result-block {
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    margin-top: 10px;
    background: #fafbfe;
    font-size: 14px;
    word-wrap: break-word;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.result-block:hover { border-color: var(--marine-600); background: var(--marine-100); }
.result-block p { margin: 3px 0; }
.result-block p strong { color: var(--marine); }
.unavailable { color: var(--danger); font-weight: 600; }

/* ==========================================================================
   Photos
   ========================================================================== */

.photo-preview-container {
    margin-top: 14px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.photo-wrapper { position: relative; }
.photo-preview {
    width: 104px;
    height: 104px;
    object-fit: cover;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    display: block;
}
.button-remove-photo {
    position: absolute;
    top: 6px;
    right: 6px;
    border: none;
    border-radius: 6px;
    background: rgba(198, 40, 40, .92);
    color: #fff;
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.button-remove-photo svg { width: 15px; height: 15px; }

/* ==========================================================================
   Signature
   ========================================================================== */

#signature-pad, .signature-pad {
    width: 100%;
    height: 190px;
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    background: #fff;
    cursor: crosshair;
    touch-action: none;
    display: block;
}

/* ==========================================================================
   Cartes Leaflet
   ========================================================================== */

.map-embed {
    width: 100%;
    height: 400px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-strong);
    z-index: 1;
}

/* Hors de la couverture IGN (haute mer), le fond prend la teinte de la mer
   du Plan IGN : la carte reste lisible au lieu d'afficher du vide. */
.leaflet-container { background: #AAD5E9; }
.map-image { width: 100%; height: auto; margin-top: 12px; border-radius: var(--radius-sm); border: 1px solid var(--border); }

/* Page carto plein écran */
body.carto-page { display: flex; flex-direction: column; height: 100dvh; overflow: hidden; }
.carto-main { flex: 1; position: relative; min-height: 0; }
#carto-map { position: absolute; inset: 0; }

.layer-panel {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 800;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: min(310px, calc(100vw - 24px));
    max-height: calc(100% - 24px);
    overflow: auto;
}
.layer-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 14px;
    font-weight: 700;
    font-size: 14px;
    color: var(--marine);
    cursor: pointer;
    user-select: none;
}
.layer-panel-body { padding: 0 14px 12px; border-top: 1px solid var(--border); }
.layer-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 0;
    font-size: 14px;
    font-weight: 600;
}
.layer-row input[type="checkbox"] { width: 20px; height: 20px; accent-color: var(--marine); }
.layer-swatch {
    width: 16px;
    height: 16px;
    min-width: 16px;
    border-radius: 4px;
    border: 1.5px solid rgba(0, 0, 0, .35);
}
.layer-section {
    font-size: 11.5px;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: var(--text-muted);
    font-weight: 700;
    margin-top: 10px;
}

.carto-fab {
    position: absolute;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
    right: 12px;
    z-index: 800;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.fab-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--marine);
    color: #fff;
    border: none;
    box-shadow: var(--shadow);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.fab-btn svg { width: 22px; height: 22px; }

.leaflet-popup-content { font-family: 'Montserrat', system-ui, sans-serif; font-size: 13px; line-height: 1.45; }
.leaflet-popup-content .popup-title { font-weight: 700; color: var(--marine); font-size: 13.5px; margin-bottom: 4px; }
.leaflet-popup-content .popup-row { margin: 2px 0; }
.leaflet-popup-content .popup-label { color: var(--text-muted); font-weight: 600; }

/* ==========================================================================
   Page statistiques
   ========================================================================== */

#filter-panel .select-field,
#filter-panel .input-field {
    margin-bottom: 8px;
    min-height: 42px;
}

.stats-float {
    position: absolute;
    bottom: calc(env(safe-area-inset-bottom, 0px) + 14px);
    left: 50%;
    transform: translateX(-50%);
    z-index: 800;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 6px;
    width: max-content;
    max-width: calc(100vw - 150px);
    font-size: 13.5px;
    pointer-events: none;
}
.stat-chip {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 5px 12px;
    font-weight: 600;
    color: var(--text-muted);
    box-shadow: var(--shadow);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}
.stat-chip strong { color: var(--marine); }
.stat-chip-top:empty { display: none; }

/* ==========================================================================
   Dictée vocale
   ========================================================================== */

.textarea-tools { display: flex; justify-content: flex-end; margin-top: -6px; margin-bottom: 8px; }
.mic-btn {
    display: inline-flex;
    align-items: center;
    gap: 7px;
    border: 1px solid var(--border-strong);
    background: #fff;
    color: var(--marine);
    border-radius: 999px;
    padding: 8px 14px;
    font-size: 13.5px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
}
.mic-btn svg { width: 16px; height: 16px; }
.mic-btn.recording {
    background: var(--danger);
    border-color: var(--danger);
    color: #fff;
    animation: mic-pulse 1.2s ease-in-out infinite;
}
@keyframes mic-pulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(198, 40, 40, .45); }
    50% { box-shadow: 0 0 0 8px rgba(198, 40, 40, 0); }
}

/* ==========================================================================
   Divers
   ========================================================================== */

.separator { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

.offline-banner {
    display: none;
    background: var(--warning-bg);
    color: var(--warning);
    border-bottom: 1px solid #ecd9a0;
    text-align: center;
    font-size: 13.5px;
    font-weight: 600;
    padding: 8px 12px;
}
body.is-offline .offline-banner { display: block; }

.queue-card { border-left: none; }
.queue-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
.queue-item:last-child { border-bottom: none; }

#loading-spinner {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    background: var(--marine);
    z-index: 2000;
    transition: opacity .3s;
}
#loading-spinner.hidden { opacity: 0; pointer-events: none; }
.spinner {
    border: 5px solid rgba(255, 255, 255, .25);
    border-top-color: #fff;
    border-radius: 50%;
    width: 48px;
    height: 48px;
    animation: spin .9s linear infinite;
}
.loading-text { margin-top: 14px; font-size: 15px; color: #fff; font-weight: 600; }
@keyframes spin { to { transform: rotate(360deg); } }

.hidden-block { display: none; }

@media (min-width: 768px) {
    .page { padding-top: 28px; }
    .grid-container { grid-template-columns: repeat(3, 1fr); }
    .grid-item.wide { grid-column: 1 / -1; }
}
