:root {
  --bg: #0e1116; --panel: #161b22; --panel-2: #1c232d; --line: #262f3a;
  --fg: #e6edf3; --muted: #8b97a6; --faint: #5a6675;
  --accent: #2dd4bf; --accent-ink: #052e2b; --violet: #a78bfa;
  --ok: #3fb950; --warn: #d29922; --crit: #f85149;
  --radius: 12px;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #f3f5f8; --panel: #fff; --panel-2: #f7f9fb; --line: #e2e7ee;
  --fg: #111822; --muted: #566072; --faint: #8893a3;
  --accent: #0d9488; --accent-ink: #d7f5f0; --violet: #7c3aed;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--sans); line-height: 1.45; }
h1, h2 { margin: 0; text-wrap: balance; }
button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

.mark { width: 40px; height: 40px; border-radius: 10px; background: linear-gradient(145deg, var(--accent), var(--violet)); display: grid; place-items: center; color: #04131a; font-weight: 800; }
.mark.sm { width: 32px; height: 32px; border-radius: 9px; font-size: 14px; }
.spacer { flex: 1; }
.btn-primary { background: var(--accent); color: var(--accent-ink); border: none; font-weight: 700; font-size: 13px; padding: 10px 16px; border-radius: 9px; }
.btn-primary:hover { filter: brightness(1.08); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--faint); display: inline-block; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 25%, transparent); }
.dot.off { background: var(--crit); }

/* ---- gate ---- */
.gate { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.gate-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 10px; }
.gate-card h1 { font-size: 20px; margin-top: 8px; }
.gate-card p { margin: 0; color: var(--muted); font-size: 13px; }
.gate-card label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--faint); margin-top: 8px; }
.gate-card input { background: var(--panel-2); border: 1px solid var(--line); color: var(--fg); border-radius: 9px; padding: 11px 13px; font-size: 14px; }
.gate-card input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.gate-card .btn-primary { margin-top: 14px; padding: 12px; }
.gate-err { color: var(--crit); font-size: 12px; }

/* ---- topbar ---- */
.topbar { display: flex; align-items: center; gap: 12px; padding: 14px max(16px, env(safe-area-inset-right,0px)) 14px max(16px, env(safe-area-inset-left,0px)); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 11px; }
.brand b { font-size: 15px; }
.brand span { display: block; font-size: 11px; color: var(--faint); font-family: var(--mono); }
.stat-pill { display: inline-flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 99px; padding: 6px 12px; font-size: 12px; color: var(--muted); font-family: var(--mono); }
.icon-btn { background: var(--panel); border: 1px solid var(--line); color: var(--muted); border-radius: 9px; width: 36px; height: 34px; display: grid; place-items: center; font-size: 15px; }
.icon-btn:hover { color: var(--fg); }

/* ---- deck ---- */
.deck { max-width: 1240px; margin: 0 auto; display: grid; grid-template-columns: 290px 1fr; gap: 16px; align-items: start; padding: 16px max(16px, env(safe-area-inset-right,0px)) 40px max(16px, env(safe-area-inset-left,0px)); }
@media (max-width: 860px) { .deck { grid-template-columns: 1fr; } }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-h { display: flex; align-items: center; justify-content: space-between; padding: 13px 15px; border-bottom: 1px solid var(--line); }
.panel-h h2 { font-size: 12px; text-transform: uppercase; letter-spacing: 1.2px; color: var(--muted); font-weight: 600; }
.count { font-family: var(--mono); font-size: 11px; color: var(--faint); }
.empty { padding: 40px 20px; text-align: center; color: var(--faint); font-size: 13px; }

