/* ===== Nocturne — style de l'appli First Incendie ===== */
:root {
  --bg: #161826;
  --surface: #232532;
  --surface-2: #2b2e3d;
  --text: #e9e9ed;
  --muted: #9397ab;
  --accent: #9184d9;
  --accent-300: #d2cefd;
  --accent-400: #b5abfc;
  --accent-700: #5d5294;
  --accent-900: #2b2741;
  --neutral-700: #595d6c;
  --neutral-800: #3f424d;
  --danger: #e06a6a;
  --ok: #6ac59a;
  --radius: 8px;
  --radius-lg: 14px;
  --font: "Inter", system-ui, -apple-system, sans-serif;
  --shadow: 0 0 0 1px var(--neutral-800), 0 6px 18px rgba(0,0,0,.55);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: radial-gradient(1200px 600px at 20% -10%, #1b1e30, var(--bg));
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}
.view { min-height: 100vh; }
[hidden] { display: none !important; }

/* Écran de démarrage (anti-flash de la page de connexion) */
.boot { min-height: 100vh; display: grid; place-items: center; }
.spinner {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--neutral-800); border-top-color: var(--accent);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Boutons ---- */
.btn {
  font: inherit;
  border-radius: var(--radius);
  padding: 10px 16px;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  color: var(--text);
  background: transparent;
}
.btn-primary { border-color: var(--accent); color: var(--accent-300); }
.btn-primary:hover { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.btn-primary:active { background: color-mix(in srgb, var(--accent) 26%, transparent); }
.btn-ghost { color: var(--muted); }
.btn-ghost:hover { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }
.btn-block { display: block; width: 100%; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Champs ---- */
.field { display: block; margin-bottom: 14px; }
.field > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--neutral-800);
  border-radius: var(--radius);
  padding: 10px 12px;
}
.input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; border-color: var(--accent); }

/* ---- Connexion ---- */
#login-view { display: grid; place-items: center; padding: 24px; }
.auth-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 28px;
  text-align: center;
}
.brand { font-weight: 500; letter-spacing: .2px; }
.auth-card h1 { font-weight: 500; font-size: 22px; margin: 14px 0 20px; }
.muted { color: var(--muted); font-size: 13px; }
.msg { min-height: 18px; font-size: 13px; margin: 12px 0 0; }
.msg.err { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* ---- Coquille de l'appli (MOBILE FIRST) ---- */
#app-view { position: relative; }
.app-shell { max-width: 480px; margin: 0 auto; min-height: 100vh; display: flex; flex-direction: column; }

/* Barre du haut */
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 16px;
  background: var(--surface); border-bottom: 1px solid var(--neutral-800);
}
.topbar .brand { font-size: 16px; font-weight: 600; }
.hamburger {
  background: transparent; border: 0; padding: 8px; margin: -8px; cursor: pointer;
  display: flex; flex-direction: column; gap: 4px;
}
.hamburger span { display: block; width: 22px; height: 2px; background: var(--text); border-radius: 1px; }
.hamburger:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.topbar-avatar {
  width: 34px; height: 34px; flex: none; border-radius: 50%;
  background: var(--accent-900); color: var(--accent-300); border: 1px solid var(--accent-700);
  display: grid; place-items: center; font-size: 13px; font-weight: 600;
}

/* Menu coulissant */
.drawer-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 10; }
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 11;
  width: 80%; max-width: 300px;
  background: var(--surface); box-shadow: 6px 0 24px rgba(0,0,0,.5);
  padding: 20px 14px; display: flex; flex-direction: column; gap: 4px;
  transform: translateX(-100%); transition: transform .22s ease;
}
#app-view.menu-open .drawer { transform: translateX(0); }
.drawer-brand { padding: 6px 10px 14px; font-size: 16px; font-weight: 600; }
.drawer nav { display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  text-align: left; width: 100%; font: inherit; color: var(--muted);
  background: transparent; border: 0; border-radius: var(--radius);
  padding: 11px 12px; cursor: pointer;
}
.nav-item:hover { background: color-mix(in srgb, var(--text) 7%, transparent); color: var(--text); }
.nav-item.active { background: var(--accent-900); color: var(--accent-300); }
.nav-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.nav-item.soon { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.nav-item:disabled { color: var(--neutral-700); cursor: not-allowed; }
.nav-item:disabled:hover { background: transparent; color: var(--neutral-700); }
.soon-tag {
  font-size: 10px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); border: 1px solid var(--neutral-800);
  border-radius: 999px; padding: 2px 8px; flex: none;
}
.drawer-foot { margin-top: auto; padding-top: 14px; border-top: 1px solid var(--neutral-800); display: flex; flex-direction: column; gap: 12px; }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 0 4px; }
.user-avatar {
  width: 36px; height: 36px; flex: none; border-radius: 50%;
  background: var(--accent-900); color: var(--accent-300); border: 1px solid var(--accent-700);
  display: grid; place-items: center; font-size: 13px; font-weight: 600;
}
.user-meta { min-width: 0; }
.user-name { font-size: 14px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.last-sync { display: flex; align-items: center; gap: 8px; font-size: 11px; color: var(--muted); padding: 0 4px; }
.last-sync .dot { width: 7px; height: 7px; flex: none; border-radius: 50%; background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent); }
.logout-btn {
  font: inherit; font-size: 13px; text-align: center;
  background: transparent; border: 1px solid var(--neutral-800); border-radius: var(--radius);
  color: var(--muted); padding: 9px 12px; cursor: pointer;
}
.logout-btn:hover { background: color-mix(in srgb, var(--text) 6%, transparent); color: var(--text); }
.logout-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.app-version { text-align: center; font-size: 10px; letter-spacing: .5px; color: var(--neutral-700); }

