:root {
  --yai-ink: #12263a;
  --yai-muted: #5b6b7a;
  --yai-line: #dbe3e8;
  --yai-surface: #ffffff;
  --yai-soft: #f3f7f8;
  --yai-ocean: #0d5961;
  --yai-ocean-dark: #073f47;
  --yai-gold: #b99348;
  --yai-danger: #a33a3a;
  --yai-success: #256b50;
  --yai-shadow: 0 24px 60px rgba(9, 31, 48, 0.2), 0 4px 16px rgba(9, 31, 48, 0.1);
}

.yachtai-widget,
.yachtai-widget * {
  box-sizing: border-box;
}

.yachtai-widget {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 99990;
  color: var(--yai-ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

.yachtai-widget .yachtai-sr-only,
.yachtai-widget .element-invisible {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  clip-path: inset(50%) !important;
  border: 0 !important;
  white-space: nowrap !important;
}

.yai-launcher,
.yai-icon-button,
.yai-button {
  border: 0;
  font: inherit;
  cursor: pointer;
}

.yai-launcher {
  display: inline-flex;
  min-height: 52px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 12px 18px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--yai-ocean-dark), var(--yai-ocean));
  box-shadow: 0 14px 36px rgba(7, 63, 71, 0.28);
  font-weight: 700;
  transition: background-color 180ms ease, box-shadow 180ms ease, transform 180ms ease;
}

.yai-launcher__mark {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #75d8b0;
  box-shadow: 0 0 0 4px rgba(117, 216, 176, 0.16);
}

.yai-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  display: grid;
  width: min(410px, calc(100vw - 24px));
  height: min(720px, calc(100vh - 100px));
  height: min(720px, calc(100dvh - 100px));
  min-height: 470px;
  grid-template-rows: auto minmax(140px, 1fr) auto auto;
  overflow: hidden;
  border: 1px solid rgba(18, 38, 58, 0.12);
  border-radius: 8px;
  background: var(--yai-surface);
  /* box-shadow: var(--yai-shadow); */
}

.yai-panel[hidden] {
  display: none !important;
}

.yai-header {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  padding: 17px 18px;
  color: #fff;
  background: linear-gradient(135deg, #092f42, var(--yai-ocean));
  box-shadow: inset 0 -1px rgba(255, 255, 255, 0.12);
}

.yai-header > div {
  min-width: 0;
}

.yai-header h2,
.yai-contact h3 {
  margin: 0;
  font-size: 18px;
  letter-spacing: 0;
  line-height: 1.25;
  color: white;
}

.yai-header p {
  grid-column: 1 / -1;
  margin: 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: 13px;
}

.yai-icon-button {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 6px;
  color: inherit;
  background: rgba(255, 255, 255, 0.1);
  font-size: 22px;
  transition: background-color 160ms ease, color 160ms ease;
}

.yai-log {
  display: flex;
  min-height: 0;
  flex-direction: column;
  gap: 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  background: linear-gradient(180deg, #f6f9fa, var(--yai-soft));
  scrollbar-color: #afbec5 transparent;
  scrollbar-width: thin;
}

.yai-message {
  max-width: 84%;
  align-self: flex-start;
  margin: 0;
  padding: 11px 13px;
  border: 1px solid var(--yai-line);
  border-radius: 8px 8px 8px 2px;
  background: #fff;
  box-shadow: 0 4px 14px rgba(9, 31, 48, 0.05);
  overflow-wrap: anywhere;
}

.yai-message p {
  margin: 0;
  white-space: pre-wrap;
}

.yai-message--ai,
.yai-message--operator {
  align-self: flex-start;
  margin-right: auto;
}

.yai-message--client {
  align-self: flex-end;
  margin-left: auto;
  border-color: var(--yai-ocean);
  border-radius: 8px 8px 2px 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--yai-ocean-dark), var(--yai-ocean));
  box-shadow: 0 6px 18px rgba(7, 63, 71, 0.16);
}

.yai-message--operator {
  border-left: 3px solid var(--yai-gold);
  background: #fffaf1;
}

.yai-message--warning {
  border-color: #d6a348;
  background: #fff8e9;
}

.yai-message--system {
  width: 100%;
  max-width: 100%;
  align-self: stretch;
  padding: 0;
  border: 0;
  color: var(--yai-muted);
  background: transparent;
  box-shadow: none;
}

.yai-message--system p + .yai-button {
  margin-top: 10px;
}

.yai-status {
  min-height: 30px;
  margin: 0;
  padding: 7px 16px;
  border-top: 1px solid var(--yai-line);
  color: var(--yai-muted);
  background: #fff;
  font-size: 12px;
}

.yai-status[data-state="error"] {
  color: var(--yai-danger);
}

