/* Area chat: window, bubble, composer, quick action, jawaban terstruktur,
   badge source/confidence, typing indicator, empty state, toast, modal. */

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

.chat-window {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 26px 32px 8px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ---------- Empty state ---------- */

.empty-state {
  margin: auto;
  max-width: 560px;
  text-align: center;
  padding: 32px 16px;
}

.empty-state__icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 16px;
  border-radius: var(--radius-lg);
  background: linear-gradient(135deg, var(--color-primary), var(--color-accent));
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}

.empty-state h2 {
  margin: 0 0 8px;
  font-size: var(--fs-heading);
  font-weight: 700;
}

.empty-state p {
  margin: 0 0 20px;
  color: var(--color-text-secondary);
  line-height: 1.55;
  font-size: 0.88rem;
}

.empty-state__examples {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.example-chip {
  padding: 8px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 0.8rem;
  cursor: pointer;
  transition: border-color var(--transition-fast), background var(--transition-fast), transform var(--transition-fast);
}

.example-chip:hover {
  border-color: var(--color-primary);
  background: var(--badge-info-bg);
  transform: translateY(-1px);
}

.example-chip:active { transform: translateY(0) scale(0.97); }

/* ---------- Message row & bubble ---------- */

.message-row {
  display: flex;
  gap: 10px;
  animation: message-in 0.22s ease both;
}

@media (prefers-reduced-motion: reduce) {
  .message-row { animation: none; }
}

/* Proporsi lebar bubble: chatbot lebih lega untuk jawaban panjang (~72%),
   pesan pengguna lebih ringkas karena biasanya berupa pertanyaan singkat
   (~65%) -- lihat permintaan polishing bagian C. */
.message-row.user {
  align-self: flex-end;
  flex-direction: row-reverse;
  max-width: 65%;
}

.message-row.bot {
  align-self: flex-start;
  max-width: 72%;
}

@keyframes message-in {
  from { opacity: 0; transform: translateY(5px); }
  to { opacity: 1; transform: translateY(0); }
}

.avatar {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  color: #fff;
  margin-top: 2px;
}

.avatar--bot { background: linear-gradient(135deg, var(--color-primary), var(--color-secondary)); }
.avatar--user { background: var(--color-text-secondary); }

.message-content {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.msg {
  padding: 13px 17px;
  border-radius: var(--radius-md);
  line-height: 1.6;
  font-size: var(--fs-body);
  box-shadow: var(--shadow-soft);
  overflow-wrap: anywhere;
}

.message-row.user .msg {
  background: var(--bubble-user-bg);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 4px;
}

.message-row.bot .msg {
  background: var(--bubble-bot-bg);
  color: var(--bubble-bot-text);
  border: 1px solid var(--bubble-bot-border);
  border-bottom-left-radius: 4px;
}

.msg p { margin: 0 0 10px; }
.msg p:last-child { margin-bottom: 0; }
.msg > *:first-child { margin-top: 0; }
.msg > *:last-child { margin-bottom: 0; }

.msg-lead {
  color: var(--color-text-secondary);
  font-size: 0.85rem;
}

.message-row.user .msg-lead { color: rgba(255,255,255,0.85); }

.msg-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  padding: 0 2px;
}

.message-row.user .msg-footer { justify-content: flex-end; }

.msg-timestamp {
  font-size: 0.7rem;
  color: var(--color-text-muted);
  opacity: 0.8;
}

/* ---------- Badge source/confidence ----------
   Sengaja digabung SATU BARIS dengan timestamp di .msg-footer (bukan baris
   sendiri di atasnya) supaya source/confidence terasa sebagai metadata
   kecil, bukan elemen yang mendominasi jawaban -- lihat permintaan
   polishing bagian H ("source dan confidence tidak mendominasi"). */

.badge-row {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  font-size: 0.68rem;
  font-weight: 500;
  cursor: default;
}

.badge--source {
  background: var(--badge-neutral-bg);
  color: var(--badge-neutral-text);
}

.badge--confidence-high { background: var(--badge-success-bg); color: var(--badge-success-text); }
.badge--confidence-mid { background: var(--badge-info-bg); color: var(--badge-info-text); }
.badge--confidence-low { background: var(--badge-warning-bg); color: var(--badge-warning-text); }
.badge--confidence-verylow { background: var(--badge-danger-bg); color: var(--badge-danger-text); }

/* ---------- Jawaban terstruktur ---------- */

.answer-steps {
  list-style: none;
  margin: 4px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.answer-steps li {
  position: relative;
  display: flex;
  gap: 10px;
  padding: 4px 0 14px 0;
}

.answer-steps li:last-child { padding-bottom: 0; }

.answer-steps li::before {
  content: counter(step);
  counter-increment: step;
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.answer-steps {
  counter-reset: step;
}

.answer-steps li:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 11px;
  top: 26px;
  bottom: 0;
  width: 1px;
  background: var(--color-border);
}

.answer-steps li span {
  padding-top: 2px;
}

.answer-checklist {
  list-style: none;
  margin: 4px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.answer-checklist li {
  display: flex;
  gap: 9px;
  align-items: flex-start;
}

.answer-checklist li i {
  flex-shrink: 0;
  margin-top: 2px;
  color: var(--color-success);
}

.answer-bullets {
  list-style: none;
  margin: 4px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.answer-bullets li {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.answer-bullets li::before {
  content: "";
  flex-shrink: 0;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--color-text-muted);
  margin-top: 8px;
}

.info-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--color-surface-soft);
  border: 1px solid var(--color-border);
  margin: 4px 0;
}

.info-card__icon {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  background: var(--badge-info-bg);
  color: var(--color-primary-dark);
}

.info-card--callout .info-card__icon {
  background: var(--badge-warning-bg);
  color: var(--badge-warning-text);
}

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

.info-card__title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  margin-bottom: 3px;
}

.info-card__text {
  font-size: 0.88rem;
  line-height: 1.5;
  white-space: pre-line;
}

.info-card__actions {
  display: flex;
  gap: 6px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.info-card__action-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  background: var(--color-surface);
  color: var(--color-text-secondary);
  font-size: 0.74rem;
  cursor: pointer;
  transition: border-color var(--transition-fast), color var(--transition-fast);
}

.info-card__action-btn:hover {
  border-color: var(--color-primary);
  color: var(--color-primary);
}

.schedule-table {
  width: 100%;
  border-collapse: collapse;
  margin: 4px 0;
  font-size: 0.86rem;
}

.schedule-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--color-border);
}