.content { padding: 20px 16px 96px; }
.content h1 { font-weight: 600; font-size: 21px; margin: 0 0 4px; }
.content .sub { color: var(--muted); margin: 0 0 20px; font-size: 13px; }

/* ---- Carte profil ---- */
.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  padding: 18px;
}
.profile-head { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.avatar {
  width: 52px; height: 52px; flex: none; border-radius: 50%;
  background: var(--accent-900); color: var(--accent-300);
  display: grid; place-items: center; font-size: 18px; font-weight: 600;
  border: 1px solid var(--accent-700);
}
.profile-head .name { font-size: 17px; font-weight: 600; }
.profile-head .role { color: var(--muted); font-size: 13px; }

/* Onglets (glissables horizontalement sur mobile) */
.tabs {
  display: flex; gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch;
  scrollbar-width: none; border-bottom: 1px solid var(--neutral-800);
  margin: 4px -4px 18px; padding: 0 4px 2px;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  font: inherit; font-weight: 500; white-space: nowrap; flex: none;
  background: transparent; border: 0; color: var(--muted);
  padding: 9px 14px; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent-300); border-bottom-color: var(--accent); }
.tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.sub-head {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .6px;
  color: var(--accent-300); margin: 18px 0 10px;
}
.tab-panel > .sub-head:first-child { margin-top: 4px; }
.tab-panel .info-grid + .sub-head { padding-top: 16px; border-top: 1px solid var(--neutral-800); }
.nr { color: var(--neutral-700); font-style: italic; }

/* Infos en UNE colonne (mobile first) */
.info-grid { display: flex; flex-direction: column; gap: 14px; }
.info-grid .label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.info-grid .value { font-size: 15px; margin-top: 2px; }

/* =========================================================
   ORDINATEUR (≥ 860px) : menu latéral fixe, pas de barre du haut,
   contenu large, infos sur 2 colonnes.
   ========================================================= */
@media (min-width: 860px) {
  #app-view { display: flex; align-items: stretch; min-height: 100vh; }

  /* Le menu coulissant devient un menu latéral fixe, à gauche */
  .drawer {
    position: static; transform: none; order: -1;
    width: 250px; max-width: none; min-height: 100vh;
    box-shadow: none; border-right: 1px solid var(--neutral-800);
  }
  .drawer-overlay { display: none !important; }

  /* Plus besoin de la barre du haut ni du hamburger sur ordinateur */
  .topbar { display: none; }

  .app-shell { max-width: none; flex: 1 1 auto; margin: 0; min-width: 0; }

  .content { padding: 32px 44px 64px; }
  .content h1 { font-size: 24px; }
  .content .sub { font-size: 14px; }

  .card { padding: 22px 24px; }
  .profile-head { margin-bottom: 18px; }

  /* Infos : autant de colonnes que la largeur le permet */
  .info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px 40px; }
}

/* =========================================================
   TABLEAU DE BORD
   ========================================================= */
