:root {
  --bg: #050f1f;
  --bg-2: #081831;
  --panel: #0c2240;
  --panel-2: #0a1c36;
  --line: #1c3f6e;
  --line-soft: rgba(255, 255, 255, .06);
  --text: #eef2f7;
  --muted: #8ea6c4;
  --yellow: #ffc600;
  --red: #ff4d6d;
  --green: #2fd18b;
  --orange: #ffa53d;
  --blue: #3d9bff;
  --radius: 14px;
  --mono: Consolas, "Cascadia Mono", "SFMono-Regular", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body { background: var(--bg); color: var(--text); font: 14.5px/1.5 "Segoe UI", system-ui, -apple-system, Arial, sans-serif; }
a { color: var(--yellow); }
button, input, select { font: inherit; }
[hidden] { display: none !important; }

/* Boutons */
.btn { display: inline-flex; align-items: center; gap: 8px; border: 1px solid transparent; border-radius: 10px; padding: 8px 14px; font-weight: 650; font-size: 13.5px; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn-primary { background: var(--yellow); color: #061224; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-ghost { background: transparent; color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: rgba(255, 255, 255, .04); }
.btn-danger { background: transparent; color: var(--red); border-color: rgba(255, 77, 109, .45); }
.btn-danger:hover { background: rgba(255, 77, 109, .1); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* Champs */
.field { display: grid; gap: 6px; }
.field > span { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
.field small { color: var(--muted); font-size: 12px; }
.input { width: 100%; background: var(--panel-2); color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; }
.input:focus { outline: 2px solid var(--yellow); outline-offset: 1px; }
.input.mono { font-family: var(--mono); font-size: 13px; }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.switch input { width: 40px; height: 22px; appearance: none; background: var(--line); border-radius: 22px; position: relative; cursor: pointer; transition: background .15s; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: left .15s; }
.switch input:checked { background: var(--green); }
.switch input:checked::after { left: 21px; }

/* Connexion */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 600px at 50% -10%, #12345f 0%, var(--bg) 60%); }
.login-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 32px; box-shadow: 0 30px 80px rgba(0, 0, 0, .45); }
.login-card img { width: 120px; display: block; margin: 0 auto 12px; }
.login-card h1 { margin: 0; text-align: center; font-size: 22px; }
.login-card p { margin: 6px 0 24px; text-align: center; color: var(--muted); }
.login-card form { display: grid; gap: 16px; }
.login-card .btn { justify-content: center; padding: 11px; }
.form-error { min-height: 1.4em; margin: 0; color: var(--red); font-size: 13px; text-align: center; }

/* Structure gestion */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; padding: 20px 14px; background: var(--bg-2); border-right: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 18px; }
.brand img { width: 44px; height: 44px; object-fit: contain; }
.brand strong { display: block; font-size: 14px; }
.brand small { color: var(--muted); font-size: 12px; }
.nav-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 600; text-align: left; cursor: pointer; }
.nav-item:hover { color: var(--text); background: rgba(255, 255, 255, .04); }
.nav-item.active { color: #061224; background: var(--yellow); }
.nav-item svg { width: 18px; height: 18px; flex: 0 0 auto; }
.sidebar-foot { margin-top: auto; display: grid; gap: 10px; padding: 12px 8px 0; border-top: 1px solid var(--line); color: var(--muted); font-size: 12px; }

.main { min-width: 0; display: flex; flex-direction: column; }
.topbar { position: sticky; top: 0; z-index: 5; display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px 28px; background: rgba(5, 15, 31, .92); backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.topbar h1 { margin: 0 auto 0 0; font-size: 18px; }
.chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 12px; border: 1px solid var(--line); border-radius: 999px; background: var(--panel-2); font-size: 12.5px; white-space: nowrap; }
.chip b { font-weight: 650; }
.chip .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); }
.chip.ok .dot { background: var(--green); box-shadow: 0 0 10px rgba(47, 209, 139, .7); }
.chip.warn .dot { background: var(--orange); }
.chip.bad .dot { background: var(--red); }
.content { padding: 24px 28px 48px; display: grid; gap: 20px; }

.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; min-width: 0; }
.panel-head { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; }
.panel-head h2, .panel h2 { margin: 0; font-size: 12.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--yellow); }
.panel-head p, .note { margin: 0; color: var(--muted); font-size: 13px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.cols-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }

/* Course */
.race { display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: center; }
.race-name { margin: 0; font-size: 22px; font-weight: 700; }
.race-sub { margin: 2px 0 0; color: var(--muted); }
.race-clock { font: 700 46px/1 var(--mono); letter-spacing: .02em; text-align: right; }
.race-clock small { display: block; margin-top: 6px; font: 600 11px/1 "Segoe UI", sans-serif; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.progress { grid-column: 1 / -1; height: 6px; border-radius: 6px; background: var(--panel-2); overflow: hidden; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--yellow), #ff8a00); transition: width .4s; }
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 650; background: rgba(142, 166, 196, .15); color: var(--muted); }
.badge.live { background: rgba(255, 77, 109, .16); color: var(--red); }
.badge.live::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--red); animation: pulse 1.2s infinite; }
.badge.done { background: rgba(47, 209, 139, .15); color: var(--green); }
.badge.demo { background: rgba(61, 155, 255, .16); color: var(--blue); }
.badge.warn { background: rgba(255, 165, 61, .16); color: var(--orange); }
@keyframes pulse { 50% { opacity: .3; } }

