:root {
  --bg: #ffffff; --fg: #1f2328; --muted: #57606a; --border: #d0d7de; --accent: #0b5fff;
  --live: #1a7f37; --delayed: #b35900; --lost: #c62828;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body { display: flex; flex-direction: column; font: 15px/1.4 system-ui, sans-serif; color: var(--fg); background: var(--bg); }
header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .5rem 1rem; border-bottom: 1px solid var(--border); }
h1 { font-size: 1.1rem; margin: 0; }
h2 { font-size: 1rem; margin: 0 0 .5rem; }
#conn { margin: 0; padding: .15rem .6rem; border-radius: 1rem; font-size: .85rem; color: #fff; background: var(--muted); }
#conn[data-state="connected"] { background: var(--live); }
#conn[data-state="reconnecting"] { background: var(--lost); }
main { flex: 1; display: flex; min-height: 0; }
#fleet { width: 16.5rem; padding: .75rem; border-right: 1px solid var(--border); overflow: auto; }
#fleet ul { list-style: none; margin: 0; padding: 0; }
#fleet button { width: 100%; text-align: left; margin-bottom: .3rem; padding: .45rem .6rem; border: 1px solid var(--border); border-left: 6px solid var(--muted); background: var(--bg); color: var(--fg); font: inherit; cursor: pointer; }
#fleet button[aria-pressed="true"] { background: #e7f0ff; border-color: var(--accent); }
.legend { list-style: none; margin: 0 0 .75rem; padding: .35rem .5rem; display: grid; gap: .1rem; background: #f6f8fa; border: 1px solid var(--border); border-radius: 8px; }
.legend li { display: grid; grid-template-columns: .8rem 1fr auto; align-items: center; column-gap: .5rem; padding: .2rem 0; font-size: .85rem; }
.legend li + li { border-top: 1px solid #eaeef2; }
.legend small { color: var(--muted); font-size: .75rem; }
.dot { display: inline-block; width: .7rem; height: .7rem; border-radius: 50%; }
.dot.live { background: var(--live); } .dot.delayed { background: var(--delayed); } .dot.lost { background: var(--lost); }
#map-wrap { flex: 1; position: relative; min-width: 0; display: flex; flex-direction: column; }
#map { flex: 1; min-height: 12rem; background-color: #e8ecef; background-image: linear-gradient(#d5dbe0 1px, transparent 1px), linear-gradient(90deg, #d5dbe0 1px, transparent 1px); background-size: 64px 64px; }
.banner[hidden], #fleet-note[hidden] { display: none; }
#fleet-note { margin: 0 0 .5rem; }
#fleet button { display: flex; flex-direction: column; }
#fleet button span { font-size: .8rem; color: var(--muted); }
#panel { width: 25rem; padding: 1rem 1.1rem 1.25rem; border-left: 1px solid var(--border); overflow: auto; background: #fbfcfd; }
#panel[hidden] { display: none; }
.panel-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .75rem; }
.panel-head h2 { margin: 0; font-size: 1.15rem; }
.panel-id { margin: .15rem 0 0; font: .75rem/1.3 ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--muted); word-break: break-all; }
button.ghost { padding: .3rem .8rem; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--fg); cursor: pointer; }
button.ghost:hover { background: #f3f4f6; }
button.primary { width: 100%; margin-top: 1rem; padding: .65rem 1rem; border: 0; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 600; cursor: pointer; }
button.primary:hover { background: #0a4fd6; }
.section-title { margin: 1.1rem 0 .5rem; font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: .6rem; margin: .5rem 0 .9rem; }
.tile { position: relative; display: flex; flex-direction: column; gap: .1rem; padding: .65rem .75rem; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; min-width: 0; }
.tile-label { font-size: .72rem; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); }
.tile-value { font-size: 1.45rem; line-height: 1.15; font-weight: 700; }
.tile-sub { font-size: .78rem; color: var(--muted); min-height: 1em; }
.tile-compass .compass-box { position: absolute; right: .5rem; top: .45rem; width: 3.6rem; height: 3.6rem; }
.compass { width: 100%; height: 100%; }
.compass .ring { fill: #f6f8fa; stroke: #c4ccd4; stroke-width: 2; }
.compass text { font: 700 13px system-ui, sans-serif; fill: var(--muted); }
.compass .needle { fill: var(--lost); }
.compass .tail { fill: #8c959f; }
.bar { height: .5rem; margin-top: .35rem; background: #e6e9ed; border-radius: 99px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--live); border-radius: 99px; transition: width .4s; }
.bar[data-level="faible"] > span { background: var(--delayed); }
.bar[data-level="critique"] > span { background: var(--lost); }
.info { padding: .6rem .8rem; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; font-size: .88rem; }
.charts { display: grid; gap: .6rem; }
.chart-card { margin: 0; padding: .55rem .7rem .45rem; background: var(--bg); border: 1px solid var(--border); border-radius: 10px; }
.chart-head { display: flex; justify-content: space-between; align-items: baseline; font-size: .8rem; color: var(--muted); }
.chart-now { font-size: 1rem; color: var(--fg); }
.chart-box { height: 4.5rem; margin: .3rem 0 .2rem; }
.chart { width: 100%; height: 100%; display: block; overflow: visible; }
.chart .grid { stroke: #e6e9ed; stroke-width: 1; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.chart .area { fill: rgba(11, 95, 255, .1); stroke: none; }
.chart .line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.chart .dot { fill: var(--accent); stroke: #fff; stroke-width: 2; }
.chart-foot { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); }
button.small { width: auto; margin: 0; padding: .3rem .8rem; font-size: .85rem; }
.rename { margin: .6rem 0 .2rem; padding: .7rem .8rem; background: var(--bg); border: 1px solid var(--accent); border-radius: 10px; display: grid; gap: .35rem; }
.rename label { font-size: .8rem; font-weight: 600; }
.rename input { width: 100%; padding: .4rem .5rem; font: inherit; border: 1px solid #6e7781; border-radius: 6px; }
.rename input[aria-invalid="true"] { border-color: var(--lost); border-width: 2px; }
.rename .row { display: flex; gap: .5rem; margin-top: .3rem; }
.rename [hidden] { display: none; }
.form-error { margin: 0; min-height: 0; font-size: .82rem; color: var(--lost); }
.form-error:empty { display: none; }
.panel-id[hidden] { display: none; }
#panel > .ghost.small { margin: .5rem 0 0; }
/* --- Fenêtre de détails --- */
#details { width: min(60rem, 94vw); max-height: 90vh; padding: 0; border: 0; border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.35); color: var(--fg); background: #fbfcfd; }
#details::backdrop { background: rgba(15, 23, 42, .55); }
.details-inner { display: flex; flex-direction: column; max-height: 90vh; }
.details-head { display: flex; align-items: center; gap: .9rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--border); background: var(--bg); }
.details-head > div { flex: 1; min-width: 0; }
.details-head h2 { margin: 0; font-size: 1.2rem; }
.details-head .badge { margin: 0; }
.details-body { padding: 1rem 1.25rem 1.5rem; overflow: auto; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(17rem, 1fr)); gap: .8rem; margin-top: .6rem; }
.stat-card { padding: .8rem .95rem; background: var(--bg); border: 1px solid var(--border); border-radius: 12px; }
.stat-card h3 { margin: 0 0 .5rem; font-size: .8rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.stat-card .info { padding: 0; border: 0; border-radius: 0; background: none; }
.hbars { list-style: none; margin: 0; padding: 0; display: grid; gap: .55rem; }
.hbar-top { display: flex; justify-content: space-between; gap: .5rem; font-size: .85rem; }
.hbar-text { color: var(--muted); }
.hbar { height: .5rem; margin-top: .2rem; background: #e6e9ed; border-radius: 99px; overflow: hidden; }
.hbar > span { display: block; height: 100%; background: var(--accent); border-radius: 99px; }
.charts-wide { grid-template-columns: repeat(auto-fit, minmax(19rem, 1fr)); }
.charts-wide .chart-box { height: 7rem; }
.badge { display: inline-block; margin: .5rem 0; padding: .1rem .6rem; border-radius: 1rem; color: #fff; background: var(--muted); font-weight: 600; }
.badge[data-freshness="live"] { background: var(--live); }
.badge[data-freshness="delayed"] { background: var(--delayed); }
.badge[data-freshness="lost"] { background: var(--lost); }
dl { display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; margin: 0; }
dt { color: var(--muted); } dd { margin: 0; font-weight: 600; }
.note { color: var(--muted); font-size: .85rem; }
button { font: inherit; }
button:focus-visible, a:focus-visible, .leaflet-marker-icon:focus-visible, h2:focus-visible {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
.skip { position: absolute; left: -999px; } .skip:focus { left: .5rem; top: .5rem; z-index: 2000; background: #fff; padding: .4rem; }
.drone-icon { background: none; border: 0; filter: drop-shadow(0 1px 2px rgba(0,0,0,.5)); }
.drone-icon.selected { filter: drop-shadow(0 0 4px var(--accent)) drop-shadow(0 0 2px var(--accent)); }
/* --- Gestion des drones --- */
#views { display: flex; gap: .25rem; }
#views button { padding: .35rem .9rem; border: 1px solid var(--border); background: var(--bg); color: var(--fg); cursor: pointer; }
#views button[aria-current="page"] { background: var(--accent); border-color: var(--accent); color: #fff; }
#map-view[hidden], #admin[hidden] { display: none; }
#admin { flex: 1; overflow: auto; padding: 1rem; max-width: 72rem; width: 100%; margin: 0 auto; }
#admin h2 { font-size: 1.2rem; } #admin h3 { font-size: 1.05rem; margin: 1rem 0 .5rem; }
.admin-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; }
.row { display: inline-flex; gap: .5rem; flex-wrap: wrap; }
.forms { display: grid; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); gap: 1.5rem; }
.field { margin-bottom: .75rem; }
.field label { display: block; font-weight: 600; margin-bottom: .2rem; }
.field input, .field select { width: 100%; padding: .4rem .5rem; font: inherit; border: 1px solid #6e7781; border-radius: 4px; }
.field input[aria-invalid="true"], .field select[aria-invalid="true"] { border-color: var(--lost); border-width: 2px; }
.field-error { color: var(--lost); font-weight: 600; margin: .2rem 0 0; min-height: 0; }
.hint { color: var(--muted); font-size: .85rem; margin: .2rem 0 0; }
#admin button { padding: .4rem .8rem; border: 1px solid #6e7781; border-radius: 4px; background: var(--bg); color: var(--fg); cursor: pointer; }
#admin button.primary, dialog button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
#admin button.danger, dialog button.danger { background: var(--lost); border-color: var(--lost); color: #fff; }
dialog button { padding: .4rem .8rem; border: 1px solid #6e7781; border-radius: 4px; background: var(--bg); color: var(--fg); cursor: pointer; }
dialog { border: 2px solid var(--fg); border-radius: 6px; max-width: min(28rem, calc(100vw - 2rem)); }
dialog::backdrop { background: rgba(31, 35, 40, .55); }
.alert { background: #ffebe9; color: #82071e; border: 1px solid var(--lost); padding: .5rem .75rem; font-weight: 600; }
.alert[hidden] { display: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.secret { background: #fff8c5; border: 2px solid var(--delayed); padding: .75rem 1rem; margin: 1rem 0; }
.warning { font-weight: 700; color: #6a3700; }
.secret-list { grid-template-columns: auto 1fr; align-items: center; }
.secret-list dd { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.secret code { background: #fff; border: 1px solid var(--border); padding: .2rem .4rem; word-break: break-all; user-select: all; }
.queue { list-style: none; padding: 0; margin: 0; }
.queue li { display: flex; justify-content: space-between; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .5rem 0; border-bottom: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; }
caption { text-align: left; color: var(--muted); padding-bottom: .4rem; }
th, td { text-align: left; padding: .4rem .5rem; border-bottom: 1px solid var(--border); vertical-align: top; }
thead th { background: #f6f8fa; }
.status { display: inline-block; padding: .1rem .55rem; border-radius: 1rem; color: #fff; font-weight: 600; font-size: .85rem; background: var(--muted); }
.status[data-tone="ok"] { background: var(--live); } .status[data-tone="warn"] { background: #8a4600; } .status[data-tone="bad"] { background: var(--lost); }
#admin :focus-visible, #views button:focus-visible, dialog :focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
header { flex-wrap: wrap; }
@media (max-width: 800px) {
  /* Téléphone / tablette : liste en bandeau défilant, carte pleine largeur, fiche en panneau du bas. */
  header { padding: .4rem .75rem; gap: .4rem .75rem; }
  h1 { font-size: 1rem; flex: 1 1 auto; }
  #conn { order: 3; flex: 1 0 100%; text-align: center; font-size: .8rem; }
  main { flex-direction: column; position: relative; }
  #fleet { width: auto; padding: .4rem .75rem; border-right: 0; border-bottom: 1px solid var(--border); overflow: visible; }
  #fleet h2 { display: inline; font-size: .9rem; margin: 0 .5rem 0 0; }
  #fleet ul { display: flex; gap: .4rem; overflow-x: auto; padding: .3rem 0; }
  #fleet li { flex: 0 0 auto; }
  #fleet button { margin: 0; min-height: 2.75rem; min-width: 9rem; }
  #fleet .legend { display: none; }
  .leaflet-control-layers { font-size: .85rem; }
  #panel { position: absolute; left: 0; right: 0; bottom: 0; z-index: 1100; width: auto; max-height: 42%; padding: .4rem .75rem; border: 0; border-top: 3px solid var(--accent); background: var(--bg); box-shadow: 0 -4px 12px rgba(0,0,0,.25); }
  #panel dl { font-size: .85rem; gap: .1rem .6rem; }
  .tiles { grid-template-columns: repeat(4, 1fr); gap: .4rem; }
  .tile { padding: .4rem .5rem; }
  .tile-value { font-size: 1.05rem; }
  .tile-compass .compass-box { display: none; }
  #details { width: 100vw; max-height: 100vh; border-radius: 0; }
  #panel .badge { margin: .2rem 0; }
  #views button, #panel button, .leaflet-bar a { min-height: 2.5rem; }
  #admin { padding: .75rem; }
}
@media (max-width: 800px) and (min-width: 560px) { #panel dl { grid-template-columns: auto 1fr auto 1fr; } }
@media (min-width: 801px) and (max-width: 1100px) { #fleet { width: 12rem; } #panel { width: 19rem; } .tile-compass .compass-box { display: none; } }
@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; } }

/* --- Accès à la carte (connexion) et bouton Quitter --- */
#logout { padding: .3rem .8rem; border: 1px solid var(--border); border-radius: 4px; background: var(--bg); color: var(--fg); cursor: pointer; }
#logout[hidden], #access[hidden], #views[hidden] { display: none; }
#logout:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
#access { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 2rem 1rem; overflow: auto; }
#access form { width: min(24rem, 100%); }
#access h2 { font-size: 1.2rem; }
#access input[type="password"] { width: 100%; padding: .5rem; font: inherit; border: 1px solid #6e7781; border-radius: 4px; }
#access input[aria-invalid="true"] { border-color: var(--lost); border-width: 2px; }
#access button.primary { padding: .45rem 1rem; border: 1px solid var(--accent); border-radius: 4px; background: var(--accent); color: #fff; font: inherit; cursor: pointer; }
#access button[disabled] { opacity: .6; cursor: progress; }
#access :focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.field.check { display: grid; grid-template-columns: auto 1fr; column-gap: .5rem; align-items: center; }
.field.check label { margin: 0; }
.field.check .hint { grid-column: 1 / -1; }
.field.check input { width: auto; }
