/* ==========================================================================
   Yordam (qo'llab-quvvatlash chati) — alohida sahifa /support
   Foydalanuvchi: bitta suhbat. Xodim: murojaatlar ro'yxati + tanlangan suhbat.
   ========================================================================== */

.support-standalone {
  padding-bottom: 0;
}

/* Bu oynada profil sahifasi yo'q, shuning uchun chiqish tugmasi telefonda ham ko'rinadi */
@media (max-width: 640px) {
  .support-standalone #btn-logout {
    display: inline-flex;
  }
}

.support-page {
  padding-top: 24px;
  padding-bottom: 32px;
}

.support-head {
  margin-bottom: 18px;
}

.support-head-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px 16px;
  flex-wrap: wrap;
}

.support-title {
  font-size: 2rem;
  margin-bottom: 4px;
}

.support-subtitle {
  font-size: 0.95rem;
  color: var(--text-muted);
}

.support-unread-pill {
  padding: 6px 14px;
  border-radius: var(--radius-full);
  background: var(--blue);
  color: var(--ink);
  font-family: var(--font-display);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.support-gate {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  min-height: 320px;
  padding: 24px;
  text-align: center;
  border: 2px dashed var(--surface-border);
  border-radius: var(--radius-xl);
  color: var(--text-muted);
}

.support-gate strong {
  color: var(--text-main);
  font-size: 1.1rem;
}

/* ---------- Chat oynasi ---------- */
.chat-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: clamp(440px, calc(100vh - 250px), 760px);
  height: clamp(440px, calc(100dvh - 250px), 760px);
  background: var(--surface-card);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.support-user-pane {
  max-width: 820px;
  margin: 0 auto;
}

.chat-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chat-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  border-bottom: 1px solid var(--surface-border);
}

.chat-head-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-head-info strong {
  font-family: var(--font-display);
  font-size: 1.05rem;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--text-main);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-note {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.chat-back {
  display: none;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: 1.5px solid var(--surface-border);
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text-main);
  cursor: pointer;
}

.chat-messages {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 16px 20px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background: var(--surface-bg);
}

.chat-empty {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  max-width: 320px;
  text-align: center;
  color: var(--text-muted);
}

.chat-empty strong {
  color: var(--text-main);
}

.chat-day {
  align-self: center;
  margin: 10px 0 4px;
  padding: 3px 12px;
  border-radius: var(--radius-full);
  background: var(--surface-muted);
  font-size: 0.75rem;
  color: var(--text-muted);
}

.chat-row {
  display: flex;
}

.chat-row.is-mine {
  justify-content: flex-end;
}

.chat-bubble {
  max-width: min(78%, 520px);
  padding: 8px 12px 6px;
  border-radius: 16px;
  background: var(--surface-card);
  border: 1px solid var(--surface-border);
  color: var(--text-main);
  overflow-wrap: anywhere;
}

.chat-row.is-theirs .chat-bubble {
  border-bottom-left-radius: 5px;
}

.chat-row.is-mine .chat-bubble {
  background: var(--blue);
  border-color: var(--blue);
  color: var(--ink);
  border-bottom-right-radius: 5px;
}

.chat-author {
  display: block;
  margin-bottom: 2px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--primary-600);
}

.chat-row.is-mine .chat-author {
  color: inherit;
  opacity: 0.75;
}

.chat-text {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.4;
}

.chat-time {
  display: block;
  margin-top: 2px;
  text-align: right;
  font-size: 0.7rem;
  opacity: 0.65;
}

.chat-tick {
  margin-left: 4px;
  font-size: 0.75rem;
  letter-spacing: -0.2em;
  opacity: 0.55;
}

/* Ko'rildi: ikkita belgi, to'liq ko'rinadi va rangi bilan ajraladi (och ko'k fonda to'q ko'k) */
.chat-tick.is-seen {
  opacity: 1;
  color: var(--deep);
  font-weight: 700;
  letter-spacing: -0.15em;
}

/* "Yozmoqda...": Instagramdagi kabi o'ynab turadigan uchta nuqta */
.chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 12px 14px;
}

.chat-typing i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: chat-dot-bounce 1.2s infinite ease-in-out;
}

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

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

@keyframes chat-dot-bounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.45;
  }
  30% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

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

.chat-form {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid var(--surface-border);
  background: var(--surface-card);
}

