/* ==============================================
   TCHAT WIDGET - Mobile-First Responsive CSS
   ============================================== */

/* ── Variables (overridden by JS from config) ── */
:root {
  --tchat-primary: #0ea5e9;
  --tchat-header-bg: #0ea5e9;
  --tchat-header-text: #ffffff;
  --tchat-msg-bg: #f3f4f6;
  --tchat-user-msg-bg: #0ea5e9;
  --tchat-user-msg-text: #ffffff;
  --tchat-agent-msg-text: #111827;
  --tchat-form-bg: #ffffff;
  --tchat-form-text: #111827;
  --tchat-border: #e5e7eb;
}

/* ── Bubble Button ── */
.tchat-bubble {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  cursor: pointer;
  z-index: 99998;
  transition: transform 0.3s cubic-bezier(.34,1.56,.64,1), box-shadow 0.3s ease;
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
  overflow: hidden;
  border: none;
  padding: 0;
  background: transparent;
}
.tchat-bubble:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(0,0,0,0.22);
}
.tchat-bubble:active {
  transform: scale(0.95);
}
.tchat-bubble img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.tchat-bubble--hidden {
  display: none !important;
}

/* ── Notification badge ── */
.tchat-bubble-badge {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 18px;
  height: 18px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 50%;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid #fff;
}
.tchat-bubble-badge.show {
  display: flex;
}

/* ── Chat Window Container ── */
.tchat-window {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 100%;
  height: 100%;
  max-height: 100dvh;
  z-index: 99999;
  display: flex;
  flex-direction: column;
  background: #fff;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px);
  transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
}
.tchat-window.open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

/* Desktop: floating panel */
@media (min-width: 500px) {
  .tchat-window {
    bottom: 90px;
    right: 20px;
    width: 400px;
    height: 600px;
    max-height: calc(100vh - 110px);
    border-radius: 16px;
    box-shadow: 0 12px 48px rgba(0,0,0,0.18);
    border: 1px solid var(--tchat-border);
    overflow: hidden;
  }
}

/* ── Header ── */
.tchat-header {
  background: var(--tchat-header-bg);
  color: var(--tchat-header-text);
  padding: 16px 16px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  position: relative;
}
.tchat-header-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255,255,255,0.3);
  flex-shrink: 0;
}
.tchat-header-info {
  flex: 1;
  min-width: 0;
}
.tchat-header-title {
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tchat-header-subtitle {
  font-size: 12px;
  opacity: 0.85;
  line-height: 1.3;
  margin-top: 2px;
}
.tchat-header-status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  opacity: 0.9;
  margin-top: 2px;
}
.tchat-header-status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
  display: inline-block;
}
.tchat-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}
.tchat-header-btn {
  background: rgba(255,255,255,0.15);
  border: none;
  color: inherit;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background 0.2s;
}
.tchat-header-btn:hover {
  background: rgba(255,255,255,0.25);
}

/* ── Form View ── */
.tchat-form-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px 16px;
  background: var(--tchat-form-bg);
  -webkit-overflow-scrolling: touch;
}
.tchat-form-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--tchat-form-text);
  margin-bottom: 4px;
}
.tchat-form-subtitle {
  font-size: 13px;
  color: #6b7280;
  margin-bottom: 20px;
  line-height: 1.4;
}
.tchat-form-group {
  margin-bottom: 14px;
}
.tchat-form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--tchat-form-text);
  margin-bottom: 5px;
}
.tchat-form-label .required {
  color: #ef4444;
  margin-left: 2px;
}
.tchat-form-input,
.tchat-form-textarea,
.tchat-form-select {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--tchat-border);
  border-radius: 10px;
  font-size: 14px;
  color: var(--tchat-form-text);
  background: #fff;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
  font-family: inherit;
  box-sizing: border-box;
}
.tchat-form-input:focus,
.tchat-form-textarea:focus,
.tchat-form-select:focus {
  border-color: var(--tchat-primary);
  box-shadow: 0 0 0 3px rgba(14,165,233,0.12);
}
.tchat-form-textarea {
  min-height: 80px;
  resize: vertical;
}
.tchat-form-error {
  font-size: 12px;
  color: #ef4444;
  margin-top: 4px;
  display: none;
}
.tchat-form-submit {
  width: 100%;
  padding: 12px;
  background: var(--tchat-primary);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
  margin-top: 6px;
  font-family: inherit;
}
.tchat-form-submit:hover {
  opacity: 0.9;
}
.tchat-form-submit:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ── Messages View ── */
.tchat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: #fafbfc;
  display: flex;
  flex-direction: column;
  gap: 6px;
  -webkit-overflow-scrolling: touch;
}

/* System event messages */
.tchat-event {
  text-align: center;
  padding: 8px 0;
}
.tchat-event-text {
  display: inline-block;
  background: #f3f4f6;
  color: #6b7280;
  font-size: 12px;
  padding: 5px 14px;
  border-radius: 20px;
  line-height: 1.3;
}
.tchat-event-text i {
  margin-right: 4px;
}

