:root {
  --bg: #0b1220; --panel: rgba(22,34,60,0.72); --ink: #e6ecf5; --muted: #8595b4;
  --line: rgba(88,110,150,0.25); --accent: #3d8bff; --green: #22c55e; --red: #ef4444;
}
:root[data-theme="light"] {
  --bg: #eef2f8; --panel: rgba(255,255,255,0.9); --ink: #16223c; --muted: #5a6b8c;
  --line: rgba(30,50,90,0.15); --accent: #2563eb;
}
:root[data-theme="light"] .app-bg {
  background:
    radial-gradient(60% 40% at 80% 0%, rgba(37,99,235,0.10), transparent 60%),
    radial-gradient(50% 40% at 10% 100%, rgba(239,68,68,0.08), transparent 60%),
    linear-gradient(180deg,#eef2f8,#e3e9f3);
}
:root[data-theme="light"] input,
:root[data-theme="light"] select { background: rgba(255,255,255,0.9); }

/* Bouton flottant de bascule de thème (visible connexion + app). */
.theme-toggle {
  position: fixed; top: 14px; right: 14px; z-index: 200;
  width: 36px; height: 36px; border-radius: 999px; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); color: var(--ink);
  font-size: 16px; display: flex; align-items: center; justify-content: center;
}
.theme-toggle:hover { filter: brightness(1.15); }

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; font-family: system-ui,"Segoe UI",Roboto,sans-serif;
  background: var(--bg); color: var(--ink); }
