.ai-trigger {
  position: fixed;
  z-index: 30;
  right: 24px;
  bottom: 24px;
  width: 52px;
  height: 52px;
  padding: 4px;
  border: 1px solid rgba(18, 107, 132, .18);
  border-radius: 50%;
  background: #fff url("../images/company/aleph.png") center / 44px 44px no-repeat;
  box-shadow: 0 10px 28px rgba(16, 20, 22, .14), 0 2px 8px rgba(16, 20, 22, .08);
  cursor: pointer;
  transition: transform var(--duration-normal) var(--ease), border-color var(--duration-fast) ease, box-shadow var(--duration-normal) var(--ease), background-color var(--duration-fast) ease;
}

.ai-trigger:hover {
  transform: translateY(-2px);
  border-color: rgba(18, 107, 132, .38);
  background-color: var(--brand-tint);
  box-shadow: 0 14px 34px rgba(16, 20, 22, .17), 0 3px 9px rgba(16, 20, 22, .08);
}

.ai-trigger:active { transform: translateY(0) scale(.96); }
.ai-trigger:focus-visible { outline: 3px solid rgba(105, 201, 223, .34); outline-offset: 3px; }
body.menu-open .ai-trigger { opacity: 0; pointer-events: none; }
body.menu-open .ai-panel { visibility: hidden; opacity: 0; pointer-events: none; }

.ai-panel {
  position: fixed;
  z-index: 31;
  right: 24px;
  bottom: 88px;
  display: flex;
  flex-direction: column;
  width: min(400px, calc(100vw - 32px));
  max-height: calc(100dvh - 112px);
  overflow: hidden;
  border: 1px solid #dedede;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .16), 0 4px 14px rgba(0, 0, 0, .06);
}

.ai-panel[hidden] { display: none; }

.ai-panel header {
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 68px;
  padding: 10px 12px 10px 14px;
  border-bottom: 1px solid #e6e6e6;
  color: var(--ink);
  background: #fff;
}

.ai-panel header::before {
  content: "";
  flex: 0 0 38px;
  width: 38px;
  height: 38px;
  border: 1px solid #e4e4e4;
  border-radius: 50%;
  background: #fff url("../images/company/aleph.png") center / 32px 32px no-repeat;
  box-shadow: 0 2px 7px rgba(0, 0, 0, .06);
}

.ai-panel header div {
  display: grid;
  flex: 1;
  gap: 2px;
  min-width: 0;
}

.ai-panel header strong { font-size: 15px; letter-spacing: .01em; }
.ai-panel header small { color: var(--muted); font-size: 12px; }

.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 7px;
  padding: 10px 14px;
  max-height: 120px;
  overflow-y: auto;
  border-bottom: 1px solid #ececec;
  background: #fbfcfc;
  scrollbar-width: none;
}

.ai-suggestions::-webkit-scrollbar { display: none; }

.ai-suggestions button {
  flex: 0 1 auto;
  padding: 6px 11px;
  border: 1px solid #e2e4e6;
  border-radius: 999px;
  color: #303336;
  background: #ffffff;
  font: inherit;
  font-size: 12px;
  line-height: 1.35;
  white-space: normal;
  word-break: break-word;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .03);
  transition: border-color var(--duration-fast) ease, background var(--duration-fast) ease, color var(--duration-fast) ease;
}

