/* ============================================
   MINAX AI Customer Service - Styles
   Brand: Blue #3732DC | White #FFFFFF
   ============================================ */

:root {
  --brand: #3732DC;
  --brand-hover: #4A45E8;
  --brand-light: rgba(55, 50, 220, 0.10);
  --brand-lighter: rgba(55, 50, 220, 0.05);
  --accent: #EB5F41;
  --black: #1A1A1A;
  --dark-gray: #2A2A2A;
  --medium-gray: #444444;
  --light-gray: #F7F7FA;
  --border-gray: #E2E2EA;
  --white: #FFFFFF;
  --text-primary: #1A1A1A;
  --text-secondary: #666666;
  --text-muted: #999999;
  --shadow-sm: 0 1px 3px rgba(55, 50, 220, 0.06);
  --shadow-md: 0 4px 12px rgba(55, 50, 220, 0.08);
  --shadow-lg: 0 8px 24px rgba(55, 50, 220, 0.12);
  --shadow-xl: 0 12px 36px rgba(55, 50, 220, 0.16);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---- Reset & Base ---- */

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  color: var(--text-primary);
  background: var(--light-gray);
  line-height: 1.6;
  overflow-x: hidden;
  min-height: 100vh;
}

a {
  color: var(--brand);
  text-decoration: none;
  transition: color var(--transition);
}

a:hover {
  color: var(--brand-hover);
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  background: none;
}

input, textarea {
  font-family: inherit;
  outline: none;
  border: none;
}

/* ---- Header ---- */

.header {
  background: var(--white);
  padding: 0 20px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 0 var(--border-gray);
}

.header-logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.header-logo-icon {
  width: 28px;
  height: 28px;
  background: var(--brand);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  color: var(--white);
}

.header-logo-text {
  color: var(--text-primary);
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
}

.header-logo-text span {
  color: var(--brand);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.lang-toggle {
  background: var(--light-gray);
  color: var(--text-primary);
  border: 1px solid var(--border-gray);
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 6px;
}

.lang-toggle:hover {
  background: var(--brand-light);
  border-color: var(--brand);
  color: var(--brand);
}

.lang-toggle-icon {
  font-size: 14px;
}

/* ---- Chat Header ---- */

.chat-header {
  background: var(--white);
  color: var(--text-primary);
  padding: 14px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-gray);
}

.chat-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chat-header-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.chat-header-avatar img {
  width: 100%;
  height: 100%;
}

.chat-header-info h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
}

.chat-header-info p {
  font-size: 12px;
  color: var(--brand);
  font-weight: 500;
}

.chat-header-close {
  color: var(--text-secondary);
  font-size: 22px;
  padding: 4px;
  border-radius: 50%;
  transition: background var(--transition);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chat-header-close:hover {
  background: var(--light-gray);
}

/* ---- Chat Messages ---- */

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--light-gray);
  -webkit-overflow-scrolling: touch;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-gray);
  border-radius: 4px;
}

/* ---- Chat Bubbles ---- */

.chat-msg {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: msgIn 0.3s ease;
}

@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.chat-msg.user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
  margin-top: 2px;
  overflow: hidden;
}

.chat-msg-avatar img {
  width: 100%;
  height: 100%;
}

.chat-msg.assistant .chat-msg-avatar {
  background: var(--brand);
  color: var(--white);
  font-weight: 700;
}

.chat-msg.user .chat-msg-avatar {
  background: var(--brand-light);
  color: var(--brand);
  font-size: 13px;
  font-weight: 600;
}

.chat-msg-bubble {
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
}

.chat-msg.assistant .chat-msg-bubble {
  background: var(--white);
  color: var(--text-primary);
  border: 1px solid var(--border-gray);
  border-top-left-radius: 4px;
}

.chat-msg.user .chat-msg-bubble {
  background: var(--brand);
  color: var(--white);
  border-top-right-radius: 4px;
}

.chat-msg-bubble p {
  margin-bottom: 8px;
}

.chat-msg-bubble p:last-child {
  margin-bottom: 0;
}

.chat-msg-bubble a {
  color: var(--brand);
  text-decoration: underline;
}