.chat-input {
  flex: 1;
  min-width: 0;
  max-height: 140px;
  padding: 11px 14px;
  font-family: inherit;
  font-size: 1rem; /* 16px: iOS yozish paytida sahifani kattalashtirmasligi uchun */
  line-height: 1.35;
  color: var(--text-main);
  background: var(--surface-bg);
  border: 1.5px solid var(--surface-border);
  border-radius: 22px;
  outline: none;
  resize: none;
  overflow-y: hidden;
  transition: border-color var(--transition-fast);
}

.chat-input:focus {
  border-color: var(--surface-border-focus);
}

.chat-send {
  flex-shrink: 0;
  height: 46px;
}

/* ---------- Xodim: murojaatlar ro'yxati ---------- */
.support-staff-grid {
  display: grid;
  grid-template-columns: minmax(280px, 360px) 1fr;
  gap: 18px;
  align-items: start;
}

.inbox {
  height: clamp(440px, calc(100vh - 250px), 760px);
  height: clamp(440px, calc(100dvh - 250px), 760px);
  overflow-y: auto;
  background: var(--surface-card);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-md);
}

.inbox-empty {
  padding: 28px 20px;
  text-align: center;
  color: var(--text-muted);
}

.inbox-list {
  list-style: none;
  margin: 0;
  padding: 6px;
}

.inbox-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 0;
  border-radius: var(--radius-lg);
  background: transparent;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
}

@media (hover: hover) {
  .inbox-item:hover {
    background: var(--surface-muted);
  }
}

.inbox-item.active {
  background: var(--primary-50);
}

.inbox-avatar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-full);
  background: var(--solid-bg);
  color: var(--solid-fg);
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
}

.inbox-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.inbox-top {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.inbox-top strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  color: var(--text-main);
}

.inbox-top time {
  flex-shrink: 0;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.inbox-preview {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.inbox-preview.is-typing {
  font-style: italic;
  color: var(--primary-600);
}

.inbox-item.unread .inbox-preview {
  color: var(--text-main);
  font-weight: 600;
}

.inbox-badge {
  flex-shrink: 0;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--blue);
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
}

.chat-pick {
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 24px;
  text-align: center;
  color: var(--text-muted);
}

.chat-pick strong {
  color: var(--text-main);
}

/* ---------- Telefon / planshet ---------- */
@media (max-width: 860px) {
  .support-staff-grid {
    grid-template-columns: 1fr;
  }

  /* Bir vaqtda bittasi: ro'yxat yoki tanlangan suhbat ("orqaga" tugmasi bilan qaytiladi) */
  .support-staff-grid.thread-open .inbox,
  .support-staff-grid:not(.thread-open) #staff-chat {
    display: none;
  }

  .chat-back {
    display: inline-flex;
  }
}

@media (max-width: 640px) {
  .support-page {
    padding-top: 14px;
    padding-bottom: 14px;
  }

  .support-title {
    font-size: 1.5rem;
  }

  .support-subtitle {
    font-size: 0.88rem;
  }

  .chat-pane,
  .inbox {
    height: calc(100vh - 190px);
    height: calc(100dvh - 190px);
    min-height: 360px;
    border-radius: var(--radius-lg);
  }

  .chat-head {
    padding: 12px 14px;
  }

  .chat-messages {
    padding: 12px 12px;
  }

  .chat-bubble {
    max-width: 88%;
  }

  .chat-form {
    padding: 10px 10px calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .chat-send {
    padding-left: 16px;
    padding-right: 16px;
  }
}


/* ---------- AI yordamchi, holat belgisi, rasm (chek) ---------- */
.chat-head {
  flex-wrap: wrap;
}

.chat-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  background: var(--surface-muted);
  border: 1px solid var(--surface-border);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
}

.chat-status-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #22a06b; /* AI faol — yashil */
  animation: chat-status-pulse 1.6s infinite ease-in-out;
}

.chat-status[data-status="operator_called"] .chat-status-dot {
  background: #e5a100; /* operator chaqirildi, kutilmoqda — sariq */
}

.chat-status[data-status="operator_connected"] .chat-status-dot {
  background: var(--blue); /* operator ulandi */
}