.yai-status[data-state="warning"] {
  color: #765418;
  background: #fff8e9;
}

.yai-status[data-state="success"] {
  color: var(--yai-success);
}

.yai-composer {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 14px 16px;
  border-top: 1px solid var(--yai-line);
  background: #fff;
}

.yai-composer > label,
.yai-composer > textarea {
  grid-column: 1 / -1;
  display: block;
  min-width: 0;
  margin: 0;
}

.yai-composer > [data-yachtai-contact-open] {
  grid-column: 1;
}

.yai-composer > [data-yachtai-send] {
  grid-column: 2;
}

.yai-composer > .yai-button {
  width: 100%;
  min-width: 0;
}

.yai-composer > [hidden] {
  display: none !important;
}

.yai-composer textarea {
  width: 100%;
  min-height: 128px;
  max-height: 220px;
  resize: vertical;
  padding: 12px 13px;
  border: 1px solid #bfcbd3;
  border-radius: 6px;
  color: var(--yai-ink);
  background: #fff;
  font: inherit;
  font-size: 16px;
  line-height: 1.45;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.yai-button {
  min-height: 44px;
  padding: 10px 16px;
  border-radius: 6px;
  font-weight: 700;
}

.yai-button--primary {
  min-width: 132px;
  justify-self: end;
  color: #fff;
  background: var(--yai-ocean);
}

.yai-button--quiet {
  border: 1px solid #cad9de;
  color: var(--yai-ocean-dark);
  background: #e8f1f2;
}

.yai-message--system .yai-button--quiet {
  width: 100%;
}

.yai-final-contact[hidden] {
  display: none !important;
}

.yai-button:disabled,
.yai-composer textarea:disabled {
  cursor: not-allowed;
  opacity: 0.58;
}

.yai-contact {
  position: absolute;
  inset: 0;
  z-index: 3;
  overflow-y: auto;
  padding: 20px;
  background: rgba(255, 255, 255, 0.98);
}

.yai-contact[hidden] {
  display: none !important;
}

.yai-contact [hidden] {
  display: none !important;
}

.yai-contact__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.yai-contact__header .yai-icon-button {
  flex: 0 0 auto;
  color: var(--yai-ink);
  background: var(--yai-soft);
}

.yai-contact__lead {
  margin: 8px 0 18px;
  color: var(--yai-muted);
}

.yai-contact__form {
  display: grid;
  gap: 13px;
}

.yai-field {
  display: grid;
  gap: 6px;
  color: var(--yai-ink);
  font-size: 13px;
  font-weight: 650;
}

.yai-field input,
.yai-field select {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid #bfcbd3;
  border-radius: 6px;
  color: var(--yai-ink);
  background: #fff;
  font: inherit;
  font-weight: 400;
}

.yai-contact__consent {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 9px;
  align-items: start;
  color: var(--yai-muted);
  font-size: 12px;
}

.yai-contact__consent input {
  width: 18px;
  height: 18px;
  margin: 1px 0 0;
}

.yai-contact__error {
  margin: 0;
  color: var(--yai-danger);
  font-size: 13px;
}

.yai-contact__saved {
  padding: 16px;
  border-left: 3px solid var(--yai-success);
  color: var(--yai-success);
  background: #eef8f3;
}

@media (hover: hover) {
  .yai-launcher:hover {
    box-shadow: 0 18px 40px rgba(7, 63, 71, 0.34);
    transform: translateY(-1px);
  }

  .yai-icon-button:hover {
    background: rgba(255, 255, 255, 0.2);
  }

  .yai-button--primary:hover {
    background: var(--yai-ocean-dark);
  }

  .yai-button--quiet:hover {
    border-color: #9ebbc0;
    background: #dbeaec;
  }
}

.yachtai-contact-page,
.yachtai-block-contact {
  width: min(620px, calc(100% - 32px));
  margin: clamp(28px, 8vh, 90px) auto;
  padding: clamp(20px, 5vw, 38px);
  border: 1px solid var(--yai-line);
  border-radius: 8px;
  color: var(--yai-ink);
  background: #fff;
  box-shadow: var(--yai-shadow);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.yachtai-block-contact {
  position: relative;
  min-height: 280px;
}

.yachtai-contact-page h1,
.yachtai-block-contact h1 {
  margin: 0 0 10px;
  color: var(--yai-ink);
  font-size: 38px;
  letter-spacing: 0;
}

.yachtai-contact-form {
  display: grid;
  gap: 9px;
  margin-top: 22px;
}

.yachtai-contact-form label {
  margin-top: 6px;
  font-weight: 650;
}

.yachtai-contact-form input,
.yachtai-contact-form select,
.yachtai-contact-form textarea {
  width: 100%;
  min-height: 44px;
  padding: 9px 11px;
  border: 1px solid #bfcbd3;
  border-radius: 6px;
  color: var(--yai-ink);
  background: #fff;
  font: inherit;
}

.yachtai-contact-form input[type="checkbox"] {
  width: 18px;
  min-height: 18px;
  margin-right: 8px;
}

.yachtai-contact-form button {
  min-height: 46px;
  margin-top: 10px;
  padding: 10px 16px;
  border: 0;
  border-radius: 6px;
  color: #fff;
  background: var(--yai-ocean);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

.yai-launcher:focus-visible,
.yai-icon-button:focus-visible,
.yai-button:focus-visible,
.yai-field input:focus-visible,
.yai-field select:focus-visible,
.yai-composer textarea:focus-visible,
.yai-contact__consent input:focus-visible {
  outline: 3px solid #e2b75c;
  outline-offset: 2px;
}

@media (max-width: 520px) {
  .yachtai-widget {
    right: max(12px, env(safe-area-inset-right));
    bottom: max(12px, env(safe-area-inset-bottom));
  }

  .yai-panel {
    position: fixed;
    inset: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    width: auto;
    height: auto;
    min-height: 0;
  }

  .yai-launcher {
    min-height: 48px;
  }

  .yai-composer {
    padding: 12px;
  }

  .yai-composer textarea {
    min-height: 116px;
  }

  .yai-composer .yai-button--primary {
    width: 100%;
  }

  .yachtai-contact-page h1,
  .yachtai-block-contact h1 {
    font-size: 24px;
  }
}

.yachtai-widget[data-display-mode="drawer"] .yai-panel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: auto;
  display: grid;
  width: clamp(380px, 32vw, 440px);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  grid-template-rows: 44px minmax(0, 1fr) auto auto;
  border-radius: 0;
  transform: translateX(100%);
  transition: transform 260ms cubic-bezier(0.22, 1, 0.36, 1);
  animation: none;
}

.yachtai-widget[data-display-mode="drawer"].is-open .yai-panel {
  transform: translateX(0);
}

.yachtai-widget[data-display-mode="drawer"] .yai-header {
  height: 44px;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  padding: 0 4px 0 16px;
  margin: 0;
}

.yachtai-widget[data-display-mode="drawer"] .yai-header > div {
  display: flex;
  min-width: 0;
  align-items: center;
}

.yachtai-widget[data-display-mode="drawer"] .yai-header h2 {
  overflow: hidden;
  font-size: 12px;
  font-weight: 750;
  letter-spacing: 0.12em;
  line-height: 1;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.yachtai-widget[data-display-mode="drawer"] .yai-header p {
  display: none;
}

.yachtai-widget[data-display-mode="drawer"] .yai-header .yai-icon-button {
  width: 44px;
  height: 44px;
  justify-self: end;
}

.yachtai-widget[data-display-mode="drawer"].is-open .yai-launcher,
.yachtai-widget[data-display-mode="drawer"].is-closing .yai-launcher {
  opacity: 0;
  pointer-events: none;
}

@media (min-width: 1024px) {
  html.yai-drawer-open,
  html.yai-drawer-closing {
    overflow-x: hidden;
  }

  html.yai-drawer-open > body,
  html.yai-drawer-closing > body {
    box-sizing: border-box;
    transition: padding-right 260ms cubic-bezier(0.22, 1, 0.36, 1);
  }

  html.yai-drawer-open > body {
    padding-right: calc(var(--yai-page-base-padding-right, 0px) + var(--yai-drawer-width, 420px));
  }

  html.yai-drawer-closing > body {
    padding-right: var(--yai-page-base-padding-right, 0px);
  }
}

@media (max-width: 1023px) {
  html.yai-chat-modal-open,
  html.yai-chat-modal-closing,
  html.yai-chat-modal-open > body,
  html.yai-chat-modal-closing > body {
    overflow: hidden;
    overscroll-behavior: none;
  }

  .yachtai-widget[data-display-mode="drawer"] {
    right: 0;
    bottom: 0;
  }

  .yachtai-widget[data-display-mode="drawer"] .yai-panel {
    inset: 0;
    width: 100vw;
    max-width: none;
    height: 100vh;
    height: 100dvh;
    border: 0;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .yachtai-widget:not([data-display-mode="drawer"]) .yai-panel {
    animation: yai-panel-in 180ms ease-out;
  }

  @keyframes yai-panel-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
  }
}

@media (prefers-reduced-motion: reduce) {
  .yachtai-widget *,
  .yachtai-widget *::before,
  .yachtai-widget *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }

  html.yai-drawer-open > body,
  html.yai-drawer-closing > body {
    transition-duration: 0.01ms !important;
  }
}