.chat-msg.user .chat-msg-bubble a {
  color: var(--white);
  opacity: 0.9;
}

.chat-msg-bubble strong {
  font-weight: 700;
}

/* ---- Welcome Screen ---- */

.chat-welcome {
  text-align: center;
  padding: 24px 16px;
}

.chat-welcome-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  border-radius: 50%;
  overflow: hidden;
}

.chat-welcome-icon img {
  width: 100%;
  height: 100%;
}

.chat-welcome h3 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.chat-welcome p {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.chat-quick-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-quick-btn {
  background: var(--white);
  border: 1px solid var(--border-gray);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  font-size: 13px;
  color: var(--text-primary);
  text-align: left;
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 8px;
}

.chat-quick-btn:hover {
  border-color: var(--brand);
  background: var(--brand-lighter);
  color: var(--brand);
}

.chat-quick-btn-icon {
  font-size: 16px;
  flex-shrink: 0;
}

/* ---- Typing Indicator ---- */

.typing-indicator {
  display: flex;
  gap: 8px;
  max-width: 88%;
  animation: msgIn 0.3s ease;
}

.typing-indicator .chat-msg-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--brand);
  color: var(--white);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  flex-shrink: 0;
  overflow: hidden;
}

.typing-indicator .chat-msg-avatar img {
  width: 100%;
  height: 100%;
}

.typing-dots {
  background: var(--white);
  border: 1px solid var(--border-gray);
  border-radius: var(--radius-lg);
  border-top-left-radius: 4px;
  padding: 12px 18px;
  display: flex;
  gap: 5px;
  align-items: center;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  background: var(--brand);
  border-radius: 50%;
  animation: typingBounce 1.2s infinite;
  opacity: 0.4;
}

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

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

@keyframes typingBounce {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* ---- Chat Input ---- */

.chat-input-area {
  padding: 12px 16px;
  background: var(--white);
  border-top: 1px solid var(--border-gray);
  display: flex;
  gap: 10px;
  align-items: flex-end;
  flex-shrink: 0;
}

.chat-input-wrapper {
  flex: 1;
  position: relative;
}

.chat-input-wrapper textarea {
  width: 100%;
  min-height: 40px;
  max-height: 120px;
  padding: 10px 14px;
  border: 1px solid var(--border-gray);
  border-radius: var(--radius-md);
  font-size: 14px;
  resize: none;
  line-height: 1.5;
  background: var(--light-gray);
  color: var(--text-primary);
  transition: all var(--transition);
}

.chat-input-wrapper textarea::placeholder {
  color: var(--text-muted);
}

.chat-input-wrapper textarea:focus {
  border-color: var(--brand);
  background: var(--white);
  box-shadow: 0 0 0 2px var(--brand-light);
}

.chat-send-btn {
  width: 40px;
  height: 40px;
  background: var(--brand);
  color: var(--white);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  transition: all var(--transition);
  flex-shrink: 0;
}

.chat-send-btn:hover {
  background: var(--brand-hover);
  transform: scale(1.05);
}

.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  transform: none;
}

/* ---- Error Message ---- */

.chat-error {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: #FFF3F3;
  border: 1px solid #FFCCCC;
  border-radius: var(--radius-md);
  font-size: 13px;
  color: #CC3333;
  animation: msgIn 0.3s ease;
}

.chat-error-retry {
  margin-left: auto;
  background: #CC3333;
  color: white;
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  transition: background var(--transition);
  flex-shrink: 0;
}

.chat-error-retry:hover {
  background: #AA2222;
}

/* ---- Loading ---- */

.loading-spinner {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
}

.loading-spinner::after {
  content: '';
  width: 28px;
  height: 28px;
  border: 3px solid var(--border-gray);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ============================================
   Fullscreen Chat Mode
   ============================================ */

.chat-fullscreen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: var(--light-gray);
}

.chat-fullscreen .chat-header {
  border-radius: 0;
  padding: 12px 20px;
  background: var(--white);
  border-bottom: 1px solid var(--border-gray);
}

.chat-fullscreen .chat-header-avatar {
  width: 38px;
  height: 38px;
}

