:root {
  --bg: #0b0f17;
  --panel: #131a26;
  --panel-2: #1a2333;
  --line: #243046;
  --text: #e6ebf4;
  --muted: #8b97ad;
  --accent: #4fa3ff;
  --accent-2: #2b7fe0;
  --ok: #3ccf8e;
  --warn: #f5b84b;
  --bad: #ff6b6b;
  --radius: 14px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* ---------- auth ---------- */
.auth {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 18px;
}
.card {
  width: 100%;
  max-width: 400px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 22px;
}
.brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.brand img { width: 44px; height: 44px; }
.brand h1 { font-size: 22px; margin: 0; letter-spacing: .5px; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 14px; }
label { display: block; font-size: 14px; color: var(--muted); margin: 14px 0 6px; }
input[type=tel], input[type=password], input[type=text], select {
  width: 100%;
  padding: 14px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 12px;
  outline: none;
  font-size: 17px;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
input.code { text-align: center; font-size: 28px; letter-spacing: 10px; font-variant-numeric: tabular-nums; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 20px;
  padding: 14px;
  border: 0;
  border-radius: 12px;
  background: var(--accent-2);
  font-weight: 600;
  cursor: pointer;
}
.btn:disabled { opacity: .55; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: transparent; border: 1px solid var(--bad); color: var(--bad); }
.btn.sm { width: auto; margin: 0; padding: 8px 12px; font-size: 14px; border-radius: 10px; }
.error { color: var(--bad); font-size: 14px; margin-top: 12px; min-height: 1em; }
.qr { display: block; margin: 16px auto; background: #fff; border-radius: 12px; padding: 8px; width: 240px; height: 240px; }
.secret { font-family: ui-monospace, Menlo, monospace; text-align: center; background: var(--bg); padding: 10px; border-radius: 10px; word-break: break-all; }
.codes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; font-family: ui-monospace, Menlo, monospace; margin: 14px 0; }
.codes span { background: var(--bg); padding: 8px; border-radius: 8px; text-align: center; }
.steps { color: var(--muted); font-size: 14px; padding-left: 20px; }

/* ---------- app ---------- */
.app { display: flex; flex-direction: column; height: 100%; height: 100dvh; }
.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.topbar h2 { flex: 1; margin: 0; font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 10px;
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 18px;
}
main { flex: 1; overflow: hidden; position: relative; }
.view { position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.pad { padding: 16px; }

.tabs {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--panel);
  padding-bottom: var(--safe-bottom);
}
.tabs button {
  flex: 1;
  background: none;
  border: 0;
  padding: 10px 0 8px;
  color: var(--muted);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
}
.tabs button .ico { font-size: 20px; }
.tabs button.active { color: var(--accent); }

/* chat */
#view-chat { display: flex; flex-direction: column; }
.messages { flex: 1; overflow-y: auto; padding: 16px 14px 8px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 88%; padding: 10px 13px; border-radius: 16px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent-2); border-bottom-right-radius: 4px; }
.msg.assistant { align-self: flex-start; background: var(--panel-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.error { align-self: center; color: var(--bad); background: transparent; font-size: 14px; }
.msg pre { background: var(--bg); padding: 10px; border-radius: 8px; overflow-x: auto; white-space: pre; font-size: 13px; margin: 6px 0; }
.msg code { font-family: ui-monospace, Menlo, monospace; font-size: 14px; }
.msg :not(pre) > code { background: rgba(0,0,0,.25); padding: 1px 5px; border-radius: 5px; }
.typing::after { content: "▍"; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { opacity: 0; } }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 30px; }
.empty img { width: 64px; opacity: .9; }
.composer {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--panel);
}
.composer textarea {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 11px 13px;
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 20px;
  outline: none;
  font-size: 16px;
}
.send {
  width: 44px; height: 44px; border-radius: 50%; border: 0;
  background: var(--accent-2); font-size: 18px; cursor: pointer; align-self: flex-end;
}
.send:disabled { opacity: .5; }
.mic {
  width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--bg); font-size: 19px; cursor: pointer; align-self: flex-end; flex: none;
}
.mic.listening { background: var(--bad); border-color: var(--bad); animation: pulse 1.2s ease-in-out infinite; }
.mic.speaking { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,163,255,.35); }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,107,107,.6); } 50% { box-shadow: 0 0 0 10px rgba(255,107,107,0); } }
.icon-btn.on { background: var(--accent-2); border-color: var(--accent); }
.icon-btn.armed { background: var(--ok); border-color: var(--ok); animation: pulse 1s ease-in-out infinite; }
.voice-status { text-align: center; font-size: 13px; color: var(--muted); padding: 4px 0 0; min-height: 18px; }

