/* AgentKaro chat assistant */

.ak-chat {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 200;
  font-family: var(--font);
  color: var(--ink);
}

.ak-chat-launcher {
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  background: linear-gradient(160deg, var(--teal-mid) 0%, var(--teal) 100%);
  color: #fff;
  box-shadow: 0 12px 28px rgba(14, 107, 98, 0.35), 0 0 0 4px rgba(201, 146, 42, 0.22);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s var(--ease), box-shadow 0.2s var(--ease);
}
.ak-chat-launcher:hover {
  transform: translateY(-2px) scale(1.04);
  box-shadow: 0 16px 32px rgba(14, 107, 98, 0.4), 0 0 0 4px rgba(201, 146, 42, 0.3);
}
.ak-chat-launcher:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 3px;
}
.ak-chat-launcher svg { width: 28px; height: 28px; display: block; }
.ak-chat.is-open .ak-chat-launcher { display: none; }

.ak-chat-panel {
  display: none;
  width: min(392px, calc(100vw - 24px));
  height: min(620px, calc(100vh - 32px));
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  flex-direction: column;
  transform-origin: bottom right;
}
.ak-chat.is-open .ak-chat-panel {
  display: flex;
  animation: ak-chat-in 0.28s var(--ease);
}
@keyframes ak-chat-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.ak-chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 14px 12px 16px;
  background: linear-gradient(160deg, var(--ink-soft) 0%, var(--teal) 100%);
  color: var(--cream);
}
.ak-chat-avatar {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--gold);
  color: var(--ink);
  font-family: var(--display);
  font-weight: 700;
  font-size: 1.2rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.ak-chat-head-text { flex: 1; min-width: 0; }
.ak-chat-head-text strong {
  display: block;
  font-family: var(--display);
  font-size: 1.05rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.2;
}
.ak-chat-status {
  display: block;
  font-size: 0.75rem;
  opacity: 0.85;
  font-weight: 500;
}
.ak-chat-close {
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 253, 248, 0.12);
  color: var(--cream);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ak-chat-close:hover { background: rgba(255, 253, 248, 0.22); }
.ak-chat-close svg { width: 16px; height: 16px; }

.ak-chat-langs {
  display: flex;
  gap: 6px;
  padding: 10px 12px;
  background: var(--cream);
  border-bottom: 1px solid var(--line);
}
.ak-chat-langs button {
  flex: 1;
  border: 1px solid var(--line-strong);
  background: var(--paper);
  color: var(--ink-soft);
  border-radius: 999px;
  padding: 6px 8px;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
  line-height: 1.3;
}
.ak-chat-langs button[aria-pressed="true"] {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
.ak-chat-langs button:focus-visible {
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}

.ak-chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 8px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background:
    radial-gradient(circle at top right, rgba(201, 146, 42, 0.08), transparent 40%),
    var(--paper);
}

.ak-chat-bubble {
  max-width: 86%;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 0.92rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}