.schedule-table tr:last-child td { border-bottom: none; }

.schedule-table td:first-child {
  font-weight: 600;
  color: var(--color-text-secondary);
  white-space: nowrap;
}

.contact-list {
  list-style: none;
  margin: 4px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.contact-list li a,
.contact-list li span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.86rem;
  color: var(--color-text);
  text-decoration: none;
}

.contact-list li a:hover { color: var(--color-primary); text-decoration: underline; }

.contact-list li i {
  color: var(--color-primary);
  width: 16px;
  text-align: center;
}

/* ---------- Feedback & message actions ---------- */

.msg-actions {
  display: flex;
  gap: 4px;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  transition: background var(--transition-fast), color var(--transition-fast), border-color var(--transition-fast);
}

.action-btn:hover:not(:disabled) { background: var(--color-surface-soft); color: var(--color-text); }
.action-btn:disabled { cursor: default; opacity: 0.55; }

.action-btn--up.is-selected { border-color: var(--color-success); color: var(--color-success); }
.action-btn--down.is-selected { border-color: var(--color-danger); color: var(--color-danger); }

/* ---------- Typing indicator ---------- */

.typing-indicator {
  flex-shrink: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  padding: 0 20px 14px;
}

.typing-bubble {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bubble-bot-bg);
  border: 1px solid var(--bubble-bot-border);
  border-radius: var(--radius-md);
  border-bottom-left-radius: 4px;
  padding: 10px 14px;
  box-shadow: var(--shadow-soft);
}

.typing-text {
  font-size: 0.78rem;
  color: var(--color-text-secondary);
}

.typing-dots { display: flex; gap: 4px; }

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--color-text-muted);
  animation: typing-bounce 1.2s infinite ease-in-out;
}

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

@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.6; }
  30% { transform: translateY(-4px); opacity: 1; }
}

/* ---------- Error bubble ---------- */

.msg--error {
  border-color: var(--color-danger) !important;
}