.dash-head { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.dash-head h1 { margin: 0; }

/* Sélecteur de période (menu déroulant) */
.period-dd { position: relative; align-self: flex-start; }
.period-toggle {
  font: inherit; font-size: 14px; background: var(--surface); border: 1px solid var(--neutral-800);
  color: var(--text); border-radius: 999px; padding: 8px 16px; cursor: pointer;
  display: inline-flex; align-items: center; gap: 8px;
}
.period-toggle .chev { color: var(--muted); font-size: 11px; }
.period-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.period-menu {
  position: absolute; top: calc(100% + 6px); right: 0; left: auto; z-index: 20;
  background: var(--surface); border: 1px solid var(--neutral-800); border-radius: var(--radius-lg);
  box-shadow: var(--shadow); padding: 8px; display: flex; gap: 10px;
}
.pm-presets { display: flex; flex-direction: column; gap: 2px; min-width: 168px; border-right: 1px solid var(--neutral-800); padding-right: 8px; }
.pm-cal { width: 252px; padding: 2px 4px; }
.period-opt {
  text-align: left; font: inherit; font-size: 14px; background: transparent; border: 0;
  color: var(--muted); border-radius: var(--radius); padding: 9px 12px; cursor: pointer;
}
.period-opt:hover { background: color-mix(in srgb, var(--text) 7%, transparent); color: var(--text); }
.period-opt.active { background: var(--accent-900); color: var(--accent-300); }

/* Calendrier */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.cal-title { font-size: 14px; font-weight: 500; }
.cal-nav { background: transparent; border: 0; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 4px 8px; border-radius: 6px; }
.cal-nav:hover { background: color-mix(in srgb, var(--text) 8%, transparent); color: var(--text); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 2px; }
.cal-dow { text-align: center; font-size: 11px; color: var(--muted); padding: 2px 0 4px; }
.cal-day { background: transparent; border: 0; color: var(--text); font: inherit; font-size: 13px; padding: 7px 0; border-radius: 6px; cursor: pointer; }
.cal-day:hover { background: color-mix(in srgb, var(--text) 8%, transparent); }
.cal-day.in-range { background: var(--accent-900); border-radius: 0; }
.cal-day.sel { background: var(--accent); color: #fff; }
.cal-foot { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; }
.cal-hint { font-size: 12px; color: var(--muted); }
.cal-apply { font: inherit; font-size: 13px; background: var(--accent-900); color: var(--accent-300); border: 1px solid var(--accent-700); border-radius: 8px; padding: 7px 14px; cursor: pointer; }
.cal-apply:hover:not(:disabled) { background: color-mix(in srgb, var(--accent) 22%, transparent); }
.cal-apply:disabled { opacity: .45; cursor: not-allowed; }

/* Sélecteur sur petit écran : empilé, ancré à gauche */
@media (max-width: 640px) {
  .period-menu { flex-direction: column; left: 0; right: auto; max-width: calc(100vw - 32px); max-height: 74vh; overflow: auto; }
  .pm-presets { border-right: 0; padding-right: 0; border-bottom: 1px solid var(--neutral-800); padding-bottom: 8px; }
  .pm-cal { width: auto; min-width: 240px; }
}

/* Groupes de chiffres */
.kpi-block-label { font-size: 11px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 0 0 10px; }
.kpi-grid { display: grid; gap: 12px; margin-bottom: 22px; }
.kpi-grid.kpi-2 { grid-template-columns: 1fr 1fr; }
.kpi-grid.kpi-3 { grid-template-columns: 1fr 1fr; }
.kpi { background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); padding: 16px; }
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.kpi-value { font-size: 22px; font-weight: 600; margin-top: 6px; }
.kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }

.section-title { font-size: 14px; font-weight: 600; margin: 6px 0 12px; }
.rank-you { color: var(--accent-300); font-weight: 400; font-size: 13px; }
.r-nb { font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 1px; }
.rank-pos { font-size: 18px; width: 30px; text-align: center; flex: none; color: var(--muted); }
.rank-ca-sub { font-size: 11px; color: var(--muted); font-weight: 400; }

/* Classement — cartes (téléphone) */
.rank-table { display: none; }
.rank-cards { display: flex; flex-direction: column; gap: 8px; }
.rank-card { background: var(--surface); border-radius: var(--radius); box-shadow: 0 0 0 1px var(--neutral-800); padding: 12px 14px; }
.rank-card.me { box-shadow: 0 0 0 1px var(--accent-700); background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }
.rc-top { display: flex; align-items: center; gap: 12px; }
.rc-name { flex: 1; min-width: 0; font-weight: 500; }
.rc-ht { text-align: right; font-weight: 600; flex: none; }
.rc-meta { font-size: 12px; color: var(--muted); margin-top: 8px; padding-left: 42px; }

@media (min-width: 860px) {
  .dash-head { flex-direction: row; align-items: center; justify-content: space-between; }
  .kpi-grid.kpi-2 { grid-template-columns: 1fr 1fr; }
  .kpi-grid.kpi-3 { grid-template-columns: repeat(3, 1fr); }
  .kpi-value { font-size: 24px; }

  /* Classement — tableau (ordinateur) */
  .rank-cards { display: none; }
  .rank-table {
    display: table; width: 100%; border-collapse: collapse;
    background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden;
  }
  .rank-table th { text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 500; padding: 13px 16px; border-bottom: 1px solid var(--neutral-800); }
  .rank-table td { padding: 13px 16px; border-bottom: 1px solid var(--neutral-800); vertical-align: middle; }
  .rank-table tbody tr:last-child td { border-bottom: 0; }
  .rank-table tr.me td { background: color-mix(in srgb, var(--accent) 9%, var(--surface)); }
  .rank-table .r-pos { font-size: 18px; width: 64px; }
  .rank-table .r-name { font-weight: 500; }
  .rank-table .r-num, .rank-table th.r-num { text-align: right; font-variant-numeric: tabular-nums; }
}
