/* AI Overlay Styles - v833-AVATAR-PULSE */
:root {
  --ai-panel-width: 400px;
  --ai-bubble-size: 66px;
  --ai-z-index: 10000;
  --ai-safe-area-bottom: env(safe-area-inset-bottom, 20px);
  --ai-color-primary: #057d21;
  --ai-color-primary-2: #7ec72f;
  --ai-color-bg: linear-gradient(180deg, rgba(255, 255, 255, 0.992), rgba(244, 249, 243, 0.982));
  --ai-color-bg-soft: linear-gradient(180deg, rgba(252, 254, 251, 0.985), rgba(240, 247, 239, 0.972));
  --ai-color-border: rgba(95, 118, 103, 0.16);
  --ai-color-text: #244128;
  --ai-color-muted: #738674;
  --ai-color-card: rgba(255, 255, 255, 0.96);
}

/* --- Container --- */
#ai-overlay-container {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: var(--ai-z-index);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
}

#ai-overlay-container.active {
  opacity: 1;
  visibility: visible;
}

/* --- Trigger Bubble --- */
.ai-trigger-btn {
  position: fixed;
  bottom: calc(20px + var(--ai-safe-area-bottom));
  right: 20px;
  width: 74px;
  height: var(--ai-bubble-size);
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 255, 255, 0.58) 0%, rgba(255, 255, 255, 0) 38%),
    linear-gradient(145deg, #ffffff 0%, #eff9f1 48%, #d9f4df 100%);
  border-radius: 23px;
  box-shadow: 0 20px 42px rgba(39, 120, 56, 0.22), 0 8px 22px rgba(17, 62, 28, 0.16), inset 0 1px 0 rgba(255, 255, 255, 0.9);
  cursor: pointer;
  pointer-events: auto;
  display: flex !important;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 1px;
  transition: transform 0.22s, box-shadow 0.22s, filter 0.22s;
  z-index: 10001;
  border: 1px solid rgba(29, 92, 49, 0.22);
  color: #12371f;
  backdrop-filter: blur(16px);
  overflow: hidden;
}

.ai-trigger-btn:hover {
  transform: translateY(-2px) scale(1.06);
  box-shadow: 0 24px 46px rgba(39, 120, 56, 0.29), 0 11px 26px rgba(17, 62, 28, 0.2), inset 0 1px 0 rgba(255, 255, 255, 0.95);
  filter: saturate(1.06);
}

.ai-trigger-btn.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0) translateY(20px);
}

.ai-trigger-mark {
  width: 26px;
  height: 24px;
  display: grid;
  place-items: center;
  color: #1c8a3e;
  filter: drop-shadow(0 2px 5px rgba(29, 92, 49, 0.18));
}

.ai-trigger-label {
  color: #10281a;
  font-size: 20px;
  font-weight: 950;
  line-height: 0.94;
  letter-spacing: -0.08em;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.9);
}

