/* ---------------------------------------------------------------------------
   Chat aziendale — foglio di stile unico.

   Nessun font o risorsa esterna: tutto viene dal server, coerentemente con la
   CSP che vieta qualsiasi connessione verso l'esterno.
   --------------------------------------------------------------------------- */

:root {
  --bg: #f4f7fb;
  --bg-panel: #ffffff;
  --bg-side: #1b2433;
  --bg-rail: #121a25;
  --bg-side-hover: #2a3648;
  --bg-input: #ffffff;
  --bg-hover: #eef3f9;
  --border: #e3e9f1;
  --border-strong: #cbd5e2;
  --text: #101c2d;
  --text-soft: #5a6b81;
  --text-side: #ccd7e4;
  --text-side-soft: #8b9cb1;
  --accent: #2f6fd0;
  --accent-hover: #2459ad;
  --accent-soft: #e9f1fd;
  --danger: #c22a1f;
  --danger-soft: #fdecea;
  --success: #12813c;
  --warning: #b45309;
  /* Colore dell'autodistruzione: distinto sia dall'accento sia dal pericolo.
     Un messaggio a scadenza non è un errore, ma non è nemmeno ordinario. */
  --ephemeral: #9a5b06;
  --ephemeral-soft: #fdf3e3;
  --ephemeral-border: #eccfa0;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --rail-w: 72px;
  --drawer-w: 256px;
  /* Margini di sicurezza: tacca, angoli arrotondati, barra dei gesti. Valgono
     zero su un computer, e diventano reali su un telefono. */
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --shadow-sm: 0 1px 2px rgb(16 24 40 / 6%);
  --shadow: 0 1px 3px rgb(16 24 40 / 8%), 0 4px 12px rgb(16 24 40 / 6%);
  --shadow-lg: 0 8px 24px rgb(16 24 40 / 12%), 0 24px 60px rgb(16 24 40 / 10%);
  --mono: ui-monospace, "Cascadia Mono", "Consolas", "SF Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --ease: cubic-bezier(.2, .7, .3, 1);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c1118;
    --bg-panel: #131b25;
    --bg-side: #0a0f16;
    --bg-rail: #05080d;
    --bg-side-hover: #1c2634;
    --bg-input: #1a2330;
    --bg-hover: #1c2734;
    --border: #243040;
    --border-strong: #354557;
    --text: #e7eef6;
    --text-soft: #93a4b8;
    --text-side: #c6d2e0;
    --text-side-soft: #7d8ea3;
    --accent: #5e9cea;
    --accent-hover: #82b5f2;
    --accent-soft: #16283f;
    --danger: #f0736a;
    --danger-soft: #331d1c;
    --success: #4ade80;
    --warning: #fbbf24;
    --ephemeral: #f0b45c;
    --ephemeral-soft: #2b2113;
    --ephemeral-border: #5c4520;
    --shadow-sm: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow: 0 1px 3px rgb(0 0 0 / 40%), 0 6px 18px rgb(0 0 0 / 30%);
    --shadow-lg: 0 10px 30px rgb(0 0 0 / 50%), 0 30px 70px rgb(0 0 0 / 40%);
  }
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  /* Sul telefono la pagina non si sposta né rimbalza: è un'applicazione, non
     un documento da scorrere. */
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
}

a { color: var(--accent); }
a:hover { color: var(--accent-hover); }

/* --- controlli ----------------------------------------------------------- */

button {
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--bg-panel);
  color: var(--text);
  padding: 8px 15px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-sm);
  transition: background 140ms var(--ease), border-color 140ms var(--ease),
              box-shadow 140ms var(--ease), transform 80ms var(--ease), color 140ms var(--ease);
}
button:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--text-soft); }
/* Il pulsante cede di un pixel sotto il dito: è l'unico segnale tattile che un
   browser possa dare, e la sua assenza fa sembrare l'interfaccia inerte. */
button:active:not(:disabled) { transform: translateY(1px); box-shadow: none; }
button:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 600;
  box-shadow: 0 1px 2px rgb(16 24 40 / 10%), 0 2px 8px color-mix(in srgb, var(--accent) 26%, transparent);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-danger { color: var(--danger); border-color: var(--danger); background: transparent; box-shadow: none; }
.btn-danger:hover:not(:disabled) { background: var(--danger-soft); border-color: var(--danger); }

.btn-ghost { border-color: transparent; background: transparent; color: var(--text-soft); box-shadow: none; }
.btn-ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); border-color: transparent; }

.btn-sm { padding: 5px 11px; font-size: 12.5px; }

.icon-btn {
  border: none;
  background: transparent;
  color: inherit;
  padding: 5px 9px;
  border-radius: var(--radius-xs);
  font-size: 15px;
  line-height: 1;
  box-shadow: none;
}
.icon-btn:hover { background: var(--bg-hover); border-color: transparent; }

