/* =========================================================
   NovaIT — saytdagi chat oynasi (assets/js/chat.js)
   Ranglar style.css tokenlaridan; tugma pastki burchakda
   (arabchada o‘ngda, inglizchada chapda — "yuqoriga" tugmasining qarshisida).
   ========================================================= */
.chat-root {
  position: fixed; z-index: 90;
  bottom: max(24px, calc(env(safe-area-inset-bottom, 0px) + 16px));
  inset-inline-start: max(24px, calc(env(safe-area-inset-left, 0px) + 16px));
  display: flex; flex-direction: column; align-items: flex-start; gap: 14px;
  font-family: var(--font-body);
}
html[lang="ar"] .chat-root { font-family: var(--font-ar-body); }

.chat-fab {
  position: relative; width: 60px; height: 60px; border-radius: 20px; display: grid; place-items: center;
  color: #fff; background: linear-gradient(135deg, var(--turq), var(--cobalt));
  box-shadow: 0 6px 0 color-mix(in srgb, var(--cobalt) 55%, #000), 0 18px 36px -14px var(--cobalt);
  transition: transform .18s var(--ease-out), box-shadow .18s var(--ease-out);
}
.chat-fab svg { width: 28px; height: 28px; }
.chat-fab:hover { transform: translateY(-2px); }
.chat-fab:active { transform: translateY(4px); box-shadow: 0 2px 0 color-mix(in srgb, var(--cobalt) 55%, #000), 0 10px 20px -14px var(--cobalt); }
.chat-fab:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.chat-fab__badge {
  position: absolute; top: -6px; inset-inline-end: -6px; min-width: 22px; height: 22px; padding: 0 6px; border-radius: 11px;
  display: grid; place-items: center; background: var(--gold); color: #1d1405; font: 700 12px/1 var(--font-body);
  box-shadow: 0 0 0 3px var(--bg);
}

.chat-panel {
  width: min(380px, calc(100vw - 32px)); height: min(560px, calc(100dvh - 140px));
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  transform-origin: bottom left; animation: chat-in .22s var(--ease-out);
}
html[dir="rtl"] .chat-panel { transform-origin: bottom right; }
.chat-panel[hidden] { display: none; }
@keyframes chat-in { from { opacity: 0; transform: translateY(10px) scale(.97); } }

.chat-head {
  display: flex; align-items: center; gap: 12px; padding: 14px 16px;
  background: linear-gradient(135deg, color-mix(in srgb, var(--turq) 22%, var(--surface)), color-mix(in srgb, var(--cobalt) 26%, var(--surface)));
  border-bottom: 1px solid var(--line);
}
.chat-head__avatar {
  width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--turq), var(--cobalt)); color: #fff; font: 700 17px/1 var(--font-display);
}
.chat-head__text { display: grid; gap: 2px; min-width: 0; flex: 1; }
.chat-head__text strong { font: 700 16px/1.2 var(--font-display); }
.chat-head__status { font-size: 13px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.chat-head__status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--turq); box-shadow: 0 0 0 3px color-mix(in srgb, var(--turq) 25%, transparent); }
.chat-head__close { width: 36px; height: 36px; border-radius: 11px; display: grid; place-items: center; color: var(--muted); flex: none; }
.chat-head__close:hover { background: var(--surface-2); color: var(--text); }
.chat-head__close svg { width: 20px; height: 20px; }

.chat-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
.chat-msg { max-width: 86%; padding: 10px 14px; border-radius: 16px; display: grid; gap: 4px; }
.chat-msg p { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; font-size: 15px; }
.chat-msg time { font-size: 11px; opacity: .62; justify-self: end; }
.chat-msg--bot, .chat-msg--team { align-self: flex-start; background: var(--surface-2); border: 1px solid var(--line); border-end-start-radius: 6px; }
.chat-msg--team { border-color: color-mix(in srgb, var(--gold) 45%, var(--line)); }
.chat-msg__who { font-size: 12px; font-weight: 700; color: var(--gold-ink); }
.chat-msg--me { align-self: flex-end; color: #fff; background: linear-gradient(135deg, var(--turq), var(--cobalt)); border-end-end-radius: 6px; }

.chat-typing { display: flex; gap: 5px; padding: 0 20px 10px; }
.chat-typing[hidden] { display: none; }
.chat-typing i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); animation: chat-dot 1s infinite ease-in-out; }
.chat-typing i:nth-child(2) { animation-delay: .15s; }
.chat-typing i:nth-child(3) { animation-delay: .3s; }
@keyframes chat-dot { 0%, 80%, 100% { opacity: .3; transform: translateY(0); } 40% { opacity: 1; transform: translateY(-4px); } }

.chat-chips { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; }
.chat-chips[hidden] { display: none; }
.chat-chip {
  padding: 8px 13px; border-radius: 999px; font-size: 13.5px; font-weight: 600;
  border: 1px solid color-mix(in srgb, var(--turq) 45%, var(--line)); color: var(--text); background: color-mix(in srgb, var(--turq) 8%, transparent);
}
.chat-chip:hover { background: color-mix(in srgb, var(--turq) 18%, transparent); }

.chat-intro { display: grid; gap: 8px; margin: 0 12px 10px; padding: 12px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line); }
.chat-intro[hidden] { display: none; }
.chat-intro p { margin: 0; font-size: 13.5px; color: var(--muted); line-height: 1.5; }
.chat-intro input {
  width: 100%; padding: 10px 12px; border-radius: 11px; border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit; font-size: 15px;
}
html[dir="rtl"] .chat-intro input[dir="ltr"] { text-align: right; }
.chat-intro__row { display: flex; align-items: center; gap: 10px; }
.chat-intro__send { padding: 9px 18px; font-size: 14px; }
.chat-intro__later { font-size: 13.5px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; }

.chat-error { margin: 0 16px 8px; font-size: 13px; color: var(--danger); }
.chat-error[hidden] { display: none; }

.chat-composer { display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px 12px; border-top: 1px solid var(--line); }
.chat-composer textarea {
  flex: 1; resize: none; max-height: 120px; padding: 11px 14px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 15px; line-height: 1.4;
}
.chat-composer textarea:focus, .chat-intro input:focus { outline: 2px solid color-mix(in srgb, var(--turq) 70%, transparent); outline-offset: 0; }
.chat-send {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; flex: none; color: #fff;
  background: linear-gradient(135deg, var(--turq), var(--cobalt));
}
.chat-send svg { width: 20px; height: 20px; }
html[dir="rtl"] .chat-send svg { transform: scaleX(-1); }
.chat-send:disabled { opacity: .5; }

/* Telefonda: oyna pastdan ochiladigan varaq */
@media (max-width: 520px) {
  .chat-root.is-open { inset: auto 0 0 0; padding: 0; gap: 0; }
  .chat-root.is-open .chat-fab { display: none; }
  .chat-root.is-open .chat-panel { width: 100%; height: min(85dvh, 640px); border-radius: var(--radius) var(--radius) 0 0; padding-bottom: env(safe-area-inset-bottom, 0px); }
}

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