/* Postes */
.posts { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.post { position: relative; display: grid; gap: 12px; padding: 16px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); }
.post.leader { border-color: rgba(255, 198, 0, .6); box-shadow: 0 0 0 1px rgba(255, 198, 0, .25), 0 10px 30px rgba(255, 198, 0, .08); }
.post-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.post-head h3 { margin: 0; font-size: 15px; }
.post-team { margin: 2px 0 0; color: var(--muted); font-size: 13px; min-height: 1.3em; }
.rank { display: grid; place-items: center; min-width: 34px; height: 34px; padding: 0 8px; border-radius: 10px; background: var(--panel); border: 1px solid var(--line); font-weight: 800; }
.post.leader .rank { background: var(--yellow); color: #061224; border-color: var(--yellow); }
.post-total { font: 800 44px/1 var(--mono); color: var(--yellow); }
.post-total small { font: 600 12px/1 "Segoe UI", sans-serif; color: var(--muted); margin-left: 6px; letter-spacing: .1em; }
.split { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.split div { padding: 8px; border-radius: 10px; background: var(--panel); text-align: center; }
.split b { display: block; font: 700 18px/1.1 var(--mono); }
.split span { font-size: 10.5px; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.post-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }

/* Tableaux */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; text-align: left; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
th { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); font-weight: 650; }
td.num, th.num { text-align: right; font-family: var(--mono); }
tbody tr:hover td { background: rgba(255, 255, 255, .02); }
tr.clickable { cursor: pointer; }
.mapping input { width: 80px; }
.empty { padding: 26px; text-align: center; color: var(--muted); }

/* Écrans */
.screens { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.screen-card { display: grid; gap: 10px; padding: 16px; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius); }
.screen-card h3 { margin: 0; font-size: 15px; }
.screen-card code { display: block; padding: 8px 10px; border-radius: 8px; background: var(--panel); font: 12.5px var(--mono); overflow-wrap: anywhere; }

/* Journaux */
.logs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px; }
.log-list { display: flex; flex-direction: column; gap: 6px; height: 62vh; overflow: auto; padding-right: 4px; }
.log-entry { padding: 8px 10px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line-soft); }
.log-entry.bad { border-color: rgba(255, 77, 109, .5); }
.log-entry header { display: flex; gap: 8px; color: var(--muted); font: 11.5px var(--mono); }
.log-entry p { margin: 2px 0 0; overflow-wrap: anywhere; font-size: 13px; }
.log-entry details summary { cursor: pointer; color: var(--muted); font-size: 12px; margin-top: 4px; }
.log-entry pre { margin: 6px 0 0; max-height: 260px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; font: 12px/1.45 var(--mono); color: #cfe0f5; }

/* Historique */
.chart { width: 100%; height: 260px; background: var(--panel-2); border-radius: var(--radius); border: 1px solid var(--line); }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12.5px; color: var(--muted); }
.legend i { display: inline-block; width: 12px; height: 3px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }

.secret { display: flex; gap: 8px; }
.secret .input { flex: 1; }
.callout { padding: 12px 14px; border-radius: 12px; background: rgba(255, 198, 0, .07); border: 1px solid rgba(255, 198, 0, .3); color: #f6e2a0; font-size: 13px; }
.callout.bad { background: rgba(255, 77, 109, .08); border-color: rgba(255, 77, 109, .4); color: #ffc2cd; }
.steps { margin: 0; padding-left: 20px; color: var(--muted); font-size: 13.5px; display: grid; gap: 4px; }
.steps a { color: var(--yellow); }
.sub-title { margin: 18px 0 8px; font-size: 13px; font-weight: 700; color: var(--text); }
.sub-title + .note { margin: 0 0 12px; }

/* Notifications et dialogues */
.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 50; display: grid; gap: 8px; }
.toast { min-width: 240px; max-width: 380px; padding: 12px 14px; border-radius: 12px; background: var(--panel); border: 1px solid var(--line); box-shadow: 0 12px 40px rgba(0, 0, 0, .45); font-size: 13.5px; animation: toast-in .2s ease; }
.toast.ok { border-color: rgba(47, 209, 139, .6); }
.toast.bad { border-color: rgba(255, 77, 109, .6); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
dialog { width: min(440px, calc(100% - 32px)); padding: 22px; border: 1px solid var(--line); border-radius: 16px; background: var(--panel); color: var(--text); box-shadow: 0 30px 80px rgba(0, 0, 0, .6); }
dialog::backdrop { background: rgba(2, 8, 18, .7); }
dialog h3 { margin: 0 0 8px; font-size: 17px; }
dialog p { margin: 0 0 20px; color: var(--muted); }
dialog .row { justify-content: flex-end; }

.offline-banner { padding: 10px 28px; background: rgba(255, 77, 109, .14); border-bottom: 1px solid rgba(255, 77, 109, .4); color: #ffc2cd; font-size: 13.5px; }

@media (max-width: 1100px) {
  .logs, .cols-2 { grid-template-columns: 1fr; }
}
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: row; flex-wrap: wrap; padding: 10px; }
  .brand { padding: 0 8px; }
  .nav-item { width: auto; }
  .sidebar-foot { margin: 0; border: 0; padding: 0 8px; }
  .content, .topbar { padding-left: 14px; padding-right: 14px; }
  .race { grid-template-columns: 1fr; }
  .race-clock { text-align: left; }
}
