/* 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); }

/* Mercatino: pagina della proposta e scheda della proposta in chat */
.offer-listing { display: flex; gap: .9rem; align-items: center; padding: .8rem; margin: 0 0 1.2rem; border: 1px solid var(--rule); border-radius: 12px; color: inherit; text-decoration: none; }
.offer-listing-photo { position: relative; flex: 0 0 72px; aspect-ratio: 3 / 4; border-radius: 8px; overflow: hidden; background: var(--sage); }
.offer-listing-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.offer-listing-photo .market-badge { top: 4px; right: 4px; font-size: .62rem; }
.offer-listing-info { display: flex; flex-direction: column; gap: .1rem; min-width: 0; }
.offer-listing-price { font-weight: 800; margin-top: .2rem; }
.offer-listing-seller { display: flex; align-items: center; gap: .35rem; margin-top: .2rem; }
.offer-form .section-title { margin: .4rem 0 .8rem; }
.offer-price input { max-width: 12rem; }

.msg.has-offer { max-width: min(420px, 86%); }
.offer-card { background: var(--surface); color: var(--ink); border-radius: 10px; padding: .6rem; margin: .15rem -.45rem .45rem; display: flex; flex-direction: column; gap: .5rem; }
.offer-tag { display: inline-flex; align-items: center; gap: .3rem; font-size: .75rem; font-weight: 750; color: var(--forest); text-transform: uppercase; letter-spacing: .04em; }
.offer-books { display: flex; align-items: center; gap: .6rem; }
.offer-thumb { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; gap: .1rem; color: inherit; text-decoration: none; }
.offer-thumb-photo { aspect-ratio: 3 / 4; max-width: 130px; border-radius: 6px; overflow: hidden; background: var(--sage); display: grid; place-items: center; }
.offer-thumb-photo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.offer-thumb-title { font-weight: 750; font-size: .88rem; line-height: 1.2; margin-top: .25rem; }
.offer-thumb-sub { font-size: .76rem; color: var(--ink-2); }
.offer-swap-icon { color: var(--forest); flex: 0 0 auto; }
.offer-price-box { flex: 1 1 0; display: flex; flex-direction: column; gap: .3rem; }
.offer-status:empty { display: none; }
.offer-badge { display: inline-block; padding: .15rem .5rem; border-radius: 4px; font-size: .76rem; font-weight: 750; background: var(--amber); color: var(--amber-ink); }

/* Chat: foto allegate */
.chat-attach { flex-shrink: 0; cursor: pointer; color: var(--ink-2); }
.chat-attach:hover { color: var(--forest); }
.chat-attach-preview { display: flex; align-items: center; gap: .7rem; padding: .5rem 1rem; border-top: 1px solid var(--rule); background: var(--surface); }
.chat-attach-preview[hidden] { display: none; }
.chat-attach-preview img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }
.chat-attach-preview span { flex: 1; min-width: 0; }
.chat-attach-preview.sending img { opacity: .5; }
.msg-photo { display: block; min-height: 140px; margin: .1rem -.45rem .3rem; border-radius: 10px; overflow: hidden; background: var(--sage); } /* spazio riservato finché la foto non è caricata */
.msg-photo img { display: block; width: 100%; max-width: 280px; max-height: 320px; object-fit: cover; }
.msg:has(.msg-photo) { max-width: min(300px, 80%); }

/* Chat: «Nuovo messaggio» */
.conv-head { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: 0 .6rem .8rem; }
.conv-head .page-title { padding: 0; }
.new-message-btn { flex-shrink: 0; width: 44px; min-height: 44px; padding: 0; justify-content: center; border-radius: 12px; }
.thread-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .8rem; }
/* Tendina «Scrivi a…» */
.recipient-search { position: relative; margin: 0 .6rem .8rem; }
.recipient-search-icon { position: absolute; left: .8rem; top: 50%; transform: translateY(-50%); color: var(--ink-2); pointer-events: none; display: flex; }
.recipient-input { width: 100%; box-sizing: border-box; padding-left: 2.4rem !important; min-height: 44px; }
.recipient-menu { position: absolute; z-index: 30; top: calc(100% + 6px); left: 0; right: 0; margin: 0; padding: .35rem; list-style: none;
  max-height: min(55vh, 380px); overflow-y: auto; overscroll-behavior: contain; background: var(--surface); border: 1px solid var(--rule);
  border-radius: 14px; box-shadow: 0 12px 32px rgba(0, 0, 0, .14); animation: recipient-in .14s ease-out; }
.recipient-menu[hidden] { display: none; }
@keyframes recipient-in { from { opacity: 0; transform: translateY(-4px); } }
.recipient-head { padding: .35rem .5rem .2rem; }
.recipient-empty { padding: .6rem .5rem; }
.recipient { display: flex; align-items: center; gap: .65rem; padding: .45rem .5rem; border-radius: 10px; cursor: pointer; min-height: 44px; }
.recipient[aria-selected="true"], .recipient:hover { background: var(--sage); }
@media (prefers-reduced-motion: reduce) { .recipient-menu { animation: none; } }
@media (max-width: 767px) {
  .conv-head { padding: 0 16px .6rem; }
  .recipient-search { margin: 0 16px .7rem; }
  .recipient-input { font-size: 1rem; } /* sotto i 16px iOS ingrandisce la pagina al tocco */
}
