/**
 * wa-messaggi.css — Chat cliente web_app (R26e)
 * Mobile-first, palette Template Base 0.1 (--wa-color-*).
 */

/* -------------------------------------------------------- */
/* Pagina                                                   */
/* -------------------------------------------------------- */

body#wa-messaggi {
  background: var(--wa-color-bg);
}

.wa-messages-container {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 12px 16px;
  box-sizing: border-box;
}

@media (min-width: 992px) {
  .wa-messages-container {
    padding: 24px 16px 32px;
  }
}

body.wa-use-bottombar #wa-messaggi .wa-messages-container {
  padding-bottom: calc(var(--wa-mobile-bottombar-h, 64px) + 12px + env(safe-area-inset-bottom, 0px));
}

/* Footer mobile: regola globale in css_style_mod.css (solo homepage). */

.wa-messages-header {
  text-align: center;
  margin-bottom: 14px;
}

.wa-messages-title {
  font-size: 1.35rem;
  font-weight: 700;
  margin: 0 0 4px;
  line-height: 1.2;
  color: var(--wa-color-text);
}

@media (min-width: 992px) {
  .wa-messages-title {
    font-size: 1.55rem;
  }
}

.wa-messages-lead {
  font-size: 0.9rem;
  color: var(--wa-color-muted);
  margin: 0 auto;
  max-width: 520px;
  line-height: 1.45;
}

/* -------------------------------------------------------- */
/* Guest                                                    */
/* -------------------------------------------------------- */

.wa-messages-guest {
  background: var(--wa-card-bg, var(--wa-color-surface));
  color: var(--wa-text-color, var(--wa-color-text));
  border: 1px solid var(--wa-card-border, var(--wa-color-border));
  border-radius: var(--wa-card-radius, 14px);
  padding: clamp(24px, 7vw, 42px) clamp(18px, 6vw, 36px);
  text-align: center;
  box-shadow: var(--wa-shadow-sm);
}

.wa-messages-guest__icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 18px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  font-size: 1.65rem;
  color: var(--wa-color-primary);
  background: var(--wa-color-primary-soft, var(--wa-color-surface-soft));
}

.wa-messages-guest__title {
  font-size: clamp(1.35rem, 5vw, 1.75rem);
  font-weight: var(--wa-heading-weight, 750);
  line-height: 1.2;
  margin: 0 0 10px;
  color: var(--wa-heading-color, var(--wa-color-text));
}

.wa-messages-guest__lead {
  color: var(--wa-muted-color, var(--wa-color-muted));
  margin: 0 auto 24px;
  max-width: 460px;
  font-size: 1rem;
  line-height: 1.55;
}

.wa-messages-guest__actions {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 12px;
  width: min(100%, 360px);
  margin: 0 auto;
}

.wa-messages-guest__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 50px;
  padding: 10px 20px;
  border-radius: var(--wa-button-radius, 999px);
  font-weight: var(--wa-button-weight, 700);
  font-size: 1rem;
  line-height: 1.2;
  gap: 9px;
  box-sizing: border-box;
  text-decoration: none;
  border: 1px solid transparent;
  transition: filter 0.15s, transform 0.05s;
}

.wa-messages-guest__btn:active {
  transform: translateY(1px);
}

.wa-messages-guest__btn--primary {
  background: var(--wa-button-primary-bg, var(--wa-color-primary));
  color: var(--wa-messages-primary-text, var(--wa-color-bg, #111111)) !important;
  -webkit-text-fill-color: currentColor;
  text-shadow: none;
  border-color: var(--wa-button-primary-bg, var(--wa-color-primary));
}

.wa-messages-guest__btn--primary > i,
.wa-messages-guest__btn--primary > span {
  color: inherit !important;
  opacity: 1 !important;
  visibility: visible !important;
}

.wa-messages-guest__btn--secondary {
  background: var(--wa-button-secondary-bg, var(--wa-secondary-bg, var(--wa-color-surface)));
  color: var(--wa-button-secondary-color, var(--wa-secondary-fg, var(--wa-color-text)));
  border-color: var(--wa-button-secondary-border, var(--wa-secondary-border, var(--wa-color-border)));
}

.wa-messages-guest__btn--tertiary {
  min-height: 44px;
  background: transparent;
  color: var(--wa-muted-color, var(--wa-color-muted));
  border-color: transparent;
}

.wa-messages-guest__btn:focus-visible {
  outline: 3px solid var(--wa-focus-ring, var(--wa-color-primary-soft));
  outline-offset: 3px;
}

@media (min-width: 640px) {
  .wa-messages-guest__actions {
    width: min(100%, 420px);
  }
}

/* -------------------------------------------------------- */
/* Card chat                                                */
/* -------------------------------------------------------- */

.wa-chat-card {
  background: var(--wa-color-surface);
  border: 1px solid var(--wa-color-border);
  border-radius: var(--wa-card-radius, 14px);
  box-shadow: var(--wa-shadow-sm);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: min(68vh, calc(100dvh - 200px));
  max-height: calc(100dvh - 140px);
}

@media (min-width: 992px) {
  .wa-chat-card {
    min-height: 520px;
    max-height: 680px;
  }
}

.wa-chat-card__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--wa-color-border);
  background: var(--wa-color-surface-soft, var(--wa-color-surface));
  flex-shrink: 0;
}