.app-bg { position: fixed; inset: 0; z-index: -1;
  background:
    radial-gradient(60% 40% at 80% 0%, rgba(61,139,255,0.16), transparent 60%),
    radial-gradient(50% 40% at 10% 100%, rgba(239,68,68,0.14), transparent 60%),
    linear-gradient(180deg,#0b1220,#0a0f1c); }
.glass { background: var(--panel); border: 1px solid var(--line);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.hidden { display: none !important; }
[hidden] { display: none !important; }
.brand-mark { font-size: 26px; }
.tagline { margin: 0; font-size: 12px; color: var(--muted); }
.field-label { display: block; font-weight: 700; margin: 14px 0 6px; font-size: 13px; color: var(--muted); }
input, select { width: 100%; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px;
  font-size: 15px; background: rgba(11,18,32,0.6); color: var(--ink); }
input:focus, select:focus { outline: none; border-color: var(--accent); }

/* --- Connexion --- */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; border-radius: 20px; padding: 28px; }
.login-switch { text-align: center; font-size: 13px; margin: 12px 0 0; }
.login-switch a { color: var(--accent); font-weight: 700; text-decoration: none; }
.forgot-intro { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 0 0 12px; }

/* Champ mot de passe (afficher/masquer) */
.pw-field { position: relative; }
.pw-field input { padding-right: 44px; }
.pw-eye {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%);
  background: transparent; border: none; cursor: pointer; font-size: 16px;
  padding: 6px; opacity: 0.7; line-height: 1;
}
.pw-eye:hover { opacity: 1; }

/* Spinner des boutons */
.spinner {
  display: inline-block; width: 15px; height: 15px; margin-left: 8px;
  vertical-align: -2px; border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.login-brand { text-align: center; margin-bottom: 10px; }
.login-brand h1 { margin: 8px 0 2px; font-size: 26px; font-weight: 800; }
.btn-primary { width: 100%; margin-top: 20px; padding: 14px; border: none; border-radius: 12px;
  background: linear-gradient(135deg,#529bff,#2b6fd6); color: #fff; font-weight: 800; font-size: 16px; cursor: pointer; }
.btn-primary:hover { filter: brightness(1.08); }
.login-error { color: #ff8181; font-size: 13px; min-height: 18px; margin-top: 10px; text-align: center; }

/* --- App --- */
.app-header { display: flex; align-items: center; justify-content: space-between;
  padding: 12px 18px; position: sticky; top: 0; z-index: 20; border-radius: 0; border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; }
.app-header h1 { margin: 0; font-size: 18px; font-weight: 800; }
.header-right { display: flex; align-items: center; gap: 12px; }
.conn-status { font-size: 15px; }
.conn-status.online { color: #4ade80; } .conn-status.offline { color: #f87171; }
.avail-select { width: auto; padding: 8px 10px; }
.btn-ghost { background: rgba(88,110,150,0.18); color: var(--ink); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 14px; font-weight: 700; cursor: pointer; }

.app-body { display: grid; grid-template-columns: 380px 1fr; height: calc(100vh - 62px); }
.alerts-panel { padding: 16px; overflow-y: auto; border-right: 1px solid var(--line); }
.alerts-panel h2 { font-size: 16px; margin: 4px 0 14px; display: flex; align-items: center; gap: 8px; }
.count { background: var(--red); color: #fff; border-radius: 10px; padding: 1px 9px; font-size: 13px; }
.alerts-list { display: flex; flex-direction: column; gap: 12px; }
.empty { color: var(--muted); text-align: center; padding: 30px 0; }

.alert-card { border-radius: 14px; padding: 14px; border-left: 4px solid var(--accent); animation: slidein 0.3s ease; }
@keyframes slidein { from { opacity: 0; transform: translateX(-8px); } to { opacity: 1; transform: none; } }
.alert-card-head { display: flex; justify-content: space-between; align-items: center; }
.alert-type { font-weight: 800; font-size: 16px; }
.alert-badge { border-radius: 10px; padding: 2px 10px; font-size: 12px; font-weight: 700; }
.alert-meta { color: var(--muted); font-size: 13px; margin: 8px 0; line-height: 1.6; }
/* Médias joints par le citoyen (photo / vocal / vidéo). */
.alert-media { display: flex; flex-direction: column; gap: 8px; margin: 4px 0 10px; }
.alert-media:empty { display: none; }
.alert-photo { max-width: 100%; max-height: 200px; border-radius: 10px;
  border: 1px solid var(--line); cursor: pointer; object-fit: cover; }
.alert-media audio { width: 100%; }
.alert-media .alert-video { width: 100%; max-height: 260px; border-radius: 10px;
  border: 1px solid var(--line); background: #000; }

.alert-actions { display: flex; gap: 8px; }
.alert-actions button { flex: 1; border: none; border-radius: 10px; padding: 9px; font-weight: 700; cursor: pointer; }
.btn-accept { background: var(--green); color: #05230f; }
.btn-locate { background: rgba(88,110,150,0.2); color: var(--ink); }
.btn-complete { background: #ef4444; color: #fff; flex-basis: 100%; margin-top: 6px; }
.alert-card.accepted { border-left-color: var(--green); }

/* Messagerie */
.chat-title { font-size: 15px; margin: 18px 0 10px; border-top: 1px solid var(--line); padding-top: 14px; }
.chat-messages { display: flex; flex-direction: column; gap: 6px; max-height: 240px; overflow-y: auto; margin-bottom: 10px; }
.chat-msg { padding: 7px 11px; border-radius: 10px; font-size: 13px; max-width: 85%; }
.chat-msg .who { font-size: 10px; color: var(--muted); display: block; margin-bottom: 2px; }
.chat-msg.mine { align-self: flex-end; background: rgba(61,139,255,0.18); border: 1px solid rgba(61,139,255,0.4); }
.chat-msg.other { align-self: flex-start; background: rgba(94,234,212,0.12); border: 1px solid rgba(94,234,212,0.3); }
/* Position GPS exacte cliquable (copie) sur les cartes d'alerte. */
.alert-coords { color: var(--accent); font-weight: 600; cursor: pointer; text-decoration: underline dotted; }
.alert-coords:hover { filter: brightness(1.15); }
.alert-approx { color: #f59e0b; font-weight: 700; }
/* Messages non lus depuis la dernière consultation + séparateur de reprise. */
.chat-msg.unread { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.chat-divider-new { align-self: center; margin: 8px 0 4px; font-size: 10px; font-weight: 700;
  letter-spacing: 0.04em; color: var(--accent); }
.chat-date { align-self: center; margin: 6px 0; padding: 3px 12px; border-radius: 10px;
  background: rgba(0,0,0,0.35); color: var(--muted); font-size: 11px; font-weight: 600; }
.chat-input { display: flex; gap: 8px; align-items: center; }
.chat-input input[type=text] { flex: 1; padding: 10px 12px; }
.chat-attach { cursor: pointer; font-size: 18px; padding: 8px 10px; border: 1px solid var(--line);
  border-radius: 10px; background: rgba(11,18,32,0.5); }
.chat-attach.armed { border-color: var(--green); }
.chat-input button { border: none; border-radius: 10px; background: var(--accent); color: #fff;
  font-size: 16px; font-weight: 800; padding: 0 16px; cursor: pointer; }
.chat-msg img { max-width: 180px; border-radius: 8px; margin-top: 6px; display: block; cursor: pointer; }
.chat-msg video.chat-video-msg { max-width: 240px; border-radius: 8px; margin-top: 6px; display: block; }
.chat-tick { display: block; text-align: right; font-size: 11px; color: var(--muted); margin-top: 2px; line-height: 1; }
.chat-tick.read { color: #53bdeb; }
.chat-info-btn { float: right; font-size: 12px; background: transparent; border: 1px solid var(--line);
  color: var(--muted); border-radius: 8px; padding: 3px 8px; cursor: pointer; }
.chat-info-btn.active { border-color: var(--accent); color: var(--accent); }
.chat-info { background: rgba(11,18,32,0.5); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 10px; margin-bottom: 8px; max-height: 180px; overflow-y: auto; }
.chat-info-legend { font-size: 11px; color: var(--muted); margin-bottom: 6px; }
.chat-info-row { display: flex; justify-content: space-between; gap: 8px; font-size: 12.5px;
  padding: 3px 0; border-top: 1px solid rgba(255,255,255,0.05); }
.chat-info-row em { color: var(--muted); font-style: normal; }
.chat-info-row .seen { color: #53bdeb; }
.chat-info-row .unseen { color: var(--muted); }
.chat-mic { font-size: 18px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px;
  background: rgba(11,18,32,0.5); cursor: pointer; }
.chat-mic.recording { border-color: #ef4444; background: rgba(239,68,68,0.18);
  animation: recpulse 1s ease-in-out infinite; }
@keyframes recpulse { 0%,100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.5); } 50% { box-shadow: 0 0 0 6px rgba(239,68,68,0); } }
.chat-rec { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.chat-rec .rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #ef4444;
  animation: recpulse 1s ease-in-out infinite; }
.chat-rec .rec-time { font-weight: 700; color: #ef4444; font-variant-numeric: tabular-nums; }
.chat-voice-preview { display: flex; align-items: center; gap: 8px; margin-top: 8px; }
.chat-voice-preview audio { flex: 1; height: 34px; }
.chat-voice-preview button { border: 1px solid var(--line); border-radius: 8px; background: rgba(11,18,32,0.5);
  color: var(--muted); cursor: pointer; padding: 4px 10px; }
.chat-msg audio.chat-voice { display: block; margin-top: 4px; max-width: 220px; height: 36px; }
.chat-msg .chat-voice-cap { display: block; margin-top: 4px; font-size: 12px; color: var(--muted); }

/* Toast de notification */
.portal-toast {
  position: fixed; top: 74px; right: 18px; z-index: 200;
  background: var(--panel); color: var(--ink); border: 1px solid var(--red);
  border-left-width: 4px; border-radius: 12px; padding: 12px 16px; font-weight: 700;
  max-width: 340px; box-shadow: 0 10px 30px rgba(0,0,0,0.5);
  backdrop-filter: blur(10px); animation: toastin 0.3s ease;
}
@keyframes toastin { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* Fenêtre modale (historique) */
.modal { position: fixed; inset: 0; z-index: 300; display: flex; align-items: center;
  justify-content: center; background: rgba(0,0,0,0.55); }
.modal.hidden { display: none; }
.modal-box { width: 92%; max-width: 560px; max-height: 80vh; border-radius: 16px;
  padding: 18px; display: flex; flex-direction: column; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.modal-head h3 { margin: 0; font-size: 18px; }
.muted { color: var(--muted); font-size: 13px; }
.history-list { overflow-y: auto; margin-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.history-item { background: rgba(11,18,32,0.5); border: 1px solid var(--line);
  border-left-width: 4px; border-radius: 10px; padding: 10px 12px; font-size: 13px; }
.history-item b { font-size: 14px; }

.map-panel { position: relative; }
#map { width: 100%; height: 100%; background: #e9edf2; }
.leaflet-container { background: #e9edf2; }

@media (max-width: 820px) {
  .app-body { grid-template-columns: 1fr; grid-template-rows: 45% 55%; height: calc(100vh - 62px); }
  .alerts-panel { border-right: none; border-bottom: 1px solid var(--line); }
}
