/* =====================================================================
   app.css — LiveChat.
   Nessun colore, font o dimensione in chiaro: tutto viene da
   theme-tokens.css, perche' il menu Aspetto dell'amministratore possa
   sovrascriverlo a runtime.
   ===================================================================== */

@import url("/theme-tokens.css");

/* ---- Ponte verso Bootstrap: si rimappano le sue variabili sui nostri
   token, cosi' i componenti Bootstrap (modali, dropdown, tabelle, form)
   seguono il tema senza doverli riscrivere uno per uno. ---- */
:root {
  --bs-body-bg: var(--c-bg);
  --bs-body-color: var(--c-ink);
  --bs-body-font-family: var(--font-ui);
  --bs-body-font-size: var(--font-size-base);
  --bs-body-line-height: var(--line-height-base);
  --bs-border-color: var(--c-line);
  --bs-primary: var(--brand);
  --bs-primary-rgb: var(--brand-rgb);
  --bs-secondary-color: var(--c-muted);
  --bs-emphasis-color: var(--c-ink);
  --bs-link-color: var(--brand-light);
  --bs-link-hover-color: var(--brand);
  --bs-code-color: var(--brand-lighter);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: linear-gradient(180deg, var(--c-bg-grad-1), var(--c-bg-grad-2));
  background-attachment: fixed;
  color: var(--c-ink);
  font-family: var(--font-ui);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  -webkit-font-smoothing: antialiased;
  /* Sicurezza per i notch: la PWA gira a tutto schermo su telefono. */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

.text-muted { color: var(--c-muted) !important; }
.btn-primary {
  --bs-btn-bg: var(--brand);
  --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-strong);
  --bs-btn-hover-border-color: var(--brand-strong);
  --bs-btn-color: var(--on-brand);
  --bs-btn-hover-color: var(--on-brand);
}

.card, .list-group-item, .modal-content, .offcanvas, .dropdown-menu, .table {
  background-color: var(--c-surface);
  color: var(--c-ink);
  border-color: var(--c-line);
}
.card { border: 1px solid var(--c-line); border-radius: var(--radius-md); box-shadow: var(--shadow-soft); margin-bottom: 18px; }
.dropdown-menu { --bs-dropdown-bg: var(--c-surface); --bs-dropdown-link-color: var(--c-ink); --bs-dropdown-link-hover-bg: var(--veil-06); --bs-dropdown-link-hover-color: var(--c-ink); --bs-dropdown-border-color: var(--c-line); }
.list-group-item-action:hover { background: var(--veil-06); color: var(--c-ink); }
.table { --bs-table-bg: transparent; --bs-table-color: var(--c-ink); --bs-table-hover-bg: var(--veil-04); --bs-table-hover-color: var(--c-ink); --bs-table-border-color: var(--c-line); }
.table thead th { background: rgb(var(--table-head-rgb)); color: var(--c-ink-soft); font-size: var(--font-size-sm); }
.modal-content { border: 1px solid var(--c-line); border-radius: var(--radius-md); }
.modal-backdrop.show { background: rgb(var(--scrim-modal-rgb)); opacity: .75; }
.form-control, .form-select {
  background-color: var(--input-bg);
  border-color: var(--c-line);
  color: var(--c-ink);
  font-size: var(--font-size-md);
}
.form-control:focus, .form-select:focus {
  background-color: var(--input-bg);
  color: var(--c-ink);
  border-color: var(--brand);
  box-shadow: 0 0 0 .2rem var(--brand-soft);
}
.form-control::placeholder { color: var(--placeholder); }
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.bg-light { background-color: var(--c-surface-2) !important; }
.bg-black, .bg-dark { background-color: var(--c-bg-2) !important; }

/* =====================================================================
   ACCESSO
   ================================================================== */
