/* ============ Reset & Base ============ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0b1015;
  --surface: #121a1f;
  --surface-light: #162125;
  --border: #243530;
  --text: #e6f0eb;
  --text-muted: #8a9e95;
  --accent: #34d399;
  --accent-hover: #5eead4;
  --accent-glow: rgba(52,211,153,.2);
  --gradient: linear-gradient(135deg, #0b1015 0%, #121a1f 50%, #142420 100%);
  --header-gradient: linear-gradient(135deg, #0a1a14 0%, #0f2e22 40%, #165a3a 70%, #0e3d2a 100%);
  --radius: 12px;
  --radius-lg: 16px;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --shadow: 0 4px 24px rgba(0,0,0,.5);
  --bot-bg: #131f1a;
  --user-bg: #14332a;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

/* ============ App Shell ============ */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 900px;
  margin: 0 auto;
  position: relative;
}

/* ============ Header ============ */
.header {
  position: relative;
  padding: 24px 24px 20px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: visible;
}

.header__bg {
  position: absolute;
  inset: 0;
  background: var(--header-gradient);
  border-radius: inherit;
  overflow: hidden;
  z-index: 0;
}

.header__bg::after {
  content: '';
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 600px 300px at 20% 50%, rgba(52,211,153,.1), transparent),
    radial-gradient(ellipse 400px 200px at 80% 30%, rgba(16,185,129,.08), transparent);
}

.header__content {
  position: relative;
  z-index: 1;
}

.header__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

/* Avatar with pulse */
.header__avatar {
  position: relative;
  flex-shrink: 0;
  width: 56px;
  height: 56px;
}

.header__avatar-img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(52,211,153,.12);
  border: 2px solid rgba(52,211,153,.35);
  object-fit: cover;
  position: relative;
  z-index: 1;
}

.header__avatar-pulse {
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid rgba(52,211,153,.35);
  animation: pulse 2.5s ease-in-out infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: .6; }
  50% { transform: scale(1.15); opacity: 0; }
}

.header__text {
  min-width: 0;
}

.header__name {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -.01em;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header__title {
  margin-top: 4px;
  font-size: .78rem;
  font-weight: 400;
  color: var(--text-muted);
  line-height: 1.5;
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
}

.header__sep {
  color: rgba(52,211,153,.45);
  margin: 0 4px;
}

/* Header actions */
.header__actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.header__link {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: var(--text-muted);
  text-decoration: none;
  transition: background .2s, color .2s;
}

.header__link:hover {
  background: rgba(255,255,255,.06);
  color: var(--text);
}

/* ============ Language Selector ============ */
.lang-select {
  position: relative;
}

.lang-select__btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: rgba(255,255,255,.06);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: .85rem;
  cursor: pointer;
  transition: background .2s, border-color .2s;
}

.lang-select__btn:hover {
  background: rgba(255,255,255,.1);
  border-color: rgba(52,211,153,.35);
}

.lang-select__flag { font-size: 1.1rem; }

.lang-select__arrow {
  color: var(--text-muted);
  transition: transform .2s;
}

.lang-select.open .lang-select__arrow {
  transform: rotate(180deg);
}

.lang-select__dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  min-width: 150px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: opacity .2s, transform .2s, visibility .2s;
  z-index: 100;
  overflow: hidden;
}

.lang-select.open .lang-select__dropdown {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.lang-select__option {
  display: block;
  width: 100%;
  padding: 10px 14px;
  border: none;
  background: none;
  color: var(--text);
  font-size: .85rem;
  text-align: left;
  cursor: pointer;
  transition: background .15s;
}

.lang-select__option:hover {
  background: rgba(255,255,255,.06);
}

.lang-select__option.active {
  background: rgba(52,211,153,.12);
  color: var(--accent);
}

/* ============ Chat Area ============ */
.chat {
  flex: 1;
  overflow-y: auto;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

/* Scrollbar */
.chat::-webkit-scrollbar { width: 6px; }
.chat::-webkit-scrollbar-track { background: transparent; }
.chat::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* Welcome Screen */
.chat__welcome {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  text-align: center;
  padding: 32px 16px;
  position: relative;
}

.chat__welcome-glow {
  position: absolute;
  width: 200px;
  height: 200px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(52,211,153,.12), transparent 70%);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -60%);
  pointer-events: none;
}

.chat__welcome-icon {
  width: 64px;
  height: 64px;
  padding: 12px;
  background: rgba(52,211,153,.1);
  border: 1px solid rgba(52,211,153,.2);
  border-radius: 50%;
  margin-bottom: 20px;
  object-fit: contain;
  position: relative;
  z-index: 1;
}

.chat__welcome h2 {
  font-size: 1.3rem;
  font-weight: 600;
  margin-bottom: 8px;
  position: relative;
  z-index: 1;
}

.chat__welcome p {
  color: var(--text-muted);
  font-size: .9rem;
  max-width: 400px;
  position: relative;
  z-index: 1;
}