input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  width: 100%;
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}
input:hover:not(:focus), textarea:hover:not(:focus), select:hover:not(:focus) {
  border-color: var(--text-soft);
}
textarea { resize: vertical; }

label {
  display: block;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-soft);
  margin-bottom: 5px;
  letter-spacing: .01em;
}
.field { margin-bottom: 14px; }
.field-hint { font-size: 12px; color: var(--text-soft); margin-top: 5px; }
.field-error { font-size: 12.5px; color: var(--danger); margin-top: 5px; }

/* --- struttura ----------------------------------------------------------- */

.layout {
  display: grid;
  grid-template-columns: var(--rail-w) var(--drawer-w) 1fr;
  height: 100vh;
  /* dvh segue la barra degli indirizzi che compare e scompare sui telefoni:
     con 100vh la barra di scrittura finirebbe sotto il bordo dello schermo. */
  height: 100dvh;
  overflow: hidden;
}

/* --- barra dei gruppi ----------------------------------------------------- */

.rail {
  background: var(--bg-rail);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0;
  gap: 6px;
  overflow-y: auto;
  overflow-x: hidden;
}
.rail::-webkit-scrollbar { width: 0; }

.rail-item {
  position: relative;
  width: 46px; height: 46px;
  border: none; background: transparent;
  padding: 0;
  border-radius: 15px;
  display: grid; place-items: center;
  color: var(--text-side);
  transition: border-radius 140ms, background 140ms;
  flex-shrink: 0;
}
.rail-item:hover { border-radius: 13px; }
.rail-glyph {
  width: 46px; height: 46px;
  border-radius: inherit;
  display: grid; place-items: center;
  background: var(--bg-side-hover);
  color: #fff;
  font-weight: 700; font-size: 15px;
  letter-spacing: .02em;
  transition: border-radius 140ms;
}
.rail-item:hover .rail-glyph { border-radius: 13px; }
.rail-item.active .rail-glyph { border-radius: 13px; box-shadow: 0 0 0 2px var(--bg-rail), 0 0 0 4px var(--accent); }

/* Barretta bianca a sinistra: dove sono e dove c'è qualcosa da leggere. */
.rail-item::before {
  content: "";
  position: absolute; left: -10px; top: 50%;
  width: 4px; height: 0;
  border-radius: 0 4px 4px 0;
  background: var(--text-side);
  transform: translateY(-50%);
  transition: height 140ms;
}
.rail-item.active::before { height: 28px; }
.rail-item.has-unread::before { height: 10px; }