.gate {
  position: fixed; inset: 0; z-index: 3000;
  display: grid; place-items: center; padding: 24px;
  background: linear-gradient(160deg, var(--c-bg-grad-1), var(--c-bg-grad-2));
  overflow-y: auto;
}
.gate-card {
  width: 100%; max-width: 400px;
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-pop);
}
.gate-brand {
  display: flex; align-items: center; gap: 10px;
  font-size: var(--font-size-lg); font-weight: var(--font-weight-bold);
  color: var(--brand-light); margin-bottom: 18px;
}
.gate-brand img { height: 34px; width: auto; }
.gate-card h1 { font-size: var(--font-size-xl); font-weight: var(--font-weight-bold); margin: 0 0 4px; }
.gate-sub { color: var(--c-muted); font-size: var(--font-size-sm); margin: 0 0 20px; }
.gate-card label { display: block; font-size: var(--font-size-sm); color: var(--c-muted); margin: 13px 0 5px; }
.gate-card .opt { opacity: .65; }
.gate-card input {
  width: 100%; padding: 10px 12px; border-radius: var(--radius-sm);
  border: 1px solid var(--c-line); background: var(--input-bg);
  color: var(--c-ink); font-size: var(--font-size-md); font-family: var(--font-ui);
}
.gate-card input:focus { outline: 2px solid var(--brand); outline-offset: -1px; }
.gate-hint { font-size: var(--font-size-xs); color: var(--c-muted); margin: 6px 0 0; }
.gate-msg { margin-top: 16px; padding: 10px 12px; border-radius: var(--radius-sm); font-size: var(--font-size-sm); display: none; white-space: pre-wrap; }
.gate-msg.error { display: block; background: var(--toast-err-bg); color: var(--toast-err-ink); border: 1px solid var(--alert); }
.gate-msg.ok { display: block; background: var(--toast-bg); color: var(--toast-ink); border: 1px solid var(--ok); }
.gate-switch { margin-top: 18px; text-align: center; font-size: var(--font-size-sm); color: var(--c-muted); }
.gate-switch a { color: var(--brand-light); text-decoration: none; }

/* =====================================================================
   GUSCIO APPLICAZIONE
   ================================================================== */
#app { display: block; min-height: 100vh; }

#topbar {
  padding: 8px 14px;
  background: rgb(var(--topbar-rgb));
  border-bottom: 1px solid var(--c-line);
  position: sticky; top: 0; z-index: 1030;
  gap: 8px;
}
.brand {
  display: inline-flex; align-items: center; gap: 8px;
  font-weight: var(--font-weight-bold); color: var(--brand-light);
  font-size: var(--font-size-lg);
}
.brand img { height: 26px; width: auto; }

.pill {
  background: var(--c-surface-2);
  border: 1px solid var(--c-line);
  color: var(--c-ink);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  display: flex; align-items: center; gap: 8px;
}
.pill > span { font-weight: var(--font-weight-medium); font-size: var(--font-size-sm); color: var(--c-muted); }
.pill select, .pill input {
  background: transparent; border: none; color: var(--c-ink);
  font-weight: var(--font-weight-medium); font-family: var(--font-ui);
  font-size: var(--font-size-md); max-width: 170px;
}
.pill select:focus, .pill input:focus { outline: none; }
.pill select option { background: var(--input-bg); color: var(--c-ink); }

.btn-toggle {
  border: 1px solid var(--c-line);
  background: var(--c-surface-2);
  color: var(--c-ink);
  border-radius: var(--radius-sm);
}
.btn-toggle:hover { background: var(--veil-08); color: var(--c-ink); }
.btn-on { background: var(--ok) !important; color: var(--on-brand-ink) !important; border: none; }
.btn-off { background: var(--alert) !important; color: var(--on-brand) !important; border: none; }
.btn-blue-off { background: var(--brand-2) !important; color: var(--on-brand) !important; border: none; }

/* Navigazione laterale (desktop) */
#sidenav {
  position: fixed; left: 0; top: 0; bottom: 0; width: 86px;
  padding-top: 64px;
  flex-direction: column; gap: 4px; align-items: stretch;
  background: linear-gradient(180deg, var(--sidebar-grad-1), var(--sidebar-grad-2));
  border-right: 1px solid var(--c-line);
  z-index: 1020;
}
#sidenav .nav-item {
  background: none; border: 0; color: var(--c-muted);
  padding: 12px 4px; display: flex; flex-direction: column; align-items: center; gap: 4px;
  font-size: var(--font-size-xs); font-weight: var(--font-weight-medium);
  border-left: 3px solid transparent;
}
#sidenav .nav-item i { font-size: var(--font-size-xl); }
#sidenav .nav-item:hover { color: var(--c-ink); background: var(--veil-04); }
#sidenav .nav-item.active { color: var(--brand-light); border-left-color: var(--brand); background: var(--brand-soft-2); }

.offcanvas { background: var(--c-surface); color: var(--c-ink); }
.offcanvas .btn-close { filter: invert(1) grayscale(1); }
#drawer-nav .list-group-item { background: transparent; color: var(--c-ink); border-color: var(--c-line); }
#drawer-nav .list-group-item.active { background: var(--brand-soft); color: var(--brand-light); }