.wa-chat-card__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--wa-color-primary-soft, var(--wa-color-accent-soft));
  color: var(--wa-color-primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 1rem;
  flex-shrink: 0;
}

.wa-chat-card__heading {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
  gap: 2px;
}

.wa-chat-card__hide-btn {
  flex-shrink: 0;
  margin-left: auto;
  border: none;
  background: transparent;
  color: var(--wa-color-muted);
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 8px;
  line-height: 1;
}

.wa-chat-card__hide-btn:focus-visible {
  color: var(--wa-color-text);
  background: var(--wa-color-surface-strong, rgba(0, 0, 0, 0.04));
}
.wa-chat-card__hide-btn:active {
  transform: scale(0.96);
}

.wa-chat-card__title {
  font-weight: 700;
  font-size: 0.98rem;
  color: var(--wa-color-text);
  margin: 0;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  white-space: normal;
}

.wa-chat-card__subtitle {
  font-size: 0.78rem;
  color: var(--wa-color-muted);
  margin: 0;
  line-height: 1.3;
}

/* -------------------------------------------------------- */
/* Push compatto (R29a) + sheet dettagli                      */
/* -------------------------------------------------------- */

.wa-push-compact {
  margin: 0;
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--wa-color-border);
  background: var(--wa-color-surface);
  flex-shrink: 0;
  max-height: 110px;
}

.wa-push-compact[hidden],
.wa-push-compact[aria-hidden='true'] {
  display: none !important;
}

.wa-push-compact__row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.wa-push-compact__icon {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--wa-color-primary-soft);
  color: var(--wa-color-primary);
  font-size: 0.82rem;
}

.wa-push-compact__text {
  min-width: 0;
  flex: 1 1 auto;
}

.wa-push-compact__title {
  font-size: 0.84rem;
  font-weight: 700;
  margin: 0;
  line-height: 1.2;
  color: var(--wa-color-text);
}

.wa-push-compact__lead {
  font-size: 0.74rem;
  color: var(--wa-color-muted);
  margin: 2px 0 0;
  line-height: 1.3;
}

.wa-push-compact__status {
  color: var(--wa-color-primary);
  margin: 2px 0 0;
  font-size: 0.74rem;
  line-height: 1.25;
}

.wa-push-compact__status[hidden] {
  display: none !important;
}

.wa-push-compact__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  margin-top: 8px;
}

.wa-push-compact__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 32px;
  line-height: 1.1;
}

.wa-push-compact__btn--primary {
  border: none;
  background: var(--wa-color-primary);
  color: var(--wa-color-primary-contrast);
}

.wa-push-compact__btn--ghost {
  background: var(--wa-color-surface-soft);
  color: var(--wa-color-primary);
  border: 1px solid var(--wa-color-border);
}

/* Bottom sheet push — visibile anche su desktop (override menu-only) */
.wa-push-sheet.wa-bottom-sheet {
  z-index: 1090;
}

@media (min-width: 992px) {
  .wa-push-sheet.wa-bottom-sheet {
    display: none;
    pointer-events: none;
  }
  .wa-push-sheet.wa-bottom-sheet.is-open {
    display: block !important;
    pointer-events: auto;
  }
  .wa-push-sheet .wa-bottom-sheet-panel {
    left: 50%;
    right: auto;
    bottom: auto;
    top: 50%;
    min-height: 0;
    max-height: min(80vh, 520px);
    width: min(420px, calc(100% - 32px));
    transform: translate(-50%, calc(-50% + 12px)) scale(0.98);
    border-radius: var(--wa-card-radius, 14px);
    padding-bottom: 0.85rem;
  }
  .wa-push-sheet.is-open .wa-bottom-sheet-panel {
    transform: translate(-50%, -50%) scale(1);
  }
  .wa-push-sheet .wa-bottom-sheet-handle {
    display: none;
  }
}

.wa-push-sheet__body {
  padding-top: 0.35rem;
}

.wa-push-sheet__https {
  font-size: 0.78rem;
  color: var(--wa-color-text);
  background: var(--wa-color-surface-soft);
  border: 1px solid var(--wa-color-border);
  border-radius: 8px;
  padding: 6px 10px;
  margin: 0 0 10px;
  line-height: 1.35;
}

.wa-push-sheet__https[hidden] {
  display: none !important;
}

