/* Centrecom AI assistant */
.ai-launcher {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 150;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: left;
}

body.no-scroll .ai-launcher {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.ai-launcher-orb {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  background: linear-gradient(145deg, var(--ink) 0%, var(--ink-2) 45%, #0a7ea6 100%);
  color: var(--white);
  box-shadow: 0 18px 45px -18px rgba(4, 137, 183, 0.75);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.ai-launcher-orb::before {
  content: "";
  position: absolute;
  inset: -6px;
  border-radius: 50%;
  border: 1px solid rgba(5, 177, 235, 0.4);
  animation: ai-ring 3.2s ease-out infinite;
}

.ai-launcher-orb::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 50%;
  background: conic-gradient(from 120deg, transparent 0deg, rgba(127, 208, 247, 0.55) 70deg, transparent 140deg);
  opacity: 0.6;
  mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 2px));
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 2px), #000 calc(100% - 2px));
  animation: ai-spin 7s linear infinite;
}

.ai-launcher-orb:hover {
  transform: translateY(-3px) scale(1.03);
  box-shadow: 0 24px 55px -18px rgba(4, 137, 183, 0.9);
}

.ai-launcher-orb .icon {
  width: 28px;
  height: 28px;
}

.ai-launcher-label {
  display: inline-flex;
  flex-direction: column;
  gap: 1px;
  padding: 9px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}

.ai-launcher-label strong {
  font-size: 12.5px;
  font-weight: 600;
}

.ai-launcher-label span {
  font-size: 10.5px;
  color: var(--slate);
}

.ai-launcher-dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: var(--success);
  border: 2px solid var(--white);
}

.ai-launcher.is-hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(8px);
}

@keyframes ai-ring {
  0% {
    transform: scale(0.92);
    opacity: 0.65;
  }
  70% {
    transform: scale(1.28);
    opacity: 0;
  }
  100% {
    opacity: 0;
  }
}

@keyframes ai-spin {
  to {
    transform: rotate(360deg);
  }
}

/* Panel */
.ai-panel {
  position: fixed;
  right: 24px;
  bottom: 100px;
  z-index: 160;
  width: 392px;
  max-width: calc(100vw - 32px);
  height: min(620px, calc(100vh - 130px));
  display: flex;
  flex-direction: column;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 40px 90px -32px rgba(10, 27, 37, 0.5);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(14px) scale(0.98);
  transform-origin: bottom right;
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s;
}

.ai-panel.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
}

.ai-panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 15px 16px;
  background: linear-gradient(135deg, var(--ink) 0%, #0b3345 60%, #075f7c 100%);
  color: var(--white);
}

.ai-panel-avatar {
  position: relative;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, var(--sky), var(--azure) 55%, #066c92 100%);
  display: grid;
  place-items: center;
  flex: none;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.25);
}

.ai-panel-avatar .icon {
  width: 19px;
  height: 19px;
}

.ai-panel-avatar::after {
  content: "";
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--success);
  border: 2px solid #0b3345;
}

.ai-panel-title {
  min-width: 0;
}

.ai-panel-title strong {
  display: block;
  font-family: var(--font-display);
  font-size: 14.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.ai-panel-title span {
  display: block;
  font-size: 10.5px;
  color: rgba(255, 255, 255, 0.62);
  letter-spacing: 0.02em;
}

.ai-panel-actions {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.ai-icon-btn {
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.8);
  display: grid;
  place-items: center;
  transition: background 0.2s ease, color 0.2s ease;
}

.ai-icon-btn:hover {
  background: rgba(255, 255, 255, 0.14);
  color: var(--white);
}

.ai-icon-btn .icon {
  width: 16px;
  height: 16px;
}

.ai-icon-btn[aria-pressed="true"] {
  background: rgba(5, 177, 235, 0.26);
  color: var(--white);
}

.ai-new-chat {
  width: auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  gap: 6px;
  padding: 0 12px 0 10px;
  border-radius: 999px;
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.ai-new-chat .icon {
  width: 14px;
  height: 14px;
  flex: none;
}

/* Narrow panels keep a tidy icon-only button; the label stays for screen readers via aria-label. */
@media (max-width: 380px) {
  .ai-new-chat {
    width: 32px;
    padding: 0;
  }

  .ai-new-chat span {
    display: none;
  }
}

.ai-new-chat:disabled {
  opacity: 0.45;
  cursor: default;
}

.ai-new-chat:disabled:hover {
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.8);
}

/* Messages */
.ai-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 8px;
  background:
    radial-gradient(circle at 90% 0%, rgba(5, 177, 235, 0.06), transparent 42%),
    var(--white);
  scrollbar-width: thin;
}

