#mg-alia-web-root {
  position: relative;
  z-index: 2147483000;
}

.mg-alia,
.mg-alia * {
  box-sizing: border-box;
}

.mg-alia {
  --alia-gold: #aa985e;
  --alia-gold-soft: #c8ba88;
  --alia-black: #111111;
  --alia-border: #e7e2d6;
  --alia-bg: #ffffff;
  --alia-soft: #f7f5ef;
  --alia-muted: #6f6f6f;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.mg-alia__launcher {
  position: fixed;
  left: 24px;
  bottom: 24px;
  min-width: 192px;
  height: 54px;
  padding: 0 16px 0 10px;
  border: 0;
  border-radius: 999px;
  background: var(--alia-black);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 12px 32px rgba(0,0,0,.22);
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  text-align: left;
  transition: transform .18s ease, box-shadow .18s ease;
}

.mg-alia__launcher:hover {
  transform: translateY(-1px);
  box-shadow: 0 15px 36px rgba(0,0,0,.25);
}

.mg-alia__launcher-icon {
  flex: 0 0 34px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--alia-gold);
  color: var(--alia-black);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 900;
  line-height: 1;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.2);
}

.mg-alia__launcher-copy {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
  line-height: 1.1;
}

.mg-alia__launcher-copy strong {
  color: #fff;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: .01em;
  white-space: nowrap;
}

.mg-alia__launcher-copy small {
  color: rgba(255,255,255,.68);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .015em;
  white-space: nowrap;
}

.mg-alia__panel {
  position: fixed;
  left: 24px;
  bottom: 88px;
  width: min(390px, calc(100vw - 32px));
  height: min(650px, calc(100vh - 120px));
  height: min(650px, calc(100dvh - 120px));
  background: var(--alia-bg);
  border: 1px solid rgba(17,17,17,.08);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,.22);
  display: grid;
  grid-template-rows: auto 1fr auto auto auto;
}

.mg-alia__panel[hidden] {
  display: none !important;
}

.mg-alia__header {
  min-height: 72px;
  background: var(--alia-black);
  color: #fff;
  padding: 15px 16px 15px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 3px solid var(--alia-gold);
}

.mg-alia__header-copy {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.mg-alia__title {
  font-size: 18px;
  line-height: 1.2;
}

.mg-alia__subtitle {
  font-size: 12px;
  line-height: 1.3;
  color: rgba(255,255,255,.72);
}

.mg-alia__close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  color: #fff;
  font: inherit;
  font-size: 25px;
  line-height: 1;
  cursor: pointer;
}

