/* Sicurnet AI · iframe rapportino asset · mobile-first.
 *
 * Target: Samsung A32-A34 / Android 13 Chrome (CLAUDE.md). Layout a colonna
 * singola, tutta altezza, touch target grandi, niente hover-dependent. Montato
 * come iframe full-viewport dentro la PWA. */

:root {
  --blu: #1F3A5F;
  --blu-scuro: #16293f;
  --verde: #1f7a4d;
  --rosso: #b3261e;
  --giallo: #8a6d00;
  --grigio: #6b7280;
  --bg: #f4f6f9;
  --bordo: #d9dee6;
  --testo: #1a1f29;
  --color-text-muted: var(--grigio);
  --color-border: var(--bordo);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

/* L'attributo `hidden` deve sempre vincere: senza !important una regola
   d'autore con `display:flex/grid` (overlay, banner, controls, dialog) lo
   annulla (stessa specificità, arriva dopo) e l'elemento resta visibile. */
[hidden] { display: none !important; }

html, body { height: 100%; margin: 0; }

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--testo);
  font-size: 16px;
  line-height: 1.4;
  overscroll-behavior: none;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--bg);
}

/* ============ Topbar (contesto compatto) ============ */

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.9rem;
  background: var(--blu);
  color: #fff;
  position: sticky;
  top: 0;
  z-index: 5;
}

.topbar__ctx { flex: 1 1 auto; min-width: 0; }
.topbar__title { font-weight: 700; font-size: 1rem; }