/* Le viste occupano lo spazio a destra della barra */
.view { display: none; }
.view.active { display: block; }
@media (min-width: 992px) { .view { margin-left: 86px; } }

/* =====================================================================
   VISTA STANZA — spazio di lavoro a finestre

   Ogni funzione è un riquadro che l'utente apre, chiude, sposta e
   ridimensiona dove preferisce. La posizione la decide il JS scrivendo le
   variabili --x/--y/--w/--h sul riquadro, così il CSS resta dichiarativo e
   una sola transizione basta a rendere fluido lo spostamento.
   ================================================================== */
.ws-bar {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: var(--c-bg-2);
  border-bottom: 1px solid var(--c-line);
  position: sticky; top: 56px; z-index: 15;
}
.ws-dock { display: flex; gap: 5px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.ws-dock::-webkit-scrollbar { display: none; }
.ws-chip {
  background: var(--c-surface-2); border: 1px solid var(--c-line);
  color: var(--c-muted); border-radius: 999px;
  padding: 3px 12px; font-size: var(--font-size-xs);
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.ws-chip:hover { color: var(--c-ink); border-color: var(--c-line-strong); }
.ws-chip.open { background: var(--brand-soft); border-color: rgba(var(--brand-rgb), .5); color: var(--brand-light); }
.ws-bar-actions { display: flex; gap: 2px; }

#workspace {
  position: relative;
  min-height: calc(100vh - 120px);
  padding: 12px;
  overflow: auto;
}

.panel {
  position: absolute;
  left: var(--x); top: var(--y);
  width: var(--w); height: var(--h);
  display: flex; flex-direction: column;
  background: var(--c-surface);
  border: 1px solid var(--c-line);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-soft);
  overflow: hidden;
  transition: box-shadow .15s;
}
.panel[hidden] { display: none; }
.panel.focused { border-color: var(--c-line-strong); box-shadow: var(--shadow-pop); }
/* Durante il trascinamento niente transizioni: devono seguire il dito. */
.panel.moving { transition: none; user-select: none; }
.panel.maximized {
  left: 0 !important; top: 0 !important;
  width: 100% !important; height: 100% !important;
  border-radius: 0;
}

.panel-head {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 8px 7px 12px;
  background: var(--c-surface-2);
  border-bottom: 1px solid var(--c-line);
  cursor: move; touch-action: none;
  flex: 0 0 auto;
}
.panel-icon { color: var(--brand-light); }
.panel-title {
  font-size: var(--font-size-sm); font-weight: var(--font-weight-bold);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.panel-actions { margin-left: auto; display: flex; gap: 1px; }
.panel-actions .icon-btn { width: 28px; height: 28px; }

.panel-body { flex: 1; min-height: 0; overflow: auto; padding: 12px; position: relative; }

.panel-resize {
  position: absolute; right: 0; bottom: 0;
  width: 18px; height: 18px; cursor: nwse-resize; touch-action: none;
  background:
    linear-gradient(135deg, transparent 50%, var(--c-line-strong) 50%, var(--c-line-strong) 62%,
      transparent 62%, transparent 74%, var(--c-line-strong) 74%, var(--c-line-strong) 86%, transparent 86%);
}

/* Su telefono le finestre mobili non hanno senso: si impilano a tutta
   larghezza, nell'ordine in cui sono state aperte. */
@media (max-width: 767px) {
  #workspace {
    display: flex; flex-direction: column; gap: 10px;
    padding: 10px; min-height: auto;
  }
  .panel {
    position: static !important;
    width: auto !important; height: auto !important;
    max-height: 78vh;
  }
  .panel-head { cursor: default; }
  .panel-resize { display: none; }
  .panel.maximized { max-height: none; }
}

