:root {
  --bg: #f4f6fa;
  --surface: #ffffff;
  --surface-2: #f8f9fc;
  --border: #e3e7ef;
  --text: #182033;
  --muted: #667089;
  --accent: #2457d6;
  --accent-soft: #e8efff;
  --ok: #138a52;
  --ok-soft: #e3f6ec;
  --warn: #b26a00;
  --warn-soft: #fff3dd;
  --danger: #c62f3b;
  --danger-soft: #fde8ea;
  --off: #9aa3b5;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f131b;
    --surface: #171c26;
    --surface-2: #1d2330;
    --border: #2a3242;
    --text: #e6e9f0;
    --muted: #97a0b3;
    --accent: #6b93ff;
    --accent-soft: #1d2a4d;
    --ok: #3ccf8a;
    --ok-soft: #12301f;
    --warn: #f0b04a;
    --warn-soft: #33270f;
    --danger: #ff6b76;
    --danger-soft: #3a1519;
    --off: #6c7589;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
[hidden] { display: none !important; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 16px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); }
.nowrap { white-space: nowrap; }

/* Boutons et champs */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 12px; border-radius: 8px; font: inherit; font-weight: 500; cursor: pointer;
  white-space: nowrap; min-height: 34px;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.btn.danger.solid { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 4px 9px; min-height: 28px; font-size: 13px; }
.btn.block { width: 100%; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 0; }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 8px; padding: 7px 10px; min-height: 34px; max-width: 100%;
}
textarea { resize: vertical; width: 100%; }
input:focus, select:focus, textarea:focus, .btn:focus-visible { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }
label { display: grid; gap: 4px; font-weight: 500; font-size: 13px; }
label input, label select, label textarea { font-weight: 400; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; }
.check input { min-height: 0; width: 16px; height: 16px; }
.form-grid { display: grid; gap: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

/* Connexion */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; padding: 28px; display: grid; gap: 14px; box-shadow: var(--shadow);
}
.login-card p { margin: 0; }

/* Mise en page */
.layout { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border); padding: 18px 12px;
  display: flex; flex-direction: column; gap: 18px; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; padding: 0 8px; }
.brand img { width: 24px; height: 24px; }
.brand-lg { font-size: 20px; padding: 0; }
.brand-lg img { width: 30px; height: 30px; }
.sidebar nav { display: grid; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text); font-weight: 500;
}
.sidebar nav a:hover { background: var(--surface-2); text-decoration: none; }
.sidebar nav a.active { background: var(--accent-soft); color: var(--accent); }
.ico { width: 18px; text-align: center; opacity: .8; }
.sidebar-foot { margin-top: auto; display: grid; gap: 8px; padding: 0 8px; font-size: 13px; }
.user { display: flex; justify-content: space-between; gap: 8px; }
.conn { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.topbar { display: none; }
.view { padding: 24px 28px 48px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.page-head .sub { color: var(--muted); }

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 50; left: 0; top: 0; width: 250px; transform: translateX(-105%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.25); }
  .sidebar.open { transform: none; }
  .topbar {
    display: flex; align-items: center; gap: 8px; padding: 8px 12px;
    background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 40;
  }
  .view { padding: 16px 16px 40px; }
}

/* Cartes */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); min-width: 0; }
.card + .card { margin-top: 16px; }
.grid { display: grid; gap: 16px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); align-items: start; }
.grid.two .card + .card { margin-top: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px; }
.stat .v { font-size: 22px; font-weight: 650; }
.stat .l { color: var(--muted); font-size: 12.5px; }
dl.info { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dl.info dt { color: var(--muted); }
dl.info dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* Tableaux */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: var(--surface-2); }
td.chk, th.chk { width: 36px; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

/* Indicateurs */
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--off); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.warn { background: var(--warn); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 99px; font-size: 12.5px; font-weight: 550; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.pill.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.pill.info { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.battery { display: inline-flex; align-items: center; gap: 6px; }
.battery .bar { width: 26px; height: 11px; border: 1.5px solid currentColor; border-radius: 3px; position: relative; opacity: .8; }
.battery .bar i { position: absolute; left: 1px; top: 1px; bottom: 1px; border-radius: 1px; background: currentColor; }
.banner { padding: 10px 12px; border-radius: 8px; background: var(--warn-soft); color: var(--warn); margin-bottom: 12px; font-size: 13.5px; }
.banner.info { background: var(--accent-soft); color: var(--accent); }
.banner.danger { background: var(--danger-soft); color: var(--danger); }

/* Barre d'actions groupées */
.bulkbar {
  position: sticky; bottom: 16px; margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; align-items: center;
  background: var(--text); color: var(--bg); padding: 10px 12px; border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.2);
}
.bulkbar .btn { background: transparent; color: inherit; border-color: color-mix(in srgb, var(--bg) 30%, transparent); }
.bulkbar .btn:hover { background: color-mix(in srgb, var(--bg) 12%, transparent); }

/* Menu déroulant */
.menu { position: relative; display: inline-block; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 30; min-width: 230px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 6px; box-shadow: 0 10px 30px rgba(0,0,0,.15);
}
.menu-list button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: 8px 10px; border-radius: 6px; font: inherit; color: var(--text); cursor: pointer; }
.menu-list button:hover { background: var(--surface-2); }
.menu-list button.danger { color: var(--danger); }
.menu-list hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

