/* Tema scuro unico per tutte le pagine del prototipo. */
:root {
  color-scheme: dark;
  --bg: #121417;
  --panel: #1b1f24;
  --border: #2e343c;
  --text: #e6e8eb;
  --muted: #9aa3ad;
  --accent: #4f9cf7;
  --button: #2a3038;
  --button-hover: #353c46;
  --in: #222830;
  --out: #1f4d36;
  --ok: #5fd38d;
  --bad: #ff6b6b;
  --warn-bg: #3a2f12;
  --warn-border: #8a6d1f;
  --bad-bg: #3d1a1d;
  --code-bg: #0d0f12;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, sans-serif;
  max-width: 720px;
  margin: 0 auto;
  padding: 12px;
}

a { color: var(--accent); }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.9em; }
.ok { color: var(--ok); }
.bad { color: var(--bad); font-weight: bold; }

section { background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 10px; margin: 10px 0; }

button {
  background: var(--button);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px 12px;
  margin: 2px;
  min-height: 40px;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--button-hover); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

a.button {
  display: inline-block;
  background: var(--button);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  margin: 2px;
  text-decoration: none;
}
a.button:hover { background: var(--button-hover); }

input, select, textarea {
  background: var(--code-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  min-height: 24px;
}
input::placeholder { color: var(--muted); }

code { word-break: break-all; color: var(--text); }
pre { white-space: pre-wrap; background: var(--code-bg); border: 1px solid var(--border); padding: 8px; border-radius: 6px; }

.row { display: flex; gap: 6px; }
.row input, .row textarea { flex: 1; }
textarea { font: inherit; resize: vertical; }

#messages { height: 45vh; overflow-y: auto; border: 1px solid var(--border); padding: 6px; background: var(--code-bg); border-radius: 6px; }
.msg { margin: 4px 0; padding: 6px 8px; border-radius: 6px; max-width: 80%; word-wrap: break-word; white-space: pre-wrap; }
.in { background: var(--in); border: 1px solid var(--border); }
.out { background: var(--out); margin-left: auto; }

/* Codice di sicurezza: 4 gruppi affiancati (2 per riga su telefono), ogni carattere con la parola NATO accanto. */
.safety { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0; }
.safety-group { background: var(--code-bg); border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; min-width: 130px; }
.safety-group-title { color: var(--muted); font-size: 0.75em; margin-bottom: 2px; }
.safety-row { display: flex; align-items: baseline; gap: 8px; line-height: 1.6; }
.safety-char { font-family: ui-monospace, Consolas, monospace; font-weight: bold; font-size: 1.35em; width: 1.2em; text-align: center; }
.safety-word { color: var(--muted); }

.push { margin: 10px 0; padding: 8px 0; border-top: 1px solid var(--border); }

/* Accesso di Claude: rosso se spento, verde se attivo */
.access { font-size: 1.1em; padding: 10px; border-radius: 6px; margin: 6px 0; background: var(--bad-bg); border: 1px solid var(--bad); }
.access.on { background: #173a26; border-color: var(--ok); }

.verify { background: var(--warn-bg); border: 1px solid var(--warn-border); border-radius: 6px; padding: 8px; margin: 8px 0; }
.verify.changed { background: var(--bad-bg); border-color: var(--bad); }

/* ---------- App: schema WhatsApp (0.5.0) ----------
   PC: barra verticale | elenco | chat. Telefono (< 760 px): elenco OPPURE chat a schermo intero,
   barra in basso solo nell'elenco, "←" per tornare indietro. */
#app {
  position: fixed; inset: 0;
  display: grid; grid-template-columns: 64px 360px minmax(0, 1fr);
  background: var(--bg);
}
#app h2 { margin: 0; font-size: 1.3em; }
#app h3 { margin: 18px 0 6px; font-size: 1em; color: var(--muted); }
.grow { flex: 1; }

#rail {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 10px 0; background: var(--panel); border-right: 1px solid var(--border);
}
.rail-btn {
  position: relative; width: 46px; height: 46px; padding: 0; margin: 0;
  font-size: 1.35em; border-radius: 50%; background: transparent; border: none;
}
.rail-btn.active { background: var(--button-hover); }
.badge {
  position: absolute; top: -2px; right: -4px; min-width: 18px; padding: 1px 5px; border-radius: 10px;
  background: #25a35a; color: #fff; font-size: 0.55em; font-weight: bold; line-height: 16px;
}
.dot { position: absolute; bottom: 4px; right: 4px; width: 11px; height: 11px; border-radius: 50%; border: 2px solid var(--panel); }
.dot.on { background: var(--ok); }
.dot.off { background: var(--bad); }