.wa-push-sheet__status {
  color: var(--wa-color-primary);
  margin: 0 0 10px;
  font-size: 0.82rem;
  line-height: 1.35;
}

.wa-push-sheet__status:empty {
  display: none;
}

.wa-push-sheet__local {
  font-size: 0.78rem;
  color: var(--wa-color-muted);
  background: var(--wa-color-surface-soft);
  border: 1px solid var(--wa-color-border);
  border-radius: 8px;
  padding: 6px 10px;
  margin: 0 0 10px;
  line-height: 1.35;
}

.wa-push-sheet__local[hidden] {
  display: none !important;
}

.wa-push-sheet__marketing {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 12px;
  color: var(--wa-color-text);
  line-height: 1.35;
  font-size: 0.84rem;
}

.wa-push-sheet__actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wa-push-sheet__btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 42px;
}

.wa-push-sheet__btn--primary {
  border: none;
  background: var(--wa-color-primary);
  color: var(--wa-color-primary-contrast);
}

.wa-push-sheet__btn--ghost {
  background: var(--wa-color-surface-soft);
  color: var(--wa-color-primary);
  border: 1px solid var(--wa-color-border);
}

.wa-push-sheet__hint {
  margin: 10px 0 0;
  color: var(--wa-color-muted);
  font-size: 0.76rem;
  line-height: 1.35;
}

/* -------------------------------------------------------- */
/* Thread + messaggi                                        */
/* -------------------------------------------------------- */

.wa-chat-thread {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
}

.wa-chat-body {
  flex: 1 1 auto;
  min-height: 160px;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--wa-color-bg);
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.wa-chat-empty {
  text-align: center;
  color: var(--wa-color-muted);
  padding: 28px 12px;
  margin: auto 0;
}

.wa-chat-empty__icon {
  font-size: 1.75rem;
  margin-bottom: 8px;
  opacity: 0.7;
  color: var(--wa-color-muted);
}

.wa-chat-empty__text {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.45;
}

/* Bolle */

.wa-msg {
  display: flex;
  flex-direction: column;
  max-width: min(78%, 320px);
  gap: 2px;
}

.wa-msg--you {
  align-self: flex-end;
  align-items: flex-end;
}

.wa-msg--them {
  align-self: flex-start;
  align-items: flex-start;
}

.wa-msg__meta {
  font-size: 0.68rem;
  color: var(--wa-color-muted);
  padding: 0 2px;
  display: inline-flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px 6px;
  max-width: 100%;
}

.wa-msg__sender {
  font-weight: 600;
  color: var(--wa-color-muted);
}

.wa-msg__time {
  opacity: 0.9;
}

.wa-msg__delbtn {
  border: none;
  background: transparent;
  color: var(--wa-color-muted);
  cursor: pointer;
  padding: 0 4px;
  font-size: 0.72rem;
  line-height: 1;
  border-radius: 4px;
  opacity: 0.55;
  margin-left: 2px;
}

.wa-msg--you:focus-within .wa-msg__delbtn {
  opacity: 1;
}

.wa-msg__delbtn:focus-visible {
  color: var(--wa-color-danger);
}
.wa-msg__delbtn:active {
  transform: scale(0.92);
}

.wa-msg__bubble {
  padding: 8px 11px;
  border-radius: 16px;
  font-size: 0.94rem;
  line-height: 1.38;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}

.wa-msg--you .wa-msg__bubble {
  background: var(--wa-color-primary);
  color: var(--wa-color-primary-contrast);
  border-bottom-right-radius: 4px;
}

.wa-msg--them:not(.wa-msg--system):not(.wa-msg--support) .wa-msg__bubble {
  background: var(--wa-color-surface);
  color: var(--wa-color-text);
  border: 1px solid var(--wa-color-border);
  border-bottom-left-radius: 4px;
  box-shadow: var(--wa-shadow-sm, 0 1px 2px rgba(0, 0, 0, 0.04));
}

.wa-msg--system .wa-msg__bubble {
  background: var(--wa-color-surface-soft);
  color: var(--wa-color-muted);
  font-style: italic;
  border: 1px dashed var(--wa-color-border);
  font-size: 0.85rem;
}

.wa-msg--support .wa-msg__bubble {
  background: var(--wa-color-info-bg);
  color: var(--wa-color-info-fg);
  border: 1px solid var(--wa-color-info, var(--wa-color-border));
}

.wa-msg--optimistic .wa-msg__bubble {
  opacity: 0.65;
}

.wa-msg__attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 4px;
}

.wa-msg--you .wa-msg__attachments {
  justify-content: flex-end;
}

.wa-msg--them .wa-msg__attachments {
  justify-content: flex-start;
}