/* Fenêtres modales */
.modal-backdrop { position: fixed; inset: 0; background: rgba(10, 14, 22, .5); display: grid; place-items: center; padding: 16px; z-index: 100; }
.modal { width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: 14px; padding: 20px; display: grid; gap: 14px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal h2 { margin: 0; font-size: 17px; }
.modal p { margin: 0; }
.pick-list { max-height: 260px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 6px 10px; display: grid; gap: 6px; }

/* Notifications */
.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 200; max-width: min(380px, calc(100vw - 32px)); }
.toast { background: var(--text); color: var(--bg); padding: 10px 14px; border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.25); font-size: 13.5px; }
.toast.error { background: var(--danger); color: #fff; }

/* Carte */
.map { height: 360px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); }
.map.tall { height: calc(100vh - 160px); min-height: 420px; }
.map-fallback { display: grid; place-items: center; height: 100%; color: var(--muted); text-align: center; padding: 16px; }
.marker-dot { width: 16px; height: 16px; border-radius: 50%; background: var(--accent); border: 3px solid #fff; box-shadow: 0 1px 4px rgba(0,0,0,.4); }
.marker-dot.off { background: #8a93a6; }

/* Interrupteurs */
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.switch-row:last-child { border-bottom: 0; }
.switch { position: relative; width: 38px; height: 22px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 99px; transition: .15s; cursor: pointer; }
.switch span::after { content: ""; position: absolute; left: 3px; top: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(16px); }
.switch input:disabled + span { opacity: .5; cursor: not-allowed; }

/* Écran à distance */
.screen-page { display: grid; grid-template-columns: 1fr 300px; gap: 16px; align-items: start; }
.screen-stage {
  background: #0b0e14; border-radius: 14px; min-height: 60vh; display: grid; place-items: center; position: relative; overflow: hidden; padding: 12px;
}
.screen-stage canvas { max-width: 100%; max-height: calc(100vh - 170px); border-radius: 6px; touch-action: none; cursor: crosshair; outline: none; background: #000; }
.screen-overlay { position: absolute; inset: 0; display: grid; place-items: center; color: #c9d1e2; text-align: center; padding: 24px; pointer-events: none; }
.screen-overlay div { background: rgba(0,0,0,.55); padding: 14px 18px; border-radius: 10px; max-width: 420px; }
.screen-tools { display: grid; gap: 12px; }
.keypad { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.keypad .btn { padding: 6px 4px; white-space: normal; font-size: 12.5px; line-height: 1.2; }
.screen-stats { font-size: 12px; color: var(--muted); }
@media (max-width: 960px) { .screen-page { grid-template-columns: 1fr; } }

/* Dépôt de fichiers */
.drop { border: 2px dashed var(--border); border-radius: 12px; padding: 22px; text-align: center; color: var(--muted); transition: .15s; }
.drop.over { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.progress { height: 6px; background: var(--surface-2); border-radius: 99px; overflow: hidden; }
.progress i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }

/* Enrôlement */
.qr-box { background: #fff; padding: 12px; border-radius: 12px; width: min(460px, 100%); border: 1px solid var(--border); }
.qr-full { position: fixed; inset: 0; background: #fff; z-index: 300; display: grid; place-items: center; padding: 16px; cursor: zoom-out; }
.qr-full svg { width: min(96vw, 96vh); height: auto; }
.qr-box svg { display: block; width: 100%; height: auto; }
.steps { margin: 0; padding-left: 20px; display: grid; gap: 6px; }
.code-big { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 22px; letter-spacing: .12em; font-weight: 700; }

/* Liste des applis d'une tablette */
.app-list { max-height: 360px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.app-item { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.app-item:last-child { border-bottom: 0; }
.app-name { min-width: 0; flex: 1 1 180px; overflow-wrap: anywhere; }
