:root {
  --bg: #0d1117;
  --bg-2: #161b22;
  --bg-3: #1c232d;
  --border: #2b3440;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --radius: 10px;
  --mono: "Cascadia Code", "Consolas", "SF Mono", ui-monospace, monospace;
  --sans: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.mono { font-family: var(--mono); }

button { font-family: inherit; cursor: pointer; }
input { font-family: inherit; }

/* ---------- Login ---------- */
.login-overlay {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(1200px 600px at 50% -10%, #1b2536, var(--bg));
  z-index: 100;
}
.login-card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  width: 340px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.login-logo { font-size: 44px; }
.login-card h1 { margin: 8px 0 4px; font-size: 22px; }
.login-card p { margin: 0 0 22px; font-size: 13px; }
.login-card input {
  width: 100%; padding: 12px 14px; margin-bottom: 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: 14px;
}
.login-card input:focus { outline: none; border-color: var(--accent); }
.login-card button {
  width: 100%; padding: 12px; border: none; border-radius: 8px;
  background: var(--accent); color: #fff; font-size: 14px; font-weight: 600;
  transition: background .15s;
}
.login-card button:hover { background: var(--accent-2); }
.login-error { color: var(--red); font-size: 13px; margin-top: 12px; min-height: 18px; }

/* ---------- Layout ---------- */
.app { display: flex; flex-direction: column; height: 100vh; }
.topbar {
  height: 52px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px; background: var(--bg-2); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.status-dot.online { background: var(--green); box-shadow: 0 0 8px var(--green); }
.status-dot.offline { background: var(--red); }
.btn-ghost {
  background: transparent; border: 1px solid var(--border);
  color: var(--text); padding: 6px 12px; border-radius: 7px; font-size: 13px;
  transition: background .15s, border-color .15s;
}
.btn-ghost:hover { background: var(--bg-3); border-color: #3d4b5c; }

.layout { flex: 1; display: flex; min-height: 0; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 260px; flex-shrink: 0; background: var(--bg-2);
  border-right: 1px solid var(--border); display: flex; flex-direction: column;
}
.sidebar-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; font-weight: 600; font-size: 13px;
  text-transform: uppercase; letter-spacing: .04em; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.badge {
  background: var(--bg-3); color: var(--text); border-radius: 20px;
  padding: 1px 9px; font-size: 12px; font-weight: 600;
}
.agent-list { overflow-y: auto; flex: 1; }
.agent-empty { padding: 24px 16px; text-align: center; font-size: 13px; color: var(--muted); }

.agent-item {
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  cursor: pointer; transition: background .12s; position: relative;
}
.agent-item:hover { background: var(--bg-3); }
.agent-item.active { background: var(--bg-3); }
.agent-item.active::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  width: 3px; background: var(--accent);
}
.agent-item .a-name { font-weight: 600; display: flex; align-items: center; gap: 7px; }
.agent-item .a-os { font-size: 12px; color: var(--muted); margin-top: 2px; }
.agent-item .a-mini { display: flex; gap: 10px; margin-top: 8px; font-size: 11px; color: var(--muted); }
.agent-item .a-mini b { color: var(--text); font-weight: 600; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.placeholder {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  color: var(--muted); gap: 12px;
}
.placeholder-icon { font-size: 52px; opacity: .6; }

.workspace { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.ws-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px 12px;
}
.ws-header h2 { margin: 0; font-size: 18px; }
.quickstats { display: flex; gap: 16px; }
.quickstats .qs { text-align: right; }
.quickstats .qs .qs-val { font-weight: 700; font-size: 15px; }
.quickstats .qs .qs-lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; }

.tabs { display: flex; gap: 2px; padding: 0 16px; border-bottom: 1px solid var(--border); }
.tab {
  background: transparent; border: none; color: var(--muted);
  padding: 10px 16px; font-size: 14px; border-bottom: 2px solid transparent;
  margin-bottom: -1px; transition: color .12s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }

.panel { display: none; flex: 1; min-height: 0; flex-direction: column; padding: 16px 20px; overflow: auto; }
.panel.active { display: flex; }
.panel-toolbar {
  display: flex; align-items: center; gap: 12px; margin-bottom: 12px; flex-wrap: wrap;
}
.btn {
  background: var(--accent); border: none; color: #fff; padding: 8px 16px;
  border-radius: 7px; font-size: 13px; font-weight: 600; transition: background .15s;
}
.btn:hover { background: var(--accent-2); }
.chk { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); cursor: pointer; }

/* ---------- Écran ---------- */
.screen-wrap {
  flex: 1; background: #000; border: 1px solid var(--border); border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
  position: relative; min-height: 300px;
}
#screen-img { max-width: 100%; max-height: 100%; display: none; }
#screen-img.live { display: block; }
#screen-img.controllable { cursor: crosshair; }
.screen-hint { color: var(--muted); position: absolute; }

/* ---------- Terminal ---------- */
.term-output {
  flex: 1; background: #0a0e13; border: 1px solid var(--border); border-radius: var(--radius);
  margin: 0; padding: 12px 14px; font-family: var(--mono); font-size: 13px; line-height: 1.5;
  color: #d6dee8; overflow: auto; white-space: pre-wrap; word-break: break-word; min-height: 200px;
}
.term-input-row {
  display: flex; align-items: center; gap: 8px; margin-top: 10px;
  background: #0a0e13; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px;
}
.term-prompt { color: var(--green); font-family: var(--mono); }
#term-input {
  flex: 1; background: transparent; border: none; color: var(--text);
  font-family: var(--mono); font-size: 13px; outline: none;
}

/* ---------- Fichiers ---------- */
.path-input {
  flex: 1; background: var(--bg); border: 1px solid var(--border); border-radius: 7px;
  color: var(--text); padding: 7px 12px; font-size: 13px;
}
.path-input:focus { outline: none; border-color: var(--accent); }
.upload-btn { cursor: pointer; }
.files-list { flex: 1; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.file-row {
  display: flex; align-items: center; gap: 12px; padding: 9px 14px;
  border-bottom: 1px solid var(--border); cursor: pointer; font-size: 13px;
}
.file-row:hover { background: var(--bg-3); }
.file-row .f-icon { width: 18px; text-align: center; }
.file-row .f-name { flex: 1; }
.file-row .f-size { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.file-row .f-dl {
  opacity: 0; color: var(--accent); font-size: 12px; transition: opacity .12s;
}
.file-row:hover .f-dl { opacity: 1; }

/* ---------- Monitoring ---------- */
.monitor-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; margin-bottom: 16px; }
.metric-card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.metric-label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.metric-value { font-size: 26px; font-weight: 700; margin: 6px 0 10px; }
.bar { height: 6px; background: var(--bg); border-radius: 4px; overflow: hidden; }
.bar-fill { height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .4s, background .4s; }
.disks { display: flex; flex-direction: column; gap: 10px; margin-bottom: 16px; }
.disk-row { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; }
.disk-head { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 8px; }
.sysinfo h3 { font-size: 14px; margin: 0 0 8px; }
.sysinfo #m-sysinfo { line-height: 1.7; font-size: 12px; }

/* ---------- Power ---------- */
.power-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 16px; }
.power-btn {
  background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius);
  color: var(--text); padding: 22px 16px; font-size: 26px;
  display: flex; flex-direction: column; align-items: center; gap: 10px; transition: all .15s;
}
.power-btn span { font-size: 13px; }
.power-btn:hover { background: var(--bg-3); border-color: #3d4b5c; }
.power-btn.warn:hover { border-color: var(--yellow); color: var(--yellow); }
.power-btn.danger:hover { border-color: var(--red); color: var(--red); }

/* ---------- Toasts ---------- */
.toasts { position: fixed; bottom: 18px; right: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--bg-3); border: 1px solid var(--border); border-left-width: 3px;
  border-radius: 8px; padding: 12px 16px; font-size: 13px; min-width: 220px; max-width: 340px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); animation: slidein .2s ease;
}
.toast.info { border-left-color: var(--accent); }
.toast.warn { border-left-color: var(--yellow); }
.toast.error { border-left-color: var(--red); }
@keyframes slidein { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Selects compacts (écran) ---------- */
.mini-select {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 7px; padding: 6px 10px; font-size: 13px;
}
.mini-select:focus { outline: none; border-color: var(--accent); }

/* ---------- Fichiers : actions par ligne ---------- */
.file-row .f-actions { display: flex; gap: 6px; opacity: 0; transition: opacity .12s; }
.file-row:hover .f-actions { opacity: 1; }
.f-act {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 6px; padding: 3px 8px; font-size: 12px;
}
.f-act:hover { color: var(--text); border-color: #3d4b5c; }
.f-act.danger:hover { color: var(--red); border-color: var(--red); }

/* ---------- Éditeur de texte ---------- */
.editor {
  position: absolute; inset: 0; background: var(--bg); z-index: 20;
  display: flex; flex-direction: column; padding: 16px 20px;
}
.panel[data-panel="files"] { position: relative; }
.editor-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.editor-actions { display: flex; gap: 8px; }
.editor-area {
  flex: 1; background: #0a0e13; border: 1px solid var(--border); border-radius: var(--radius);
  color: #d6dee8; padding: 12px 14px; font-size: 13px; line-height: 1.5; resize: none; outline: none;
}

/* ---------- Applications ---------- */
.apps-list { flex: 1; overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
.app-row {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.app-row:hover { background: var(--bg-3); }
.app-info { flex: 1; min-width: 0; }
.app-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.app-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.app-uninstall {
  background: transparent; border: 1px solid var(--border); color: var(--muted);
  border-radius: 6px; padding: 5px 12px; font-size: 12px; flex-shrink: 0;
}
.app-uninstall:hover { color: var(--red); border-color: var(--red); }

/* ---------- Auto-start ---------- */
.autostart-box {
  margin-top: 20px; background: var(--bg-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px;
}
.autostart-box h3 { margin: 0 0 4px; font-size: 15px; }
.autostart-row { display: flex; align-items: center; gap: 16px; margin-top: 12px; flex-wrap: wrap; }
.firmware-info { margin: 10px 0; font-size: 12px; line-height: 1.7; }
.power-btn-inline {
  background: var(--bg-3); border: 1px solid var(--border); color: var(--text);
  border-radius: 8px; padding: 8px 16px; font-size: 13px; font-weight: 600;
}
.power-btn-inline.warn:hover { border-color: var(--yellow); color: var(--yellow); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #2b3440; border-radius: 6px; }
::-webkit-scrollbar-thumb:hover { background: #3d4b5c; }