/* lecteur YouTube */
.player { border-bottom: 1px solid var(--line); background: #000; flex: none; }
.player-frame { position: relative; width: 100%; max-width: 900px; margin: 0 auto; aspect-ratio: 16 / 9; max-height: 42vh; }
.player-frame iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; }
.player-frame.empty { display: none; }
.player-bar { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--panel); }
.player-title { flex: 1; font-size: 13px; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.player-bar .icon-btn { width: 34px; height: 34px; font-size: 15px; }
.results { list-style: none; margin: 0; padding: 6px; max-height: 38vh; overflow-y: auto; background: var(--panel); }
.results li { display: flex; gap: 10px; align-items: center; padding: 6px; border-radius: 10px; cursor: pointer; }
.results li:hover, .results li.active { background: var(--panel-2); }
.results img { width: 96px; height: 54px; object-fit: cover; border-radius: 6px; flex: none; background: #000; }
.results .rt { font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.results .rc { font-size: 12px; color: var(--muted); }
.yt-link { display: inline-block; margin-top: 6px; padding: 8px 12px; border-radius: 10px; background: #c4302b; color: #fff; text-decoration: none; font-weight: 600; font-size: 14px; }

/* drawer */
.drawer-bg { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 10; }
.drawer {
  position: fixed; top: 0; bottom: 0; left: 0; width: 82%; max-width: 330px; z-index: 11;
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; padding-top: env(safe-area-inset-top, 0px);
}
.drawer header { padding: 14px; border-bottom: 1px solid var(--line); }
.drawer ul { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.drawer li { display: flex; align-items: center; gap: 6px; border-radius: 10px; }
.drawer li.active { background: var(--panel-2); }
.drawer li button.open { flex: 1; text-align: left; background: none; border: 0; padding: 12px 10px; cursor: pointer; overflow: hidden; }
.drawer li .t { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.drawer li .d { font-size: 12px; color: var(--muted); }
.drawer li button.del { background: none; border: 0; color: var(--muted); padding: 10px; cursor: pointer; }

/* cartes */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tile { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.tile .k { color: var(--muted); font-size: 13px; }
.tile .v { font-size: 24px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.tile .s { color: var(--muted); font-size: 12px; margin-top: 2px; }
.bar { height: 6px; background: var(--bg); border-radius: 4px; margin-top: 10px; overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--ok); border-radius: 4px; transition: width .4s; }
.bar i.warn { background: var(--warn); }
.bar i.bad { background: var(--bad); }
h3.section { font-size: 14px; color: var(--muted); text-transform: uppercase; letter-spacing: .8px; margin: 22px 2px 10px; }
.list { display: flex; flex-direction: column; gap: 10px; }
.item { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 13px 14px; }
.item .row { display: flex; align-items: center; gap: 10px; }
.item .name { flex: 1; font-weight: 600; font-size: 15px; word-break: break-all; }
.item .meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.item .actions { display: flex; gap: 8px; margin-top: 10px; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.running { background: var(--ok); }
.dot.exited, .dot.dead { background: var(--bad); }
.dot.restarting { background: var(--warn); }
.logs {
  background: #05070b; border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-top: 10px;
  font: 11px/1.45 ui-monospace, Menlo, monospace; max-height: 50vh; overflow: auto; white-space: pre-wrap; word-break: break-all;
}
.toast {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + var(--safe-bottom));
  background: var(--panel-2); border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px; z-index: 20;
  font-size: 14px; max-width: 90%;
}
.audit { font-size: 13px; }
.audit div { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 8px; }
.audit div span:first-child { color: var(--muted); white-space: nowrap; }
.badge { font-size: 12px; padding: 2px 8px; border-radius: 20px; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); }