.ai-trigger-btn::after {
  content: "Asistent";
  color: #41714e;
  font-size: 8px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

/* --- Panel --- */
.ai-panel {
  position: absolute;
  top: 70px;
  right: 20px;
  bottom: calc(20px + var(--ai-safe-area-bottom));
  width: var(--ai-panel-width);
  background: var(--ai-color-bg);
  border: 1px solid var(--ai-color-border);
  border-radius: 22px;
  box-shadow: -8px 0 32px rgba(28, 77, 29, 0.14);
  backdrop-filter: blur(12px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  pointer-events: auto;
  transform: translateX(120%);
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

#ai-overlay-container.open .ai-panel {
  transform: translateX(0);
}

/* --- Header --- */
.ai-header {
  padding: 12px 16px;
  border-bottom: 1px solid var(--ai-color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: linear-gradient(180deg, rgba(252,254,251,0.98), rgba(241,247,239,0.97));
  flex-shrink: 0;
}

.ai-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
}

.ai-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--ai-color-text);
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-status {
  font-size: 14px;
  line-height: 1;
}

.ai-status.disconnected {
  color: #d02013;
}

.ai-status.connected {
  color: #459522;
  text-shadow: 0 0 8px rgba(69, 149, 34, 0.18);
}

/* Header Controls (Settings + Close) */
.ai-header-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ai-icon-btn {
  background: linear-gradient(180deg, #ffffff 0%, #f2f7f1 100%);
  border: 1px solid var(--ai-color-border);
  cursor: pointer;
  color: #6e856f;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: all 0.2s;
}

.ai-icon-btn:hover {
  background: linear-gradient(180deg, #ffffff 0%, #edf7ea 100%);
  color: var(--ai-color-text);
}

.ai-icon-btn.hidden {
  display: none;
}

/* --- Tabs --- */
.ai-tabs {
  display: flex;
  border-bottom: 1px solid var(--ai-color-border);
  background: rgba(245, 249, 243, 0.92);
}

.ai-tab {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  color: #748675;
  font-weight: 600;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.ai-tab:hover {
  color: var(--ai-color-text);
  background: rgba(177, 234, 77, 0.08);
}

.ai-tab.active {
  color: var(--ai-color-primary);
  border-bottom-color: var(--ai-color-primary);
  background: rgba(177, 234, 77, 0.12);
}

/* --- Content Views --- */
.ai-content {
  position: relative;
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.ai-view {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  background: transparent;
}

.ai-view.active {
  display: flex;
}

/* --- Settings Modal --- */
.ai-settings-modal {
  position: absolute;
  inset: 0;
  background: rgba(16, 24, 18, 0.34);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  backdrop-filter: blur(4px);
}

.ai-settings-modal.hidden {
  display: none;
}

.ai-settings-card {
  background: var(--ai-color-bg-soft);
  border: 1px solid var(--ai-color-border);
  border-radius: 18px;
  padding: 20px;
  width: 90%;
  max-width: 320px;
  box-shadow: 0 18px 34px rgba(28, 77, 29, 0.12);
}

.ai-settings-card h3 {
  margin: 0 0 12px 0;
  font-size: 16px;
  color: var(--ai-color-text);
}

.ai-settings-card p {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: var(--ai-color-muted);
}

.ai-settings-card input {
  width: 100%;
  padding: 8px;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--ai-color-border);
  border-radius: 12px;
  color: var(--ai-color-text);
  font-size: 13px;
  margin-bottom: 16px;
  box-sizing: border-box;
  /* Fix for width + padding */
}

.ai-settings-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.ai-settings-actions button {
  padding: 6px 12px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
  border: none;
  font-weight: 500;
}

.btn-secondary {
  background: linear-gradient(180deg, #ffffff 0%, #f2f7f1 100%);
  color: #58705a;
  border: 1px solid var(--ai-color-border) !important;
}

.btn-secondary:hover {
  background: linear-gradient(180deg, #ffffff 0%, #edf7ea 100%);
  color: var(--ai-color-text);
}

.btn-primary {
  background: linear-gradient(135deg, #1c4d1d 0%, #057d21 56%, #7ec72f 100%);
  color: #ffffff;
}

.btn-primary:hover {
  filter: brightness(1.1);
}


/* --- Voice View (Center) --- */
.ai-voice-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  gap: 30px;
  text-align: center;
}

/* Avatar Animation & Styling */
.ai-avatar-container {
  width: 280px;
  height: 280px;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.5s ease;
}

.ai-avatar-img {
  width: 250px;
  height: 250px;
  border-radius: 50%;
  object-fit: cover;
  z-index: 2;
  border: 3px solid rgba(95, 118, 103, 0.26);
  /* Inactive border */
  transition: all 0.3s ease;
  background: #ffffff;
}

.ai-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--ai-color-primary);
  opacity: 0;
  z-index: 1;
  pointer-events: none;
}

/* ACTIVE States */
.ai-avatar-container.active .ai-avatar-img {
  border-color: var(--ai-color-primary);
  box-shadow: 0 0 20px rgba(69, 149, 34, 0.18);
}

/* LISTENING: Soft "Breathing" Pulse */
.ai-avatar-container.listening .ai-ring {
  animation: pulse-listening 2.5s infinite ease-in-out;
}

@keyframes pulse-listening {
  0% {
    transform: scale(0.85);
    opacity: 0;
    border-width: 1px;
  }

  50% {
    transform: scale(1.05);
    opacity: 0.4;
    border-width: 2px;
  }

  100% {
    transform: scale(1.15);
    opacity: 0;
    border-width: 0px;
  }
}

/* SPEAKING: Strong Ripple Pulse */
.ai-avatar-container.speaking .ai-avatar-img {
  transform: scale(1.05);
  box-shadow: 0 0 30px rgba(69, 149, 34, 0.26);
}

.ai-avatar-container.speaking .ai-ring {
  animation: pulse-speaking 1.2s infinite ease-out;
  border-color: #2dd4bf;
}

@keyframes pulse-speaking {
  0% {
    transform: scale(0.9);
    opacity: 0.8;
    border-width: 4px;
  }

  100% {
    transform: scale(1.4);
    opacity: 0;
    border-width: 0px;
  }
}


.ai-controls button {
  padding: 12px 24px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  border: none;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-connect {
  background: linear-gradient(135deg, #1c4d1d 0%, #057d21 56%, #7ec72f 100%);
  color: #ffffff;
  box-shadow: 0 10px 20px rgba(69, 149, 34, 0.18);
}

.btn-connect:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 22px rgba(69, 149, 34, 0.24);
}

.btn-disconnect {
  background: rgba(236, 0, 0, 0.08);
  color: #d02013;
  border: 1px solid rgba(208, 32, 19, 0.24);
}

.btn-disconnect:hover {
  background: rgba(236, 0, 0, 0.14);
}

.ai-permission-alert {
  background: rgba(236, 0, 0, 0.08);
  border: 1px solid rgba(208, 32, 19, 0.24);
  color: #920000;
  padding: 12px;
  border-radius: 8px;
  font-size: 13px;
  max-width: 90%;
  margin-top: 10px;
}

.ai-permission-alert.hidden {
  display: none;
}


/* --- Text View --- */
.ai-chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  position: relative;
  word-wrap: break-word;
}

.chat-msg.system {
  align-self: center;
  background: rgba(240, 247, 239, 0.92);
  color: #6f8571;
  font-size: 12px;
  border-radius: 20px;
  max-width: 90%;
}

.chat-msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, #1c4d1d 0%, #057d21 56%, #7ec72f 100%);
  color: #ffffff;
  font-weight: 500;
  border-bottom-right-radius: 4px;
}

.chat-msg.ai {
  align-self: flex-start;
  background: rgba(255, 255, 255, 0.96);
  color: var(--ai-color-text);
  border: 1px solid var(--ai-color-border);
  border-bottom-left-radius: 4px;
}

.msg-meta {
  font-size: 10px;
  opacity: 0.7;
  text-align: right;
  margin-top: 4px;
}

.ai-chat-input-area {
  padding: 12px;
  border-top: 1px solid var(--ai-color-border);
  background: rgba(245, 249, 243, 0.92);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#ai-chat-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid var(--ai-color-border);
  border-radius: 8px;
  padding: 10px;
  color: var(--ai-color-text);
  resize: none;
  font-size: 14px;
  min-height: 48px;
}

#ai-chat-input::placeholder {
  color: #8ea18f;
  opacity: 1;
}

#ai-chat-input:focus {
  outline: none;
  border-color: var(--ai-color-primary);
}

.ai-chat-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

#ai-chat-clear {
  background: linear-gradient(180deg, #ffffff 0%, #f2f7f1 100%);
  border: 1px solid var(--ai-color-border);
  font-size: 16px;
  cursor: pointer;
  opacity: 1;
  padding: 6px;
  color: #5f7767;
}

#ai-chat-clear:hover {
  opacity: 1;
  background: linear-gradient(180deg, #ffffff 0%, #edf7ea 100%);
}

#ai-chat-send {
  background: linear-gradient(135deg, #1c4d1d 0%, #057d21 56%, #7ec72f 100%);
  border: none;
  border-radius: 6px;
  padding: 6px 16px;
  color: #ffffff;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
}

#ai-chat-send:hover {
  filter: brightness(1.1);
}

/* --- Mobile --- */
@media (max-width: 768px) {
  .ai-panel {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 85vh;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
  }

  #ai-overlay-container.open .ai-panel {
    transform: translateY(0);
  }

  .ai-trigger-btn {
    bottom: calc(20px + var(--ai-safe-area-bottom));
    right: 16px;
    width: 70px;
    height: 62px;
  }
}
