:root {
  --bg: #0f1419;
  --panel: #161c23;
  --panel-2: #1d252e;
  --border: #2a3440;
  --text: #dbe3ea;
  --muted: #8796a5;
  --accent: #3b9eff;
  --accent-2: #1f6fbf;
  --ok: #3fb950;
  --warn: #d29922;
  --err: #f85149;
  --mono: "Cascadia Mono", Consolas, "Courier New", monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, sans-serif; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--err); min-height: 1.2em; }
.mono { font-family: var(--mono); }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 10px; }

button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px; outline: none; min-width: 0;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { font-family: var(--mono); resize: vertical; }
button { background: var(--panel-2); border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }
button.primary { background: var(--accent-2); border-color: var(--accent-2); color: #fff; }
button.primary:hover { background: var(--accent); }
button.danger { color: var(--err); }
button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
button.ghost:hover { color: var(--text); border-color: var(--border); }
button.small { padding: 3px 9px; font-size: 13px; }
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 13px; }
label.check { flex-direction: row; align-items: center; gap: 6px; }

.brand { font-weight: 700; font-size: 18px; letter-spacing: .5px; }
.brand span { color: var(--accent); }
.brand.big { font-size: 30px; }
#brandHome { cursor: pointer; user-select: none; }

/* ---------- tableau de bord (accueil) */
.dash { padding: 20px; overflow: auto; height: 100%; }
.dash-head { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.dash-head h2 { margin: 0; }
.dash-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.card-block { background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 14px 16px; margin-top: 16px; }
.card-block h3 { margin: 0 0 8px; display: flex; align-items: center; gap: 6px; font-size: 14px; }
.card-block h3 .ico { width: 14px; height: 14px; opacity: .8; }
.dash-row { display: flex; align-items: center; gap: 10px; padding: 7px 0; cursor: pointer; border-top: 1px solid var(--border); }
.dash-row:first-of-type { border-top: none; }
.dash-row:hover .nm { color: var(--accent); }
.dash-row .nm { flex: 0 0 38%; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dash-row .bar { flex: 1; }
.dash-row .pct { flex: 0 0 42px; text-align: right; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.dash-row .when { margin-left: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ---------- connexion */
.login { position: fixed; inset: 0; display: grid; place-items: center; }
.login-box { width: min(360px, calc(100vw - 32px)); background: var(--panel); border: 1px solid var(--border);
  border-radius: 12px; padding: 28px; display: flex; flex-direction: column; gap: 14px; }

/* ---------- structure */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--border); }
.topbar nav { display: flex; gap: 4px; margin-left: 20px; }
.nav { background: transparent; border-color: transparent; color: var(--muted); }
.nav.active { color: var(--text); background: var(--panel-2); border-color: var(--border); }
.spacer { flex: 1; }
.hub-state { color: var(--err); font-size: 12px; }
.hub-state.on { color: var(--ok); }
.view { flex: 1; min-height: 0; }
.machines { display: flex; }
.page { padding: 20px; overflow: auto; height: 100%; }
.page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.two-cols { display: grid; grid-template-columns: minmax(320px, 1fr) minmax(0, 2fr); gap: 24px; }
.two-cols > div { min-width: 0; }
.table.compact { table-layout: fixed; }
.table.compact td { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- liste des machines */
.sidebar { width: 330px; flex-shrink: 0; display: flex; flex-direction: column; border-right: 1px solid var(--border); background: var(--panel); }
.sidebar-tools { display: flex; gap: 6px; padding: 10px; }
.sidebar-tools input { flex: 1; }
.sidebar-count { display: flex; justify-content: space-between; padding: 0 12px 6px; color: var(--muted); font-size: 12px; }
.agent-list { flex: 1; overflow: auto; }
.group-title { padding: 10px 12px 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); }
.agent { display: flex; align-items: center; gap: 8px; padding: 7px 12px; cursor: pointer; border-left: 3px solid transparent; }
.agent:hover { background: var(--panel-2); }
.agent.active { background: var(--panel-2); border-left-color: var(--accent); }
.agent .info { flex: 1; min-width: 0; }
.agent .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.agent .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #56606b; flex-shrink: 0; }
.dot.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.cpu { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.metrics { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; flex-shrink: 0; font-size: 11px; color: var(--muted); font-family: var(--mono); }
.met { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; min-width: 40px; justify-content: flex-end; }
.met .ico { width: 12px; height: 12px; flex: 0 0 12px; opacity: .75; }
.selection-bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-top: 1px solid var(--border); background: var(--panel-2); }

/* ---------- détail */
.detail { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.empty-state { margin: auto; color: var(--muted); }
.detail-head { display: flex; align-items: center; gap: 12px; padding: 14px 20px 0; flex-wrap: wrap; }
.detail-head h2 { margin: 0; }
.tag { font-size: 12px; padding: 2px 8px; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--border); color: var(--muted); }
.pill { font-size: 12px; padding: 2px 9px; border-radius: 10px; white-space: nowrap; border: 1px solid transparent; }
.pill.run { color: var(--ok); border-color: color-mix(in srgb, var(--ok) 40%, transparent); background: color-mix(in srgb, var(--ok) 14%, transparent); }
.pill.stop { color: var(--muted); border-color: var(--border); background: var(--panel-2); }
.pill.pend { color: var(--warn); border-color: color-mix(in srgb, var(--warn) 40%, transparent); background: color-mix(in srgb, var(--warn) 14%, transparent); }
.tabs { display: flex; gap: 2px; padding: 10px 20px 0; border-bottom: 1px solid var(--border); }
.tab { background: transparent; border: 1px solid transparent; border-bottom: none; border-radius: 6px 6px 0 0; color: var(--muted); }
.tab.active { background: var(--panel); border-color: var(--border); color: var(--text); margin-bottom: -1px; }
.tab-body { flex: 1; min-height: 0; overflow: auto; padding: 16px 20px; background: var(--panel); }

.grid-info { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 12px; }
.card { background: var(--panel-2); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; }
.card .k { font-size: 12px; color: var(--muted); }
.card .v { font-size: 15px; word-break: break-word; }
.bar { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; margin-top: 6px; }
.bar > div { height: 100%; background: var(--accent); }
.bar > div.hot { background: var(--err); }
.form-grid { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* ---------- commandes */
.cmd-form { display: flex; flex-direction: column; gap: 8px; }
.cmd-row { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.cmd-row > label { flex: 1; min-width: 140px; }
.cmd-form textarea { min-height: 80px; }
.console { background: #0a0d10; border: 1px solid var(--border); border-radius: 6px; padding: 10px; font-family: var(--mono);
  font-size: 13px; white-space: pre-wrap; word-break: break-all; min-height: 160px; max-height: 50vh; overflow: auto; margin: 0; }
.console .err { color: #ff9a8f; }
.console-head { display: flex; align-items: center; gap: 10px; margin: 14px 0 6px; flex-wrap: wrap; }
.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 18px; }
.job-list { display: flex; flex-direction: column; gap: 4px; max-height: 70vh; overflow: auto; }
.job { padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; cursor: pointer; background: var(--bg); }
.job:hover { border-color: var(--accent); }
.job .c { font-family: var(--mono); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.job .m { font-size: 11px; color: var(--muted); display: flex; justify-content: space-between; gap: 6px; }

.status { font-size: 11px; font-weight: 600; padding: 1px 7px; border-radius: 9px; white-space: nowrap; }
.st-Pending, .st-Running { background: #1c3a5c; color: #8cc4ff; }
.st-Succeeded { background: #193d24; color: #7ee293; }
.st-Failed, .st-TimedOut { background: #4a1c1c; color: #ff9a8f; }
.st-Cancelled { background: #3d331a; color: #e6c370; }

/* ---------- fichiers */
.fs-bar { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.fs-bar input { flex: 1; min-width: 200px; font-family: var(--mono); }
/* Zone de glisser/déposer de fichiers */
.fs-drop { position: relative; border: 2px dashed transparent; border-radius: 10px; transition: border-color .12s, background .12s; }
.fs-drop.over { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.fs-drophint { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; pointer-events: none; border-radius: 8px; z-index: 5; }
.fs-drop.over .fs-drophint { display: flex; }
.fs-dropcard { background: var(--panel); border: 1px solid var(--accent); border-radius: 10px; padding: 14px 22px; font-weight: 600; color: var(--accent); box-shadow: 0 8px 28px rgba(0,0,0,.28); text-align: center; }
.fs-dropcard small { display: block; margin-top: 4px; font-weight: 400; font-size: 12px; color: var(--muted); font-family: var(--mono); }
.fs-drop.nodest.over { border-color: var(--danger, #e5484d); background: color-mix(in srgb, var(--danger, #e5484d) 7%, transparent); }
.fs-drop.nodest .fs-dropcard { border-color: var(--danger, #e5484d); color: var(--danger, #e5484d); }
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; font-weight: 600; color: var(--muted); font-size: 12px; border-bottom: 1px solid var(--border); padding: 6px 8px; }
.table td { border-bottom: 1px solid var(--border); padding: 5px 8px; vertical-align: middle; }
.table tr.click { cursor: pointer; }
.table tr.click:hover td { background: var(--panel-2); }
.table.compact td { font-size: 12px; }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.cmd { font-family: var(--mono); font-size: 12px; max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- SSH */
.ssh-form { display: grid; grid-template-columns: minmax(0, 2fr) 80px minmax(0, 1fr) minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.ssh-form input { width: 100%; }
.tab-body { overflow-x: hidden; }
.ssh-form textarea { grid-column: 1 / -1; min-height: 70px; font-size: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin: 10px 0; }
.chip { font-size: 12px; padding: 3px 10px; border-radius: 12px; }
.saved-hosts { margin: 4px 0 12px; }
.saved-hosts .k { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.chip.saved { background: var(--panel-2); border-color: var(--border); display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; }
.chip.saved:hover { border-color: var(--accent); background: var(--accent-2); color: #fff; }
.chip-type { font-size: 10px; text-transform: uppercase; letter-spacing: .4px; background: var(--bg); color: var(--accent); padding: 1px 6px; border-radius: 8px; }
.chip.saved:hover .chip-type { background: rgba(0,0,0,.25); color: #fff; }
.terminal-wrap { height: calc(100vh - 330px); min-height: 300px; background: #000; border: 1px solid var(--border); border-radius: 6px; padding: 4px; }

/* ---------- écran */
.screen-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.screen img { max-width: 100%; border: 1px solid var(--border); border-radius: 4px; cursor: zoom-in; }
.screen img.full { max-width: none; cursor: zoom-out; }

/* ---------- modale & toasts */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: grid; place-items: center; z-index: 50; }
.modal-box { width: min(1000px, calc(100vw - 32px)); max-height: 88vh; display: flex; flex-direction: column; background: var(--panel);
  border: 1px solid var(--border); border-radius: 10px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; }
.modal-body { padding: 16px; overflow: auto; }
.modal-body .console { max-height: 60vh; }
.warn-banner { background: #4a3a10; color: #ffe08a; padding: 8px 16px; font-size: 13px; border-bottom: 1px solid #806010; }
.upd { margin-top: 6px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.warn-txt { color: var(--warn); }
.toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; }
.toast { background: var(--panel-2); border: 1px solid var(--border); border-left: 4px solid var(--accent); padding: 10px 14px; border-radius: 6px;
  max-width: 420px; box-shadow: 0 4px 16px rgba(0,0,0,.4); }
.toast.err { border-left-color: var(--err); }
.toast.ok { border-left-color: var(--ok); }
.toast.warn { border-left-color: var(--warn); }

/* Double authentification */
.sep { border: none; border-top: 1px solid var(--border); margin: 20px 0 14px; }
.otp-steps { margin: 0; padding-left: 20px; }
.otp-steps li { margin-bottom: 14px; }
.otp-secret { display: inline-block; margin: 6px 0; padding: 8px 12px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; font-size: 18px; letter-spacing: 3px; user-select: all; }
.otp-qr { margin: 8px 0; padding: 10px; background: #fff; border-radius: 8px; width: max-content; }
.otp-qr svg { display: block; width: 200px; height: 200px; }

@media (max-width: 1300px) {
  .ssh-form { grid-template-columns: minmax(0, 2fr) 80px minmax(0, 1fr); }
  .split { grid-template-columns: minmax(0, 1fr) 280px; }
}
@media (max-width: 1100px) {
  .dash-cols { grid-template-columns: 1fr; }
}
@media (max-width: 900px) {
  .machines { flex-direction: column; }
  .sidebar { width: 100%; max-height: 40vh; }
  .split, .two-cols { grid-template-columns: 1fr; }
  .ssh-form { grid-template-columns: 1fr 1fr; }
}