#sidebar { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); background: var(--bg); }
.panel { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.panel-body { overflow-y: auto; padding: 4px 14px 20px; }
.bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; min-height: 52px; box-sizing: border-box; }
.fab { background: #25a35a; border: none; color: #fff; border-radius: 12px; min-width: 46px; font-size: 1.05em; }
.fab:hover:not(:disabled) { background: #2bb866; }
.notice { margin: 4px 12px 8px; padding: 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
.bad-notice { border-color: var(--bad); background: var(--bad-bg); }
.search { padding: 0 12px 6px; }
.search input { width: 100%; box-sizing: border-box; border-radius: 20px; padding: 9px 14px; }
.chips { padding: 0 12px 6px; }
.chip { border-radius: 16px; min-height: 32px; padding: 4px 12px; }
.chip.active { background: #1f4d36; border-color: #25a35a; }

.list { overflow-y: auto; flex: 1; }
.contact { display: flex; align-items: center; gap: 12px; padding: 10px 14px; cursor: pointer; border-radius: 10px; margin: 0 6px; }
.contact:hover { background: var(--panel); }
.contact.active { background: var(--button); }
.contact-main { flex: 1; min-width: 0; }
.contact-top, .contact-bottom { display: flex; align-items: center; gap: 6px; }
.contact-name { flex: 1; font-size: 1.02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact-time { color: var(--muted); font-size: 0.78em; }
.contact.unread .contact-time { color: #25a35a; font-weight: bold; }
.contact-preview { flex: 1; color: var(--muted); font-size: 0.9em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact.unread .contact-preview { color: var(--text); }
.count { background: #25a35a; color: #fff; border-radius: 10px; min-width: 20px; padding: 1px 6px; font-size: 0.78em; font-weight: bold; text-align: center; }
.list-empty { padding: 20px 14px; }

.avatar {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 46px; height: 46px; border-radius: 50%; color: #fff; font-weight: bold; font-size: 1.2em;
  background: #4a5568;
}
.avatar.small { width: 34px; height: 34px; font-size: 0.95em; }

#chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--code-bg); }
.empty { margin: auto; text-align: center; max-width: 420px; padding: 20px; }
.empty-lock { font-size: 3em; }
#chat-view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-head { background: var(--panel); border-bottom: 1px solid var(--border); }
.chat-title { min-width: 0; }
.chat-title > div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon {
  background: transparent; border: none; font-size: 1.3em; min-height: 40px; min-width: 40px;
  padding: 4px; margin: 0; text-decoration: none; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%;
}
.icon:hover { background: var(--button-hover); }
.back { display: none; }
#chat-view .verify { margin: 8px; max-height: 55%; overflow-y: auto; flex: none; }

#messages { flex: 1; height: auto; border: none; border-radius: 0; padding: 10px 6%; }
.msg { position: relative; max-width: 75%; padding: 6px 9px 5px; border-radius: 8px; }
.msg .time { float: right; margin: 6px 0 -4px 10px; font-size: 0.7em; color: var(--muted); }
.out .time { color: #9fd4b5; }
.day { text-align: center; margin: 10px 0; }
.day span { background: var(--panel); color: var(--muted); font-size: 0.78em; padding: 4px 10px; border-radius: 8px; }

.hint { padding: 0 12px; font-size: 0.78em; min-height: 0; }
.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 10px; background: var(--panel); }
.composer textarea { flex: 1; resize: none; border-radius: 20px; padding: 10px 14px; max-height: 140px; min-height: 22px; }
.send { background: #25a35a; border: none; color: #fff; border-radius: 50%; width: 44px; height: 44px; padding: 0; font-size: 1.2em; }
.send:hover:not(:disabled) { background: #2bb866; }

#toast {
  position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); z-index: 10;
  background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; max-width: 90vw;
}

/* Telefono: una schermata alla volta, come WhatsApp */
@media (max-width: 760px) {
  #app { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  #sidebar { grid-row: 1; border-right: none; }
  #rail {
    grid-row: 2; flex-direction: row; justify-content: space-around; padding: 4px 0 calc(4px + env(safe-area-inset-bottom));
    border-right: none; border-top: 1px solid var(--border);
  }
  #rail .grow { display: none; }
  #chat { grid-row: 1; }
  #app:not(.in-chat) #chat { display: none; }
  #app.in-chat #sidebar, #app.in-chat #rail { display: none; }
  #app.in-chat { grid-template-rows: minmax(0, 1fr); }
  .back { display: inline-flex; }
  #messages { padding: 8px; }
  .msg { max-width: 85%; }
}
.notice { position: relative; }
.notice .close { position: absolute; top: 4px; right: 4px; font-size: 1em; min-height: 32px; min-width: 32px; }

/* Selettore emoji 😊 (0.5.8): pannello sopra la barra del messaggio */
#btn-emoji.active { background: var(--button-hover); }
.emoji-panel { display: flex; flex-direction: column; height: 300px; background: var(--panel); border-top: 1px solid var(--border); }
.emoji-search { margin: 8px 10px 4px; border-radius: 20px; padding: 8px 14px; }
.emoji-tabs { display: flex; overflow-x: auto; padding: 0 6px; border-bottom: 1px solid var(--border); flex: none; }
.emoji-tabs button { background: transparent; border: none; border-bottom: 3px solid transparent; border-radius: 0; font-size: 1.25em; min-height: 40px; min-width: 42px; margin: 0; }
.emoji-tabs button.active { border-bottom-color: #25a35a; }
.emoji-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); align-content: start; padding: 6px; }
.emoji-grid button, .emoji-tabs button, #btn-emoji {
  font-family: "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}
.emoji-grid button { background: transparent; border: none; font-size: 1.7em; min-height: 44px; padding: 2px; margin: 0; border-radius: 8px; }
.emoji-grid button:hover { background: var(--button-hover); }
.emoji-empty { grid-column: 1 / -1; padding: 16px; }
@media (max-width: 760px) { .emoji-panel { height: 280px; } }

/* Cancellazione (0.5.9): messaggio eliminato, freccetta del menu sul fumetto, menu dal basso */
.msg.deleted { font-style: italic; color: var(--muted); }
.msg-more {
  display: none; position: absolute; top: 2px; right: 2px; min-height: 0; min-width: 0; width: 24px; height: 22px;
  padding: 0; margin: 0; border: none; border-radius: 6px; background: rgba(0, 0, 0, 0.35); color: var(--text); font-size: 0.85em;
}
.msg:hover .msg-more { display: block; }
@media (pointer: coarse) {
  .msg:hover .msg-more { display: none; }           /* sul telefono si tiene premuto il fumetto */
  .msg { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }  /* il testo si copia dal menu */
}
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0, 0, 0, 0.5); display: flex; align-items: flex-end; justify-content: center; }
.sheet-box {
  width: 100%; max-width: 420px; background: var(--panel); border: 1px solid var(--border); border-radius: 14px 14px 0 0;
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 4px;
}
@media (min-width: 761px) { .sheet { align-items: center; } .sheet-box { border-radius: 14px; } }
.sheet-title { color: var(--muted); font-size: 0.9em; padding: 4px 8px 8px; }
.sheet-box button { text-align: left; width: 100%; margin: 0; min-height: 46px; font-size: 1em; }
.sheet-box button.danger { color: var(--bad); }
#sheet-cancel { text-align: center; margin-top: 6px; }

/* 0.5.11: spunte (✓ inviato, ✓✓ blu letto) e avviso "chiave mancante" semplice */
.ticks { margin-left: 4px; letter-spacing: -3px; }
.ticks.seen { color: #53bdeb; }
.contact-preview .ticks { margin: 0 2px 0 0; }
#key-missing b { display: block; margin-bottom: 4px; }
#key-missing p { margin: 4px 0 8px; }
#key-missing button { margin: 2px 4px 2px 0; }
#key-missing .muted { font-size: 0.85em; }

/* 0.5.12: pagina d'ingresso con un solo pulsante grande; "Crea un account" come link */
#auth button.big { display: block; width: 100%; max-width: 360px; min-height: 52px; font-size: 1.1em; margin: 16px 0 8px; background: #1f6f4a; }
#auth button.big:hover:not(:disabled) { background: #26855a; }
button.link { background: none; border: none; color: var(--accent); text-decoration: underline; padding: 0; min-height: 0; margin: 0; }
button.link:hover:not(:disabled) { background: none; }

/* 0.5.13: selezione di più messaggi come WhatsApp (casella a sinistra di ogni riga, barra in basso) */
.msg-row { display: flex; align-items: center; gap: 12px; border-radius: 6px; }
.msg-row .msg { min-width: 0; }
.msg-row .check { display: none; flex: none; width: 20px; height: 20px; border: 2px solid var(--muted); border-radius: 4px; }
#messages.selecting .msg-row { cursor: pointer; }
#messages.selecting .msg-row .check { display: block; }
#messages.selecting .msg-more { display: none !important; }
.msg-row.picked { background: rgba(255, 255, 255, 0.06); }
.msg-row.picked .check { background: #25a35a; border-color: #25a35a; position: relative; }
.msg-row.picked .check::after { content: "✓"; position: absolute; inset: 0; color: #fff; font-size: 15px; line-height: 20px; text-align: center; font-weight: bold; }
.select-bar { align-items: center; min-height: 50px; }
.select-bar #select-count { font-size: 1.05em; }

/* 0.5.14: connettore creato ma mai usato da Claude */
#connected-as.waiting { border: 1px solid var(--warn-border); background: var(--warn-bg); border-radius: 8px; padding: 8px; }

/* 0.5.15: contatti bloccati */
.blocked-line { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--text); margin: 4px 0; }
#blocked-bar #blocked-text { color: var(--muted); }

/* 0.5.17: contatto silenziato */
.muted-mark { margin-left: 4px; font-size: 0.85em; opacity: 0.8; }
.count.quiet { background: var(--muted); }

/* 0.5.18: cerca nella chat */
.chat-search { display: flex; align-items: center; gap: 6px; padding: 6px 10px; background: var(--panel); border-bottom: 1px solid var(--border); }
.chat-search input { flex: 1; min-width: 0; border-radius: 18px; padding: 8px 12px; }
.chat-search #chat-search-count { font-size: 0.85em; white-space: nowrap; }
.msg mark { background: #e2b93b; color: #111; border-radius: 3px; padding: 0 1px; }
.msg-row.hit-now .msg { outline: 2px solid #e2b93b; }

/* Impostazioni (0.5.19): un riquadro arrotondato per argomento, che si apre e si chiude */
details.card { border: 1px solid var(--border); border-radius: 12px; background: var(--panel); margin: 10px 0; padding: 0 12px; }
details.card > summary { list-style: none; cursor: pointer; font-weight: bold; padding: 12px 0; display: flex; align-items: center; }
details.card > summary::-webkit-details-marker { display: none; }
details.card > summary::after { content: "›"; margin-left: auto; color: var(--muted); font-size: 1.3em; transition: transform 0.15s; }
details.card[open] > summary::after { transform: rotate(90deg); }
details.card[open] { padding-bottom: 12px; }
details.card[open] > summary { border-bottom: 1px solid var(--border); margin-bottom: 8px; }
details.card .notice { margin: 8px 0; }

/* AI scelta (0.5.21): logo nella barra a sinistra, nel pulsante "Apri con l'AI" e nel menu */
.ai-icon { width: 1.15em; height: 1.15em; vertical-align: middle; }
.rail-btn .ai-icon { width: 26px; height: 26px; }
.ai-btn { display: inline-flex; align-items: center; gap: 6px; border-radius: 18px; padding: 4px 12px; min-height: 36px;
  white-space: nowrap; }
.ai-btn .ai-icon { width: 20px; height: 20px; }
.sheet-box .ai-icon { width: 22px; height: 22px; margin-right: 10px; }
.sheet-box button.picked-ai { font-weight: bold; }
/* Telefono: solo il logo, il nome sta nel menu */
@media (max-width: 760px) {
  .ai-btn { background: transparent; border: none; padding: 4px; min-width: 40px; justify-content: center; }
  .ai-btn .ai-label { display: none; }
  .ai-btn .ai-icon { width: 24px; height: 24px; }
}

/* Logo (0.5.26): nella pagina d'ingresso accanto al nome, e al posto del 🔒 nella chat vuota */
.brand { display: flex; align-items: center; gap: 14px; }
.brand h2 { margin: 0; }
.logo { width: 56px; height: 56px; border-radius: 22%; flex: none; }
.big-logo { width: 96px; height: 96px; }
