*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

/* Palette allineata a Friend Post (style.css): #fff, testo #232323/#333, CTA #0C5ADB, hover #00247E */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e6ec;
  --text: #232323;
  --muted: #616161;
  --accent: #0c5adb;
  --accent-dim: #00247e;
  --accent-soft: rgba(12, 90, 219, 0.1);
  --accent-soft-strong: rgba(12, 90, 219, 0.18);
  --bot-bubble: #eef1f6;
  --user-bubble: #e8f1ff;
  --radius: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --widget-shadow: 0 12px 40px rgba(15, 35, 95, 0.12);
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
}

.page {
  max-width: 42rem;
  margin: 0 auto;
  padding: 2rem 1.25rem;
}

.page__title {
  margin: 0 0 0.75rem;
  font-size: 1.5rem;
  font-weight: 600;
}

.page__text {
  margin: 0;
  line-height: 1.55;
  color: var(--muted);
}

.page__lang {
  margin-bottom: 1.5rem;
  padding: 0.85rem 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.page__lang-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  margin-bottom: 0.4rem;
}

.page__lang-select {
  width: 100%;
  max-width: 280px;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.95rem;
  cursor: pointer;
}

.page__lang-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.page__lang-hint {
  margin: 0.6rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

.page__lang-hint code {
  font-size: 0.85em;
  padding: 0.1em 0.35em;
  background: rgba(0, 36, 126, 0.08);
  color: var(--accent-dim);
  border-radius: 4px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Widget fisso: angolo in basso a destra */
.chat-widget {
  position: fixed;
  z-index: 9999;
  bottom: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.75rem;
  font-family: var(--font);
}

.chat-widget__panel {
  width: 560px;
  height: 880px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--widget-shadow);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.chat-widget__panel[hidden] {
  display: none !important;
}

.chat-widget__fab {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 18px rgba(12, 90, 219, 0.35);
  transition: transform 0.15s ease, background 0.15s ease;
}

.chat-widget__fab:hover {
  background: var(--accent-dim);
  transform: scale(1.05);
}

.chat-widget__fab:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.chat-widget__fab-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.chat-widget__close {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  margin: 0;
  padding: 0;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-widget__close:hover {
  color: var(--text);
  background: rgba(0, 36, 126, 0.08);
}

.app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: 1rem;
}

.app--widget {
  max-width: none;
  min-height: 0;
  min-width: 0;
  flex: 1;
  height: 100%;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
}

.app__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.85rem 0.75rem 0.65rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.app--widget .app__header {
  padding-bottom: 0;
  border-bottom: none;
  flex: 1;
  min-width: 0;
}

.app__header {
  padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--border);
}

.app__title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.app__subtitle {
  margin: 0.3rem 0 0;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}

.app--widget .chat {
  flex: 1;
  min-height: 0;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 0.65rem 0.75rem;
}

.chat {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.msg {
  max-width: 92%;
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius);
  line-height: 1.45;
  font-size: 0.9rem;
  animation: fadeIn 0.2s ease;
  overflow-wrap: anywhere;
  word-break: break-word;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg--bot {
  align-self: flex-start;
  background: var(--bot-bubble);
  border: 1px solid var(--border);
}

.msg--rich a {
  color: var(--accent);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg--rich a:hover {
  color: var(--accent-dim);
}

.msg--user {
  align-self: flex-end;
  background: var(--user-bubble);
  border: 1px solid rgba(12, 90, 219, 0.25);
}

/* Riga bottoni sotto una domanda a scelta (senza box messaggio). */
.msg--choices {
  padding-top: 0.35rem;
}

.chat-choices {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
}

.chat-choice-btn {
  padding: 0.5rem 0.85rem;
  border-radius: var(--radius);
  border: 1px solid rgba(12, 90, 219, 0.35);
  background: var(--accent-soft);
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.chat-choice-btn:hover:not(:disabled) {
  background: var(--accent-soft-strong);
  border-color: rgba(12, 90, 219, 0.55);
}

.chat-choice-btn:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.chat-choice-btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.app--widget .composer {
  padding: 0.65rem 0.75rem 0.85rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  min-width: 0;
  box-sizing: border-box;
}

.composer {
  display: flex;
  gap: 0.5rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  width: 100%;
  max-width: 100%;
}

/* Nasconde input + Invia nelle schermate solo a scelta (gestito da impostaComposer in chatbot.js). */
.composer.composer--nascosto {
  display: none !important;
}

.composer__input {
  flex: 1 1 0;
  min-width: 0;
  width: 0;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
}

.composer__input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.composer__send {
  flex-shrink: 0;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius);
  border: none;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
}

.composer__send:hover {
  background: var(--accent-dim);
}

.composer__send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (max-width: 600px) {
  .chat-widget {
    bottom: 12px;
    right: 12px;
  }

  .chat-widget__panel {
    width: 300px;
    height: 640px;
  }

  .app--widget .composer {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .app--widget .composer__input {
    width: 100%;
    flex: none;
  }

  .app--widget .composer__send {
    width: 100%;
  }
}