.chat-fullscreen .chat-messages {
  flex: 1;
  padding: 24px;
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
}

.chat-fullscreen .chat-input-area {
  max-width: 800px;
  width: 100%;
  margin: 0 auto;
  padding: 16px 24px 24px;
  border-top: none;
  background: var(--light-gray);
}

.chat-fullscreen .chat-input-wrapper textarea {
  min-height: 48px;
  padding: 14px 18px;
  font-size: 15px;
  border-radius: var(--radius-lg);
}

.chat-fullscreen .chat-send-btn {
  width: 48px;
  height: 48px;
  font-size: 20px;
}

.chat-fullscreen .chat-welcome {
  padding: 60px 20px 40px;
}

.chat-fullscreen .chat-welcome-icon {
  width: 64px;
  height: 64px;
  margin-bottom: 20px;
}

.chat-fullscreen .chat-welcome h3 {
  font-size: 22px;
  margin-bottom: 8px;
}

.chat-fullscreen .chat-welcome p {
  font-size: 15px;
  margin-bottom: 28px;
}

.chat-fullscreen .chat-quick-actions {
  max-width: 400px;
  margin: 0 auto;
}

.chat-fullscreen .chat-quick-btn {
  padding: 14px 18px;
  font-size: 14px;
  border-radius: var(--radius-lg);
}

.chat-fullscreen .chat-msg {
  max-width: 80%;
}

.chat-fullscreen .chat-msg-bubble {
  padding: 12px 18px;
  font-size: 15px;
}

.chat-fullscreen .header-actions {
  display: flex;
  align-items: center;
}

/* ---- Chat Float Button (Widget Mode) ---- */

.chat-float-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  width: 56px;
  height: 56px;
  background: var(--brand);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  transition: all var(--transition);
  color: var(--white);
  font-size: 24px;
}

.chat-float-btn:hover {
  transform: scale(1.08);
  box-shadow: var(--shadow-xl);
  background: var(--brand-hover);
}

.chat-float-btn.hidden {
  transform: scale(0);
  opacity: 0;
  pointer-events: none;
}

/* ---- Chat Panel (Widget Mode) ---- */

.chat-panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 299;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
}

.chat-panel-overlay.active {
  opacity: 1;
  visibility: visible;
}

.chat-panel {
  position: fixed;
  bottom: 0;
  right: 0;
  width: 100%;
  height: 100%;
  max-width: 420px;
  max-height: 680px;
  background: var(--white);
  z-index: 300;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  opacity: 0;
  transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: var(--radius-xl) var(--radius-xl) 0 0;
  box-shadow: var(--shadow-xl);
  overflow: hidden;
}

@media (min-width: 480px) {
  .chat-panel {
    bottom: 20px;
    right: 20px;
    border-radius: var(--radius-xl);
    height: calc(100% - 40px);
  }
}

.chat-panel.active {
  transform: translateY(0);
  opacity: 1;
}

/* ---- Utility ---- */

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 14px;
}

.empty-state-icon {
  font-size: 36px;
  margin-bottom: 12px;
}

/* ---- Satisfaction Rating ---- */

.chat-rating {
  display: flex;
  gap: 4px;
  margin-top: 6px;
  padding-left: 36px;
}

.chat-fullscreen .chat-rating {
  padding-left: 36px;
}

.chat-rating-btn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all var(--transition);
  background: transparent;
}

.chat-rating-btn:hover {
  background: var(--brand-light);
  color: var(--brand);
}

.chat-rating-btn.active {
  color: var(--brand);
  background: var(--brand-light);
}

.chat-rating-btn svg {
  width: 16px;
  height: 16px;
}

.chat-rating-thanks {
  font-size: 12px;
  color: var(--text-muted);
  padding-left: 4px;
  display: flex;
  align-items: center;
}

/* ---- Header Action Buttons ---- */

.header-action-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  transition: all var(--transition);
  font-size: 16px;
}

.header-action-btn:hover {
  background: var(--brand-light);
  color: var(--brand);
}

.header-action-btn svg {
  width: 18px;
  height: 18px;
}

