/* Live Technician (KTV) Support UI Styles — Composer Chip, Customer 360 & Right-side Chat Popup */

/* ---------- Composer chip (next to "Kết nối máy") ---------- */
.btn-live-ktv {
  cursor: pointer;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.btn-live-ktv[hidden] {
  display: none !important;
}

.btn-live-ktv:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-live-ktv svg {
  width: 15px;
  height: 15px;
  color: var(--brand-2);
  flex-shrink: 0;
}

.btn-live-ktv.is-active {
  border-color: var(--brand-2);
  background: var(--brand-soft);
  color: var(--text);
}

.live-chip-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--brand-2);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.live-chip-badge[hidden] {
  display: none !important;
}

/* ---------- Right-side KTV Chat Popup Panel ---------- */
.live-panel {
  width: 390px;
  flex-shrink: 0;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg-soft);
  border-left: 1px solid var(--border);
  z-index: 45;
  animation: live-panel-in 0.2s var(--ease);
}

.live-panel[hidden] {
  display: none !important;
}

.live-panel.is-dragover {
  outline: 2px dashed var(--brand-2);
  outline-offset: -4px;
}

@keyframes live-panel-in {
  from {
    opacity: 0;
    transform: translateX(16px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.live-backdrop {
  display: none;
}

.live-backdrop[hidden] {
  display: none !important;
}

@media (max-width: 960px) {
  .live-panel {
    position: fixed;
    inset: 0 0 0 auto;
    width: min(94vw, 390px);
    box-shadow: var(--shadow-lg);
    z-index: 55;
  }
  .live-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: var(--overlay);
    z-index: 50;
  }
}

/* Panel Header */
.live-panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.live-head-icon {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--brand-soft);
  color: var(--brand-2);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.live-head-icon svg {
  width: 18px;
  height: 18px;
}

.live-head-info {
  flex: 1;
  min-width: 0;
}

.live-head-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-head-sub {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-2);
  margin-top: 2px;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--brand-2);
  flex-shrink: 0;
}

.live-dot.is-waiting {
  background: var(--warning);
  animation: live-pulse 1.2s ease-in-out infinite;
}

.live-dot.is-offline {
  background: var(--text-3);
}

@keyframes live-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

.btn-live-end {
  min-height: 28px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  color: var(--danger);
  flex-shrink: 0;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.btn-live-end:hover {
  background: var(--danger-soft);
  border-color: var(--danger);
}

/* Customer 360 Bar inside panel */
.live-customer-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-2);
  flex-shrink: 0;
}

.live-customer-bar[hidden] {
  display: none !important;
}

.live-customer-bar svg {
  width: 14px;
  height: 14px;
  color: var(--brand-2);
  flex-shrink: 0;
}

.live-customer-bar-text {
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.live-customer-bar-text b {
  color: var(--text);
}

/* Panel Messages Area */
.live-panel-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.live-welcome-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-2);
}

.live-welcome-card b {
  color: var(--text);
}

/* Auth Gate Card (when not logged in via Phone OTP) */
.live-auth-gate {
  margin: 0 14px 10px;
  padding: 14px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.live-auth-gate[hidden] {
  display: none !important;
}

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

.live-auth-gate-title svg {
  width: 16px;
  height: 16px;
  color: var(--brand-2);
  flex-shrink: 0;
}

.live-auth-gate-desc {
  font-size: 12.5px;
  line-height: 1.45;
  color: var(--text-2);
  margin: 0;
}

.btn-live-login {
  width: 100%;
  min-height: 38px;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
  border: none;
  font-size: 13.5px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  cursor: pointer;
  transition: filter 0.15s;
}

.btn-live-login:hover {
  filter: brightness(1.08);
}

.btn-live-login svg {
  width: 16px;
  height: 16px;
}

/* Message bubbles inside KTV panel */
.live-msg {
  display: flex;
  flex-direction: column;
  max-width: 88%;
  animation: msg-in 0.18s var(--ease);
}

.live-msg-user {
  align-self: flex-end;
  align-items: flex-end;
}

.live-msg-ktv {
  align-self: flex-start;
  align-items: flex-start;
}

.live-msg-meta {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-3);
  margin-bottom: 3px;
  padding: 0 4px;
}

.live-msg-ktv .live-msg-meta {
  color: var(--brand-2);
}

