/* Messaggi (web/messages.js): conversations and 1:1 threads, «Creuza a colori» (ink outlines, flat blocks).
   Tokens: web/app.css. Loaded before creuza.css, which stays last. */

.dm-i { width: 20px; height: 20px; flex: none; }

/* ---------- Avatars ---------- */
.dm-avatar { width: 48px; height: 48px; flex: none; border-radius: 50%; display: grid; place-items: center; overflow: hidden; background: var(--gold); color: #1d1f24; border: 2px solid var(--outline); font: 900 17px/1 var(--display); font-stretch: 72%; }
.dm-avatar img { width: 100%; height: 100%; object-fit: cover; }
.dm-avatar.is-sm { width: 38px; height: 38px; font-size: 14px; }

/* ---------- List (#messaggi) ---------- */
.dm-page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.dm-new { display: inline-flex; align-items: center; gap: 6px; }
.dm-list { list-style: none; margin: 16px 0 0; padding: 0; display: grid; gap: 10px; }
.dm-row { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: var(--r-md); background: var(--surface); border: var(--card-border); box-shadow: var(--card-shadow); color: inherit; text-decoration: none; min-width: 0; transition: transform .12s var(--ease), box-shadow .12s var(--ease); }
.dm-row:active { transform: translate(3px, 3px); box-shadow: var(--press-shadow); }
.dm-row-copy { display: grid; flex: 1; min-width: 0; }
.dm-row-copy strong { font-size: 15.5px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-row-copy small { color: var(--muted); font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-row.is-unread .dm-row-copy small { color: var(--ink); font-weight: 800; }
.dm-row-meta { display: grid; justify-items: end; gap: 6px; flex: none; }
.dm-row-meta time { color: var(--muted); font-size: 12px; font-weight: 700; }
.dm-count { min-width: 22px; height: 22px; padding: 0 6px; border-radius: var(--r-pill); display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-size: 12px; font-weight: 900; }
.dm-empty { margin-top: 18px; text-align: center; }
.dm-empty-icon { width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 50%; display: grid; place-items: center; background: var(--gold); color: #1d1f24; border: 2px solid var(--outline); }
.dm-empty-icon .dm-i { width: 28px; height: 28px; }

/* ---------- Thread (#messaggi/<id>) ---------- */
/* The composer sticks above the bottom navigation, like the groups' bacheca. */
.workspace:has(.dm-thread) { padding-bottom: calc(var(--nav-h) + var(--safe-bottom)); }
main:has(.dm-thread) { padding-bottom: 0; }
.dm-thread { display: flex; flex-direction: column; min-height: calc(100dvh - var(--header-h) - var(--safe-top) - var(--nav-h) - var(--safe-bottom) - 8px); }
.dm-thread-head { position: sticky; top: calc(var(--header-h) + var(--safe-top)); z-index: 22; display: flex; align-items: center; gap: 6px; margin: -8px calc(-1 * var(--gutter)) 0; padding: 8px var(--gutter) 8px calc(var(--gutter) - 10px); background: color-mix(in srgb, var(--bg) 90%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border-bottom: 2px solid var(--outline); }
.dm-back { flex: none; }
.dm-head-main { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; color: inherit; text-decoration: none; padding: 2px 4px; border-radius: var(--r-md); }
.dm-head-copy { display: grid; min-width: 0; }
.dm-head-copy strong { font: 900 19px/1.1 var(--display); font-stretch: 68%; text-transform: uppercase; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-head-copy small { color: var(--muted); font-size: 12.5px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-older { display: flex; justify-content: center; min-height: 8px; margin-top: 10px; }
.dm-stream { flex: 1; display: flex; flex-direction: column; gap: 4px; padding: 8px 0 12px; }
.dm-start { margin: auto 0 0; text-align: center; color: var(--muted); font-weight: 650; }
.dm-day, .dm-new-divider { display: flex; align-items: center; gap: 10px; margin: 14px 0 6px; color: var(--muted); font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.dm-day::before, .dm-day::after, .dm-new-divider::before, .dm-new-divider::after { content: ""; flex: 1; height: 2px; background: var(--line); }
.dm-new-divider { color: var(--accent); }
.dm-new-divider::before, .dm-new-divider::after { background: var(--accent); }

.dm-msg { display: flex; flex-direction: column; max-width: min(78%, 520px); }
.dm-msg.is-mine { align-self: flex-end; align-items: flex-end; }
.dm-msg.is-theirs { align-self: flex-start; align-items: flex-start; }
.dm-bubble { padding: 9px 13px; border-radius: 20px; border: var(--card-border); overflow-wrap: anywhere; min-width: 0; max-width: 100%; }
.dm-msg.is-mine .dm-bubble { background: var(--accent); color: var(--accent-ink); border-bottom-right-radius: 6px; }   /* white on red; dark ink on the lighter dark-mode red */
.dm-msg.is-theirs .dm-bubble { background: var(--surface); color: var(--ink); border-bottom-left-radius: 6px; }
.dm-msg.is-pending .dm-bubble { opacity: .7; }
.dm-msg.is-failed .dm-bubble { background: var(--danger-soft); color: var(--ink); }
.dm-msg.has-card .dm-bubble { padding: 6px; }
.dm-text { margin: 0; white-space: pre-wrap; font-size: 15px; line-height: 1.4; }
.dm-msg.has-card .dm-text { padding: 6px 7px 3px; }
.dm-deleted { font-style: italic; opacity: .8; }
.dm-meta { display: flex; align-items: center; gap: 4px; margin: 2px 6px 4px; color: var(--muted); font-size: 11.5px; font-weight: 700; }
.dm-failed { color: var(--danger); }
.dm-link { background: none; border: 0; padding: 4px 6px; color: var(--accent); font: 800 13px var(--font); text-decoration: underline; cursor: pointer; }
.dm-del { width: 22px; height: 22px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; color: var(--muted); opacity: .55; cursor: pointer; }
.dm-del .dm-i { width: 14px; height: 14px; }
.dm-del:hover, .dm-del:focus-visible { opacity: 1; background: var(--surface-2); }

/* Shared cards inside a bubble */
.dm-card { display: grid; gap: 8px; min-width: min(240px, 60vw); padding: 10px; border-radius: 14px; background: var(--surface); color: var(--ink); border: var(--card-border); }
.dm-card-top { display: flex; gap: 10px; align-items: flex-start; min-width: 0; }
.dm-card-emoji { width: 38px; height: 38px; flex: none; border-radius: 12px; display: grid; place-items: center; font-size: 19px; background: var(--gold); border: 2px solid var(--outline); }
.dm-card--event .dm-card-emoji, .dm-card--plan .dm-card-emoji { background: var(--sea-soft); }
.dm-card-copy { display: grid; min-width: 0; }
.dm-card-copy small { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .05em; }
.dm-card-copy strong { font-size: 15px; line-height: 1.25; overflow-wrap: anywhere; }
.dm-card-copy span { color: var(--ink-2); font-size: 13px; font-weight: 600; }
.dm-card-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.dm-card-btn { display: inline-flex; align-items: center; gap: 5px; min-height: 36px; padding: 0 12px; border-radius: var(--r-pill); background: var(--surface); color: var(--ink); border: 2px solid var(--outline); font: 800 13px var(--font); text-decoration: none; cursor: pointer; }
.dm-card-btn.is-go { background: var(--accent); color: var(--accent-ink); }
.dm-card-btn .dm-i { width: 16px; height: 16px; }

/* Composer */
.dm-dock { position: sticky; bottom: calc(var(--nav-h) + var(--safe-bottom)); z-index: 20; margin: 6px calc(-1 * var(--gutter)) 0; padding: 8px var(--gutter) 10px; background: var(--bg); box-shadow: 0 -12px 16px -8px var(--bg); }
.dm-composer { display: flex; align-items: flex-end; gap: 8px; padding: 5px 5px 5px 16px; border-radius: 24px; background: var(--surface); border: var(--card-border); box-shadow: var(--card-shadow); }
.dm-composer textarea { flex: 1; min-width: 0; min-height: 40px; max-height: 132px; padding: 9px 0; border: 0; background: transparent; color: var(--ink); resize: none; font: 500 15px/1.4 var(--font); box-shadow: none !important; outline: none; }
.dm-send { width: 42px; height: 42px; flex: none; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); border: 2px solid var(--outline); cursor: pointer; }
.dm-send .dm-i { width: 19px; height: 19px; }
.dm-closed { margin: 0; padding: 12px 14px; border-radius: var(--r-md); background: var(--surface-2); color: var(--ink-2); font-size: 14px; font-weight: 650; text-align: center; border: var(--card-border); }
.dm-jump { position: absolute; left: 50%; top: -42px; transform: translateX(-50%); display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: var(--r-pill); background: var(--ink); color: var(--bg); border: 0; font: 800 13px var(--font); box-shadow: var(--shadow-2); white-space: nowrap; }
.dm-jump .dm-i { width: 15px; height: 15px; }
@media (min-width: 960px) {
  .workspace:has(.dm-thread) { padding-bottom: 0; }
  .dm-dock { bottom: 0; }
  .dm-thread { min-height: calc(100dvh - var(--header-h) - 40px); }
}

/* ---------- Sheets: «Nuovo messaggio» and «Invia a un amico» ---------- */
.dm-sheet { margin-top: 4px; }
.dm-sheet-empty { color: var(--ink-2); font-weight: 600; }
.dm-share-preview { margin-bottom: 12px; }
.dm-share-preview .dm-card { min-width: 0; }
.dm-note { display: grid; gap: 6px; margin-bottom: 12px; }
.dm-optional { color: var(--muted); font-weight: 600; }
.dm-friends { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.dm-friend { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 12px; border-radius: var(--r-md); background: var(--surface); color: inherit; border: var(--card-border); text-align: left; cursor: pointer; }
.dm-friend:active { transform: translate(2px, 2px); }
.dm-friend .dm-avatar { width: 40px; height: 40px; font-size: 15px; }

@media (prefers-reduced-motion: reduce) {
  .dm-row, .dm-friend { transition: none; }
  .dm-row:active, .dm-friend:active { transform: none; }
}
