/* guscio: rifinitura del 18/11/2026. Caricato dopo style.css: le regole qui vincono.
   Copre: barra laterale, barra in alto e in basso del telefono, intestazioni di pagina,
   chat, finestre e menu «⋯», moderazione. Colori solo da variabili (valgono anche per lo scuro). */

/* ---------- Guscio: fuoco e aree di tocco ---------- */
.nav-link:focus-visible, .conv:focus-visible, .more-item:focus-visible, .tabs button:focus-visible {
  outline: 2px solid var(--forest); outline-offset: -2px; border-radius: 8px;
}
.nav-link { -webkit-tap-highlight-color: transparent; }
.nav-link .badge { min-width: 20px; text-align: center; }
.page-title { text-wrap: balance; }
.page-head { align-items: center; }
.page-head > .btn { flex-shrink: 0; }
.empty { display: flex; flex-direction: column; align-items: center; gap: .6rem; }
.empty > p { margin: 0; }

/* ---------- Menu «⋯» ---------- */
.more-menu summary { cursor: pointer; }
.more-menu summary:focus-visible { outline: 2px solid var(--forest); outline-offset: 2px; }
.more-menu[open] > summary { background: var(--sage-2); color: var(--ink); }
.more-item { min-height: 40px; }
.more-item:focus-visible { background: var(--sage-2); }
.more-item .icon { color: var(--ink-2); flex-shrink: 0; }
.more-item.danger .icon { color: inherit; }
.more-item.danger:hover, .more-item.danger:focus-visible { background: color-mix(in srgb, var(--danger) 10%, transparent); }

/* ---------- Finestre ---------- */
.sheet { max-height: calc(100dvh - 32px); overflow-y: auto; overscroll-behavior: contain; }
.sheet:focus { outline: none; }
.sheet-head h2 { font-size: 1.15rem; letter-spacing: -.02em; text-wrap: balance; }
.sheet .form-actions { margin-top: .4rem; }
.sheet .form-actions .btn { min-height: 44px; }
.sheet .field:last-of-type, .report-form .field { margin-bottom: .8rem; }
.sheet .form-error:empty { display: none; }
.choice { min-height: 44px; }
.choice input { flex-shrink: 0; }
@media (max-width: 720px) {
  .more-item { min-height: 46px; }
  .more-list { min-width: min(240px, calc(100vw - 32px)); }
  .sheet .form-actions { flex-direction: column-reverse; }
  .sheet .form-actions .btn { width: 100%; }
}

/* ---------- Chat ---------- */
.chat { height: calc(100dvh - 60px); background: var(--surface); }
.conv-list { background: var(--surface); }
.conv { min-height: 64px; position: relative; }
.conv:focus-visible { outline-offset: -2px; }
.conv.unread .conv-last { color: var(--ink); font-weight: 650; }
.conv.unread .strong { font-weight: 800; }
.conv-empty { padding: .4rem .6rem; display: flex; flex-direction: column; align-items: flex-start; gap: .8rem; color: var(--ink-2); }
.conv-empty p { margin: 0; }
.thread-head { min-height: 60px; background: var(--surface); }
.thread-who:hover { color: inherit; }
.thread-empty { padding: 2rem; text-align: center; }
.thread-empty p { margin: 0; max-width: 28ch; }
.thread-blocked { display: flex; flex-direction: column; align-items: center; gap: .6rem; padding: 1rem 1rem calc(1rem + env(safe-area-inset-bottom)); }
.thread-blocked p { margin: 0; }
.thread-start { align-self: center; margin: auto 0; padding: 1rem; text-align: center; color: var(--ink-2); max-width: 30ch; }
.messages { overscroll-behavior: contain; scroll-behavior: smooth; }
.day-sep { margin: .9rem 0 .4rem; }
.msg { border-radius: 14px; line-height: 1.4; }
.msg.mine { border-bottom-right-radius: 4px; }
.msg.theirs { border-bottom-left-radius: 4px; }
.msg.grouped { margin-top: -.2rem; }
.msg.mine:has(+ .msg.mine.grouped) { border-bottom-right-radius: 14px; }
.msg.theirs:has(+ .msg.theirs.grouped) { border-bottom-left-radius: 14px; }
.msg.mine.grouped { border-top-right-radius: 4px; }
.msg.theirs.grouped { border-top-left-radius: 4px; }
/* l'ora compare solo sull'ultimo messaggio di un gruppo */
.msg:has(+ .msg.grouped) time { display: none; }
.msg .more-menu:focus-within { opacity: 1; }
.msg .more-menu summary { position: relative; }
.msg .more-menu summary::after { content: ''; position: absolute; inset: -6px; }
.msg.theirs .more-list { right: auto; left: 0; }
.msg .more-list { top: auto; bottom: calc(100% + 4px); }
.composer-chat { background: var(--surface); padding: .7rem 1rem; align-items: flex-end; }
.composer-chat textarea { min-height: 44px; line-height: 1.4; overflow-y: auto; }
.composer-chat .btn-icon-round { flex-shrink: 0; }
.composer-chat .btn-icon-round:disabled { opacity: .4; cursor: default; }