#video-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  grid-auto-rows: minmax(150px, auto);
  gap: 12px;
}
@media (max-width: 575px) { #video-grid { grid-template-columns: 1fr 1fr; gap: 8px; } }

.tile {
  position: relative; background: var(--tile-bg);
  border-radius: var(--radius-sm); overflow: hidden;
  aspect-ratio: 16/9; cursor: pointer;
  border: 2px solid transparent;
  transition: border-color .18s;
}
.tile:hover { border-color: var(--c-line-strong); }
.tile.selected { border-color: var(--tile-selected); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile .badge {
  position: absolute; left: 6px; bottom: 6px;
  background: rgba(var(--shadow-rgb), .72);
  backdrop-filter: blur(4px);
  padding: 3px 7px; border-radius: 4px;
  font-size: var(--font-size-xs); color: var(--on-brand);
  max-width: 80%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tile .controls {
  position: absolute; top: 0; right: 0; padding: 5px;
  display: flex; gap: 4px;
  background: rgba(var(--shadow-rgb), .4);
  backdrop-filter: blur(4px);
  border-bottom-left-radius: var(--radius-sm);
}
.tile .controls .btn { padding: 2px 7px; font-size: var(--font-size-xs); }

/* Riquadro dell'analisi: fluttuante e trascinabile */
.stream-box {
  position: absolute; right: 18px; top: 52px; width: 240px;
  z-index: 900;
  box-shadow: var(--shadow-pop);
  border-radius: var(--radius-sm); overflow: hidden;
  border: 2px solid var(--c-line-strong);
  background: var(--video-bg);
  user-select: none; touch-action: none;
}
.stream-box.dragging { opacity: .92; }
.stream-box-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 1px 6px; cursor: move;
  background: var(--c-surface-2); color: var(--c-muted);
  font-size: var(--font-size-xs);
}
.stream-box-btn { background: none; border: 0; color: var(--c-muted); padding: 1px 5px; }
.stream-box-btn:hover { color: var(--c-ink); }
.stream-box img { width: 100%; display: block; pointer-events: none; }
@media (max-width: 575px) { .stream-box { width: 150px; right: 10px; top: 46px; } }

/* Lavagna */
/* Il contenitore della lavagna riempie il riquadro: prima era bloccato a 16/9
   e lasciava una fascia vuota sotto ogni volta che il riquadro era piu' alto. */
[data-panel="whiteboard"] .panel-body { display: flex; flex-direction: column; overflow: hidden; }
#whiteboard-canvas-container { position: relative; flex: 1; min-height: 260px; width: 100%; }
#wb-bg-layer {
  position: absolute; top: 50px; left: 0;
  width: 100%; height: calc(100% - 100px);
  object-fit: contain; display: none; opacity: .8;
  z-index: 0; pointer-events: none;
}
#whiteboard-root {
  position: relative; width: 100%; height: 100%; z-index: 1;
  border-radius: var(--radius-sm); border: 1px solid var(--c-line);
  background: var(--wb-canvas);
}
.toolbar .btn { font-size: var(--font-size-sm); }

/* Documenti */
#pdf-scroll {
  width: 100%; height: 62vh; min-height: 320px; overflow: auto;
  background: var(--c-bg); border-radius: var(--radius-sm);
  border: 1px solid var(--c-line);
}
#pdf-canvas { display: block; margin: 0 auto; background: var(--paper-bg); box-shadow: var(--shadow-soft); }

/* Regia */
#vlm-output {
  height: 180px; overflow-y: auto;
  background: var(--vlm-bg); color: var(--vlm-ink);
  font-family: var(--font-mono); font-size: var(--font-size-xs);
}
#vlm-output p { margin: 0 0 4px; }
#director-stream-container { min-height: 140px; position: relative; }
#director-stream-container img { width: 100%; height: auto; display: block; }
#medical-output { font-size: var(--font-size-sm); }
#medical-output table { width: 100%; }
#medical-output td { padding: 1px 6px 1px 0; }

/* =====================================================================
   VISTA VIEWER
   ================================================================== */
.viewer-layout { display: grid; grid-template-columns: 260px 1fr; height: calc(100vh - 56px); }
@media (max-width: 767px) { .viewer-layout { grid-template-columns: 1fr; height: auto; } }
.viewer-side { background: var(--c-surface); border-right: 1px solid var(--c-line); padding: 18px; overflow-y: auto; }
.viewer-main { background: var(--video-bg); position: relative; display: flex; align-items: center; justify-content: center; min-height: 50vh; }
.viewer-main video { width: 100%; height: 100%; max-height: calc(100vh - 56px); object-fit: contain; }
.status-badge {
  position: absolute; top: 14px; right: 14px; z-index: 5;
  background: rgba(var(--shadow-rgb), .75); color: var(--on-brand);
  padding: 5px 11px; border-radius: 999px; font-size: var(--font-size-xs);
  display: flex; align-items: center; gap: 6px;
}

/* =====================================================================
   VISTA GESTIONE
   ================================================================== */
