/* ── Reset & Base ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:       #4F46E5;   /* indigo - tombol & bubble user */
  --primary-dark:  #3730A3;
  --primary-light: #EEF2FF;

  --surface:       #FFFFFF;
  --surface-2:     #F8F9FA;
  --border:        #E5E7EB;

  --text:          #111827;
  --text-muted:    #6B7280;
  --text-inverse:  #FFFFFF;

  --green:         #22C55E;   /* status dot */
  --radius-card:   20px;
  --radius-bubble: 18px;
}

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}

/* ── Page background ── */
.page-bg {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background: #F3F4F6;
  background-image:
    radial-gradient(circle at 20% 20%, rgba(79,70,229,.08) 0%, transparent 55%),
    radial-gradient(circle at 80% 80%, rgba(79,70,229,.06) 0%, transparent 50%);
}

/* ── Chat card ── */
.chat-card {
  width: 100%;
  max-width: 440px;
  height: 620px;
  background: var(--surface);
  border-radius: var(--radius-card);
  box-shadow:
    0 4px 6px rgba(0,0,0,.04),
    0 12px 40px rgba(0,0,0,.10);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
}

/* ── Header ── */
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.bot-avatar {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.header-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.header-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}

.header-sub {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-muted);
}

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

.header-badge {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--primary);
  background: var(--primary-light);
  border-radius: 6px;
  padding: 3px 7px;
  flex-shrink: 0;
}

/* ── Messages area ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface-2);
  scroll-behavior: smooth;
}

.chat-messages::-webkit-scrollbar { width: 4px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }
.chat-messages::-webkit-scrollbar-thumb {
  background: #D1D5DB;
  border-radius: 4px;
}

/* ── Message row ── */
.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  max-width: 82%;
}

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

/* Small bot icon next to bubble */
.msg-icon {
  width: 26px;
  height: 26px;
  border-radius: 8px;
  background: var(--primary-light);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-bottom: 2px;
}

/* ── Bubble ── */
.bubble {
  padding: 10px 14px;
  border-radius: var(--radius-bubble);
  font-size: 14px;
  line-height: 1.6;
  word-break: break-word;
  position: relative;
}

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

.msg-row.user .bubble {
  background: var(--primary);
  color: var(--text-inverse);
  border-bottom-right-radius: 5px;
}

/* Bubble text */
.bubble-text {
  display: block;
  margin-bottom: 4px;
  white-space: pre-wrap;
}

/* Meta (time) */
.bubble-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
}

.bubble-time {
  font-size: 10.5px;
  color: var(--text-muted);
}

.msg-row.user .bubble-time {
  color: rgba(255,255,255,.6);
}

/* ── Typing indicator ── */
.typing-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-bubble);
  border-bottom-left-radius: 5px;
}

.typing-dot {
  width: 7px;
  height: 7px;
  background: #9CA3AF;
  border-radius: 50%;
  animation: pulse 1.3s ease-in-out infinite;
}
.typing-dot:nth-child(2) { animation-delay: .18s; }
.typing-dot:nth-child(3) { animation-delay: .36s; }

@keyframes pulse {
  0%, 70%, 100% { transform: scale(1);   opacity: .5; }
  35%            { transform: scale(1.3); opacity: 1;  }
}

/* ── Footer / Input ── */
.chat-footer {
  border-top: 1px solid var(--border);
  background: var(--surface);
  padding: 12px 16px 10px;
  flex-shrink: 0;
}

.input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 12px;
  padding: 8px 8px 8px 14px;
  transition: border-color .2s;
}

.input-row:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(79,70,229,.08);
}

#user-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-family: inherit;
  font-size: 14px;
  color: var(--text);
  min-width: 0;
}

#user-input::placeholder { color: var(--text-muted); }

.send-btn {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  border: none;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .15s, transform .1s;
}

.send-btn:hover  { background: var(--primary-dark); }
.send-btn:active { transform: scale(.93); }
.send-btn:disabled {
  background: #D1D5DB;
  cursor: not-allowed;
  transform: none;
}

/* Footer note */
.footer-note {
  margin-top: 7px;
  text-align: center;
  font-size: 10.5px;
  color: #9CA3AF;
}

/* ── Selector screen ── */
.selector-card {
  height: auto;
  min-height: 340px;
  max-height: 620px;
}

.selector-list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  background: var(--surface-2);
}

.selector-list::-webkit-scrollbar { width: 4px; }
.selector-list::-webkit-scrollbar-track { background: transparent; }
.selector-list::-webkit-scrollbar-thumb { background: #D1D5DB; border-radius: 4px; }

.selector-loading,
.selector-error {
  text-align: center;
  font-size: 14px;
  color: var(--text-muted);
  padding: 32px 16px;
}

.biz-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  cursor: pointer;
  text-align: left;
  transition: border-color .18s, box-shadow .18s, transform .1s;
  width: 100%;
}

.biz-card:hover {
  border-color: var(--biz-color, var(--primary));
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--biz-color, var(--primary)) 12%, transparent);
  transform: translateY(-1px);
}

.biz-card:active { transform: translateY(0); }

.biz-avatar {
  font-size: 28px;
  line-height: 1;
  flex-shrink: 0;
}

.biz-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.biz-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.biz-agent {
  font-size: 12px;
  color: var(--text-muted);
}

.biz-arrow {
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ── Back button ── */
.back-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color .15s, color .15s, background .15s;
}

.back-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
  background: var(--primary-light);
}

/* ── Attach button ── */
.attach-btn {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: color .15s, background .15s;
}

.attach-btn:hover { color: var(--primary); background: var(--primary-light); }
.attach-btn:disabled { opacity: .4; cursor: not-allowed; }
.attach-btn--active { color: var(--primary); }

/* ── File preview bar ── */
.file-preview-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  margin-bottom: 8px;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  min-width: 0;
}

.file-preview-content {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.preview-thumb {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  object-fit: cover;
  flex-shrink: 0;
}

.preview-name {
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}

.preview-size {
  font-size: 11px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.file-remove-btn {
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: color .15s, background .15s;
}

.file-remove-btn:hover { color: #EF4444; background: #FEF2F2; }

/* ── Image bubble ── */
.bubble-img {
  display: block;
  max-width: 200px;
  max-height: 180px;
  border-radius: 10px;
  object-fit: cover;
  margin-bottom: 6px;
}

/* ── File chip (audio / PDF) ── */
.bubble-file-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(255,255,255,.15);
  border-radius: 8px;
  margin-bottom: 6px;
  max-width: 200px;
}

.msg-row.bot .bubble-file-chip {
  background: var(--surface-2);
}

.chip-icon { font-size: 16px; flex-shrink: 0; }

.chip-name {
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── File error toast ── */
.file-error-toast {
  align-self: center;
  padding: 7px 14px;
  background: #FEF2F2;
  border: 1px solid #FECACA;
  border-radius: 10px;
  font-size: 12.5px;
  color: #B91C1C;
  text-align: center;
  animation: fadeIn .2s ease;
}

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