.ak-chat-bubble[data-role="assistant"] {
  align-self: flex-start;
  background: var(--cream);
  border: 1px solid var(--line);
  border-bottom-left-radius: 4px;
  color: var(--ink);
}
.ak-chat-bubble[data-role="user"] {
  align-self: flex-end;
  background: var(--teal);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.ak-chat[data-lang="ur"] .ak-chat-bubble,
.ak-chat[data-lang="ur"] .ak-chat-langs button[data-lang="ur"],
.ak-chat[data-lang="ur"] textarea.ak-chat-input,
.ak-chat[data-lang="ur"] .ak-chat-status,
.ak-chat[data-lang="ur"] .ak-chat-send {
  font-family: "Noto Nastaliq Urdu", "Noto Naskh Arabic", "Noto Sans Arabic", var(--font);
}
.ak-chat[data-lang="ur"] .ak-chat-bubble,
.ak-chat[data-lang="ur"] textarea.ak-chat-input {
  line-height: 2;
  font-size: 0.95rem;
}

.ak-chat-typing {
  align-self: flex-start;
  display: inline-flex;
  gap: 5px;
  padding: 12px 14px;
  background: var(--cream);
  border: 1px solid var(--line);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.ak-chat-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--teal);
  opacity: 0.35;
  animation: ak-dot 1s ease-in-out infinite;
}
.ak-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.ak-chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes ak-dot {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

.ak-chat-compose {
  padding: 8px 0 0;
  background: var(--cream);
  border-top: 1px solid var(--line);
}
.ak-chat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 0 12px 8px;
}
.ak-chat-chips[hidden] { display: none; }
.ak-chat-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  background: var(--paper);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 4px 8px 4px 4px;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-soft);
}
.ak-chat-chip img {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.ak-chat-chip-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--teal-pale);
  color: var(--teal);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 0.65rem;
}
.ak-chat-chip-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
}
.ak-chat-chip-x {
  border: 0;
  background: transparent;
  cursor: pointer;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
}
.ak-chat-attach-error {
  color: var(--danger);
  font-size: 0.75rem;
  padding: 0 12px 6px;
}
.ak-chat-attach-error:empty { display: none; }
.ak-chat-form {
  display: block;
  padding: 0;
  border-top: 0;
  background: var(--cream);
}
.ak-chat-row {
  display: flex;
  gap: 6px;
  padding: 0 12px 10px;
  align-items: flex-end;
}
.ak-chat-icon {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  background: var(--paper);
  color: var(--teal);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.ak-chat-icon svg { width: 20px; height: 20px; display: block; }
.ak-chat-icon:hover { border-color: var(--teal); background: var(--teal-pale); }
.ak-chat-icon:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.ak-chat-mic.is-recording {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
  animation: ak-mic 1s ease-in-out infinite;
}
@keyframes ak-mic {
  50% { opacity: 0.72; }
}
.ak-chat-input {
  flex: 1;
  resize: none;
  min-height: 42px;
  max-height: 96px;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  padding: 10px 12px;
  background: var(--paper);
  line-height: 1.4;
  overflow-x: hidden;
}
.ak-chat-input::placeholder {
  color: var(--muted);
}
.ak-chat-input:focus {
  outline: 2px solid var(--teal-bright);
  outline-offset: 0;
  border-color: var(--teal);
}
.ak-chat-send {
  flex-shrink: 0;
  border: 0;
  border-radius: 12px;
  background: var(--gold);
  color: var(--ink);
  font-weight: 800;
  font-size: 0.82rem;
  padding: 10px 12px;
  cursor: pointer;
  min-height: 42px;
}
.ak-chat-send:hover { background: #d4a13a; }
.ak-chat-send:disabled { opacity: 0.55; cursor: default; }
.ak-chat-msg-files {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  opacity: 0.9;
}

.ak-chat-hint {
  font-size: 0.7rem;
  color: var(--muted);
  padding: 0 14px 8px;
  background: var(--cream);
  text-align: center;
}

.ak-chat[data-dir="rtl"] .ak-chat-log { direction: rtl; }
.ak-chat[data-dir="rtl"] .ak-chat-bubble[data-role="assistant"] {
  border-bottom-left-radius: 14px;
  border-bottom-right-radius: 4px;
}
.ak-chat[data-dir="rtl"] .ak-chat-bubble[data-role="user"] {
  border-bottom-right-radius: 14px;
  border-bottom-left-radius: 4px;
}
.ak-chat[data-dir="rtl"] .ak-chat-row { flex-direction: row-reverse; }
.ak-chat[data-dir="rtl"] .ak-chat-head { flex-direction: row-reverse; }
.ak-chat[data-dir="rtl"] .ak-chat-head-text { text-align: right; }

@media (max-width: 520px) {
  .ak-chat {
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    pointer-events: none;
  }
  .ak-chat-launcher {
    pointer-events: auto;
    position: absolute;
    right: 16px;
    bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  }
  .ak-chat-panel {
    pointer-events: auto;
    width: 100%;
    height: min(92vh, 680px);
    border-radius: 18px 18px 0 0;
    border-left: 0;
    border-right: 0;
    border-bottom: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .ak-chat-panel, .ak-chat-launcher, .ak-chat-typing span { animation: none; transition: none; }
}