.msg-retry-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
  padding: 6px 12px;
  border: 1px solid var(--color-danger);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--color-danger);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.msg-retry-btn:hover { background: var(--badge-danger-bg); }

/* ---------- Composer area ---------- */

.composer-area {
  flex-shrink: 0;
  padding: 10px 20px 16px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
}

.quick-replies {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding: 2px 2px 10px;
  scrollbar-width: thin;
}

.quick-reply-chip {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 13px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--color-text);
  background: var(--color-surface-soft);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition-fast), border-color var(--transition-fast), color var(--transition-fast);
}

.quick-reply-chip:hover {
  background: var(--badge-info-bg);
  border-color: var(--color-primary);
  color: var(--color-primary-dark);
}

.quick-reply-chip:active { transform: scale(0.97); }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 8px 8px 16px;
  background: var(--color-surface-soft);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.composer:focus-within {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

.composer__input {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--color-text);
  font-family: inherit;
  font-size: 0.95rem;
  line-height: 1.4;
  padding: 8px 0;
  outline: none;
  resize: none;
  max-height: 160px;
}

.composer__input::placeholder { color: var(--color-text-muted); }

/* Satu tombol yang berganti peran: kirim (idle) <-> batalkan (loading) --
   lihat permintaan polishing bagian L. Ikon dan spinner ditukar lewat class
   is-loading (chat.js), bukan dua tombol terpisah seperti sebelumnya. */
.composer__send-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--color-primary);
  color: #fff;
  transition: background 180ms ease, transform 180ms ease, opacity 180ms ease;
}

.composer__send-btn:hover:not(:disabled) { background: var(--color-primary-dark); transform: scale(1.05); }
.composer__send-btn:active:not(:disabled) { transform: scale(0.96); }
.composer__send-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.composer__send-btn.is-loading {
  background: var(--color-danger);
}

.composer__send-btn.is-loading:hover { background: var(--color-danger); }

.composer__send-icon,
.composer__send-spinner {
  display: flex;
  align-items: center;
  justify-content: center;
}

.composer__send-btn.is-loading .composer__send-icon { display: none; }

.composer__send-spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.4);
  border-top-color: #fff;
  border-radius: 50%;
}

.composer__send-btn.is-loading .composer__send-spinner {
  display: flex;
  animation: send-spin 0.6s linear infinite;
}

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

@media (prefers-reduced-motion: reduce) {
  .composer__send-btn.is-loading .composer__send-spinner { animation: none; }
}

.composer__hint {
  margin: 8px 2px 0;
  font-size: 0.72rem;
  color: var(--color-text-muted);
}

/* ---------- Toast ---------- */

.toast-container {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-pill);
  background: var(--color-text);
  color: var(--color-bg);
  font-size: 0.82rem;
  font-weight: 500;
  box-shadow: var(--shadow-float);
  animation: toast-in 0.2s ease both;
}

:root[data-theme="dark"] .toast {
  background: var(--color-surface-soft);
  color: var(--color-text);
  border: 1px solid var(--color-border);
}

.toast.is-leaving { animation: toast-out 0.18s ease both; }

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

@keyframes toast-out {
  from { opacity: 1; transform: translateY(0); }
  to { opacity: 0; transform: translateY(6px); }
}

/* ---------- Modal (Panduan / Tentang) ---------- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 150;
}

.modal-overlay[hidden] { display: none; }

.modal-card {
  width: 100%;
  max-width: 480px;
  max-height: 85vh;
  overflow-y: auto;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-float);
  padding: 22px 22px 20px;
}

.modal-card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.modal-card__header h2 {
  margin: 0;
  font-size: var(--fs-heading);
  font-weight: 700;
}

.modal-card__body {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--color-text-secondary);
}

.modal-card__body h3 {
  font-size: 0.86rem;
  color: var(--color-text);
  margin: 14px 0 6px;
}

.modal-card__body ul {
  margin: 0 0 10px;
  padding-left: 18px;
}

.modal-card__close {
  width: 32px;
  height: 32px;
  border: none;
  background: var(--color-surface-soft);
  border-radius: 50%;
  color: var(--color-text-secondary);
  cursor: pointer;
  flex-shrink: 0;
}

.modal-card__close:hover { color: var(--color-text); }
