/* SOGES AI Assistant */
.soges-ai-widget {
  position: fixed;
  right: 18px;
  bottom: calc(76px + env(safe-area-inset-bottom));
  z-index: 70;
  font-family: Inter, "Helvetica Neue", Arial, sans-serif;
}

.soges-ai-button {
  min-height: 46px;
  padding: 0 17px;
  border: 1px solid rgba(7,59,122,.18);
  border-radius: 999px;
  background: var(--blue, #073B7A);
  color: #fff;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  box-shadow: 0 14px 36px rgba(6,31,74,.18);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.soges-ai-button svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.soges-ai-panel {
  position: absolute;
  right: 0;
  bottom: 58px;
  width: min(370px, calc(100vw - 32px));
  max-height: min(620px, calc(100vh - 130px));
  background: #fff;
  border: 1px solid rgba(7,59,122,.13);
  border-radius: 22px;
  box-shadow: 0 24px 70px rgba(6,31,74,.20);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px);
  transition: opacity .24s ease, visibility .24s ease, transform .24s ease;
}

.soges-ai-widget.is-open .soges-ai-panel {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.soges-ai-header {
  padding: 16px 18px;
  background: linear-gradient(145deg, var(--blue, #073B7A), var(--dark, #052C5E));
  color: #fff;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.soges-ai-header strong {
  display: block;
  font-size: 15px;
  line-height: 1.2;
}

.soges-ai-header span {
  display: block;
  margin-top: 3px;
  color: rgba(255,255,255,.78);
  font-size: 12px;
  line-height: 1.25;
}

.soges-ai-close {
  width: 34px;
  height: 34px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  color: #fff;
  cursor: pointer;
  font-size: 22px;
  line-height: 1;
}

.soges-ai-messages {
  height: 330px;
  overflow-y: auto;
  padding: 18px;
  background: #f7f9fc;
}

.soges-ai-message {
  margin-bottom: 12px;
  display: flex;
}

.soges-ai-message span {
  display: inline-block;
  max-width: 88%;
  padding: 11px 13px;
  border-radius: 15px;
  font-size: 14px;
  line-height: 1.45;
}

.soges-ai-message.assistant span {
  background: #fff;
  border: 1px solid #dde5ef;
  color: #071C3F;
}

.soges-ai-message.user {
  justify-content: flex-end;
}

.soges-ai-message.user span {
  background: var(--blue, #073B7A);
  color: #fff;
}

.soges-ai-quick {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 18px 14px;
  background: #f7f9fc;
}

.soges-ai-quick button {
  border: 1px solid #d8dee8;
  background: #fff;
  color: var(--blue, #073B7A);
  border-radius: 999px;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 800;
  cursor: pointer;
}

.soges-ai-form {
  display: grid;
  grid-template-columns: 1fr 44px;
  gap: 8px;
  padding: 14px;
  border-top: 1px solid #dde5ef;
  background: #fff;
}

.soges-ai-form textarea {
  resize: none;
  min-height: 44px;
  max-height: 110px;
  border: 1px solid #d8dee8;
  border-radius: 14px;
  padding: 11px 12px;
  font: inherit;
  font-size: 14px;
  line-height: 1.35;
  outline: none;
}

.soges-ai-form textarea:focus {
  border-color: var(--blue, #073B7A);
  box-shadow: 0 0 0 3px rgba(7,59,122,.08);
}

.soges-ai-form button {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  background: var(--blue, #073B7A);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
}

.soges-ai-form button svg {
  width: 18px;
  height: 18px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2.3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.soges-ai-disclaimer {
  padding: 0 14px 14px;
  margin: 0;
  background: #fff;
  color: #526077;
  font-size: 11px;
  line-height: 1.35;
}

@media(max-width: 760px) {
  .soges-ai-widget {
    right: 16px;
    bottom: calc(70px + env(safe-area-inset-bottom));
  }

  .soges-ai-button {
    width: 46px;
    height: 46px;
    padding: 0;
    justify-content: center;
  }

  .soges-ai-button span {
    display: none;
  }

  .soges-ai-panel {
    right: -2px;
    width: calc(100vw - 28px);
    bottom: 58px;
  }

  .soges-ai-messages {
    height: 330px;
  }
}


/* SOGES V27 secretary wording */
.soges-ai-header strong {
  letter-spacing: -.01em;
}

/* STEP 5I — Fix definitivo apertura Segreteria SOGES
   Mantiene il widget sempre sopra l'header e, su mobile,
   apre il pannello dentro l'area visibile senza coprire il primo messaggio. */
.soges-ai-widget{
  z-index: 140 !important;
}

.soges-ai-panel{
  z-index: 141 !important;
}

@media (max-width: 760px){
  .soges-ai-widget{
    position: fixed !important;
    right: 16px !important;
    bottom: calc(70px + env(safe-area-inset-bottom)) !important;
    z-index: 140 !important;
  }

  .soges-ai-panel{
    position: fixed !important;
    left: 14px !important;
    right: 14px !important;
    top: calc(76px + env(safe-area-inset-top)) !important;
    bottom: calc(76px + env(safe-area-inset-bottom)) !important;
    width: auto !important;
    max-width: none !important;
    max-height: none !important;
    height: auto !important;
    display: flex !important;
    flex-direction: column !important;
    border-radius: 20px !important;
    overflow: hidden !important;
    transform: translateY(10px) !important;
  }

  .soges-ai-widget.is-open .soges-ai-panel{
    transform: translateY(0) !important;
  }

  .soges-ai-header{
    flex: 0 0 auto !important;
    min-height: 66px !important;
    padding: 13px 15px !important;
  }

  .soges-ai-messages{
    flex: 1 1 auto !important;
    height: auto !important;
    min-height: 0 !important;
    padding: 14px !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
  }

  .soges-ai-quick,
  .soges-ai-form,
  .soges-ai-disclaimer{
    flex: 0 0 auto !important;
  }

  .soges-ai-quick{
    padding: 0 14px 12px !important;
    gap: 6px !important;
  }

  .soges-ai-form{
    padding: 12px !important;
  }

  .soges-ai-disclaimer{
    padding: 0 12px 12px !important;
  }
}

@media (max-width: 420px){
  .soges-ai-panel{
    left: 10px !important;
    right: 10px !important;
    top: calc(70px + env(safe-area-inset-top)) !important;
    bottom: calc(72px + env(safe-area-inset-bottom)) !important;
    border-radius: 18px !important;
  }

  .soges-ai-header span{
    font-size: 11px !important;
  }

  .soges-ai-message span{
    max-width: 94% !important;
    font-size: 13px !important;
  }
}