@media (max-width: 720px) {
  /* campo di scrittura fisso in basso, sopra la barra di navigazione fluttuante */
  .shell.is-chat .main { padding: 0 0 calc(82px + env(safe-area-inset-bottom)); }
  .chat {
    margin: 0 -16px; border-radius: 0; border-left: 0; border-right: 0; border-top: 0;
    height: calc(100dvh - 57px - 82px - env(safe-area-inset-bottom));
  }
  .conv { padding: .55rem 16px; border-radius: 0; }
  .conv-list { padding: 1rem 0 .5rem; }
  .conv-list .page-title { padding: 0 16px .6rem; }
  .conv-empty { padding: .4rem 16px; }
  .thread-head { padding: .4rem .6rem .4rem .4rem; }
  .thread-back { width: 44px; min-height: 44px; }
  .messages { padding: .8rem 14px; }
  .composer-chat { padding: .6rem 12px; gap: .5rem; }
  .composer-chat textarea { font-size: 1rem; } /* sotto i 16px iOS ingrandisce la pagina al tocco */
  .msg { max-width: 86%; }
  .msg .more-menu summary { width: 28px; min-height: 24px; }
  .msg .more-menu summary::after { inset: -10px; }
}

/* ---------- Moderazione ---------- */
.admin { gap: 18px; }
.stat-row { overflow: hidden; }
.stat strong { font-size: 1.6rem; }
.tabs-wrap { flex-wrap: wrap; overflow: visible; gap: 0 2px; }
.tabs button { min-height: 44px; padding-inline: .9rem; }
.tabs button:focus-visible { outline-offset: -3px; }
.admin-body { min-height: 120px; }
.admin-body[aria-busy="true"] { opacity: .7; }
.report { gap: .9rem; }
.report-head { flex-wrap: wrap; row-gap: .3rem; }
.report-target { align-items: flex-start; }
.report-target a { text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1px; }
.report-reasons { display: flex; flex-direction: column; gap: .2rem; }
.report .form-actions .btn { min-height: 44px; }
.data-table caption { text-align: left; }
.data-table tbody tr:hover { background: var(--sage-2); }
.invite-form { padding: 1.2rem; }
.invite-form h2 { margin: 0 0 .3rem; font-size: 1.1rem; }
.invite-form > .muted { margin: 0 0 1rem; }

.users-filters { display: flex; flex-wrap: wrap; gap: .6rem; }
.users-filters input { flex: 1 1 220px; width: auto; }
.users-filters .select { flex: 0 1 190px; width: auto; }
.user-row { align-items: flex-start; }
.user-row > .avatar { margin-top: 2px; }
.user-info { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.user-info > .muted { overflow-wrap: anywhere; }
.user-tags { display: flex; flex-wrap: wrap; gap: .3rem; margin-top: .2rem; }
.user-actions { display: flex; align-items: center; gap: .4rem; flex-shrink: 0; }
.role-select { width: auto; min-width: 150px; }
.role-tag.role-admin { background: var(--forest-soft); color: var(--ink); }
.role-tag.role-moderatore { background: var(--sage); color: var(--ink); }
.role-tag.role-utente { background: var(--sage-2); }
.users-results { display: flex; flex-direction: column; gap: .8rem; }

@media (max-width: 720px) {
  .stat strong { font-size: 1.4rem; }
  .tabs-wrap { margin: 0 -16px; padding: 0 12px; }
  .tabs button { padding-inline: .7rem; }
  .user-row { flex-wrap: wrap; }
  .user-info { flex: 1 1 calc(100% - 52px); }
  .user-actions { flex: 1 1 100%; margin-left: 48px; }
  .user-actions .role-select { flex: 1; }
  .report-target { flex-direction: column; }
  .report-thumb { width: 72px; }
  .report .form-actions { flex-direction: column-reverse; }
  .report .form-actions .btn { width: 100%; }
}

/* ---------- Telefono: barra in alto e barra in basso ---------- */
@media (max-width: 720px) {
  .topbar { min-height: 56px; }
  .topbar-actions .btn-icon { width: 44px; min-height: 44px; }
  .topbar-bell .badge { top: 4px; right: 2px; }
  .nav-link { min-height: 52px; }
  .nav-link:focus-visible { outline-offset: -3px; border-radius: 22px; }
  .page-title { font-size: 1.6rem; letter-spacing: -.03em; }
  .page-head { flex-direction: row; align-items: center; flex-wrap: wrap; }
}

/* ---------- Schermi medi: barra laterale a sole icone ---------- */
@media (min-width: 721px) and (max-width: 1180px) {
  .nav-link { min-height: 48px; }
  .nav-link:focus-visible { outline-offset: 0; }
}

/* Area di amministrazione nel menu: separata da quella di tutti, solo per chi modera o amministra */
.nav-admin { display: flex; flex-direction: column; gap: 2px; padding-bottom: 10px; margin-bottom: 10px; border-bottom: 1px solid var(--rule); }
.nav-admin-title { font-size: .75rem; font-weight: 700; color: var(--ink-2); padding: 0 .75rem .2rem; }
@media (max-width: 1180px) {
  .nav-admin-title { display: none; }
}
.topbar-admin { color: var(--forest); }