.wa-msg__thumb-link,
.wa-msg__thumb-btn {
  padding: 0;
  border: 0;
  background: none;
  border-radius: 8px;
  cursor: pointer;
  line-height: 0;
}

.wa-msg__thumb {
  display: block;
  width: 96px;
  height: 72px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--wa-color-border);
}

/* Lightbox */

.wa-chat-lightbox {
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(15, 23, 42, 0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.wa-chat-lightbox[hidden] {
  display: none !important;
}

.wa-chat-lightbox__inner {
  max-width: min(96vw, 900px);
  max-height: 88vh;
}

.wa-chat-lightbox__img {
  max-width: 100%;
  max-height: 88vh;
  border-radius: 8px;
  box-shadow: var(--wa-shadow-md, 0 8px 32px rgba(0, 0, 0, 0.35));
}

.wa-chat-lightbox__close {
  position: fixed;
  top: 12px;
  right: 14px;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: var(--wa-color-surface);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  color: var(--wa-color-text);
}

/* -------------------------------------------------------- */
/* Composer                                                 */
/* -------------------------------------------------------- */

.wa-chat-composer {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px calc(10px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--wa-color-border);
  background: var(--wa-color-surface);
}

.wa-chat-composer__hint {
  margin: 0;
  font-size: 0.72rem;
  color: var(--wa-color-muted);
  line-height: 1.3;
}

.wa-chat-composer__previews {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.wa-chat-composer__previews[hidden] {
  display: none !important;
}

.wa-chat-composer__preview {
  position: relative;
  width: 52px;
  height: 52px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--wa-color-border);
}

.wa-chat-composer__preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.wa-chat-composer__preview-remove {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  padding: 0;
}

.wa-chat-composer__file {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.wa-chat-composer__row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.wa-chat-composer__attach {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  border: 1px solid var(--wa-color-border);
  background: var(--wa-color-surface-soft, var(--wa-color-bg));
  color: var(--wa-color-text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.wa-chat-composer__attach:active:not(:disabled) {
  transform: scale(0.96);
}

.wa-chat-composer__input {
  flex: 1 1 auto;
  min-height: 42px;
  max-height: 120px;
  padding: 9px 12px;
  border-radius: 12px;
  border: 1px solid var(--wa-color-border);
  font-size: 0.95rem;
  line-height: 1.35;
  resize: none;
  font-family: inherit;
  background: var(--wa-color-bg);
  color: var(--wa-color-text);
  outline: none;
}

.wa-chat-composer__input:focus {
  border-color: var(--wa-color-primary);
  box-shadow: 0 0 0 2px var(--wa-color-primary-soft, rgba(196, 30, 30, 0.12));
}

.wa-chat-composer__input::placeholder {
  color: var(--wa-color-muted);
}

.wa-chat-composer__btn {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  padding: 0;
  border-radius: 12px;
  border: 0;
  background: var(--wa-color-primary);
  color: var(--wa-color-primary-contrast);
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.wa-chat-composer__btn:disabled {
  background: var(--wa-color-surface-strong);
  color: var(--wa-color-muted);
  cursor: not-allowed;
}

@media (max-width: 575.98px) {
  .wa-chat-composer__btn-label {
    display: none;
  }
}

/* Alert */

.wa-chat-alert {
  margin: 8px 12px 0;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 0.85rem;
  line-height: 1.35;
  background: var(--wa-color-danger-bg);
  color: var(--wa-color-danger-fg, var(--wa-color-danger));
  border: 1px solid var(--wa-color-danger-border, var(--wa-color-danger));
  flex-shrink: 0;
}

/* Altri thread */

.wa-chat-others {
  margin-top: 18px;
}

.wa-chat-others__title {
  font-size: 0.92rem;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--wa-color-text);
}

.wa-chat-others__lead {
  font-size: 0.82rem;
  color: var(--wa-color-muted);
  margin: 0 0 10px;
}

.wa-chat-others__list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wa-chat-others__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: var(--wa-color-surface);
  border: 1px solid var(--wa-color-border);
  border-radius: 10px;
  text-decoration: none;
  color: var(--wa-color-text);
}

.wa-chat-others__item:active {
  background: var(--wa-color-surface-soft);
}

.wa-chat-others__subject {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wa-chat-others__preview {
  font-size: 0.8rem;
  color: var(--wa-color-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.wa-chat-others__badge {
  flex-shrink: 0;
  background: var(--wa-color-primary);
  color: var(--wa-color-primary-contrast);
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 2px 8px;
  min-width: 20px;
  text-align: center;
}

.wa-messages-toolbar {
  text-align: center;
  margin: 16px 0 0;
  font-size: 0.85rem;
}

.wa-messages-toolbar a {
  color: var(--wa-color-muted);
  text-decoration: none;
}

.wa-messages-toolbar a:focus-visible {
  color: var(--wa-color-text);
  text-decoration: underline;
}
