.ami-settings-trigger {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 4px solid var(--canvas);
  border-radius: 50%;
  background: var(--paper);
  color: var(--forest);
  box-shadow: 0 10px 24px -16px rgba(37, 55, 47, .72);
  cursor: pointer;
  z-index: 3;
}

.ami-settings-trigger svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.8;
}

.user-avatar-wrap > .ami-settings-trigger {
  position: absolute;
  top: 2px;
  left: -5px;
}

.chat-header > .ami-settings-trigger {
  position: absolute;
  right: 22px;
  top: 18px;
  border-width: 0;
  border-radius: 12px;
  background: var(--quiet);
  box-shadow: none;
}

.chat-header {
  position: relative;
}

.ami-settings-open {
  overflow: hidden;
}

.ami-settings-overlay[hidden] {
  display: none;
}

.ami-settings-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(31, 39, 35, .32);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.ami-settings-panel {
  width: min(560px, 100%);
  max-height: min(760px, calc(100dvh - 40px));
  overflow-y: auto;
  padding: 28px;
  border: 1px solid rgba(83, 98, 91, .18);
  border-radius: 30px;
  background: var(--paper);
  box-shadow: 0 36px 100px -42px rgba(20, 34, 28, .62);
  animation: ami-settings-in .28s cubic-bezier(.16, 1, .3, 1) both;
}

.ami-settings-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
}

.ami-settings-head p {
  color: var(--forest);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.ami-settings-head h2 {
  margin-top: 7px;
  font-size: 25px;
  font-weight: 500;
  letter-spacing: -.035em;
  line-height: 1.16;
}

.ami-settings-close {
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border-radius: 13px;
  background: var(--quiet);
  color: var(--muted);
  font-size: 25px;
  line-height: 1;
  cursor: pointer;
}

.ami-settings-form {
  margin-top: 25px;
}

.ami-settings-form fieldset {
  margin: 0 0 24px;
  padding: 0;
  border: 0;
}

.ami-settings-form legend {
  font-size: 15px;
  font-weight: 600;
}

.ami-settings-hint {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.ami-choice-grid {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

.ami-choice-grid--gender {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.ami-choice {
  position: relative;
  cursor: pointer;
}

.ami-choice input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.ami-choice > span {
  min-height: 66px;
  padding: 12px 13px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fbfaf6;
  transition: border-color .18s ease, background-color .18s ease, transform .18s ease;
}

.ami-choice:hover > span {
  transform: translateY(-1px);
  border-color: rgba(47, 98, 84, .35);
}

.ami-choice input:checked + span {
  border-color: var(--forest);
  background: var(--forest-soft);
}

.ami-choice input:focus-visible + span {
  outline: 3px solid rgba(47, 98, 84, .22);
  outline-offset: 2px;
}

.ami-choice strong,
.ami-choice small {
  display: block;
}

.ami-choice strong {
  font-size: 13px;
  font-weight: 600;
}

.ami-choice small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
  line-height: 1.35;
}

.ami-context-toggle {
  padding: 15px;
  display: grid;
  grid-template-columns: 20px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  border: 1px solid var(--line);
  border-radius: 17px;
  background: #fbfaf6;
  cursor: pointer;
}

.ami-context-toggle input {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  accent-color: var(--forest);
}

.ami-context-toggle span {
  display: flex;
  flex-direction: column;
}

.ami-context-toggle strong {
  font-size: 13px;
  font-weight: 600;
}

.ami-context-toggle small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
}

.ami-context-toggle--disabled {
  opacity: .48;
  cursor: default;
}

.ami-settings-status {
  min-height: 18px;
  margin: 10px 2px 5px;
  color: var(--muted);
  font-size: 11px;
}

.ami-settings-save {
  width: 100%;
  min-height: 52px;
  border-radius: 16px;
  background: var(--forest);
  color: var(--paper);
  font-weight: 600;
  cursor: pointer;
}

@keyframes ami-settings-in {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

@media (max-width: 600px) {
  .chat-header > .ami-settings-trigger {
    right: 13px;
    top: 15px;
  }

  .ami-settings-overlay {
    padding: 0;
    align-items: end;
  }

  .ami-settings-panel {
    width: 100%;
    max-height: calc(100dvh - 18px);
    padding: 23px 17px max(18px, env(safe-area-inset-bottom));
    border-radius: 28px 28px 0 0;
  }

  .ami-settings-head h2 {
    font-size: 22px;
  }

  .ami-choice-grid--gender {
    grid-template-columns: 1fr;
  }

  .ami-choice-grid--gender .ami-choice > span {
    min-height: 56px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ami-settings-panel { animation: none; }
}