.mg-alia__messages {
  padding: 18px 16px 12px;
  overflow-y: auto;
  background: linear-gradient(180deg, #fff 0%, #fbfaf7 100%);
  scroll-behavior: smooth;
  overscroll-behavior: contain;
}

.mg-alia__row {
  display: flex;
  margin: 0 0 10px;
}

.mg-alia__row--user { justify-content: flex-end; }
.mg-alia__row--assistant,
.mg-alia__row--operator,
.mg-alia__row--system { justify-content: flex-start; }

.mg-alia__bubble {
  max-width: 84%;
  padding: 11px 13px;
  border-radius: 15px;
  font-size: 14px;
  line-height: 1.48;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.mg-alia__row--user .mg-alia__bubble {
  background: var(--alia-black);
  color: #fff;
  border-bottom-right-radius: 5px;
}

.mg-alia__row--assistant .mg-alia__bubble {
  background: var(--alia-soft);
  color: #1b1b1b;
  border: 1px solid var(--alia-border);
  border-bottom-left-radius: 5px;
}

.mg-alia__row--operator .mg-alia__bubble {
  background: #fffaf0;
  color: #1b1b1b;
  border: 1px solid var(--alia-gold-soft);
  border-bottom-left-radius: 5px;
}

.mg-alia__row--operator .mg-alia__bubble::before {
  content: "Operatore";
  display: block;
  margin-bottom: 4px;
  color: #76662f;
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.mg-alia__row--system .mg-alia__bubble {
  background: #fff;
  color: var(--alia-muted);
  border: 1px dashed #d5d5d5;
  font-size: 13px;
}

.mg-alia__quick {
  padding: 4px 14px 12px;
  background: #fbfaf7;
  display: flex;
  gap: 7px;
  flex-wrap: wrap;
  max-height: 154px;
  overflow-y: auto;
}

.mg-alia__quick[hidden] { display: none; }

.mg-alia__quick-button {
  border: 1px solid #d8d0b5;
  border-radius: 999px;
  background: #fff;
  color: #1b1b1b;
  padding: 8px 11px;
  font: inherit;
  font-size: 12.5px;
  font-weight: 650;
  cursor: pointer;
}

.mg-alia__quick-button:hover {
  border-color: var(--alia-gold);
  background: #fffdf8;
}

.mg-alia__status {
  padding: 9px 14px;
  background: #f5f0df;
  color: #5e542d;
  border-top: 1px solid #e3d7ab;
  font-size: 12.5px;
  line-height: 1.35;
}

.mg-alia__status[hidden] { display: none; }

.mg-alia__new-session {
  margin: 10px 14px 0;
  min-height: 38px;
  border: 1px solid var(--alia-gold);
  border-radius: 10px;
  background: #fff;
  color: var(--alia-black);
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.mg-alia__new-session[hidden] { display: none; }

.mg-alia__form {
  padding: 12px;
  background: #fff;
  border-top: 1px solid #ece8df;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}

.mg-alia__input {
  width: 100%;
  min-height: 42px;
  max-height: 110px;
  resize: none;
  border: 1px solid #d9d5ca;
  border-radius: 12px;
  padding: 10px 11px;
  outline: none;
  color: #151515;
  background: #fff;
  font: inherit;
  font-size: 14px;
  line-height: 1.35;
}

.mg-alia__input:focus {
  border-color: var(--alia-gold);
  box-shadow: 0 0 0 3px rgba(170,152,94,.13);
}

.mg-alia__send {
  min-width: 70px;
  min-height: 42px;
  padding: 0 14px;
  border: 0;
  border-radius: 12px;
  background: var(--alia-gold);
  color: #111;
  font: inherit;
  font-weight: 800;
  cursor: pointer;
}

.mg-alia__send:disabled,
.mg-alia__input:disabled,
.mg-alia__quick-button:disabled {
  opacity: .55;
  cursor: wait;
}

/* Tablet: stessa esperienza mobile, ma pannello più arioso. */
@media (max-width: 1024px) {
  .mg-alia__launcher {
    left: 16px;
    right: auto;
    bottom: max(16px, env(safe-area-inset-bottom));
    min-width: 176px;
    height: 50px;
    padding: 0 13px 0 8px;
    gap: 9px;
  }

  .mg-alia__launcher-icon {
    flex-basis: 32px;
    width: 32px;
    height: 32px;
    font-size: 15px;
  }

  .mg-alia__launcher-copy strong { font-size: 12.5px; }
  .mg-alia__launcher-copy small { font-size: 9px; }

  .mg-alia__panel {
    left: 16px;
    right: auto;
    bottom: calc(78px + env(safe-area-inset-bottom));
    width: min(460px, calc(100vw - 32px));
    height: min(76svh, 720px);
    max-height: calc(100dvh - 96px - env(safe-area-inset-bottom));
    border-radius: 20px;
  }

  .mg-alia__quick {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    max-height: 176px;
    padding: 8px 12px 12px;
  }

  .mg-alia__quick-button {
    width: 100%;
    min-height: 42px;
    border-radius: 11px;
    padding: 8px 9px;
    font-size: 12px;
    line-height: 1.18;
    text-align: center;
  }

  .mg-alia__quick-button[data-action-id="human_support"] {
    background: var(--alia-black);
    color: #fff;
    border-color: var(--alia-black);
  }

  .mg-alia__quick-button:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }
}

/* Mobile: bottom-sheet compatto e launcher che non copre la home. */
@media (max-width: 767px) {
  .mg-alia__launcher {
    left: 12px;
    right: auto;
    bottom: max(12px, env(safe-area-inset-bottom));
    min-width: 158px;
    max-width: calc(100vw - 110px);
    height: 46px;
    padding: 0 11px 0 7px;
    gap: 8px;
    box-shadow: 0 10px 26px rgba(0,0,0,.20);
  }

  .mg-alia__launcher-icon {
    flex-basis: 30px;
    width: 30px;
    height: 30px;
    font-size: 14px;
  }

  .mg-alia__launcher-copy strong {
    font-size: 11.5px;
    line-height: 1.05;
  }

  .mg-alia__launcher-copy small {
    font-size: 8px;
    line-height: 1.05;
  }

  .mg-alia__panel {
    left: 8px;
    right: 8px;
    bottom: calc(66px + env(safe-area-inset-bottom));
    width: auto;
    height: min(80svh, 660px);
    max-height: calc(100dvh - 78px - env(safe-area-inset-bottom));
    border-radius: 18px;
    box-shadow: 0 18px 50px rgba(0,0,0,.24);
  }

  .mg-alia__header {
    min-height: 62px;
    padding: 11px 12px 11px 14px;
    border-bottom-width: 2px;
  }

  .mg-alia__title { font-size: 16px; }
  .mg-alia__subtitle { font-size: 10.5px; }

  .mg-alia__close {
    width: 34px;
    height: 34px;
    font-size: 23px;
  }

  .mg-alia__messages {
    padding: 13px 11px 9px;
  }

  .mg-alia__row { margin-bottom: 8px; }

  .mg-alia__bubble {
    max-width: 90%;
    padding: 10px 11px;
    border-radius: 13px;
    font-size: 13.5px;
    line-height: 1.43;
  }

  .mg-alia__quick {
    gap: 7px;
    max-height: 168px;
    padding: 7px 10px 10px;
  }

  .mg-alia__quick-button {
    min-height: 40px;
    border-radius: 10px;
    padding: 7px 7px;
    font-size: 11px;
  }

  .mg-alia__status {
    padding: 8px 11px;
    font-size: 11.5px;
  }

  .mg-alia__new-session {
    margin: 8px 10px 0;
    min-height: 38px;
  }

  .mg-alia__form {
    padding: 9px 9px calc(9px + env(safe-area-inset-bottom));
    gap: 7px;
  }

  .mg-alia__input {
    min-height: 40px;
    padding: 9px 10px;
    border-radius: 11px;
    font-size: 14px;
  }

  .mg-alia__send {
    min-width: 64px;
    min-height: 40px;
    padding: 0 11px;
    border-radius: 11px;
    font-size: 13px;
  }
}

@media (max-width: 380px) {
  .mg-alia__launcher {
    min-width: 146px;
    max-width: calc(100vw - 96px);
  }

  .mg-alia__launcher-copy small {
    display: none;
  }

  .mg-alia__panel {
    left: 6px;
    right: 6px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .mg-alia__messages { scroll-behavior: auto; }
  .mg-alia__launcher { transition: none; }
  .mg-alia__launcher:hover { transform: none; }
}