.ai-offline-note {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 11px 13px;
  margin-bottom: 12px;
  border: 1px solid #efc56b;
  border-radius: 12px;
  background: #fff8e8;
  color: #6b4e00;
  font-size: 12px;
  line-height: 1.45;
}

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

.ai-offline-note strong {
  font-family: var(--font-display);
  font-size: 12.5px;
}

.ai-offline-note code {
  padding: 1px 4px;
  border-radius: 4px;
  background: rgba(107, 78, 0, 0.08);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11.5px;
}

.ai-offline-note a {
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
}

.ai-intro {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: linear-gradient(180deg, #ffffff, var(--cloud));
  margin-bottom: 14px;
}

.ai-intro strong {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-size: 14.5px;
}

.ai-intro strong .icon {
  width: 17px;
  height: 17px;
  color: var(--azure-dark);
}

.ai-intro p {
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.55;
  color: var(--slate);
}

.ai-suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.ai-suggestion {
  padding: 7px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--white);
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-2);
  transition: border-color 0.2s ease, background 0.2s ease;
}

.ai-suggestion:hover {
  border-color: var(--azure);
  background: rgba(5, 177, 235, 0.06);
}

.ai-messages {
  display: grid;
  gap: 12px;
}

.ai-msg {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  animation: ai-msg-in 0.22s ease both;
}

.ai-msg-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--cloud);
  color: var(--azure-dark);
  font-family: var(--font-display);
  font-size: 9px;
  font-weight: 600;
}

.ai-msg--bot .ai-msg-avatar {
  background: linear-gradient(135deg, var(--ink-2), var(--azure-dark));
  color: var(--white);
}

.ai-msg-bubble {
  max-width: 86%;
  padding: 10px 13px;
  border-radius: 12px;
  border-top-left-radius: 4px;
  background: var(--cloud);
  font-size: 12.8px;
  line-height: 1.55;
  color: var(--ink-2);
}

.ai-msg--user {
  flex-direction: row-reverse;
}

.ai-msg--user .ai-msg-avatar {
  background: var(--ink);
  color: var(--white);
}

.ai-msg--user .ai-msg-bubble {
  border-top-left-radius: 12px;
  border-top-right-radius: 4px;
  background: var(--ink);
  color: var(--white);
}

.ai-msg-bubble a {
  color: var(--azure-dark);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-msg--user .ai-msg-bubble a {
  color: var(--sky);
}

.ai-msg-bubble strong {
  font-weight: 600;
}

.ai-msg-bubble ul {
  margin: 6px 0 0 16px;
  padding: 0;
}

.ai-msg-bubble li {
  margin-bottom: 3px;
}

.ai-msg-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 9px;
}

.ai-msg-actions a {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 9px;
  border-radius: 6px;
  border: 1px solid rgba(5, 177, 235, 0.28);
  background: rgba(5, 177, 235, 0.08);
  font-size: 10.5px;
  font-weight: 600;
  color: var(--azure-dark);
  text-decoration: none;
}

.ai-msg-actions .icon {
  width: 12px;
  height: 12px;
}

.ai-msg-time {
  display: block;
  margin-top: 5px;
  font-size: 9.5px;
  color: var(--slate-2);
}

.ai-msg--user .ai-msg-time {
  color: rgba(255, 255, 255, 0.45);
}

@keyframes ai-msg-in {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* Typing */
.ai-typing {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 12px 14px;
}

.ai-typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--azure-dark);
  animation: ai-typing 1.2s infinite ease-in-out;
}

