/* MySifa — Agent IA (widget flottant) */
#ai-chat-root {
  display: none;
}
#ai-chat-root.ai-on-portal #ai-chat-btn {
  right: max(24px, env(safe-area-inset-right, 0px));
}
#ai-chat-root.ai-on-portal #ai-chat-panel {
  right: max(24px, env(safe-area-inset-right, 0px));
}
#ai-chat-btn {
  position: fixed;
  bottom: max(24px, env(safe-area-inset-bottom, 0px));
  right: max(24px, env(safe-area-inset-right, 0px));
  z-index: 8003;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(34, 211, 238, 0.35);
  transition: transform 0.18s, box-shadow 0.18s;
}
#ai-chat-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(34, 211, 238, 0.5);
}
#ai-chat-btn svg {
  display: block;
  color: var(--bg);
}
#ai-chat-panel {
  position: fixed;
  bottom: 84px;
  right: max(24px, env(safe-area-inset-right, 0px));
  z-index: 8002;
  width: 360px;
  height: 500px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  transform-origin: bottom right;
  transform: scale(0.9) translateY(10px);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.15s,
    visibility 0s linear 0.15s;
  overflow: hidden;
}
#ai-chat-panel.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  z-index: 8004;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.15s, visibility 0s;
}
#ai-chat-header {
  padding: 12px 16px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
#ai-chat-header .ai-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  animation: ai-pulse 2s infinite;
}
@keyframes ai-pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
}
#ai-chat-header .ai-title {
  flex: 1;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}
#ai-chat-header .ai-sub {
  font-size: 10px;
  color: var(--muted);
  display: block;
  font-weight: 400;
}
#ai-chat-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  padding: 4px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  transition: color 0.15s;
}
#ai-chat-close:hover {
  color: var(--text);
}
#ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.ai-msg {
  display: flex;
  flex-direction: column;
  max-width: 86%;
}
.ai-msg.bot {
  align-self: flex-start;
}
.ai-msg.user {
  align-self: flex-end;
}
.ai-label {
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 3px;
}
.ai-msg.user .ai-label {
  text-align: right;
}
.ai-bubble {
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.5;
  word-break: break-word;
}
.ai-msg.bot .ai-bubble {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 3px;
}
.ai-msg.user .ai-bubble {
  background: var(--accent);
  color: var(--bg);
  font-weight: 600;
  border-bottom-right-radius: 3px;
}
.ai-status {
  display: inline-block;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 20px;
  margin-top: 4px;
  font-weight: 600;
}
.ai-status.ok {
  background: rgba(52, 211, 153, 0.15);
  color: var(--ok);
  border: 1px solid var(--ok);
}
.ai-status.err {
  background: rgba(248, 113, 113, 0.15);
  color: var(--danger);
  border: 1px solid var(--danger);
}
.ai-status.info {
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid var(--accent);
}
#ai-typing {
  display: none;
  align-self: flex-start;
  padding: 8px 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  border-bottom-left-radius: 3px;
  gap: 4px;
  align-items: center;
}
#ai-typing.visible {
  display: flex;
}
.ai-dot-t {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--muted);
  animation: ai-bounce 1.2s infinite;
}
.ai-dot-t:nth-child(2) {
  animation-delay: 0.2s;
}
.ai-dot-t:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes ai-bounce {
  0%,
  60%,
  100% {
    transform: translateY(0);
  }
  30% {
    transform: translateY(-4px);
  }
}
#ai-input-area {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
  background: var(--card);
}
#ai-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  padding: 8px 12px;
  resize: none;
  max-height: 80px;
  min-height: 36px;
  outline: none;
  line-height: 1.4;
  transition: border-color 0.15s;
}
#ai-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.1);
}
#ai-send {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: filter 0.15s;
}
#ai-send:hover {
  filter: brightness(1.1);
}
#ai-send:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}
#ai-send svg {
  color: var(--bg);
}
.ai-confirm-actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}
.ai-confirm-btn {
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text2);
  font-family: inherit;
  transition: filter 0.15s, border-color 0.15s;
}
.ai-confirm-btn:hover {
  filter: brightness(1.05);
}
.ai-confirm-btn.primary {
  background: var(--accent);
  color: var(--bg);
  border-color: var(--accent);
}
@media (max-width: 900px) {
  #ai-chat-root.ai-on-portal #ai-chat-btn,
  #ai-chat-btn {
    right: max(24px, env(safe-area-inset-right, 0px));
    z-index: 8002;
  }
  #ai-chat-panel {
    left: max(12px, env(safe-area-inset-left, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    width: auto;
    max-width: min(420px, calc(100vw - 24px));
    margin-left: auto;
    margin-right: auto;
    transform-origin: bottom center;
  }
  #ai-chat-panel.open {
    transform: scale(1) translateY(0);
    z-index: 8016;
  }
}

@media (max-width: 900px) and (orientation: landscape) {
  #ai-chat-panel.open {
    top: max(8px, env(safe-area-inset-top, 0px));
    left: max(12px, env(safe-area-inset-left, 0px));
    right: max(12px, env(safe-area-inset-right, 0px));
    width: auto;
    max-width: none;
    margin: 0;
    height: calc(100dvh - 72px);
    max-height: calc(100dvh - 72px);
    bottom: max(62px, calc(env(safe-area-inset-bottom, 0px) + 62px));
    transform-origin: bottom center;
  }
  #ai-messages {
    min-height: 0;
  }
}
