:root {
  color-scheme: light;
  --bg: #f6f5f1;
  --panel: #ffffff;
  --ink: #1f2428;
  --muted: #66706b;
  --line: #d9ded8;
  --accent: #22745a;
  --accent-dark: #165843;
  --warn: #9a5b18;
  --soft: #eef6f1;
  --shadow: 0 18px 45px rgba(31, 36, 40, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

button,
textarea {
  font: inherit;
}

.app {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.workspace,
.sources {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.workspace {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: calc(100vh - 36px);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

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

.brandLogo {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  flex: 0 0 auto;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.15;
}

h2 {
  font-size: 16px;
}

#status {
  margin-top: 5px;
  color: var(--muted);
  font-size: 14px;
}

button {
  border: 0;
  border-radius: 7px;
  background: var(--accent);
  color: #fff;
  padding: 11px 14px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  background: var(--accent-dark);
}

button:disabled {
  cursor: wait;
  opacity: 0.72;
}

.messages {
  overflow-y: auto;
  padding: 20px;
}

.mascot {
  position: absolute;
  right: 22px;
  bottom: 92px;
  display: grid;
  justify-items: end;
  gap: 8px;
  width: 170px;
  pointer-events: none;
  z-index: 2;
}

.mascot img {
  width: 118px;
  height: 118px;
  border-radius: 18px;
  object-fit: contain;
  filter: drop-shadow(0 14px 20px rgba(31, 36, 40, 0.16));
  transform-origin: 50% 85%;
  animation: mascotFloat 3.2s ease-in-out infinite;
}

.mascotBubble {
  max-width: 170px;
  border: 1px solid #d7eadf;
  border-radius: 8px;
  background: rgba(238, 246, 241, 0.94);
  color: var(--ink);
  font-size: 12px;
  line-height: 1.3;
  padding: 8px 9px;
  box-shadow: 0 10px 24px rgba(31, 36, 40, 0.08);
}

.mascotSearching img {
  animation: mascotSearch 1.05s ease-in-out infinite;
}

.mascotHappy img {
  animation: mascotHappy 0.72s ease-in-out 2;
}

@keyframes mascotFloat {
  0%,
  100% {
    transform: translateY(0) rotate(-1deg);
  }
  50% {
    transform: translateY(-7px) rotate(1deg);
  }
}

@keyframes mascotSearch {
  0%,
  100% {
    transform: translateX(0) rotate(-2deg);
  }
  50% {
    transform: translateX(-7px) rotate(2deg);
  }
}

@keyframes mascotHappy {
  0%,
  100% {
    transform: translateY(0) scale(1);
  }
  45% {
    transform: translateY(-10px) scale(1.04);
  }
}

.message {
  display: flex;
  margin-bottom: 14px;
}

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

.bubble {
  max-width: min(760px, 88%);
  border-radius: 8px;
  padding: 13px 15px;
  line-height: 1.48;
  white-space: pre-wrap;
}

.assistant .bubble {
  background: var(--soft);
  border: 1px solid #d6eadf;
}

.user .bubble {
  background: #22312c;
  color: #fff;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  padding: 16px 20px 20px;
  border-top: 1px solid var(--line);
}

textarea {
  width: 100%;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px 13px;
  min-height: 52px;
  max-height: 160px;
  outline: none;
}

textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(34, 116, 90, 0.13);
}

.sources {
  min-height: calc(100vh - 36px);
  overflow: hidden;
}

.sourcesHeader {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

#modeBadge {
  border-radius: 999px;
  background: #f1efe7;
  color: var(--warn);
  font-size: 12px;
  padding: 5px 9px;
}

.sourcesList {
  padding: 14px;
  overflow-y: auto;
  max-height: calc(100vh - 96px);
}

.sourceItem {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
}

.sourceItem strong {
  display: block;
  font-size: 14px;
  margin-bottom: 5px;
}

.sourceItem p {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.42;
}

.muted {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .workspace,
  .sources {
    min-height: auto;
  }

  .mascot {
    display: none;
  }

  .workspace {
    min-height: calc(100vh - 20px);
  }

  .topbar,
  .composer {
    grid-template-columns: 1fr;
    flex-direction: column;
    align-items: stretch;
  }

  .composer {
    display: grid;
  }
}
