/* JARVIS v4 — HUD dashboard (tema scuro unico, SPEC §7) */
:root {
  --bg0: #05080f;
  --bg1: #0a1020;
  --cyan: #19e6ff;
  --amber: #ffb000;
  --green: #39ff88;
  --red: #ff3b5c;
  --text: #d9f4ff;
  --text-dim: #a9c2d6;
  --muted: #6f88a0;
  --glass: rgba(10, 20, 38, 0.62);
  --glass-2: rgba(14, 28, 52, 0.72);
  --line: rgba(25, 230, 255, 0.16);
  --line-strong: rgba(25, 230, 255, 0.42);
  --glow: 0 0 0 1px rgba(25, 230, 255, 0.08), 0 0 24px rgba(25, 230, 255, 0.06) inset;
  --radius: 10px;
  --f-title: "Orbitron", "Rajdhani", system-ui, sans-serif;
  --f-ui: "Rajdhani", system-ui, -apple-system, "Segoe UI", sans-serif;
  --f-mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", Consolas, monospace;
  --topbar-h: 56px;
  --tabs-h: 0px;
  --gutter: 16px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: linear-gradient(160deg, var(--bg0) 0%, var(--bg1) 100%) fixed;
  background-color: var(--bg0);
  color: var(--text);
  font-family: var(--f-ui);
  font-size: 16px;
  line-height: 1.4;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
.bg-grid {
  position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background-image:
    linear-gradient(rgba(25, 230, 255, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(25, 230, 255, 0.045) 1px, transparent 1px),
    radial-gradient(ellipse at 20% 30%, rgba(25, 230, 255, 0.07), transparent 55%),
    radial-gradient(ellipse at 85% 90%, rgba(57, 255, 136, 0.035), transparent 50%);
  background-size: 32px 32px, 32px 32px, 100% 100%, 100% 100%;
  mask-image: radial-gradient(ellipse at center, #000 55%, transparent 100%);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono, code, pre { font-family: var(--f-mono); }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: var(--text); }
svg { width: 1em; height: 1em; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

/* ---------- Barra in alto ---------- */
.topbar {
  position: relative; z-index: 3;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 16px;
  padding: 0 var(--gutter);
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(5, 8, 15, 0.92), rgba(5, 8, 15, 0.6));
  backdrop-filter: blur(10px);
}
.wordmark { display: flex; align-items: center; gap: 10px; flex: none; }
.wm-ring {
  width: 22px; height: 22px; border-radius: 50%;
  border: 2px solid var(--cyan);
  box-shadow: 0 0 12px rgba(25, 230, 255, 0.6), inset 0 0 8px rgba(25, 230, 255, 0.5);
  position: relative;
}
.wm-ring::after { content: ""; position: absolute; inset: 5px; border-radius: 50%; background: var(--cyan); box-shadow: 0 0 10px var(--cyan); }
.wm-text { font-family: var(--f-title); font-weight: 900; letter-spacing: 0.32em; font-size: 18px; color: var(--cyan); text-shadow: 0 0 14px rgba(25, 230, 255, 0.55); }
.wm-ver { font-family: var(--f-mono); font-size: 11px; color: var(--muted); }
.chips { display: flex; align-items: center; gap: 8px; margin-left: auto; min-width: 0; overflow: hidden; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  height: 26px; padding: 0 10px; border-radius: 13px;
  border: 1px solid var(--line); background: rgba(25, 230, 255, 0.05);
  font-size: 13px; font-weight: 600; letter-spacing: 0.04em; color: var(--text-dim);
  white-space: nowrap; max-width: 220px; overflow: hidden; text-overflow: ellipsis;
}
.chip-arm.armed { color: var(--green); border-color: rgba(57, 255, 136, 0.45); background: rgba(57, 255, 136, 0.07); }
.chip-arm.disarmed { color: var(--red); border-color: rgba(255, 59, 92, 0.55); background: rgba(255, 59, 92, 0.1); }
.chip-ws .dot, .dev-dot { width: 8px; height: 8px; border-radius: 50%; background: #3a4a5c; flex: none; }
.chip-ws.online .dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.chip-ws.connecting .dot { background: var(--amber); box-shadow: 0 0 8px var(--amber); animation: blink 1s infinite; }
.chip-ws.offline { color: var(--red); border-color: rgba(255, 59, 92, 0.4); }
.chip-ws.offline .dot { background: var(--red); }
.chip-mock { color: var(--amber); border-color: rgba(255, 176, 0, 0.5); }
@keyframes blink { 50% { opacity: 0.35; } }

/* ---------- Schede (solo < 1100 px) ---------- */
.tabs { display: none; }

/* ---------- Layout ---------- */
.layout {
  position: relative; z-index: 1;
  height: calc(100dvh - var(--topbar-h) - env(safe-area-inset-top));
  display: grid;
  grid-template-columns: minmax(300px, 360px) minmax(0, 1fr) minmax(320px, 390px);
  grid-template-areas: "core conv panels";
  gap: 14px;
  padding: 14px var(--gutter) 14px;
}
.col-core { grid-area: core; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.col-conv { grid-area: conv; }
.col-panels { grid-area: panels; display: flex; flex-direction: column; gap: 14px; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding-right: 2px; }

/* ---------- Pannelli vetro ---------- */
.panel {
  position: relative;
  display: flex; flex-direction: column; min-height: 0;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--glow);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}
.panel::before, .panel::after {
  content: ""; position: absolute; width: 14px; height: 14px; pointer-events: none;
  border-color: var(--line-strong); border-style: solid;
}
.panel::before { top: -1px; left: -1px; border-width: 2px 0 0 2px; border-top-left-radius: var(--radius); }
.panel::after { bottom: -1px; right: -1px; border-width: 0 2px 2px 0; border-bottom-right-radius: var(--radius); }
.panel-head {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; border-bottom: 1px solid var(--line); flex: none;
}
.panel-head h2 {
  margin: 0; font-family: var(--f-title); font-size: 12px; font-weight: 700;
  letter-spacing: 0.22em; text-transform: uppercase; color: var(--cyan);
}
.panel-meta { font-size: 12px; color: var(--muted); font-family: var(--f-mono); }
.panel-foot { padding: 6px 14px 10px; font-size: 12px; font-family: var(--f-mono); }

/* ---------- Pulsanti ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 34px; padding: 0 14px; border-radius: 8px;
  border: 1px solid var(--line-strong); background: rgba(25, 230, 255, 0.07);
  color: var(--cyan); font-weight: 700; letter-spacing: 0.05em; font-size: 14px;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
}
.btn:hover { background: rgba(25, 230, 255, 0.15); box-shadow: 0 0 14px rgba(25, 230, 255, 0.18); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-primary { background: rgba(25, 230, 255, 0.18); color: #e9fdff; }
.btn-approve { border-color: rgba(57, 255, 136, 0.6); color: var(--green); background: rgba(57, 255, 136, 0.1); }
.btn-approve:hover { background: rgba(57, 255, 136, 0.2); box-shadow: 0 0 16px rgba(57, 255, 136, 0.3); }
.btn-reject { border-color: rgba(255, 59, 92, 0.6); color: var(--red); background: rgba(255, 59, 92, 0.08); }
.btn-reject:hover { background: rgba(255, 59, 92, 0.18); box-shadow: 0 0 16px rgba(255, 59, 92, 0.3); }

/* ---------- Nucleo ---------- */
.core-wrap {
  position: relative; flex: 1 1 auto; min-height: 220px;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: radial-gradient(circle at 50% 45%, rgba(25, 230, 255, 0.06), transparent 65%), rgba(5, 10, 20, 0.35);
  overflow: hidden;
}
#core { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.core-label {
  position: absolute; left: 0; right: 0; bottom: 12px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; pointer-events: none;
  text-align: center; padding: 0 10px;
}
.core-state { font-family: var(--f-title); font-size: 13px; font-weight: 700; letter-spacing: 0.3em; color: var(--cyan); text-shadow: 0 0 10px currentColor; transition: color 0.3s; }
.core-sub { font-size: 13px; color: var(--muted); min-height: 18px; }
body[data-core="thinking"] .core-state { color: var(--amber); }
body[data-core="speaking"] .core-state { color: var(--green); }
body[data-core="idle"] .core-state { color: rgba(25, 230, 255, 0.75); }

/* ---------- Composer: microfono + testo ---------- */
.composer { flex: none; display: flex; flex-direction: column; gap: 10px; }
.mic-row { display: flex; align-items: center; justify-content: center; gap: 18px; }
.mic {
  position: relative; width: 88px; height: 88px; border-radius: 50%;
  border: 2px solid var(--line-strong);
  background: radial-gradient(circle at 50% 40%, rgba(25, 230, 255, 0.22), rgba(5, 12, 24, 0.9) 70%);
  color: var(--cyan); font-size: 36px;
  display: grid; place-items: center;
  box-shadow: 0 0 22px rgba(25, 230, 255, 0.22), inset 0 0 18px rgba(25, 230, 255, 0.18);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform 0.12s, box-shadow 0.2s, border-color 0.2s, color 0.2s;
}
.mic svg { position: relative; z-index: 1; }
.mic:hover { box-shadow: 0 0 30px rgba(25, 230, 255, 0.35), inset 0 0 18px rgba(25, 230, 255, 0.25); }
.mic-glow { position: absolute; inset: -8px; border-radius: 50%; border: 2px solid transparent; pointer-events: none; transform: scale(var(--lvl, 1)); transition: transform 0.06s linear; }
.mic.continuous { border-color: var(--cyan); }
.mic.continuous .mic-glow { border-color: rgba(25, 230, 255, 0.35); }
.mic.rec { transform: scale(1.06); border-color: var(--cyan); color: #fff; box-shadow: 0 0 40px rgba(25, 230, 255, 0.6), inset 0 0 26px rgba(25, 230, 255, 0.45); }
.mic.rec .mic-glow { border-color: var(--cyan); box-shadow: 0 0 18px rgba(25, 230, 255, 0.5); }
.mic.busy { border-color: rgba(255, 176, 0, 0.6); color: var(--amber); }
.mic.denied { border-color: rgba(255, 59, 92, 0.6); color: var(--red); }
.wake-badge {
  position: absolute; bottom: -9px; left: 50%; transform: translateX(-50%); z-index: 2;
  font-family: var(--f-title); font-size: 9px; font-weight: 700; letter-spacing: 0.15em;
  padding: 2px 6px; border-radius: 8px; background: var(--bg0); color: var(--cyan);
  border: 1px solid var(--cyan); box-shadow: 0 0 8px rgba(25, 230, 255, 0.5); white-space: nowrap; pointer-events: none;
}
.btn-side {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  width: 64px; padding: 8px 0; border-radius: 10px;
  border: 1px solid var(--line); background: rgba(25, 230, 255, 0.04);
  color: var(--text-dim); font-size: 12px; font-weight: 600; letter-spacing: 0.05em;
}
.btn-side svg { font-size: 20px; }
.btn-side:hover { border-color: var(--line-strong); color: var(--cyan); }
.btn-side[aria-pressed="true"] { border-color: var(--cyan); color: var(--cyan); background: rgba(25, 230, 255, 0.14); box-shadow: 0 0 12px rgba(25, 230, 255, 0.25); }
#btn-stop:hover { color: var(--red); border-color: rgba(255, 59, 92, 0.5); }
.text-form {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 6px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--glass-2);
}
.text-form:focus-within { border-color: var(--line-strong); box-shadow: 0 0 14px rgba(25, 230, 255, 0.12); }
#text-input {
  flex: 1; min-width: 0; resize: none; border: 0; outline: 0; background: transparent;
  padding: 7px 8px; max-height: 140px; font-size: 16px; line-height: 1.35;
}
#text-input::placeholder { color: var(--muted); }
.btn-send {
  flex: none; width: 38px; height: 38px; border-radius: 9px;
  border: 1px solid var(--line-strong); background: rgba(25, 230, 255, 0.14); color: var(--cyan);
  display: grid; place-items: center; font-size: 18px;
}
.btn-send:hover { background: rgba(25, 230, 255, 0.25); }
.hint { text-align: center; font-size: 12px; color: var(--muted); letter-spacing: 0.04em; }

/* ---------- Conversazione ---------- */
.conv { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; padding: 14px; display: flex; flex-direction: column; gap: 14px; scroll-behavior: smooth; }
.conv-empty { margin: auto; text-align: center; max-width: 360px; }
.conv-empty p:first-child { font-family: var(--f-title); letter-spacing: 0.2em; color: var(--cyan); font-size: 14px; }
.msg { max-width: 92%; display: flex; flex-direction: column; gap: 4px; animation: msgIn 0.22s ease-out; }
@keyframes msgIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.msg-meta { font-size: 11px; color: var(--muted); font-family: var(--f-mono); display: flex; gap: 8px; align-items: center; }
.msg-user { align-self: flex-end; align-items: flex-end; }
.msg-user .bubble {
  background: rgba(25, 230, 255, 0.1); border: 1px solid rgba(25, 230, 255, 0.28);
  border-radius: 12px 12px 3px 12px; padding: 8px 12px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg-user .src-voice { color: var(--cyan); display: inline-flex; align-items: center; gap: 3px; }
.msg-user .src-voice svg { font-size: 13px; }
.msg-jarvis { align-self: flex-start; width: 100%; max-width: 100%; }
.msg-jarvis .body { border-left: 2px solid rgba(25, 230, 255, 0.5); padding: 2px 0 2px 12px; display: flex; flex-direction: column; gap: 8px; }
.msg-jarvis .who { font-family: var(--f-title); font-size: 10px; letter-spacing: 0.25em; color: var(--cyan); }
.txt { overflow-wrap: anywhere; font-size: 16.5px; line-height: 1.5; color: #e6f7ff; }
.txt:empty { display: none; }
.txt p { margin: 0 0 6px; }
.txt p:last-child { margin-bottom: 0; }
.txt code { background: rgba(25, 230, 255, 0.08); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; font-size: 0.86em; }
.txt pre { margin: 6px 0; padding: 10px; border-radius: 8px; background: rgba(0, 0, 0, 0.45); border: 1px solid var(--line); overflow-x: auto; font-size: 13px; line-height: 1.45; }
.txt pre code { background: none; border: 0; padding: 0; }
.txt ul { margin: 4px 0; padding-left: 20px; }
.txt strong { color: #fff; }
.txt a { color: var(--cyan); }
.streaming .txt:last-of-type::after { content: "▍"; color: var(--cyan); animation: blink 0.9s infinite; margin-left: 1px; }
.msg-jarvis.cancelled .who::after { content: " · interrotto"; color: var(--amber); }
.msg-jarvis.error .body { border-left-color: var(--red); }
.usage { font-size: 11px; color: var(--muted); font-family: var(--f-mono); }

/* Card strumento */
.tool {
  border: 1px solid rgba(255, 176, 0, 0.45); border-radius: 9px;
  background: rgba(255, 176, 0, 0.045); overflow: hidden;
}
.tool.ok { border-color: rgba(57, 255, 136, 0.38); background: rgba(57, 255, 136, 0.035); }
.tool.fail { border-color: rgba(255, 59, 92, 0.5); background: rgba(255, 59, 92, 0.05); }
.tool-head {
  width: 100%; display: flex; align-items: center; gap: 8px; text-align: left;
  padding: 7px 10px; background: none; border: 0; min-width: 0;
}
.tool-ico { flex: none; width: 16px; height: 16px; display: grid; place-items: center; }
.tool .spin { width: 13px; height: 13px; border-radius: 50%; border: 2px solid rgba(255, 176, 0, 0.25); border-top-color: var(--amber); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.tool.ok .tool-ico { color: var(--green); }
.tool.fail .tool-ico { color: var(--red); }
.tool-name { font-family: var(--f-mono); font-size: 12.5px; font-weight: 600; color: var(--amber); flex: none; }
.tool.ok .tool-name { color: var(--green); }
.tool.fail .tool-name { color: var(--red); }
.tool-sum { flex: 1; min-width: 0; font-size: 14px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tool-dev { flex: none; font-size: 11px; padding: 1px 6px; border-radius: 6px; border: 1px solid var(--line); color: var(--cyan); font-family: var(--f-mono); }
.tool-ms { flex: none; font-size: 11px; color: var(--muted); font-family: var(--f-mono); }
.tool-chev { flex: none; color: var(--muted); transition: transform 0.15s; font-size: 14px; }
.tool.open .tool-chev { transform: rotate(90deg); }
.tool-body { display: none; border-top: 1px solid rgba(255, 255, 255, 0.06); }
.tool.open .tool-body { display: block; }
.tool-body pre {
  margin: 0; padding: 10px 12px; max-height: 280px; overflow: auto;
  font-size: 12.5px; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere;
  color: #cfe9f5; background: rgba(0, 0, 0, 0.35);
}
.tool-body .result-sum { padding: 8px 12px; font-size: 14px; color: var(--text-dim); }
.tool-body img { display: block; max-width: 100%; height: auto; border-top: 1px solid var(--line); cursor: zoom-in; }

/* ---------- Dispositivi ---------- */
.devices { list-style: none; margin: 0; padding: 6px 8px; }
.devices > li.muted { padding: 8px 6px; }
.dev { display: flex; align-items: center; gap: 10px; padding: 8px 6px; border-bottom: 1px solid rgba(25, 230, 255, 0.07); }
.dev:last-child { border-bottom: 0; }
.dev.online .dev-dot { background: var(--green); box-shadow: 0 0 8px var(--green); }
.dev-info { flex: 1; min-width: 0; }
.dev-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dev-sub { font-size: 12px; color: var(--muted); font-family: var(--f-mono); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dev-actions { display: flex; gap: 6px; flex: none; }
.pill {
  height: 24px; padding: 0 9px; border-radius: 12px; font-size: 12px; font-weight: 700; letter-spacing: 0.04em;
  border: 1px solid var(--line); background: none; color: var(--muted);
}
.pill:hover { border-color: var(--line-strong); color: var(--cyan); }
.pill.active { color: var(--bg0); background: var(--cyan); border-color: var(--cyan); box-shadow: 0 0 10px rgba(25, 230, 255, 0.45); }
.pill.danger:hover, .pill.danger.armed { color: var(--red); border-color: rgba(255, 59, 92, 0.6); }

/* ---------- Cryptohost ---------- */
.host { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 12px 14px 4px; }
.stat { display: flex; flex-direction: column; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: rgba(25, 230, 255, 0.03); }
.stat-v { font-family: var(--f-title); font-size: 26px; font-weight: 700; color: var(--green); line-height: 1.1; }
.stat-v.bad { color: var(--red); text-shadow: 0 0 10px rgba(255, 59, 92, 0.5); }
.stat-v.zero { color: var(--text-dim); }
.stat-l { font-size: 12px; color: var(--muted); letter-spacing: 0.05em; }

/* ---------- Registro azioni ---------- */
.col-panels > .panel { flex: none; }
.col-panels > .panel-audit { min-height: 180px; flex: 1 0 240px; }
.audit { list-style: none; margin: 0; padding: 4px 8px 8px; overflow-y: auto; flex: 1; min-height: 0; max-height: 420px; }
.audit > li.muted { padding: 8px 6px; }
.au { display: grid; grid-template-columns: auto 1fr auto; gap: 2px 8px; padding: 6px; border-bottom: 1px solid rgba(25, 230, 255, 0.06); font-size: 13px; }
.au.fresh { animation: flash 1.4s ease-out; }
@keyframes flash { from { background: rgba(25, 230, 255, 0.16); } to { background: transparent; } }
.au-t { font-family: var(--f-mono); color: var(--muted); font-size: 11.5px; }
.au-tool { font-family: var(--f-mono); font-weight: 600; font-size: 12px; color: var(--cyan); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.au-st { font-size: 11px; font-weight: 700; letter-spacing: 0.04em; }
.au-st.ok { color: var(--green); }
.au-st.ko { color: var(--red); }
.au-cmd { grid-column: 1 / -1; font-family: var(--f-mono); font-size: 11.5px; color: var(--text-dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.au-tag { font-size: 10px; padding: 0 5px; border-radius: 5px; border: 1px solid rgba(255, 176, 0, 0.5); color: var(--amber); margin-left: 4px; }

/* ---------- Impostazioni ---------- */
.settings { padding: 10px 14px 14px; display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); letter-spacing: 0.04em; }
.field > span { font-weight: 600; }
.field-inline { flex-direction: row; align-items: center; gap: 10px; }
.field-inline input { flex: 1; }
.field .row { display: flex; gap: 8px; }
.field .row select { flex: 1; min-width: 0; }
select, input[type="text"] {
  height: 34px; padding: 0 10px; border-radius: 8px;
  border: 1px solid var(--line); background: rgba(5, 12, 24, 0.8);
  font-size: 15px; outline: 0;
}
select:focus, input[type="text"]:focus { border-color: var(--line-strong); }
select option { background: #0a1020; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: 15px; cursor: pointer; user-select: none; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle i {
  position: relative; flex: none; width: 38px; height: 20px; border-radius: 10px;
  border: 1px solid var(--line-strong); background: rgba(5, 12, 24, 0.9); transition: background 0.15s;
}
.toggle i::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 14px; height: 14px; border-radius: 50%;
  background: var(--muted); transition: transform 0.15s, background 0.15s;
}
.toggle input:checked + i { background: rgba(25, 230, 255, 0.22); }
.toggle input:checked + i::after { transform: translateX(18px); background: var(--cyan); box-shadow: 0 0 8px var(--cyan); }
.toggle input:focus-visible + i { outline: 2px solid var(--cyan); outline-offset: 2px; }
.arm-box {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  margin-top: 4px; padding: 10px 12px; border-radius: 9px;
  border: 1px solid rgba(57, 255, 136, 0.35); background: rgba(57, 255, 136, 0.05);
}
.arm-box.disarmed { border-color: rgba(255, 59, 92, 0.5); background: rgba(255, 59, 92, 0.07); }
.arm-title { font-family: var(--f-title); font-size: 11px; letter-spacing: 0.2em; }
.arm-desc { font-size: 13px; }
.btn-arm { border-color: rgba(255, 59, 92, 0.6); color: var(--red); background: rgba(255, 59, 92, 0.08); min-width: 118px; }
.arm-box.disarmed .btn-arm { border-color: rgba(57, 255, 136, 0.6); color: var(--green); background: rgba(57, 255, 136, 0.08); }
.btn-arm.pending { animation: pulseBtn 0.7s infinite alternate; }
@keyframes pulseBtn { to { box-shadow: 0 0 18px currentColor; } }

/* ---------- Modali ---------- */
.modal-back {
  position: fixed; inset: 0; z-index: 20;
  display: grid; place-items: center; padding: 16px;
  background: rgba(2, 4, 9, 0.72); backdrop-filter: blur(4px);
  animation: fadeIn 0.15s ease-out;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  position: relative; width: min(560px, 100%); max-height: calc(100dvh - 32px); overflow-y: auto;
  padding: 18px 18px 16px; border-radius: 12px;
  background: linear-gradient(180deg, rgba(14, 26, 48, 0.97), rgba(8, 14, 28, 0.97));
  border: 1px solid var(--line-strong);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6), 0 0 30px rgba(25, 230, 255, 0.12);
}
.modal h3 { margin: 0 0 8px; font-family: var(--f-title); font-size: 16px; letter-spacing: 0.08em; color: #eafcff; }
.modal-x { position: absolute; top: 8px; right: 10px; width: 32px; height: 32px; border: 0; background: none; color: var(--muted); font-size: 24px; line-height: 1; }
.modal-x:hover { color: var(--cyan); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; flex-wrap: wrap; }
.modal-confirm { border: 2px solid var(--red); animation: redPulse 1.2s ease-in-out infinite; }
@keyframes redPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 59, 92, 0.6), 0 0 22px rgba(255, 59, 92, 0.35), 0 20px 60px rgba(0, 0, 0, 0.6); }
  50% { box-shadow: 0 0 0 6px rgba(255, 59, 92, 0), 0 0 46px rgba(255, 59, 92, 0.65), 0 20px 60px rgba(0, 0, 0, 0.6); }
}
.modal-kicker { font-family: var(--f-title); font-size: 10px; letter-spacing: 0.22em; color: var(--red); margin-bottom: 8px; }
.modal-confirm p { margin: 0 0 10px; }
.confirm-device { font-size: 13px; color: var(--cyan); margin-bottom: 8px; font-family: var(--f-mono); }
.confirm-cmd {
  margin: 0 0 12px; padding: 12px; border-radius: 8px; max-height: 220px; overflow: auto;
  background: rgba(0, 0, 0, 0.55); border: 1px solid rgba(255, 59, 92, 0.4);
  color: #ffd6dd; font-size: 13px; white-space: pre-wrap; overflow-wrap: anywhere;
}
.countdown { height: 4px; border-radius: 2px; background: rgba(255, 59, 92, 0.15); overflow: hidden; }
.countdown-bar { height: 100%; width: 100%; background: var(--red); box-shadow: 0 0 8px var(--red); transform-origin: left; }
.confirm-foot { display: flex; justify-content: space-between; align-items: center; margin-top: 6px; gap: 10px; font-size: 13px; }
.modal-confirm .modal-actions .btn { min-width: 120px; height: 42px; font-size: 16px; }
.modal-confirm.resolved { animation: none; border-color: var(--line-strong); }
.pair-step .field { margin-top: 6px; }
.warn-line { margin: 4px 0 12px; color: var(--amber); font-size: 14px; }
.kv { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; font-size: 13px; color: var(--muted); flex-wrap: wrap; }
.kv > span { width: 82px; flex: none; }
.kv code { flex: 1; min-width: 0; padding: 6px 8px; border-radius: 6px; background: rgba(0, 0, 0, 0.45); border: 1px solid var(--line); color: var(--text); overflow-wrap: anywhere; font-size: 12.5px; }
.kv code.token { color: var(--green); }
.install { margin-top: 10px; }
.install-h { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.install pre { margin: 0; padding: 10px; border-radius: 8px; background: rgba(0, 0, 0, 0.5); border: 1px solid var(--line); font-size: 12px; white-space: pre-wrap; overflow-wrap: anywhere; color: #cfe9f5; }
.modal-expired { border-color: rgba(255, 176, 0, 0.6); text-align: center; }
.modal-expired .modal-actions { justify-content: center; }
.img-zoom { max-width: 100%; max-height: calc(100dvh - 32px); border: 1px solid var(--line-strong); border-radius: 8px; }

/* ---------- Toast ---------- */
.toasts {
  position: fixed; z-index: 30; top: calc(var(--topbar-h) + 10px + env(safe-area-inset-top)); right: 16px;
  display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 32px)); pointer-events: none;
}
.toast {
  pointer-events: auto; padding: 10px 12px 10px 14px; border-radius: 9px;
  background: rgba(10, 18, 34, 0.96); border: 1px solid var(--line-strong); border-left: 3px solid var(--cyan);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5); font-size: 14.5px; display: flex; gap: 10px; align-items: flex-start;
  animation: toastIn 0.2s ease-out;
}
.toast.warn { border-left-color: var(--amber); }
.toast.error { border-left-color: var(--red); }
.toast.ok { border-left-color: var(--green); }
.toast .t-x { margin-left: auto; border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; padding: 0 2px; }
.toast.out { opacity: 0; transform: translateX(20px); transition: all 0.25s; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } }

/* Scrollbar */
* { scrollbar-width: thin; scrollbar-color: rgba(25, 230, 255, 0.25) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(25, 230, 255, 0.2); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- Responsive ---------- */
@media (max-width: 1360px) { .chip-opt { display: none; } }

/* Tablet 800–1099: nucleo a sinistra, contenuto a schede a destra */
@media (max-width: 1099px) {
  :root { --tabs-h: 44px; }
  .tabs {
    position: relative; z-index: 2;
    display: flex; gap: 4px; height: var(--tabs-h); align-items: stretch;
    padding: 0 var(--gutter); border-bottom: 1px solid var(--line);
    background: rgba(5, 8, 15, 0.6); overflow-x: auto; scrollbar-width: none;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs button {
    flex: 1 0 auto; border: 0; background: none; padding: 0 10px;
    font-weight: 700; font-size: 14px; letter-spacing: 0.06em; color: var(--muted);
    border-bottom: 2px solid transparent; text-transform: uppercase;
  }
  .tabs button[aria-selected="true"] { color: var(--cyan); border-bottom-color: var(--cyan); text-shadow: 0 0 10px rgba(25, 230, 255, 0.5); }
  .tabs button .badge { display: inline-block; min-width: 16px; padding: 0 4px; margin-left: 4px; border-radius: 8px; font-size: 11px; background: var(--amber); color: var(--bg0); }
  .layout {
    height: calc(100dvh - var(--topbar-h) - var(--tabs-h) - env(safe-area-inset-top));
    grid-template-columns: minmax(250px, 300px) minmax(0, 1fr);
    grid-template-areas: "core content";
  }
  .col-conv, .col-panels { grid-area: content; }
  .col-conv, .col-panels .panel { display: none; }
  body.tab-conv .col-conv { display: flex; }
  body.tab-conv .col-panels { display: none; }
  body.tab-devices .panel[data-tab="devices"],
  body.tab-host .panel[data-tab="host"],
  body.tab-audit .panel[data-tab="audit"],
  body.tab-settings .panel[data-tab="settings"] { display: flex; }
  .panel-audit { flex: 1 1 auto; }
  .audit { max-height: none; }
}

/* Telefono < 800: una colonna, nucleo ridotto in alto, microfono fisso in basso */
@media (max-width: 799px) {
  :root { --topbar-h: 50px; --gutter: 12px; --composer-h: 150px; }
  .chips .chip:not(.chip-arm):not(.chip-ws):not(.chip-mock) { display: none; }
  .chip { height: 24px; font-size: 12px; padding: 0 8px; }
  .chip-ws span { display: none; }
  .wm-text { font-size: 16px; letter-spacing: 0.26em; }
  .wm-ver { display: none; }
  .tabs { padding: 0 6px; gap: 0; }
  .tabs button { padding: 0 8px; font-size: 13px; letter-spacing: 0.03em; }
  .layout {
    display: flex; flex-direction: column; gap: 10px;
    padding: 10px var(--gutter) calc(var(--composer-h) + env(safe-area-inset-bottom));
  }
  .col-core { flex: none; gap: 0; }
  .core-wrap { flex: none; height: 132px; min-height: 0; }
  .core-label { top: 8px; left: 10px; right: auto; bottom: auto; align-items: flex-start; padding: 0; }
  .core-state { font-size: 10px; letter-spacing: 0.22em; }
  .core-sub { display: none; }
  body:not(.tab-conv) .core-wrap { height: 84px; }
  body:not(.tab-conv) .core-label { display: none; }
  .col-conv, .col-panels { flex: 1 1 auto; min-height: 0; }
  .composer {
    position: fixed; z-index: 5; left: 0; right: 0; bottom: 0;
    padding: 10px var(--gutter) calc(10px + env(safe-area-inset-bottom));
    background: linear-gradient(180deg, rgba(5, 8, 15, 0), rgba(5, 8, 15, 0.94) 22%);
    gap: 8px;
  }
  .mic-row { gap: 22px; order: 2; }
  .text-form { order: 1; }
  .mic { width: 72px; height: 72px; font-size: 30px; }
  .btn-side { width: 58px; padding: 6px 0; }
  .hint { display: none; }
  .msg { max-width: 96%; }
  .txt { font-size: 16px; }
  .tool-ms { display: none; }
  .toasts { right: 12px; left: 12px; width: auto; }
  .modal { padding: 16px 14px 14px; }
  .modal-confirm .modal-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .modal-confirm .modal-actions .btn { min-width: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