@keyframes chat-status-pulse {
  0%, 100% {
    box-shadow: 0 0 0 0 rgba(34, 160, 107, 0.45);
  }
  50% {
    box-shadow: 0 0 0 6px rgba(34, 160, 107, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-status-dot {
    animation: none;
  }
}

.chat-row.is-system {
  justify-content: center;
}

.chat-system {
  max-width: 88%;
  padding: 6px 14px;
  border-radius: var(--radius-lg);
  background: var(--surface-muted);
  border: 1px dashed var(--surface-border);
  font-size: 0.82rem;
  line-height: 1.4;
  text-align: center;
  color: var(--text-muted);
}

.chat-bubble.is-ai {
  border-style: dashed;
}

.chat-img {
  display: block;
  width: 100%;
  max-width: 280px;
  min-height: 90px;
  margin-bottom: 6px;
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  object-fit: cover;
  cursor: zoom-in;
}

.chat-img.is-broken {
  cursor: default;
  font-size: 0.8rem;
}

.chat-attach {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 1.5px solid var(--surface-border);
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition-fast), border-color var(--transition-fast);
}

@media (hover: hover) {
  .chat-attach:hover {
    color: var(--primary-600);
    border-color: var(--primary-200);
  }
}

.chat-form {
  flex-wrap: wrap;
}

.chat-preview {
  flex: 1 0 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  font-size: 0.85rem;
  color: var(--text-main);
}

.chat-preview img {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
}

.chat-preview span {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-preview button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  font-size: 1.3rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
}

/* Operator ko'rinishi: foydalanuvchi tezkor ma'lumoti, operator kerak belgisi */
.chat-info {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  padding: 8px 20px;
  border-bottom: 1px solid var(--surface-border);
  background: var(--surface-muted);
  font-size: 0.82rem;
  color: var(--text-muted);
}

.chat-info b {
  color: var(--text-main);
}

.inbox-item.needs-operator {
  background: rgba(220, 53, 69, 0.08);
}

.inbox-alert-dot {
  flex-shrink: 0;
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #dc3545;
  box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.5);
  animation: inbox-alert-pulse 1.4s infinite;
}

@keyframes inbox-alert-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.5);
  }
  70%, 100% {
    box-shadow: 0 0 0 8px rgba(220, 53, 69, 0);
  }
}

.inbox-flag {
  font-size: 0.75rem;
  font-weight: 700;
  color: #dc3545;
}

.support-unread-pill.is-alert {
  background: #dc3545;
  color: #fff;
}

@media (prefers-reduced-motion: reduce) {
  .inbox-alert-dot {
    animation: none;
  }
}

@media (max-width: 640px) {
  .chat-status {
    margin-left: 0;
    flex-basis: 100%;
    justify-content: center;
  }

  .chat-info {
    padding: 8px 14px;
  }
}

@media (max-width: 640px) {
  /* Tor ekranda yozish maydoniga ko'proq joy */
  .chat-form {
    gap: 6px;
  }

  .chat-attach {
    width: 40px;
    height: 40px;
  }

  .chat-send {
    height: 42px;
    padding-left: 12px;
    padding-right: 12px;
    font-size: 0.85rem;
  }
}

/* ---------- Telefon: klaviatura ochilganda sahifa joyidan qo'zg'almasligi uchun ----------
   Sahifa ko'rinadigan oynaga (visualViewport) mixlanadi: sarlavha doim tepada, chat qolgan joyni egallaydi,
   klaviatura chiqqanda brauzer sahifani suradigan joy qolmaydi. --app-vh/--app-top ni support-app.js yangilaydi. */
@media (max-width: 860px) {
  html.support-locked {
    overflow: hidden;
    height: 100%;
  }

  .support-standalone {
    position: fixed;
    top: var(--app-top, 0px);
    left: 0;
    right: 0;
    height: var(--app-vh, 100dvh);
    min-height: 0;
    overflow: hidden;
  }

  .support-standalone .app-header,
  .support-standalone .test-banner {
    position: static;
    flex-shrink: 0;
  }

  .support-standalone .app-main {
    flex: 1 1 0;
    min-height: 0;
    overflow: hidden;
  }

  .support-standalone .support-page {
    display: flex;
    flex-direction: column;
    flex: 1 1 0;
    min-height: 0;
    padding-top: 10px;
    padding-bottom: 10px;
  }

  .support-standalone .support-page.hidden {
    display: none;
  }

  .support-standalone .support-head {
    flex-shrink: 0;
    margin-bottom: 10px;
  }

  /* Klaviatura ochiq: sarlavha matni joyni egallamasin */
  .support-standalone.kb-open .support-head {
    display: none;
  }

  .support-standalone .chat-pane,
  .support-standalone .inbox {
    height: auto;
    min-height: 0;
    flex: 1 1 0;
  }

  .support-standalone .support-staff-grid {
    flex: 1 1 0;
    min-height: 0;
    grid-template-rows: minmax(0, 1fr);
  }

  .support-standalone .support-staff-grid .chat-pane,
  .support-standalone .support-staff-grid .inbox {
    height: 100%;
  }

  .support-standalone .support-gate {
    flex: 1;
    min-height: 0;
  }
}
