:root {
  --bg: #0b0d10;
  --bg-deep: #06080b;
  --panel: #12161c;
  --panel-light: #161c24;
  --text: #e8eef7;
  --muted: #8fa3b8;
  --accent: #3ba09e;
  --accent-strong: #4bc9c4;
  --accent-soft: rgba(75, 201, 196, 0.14);
  --border: #324252;
  --user-bg: rgba(75, 201, 196, 0.16);
  --bot-bg: rgba(18, 22, 28, 0.92);
  --danger: #f87171;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --header-h: 72px;
  --composer-h: 118px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

html,
body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Manrope", "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, rgba(75, 201, 196, 0.14), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 100%, rgba(59, 100, 140, 0.12), transparent 50%),
    linear-gradient(180deg, rgba(6, 10, 15, 0.92), rgba(3, 6, 10, 0.96)),
    repeating-linear-gradient(90deg, rgba(75, 201, 196, 0.035) 0 1px, transparent 1px 120px),
    repeating-linear-gradient(0deg, rgba(75, 201, 196, 0.03) 0 1px, transparent 1px 120px);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 100%;
  min-height: 100dvh;
  max-width: 860px;
  margin: 0 auto;
}

/* —— Header —— */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid rgba(50, 66, 82, 0.7);
  background: linear-gradient(180deg, rgba(12, 16, 22, 0.95), rgba(11, 13, 16, 0.75));
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.header__mark {
  flex-shrink: 0;
  color: var(--accent-strong);
  filter: drop-shadow(0 0 10px rgba(75, 201, 196, 0.25));
}

.header__titles {
  min-width: 0;
}

.header__title {
  margin: 0;
  font-size: clamp(0.95rem, 2.8vw, 1.15rem);
  font-weight: 700;
  letter-spacing: 0.01em;
  line-height: 1.25;
}

.header__subtitle {
  margin: 3px 0 0;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header__link {
  flex-shrink: 0;
  color: var(--accent-strong);
  text-decoration: none;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 8px 12px;
  border: 1px solid rgba(75, 201, 196, 0.35);
  border-radius: 999px;
  transition: background 0.15s ease, border-color 0.15s ease;
}

.header__link:hover {
  background: var(--accent-soft);
  border-color: var(--accent-strong);
}

/* —— Chat —— */
.chat {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
}

.chat__welcome {
  margin: 28px 18px 8px;
  padding: 20px 22px;
  border-radius: var(--radius);
  border: 1px solid rgba(75, 201, 196, 0.22);
  background:
    linear-gradient(135deg, rgba(75, 201, 196, 0.1), transparent 55%),
    var(--panel);
  box-shadow: var(--shadow);
}

.chat__welcome.is-hidden {
  display: none;
}

.chat__welcome-kicker {
  margin: 0 0 8px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--accent-strong);
}

.chat__welcome-text {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.55;
}

.chat__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px 8px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  scroll-behavior: smooth;
  -webkit-overflow-scrolling: touch;
}

.msg {
  max-width: min(92%, 640px);
  animation: msg-in 0.28s ease;
}

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

.msg--user {
  align-self: flex-end;
}

.msg--bot,
.msg--error,
.msg--typing {
  align-self: flex-start;
}

