:root {
  --bg: #0b0f17;
  --bg-2: #111824;
  --bg-3: #16202e;
  --line: #1f2c3d;
  --text: #e7eef7;
  --dim: #8aa0b8;
  --accent: #4f8cff;
  --accent-2: #21d4a8;
  --warn: #ff6b6b;
  --ok: #21d4a8;
  --radius: 14px;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

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

/* ---------- brand ---------- */
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 26px; letter-spacing: 1px; }
.brand-sub { margin: 2px 0 0; color: var(--dim); font-size: 12px; }
.brand-dot {
  width: 16px; height: 16px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, var(--accent-2), var(--accent));
  box-shadow: 0 0 16px var(--accent);
}
.brand-dot.small { width: 11px; height: 11px; }

/* ---------- login ---------- */
.login {
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background:
    radial-gradient(900px 500px at 50% -10%, #16263f 0%, transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 360px;
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 26px 22px 18px;
  box-shadow: 0 24px 60px rgba(0,0,0,.5);
}
.login-hint { color: var(--dim); font-size: 14px; margin: 18px 0 12px; }
.pin-display { display: flex; gap: 14px; justify-content: center; margin: 8px 0 6px; }
.pin-dot {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid var(--line); background: transparent;
  transition: .15s;
}
.pin-dot.filled { background: var(--accent); border-color: var(--accent); box-shadow: 0 0 10px var(--accent); }
.pin-error { color: var(--warn); font-size: 13px; min-height: 18px; text-align: center; margin-bottom: 6px; }

.keypad {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 6px 0 16px;
}
.key {
  height: 62px; font-size: 22px; font-family: var(--mono);
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--line); border-radius: var(--radius);
  cursor: pointer; transition: .1s; user-select: none;
}
.key:active { transform: scale(.96); background: var(--accent); border-color: var(--accent); }
.key.ghost { background: transparent; color: var(--dim); font-size: 18px; }
.login-foot { color: var(--dim); font-size: 11px; line-height: 1.5; margin: 4px 0 0; }

/* ---------- app shell ---------- */
.app { display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  background: var(--bg-2);
}
.topbar-brand { display: flex; align-items: center; gap: 8px; font-weight: 600; }

/* dynamic socket/agent dropdown (populated live from the gateway) */
.target-wrap { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.target-select {
  flex: 1; min-width: 0;
  background: var(--bg-3); color: #fff;
  border: 1px solid var(--accent); border-radius: 999px;
  padding: 8px 13px; font-size: 13px; cursor: pointer;
  background-image: linear-gradient(180deg, #1c3357, #14233a);
  max-width: 100%;
}
.target-select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.target-select optgroup { background: var(--bg-2); color: var(--dim); font-style: normal; }
.target-select option { background: var(--bg-2); color: var(--text); }

.topbar-right { display: flex; align-items: center; gap: 8px; }
.iconbtn.ghost { background: transparent; color: var(--dim); font-size: 18px; width: 34px; height: 34px; }

/* live telemetry strip for the selected device socket */
.telemetry {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
  padding: 8px 12px; border-bottom: 1px solid var(--line);
  background: var(--bg-2); font-family: var(--mono); font-size: 12px;
  overflow-x: auto;
}
.telemetry .tlabel { color: var(--accent-2); text-transform: uppercase; letter-spacing: .5px; margin-right: 4px; }
.telemetry .chip {
  display: inline-flex; gap: 6px; align-items: baseline;
  background: var(--bg-3); border: 1px solid var(--line);
  border-radius: 8px; padding: 4px 8px; white-space: nowrap;
}
.telemetry .chip .k { color: var(--dim); }
.telemetry .chip .v { color: var(--text); }
.conn { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--dim); font-family: var(--mono); }
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); transition: .2s; }
.conn.online .conn-dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.conn.connecting .conn-dot { background: #ffb020; }
.iconbtn {
  background: var(--bg-3); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; width: 38px; height: 38px; cursor: pointer; font-size: 16px;
}

/* ---------- chat ---------- */
.chat {
  flex: 1; overflow-y: auto; padding: 16px 12px 8px;
  display: flex; flex-direction: column; gap: 10px;
}
.msg { max-width: 80%; padding: 10px 13px; border-radius: 14px; font-size: 15px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--bg-2); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.sys { align-self: center; background: transparent; color: var(--dim); font-size: 12px; font-family: var(--mono); text-align: center; max-width: 92%; }
.msg .meta { display: block; font-size: 10px; color: var(--dim); margin-bottom: 3px; font-family: var(--mono); text-transform: uppercase; letter-spacing: .5px; }
.msg.user .meta { color: #d4e3ff; }
.msg.streaming::after { content: "▋"; animation: blink 1s steps(2) infinite; color: var(--accent-2); }
@keyframes blink { 50% { opacity: 0; } }

.approval {
  align-self: stretch; background: #2a1414; border: 1px solid #5a2a2a; border-radius: 14px;
  padding: 12px; font-size: 14px; max-width: 92%;
}
.approval h4 { margin: 0 0 6px; color: var(--warn); font-size: 13px; }
.approval .acts { display: flex; gap: 8px; margin-top: 10px; }
.approval button { flex: 1; padding: 9px; border-radius: 10px; border: 1px solid var(--line); cursor: pointer; font-size: 13px; }
.approval .approve { background: var(--ok); color: #042; border-color: var(--ok); }
.approval .deny { background: var(--bg-3); color: var(--text); }

/* ---------- composer ---------- */
.composer { border-top: 1px solid var(--line); background: var(--bg-2); padding: 10px 12px calc(10px + env(safe-area-inset-bottom)); }
.composer-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.composer-row:last-of-type { margin-bottom: 0; }
.lang {
  background: var(--bg-3); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 7px 10px; font-size: 13px; max-width: 60%;
}
.tts-toggle { display: flex; align-items: center; gap: 6px; color: var(--dim); font-size: 13px; }
.micbtn, .sendbtn {
  flex: 0 0 auto; width: 46px; height: 46px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--bg-3); color: var(--text);
  font-size: 20px; cursor: pointer; transition: .12s;
}
.micbtn.listening { background: var(--warn); border-color: var(--warn); animation: pulse 1.2s infinite; }
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(255,107,107,.5); } 50% { box-shadow: 0 0 0 10px rgba(255,107,107,0); } }
.sendbtn { background: var(--accent); border-color: var(--accent); color: #fff; }
#input {
  flex: 1; resize: none; max-height: 120px;
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  padding: 12px; font-size: 15px; font-family: var(--sans); line-height: 1.4;
}
#input:focus, .lang:focus, .key:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.composer-foot { display: flex; justify-content: space-between; font-size: 11px; color: var(--dim); font-family: var(--mono); margin-top: 8px; }
.dim { color: var(--dim); }

@media (min-width: 720px) {
  .msg { max-width: 65%; }
  .login-card { max-width: 380px; }
}