.ai-suggestions button:hover { border-color: #2ea3f2; background: #f4faff; color: #0077c8; }
.ai-suggestions button:focus-visible { outline: 3px solid rgba(105, 201, 223, .26); outline-offset: 1px; }
.ai-suggestions button:disabled { opacity: .5; cursor: default; }

.ai-close {
  display: grid;
  flex: 0 0 38px;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0 0 2px;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  transition: color var(--duration-fast) ease, background var(--duration-fast) ease;
}

.ai-close:hover { color: var(--ink); background: #f2f2f2; }
.ai-close:focus-visible { outline: 3px solid rgba(105, 201, 223, .3); outline-offset: 1px; }
.ai-close svg { display: block; width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }

.ai-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 20px;
  min-height: 220px;
  max-height: min(45vh, 380px);
  padding: 24px 20px 28px;
  overflow-y: auto;
  color: var(--ink);
  background: #fff;
  font-size: 14px;
  line-height: 1.7;
  scrollbar-color: #c8c8c8 transparent;
  scrollbar-width: thin;
  overscroll-behavior: contain;
}

.ai-body::-webkit-scrollbar { width: 6px; }
.ai-body::-webkit-scrollbar-track { background: transparent; }
.ai-body::-webkit-scrollbar-thumb { border-radius: 999px; background: #c8c8c8; }
.ai-message {
  display: flex;
  flex: none;
  flex-direction: column;
  max-width: 100%;
  animation: ai-message-enter 180ms ease both;
}

@keyframes ai-message-enter {
  from { opacity: 0; transform: translateY(5px); }
}

.ai-message--user { align-self: flex-end; max-width: 84%; }
.ai-message--assistant { align-self: stretch; }

.ai-message__content {
  color: var(--ink);
  font-size: 15px;
  line-height: 1.7;
  overflow-wrap: anywhere;
  text-wrap: pretty;
}

.ai-message--user .ai-message__content {
  padding: 10px 15px;
  border-radius: 18px 18px 5px 18px;
  background: #f1f1f1;
  white-space: pre-wrap;
}

.ai-message--assistant .ai-message__content { padding: 0 2px; }
.ai-message--welcome .ai-message__content { color: #404040; }
.ai-message__content h3,
.ai-message__content h4 { margin: 16px 0 6px; color: var(--ink); font-size: 15px; line-height: 1.5; }
.ai-message__content code { padding: 2px 5px; border-radius: 5px; background: var(--surface-muted); font-size: .9em; }
.ai-message__content a { color: var(--blue-dark); text-decoration-color: rgba(18, 107, 132, .3); text-underline-offset: 3px; }

.ai-message--error .ai-message__content { color: #555; }

.ai-retry {
  align-self: flex-start;
  margin-top: 9px;
  padding: 6px 11px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: #222;
  background: #fff;
  font: inherit;
  font-size: 12px;
  cursor: pointer;
}

.ai-retry:hover { border-color: #c8c8c8; background: #f4f4f4; }

.ai-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-height: 28px;
}

.ai-typing__label { margin-right: 4px; color: var(--muted); font-size: 12px; font-weight: 600; }
.ai-typing__dot { width: 5px; height: 5px; border-radius: 50%; background: var(--muted); animation: ai-typing 1.2s infinite ease-in-out both; }
.ai-typing__dot:nth-of-type(2) { animation-delay: -.24s; }
.ai-typing__dot:nth-of-type(3) { animation-delay: -.12s; }

@keyframes ai-typing {
  0%, 70%, 100% { opacity: .25; transform: translateY(0); }
  35% { opacity: 1; transform: translateY(-3px); }
}

.ai-sources { display: grid; gap: 5px; padding: 11px 13px; border: 1px solid #e3e3e3; border-radius: 12px; background: #f7f7f8; }
.ai-sources a { color: var(--blue-dark); font-size: 13px; text-decoration: none; }
.ai-sources a::before { margin-right: 7px; content: "↗"; }

.ai-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px 14px;
  border-top: 1px solid #e6e6e6;
  background: #fff;
}

.ai-form textarea {
  flex: 1;
  min-width: 0;
  min-height: 46px;
  max-height: 120px;
  padding: 11px 16px;
  overflow-y: hidden;
  border: 1px solid #d9d9d9;
  border-radius: 24px;
  color: var(--ink);
  background: #fff;
  outline: none;
  font: inherit;
  line-height: 1.55;
  resize: none;
  transition: border-color var(--duration-fast) ease, box-shadow var(--duration-fast) ease, background var(--duration-fast) ease;
}

.ai-form textarea::placeholder { color: #7c878b; }
.ai-form textarea:focus { border-color: #949494; background: #fff; box-shadow: 0 0 0 3px rgba(0, 0, 0, .06); }

.ai-form button {
  display: grid;
  flex: 0 0 42px;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: #fff;
  background: #111;
  font-size: 0;
  cursor: pointer;
  transition: transform var(--duration-fast) ease, background var(--duration-fast) ease;
}

.ai-form button svg { display: block; width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.ai-form button:hover { transform: translateY(-1px); background: #303030; }
.ai-form button:active { transform: scale(.95); }
.ai-form button:focus-visible { outline: 3px solid rgba(105, 201, 223, .3); outline-offset: 2px; }
.ai-form button:disabled { color: #fff; background: #d5d5d5; opacity: 1; transform: none; cursor: default; }

@media (max-width: 600px) {
  .ai-trigger { right: 16px; bottom: 16px; width: 48px; height: 48px; background-size: 40px 40px; }
  .ai-panel {
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    max-height: min(78dvh, 680px);
    border-right: 0;
    border-bottom: 0;
    border-left: 0;
    border-radius: 20px 20px 0 0;
  }
  .ai-body { min-height: 240px; max-height: none; }
  .ai-suggestions { padding-right: 16px; padding-left: 16px; }
  .ai-form { padding-bottom: max(14px, env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  .ai-trigger,
  .ai-close,
  .ai-form textarea,
  .ai-form button { transition: none; }
  .ai-message { animation: none; }
  .ai-typing__dot { animation: none; opacity: .55; }
}