.manage-layout { display: grid; grid-template-columns: 250px 1fr; min-height: calc(100vh - 56px); }
@media (max-width: 991px) { .manage-layout { grid-template-columns: 1fr; } }
.manage-side { background: var(--c-surface); border-right: 1px solid var(--c-line); padding: 16px; }
.manage-main { padding: 18px; }
#room-list .list-group-item { background: transparent; color: var(--c-ink); border-color: var(--c-line); text-align: left; }
#room-list .list-group-item.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-light); }

/* =====================================================================
   PANNELLO LATERALE A SCHEDE
   Prima i pannelli si escludevano a vicenda e aprirne uno chiudeva l'altro;
   con le schede si passa da lavagna a documenti a chat senza perdere nulla.
   ================================================================== */
.side-head {
  display: flex; align-items: center; gap: 8px;
  margin: -4px -4px 10px; padding-bottom: 8px;
  border-bottom: 1px solid var(--c-line);
}
.side-tabs { display: flex; gap: 2px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.side-tabs::-webkit-scrollbar { display: none; }
.side-tab {
  position: relative;
  background: none; border: 0; border-radius: var(--radius-sm);
  color: var(--c-muted); padding: 6px 11px;
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  font-size: var(--font-size-sm); font-weight: var(--font-weight-medium);
}
.side-tab:hover { background: var(--veil-06); color: var(--c-ink); }
.side-tab.active { background: var(--brand-soft); color: var(--brand-light); }
.side-tab i { font-size: var(--font-size-lg); }
@media (max-width: 575px) { .side-tab span { display: none; } }

.side-head-actions { display: flex; gap: 2px; }
.icon-btn {
  background: none; border: 0; border-radius: var(--radius-sm);
  color: var(--c-muted); width: 34px; height: 34px;
  display: inline-flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: var(--veil-08); color: var(--c-ink); }

.unread-dot {
  position: absolute; top: -5px; right: -5px;
  font-size: 10px; padding: 2px 5px; min-width: 17px;
}
.side-tab .unread-dot { position: static; margin-left: 2px; }

/* =====================================================================
   MESSAGGISTICA
   ================================================================== */
#chat-wrap { display: flex; flex-direction: column; height: min(62vh, 560px); }
.chat-log {
  flex: 1; overflow-y: auto; overscroll-behavior: contain;
  display: flex; flex-direction: column; gap: 8px;
  padding: 4px 2px 10px;
}
.chat-empty { text-align: center; padding: 28px 12px; font-size: var(--font-size-sm); }

.chat-day {
  align-self: center; margin: 6px 0;
  font-size: var(--font-size-xs); color: var(--c-muted);
  background: var(--c-surface-2); border: 1px solid var(--c-line);
  padding: 2px 10px; border-radius: 999px;
}

.chat-msg { max-width: 82%; align-self: flex-start; }
.chat-msg.mine { align-self: flex-end; }
.chat-msg .who {
  font-size: var(--font-size-xs); color: var(--c-muted);
  margin: 0 0 2px 10px; font-weight: var(--font-weight-medium);
}
.chat-msg.mine .who { display: none; }
.chat-bubble {
  background: var(--c-surface-2);
  border: 1px solid var(--c-line);
  border-radius: 14px 14px 14px 4px;
  padding: 7px 12px;
  white-space: pre-wrap; word-break: break-word;
  font-size: var(--font-size-md);
  position: relative;
}
.chat-msg.mine .chat-bubble {
  background: var(--brand-soft);
  border-color: rgba(var(--brand-rgb), .45);
  border-radius: 14px 14px 4px 14px;
}
.chat-bubble.deleted { font-style: italic; color: var(--c-muted); }
.chat-bubble.pending { opacity: .6; }
.chat-meta {
  font-size: var(--font-size-xs); color: var(--c-muted);
  margin-top: 3px; display: flex; gap: 8px; align-items: center;
}
.chat-msg.mine .chat-meta { justify-content: flex-end; }
.chat-del {
  background: none; border: 0; color: var(--c-muted); padding: 0 2px;
  opacity: 0; transition: opacity .15s;
}
.chat-msg:hover .chat-del { opacity: 1; }
.chat-del:hover { color: var(--alert); }

.chat-new-divider {
  align-self: stretch; text-align: center;
  border-top: 1px solid var(--alert); margin: 8px 0 2px;
  font-size: var(--font-size-xs); color: var(--alert-ink);
}

.chat-composer { display: flex; gap: 8px; align-items: flex-end; padding-top: 8px; border-top: 1px solid var(--c-line); }
.chat-composer textarea {
  flex: 1; resize: none; max-height: 140px;
  background: var(--input-bg); color: var(--c-ink);
  border: 1px solid var(--c-line); border-radius: var(--radius-sm);
  padding: 9px 12px; font-family: var(--font-ui); font-size: var(--font-size-md);
  line-height: 1.4;
}
.chat-composer textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 .2rem var(--brand-soft); }
.chat-composer .btn { height: 40px; padding: 0 16px; }
.chat-hint { font-size: var(--font-size-xs); margin-top: 5px; }
@media (max-width: 767px) { .chat-hint { display: none; } }