.ctx-line {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ctx-line--main { font-weight: 700; font-size: 0.95rem; }
.ctx-line--sub { font-size: 0.78rem; opacity: 0.85; }

.pill {
  flex: 0 0 auto;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  color: #fff;
  white-space: nowrap;
}
.pill--ready, .pill--recording { background: var(--verde); }
.pill--assistant_speaking { background: #2f6fb0; }
.pill--opening, .pill--connecting_ws, .pill--closing { background: var(--giallo); }
.pill--error { background: var(--rosso); }
.pill--closed { background: rgba(255, 255, 255, 0.28); }

/* ============ Dialogo / trascrizione ============ */

.dialog {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.dialog__empty {
  margin: auto;
  color: var(--grigio);
  font-size: 0.9rem;
  text-align: center;
}

.bubble {
  max-width: 88%;
  padding: 0.55rem 0.75rem;
  border-radius: 14px;
  font-size: 0.95rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}
.bubble--assistant { align-self: flex-start; background: #fff; border: 1px solid var(--bordo); border-bottom-left-radius: 4px; }
.bubble--user { align-self: flex-end; background: var(--blu); color: #fff; border-bottom-right-radius: 4px; }
.bubble--draft { opacity: 0.65; }
.bubble__role { font-size: 0.66rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; opacity: 0.7; margin-bottom: 0.15rem; }
.bubble__text { white-space: pre-wrap; word-break: break-word; }

/* ============ Controlli (bottom bar) ============ */

.controls {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.7rem 0.9rem calc(0.7rem + var(--safe-bottom));
  background: #fff;
  border-top: 1px solid var(--bordo);
}

.mic {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  width: 100%;
  min-height: 64px;
  border: none;
  border-radius: 14px;
  background: var(--verde);
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, transform 0.05s;
}
.mic:active { transform: scale(0.99); }
.mic[disabled] { background: #c4cad3; color: #fff; cursor: not-allowed; }
.mic--muted { background: var(--grigio); }
.mic--speaking { background: #2f6fb0; }
.mic__icon { font-size: 1.4rem; line-height: 1; }

.controls__row { display: flex; align-items: stretch; gap: 0.5rem; }

.mic-select {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  min-width: 0;
  padding: 0 0.6rem;
  border: 1px solid var(--bordo);
  border-radius: 10px;
  background: #fff;
}
.mic-select__icon { flex: 0 0 auto; }
.mic-select select {
  flex: 1 1 auto;
  min-width: 0;
  border: none;
  background: transparent;
  font: inherit;
  font-size: 0.85rem;
  padding: 0.55rem 0;
  color: var(--testo);
}
.mic-select select:focus { outline: none; }

.btn-close {
  flex: 0 0 auto;
  min-height: 48px;
  padding: 0 1.1rem;
  border: 1px solid var(--blu);
  border-radius: 10px;
  background: #fff;
  color: var(--blu);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
}
.btn-close[disabled] { opacity: 0.4; cursor: not-allowed; }

/* ============ Output di chiusura (RapportinoAsset) ============ */

.output {
  flex: 1 1 auto;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 0.9rem;
}

.output__meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--verde);
  margin-bottom: 0.7rem;
}

.btn-mini {
  font: inherit;
  font-size: 0.78rem;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--bordo);
  border-radius: 8px;
  background: #fff;
  color: var(--blu);
  cursor: pointer;
}

.cards { display: flex; flex-direction: column; gap: 0.7rem; }

.card {
  background: #fff;
  border: 1px solid var(--bordo);
  border-radius: 12px;
  padding: 0.8rem 0.9rem;
}
.card__title { margin: 0 0 0.5rem; font-size: 0.95rem; color: var(--blu); }
.card__empty { margin: 0; color: var(--grigio); font-size: 0.88rem; }

.card__dl { display: grid; grid-template-columns: max-content 1fr; gap: 0.2rem 0.7rem; margin: 0; font-size: 0.88rem; }
.card__dl dt { color: var(--grigio); }
.card__dl dd { margin: 0; word-break: break-word; }
.card__dl--inset { margin-top: 0.4rem; padding-top: 0.4rem; border-top: 1px dashed var(--bordo); }

.istruzione { padding: 0.55rem 0; border-top: 1px solid #eef1f5; }
.istruzione:first-of-type { border-top: none; }
.istruzione__head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.25rem; }
.istruzione__desc { font-size: 0.92rem; }

.badge {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  color: #fff;
}
.badge--positivo { background: var(--verde); }
.badge--negativo { background: var(--rosso); }

/* ============ Asset done bar (Termina) ============ */

.asset-done-bar {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-top: 1rem;
  padding: 0.9rem;
  border: 1px solid #cfe3d6;
  border-radius: 12px;
  background: #f0f8f2;
}
.asset-done-bar__note { font-size: 0.85rem; color: var(--grigio); }
.btn-termina {
  width: 100%;
  min-height: 56px;
  border: none;
  border-radius: 12px;
  background: var(--blu);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
}
.btn-termina:active { transform: scale(0.99); }

/* ============ Overlay (spinner / stati bloccanti) ============ */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(244, 246, 249, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 1.5rem;
}
.overlay__box { text-align: center; }
.overlay__text { margin: 0.9rem 0 0; font-size: 0.95rem; color: var(--testo); }

.overlay__action {
  margin: 1.1rem auto 0;
  display: block;
  min-height: 64px;
  padding: 0 1.6rem;
  border: none;
  border-radius: 14px;
  background: var(--blu);
  color: #fff;
  font: inherit;
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
}
.overlay__action:active { transform: scale(0.99); }

.spinner {
  width: 42px;
  height: 42px;
  margin: 0 auto;
  border: 4px solid var(--bordo);
  border-top-color: var(--blu);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ============ Banner (errori non bloccanti / azioni) ============ */

.banner {
  position: fixed;
  left: 0.7rem;
  right: 0.7rem;
  bottom: calc(0.7rem + var(--safe-bottom));
  z-index: 25;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.9rem 1rem;
  border-radius: 12px;
  background: var(--blu-scuro);
  color: #fff;
  font-size: 0.9rem;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.25);
}
.banner--warn { background: #8a5a00; }
.banner--error { background: var(--rosso); }
.banner__actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.banner__btn {
  font: inherit;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 0.5rem 0.9rem;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, 0.6);
  background: transparent;
  color: #fff;
  cursor: pointer;
}
.banner__btn--primary { background: #fff; color: var(--blu-scuro); border-color: #fff; }
