:root {
  --ink: #17222e;
  --ink-2: #1f2d3c;
  --surface: #eef2f5;
  --card: #ffffff;
  --accent: #0e7c86;
  --accent-dark: #0a5f67;
  --amber: #f0a500;
  --text: #1b2733;
  --muted: #64748b;
  --bubble-me: #0e7c86;
  --bubble-other: #ffffff;
  --radius: 14px;
  --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", Menlo, monospace;
}

html, body { height: 100%; }
body {
  margin: 0;
  background: var(--surface);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
}

.btn-accent { background: var(--accent); color: #fff; border: none; }
.btn-accent:hover, .btn-accent:focus { background: var(--accent-dark); color: #fff; }
.bg-accent { background: var(--accent) !important; }
.link-accent { color: var(--accent); }
.min-w-0 { min-width: 0; }

/* ---------------- LOGIN ---------------- */
.auth-wrap {
  height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, var(--ink) 0%, #0e3a41 100%);
  padding: 1rem;
}
.auth-card {
  background: var(--card); border-radius: 18px; padding: 2.2rem;
  width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.auth-brand { text-align: center; margin-bottom: 1.6rem; }
.auth-logo {
  width: 64px; height: 64px; margin: 0 auto .8rem; border-radius: 16px;
  background: var(--accent); color: #fff; font-size: 1.6rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.auth-brand h1 { font-size: 1.35rem; font-weight: 700; margin: 0; }

/* ---------------- LAYOUT APP ---------------- */
.app-wrap { display: flex; height: 100vh; height: 100dvh; }

.sidebar {
  width: 340px; min-width: 340px; background: var(--ink); color: #e9eef3;
  display: flex; flex-direction: column;
}
.sidebar-top { padding: 1rem 1rem .8rem; border-bottom: 1px solid rgba(255,255,255,.08); }
.sidebar-search { background: var(--ink-2); border: 1px solid rgba(255,255,255,.12); color: #e9eef3; }
.sidebar-search::placeholder { color: rgba(233,238,243,.5); }
.sidebar-search:focus { background: var(--ink-2); color: #fff; border-color: var(--accent); box-shadow: none; }

.btn-icon {
  background: transparent; border: none; color: inherit; font-size: 1.05rem;
  line-height: 1; padding: .35rem .55rem; border-radius: 8px;
}
.btn-icon:hover { background: rgba(127,127,127,.15); color: inherit; }

/* Lista conversazioni */
.conv-list { flex: 1; overflow-y: auto; }
.conv-empty { padding: 2rem 1rem; text-align: center; opacity: .6; font-size: .9rem; }
.conv-item {
  display: flex; gap: .7rem; padding: .7rem 1rem; cursor: pointer;
  border-left: 3px solid transparent; align-items: center;
}
.conv-item:hover { background: rgba(255,255,255,.05); }
.conv-item.active { background: var(--ink-2); border-left-color: var(--accent); }
.conv-item .conv-name { font-weight: 600; font-size: .93rem; }
.conv-item .conv-preview { font-size: .8rem; opacity: .65; }
.conv-item .conv-time { font-size: .68rem; opacity: .55; font-family: var(--mono); white-space: nowrap; }
.conv-badge {
  background: var(--amber); color: #1b2733; font-size: .7rem; font-weight: 700;
  border-radius: 10px; padding: .1rem .45rem; min-width: 20px; text-align: center;
}
.conv-blocked-tag { font-size: .65rem; color: #ff8f8f; }

/* Avatar */
.avatar {
  width: 42px; height: 42px; min-width: 42px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .95rem; color: #fff; background: var(--accent);
  text-transform: uppercase;
}
.avatar-sm { width: 32px; height: 32px; min-width: 32px; font-size: .75rem; border-radius: 9px; }
.avatar-me { background: var(--amber); color: var(--ink); }

/* ---------------- AREA CHAT ---------------- */
.chat-area { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }

.announcement {
  background: var(--amber); color: #1b2733; padding: .5rem 1rem;
  font-size: .85rem; font-weight: 500; text-align: center;
}

.chat-empty {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  justify-content: center; color: var(--muted); text-align: center;
}
.chat-empty-logo {
  width: 72px; height: 72px; border-radius: 18px; background: #dbe3e9;
  color: var(--muted); font-size: 1.8rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center; margin-bottom: 1rem;
}

.chat-pane { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-header {
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem 1rem; background: var(--card);
  border-bottom: 1px solid #dde4ea;
}

.messages {
  flex: 1; min-height: 0; overflow-y: auto; padding: 1rem 1.2rem;
  display: flex; flex-direction: column; gap: .35rem;
}
.msg-day {
  align-self: center; background: rgba(23,34,46,.08); color: var(--muted);
  font-size: .72rem; padding: .15rem .7rem; border-radius: 10px; margin: .6rem 0 .3rem;
  font-family: var(--mono);
}
.msg { display: flex; max-width: 72%; gap: .5rem; align-items: flex-end; }
.msg.me { align-self: flex-end; flex-direction: row-reverse; }
.msg.other { align-self: flex-start; }

.bubble {
  padding: .5rem .75rem; border-radius: var(--radius);
  background: var(--bubble-other); box-shadow: 0 1px 1px rgba(0,0,0,.06);
  font-size: .92rem; word-break: break-word; position: relative;
}
.msg.me .bubble { background: var(--bubble-me); color: #fff; border-bottom-right-radius: 4px; }
.msg.other .bubble { border-bottom-left-radius: 4px; }
.bubble .msg-sender { font-size: .72rem; font-weight: 700; color: var(--accent); margin-bottom: .1rem; }
.bubble .msg-time {
  font-size: .64rem; opacity: .6; text-align: right; margin-top: .15rem;
  font-family: var(--mono);
}
.bubble.deleted { font-style: italic; opacity: .6; }

.msg-delete-btn {
  visibility: hidden; background: none; border: none; color: var(--muted);
  font-size: .75rem; padding: 0 .2rem; align-self: center;
}
.msg:hover .msg-delete-btn { visibility: visible; }

/* Allegati */
.file-card {
  display: flex; align-items: center; gap: .6rem; text-decoration: none;
  color: inherit; margin-top: .15rem;
}
.file-icon {
  width: 38px; height: 38px; min-width: 38px; border-radius: 10px;
  background: rgba(127,127,127,.18); display: flex; align-items: center;
  justify-content: center; font-size: 1.1rem;
}
.msg.me .file-icon { background: rgba(255,255,255,.2); }
.file-meta { font-size: .7rem; opacity: .7; font-family: var(--mono); }
.img-attach { max-width: 280px; max-height: 280px; border-radius: 10px; display: block; margin-top: .2rem; cursor: pointer; }

/* Composer */
.composer {
  display: flex; align-items: flex-end; gap: .5rem;
  padding: .6rem .9rem; background: var(--card); border-top: 1px solid #dde4ea;
  flex-shrink: 0;
}
.composer textarea { min-width: 0; }
.chat-header { flex-shrink: 0; }
.composer textarea {
  resize: none; border-radius: 12px; max-height: 140px;
  border-color: #dde4ea; font-size: .93rem;
}
.composer textarea:focus { border-color: var(--accent); box-shadow: none; }
.composer .btn-icon { color: var(--muted); font-size: 1.2rem; }
.composer .btn-accent { border-radius: 12px; padding: .45rem .9rem; }

.upload-bar { padding: .4rem 1rem .7rem; background: var(--card); }
.conv-blocked {
  background: #fdecec; color: #b23a3a; text-align: center;
  padding: .6rem; font-size: .85rem; border-top: 1px solid #f5cccc;
}

/* Selezione utenti nei modali */
.user-pick-list { max-height: 300px; overflow-y: auto; }
.user-pick {
  display: flex; align-items: center; gap: .6rem; padding: .45rem .5rem;
  border-radius: 10px; cursor: pointer;
}
.user-pick:hover { background: var(--surface); }
.user-pick.selected { background: rgba(14,124,134,.12); }
.user-pick .up-name { font-weight: 600; font-size: .9rem; }
.user-pick .up-email { font-size: .75rem; color: var(--muted); }
.selected-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip {
  background: var(--accent); color: #fff; font-size: .78rem;
  padding: .15rem .6rem; border-radius: 20px; cursor: pointer;
}
.chip::after { content: " ✕"; opacity: .7; }
.badge-groupadmin { font-size: .62rem; background: var(--amber); color: var(--ink); border-radius: 6px; padding: .05rem .35rem; font-weight: 700; }

/* Toast */
.toast-wrap { position: fixed; bottom: 1rem; right: 1rem; z-index: 2000; display: flex; flex-direction: column; gap: .5rem; }
.toast-item {
  background: var(--ink); color: #fff; padding: .6rem 1rem; border-radius: 10px;
  font-size: .85rem; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: 320px;
}
.toast-item.error { background: #a33; }

/* ---------------- MOBILE ---------------- */
@media (max-width: 767.98px) {
  .sidebar { width: 100%; min-width: 100%; }
  .chat-area { display: none; }
  .app-wrap.mobile-chat-open .sidebar { display: none; }
  .app-wrap.mobile-chat-open .chat-area { display: flex; }
  .msg { max-width: 88%; }

  .composer { gap: .25rem; padding: .45rem .5rem; }
  .composer .btn-icon { font-size: 1.05rem; padding: .3rem .35rem; }
  .composer .btn-accent { padding: .4rem .6rem; }
  .img-attach { max-width: 220px; max-height: 220px; }
  .video-attach { max-width: 100%; }
  .link-preview { max-width: 100%; }
}

/* Posizione */
.loc-card { min-width: 190px; }
.loc-head { font-weight: 600; }
.loc-coords { font-family: var(--mono, monospace); font-size: .78rem; opacity: .8; margin: .15rem 0 .3rem; }
.loc-links { display: flex; gap: .8rem; font-size: .85rem; }

/* Anteprima link */
.link-preview {
  display: flex; gap: .6rem; margin-top: .45rem; padding: .5rem .6rem;
  background: rgba(0,0,0,.06); border-left: 3px solid var(--accent);
  border-radius: 8px; text-decoration: none; color: inherit; max-width: 380px;
}
.msg.me .link-preview { background: rgba(255,255,255,.15); border-left-color: rgba(255,255,255,.7); }
.lp-img { width: 64px; height: 64px; object-fit: cover; border-radius: 6px; flex-shrink: 0; }
.lp-body { display: flex; flex-direction: column; min-width: 0; }
.lp-site { font-size: .72rem; text-transform: uppercase; letter-spacing: .03em; opacity: .7; }
.lp-title { font-weight: 600; font-size: .88rem; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.lp-desc { font-size: .8rem; opacity: .8; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }

/* Banner realtime assente */
.rt-warn {
  background: #7a4a00; color: #ffe2b0; font-size: .82rem;
  padding: .4rem .9rem; text-align: center;
}

/* Indicatore "sta scrivendo…" */
.typing-indicator { color: var(--accent); font-style: italic; }
.typing-indicator::after {
  content: ''; display: inline-block; width: 1em; text-align: left;
  animation: typing-dots 1.2s steps(4, end) infinite;
}
@keyframes typing-dots {
  0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; }
}

/* Barra registrazione */
.rec-bar {
  display: flex; align-items: center; gap: .7rem;
  background: var(--ink); color: #fff; padding: .55rem .9rem;
}
.rec-dot {
  width: 12px; height: 12px; border-radius: 50%; background: #e14b4b;
  animation: rec-pulse 1s ease-in-out infinite;
}
@keyframes rec-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .25; } }
.rec-timer { font-family: var(--mono, monospace); font-size: .85rem; }
.rec-bar #recLabel { flex: 1; font-size: .88rem; }

/* Player audio/video */
.audio-attach { width: 260px; max-width: 100%; display: block; }
.video-attach { max-width: 320px; width: 100%; border-radius: 10px; display: block; background: #000; }
.vid-preview { width: 100%; border-radius: 10px; background: #000; aspect-ratio: 4/3; object-fit: cover; }