.ai-typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.ai-typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes ai-typing {
  0%,
  60%,
  100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

/* Listening */
.ai-listening {
  display: none;
  align-items: center;
  gap: 10px;
  margin: 0 16px 8px;
  padding: 11px 14px;
  border-radius: 10px;
  background: rgba(5, 177, 235, 0.1);
  border: 1px solid rgba(5, 177, 235, 0.28);
  color: var(--ink-2);
  font-size: 12px;
}

.ai-listening.is-visible {
  display: flex;
}

.ai-wave {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 18px;
}

.ai-wave span {
  width: 2.5px;
  border-radius: 2px;
  background: var(--azure-dark);
  animation: ai-wave 0.9s ease-in-out infinite;
}

.ai-wave span:nth-child(1) {
  height: 7px;
  animation-delay: 0s;
}

.ai-wave span:nth-child(2) {
  height: 14px;
  animation-delay: 0.1s;
}

.ai-wave span:nth-child(3) {
  height: 18px;
  animation-delay: 0.2s;
}

.ai-wave span:nth-child(4) {
  height: 11px;
  animation-delay: 0.3s;
}

.ai-wave span:nth-child(5) {
  height: 16px;
  animation-delay: 0.4s;
}

@keyframes ai-wave {
  0%,
  100% {
    transform: scaleY(0.45);
  }
  50% {
    transform: scaleY(1);
  }
}

.ai-listening-stop {
  margin-left: auto;
  border: 0;
  background: transparent;
  font-size: 11px;
  font-weight: 600;
  color: var(--azure-dark);
}

/* Composer */
.ai-composer {
  padding: 10px 12px 12px;
  border-top: 1px solid var(--line);
  background: var(--white);
}

.ai-composer-row {
  display: flex;
  align-items: flex-end;
  gap: 7px;
  padding: 7px 7px 7px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--white);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.ai-composer-row:focus-within {
  border-color: var(--azure);
  box-shadow: 0 0 0 3px rgba(5, 177, 235, 0.12);
}

.ai-input {
  flex: 1;
  border: 0;
  outline: none;
  resize: none;
  min-height: 32px;
  max-height: 100px;
  padding: 6px 0;
  font-size: 13px;
  line-height: 1.45;
  background: transparent;
}

.ai-input::placeholder {
  color: #94a3aa;
}

.ai-mic,
.ai-send {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
  flex: none;
  transition: background 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}

.ai-mic {
  background: var(--white);
  color: var(--ink-2);
}

.ai-mic:hover {
  border-color: var(--azure);
  color: var(--azure-dark);
}

.ai-mic.is-listening {
  background: rgba(200, 68, 60, 0.1);
  border-color: rgba(200, 68, 60, 0.4);
  color: var(--danger);
  animation: ai-mic-pulse 1.4s ease-out infinite;
}

.ai-mic .icon,
.ai-send .icon {
  width: 16px;
  height: 16px;
}

.ai-send {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--white);
}

.ai-send:hover {
  background: var(--azure);
  border-color: var(--azure);
  color: var(--ink);
}

.ai-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.ai-composer-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 7px;
  font-size: 9.5px;
  color: var(--slate-2);
}

.ai-composer-meta a {
  color: var(--ink-2);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.ai-unsupported {
  display: none;
  margin-top: 7px;
  font-size: 10px;
  color: var(--slate-2);
}

.ai-unsupported.is-visible {
  display: block;
}

@keyframes ai-mic-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(200, 68, 60, 0.22);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(200, 68, 60, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(200, 68, 60, 0);
  }
}

@media (max-width: 900px) {
  .ai-launcher-label {
    display: none;
  }
}

@media (max-width: 640px) {
  .ai-launcher {
    right: 16px;
    bottom: 16px;
  }

  .ai-launcher-orb {
    width: 58px;
    height: 58px;
  }

  .ai-launcher-label {
    display: none;
  }

  .ai-panel {
    right: 10px;
    left: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    width: auto;
    max-width: none;
    height: min(78vh, 640px);
    height: min(78dvh, 640px);
    border-radius: 20px;
    transform-origin: bottom center;
  }

  /* 16px stops iOS Safari zooming the page when the field is focused. */
  .ai-input {
    font-size: 16px;
  }

  .ai-panel-head {
    padding: 13px 14px;
  }

  .ai-new-chat {
    width: 32px;
    padding: 0;
  }

  .ai-new-chat span {
    display: none;
  }

  .ai-msg-bubble {
    max-width: 88%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ai-launcher-orb::before,
  .ai-launcher-orb::after,
  .marquee-track,
  .pin::before,
  .ai-mic.is-listening,
  .ai-wave span {
    animation: none;
  }

  html {
    scroll-behavior: auto;
  }
}