.rail-dm .rail-glyph { background: var(--accent); font-size: 19px; }
.rail-add {
  color: var(--success);
  border: 1px dashed currentColor;
  font-size: 20px; line-height: 1;
}
.rail-add:hover { background: var(--bg-side-hover); }
.rail-joinable .rail-glyph { background: transparent; border: 1px dashed var(--text-side-soft); color: var(--text-side-soft); }
.rail-eye { position: absolute; right: -1px; bottom: -1px; font-size: 11px; }
.rail-sep { width: 26px; height: 1px; background: rgb(255 255 255 / 12%); flex-shrink: 0; }
.rail-list { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.rail-foot { margin-top: auto; padding-top: 8px; }
.rail-admin { text-decoration: none; font-size: 19px; color: var(--text-side-soft); }
.rail-admin:hover { color: #fff; background: var(--bg-side-hover); }

.sidebar {
  background: var(--bg-side);
  color: var(--text-side);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.group-head {
  padding: 14px 12px 14px 16px;
  border-bottom: 1px solid rgb(255 255 255 / 8%);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  min-height: 56px;
}
.group-head-text { min-width: 0; flex: 1; }
.group-name {
  font-weight: 600; font-size: 14.5px; color: #fff;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.group-sub {
  font-size: 11px;
  color: var(--text-side-soft);
  display: flex; align-items: center; gap: 5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.group-head .icon-btn { color: var(--text-side); font-size: 18px; }
.group-head .icon-btn:hover { background: var(--bg-side-hover); }
.lock-badge { color: var(--success); }

.staff-banner {
  margin: 8px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  background: rgb(180 83 9 / 22%);
  border: 1px solid rgb(180 83 9 / 55%);
  color: #fcd9a5;
  font-size: 11.5px;
  line-height: 1.4;
}

.side-scroll { flex: 1; overflow-y: auto; padding: 10px 8px 16px; }

.side-section { margin-bottom: 18px; }
.side-title {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 10.5px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase;
  color: var(--text-side-soft);
  padding: 0 8px 6px;
}
.side-title button {
  border: none; background: transparent; color: var(--text-side-soft);
  padding: 1px 6px; font-size: 15px; line-height: 1; border-radius: 4px;
}
.side-title button:hover { background: var(--bg-side-hover); color: #fff; }

.side-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 7px 9px;
  border: none; background: transparent;
  color: var(--text-side);
  border-radius: var(--radius-sm);
  text-align: left;
  font-size: 13.5px;
  box-shadow: none;
  transition: background 130ms var(--ease), color 130ms var(--ease);
}
.side-item:hover { background: var(--bg-side-hover); color: #fff; border-color: transparent; }
.side-item.active {
  background: var(--accent); color: #fff; font-weight: 600;
  box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 40%, transparent);
}
.side-item:active:not(:disabled) { transform: none; }
.side-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-item-sigil { opacity: .6; font-size: 13px; width: 14px; text-align: center; flex-shrink: 0; }
.side-item.active .side-item-sigil { opacity: .9; }

.badge {
  background: var(--danger);
  color: #fff;
  border-radius: 9px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 600;
  min-width: 18px;
  text-align: center;
}

.presence-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-side-soft);
  flex-shrink: 0;
}
.presence-dot.online { background: #22c55e; }

.side-empty { padding: 6px 8px; font-size: 12.5px; color: var(--text-side-soft); }

/* --- canali vocali -------------------------------------------------------- */

.voice-count {
  font-size: 11px;
  color: var(--text-side-soft);
  background: rgb(255 255 255 / 8%);
  border-radius: 9px;
  padding: 0 6px;
}
.voice-person {
  display: flex; align-items: center; gap: 7px;
  padding: 3px 8px 3px 26px;
  font-size: 12.5px;
  color: var(--text-side-soft);
  border-radius: var(--radius-sm);
}
.voice-person:hover { background: var(--bg-side-hover); }
.voice-person:hover .voice-kick { opacity: 1; }
.voice-person-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.avatar-xs { width: 18px; height: 18px; font-size: 8px; }
/* Il cerchio verde attorno all'avatar segnala chi sta parlando in questo istante. */
.voice-person.speaking .avatar-xs { box-shadow: 0 0 0 2px #22c55e; }
.voice-person.speaking .voice-person-name { color: #fff; }
.voice-flag { font-size: 10.5px; }
.voice-kick {
  opacity: 0; border: none; background: transparent;
  color: var(--danger); padding: 0 3px; font-size: 12px; line-height: 1;
}

.voice-bar {
  border-top: 1px solid rgb(255 255 255 / 8%);
  background: rgb(21 128 61 / 16%);
  padding: 8px 10px;
  display: flex; align-items: center; gap: 8px;
  flex-shrink: 0;
}
.voice-bar-info { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.voice-bar-text { min-width: 0; }
.voice-bar-title { font-size: 12px; font-weight: 600; color: #4ade80; }
.voice-bar-sub {
  font-size: 11px; color: var(--text-side-soft);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.voice-dot { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; flex-shrink: 0; }
.voice-dot.pending { background: var(--warning); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.voice-bar-actions { display: flex; gap: 1px; }
.voice-bar-actions .icon-btn { color: var(--text-side); font-size: 14px; padding: 4px 6px; }
.voice-bar-actions .icon-btn:hover { background: var(--bg-side-hover); }
.voice-bar-actions .icon-btn.off { color: var(--danger); }
.voice-hang { color: var(--danger) !important; }

/* Chiamata in corso vista dall'area messaggi: esiste solo sul telefono, dove
   il pannello laterale (e quindi la sua barra) resta chiuso quasi sempre. */
.call-pill {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px 8px 14px;
  background: var(--bg-side);
  color: var(--text-side);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.call-pill-text {
  flex: 1; min-width: 0;
  font-size: 13px; color: #4ade80; font-weight: 600;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.call-pill .icon-btn { color: var(--text-side); font-size: 17px; }
.call-pill .icon-btn.off { color: var(--danger); }
.call-pill-hang { color: var(--danger) !important; }

.side-foot {
  border-top: 1px solid rgb(255 255 255 / 8%);
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  display: flex; align-items: center; gap: 9px;
  flex-shrink: 0;
}
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  color: #fff; font-size: 11.5px; font-weight: 600;
  flex-shrink: 0;
}
.avatar-lg { width: 38px; height: 38px; font-size: 14px; }
.side-foot-info { flex: 1; min-width: 0; }
.side-foot-name { font-size: 13px; color: #fff; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-foot-role { font-size: 11px; color: var(--text-side-soft); }

/* --- area principale ----------------------------------------------------- */

.main { display: flex; flex-direction: column; overflow: hidden; background: var(--bg-panel); }

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg-panel);
  z-index: 2;
}
.topbar-title { font-weight: 650; font-size: 15.5px; letter-spacing: -.01em; }
.topbar-topic {
  color: var(--text-soft); font-size: 12.5px;
  padding-left: 12px; margin-left: 4px;
  border-left: 1px solid var(--border);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  flex: 1; min-width: 0;
}
.topbar-actions { display: flex; gap: 4px; align-items: center; margin-left: auto; }

.motd {
  padding: 8px 18px;
  background: var(--accent-soft);
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
  flex-shrink: 0;
}

.messages { flex: 1; overflow-y: auto; padding: 14px 18px 6px; }

.day-sep {
  display: flex; align-items: center; gap: 14px;
  margin: 22px 0 14px;
  color: var(--text-soft); font-size: 11px; font-weight: 700;
  text-transform: capitalize; letter-spacing: .03em;
}
.day-sep::before, .day-sep::after { content: ""; flex: 1; height: 1px; }
.day-sep::before { background: linear-gradient(90deg, transparent, var(--border)); }
.day-sep::after { background: linear-gradient(90deg, var(--border), transparent); }

.msg {
  display: flex; gap: 12px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  transition: background 120ms var(--ease);
}
.msg:hover { background: var(--bg-hover); }
.msg:hover .msg-tools { opacity: 1; }
.msg.grouped { margin-top: -1px; }
/* L'anello attorno all'avatar lo stacca dallo sfondo che cambia al passaggio. */
.msg .avatar { box-shadow: 0 0 0 2px var(--bg-panel), 0 1px 2px rgb(16 24 40 / 18%); }
.msg-gutter { width: 36px; flex-shrink: 0; display: flex; justify-content: center; padding-top: 2px; }
.msg-gutter-time { font-size: 10.5px; color: var(--text-soft); opacity: 0; padding-top: 4px; transition: opacity 120ms; }
.msg:hover .msg-gutter-time { opacity: 1; }
.msg-content { flex: 1; min-width: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; flex-wrap: wrap; }
.msg-author { font-weight: 650; font-size: 13.5px; letter-spacing: -.005em; }
.msg-time { font-size: 11px; color: var(--text-soft); }
.msg-flag { font-size: 11px; color: var(--text-soft); font-style: italic; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.msg-body.deleted { color: var(--text-soft); font-style: italic; }
.msg-tools { opacity: 0; display: flex; gap: 2px; transition: opacity 120ms; flex-shrink: 0; }
.msg-row { display: flex; gap: 8px; align-items: flex-start; }
.msg-row .msg-body { flex: 1; min-width: 0; }

.attachment {
  display: inline-flex; align-items: center; gap: 9px;
  margin-top: 6px; padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
  font-size: 13px;
  max-width: 340px;
  transition: border-color 140ms var(--ease), background 140ms var(--ease), transform 80ms var(--ease);
}
.attachment:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}
.attachment:active { transform: translateY(1px); }
.attachment-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-size { color: var(--text-soft); font-size: 11.5px; flex-shrink: 0; }

.typing {
  height: 18px; padding: 0 24px 2px;
  font-size: 12px; color: var(--text-soft); font-style: italic;
  flex-shrink: 0;
}

.composer {
  border-top: 1px solid var(--border);
  padding: 11px 18px 14px;
  flex-shrink: 0;
}
.composer-box {
  display: flex; align-items: flex-end; gap: 8px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  padding: 7px 9px;
  background: var(--bg-input);
  transition: border-color 140ms var(--ease), box-shadow 140ms var(--ease);
}
.composer-box:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}
.composer-box textarea {
  border: none; background: transparent; padding: 5px 4px;
  max-height: 190px; min-height: 24px;
}
.composer-box textarea:focus-visible { outline: none; }
.composer-hint { font-size: 11.5px; color: var(--text-soft); margin-top: 6px; }

.pending-files { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 7px; }
.pending-file {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 4px 9px; font-size: 12.5px;
  background: var(--accent-soft); border-radius: 20px;
}
.pending-file button { border: none; background: transparent; padding: 0 2px; color: var(--text-soft); }

.empty {
  display: grid; place-items: center; height: 100%;
  color: var(--text-soft); text-align: center; padding: 30px;
}
.empty-inner { max-width: 380px; }
.empty h2 { font-size: 17px; color: var(--text); margin: 0 0 8px; }
.empty p { margin: 0 0 6px; font-size: 13.5px; }

/* --- modale -------------------------------------------------------------- */

.modal-overlay {
  position: fixed; inset: 0;
  background: rgb(8 13 20 / 58%);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  padding: 20px; z-index: 100;
  opacity: 0;
  animation: fade-in 140ms var(--ease) forwards;
}
.modal {
  background: var(--bg-panel);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: min(560px, 100%);
  max-height: 88vh;
  display: flex; flex-direction: column;
  border: 1px solid var(--border);
  animation: modal-in 180ms var(--ease);
}
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.99); } }
.modal-wide { width: min(980px, 100%); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; font-size: 15.5px; }
.modal-body { padding: 18px; overflow-y: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 13px 18px; border-top: 1px solid var(--border);
}

/* --- tabelle ------------------------------------------------------------- */

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-soft); font-weight: 700;
  position: sticky; top: 0; background: var(--bg-panel); z-index: 1;
}
tbody tr:hover { background: var(--bg-hover); }
td.actions { text-align: right; white-space: nowrap; }
td.actions button { margin-left: 4px; }

.tag {
  display: inline-block; padding: 1.5px 8px;
  border-radius: 11px; font-size: 11px; font-weight: 600;
  background: var(--bg-hover); color: var(--text-soft);
  border: 1px solid var(--border);
}
.tag-admin { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.tag-ok { background: transparent; color: var(--success); border-color: var(--success); }
.tag-off { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.tag-warn { background: transparent; color: var(--warning); border-color: var(--warning); }

.mono { font-family: var(--mono); font-size: 12.5px; }

/* --- notifiche ----------------------------------------------------------- */

.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 200; }
.toast {
  background: var(--bg-panel);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  line-height: 1.45;
  max-width: 340px;
  animation: toast-in 200ms var(--ease);
}
.toast-error { border-left-color: var(--danger); }
.toast-success { border-left-color: var(--success); }
.toast-out { opacity: 0; transition: opacity 300ms; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* --- login --------------------------------------------------------------- */

.login-page {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: 20px;
  padding-top: calc(20px + var(--safe-top));
  padding-bottom: calc(20px + var(--safe-bottom));
  background: var(--bg);
}
.login-card {
  width: min(400px, 100%);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 30px 30px 26px;
}
.login-head { text-align: center; margin-bottom: 22px; }
.login-mark {
  width: 46px; height: 46px; border-radius: 11px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  font-size: 20px; font-weight: 700;
  margin: 0 auto 13px;
}
.login-head h1 { font-size: 19px; margin: 0 0 5px; }
.login-head p { color: var(--text-soft); font-size: 13px; margin: 0; }
.login-note {
  margin-top: 18px; padding-top: 16px;
  border-top: 1px solid var(--border);
  font-size: 11.5px; color: var(--text-soft);
  display: flex; align-items: flex-start; gap: 7px;
}
.login-alert {
  background: var(--danger-soft); color: var(--danger);
  border: 1px solid var(--danger); border-radius: var(--radius-sm);
  padding: 9px 12px; font-size: 13px; margin-bottom: 15px;
}
.login-motd {
  background: var(--accent-soft); border-radius: var(--radius-sm);
  padding: 9px 12px; font-size: 12.5px; margin-bottom: 15px;
}

/* --- pannello amministrazione -------------------------------------------- */

.admin-page { max-width: 1220px; margin: 0 auto; padding: 22px; }
.admin-head {
  display: flex; align-items: center; gap: 14px;
  margin-bottom: 20px; flex-wrap: wrap;
}
.admin-head h1 { font-size: 20px; margin: 0; }
.admin-head .spacer { flex: 1; }

.tabs { display: flex; gap: 3px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tab {
  border: none; background: transparent;
  padding: 9px 15px; font-size: 13.5px;
  color: var(--text-soft);
  border-bottom: 2px solid transparent;
  border-radius: 0;
}
.tab:hover { background: var(--bg-hover); color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(155px, 1fr)); gap: 12px; margin-bottom: 22px; }
.card {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px 16px;
}
.card-label { font-size: 11px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-soft); font-weight: 700; }
.card-value { font-size: 24px; font-weight: 600; margin-top: 3px; }
.card-note { font-size: 11.5px; color: var(--text-soft); margin-top: 2px; }

.panel {
  background: var(--bg-panel); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; margin-bottom: 18px;
}
.panel-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.panel-head h2 { font-size: 14.5px; margin: 0; }
.panel-head .spacer { flex: 1; }
.panel-body { padding: 16px; }
.panel-scroll { max-height: 62vh; overflow-y: auto; }

.kv { display: grid; grid-template-columns: minmax(150px, auto) 1fr; gap: 7px 18px; font-size: 13px; }
.kv dt { color: var(--text-soft); }
.kv dd { margin: 0; }

.transcript { max-height: 60vh; overflow-y: auto; font-size: 13px; }
.transcript-line { padding: 5px 0; border-bottom: 1px solid var(--border); }
.transcript-meta { font-size: 11.5px; color: var(--text-soft); }
.transcript-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.transcript-body.deleted { color: var(--danger); font-style: italic; }

.filters { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.filters input, .filters select { width: auto; min-width: 165px; }

.warning-box {
  background: var(--danger-soft);
  border: 1px solid var(--danger);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  font-size: 13px;
  margin-bottom: 15px;
}

.secret-box {
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: .08em;
  background: var(--bg);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 13px;
  text-align: center;
  overflow-wrap: anywhere;
  user-select: all;
}

.checkbox-row { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; font-weight: 400; color: var(--text); font-size: 13.5px; }

.list-picker {
  max-height: 190px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 6px;
}
.list-picker .checkbox-row { margin-bottom: 3px; padding: 3px 5px; border-radius: 4px; }
.list-picker .checkbox-row:hover { background: var(--bg-hover); }

/* --- gestione gruppo ----------------------------------------------------- */

.manager { min-height: 420px; }
.manager .tabs { margin-bottom: 16px; }
.manager-panel { min-height: 360px; }
.manager-h3 { margin: 0 0 8px; font-size: 14px; }
.modal-lead { margin: 0 0 14px; color: var(--text-soft); font-size: 13.5px; }
.sep { margin: 20px 0; border: none; border-top: 1px solid var(--border); }
.row-fields { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; }
.row-fields .field { margin-bottom: 0; }
.row-fields .grow { flex: 1; min-width: 160px; }
.row-fields select { width: auto; min-width: 180px; }

.notice {
  background: var(--accent-soft);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 12.5px;
  margin-bottom: 14px;
}

/* Elenco a sinistra, dettaglio a destra: ranghi e loro permessi. */
.split { display: grid; grid-template-columns: 210px 1fr; gap: 16px; align-items: start; }
.split-list {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 5px;
  max-height: 62vh; overflow-y: auto;
}
.split-item {
  display: flex; align-items: center; gap: 8px;
  width: 100%; text-align: left;
  border: none; background: transparent;
  padding: 7px 9px; border-radius: var(--radius-sm);
  font-size: 13px;
}
.split-item:hover { background: var(--bg-hover); }
.split-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.split-item-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.split-item-meta { font-size: 11px; color: var(--text-soft); }
.split-item-lock { font-size: 11px; }
.split-add {
  width: 100%; margin-top: 4px;
  border: 1px dashed var(--border-strong); background: transparent;
  color: var(--text-soft); font-size: 12.5px; padding: 7px;
}
.split-body { max-height: 62vh; overflow-y: auto; padding-right: 4px; }

.rank-dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.rank-chips { display: flex; flex-wrap: wrap; gap: 4px; }
.rank-chip {
  display: inline-block;
  padding: 1px 8px;
  border: 1px solid currentColor;
  border-radius: 11px;
  font-size: 11px; font-weight: 600;
}

/* Caselle dei permessi: due colonne su schermi larghi, una su stretti. */
.perm-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 6px 22px;
  margin: 16px 0;
}
.perm-area h4 {
  margin: 10px 0 6px;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-soft);
}
.perm-row { display: flex; align-items: flex-start; gap: 9px; padding: 5px 0; }
.perm-row input { width: auto; margin-top: 3px; flex-shrink: 0; }
.perm-row label { margin: 0; font-weight: 400; }
.perm-label { display: block; font-size: 13px; color: var(--text); font-weight: 500; }
.perm-help { display: block; font-size: 11.5px; color: var(--text-soft); line-height: 1.35; }
.perm-row input:disabled + label .perm-label { color: var(--text-soft); }

.member-cell { display: flex; align-items: center; gap: 9px; }
.member-sub { font-size: 11.5px; color: var(--text-soft); }
.member-card { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.member-card-name { font-size: 16px; font-weight: 600; }

.msg-rank {
  font-size: 10.5px; color: var(--text-soft);
  border: 1px solid var(--border); border-radius: 9px; padding: 0 6px;
}
.msg.mention { background: var(--accent-soft); }

.composer-locked {
  border-top: 1px solid var(--border);
  padding: 14px 18px;
  font-size: 12.5px;
  color: var(--text-soft);
  text-align: center;
  flex-shrink: 0;
}

/* --- scrollbar ----------------------------------------------------------- */

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 5px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-thumb:hover { background: var(--text-soft); background-clip: content-box; }

/* --- schermi stretti ----------------------------------------------------- */

/* --- pannello scorrevole -------------------------------------------------- */

.drawer-backdrop {
  position: fixed; inset: 0;
  background: rgb(8 12 18 / 55%);
  z-index: 45;
  opacity: 0;
  animation: fade-in 160ms forwards;
}
@keyframes fade-in { to { opacity: 1; } }

/* --- tablet: la barra dei gruppi resta, i canali diventano un pannello ----- */

@media (max-width: 900px) {
  .layout { grid-template-columns: var(--rail-w) 1fr; }
  /* Sopra lo sfondo scuro del pannello: con il pannello aperto si deve poter
     comunque cambiare gruppo. */
  .rail { position: relative; z-index: 51; }
  .sidebar {
    position: fixed;
    top: 0; bottom: 0; left: var(--rail-w);
    width: var(--drawer-w);
    z-index: 50;
    transform: translateX(calc(-1 * (var(--rail-w) + var(--drawer-w))));
    transition: transform 200ms ease;
    box-shadow: 8px 0 24px rgb(0 0 0 / 28%);
  }
  body.drawer-open .sidebar { transform: none; }
  .topbar-topic { display: none; }
  .admin-page { padding: 14px; }
  .split { grid-template-columns: 1fr; }
  .split-list { max-height: 200px; }
}

@media (min-width: 901px) {
  .menu-toggle { display: none; }
  .drawer-backdrop { display: none; }
  .call-pill { display: none; }
}

/* --- telefono ------------------------------------------------------------- */

@media (max-width: 700px) {
  :root { --rail-w: 62px; --drawer-w: min(78vw, 292px); }

  .layout { grid-template-columns: 1fr; }

  /* Barra dei gruppi e canali scorrono insieme, come un unico pannello. */
  .rail {
    position: fixed;
    top: 0; bottom: 0; left: 0;
    width: var(--rail-w);
    z-index: 51;
    padding-top: calc(10px + var(--safe-top));
    padding-bottom: calc(10px + var(--safe-bottom));
    padding-left: var(--safe-left);
    transform: translateX(calc(-1 * (var(--rail-w) + var(--drawer-w))));
    transition: transform 200ms ease;
  }
  body.drawer-open .rail { transform: none; }

  .sidebar { padding-top: var(--safe-top); }
  .group-head { padding-top: calc(14px + var(--safe-top)); }

  /* Bersagli più grandi: il dito non ha la precisione del puntatore. */
  .side-item { padding: 10px 10px; font-size: 14.5px; }
  .voice-person { padding: 7px 10px 7px 28px; }
  .side-title { padding: 0 10px 8px; font-size: 11px; }
  .side-title button { font-size: 20px; padding: 2px 10px; }

  .topbar {
    padding: 10px 12px;
    padding-top: calc(10px + var(--safe-top));
    gap: 8px;
  }
  .topbar-title { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar-actions { gap: 2px; }

  /* In alto lo spazio è poco: le etichette lunghe lasciano il posto al loro
     simbolo, mentre il nome per i lettori di schermo resta nell'aria-label. */
  .compact { font-size: 0; padding: 7px 9px; }
  .compact::before { content: attr(data-icon); font-size: 17px; line-height: 1; }

  .messages {
    padding: 10px 12px 4px;
    /* Lo scorrimento resta dentro l'elenco: niente "tira per aggiornare" che
       ricarica la pagina mentre si legge. */
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
  }
  .msg { padding: 5px 4px; }
  .msg-gutter { width: 30px; }
  .day-sep { margin: 14px 0 10px; }

  .composer {
    padding: 9px 12px;
    padding-bottom: calc(9px + var(--safe-bottom));
  }
  .composer-hint { display: none; }
  .composer-box { padding: 5px 6px; }
  .composer-locked { padding-bottom: calc(14px + var(--safe-bottom)); }

  .typing { padding: 0 14px 2px; }

  /* Le finestre diventano fogli che salgono dal basso: si raggiungono col
     pollice e si chiudono con lo stesso gesto di sempre. */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    width: 100%;
    max-height: 92dvh;
    border-radius: 14px 14px 0 0;
    padding-bottom: var(--safe-bottom);
    animation: sheet-up 220ms ease;
  }
  @keyframes sheet-up { from { transform: translateY(18px); opacity: .6; } }
  .modal-head { padding: 15px 16px; }
  .modal-head h2 { font-size: 16px; }
  .modal-body { padding: 16px; }
  .modal-foot { padding: 12px 16px calc(12px + var(--safe-bottom)); }
  .modal-foot button { flex: 1; padding: 11px 14px; }

  /* Le tabelle non si comprimono: scorrono in orizzontale dentro il loro
     riquadro, senza trascinarsi dietro la pagina. */
  .panel-scroll, .modal-body { overflow-x: auto; }
  table { min-width: 520px; }
  .row-fields select, .row-fields .grow { width: 100%; min-width: 0; }
  .row-fields { flex-direction: column; align-items: stretch; }

  .toasts { right: 10px; left: 10px; bottom: calc(10px + var(--safe-bottom)); }
  .toast { max-width: none; }

  .admin-page { padding: 12px 12px calc(12px + var(--safe-bottom)); }
  .cards { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); }
  .tabs { overflow-x: auto; flex-wrap: nowrap; }
  .tab { white-space: nowrap; }

  .login-card { padding: 24px 20px 22px; }
}

/* --- comandi a sfioramento ------------------------------------------------ */

/* Senza puntatore non esiste il passaggio del mouse: ciò che si rivelava al
   passaggio deve essere sempre visibile, altrimenti diventa irraggiungibile. */
@media (hover: none) {
  .msg-tools { opacity: 1; }
  .msg-gutter-time { opacity: 1; }
  .voice-kick { opacity: 1; }
  .msg-tools .icon-btn { padding: 6px 9px; font-size: 16px; }
  .icon-btn { padding: 8px 10px; }
  .btn-sm { padding: 7px 12px; }
  td.actions button { margin: 2px; }
  /* Sotto i 16px iOS ingrandisce la pagina appena si tocca un campo, e non la
     rimpicciolisce più. */
  input, textarea, select { font-size: 16px; }
  .composer-box textarea { font-size: 16px; }
}

/* --- autodistruzione dei messaggi ----------------------------------------- */

/* Pulsante in alto: dice sempre per quanto vive ciò che si scrive qui dentro. */
.eph-btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-soft);
  border-radius: 999px;
  font-size: 12.5px; font-weight: 600;
  box-shadow: none;
  white-space: nowrap;
}
/* `display` batte l'attributo hidden del browser: senza questa riga il
   pulsante resterebbe visibile anche quando il codice lo nasconde. */
.eph-btn[hidden] { display: none; }
.eph-btn:hover:not(:disabled) {
  background: var(--bg-hover); color: var(--text); border-color: var(--border-strong);
}
.eph-btn .eph-ico { font-size: 13px; line-height: 1; }

/* Acceso: colore proprio, riconoscibile a colpo d'occhio in mezzo al resto. */
.eph-btn.on {
  color: var(--ephemeral);
  background: var(--ephemeral-soft);
  border-color: var(--ephemeral-border);
}
.eph-btn.on:hover:not(:disabled) {
  color: var(--ephemeral); background: var(--ephemeral-soft); border-color: var(--ephemeral);
}
/* Chi non può cambiare la durata la legge soltanto: niente invito a premere. */
.eph-btn:disabled { opacity: 1; cursor: default; }

/* Scelta della durata dentro la finestra. */
.eph-choices { display: grid; gap: 7px; margin-bottom: 16px; }
.eph-choice {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  width: 100%; text-align: left;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-panel);
  box-shadow: none;
  font-size: 13.5px; font-weight: 500;
}
.eph-choice:hover:not(:disabled) { border-color: var(--border-strong); background: var(--bg-hover); }
.eph-choice-mark { opacity: 0; color: var(--accent); font-weight: 700; }
.eph-choice.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 650;
  box-shadow: inset 0 0 0 1px var(--accent);
}
.eph-choice.active .eph-choice-mark { opacity: 1; }