/* ---- machines ---- */
.machines { padding: 7px; display: flex; flex-direction: column; gap: 3px; max-height: 70vh; overflow-y: auto; }
.machine { display: grid; grid-template-columns: auto 1fr auto; gap: 11px; align-items: center; padding: 10px 11px; border-radius: 9px; border: 1px solid transparent; text-align: left; background: transparent; color: var(--fg); width: 100%; }
.machine:hover { background: var(--panel-2); }
.machine[aria-selected="true"] { background: var(--panel-2); border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.machine .os { width: 30px; height: 30px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); display: grid; place-items: center; font-size: 15px; }
.m-name { font-size: 13.5px; font-weight: 600; }
.m-sub { font-size: 11px; color: var(--faint); font-family: var(--mono); margin-top: 1px; }
.m-state { font-size: 10px; font-family: var(--mono); text-transform: uppercase; letter-spacing: .5px; padding: 3px 7px; border-radius: 6px; }
.s-online { color: var(--ok); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.s-locked { color: var(--warn); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.s-offline { color: var(--faint); background: color-mix(in srgb, var(--faint) 16%, transparent); }
.s-pending { color: var(--violet); background: color-mix(in srgb, var(--violet) 16%, transparent); }

/* ---- approbation ---- */
.pending-bar { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 15px; border-color: color-mix(in srgb, var(--violet) 45%, var(--line)); flex-wrap: wrap; }
.pending-txt { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.pending-txt strong { font-size: 14px; }
.mono-fp { font-family: var(--mono); font-size: 11px; color: var(--faint); word-break: break-all; }
.pending-actions { display: flex; gap: 8px; }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--muted); border-radius: 9px; padding: 10px 14px; font-size: 13px; font-weight: 600; }
.btn-ghost:hover { border-color: var(--crit); color: var(--crit); }
.locked-note { color: var(--faint); font-size: 13px; padding: 8px 2px; }

/* ---- workspace ---- */
.workspace { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.host-head { display: flex; align-items: center; gap: 14px; padding: 16px; flex-wrap: wrap; }
.host-avatar { width: 46px; height: 46px; border-radius: 11px; background: var(--accent-ink); display: grid; place-items: center; font-size: 22px; }
.host-head h1 { font-size: 20px; }
.host-meta { font-size: 12px; color: var(--muted); font-family: var(--mono); margin-top: 3px; display: flex; gap: 14px; flex-wrap: wrap; }

/* ---- actions ---- */
.actions { padding: 15px; }
.action-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 9px; }
.action { display: flex; flex-direction: column; gap: 9px; align-items: flex-start; padding: 13px; border-radius: 10px; border: 1px solid var(--line); background: var(--panel-2); color: var(--fg); text-align: left; }
.action:hover { border-color: color-mix(in srgb, var(--accent) 50%, var(--line)); }
.action:active { transform: translateY(1px); }
.action.danger:hover { border-color: color-mix(in srgb, var(--crit) 55%, var(--line)); }
.action .ico { width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; font-size: 16px; background: var(--panel); border: 1px solid var(--line); }
.action.danger .ico { color: var(--crit); }
.action .t { font-size: 13px; font-weight: 600; }
.action .d { font-size: 11px; color: var(--faint); }

/* ---- log ---- */
.log { font-family: var(--mono); font-size: 11.5px; padding: 13px 15px; max-height: 240px; overflow-y: auto; display: flex; flex-direction: column; gap: 5px; }
.log .ln { display: flex; gap: 10px; color: var(--muted); }
.log .ln time { color: var(--faint); flex: none; }
.log .ln.ok b { color: var(--ok); } .log .ln.warn b { color: var(--warn); } .log .ln.crit b { color: var(--crit); }

/* ---- toast ---- */
.toast { position: fixed; z-index: 50; left: 50%; bottom: calc(18px + env(safe-area-inset-bottom,0px)); transform: translateX(-50%) translateY(20px); background: var(--panel); border: 1px solid var(--line); border-left: 3px solid var(--accent); border-radius: 10px; padding: 11px 16px; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast b { color: var(--accent); }
[hidden] { display: none !important; }

/* ─── Aperçu / transfert de fond d'écran ─── */
#wp-overlay {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .55); padding: 16px;
}
.wp-card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px; max-width: min(92vw, 720px);
  box-shadow: 0 16px 48px rgba(0, 0, 0, .4);
}
.wp-head { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.wp-head b { color: var(--fg); }
.wp-img {
  display: block; max-width: 100%; max-height: 60vh; border-radius: 8px;
  border: 1px solid var(--line); background: var(--panel-2);
}
.wp-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.wp-btn {
  border: 1px solid var(--line); background: var(--panel-2); color: var(--fg);
  border-radius: 8px; padding: 8px 12px; cursor: pointer; font: inherit;
}
.wp-btn.wp-send { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 600; }
.wp-btn:hover { filter: brightness(1.08); }
/* Machines en mode cible de transfert */
.machine.target { outline: 2px dashed var(--accent); outline-offset: -2px; }

/* ─── Écran distant (WebRTC) ─── */
/* Fenêtre flottante NON bloquante : la console reste utilisable derrière. */
#rtc-overlay {
  position: fixed; inset: 0; z-index: 55; pointer-events: none;
}
.rtc-card {
  position: absolute; top: 64px; right: 24px; pointer-events: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 10px; width: min(70vw, 1280px); height: min(70vh, 720px);
  min-width: 320px; min-height: 220px; max-width: 98vw; max-height: 96vh;
  display: flex; flex-direction: column; resize: both; overflow: hidden;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .5);
}
.rtc-head { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; margin-bottom: 10px; flex: none; cursor: move; user-select: none; }
.rtc-head b { color: var(--fg); }
.rtc-status { color: var(--accent); font-variant-numeric: tabular-nums; }
.rtc-btn { border: 1px solid var(--line); background: var(--panel-2); color: var(--fg); border-radius: 8px; padding: 6px 12px; cursor: pointer; font: inherit; }
.rtc-btn:hover { border-color: var(--accent); }
.rtc-full { margin-left: auto; }
.rtc-video { display: block; width: 100%; flex: 1 1 auto; min-height: 0; object-fit: contain; background: #000; border-radius: 8px; border: 1px solid var(--line); }
.rtc-card:fullscreen { position: fixed; inset: 0; width: 100vw; height: 100vh; max-width: none; max-height: none; border-radius: 0; padding: 8px; resize: none; }
.rtc-card:fullscreen .rtc-video { max-height: none; border-radius: 0; border: 0; }

/* Mise à jour en attente : badge dans la liste + bouton d'action dans l'en-tête. */
.m-upd { display: inline-block; margin-left: 6px; font-size: 9px; font-weight: 800; letter-spacing: .03em; color: #fff; background: var(--accent); border-radius: 5px; padding: 1px 4px; vertical-align: middle; }
.upd-pill { cursor: pointer; font: inherit; font-size: 12px; font-weight: 600; color: var(--accent); background: transparent; border: 1px solid var(--accent); border-radius: 999px; padding: 2px 10px; }
.upd-pill:hover { background: var(--accent); color: #fff; }

/* Bannière « nouvelle version de la console disponible ». */
#app-update { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(16px, env(safe-area-inset-bottom, 0px)); z-index: 60; display: flex; align-items: center; gap: 12px; background: var(--panel); border: 1px solid var(--accent); border-radius: 10px; padding: 10px 14px; box-shadow: 0 10px 30px rgba(0, 0, 0, .4); font-size: 13.5px; }
#app-update button { border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: 8px; padding: 6px 12px; cursor: pointer; font: inherit; font-weight: 600; }
