/* ==========================================================================
   AI Chat — style.css
   Bảng màu ấm nhưng tránh tông cam đất / be kem mặc định:
     - English mode : hồng san hô ấm (coral rose)
     - Tiếng Việt    : vàng hổ phách ấm (warm marigold)
   ========================================================================== */

:root {
  --bg: #F6F2F1;
  --surface: #FFFFFF;
  --surface-alt: #FBF7F6;
  --text: #2B2230;
  --text-soft: #6E6169;
  --border: #E9E1E1;

  --en-accent: #E24D6E;
  --en-accent-strong: #C93A5A;
  --en-accent-soft: #FCE3E9;

  --vi-accent: #C8890A;
  --vi-accent-strong: #A96F06;
  --vi-accent-soft: #FBECC9;

  --accent: var(--vi-accent);
  --accent-strong: var(--vi-accent-strong);
  --accent-soft: var(--vi-accent-soft);

  --danger: #C93A3A;
  --danger-soft: #FBE4E4;

  /* Màu nhận diện từng AI (chỉ dùng cho nhãn nhỏ trên bong bóng trả lời) */
  --claude-color: #8A63D2;
  --openai-color: #128A6E;
  --gemini-color: #3D74E0;

  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 24px rgba(43, 34, 48, 0.08);
}

body.mode-en {
  --accent: var(--en-accent);
  --accent-strong: var(--en-accent-strong);
  --accent-soft: var(--en-accent-soft);
}

body.mode-vi {
  --accent: var(--vi-accent);
  --accent-strong: var(--vi-accent-strong);
  --accent-soft: var(--vi-accent-soft);
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 720px;
  margin: 0 auto;
  background: var(--surface-alt);
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 14px 18px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.topbar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  min-width: 0;
}

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  transition: background 0.25s ease;
  flex-shrink: 0;
}

.brand-name {
  white-space: nowrap;
}

.provider-select {
  appearance: none;
  -webkit-appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  padding: 7px 30px 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  flex-shrink: 0;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-soft) 50%),
                     linear-gradient(135deg, var(--text-soft) 50%, transparent 50%);
  background-position: calc(100% - 16px) center, calc(100% - 11px) center;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  transition: border-color 0.2s ease;
}

.provider-select:hover,
.provider-select:focus {
  border-color: var(--accent);
  outline: none;
}

.topbar-actions-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.new-chat-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text-soft);
  font-size: 13px;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 999px;
  cursor: pointer;
  text-decoration: none;
  transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
  white-space: nowrap;
  flex-shrink: 0;
}

.new-chat-btn:hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.new-chat-btn span:first-child {
  font-size: 15px;
  line-height: 1;
}

/* ---------- Segmented pill toggle ---------- */

.lang-toggle {
  position: relative;
  display: inline-flex;
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  flex-shrink: 0;
}

.lang-pill {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc(50% - 3px);
  background: var(--accent);
  border-radius: 999px;
  transition: transform 0.25s ease, background 0.25s ease;
  z-index: 0;
}

body.mode-vi .lang-pill {
  transform: translateX(100%);
}

.lang-btn {
  position: relative;
  z-index: 1;
  border: none;
  background: transparent;
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-soft);
  border-radius: 999px;
  cursor: pointer;
  transition: color 0.2s ease;
  white-space: nowrap;
}

.lang-btn.active {
  color: #fff;
}

/* ---------- Chat area ---------- */

.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-hint {
  margin: auto;
  text-align: center;
  color: var(--text-soft);
  padding: 24px;
}

.empty-hint p:first-child {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  margin: 0 0 6px;
}

.empty-sub {
  font-size: 14px;
  margin: 0;
  max-width: 320px;
}

.bubble-row {
  display: flex;
}

.bubble-row.bubble-user {
  justify-content: flex-end;
}

.bubble-row.bubble-ai {
  justify-content: flex-start;
}

.bubble-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  max-width: 78%;
}

.provider-tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text-soft);
  padding-left: 2px;
}

.provider-tag::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
}

.provider-tag.provider-claude { color: var(--claude-color); }
.provider-tag.provider-openai { color: var(--openai-color); }
.provider-tag.provider-gemini { color: var(--gemini-color); }

.bubble {
  max-width: 78%;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-wrap: break-word;
  box-shadow: var(--shadow);
}

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

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

.bubble-ai.typing {
  color: var(--text-soft);
  font-style: italic;
}

.bubble-stack .bubble {
  max-width: 100%;
}

.bubble-error {
  background: var(--danger-soft);
  color: var(--danger);
  border: 1px solid rgba(201, 58, 58, 0.25);
  border-bottom-left-radius: 4px;
}

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

.composer {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 12px 16px;
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.composer-input {
  flex: 1;
  resize: none;
  max-height: 140px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface-alt);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.composer-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.send-btn {
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 14px;
  padding: 0 20px;
  height: 42px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s ease, transform 0.1s ease;
  flex-shrink: 0;
}

.send-btn:hover {
  background: var(--accent-strong);
}

.send-btn:active {
  transform: scale(0.97);
}

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

/* ---------- Responsive ---------- */

@media (max-width: 480px) {
  .app {
    max-width: 100%;
  }

  .topbar {
    padding: 12px 14px;
  }

  .brand-name {
    font-size: 15px;
  }

  .new-chat-label {
    display: none;
  }

  .new-chat-btn {
    padding: 8px 10px;
  }

  .chat-container {
    padding: 14px 12px;
  }

  .bubble {
    max-width: 86%;
    font-size: 14.5px;
  }

  .bubble-stack {
    max-width: 86%;
  }

  .composer {
    padding: 10px 12px;
  }
}

/* ---------- Scrollbar (webkit) ---------- */

.chat-container::-webkit-scrollbar {
  width: 8px;
}

.chat-container::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 999px;
}