/* ---- CTA Action Link in Bubbles ---- */

.chat-msg-bubble .chat-cta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 8px 16px;
  background: var(--brand);
  color: var(--white) !important;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none !important;
  transition: all var(--transition);
}

.chat-msg-bubble .chat-cta:hover {
  background: var(--brand-hover);
  transform: translateY(-1px);
}

.chat-msg-bubble .chat-cta::after {
  content: " \2192";
}

/* ---- Search Highlight ---- */

mark {
  background: rgba(55, 50, 220, 0.15);
  color: var(--brand);
  padding: 1px 2px;
  border-radius: 2px;
}

/* ---- Search Results ---- */

.search-results {
  display: none;
  padding: 0 20px 20px;
}

.search-results.active {
  display: block;
}

.search-result-item {
  background: var(--white);
  border: 1px solid var(--border-gray);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-bottom: 8px;
  cursor: pointer;
  transition: all var(--transition);
}

.search-result-item:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow-sm);
}

.search-result-item h4 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.search-result-item p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
}

/* ---- FAQ Section ---- */

.faq-section {
  display: none;
  padding: 0 20px 20px;
}

.faq-section.active {
  display: block;
}

.faq-section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.faq-back-btn {
  color: var(--brand);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  background: none;
  border: none;
  padding: 4px 0;
}

.faq-section-title {
  font-size: 16px;
  font-weight: 600;
}

.faq-item {
  background: var(--white);
  border: 1px solid var(--border-gray);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  overflow: hidden;
}

.faq-question {
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background var(--transition);
}

.faq-question:hover {
  background: var(--brand-lighter);
}

.faq-question-arrow {
  font-size: 10px;
  color: var(--text-muted);
  transition: transform 0.2s;
}

.faq-item.open .faq-question-arrow {
  transform: rotate(180deg);
}

.faq-answer {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s ease;
}

.faq-item.open .faq-answer {
  max-height: 500px;
}

.faq-answer-content {
  padding: 0 16px 14px;
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.7;
}

/* ============================================
   Mobile Responsive
   ============================================ */

@media (max-width: 480px) {
  .chat-fullscreen .chat-messages {
    padding: 12px;
  }

  .chat-fullscreen .chat-input-area {
    padding: 10px 12px 16px;
  }

  .chat-fullscreen .chat-input-wrapper textarea {
    min-height: 40px;
    padding: 10px 14px;
    font-size: 14px;
  }

  .chat-fullscreen .chat-send-btn {
    width: 40px;
    height: 40px;
    font-size: 18px;
  }

  .chat-fullscreen .chat-welcome {
    padding: 32px 12px 24px;
  }

  .chat-fullscreen .chat-welcome-icon {
    width: 48px;
    height: 48px;
  }

  .chat-fullscreen .chat-welcome h3 {
    font-size: 18px;
  }

  .chat-fullscreen .chat-welcome p {
    font-size: 13px;
    margin-bottom: 16px;
  }

  .chat-fullscreen .chat-msg {
    max-width: 90%;
  }

  .chat-fullscreen .chat-msg-bubble {
    padding: 10px 14px;
    font-size: 14px;
  }

  .chat-header {
    padding: 10px 12px;
    height: auto;
    min-height: 48px;
  }

  .chat-header-avatar {
    width: 32px;
    height: 32px;
  }

  .chat-header-info h3 {
    font-size: 14px;
  }

  .header-actions {
    gap: 6px;
  }

  .header-action-btn {
    width: 30px;
    height: 30px;
  }

  .lang-toggle {
    padding: 4px 10px;
    font-size: 12px;
  }

  .chat-rating {
    padding-left: 0;
  }

  .chat-fullscreen .chat-rating {
    padding-left: 0;
  }
}

/* Admin responsive */
@media (max-width: 768px) {
  .admin-container {
    padding: 12px;
  }

  .admin-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    white-space: nowrap;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .admin-tabs::-webkit-scrollbar {
    display: none;
  }

  .admin-responsive-table {
    display: block;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .admin-responsive-table table {
    min-width: 600px;
  }
}