/* Suggestion buttons */
.chat__suggestions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 24px;
  justify-content: center;
  position: relative;
  z-index: 1;
}

.suggestion {
  padding: 8px 16px;
  background: var(--surface-light);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  font-size: .82rem;
  cursor: pointer;
  transition: all .2s;
  white-space: nowrap;
}

.suggestion:hover {
  background: rgba(52,211,153,.1);
  border-color: rgba(52,211,153,.3);
  color: var(--accent);
  transform: translateY(-1px);
}

/* ============ Messages ============ */
.msg {
  display: flex;
  gap: 10px;
  max-width: 85%;
  animation: msgIn .3s ease;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg--user {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg__icon {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-size: .85rem;
}

.msg--bot .msg__icon {
  background: rgba(52,211,153,.12);
  border: 1px solid rgba(52,211,153,.2);
  overflow: hidden;
}

.msg--bot .msg__icon img {
  width: 20px;
  height: 20px;
  object-fit: contain;
}

.msg--user .msg__icon {
  background: rgba(16,185,129,.15);
  border: 1px solid rgba(16,185,129,.25);
  overflow: hidden;
}

.msg--user .msg__icon img {
  width: 20px;
  height: 20px;
  object-fit: contain;
}

.msg__bubble {
  padding: 12px 16px;
  border-radius: var(--radius);
  line-height: 1.6;
  font-size: .9rem;
  word-break: break-word;
}

.msg--bot .msg__bubble {
  background: var(--bot-bg);
  border: 1px solid var(--border);
  border-top-left-radius: 4px;
}

.msg--user .msg__bubble {
  background: var(--user-bg);
  border: 1px solid rgba(52,211,153,.15);
  border-top-right-radius: 4px;
  color: #d1e6dd;
}

/* Markdown inside bot bubbles */
.msg__bubble h1, .msg__bubble h2, .msg__bubble h3 {
  font-size: 1em;
  font-weight: 600;
  margin: 12px 0 4px 0;
}

.msg__bubble h1:first-child,
.msg__bubble h2:first-child,
.msg__bubble h3:first-child { margin-top: 0; }

.msg__bubble p { margin: 4px 0; }

.msg__bubble ul, .msg__bubble ol {
  margin: 6px 0;
  padding-left: 20px;
}

.msg__bubble li { margin: 2px 0; }

.msg__bubble code {
  background: rgba(255,255,255,.06);
  padding: 1px 6px;
  border-radius: 4px;
  font-size: .85em;
}

.msg__bubble pre {
  background: rgba(0,0,0,.3);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}

.msg__bubble pre code {
  background: none;
  padding: 0;
}

.msg__bubble a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.msg__bubble strong { color: #ecfdf5; }

/* Typing indicator */
.typing-dots {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}

.typing-dots span {
  width: 7px;
  height: 7px;
  background: var(--text-muted);
  border-radius: 50%;
  animation: dotPulse 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }

@keyframes dotPulse {
  0%, 60%, 100% { transform: scale(.6); opacity: .4; }
  30% { transform: scale(1); opacity: 1; }
}

/* ============ Input Area ============ */
.input-area {
  padding: 16px 16px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  border-radius: var(--radius-lg);
  flex-shrink: 0;
}

.input-area__form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.input-area__input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: .9rem;
  font-family: var(--font);
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}

.input-area__input::placeholder { color: var(--text-muted); }

.input-area__input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.input-area__send {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: 44px;
  border: none;
  border-radius: var(--radius);
  background: var(--accent);
  color: #0b1015;
  font-family: var(--font);
  font-size: .88rem;
  font-weight: 600;
  letter-spacing: .01em;
  cursor: pointer;
  transition: background .2s, transform .1s;
}

.input-area__send:hover { background: var(--accent-hover); }
.input-area__send:active { transform: scale(.98); }

.input-area__send:disabled {
  opacity: .4;
  cursor: not-allowed;
}

/* ============ Responsive ============ */
@media (max-width: 600px) {
  .header { padding: 16px 14px 14px; }

  .header__avatar { width: 44px; height: 44px; }
  .header__avatar-img { width: 44px; height: 44px; }
  .header__avatar-pulse { inset: -3px; }

  .header__name { font-size: 1.05rem; }

  .header__title {
    font-size: .68rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  .header__link { display: none; }

  .chat { padding: 16px 10px; }
  .msg { max-width: 92%; }

  .chat__welcome h2 { font-size: 1.1rem; }
  .chat__welcome-icon { width: 52px; height: 52px; padding: 10px; }

  .suggestion { font-size: .78rem; padding: 6px 12px; }

  .input-area { padding: 10px 10px 16px; }
  .input-area__input { padding: 12px 14px; font-size: 16px; }
  .input-area__send { height: 40px; font-size: .84rem; }
}

@media (max-width: 380px) {
  .header__brand { gap: 10px; }
  .header__title .header__sep { display: none; }
  .header__title span { display: block; }
}
