:root {
  --bg: #f4f6f8; --card: #ffffff; --text: #16202a; --muted: #5b6b7b;
  --primary: #1b5fb4; --primary-text: #fff; --danger: #b3261e; --ok: #1b7f3b;
  --warn-bg: #fff4d6; --warn-border: #e0a800; --border: #d5dbe2;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
header { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 20px; background: #fff; border-bottom: 1px solid var(--border); }
h1 { font-size: 22px; margin: 0; }
h1 .sub { font-weight: 400; color: var(--muted); font-size: 15px; margin-left: 6px; }
h2 { font-size: 20px; margin: 0 0 12px; }
h3 { font-size: 16px; margin: 0 0 8px; }
main { padding: 20px; max-width: 1400px; margin: 0 auto; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 16px; margin-bottom: 16px; }
label { display: block; font-weight: 600; margin: 12px 0 4px; }
input { width: 100%; font-size: 16px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; }
input:focus, button:focus-visible, .stage:focus-visible { outline: 3px solid #7fb3ff; outline-offset: 2px; }
button { font-size: 15px; padding: 10px 14px; border-radius: 8px; border: 1px solid var(--border); background: #fff; cursor: pointer; }
button:hover { background: #eef2f6; }
button.primary { background: var(--primary); color: var(--primary-text); border-color: var(--primary); font-size: 17px; padding: 12px 18px; margin-top: 16px; }
button.danger { background: var(--danger); color: #fff; border-color: var(--danger); width: 100%; margin-top: 8px; font-size: 16px; }
button.link { background: none; border: none; color: var(--primary); text-decoration: underline; padding: 0; font-size: inherit; }
.msg { min-height: 1.4em; color: var(--muted); }
.msg.error { color: var(--danger); font-weight: 600; }
.pill { padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 14px; white-space: nowrap; }
.pill.off { background: #e7ebef; color: var(--muted); }
.pill.wait { background: #fff4d6; color: #7a5a00; }
.pill.on { background: #dff5e5; color: var(--ok); }
.session { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 16px; }
@media (max-width: 900px) { .session { grid-template-columns: 1fr; } }
.stage { position: relative; background: #111; border-radius: 12px; overflow: hidden; height: 78vh; min-height: 420px; touch-action: none; user-select: none; cursor: crosshair; }
.stage video { width: 100%; height: 100%; object-fit: contain; display: block; pointer-events: none; }
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 20px; background: rgba(0,0,0,.55); pointer-events: none; }
.navbar { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.navbar button { flex: 1 1 auto; min-width: 120px; padding: 12px; font-size: 16px; }
.navbar.apps button { background: #eaf1fb; border-color: #b9cdf0; font-weight: 600; }
.row { display: flex; gap: 8px; margin-bottom: 8px; }
.row input { flex: 1; }
.col { display: flex; flex-direction: column; gap: 8px; margin-bottom: 8px; }
.hint { color: var(--muted); font-size: 14px; margin: 0 0 8px; }
.warn { background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 10px; padding: 10px 12px; margin-bottom: 10px; }
.info { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 8px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; font-weight: 600; }
.log-card pre { max-height: 180px; overflow: auto; background: #0f172a; color: #c8d3e0; padding: 10px; border-radius: 8px; font-size: 12px; margin: 0; white-space: pre-wrap; }

/* ---- schermo in testo ---- */
.row.between { justify-content: space-between; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.chk { display: flex; align-items: center; gap: 6px; font-size: 14px; white-space: nowrap; }
.treecard { margin-top: 12px; }
.treecard h3 .hint { font-weight: 400; margin-left: 6px; }
.tree { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.tree li { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-bottom: 1px solid #eef1f4; font-size: 15px; }
.tree li:last-child { border-bottom: none; }
.tree li .lbl { flex: 1; text-align: left; background: none; border: none; padding: 6px 4px; font-size: 15px; cursor: pointer; border-radius: 6px; }
.tree li .lbl:hover { background: #eef2f6; }
.tree li.r-text .lbl { color: var(--muted); cursor: default; }
.tree li.r-text .lbl:hover { background: none; }
.tree li.r-button .lbl, .tree li.r-item .lbl { color: var(--primary); font-weight: 600; }
.tree li.r-check .lbl::before { content: "☐ "; }
.tree li.r-check.on .lbl::before { content: "☑ "; }
.tree li.r-edit { background: #fffbe6; }
.tree li .mini { font-size: 12px; padding: 4px 8px; }
.tree li input { max-width: 220px; font-size: 14px; padding: 6px 8px; }
.tree .badge { font-size: 11px; color: #fff; background: var(--muted); border-radius: 4px; padding: 1px 5px; }
.locked { background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
/* ---- rubrica ---- */
.contacts { list-style: none; margin: 0; padding: 0; max-height: 260px; overflow: auto; }
.contacts li { display: flex; align-items: center; gap: 8px; padding: 6px 4px; border-bottom: 1px solid #eef1f4; font-size: 14px; }
.contacts li .who { flex: 1; }
.contacts li .who b { display: block; }
.contacts li button { padding: 6px 8px; font-size: 13px; }

/* ---- schede dati ---- */
.navbar.apps button.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.tabpane { margin-top: 12px; }
.threads { list-style: none; margin: 0; padding: 0; max-height: 55vh; overflow: auto; border: 1px solid var(--border); border-radius: 8px; }
.threads li { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-bottom: 1px solid #eef1f4; cursor: pointer; }
.threads li:hover { background: #eef2f6; }
.threads li:last-child { border-bottom: none; }
.threads li .who { flex: 1; min-width: 0; }
.threads li .who b { display: block; }
.threads li .who span { color: var(--muted); font-size: 14px; display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.threads li .when { color: var(--muted); font-size: 12px; white-space: nowrap; }
.threads li.unread .who b::before { content: "● "; color: var(--primary); }
.threads li .type { width: 22px; text-align: center; }
.messages { display: flex; flex-direction: column; gap: 6px; max-height: 50vh; overflow: auto; padding: 10px; background: #f4f6f8; border-radius: 8px; margin: 8px 0; }
.bubble { max-width: 78%; padding: 8px 12px; border-radius: 14px; font-size: 15px; white-space: pre-wrap; word-wrap: break-word; }
.bubble.in { align-self: flex-start; background: #fff; border: 1px solid var(--border); }
.bubble.out { align-self: flex-end; background: var(--primary); color: #fff; }
.bubble .when { display: block; font-size: 11px; opacity: .7; margin-top: 3px; }

/* ---- galleria ---- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; max-height: 60vh; overflow: auto; padding: 4px; }
.grid figure { margin: 0; cursor: pointer; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.grid figure:hover { border-color: var(--primary); }
.grid figure .ph { width: 100%; aspect-ratio: 1; background: #e7ebef; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 12px; overflow: hidden; }
.grid figure img { width: 100%; height: 100%; object-fit: cover; display: block; }
.grid figcaption { font-size: 12px; padding: 4px 6px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photoview img { max-width: 100%; max-height: 60vh; display: block; margin: 8px auto; border-radius: 8px; }
.filebtn { display: inline-block; padding: 10px 14px; border: 1px solid var(--border); border-radius: 8px; background: #fff; cursor: pointer; font-size: 15px; }
.filebtn:hover { background: #eef2f6; }
.btnlink { display: inline-block; padding: 10px 14px; border: 1px solid var(--ok); border-radius: 8px; background: var(--ok); color: #fff; text-decoration: none; font-size: 15px; }

/* ---- voce e guida ---- */
.navbar.voice input { flex: 2 1 220px; }
.navbar.voice button.on { background: var(--ok); color: #fff; border-color: var(--ok); }
.filebtn.small { padding: 6px 10px; font-size: 14px; }
select { font-size: 14px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; }
.threads li .body { color: var(--text); font-size: 14px; white-space: pre-wrap; }
.threads li.notif { flex-wrap: wrap; cursor: default; }
.threads li.notif .who { flex: 1 1 60%; }
.threads li.notif .replybox { flex-basis: 100%; display: flex; gap: 6px; margin-top: 6px; }
.threads li.notif .replybox input { flex: 1; }

/* ---- permessi ---- */
button.primary.small { font-size: 14px; padding: 8px 12px; margin: 0; }
.setup { list-style: none; margin: 8px 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 4px 12px; font-size: 14px; }
.setup li.ok::before { content: "✅ "; }
.setup li.no::before { content: "❌ "; }
#xrayBtn.on { background: var(--ok); color: #fff; border-color: var(--ok); }

/* ---- strisce di pulsanti sopra il video ---- */
.strip { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-bottom: 6px; }
.strip button { flex: 0 0 auto; padding: 6px 10px; font-size: 14px; min-width: 0; height: 34px; }
.strip button.tab.active, .strip button.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.strip input { width: auto; padding: 6px 8px; font-size: 14px; height: 34px; }
.strip .sep { width: 1px; height: 26px; background: var(--border); margin: 0 4px; }
.menu { position: relative; }
.menu-list { position: absolute; top: 38px; left: 0; z-index: 20; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 6px; display: flex; flex-direction: column; gap: 4px; min-width: 240px; box-shadow: 0 4px 16px rgba(0,0,0,.12); }
.menu-list button { text-align: left; }
details.card summary { cursor: pointer; font-weight: 600; }
.stage { height: 72vh; }

/* strisce a tutta larghezza, sopra le due colonne */
.strips { grid-column: 1 / -1; }
.strips .strip { gap: 6px 8px; }

/* ---- schermo virtuale (replica cliccabile) ---- */
.wire { position: absolute; pointer-events: none; }
.wire .el { position: absolute; box-sizing: border-box; overflow: hidden; font-size: 11px; line-height: 1.1; padding: 1px 3px; pointer-events: auto; cursor: pointer; border-radius: 3px; white-space: nowrap; text-overflow: ellipsis; }
.wire .el.text { color: #e8eef5; border: 1px dashed rgba(255,255,255,.25); cursor: default; }
.wire .el.item, .wire .el.button { color: #fff; background: rgba(27,95,180,.45); border: 1px solid #8ab4f8; }
.wire .el.edit { color: #16202A; background: rgba(255,244,214,.9); border: 1px solid #e0a800; }
.wire .el.check { color: #fff; background: rgba(27,127,59,.45); border: 1px solid #7fd19a; }
.wire .el.ime { background: rgba(255,255,255,.18); border: 1px solid rgba(255,255,255,.6); color: #fff; text-align: center; font-weight: 700; font-size: 13px; }
.wire .el:hover { outline: 2px solid #fff; }
.stage.wireon { background: #0f172a; }

.wire .el.pattern { background: rgba(255,255,255,.06); border: 1px dashed rgba(255,255,255,.5); cursor: crosshair; }
.wire .el.pattern .dot { position: absolute; width: 22px; height: 22px; margin: -11px 0 0 -11px; border-radius: 50%; background: #fff; opacity: .85; pointer-events: none; box-shadow: 0 0 0 4px rgba(255,255,255,.15); }
.wire .el.pattern .dot.on { background: #ff3b30; opacity: 1; }
.wire .el.pattern .phint { position: absolute; left: 0; right: 0; bottom: 4px; text-align: center; font-size: 11px; color: #cfd8e3; pointer-events: none; }
.wire .el.text { border: none; color: #c8d3e0; }
.wire .el.ime { border-radius: 5px; }

.wire .el.image { color: #ffd27f; border: 1px dashed rgba(255,210,127,.8); background: rgba(255,210,127,.08); cursor: default; }
#openInHb { background: var(--ok); color: #fff; border-color: var(--ok); }

/* ---- schermo virtuale: stati e leggibilità ---- */
.wire .el { display: flex; align-items: center; justify-content: center; text-align: center; line-height: 1.15; }
.wire .el.text { justify-content: flex-start; text-align: left; }
.wire .el.wrap { white-space: normal; overflow: hidden; }
.wire .el.dis { opacity: .45; filter: grayscale(1); cursor: not-allowed; }
.wire .el.sel { border-width: 2px; border-color: #fff; box-shadow: 0 0 0 2px rgba(255,255,255,.35) inset; }
.wire .el.foc { outline: 2px solid #ffd27f; outline-offset: 1px; animation: focblink 1s infinite; }
.wire .el.checked::before { content: "☑ "; }
.wire .el.check:not(.checked)::before { content: "☐ "; }
.wire .el.under { opacity: .28; }
.wire .backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.45); pointer-events: none; }
@keyframes focblink { 50% { outline-color: transparent; } }