/* Wait indicator */
.tchat-waiting {
  text-align: center;
  padding: 24px 16px;
}
.tchat-waiting-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid #e5e7eb;
  border-top-color: var(--tchat-primary);
  border-radius: 50%;
  animation: tchat-spin 0.8s linear infinite;
  margin: 0 auto 12px;
}
@keyframes tchat-spin {
  to { transform: rotate(360deg); }
}
.tchat-waiting-text {
  font-size: 13px;
  color: #6b7280;
  line-height: 1.4;
}

/* Message bubbles */
.tchat-msg {
  display: flex;
  gap: 8px;
  max-width: 85%;
  animation: tchat-fadeIn 0.25s ease;
}
@keyframes tchat-fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.tchat-msg--agent {
  align-self: flex-start;
}
.tchat-msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.tchat-msg-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  margin-top: 2px;
}
.tchat-msg--user .tchat-msg-avatar {
  display: none;
}
.tchat-msg-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tchat-msg-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}
.tchat-msg--agent .tchat-msg-bubble {
  background: var(--tchat-msg-bg);
  color: var(--tchat-agent-msg-text);
  border-bottom-left-radius: 4px;
}
.tchat-msg--user .tchat-msg-bubble {
  background: var(--tchat-user-msg-bg);
  color: var(--tchat-user-msg-text);
  border-bottom-right-radius: 4px;
}
.tchat-msg-time {
  font-size: 10px;
  color: #9ca3af;
  padding: 0 4px;
}
.tchat-msg--user .tchat-msg-time {
  text-align: right;
}
.tchat-seen {
  margin-left: 6px;
  color: var(--tchat-primary, #6366f1);
  font-weight: 600;
  opacity: 0;
  animation: tchat-fade-in 0.3s ease forwards;
}
.tchat-seen-indicator {
  text-align: right;
  font-size: 11px;
  color: var(--tchat-primary, #6366f1);
  padding: 2px 4px 0;
  opacity: 0;
  animation: tchat-fade-in 0.3s ease forwards;
}
@keyframes tchat-fade-in {
  from { opacity: 0; transform: translateY(2px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Typing indicator */
.tchat-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
}
.tchat-typing-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}
.tchat-typing-dots {
  display: flex;
  gap: 4px;
  background: var(--tchat-msg-bg);
  padding: 10px 16px;
  border-radius: 16px;
  border-bottom-left-radius: 4px;
}
.tchat-typing-dots span {
  width: 7px;
  height: 7px;
  background: #9ca3af;
  border-radius: 50%;
  animation: tchat-bounce 1.4s infinite ease-in-out both;
}
.tchat-typing-dots span:nth-child(1) { animation-delay: -0.32s; }
.tchat-typing-dots span:nth-child(2) { animation-delay: -0.16s; }
@keyframes tchat-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Input area ── */
.tchat-input-area {
  padding: 10px 12px;
  border-top: 1px solid var(--tchat-border);
  background: #fff;
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.tchat-input-field {
  flex: 1;
  border: 1px solid var(--tchat-border);
  border-radius: 20px;
  padding: 10px 16px;
  font-size: 14px;
  outline: none;
  resize: none;
  min-height: 20px;
  max-height: 120px;
  line-height: 1.4;
  font-family: inherit;
  background: #f9fafb;
  transition: border-color 0.2s;
  box-sizing: border-box;
}
.tchat-input-field:focus {
  border-color: var(--tchat-primary);
  background: #fff;
}
.tchat-send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--tchat-primary);
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s, transform 0.15s;
  font-size: 16px;
}
.tchat-send-btn:hover {
  opacity: 0.9;
}
.tchat-send-btn:active {
  transform: scale(0.92);
}
.tchat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Restart bar ── */
.tchat-restart-bar {
  padding: 8px 12px;
  background: #f9fafb;
  border-top: 1px solid var(--tchat-border);
  display: flex;
  justify-content: center;
  flex-shrink: 0;
}
.tchat-restart-btn {
  background: none;
  border: 1px solid var(--tchat-border);
  color: #6b7280;
  font-size: 12px;
  padding: 6px 16px;
  border-radius: 20px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  font-family: inherit;
}
.tchat-restart-btn:hover {
  background: #f3f4f6;
  color: #374151;
}

/* ── Powered by (removed per requirement - no AI mention) ── */

/* ── iOS safe area ── */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .tchat-input-area {
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .tchat-restart-bar {
    padding-bottom: calc(8px + env(safe-area-inset-bottom));
  }
}

/* ── Scrollbar styling ── */
.tchat-messages::-webkit-scrollbar {
  width: 5px;
}
.tchat-messages::-webkit-scrollbar-track {
  background: transparent;
}
.tchat-messages::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 10px;
}
.tchat-form-container::-webkit-scrollbar {
  width: 5px;
}
.tchat-form-container::-webkit-scrollbar-track {
  background: transparent;
}
.tchat-form-container::-webkit-scrollbar-thumb {
  background: #d1d5db;
  border-radius: 10px;
}