.live-msg-bubble {
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.live-msg-user .live-msg-bubble {
  background: var(--brand);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.live-msg-ktv .live-msg-bubble {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.live-msg-status {
  font-size: 10.5px;
  color: var(--text-3);
  margin-top: 2px;
  padding: 0 4px;
  line-height: 1.2;
}

.live-msg-status.is-sending {
  opacity: 0.75;
}

.live-msg-status.is-error {
  color: var(--danger);
  font-weight: 600;
}

.live-msg-img-link {
  display: block;
  border-radius: 10px;
  overflow: hidden;
  max-width: 240px;
}

.live-msg-img {
  display: block;
  width: 100%;
  max-height: 220px;
  object-fit: cover;
  border-radius: 10px;
}

.live-msg-file {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.14);
  color: inherit;
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 600;
  max-width: 240px;
}

.live-msg-ktv .live-msg-file {
  background: var(--surface-2);
  border: 1px solid var(--border);
}

.live-msg-file svg {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
}

.live-msg-file span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.live-msg-system {
  align-self: center;
  max-width: 94%;
  text-align: center;
  font-size: 12px;
  line-height: 1.45;
  color: var(--text-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  padding: 6px 12px;
  border-radius: 10px;
}

/* Attachment preview bar above input */
.live-attach-preview {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  margin-bottom: 8px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 12.5px;
  color: var(--text);
}

.live-attach-preview[hidden] {
  display: none !important;
}

.live-attach-thumb {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.live-attach-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 500;
}

.live-attach-remove {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  flex-shrink: 0;
}

.live-attach-remove svg {
  width: 12px;
  height: 12px;
}

/* Panel Footer Composer */
.live-panel-foot {
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.live-input-row {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  background: var(--bg-soft);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 6px 8px;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.live-input-row:focus-within {
  border-color: var(--brand-2);
  box-shadow: 0 0 0 2px var(--brand-ring);
}

.live-attach-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--text-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  padding: 0;
  transition: background 0.15s, color 0.15s;
}

.live-attach-btn:hover {
  background: var(--surface-2);
  color: var(--brand-2);
}

.live-attach-btn svg {
  width: 16px;
  height: 16px;
}

.live-input {
  flex: 1;
  min-width: 0;
  border: none;
  background: transparent;
  color: var(--text);
  font-family: inherit;
  font-size: 13.5px;
  line-height: 1.45;
  resize: none;
  max-height: 96px;
  padding: 3px 0;
  outline: none;
}

.live-input::placeholder {
  color: var(--text-3);
}

.live-send-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: var(--brand);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s, filter 0.15s;
}

.live-send-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.live-send-btn svg {
  width: 15px;
  height: 15px;
}

/* Keep legacy banner hidden since status lives inside the right panel */
.live-banner {
  display: none !important;
}

/* ---------- Mobile Optimization (<= 768px & <= 640px) ---------- */
@media (max-width: 768px) {
  .btn-live-ktv {
    flex-shrink: 0;
    white-space: nowrap;
    font-size: 12.5px;
    padding: 5px 11px;
  }

  .live-panel-messages {
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 12px;
  }

  /* Prevent iOS Safari / Android Chrome auto-zoom on input focus */
  .live-input {
    font-size: 16px;
    line-height: 1.4;
    padding: 4px 2px;
  }

  .live-attach-btn,
  .live-send-btn {
    width: 36px;
    height: 36px;
  }

  .live-attach-btn svg {
    width: 18px;
    height: 18px;
  }

  .live-send-btn svg {
    width: 16px;
    height: 16px;
  }
}

@media (max-width: 640px) {
  .live-panel {
    position: fixed;
    inset: 0;
    width: 100%;
    max-width: 100%;
    height: 100dvh;
    border-left: none;
    box-shadow: none;
    z-index: 60;
    animation: live-panel-mobile-in 0.2s var(--ease);
  }

  @keyframes live-panel-mobile-in {
    from {
      opacity: 0;
      transform: translateY(14px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  .live-panel-head {
    padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
    gap: 8px;
  }

  .live-panel-head #btn-live-close {
    width: 36px;
    height: 36px;
  }

  .live-customer-bar {
    padding: 7px 12px;
    font-size: 11.5px;
  }

  .live-msg {
    max-width: 90%;
  }

  .live-msg-img-link {
    max-width: min(220px, 70vw);
  }

  .live-msg-img {
    max-height: 190px;
  }

  .live-panel-foot {
    padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  }

  .live-input-row {
    padding: 5px 7px;
    border-radius: 18px;
  }
}