.msg__bubble {
  padding: 12px 16px;
  border-radius: 16px;
  line-height: 1.55;
  font-size: 0.95rem;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg--user .msg__bubble {
  background: var(--user-bg);
  border: 1px solid rgba(75, 201, 196, 0.35);
  border-bottom-right-radius: 6px;
  color: var(--text);
}

.msg--bot .msg__bubble {
  background: var(--bot-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
}

.msg--error .msg__bubble {
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid rgba(248, 113, 113, 0.35);
  color: #fecaca;
  border-bottom-left-radius: 6px;
}

.msg__role {
  display: block;
  margin-bottom: 6px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.msg--user .msg__role {
  text-align: right;
  color: var(--accent-strong);
}

.msg--bot .msg__role {
  color: var(--accent-strong);
}

.msg__sources {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.msg__source {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 11px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-strong);
  text-decoration: none;
  border: 1px solid rgba(75, 201, 196, 0.3);
  border-radius: 999px;
  background: rgba(75, 201, 196, 0.06);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.msg__source:hover {
  background: var(--accent-soft);
  border-color: var(--accent-strong);
}

.msg__source::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-strong);
  opacity: 0.8;
}

/* Typing indicator */
.msg--typing .msg__bubble {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  background: var(--bot-bg);
  border: 1px solid var(--border);
  border-bottom-left-radius: 6px;
  color: var(--muted);
  font-size: 0.88rem;
}

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

.typing-dots span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-strong);
  animation: 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 bounce {
  0%, 80%, 100% { opacity: 0.3; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* —— Composer —— */
.composer {
  width: 100%;
  padding: 14px 18px calc(16px + var(--safe-bottom));
  border-top: 1px solid rgba(50, 66, 82, 0.55);
  background: linear-gradient(0deg, rgba(6, 9, 13, 0.98), rgba(11, 13, 16, 0.82));
  backdrop-filter: blur(12px);
}

.composer__form {
  display: block;
  width: 100%;
}

.composer__shell {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: flex-end;
  gap: 12px;
  width: 100%;
  box-sizing: border-box;
  padding: 12px 12px 12px 18px;
  border-radius: 20px;
  border: 1px solid rgba(75, 201, 196, 0.22);
  background:
    linear-gradient(165deg, rgba(24, 32, 42, 0.98), rgba(12, 16, 22, 0.99));
  box-shadow:
    inset 0 1px 0 rgba(75, 201, 196, 0.1),
    0 12px 32px rgba(0, 0, 0, 0.32);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.composer__shell:focus-within {
  border-color: rgba(75, 201, 196, 0.55);
  box-shadow:
    inset 0 1px 0 rgba(75, 201, 196, 0.14),
    0 0 0 3px rgba(75, 201, 196, 0.12),
    0 14px 36px rgba(0, 0, 0, 0.38);
}

.composer__field {
  flex: 1 1 auto;
  position: relative;
  min-width: 0;
  width: 100%;
  padding-bottom: 20px;
}

.composer__field textarea {
  display: block;
  width: 100%;
  box-sizing: border-box;
  resize: none;
  overflow: hidden;
  min-height: 52px;
  max-height: 160px;
  padding: 10px 8px 6px 0;
  border: none;
  border-radius: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1.05rem;
  line-height: 1.5;
  outline: none;
  box-shadow: none;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.composer__field textarea::-webkit-scrollbar {
  display: none;
  width: 0;
  height: 0;
}

.composer__field textarea::placeholder {
  color: #6b7f94;
}

.composer__counter {
  position: absolute;
  left: 0;
  bottom: 0;
  font-size: 0.7rem;
  letter-spacing: 0.04em;
  color: #5d7084;
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.composer__send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 0 0 auto;
  height: 52px;
  min-width: 132px;
  padding: 0 20px;
  border: none;
  border-radius: 14px;
  background: linear-gradient(155deg, #57d6d1, #2f9a96);
  color: #031016;
  font: inherit;
  font-weight: 700;
  font-size: 0.95rem;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(75, 201, 196, 0.28);
  transition: filter 0.15s ease, transform 0.1s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

.composer__send:hover:not(:disabled) {
  filter: brightness(1.07);
  box-shadow: 0 6px 18px rgba(75, 201, 196, 0.35);
}

.composer__send:active:not(:disabled) {
  transform: scale(0.97);
}

.composer__send:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
}

.composer__send svg {
  flex-shrink: 0;
}

.composer__hint {
  margin: 10px 8px 0;
  font-size: 0.7rem;
  color: #556779;
}

@media (max-width: 560px) {
  .header {
    padding: 12px 14px;
  }

  .header__subtitle {
    display: none;
  }

  .header__link {
    padding: 7px 10px;
    font-size: 0.75rem;
  }

  .chat__welcome,
  .chat__messages {
    margin-left: 12px;
    margin-right: 12px;
  }

  .chat__messages {
    padding-left: 0;
    padding-right: 0;
  }

  .composer {
    padding-left: 12px;
    padding-right: 12px;
  }

  .composer__shell {
    padding: 10px 10px 10px 14px;
    border-radius: 18px;
    gap: 10px;
  }

  .composer__send span {
    display: none;
  }

  .composer__send {
    width: 52px;
    min-width: 52px;
    padding: 0;
    border-radius: 14px;
  }
}