/* =====================================================================
   EDITOR DEL TEMA
   ================================================================== */
.theme-group { margin-bottom: 18px; }
.theme-group h6 { color: var(--c-ink-soft); font-size: var(--font-size-sm); text-transform: uppercase; letter-spacing: .4px; }
.theme-row { display: flex; align-items: center; gap: 10px; padding: 5px 0; }
.theme-row label { flex: 1; font-size: var(--font-size-sm); margin: 0; }
.theme-row code { font-size: var(--font-size-xs); color: var(--c-muted); }
.theme-row input[type="color"] { width: 42px; height: 30px; padding: 2px; border-radius: 6px; border: 1px solid var(--c-line); background: var(--input-bg); }
.theme-row input[type="text"] { width: 190px; }
.theme-row .reset { background: none; border: 0; color: var(--c-muted); }
.theme-row .reset:hover { color: var(--alert); }

/* =====================================================================
   TOAST
   ================================================================== */
.toast-stack {
  position: fixed; z-index: 4000;
  left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom));
  display: flex; flex-direction: column; gap: 8px;
  width: min(92vw, 460px); pointer-events: none;
}
.toast-item {
  background: var(--toast-bg); color: var(--toast-ink);
  border: 1px solid var(--c-line-strong);
  border-radius: var(--radius-sm);
  padding: 10px 14px; font-size: var(--font-size-sm);
  box-shadow: var(--shadow-pop);
  animation: toast-in .18s ease-out;
}
.toast-item.error { background: var(--toast-err-bg); color: var(--toast-err-ink); border-color: var(--alert); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* =====================================================================
   ADATTAMENTO A TELEFONO
   I comandi della stanza scendono in una barra in basso: su un telefono
   tenuto in mano il pollice arriva li', non in cima allo schermo. E' la
   disposizione che usano tutte le app di videochiamata.
   ================================================================== */
@media (max-width: 767px) {
  .lbl { display: none; }

  /* L'intestazione non deve mangiarsi mezzo schermo: una riga sola. */
  #topbar { flex-wrap: nowrap; padding: 6px 8px; gap: 6px; }
  #topbar .brand { display: none; }
  #room-controls { flex: 1; min-width: 0; flex-wrap: nowrap; }
  #room-controls .pill { flex: 1; min-width: 0; padding: 3px 8px; }
  #room-controls .pill > span { display: none; }
  #room-controls .pill select { max-width: none; width: 100%; }
  #join-btn { padding: 5px 10px; white-space: nowrap; }
  #join-btn .bi + * { display: none; }
  .ws-bar { top: 48px; padding: 5px 8px; }

  #room-actions {
    position: fixed; left: 0; right: 0; z-index: 1040;
    bottom: 0; padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
    background: rgb(var(--topbar-rgb));
    border-top: 1px solid var(--c-line);
    justify-content: center; gap: 6px !important;
    box-shadow: 0 -6px 18px rgba(var(--shadow-rgb), .35);
  }
  #room-actions .btn { min-width: 46px; height: 44px; font-size: var(--font-size-lg); }

  /* Spazio in fondo, altrimenti la barra copre l'ultimo contenuto. */
  #view-stanza { padding-bottom: 76px; }
  .toast-stack { bottom: calc(80px + env(safe-area-inset-bottom)); }

  #shell { padding: 10px; gap: 10px; }
  #main-area, #side-area { padding: 10px; }
  #chat-wrap { height: 58vh; }
}

/* Su tablet in verticale conviene comunque impilare i pannelli. */
@media (min-width: 768px) and (max-width: 991px) {
  #room-actions .btn { padding: 6px 10px; }
}

/* L'utente puo' chiedere meno movimento: va rispettato. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