/* Conto alla rovescia accanto al messaggio. */
.msg-expiry {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0 7px;
  border: 1px solid var(--ephemeral-border);
  background: var(--ephemeral-soft);
  color: var(--ephemeral);
  border-radius: 999px;
  font-size: 10.5px; font-weight: 700;
  line-height: 1.7;
  white-space: nowrap;
  flex-shrink: 0;
}
.msg-expiry-ico { font-size: 9.5px; }
/* Ultimo minuto: fra poco il messaggio sparisce davvero. */
.msg-expiry.urgent {
  color: var(--danger);
  border-color: var(--danger);
  background: var(--danger-soft);
  animation: eph-pulse 1.4s ease-in-out infinite;
}
@keyframes eph-pulse { 50% { opacity: .45; } }

/* Filo sul bordo sinistro: si vede che il messaggio è a tempo anche scorrendo
   in fretta, senza fermarsi a leggere il conto alla rovescia. */
.msg.ephemeral { box-shadow: inset 2px 0 0 var(--ephemeral-border); }

/* Promemoria sotto la casella di scrittura. */
.composer-hint.ephemeral-on { color: var(--ephemeral); font-weight: 600; }

/* --- ritocchi ------------------------------------------------------------- */

/* Le voci di elenco non si "premono": sono navigazione, non azioni. */
.rail-item:active:not(:disabled),
.side-item:active:not(:disabled),
.split-item:active:not(:disabled),
.tab:active:not(:disabled) { transform: none; }

@media (max-width: 700px) {
  /* In alto lo spazio è poco: restano il simbolo e la durata, non la parola. */
  .eph-btn { padding: 6px 9px; font-size: 12px; }
  .eph-btn:not(.on) .eph-label { display: none; }
  .eph-choice { padding: 13px 14px; }
}

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