:root {
  --bg-color: #f4f5f8;
  --panel-bg: #ffffff;
  --text-main: #1c1c1e;
  --text-muted: #8e8e93;
  --accent: #007aff;
  --accent-hover: #0062cc;
  --user-msg: #007aff;
  --user-text: #ffffff;
  --assistant-msg: #e8e8f0;
  --border-color: rgba(60, 60, 67, 0.08);
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-family);
  background: var(--bg-color);
  color: var(--text-main);
  height: 100dvh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

header {
  background: var(--panel-bg);
  padding: 16px 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.02);
  z-index: 10;
}

.header-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

header h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.3px;
  margin: 0;
}

.header-subtitle {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: -0.2px;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 8px;
  border-radius: 50%;
  transition: 0.2s ease;
}

.icon-btn:hover {
  background: var(--bg-color);
  color: var(--text-main);
}

.icon-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.clear-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  background: var(--panel-bg);
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.2s ease;
}

.clear-btn span {
  white-space: nowrap;
}

.clear-btn:hover {
  background: var(--bg-color);
  color: var(--text-main);
  border-color: #c6c6c8;
}

.chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
}

.msg {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 20px;
  font-size: 15px;
  line-height: 1.4;
  white-space: pre-wrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  animation: fade-in 0.42s cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg.user {
  align-self: flex-end;
  background: var(--user-msg);
  color: var(--user-text);
  border-bottom-right-radius: 4px;
}

.msg.assistant {
  align-self: flex-start;
  background: var(--assistant-msg);
  color: var(--text-main);
  border-bottom-left-radius: 4px;
  border: 1px solid var(--border-color);
}

.msg.assistant.reveal {
  animation: reply-reveal 0.52s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.msg.typing {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 42px;
}

.msg.typing .agent-typing-badge {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #60a5fa;
  box-shadow: 0 0 0 0 rgba(96, 165, 250, 0.55);
  animation: typing-pulse 1.8s infinite ease-out;
}

.msg.typing .typing-phrase {
  margin-left: 6px;
  color: var(--text-muted);
  font-size: 14px;
  display: inline-block;
  white-space: nowrap;
  overflow: hidden;
  max-width: 0;
  border-right: 1px solid rgba(142, 142, 147, 0.75);
  transition: opacity 0.4s ease-in-out;
}

.msg.typing .typing-phrase.fade-out {
  animation: phrase-fade-out 0.3s ease-in-out forwards;
}

.msg.typing .typing-phrase.fade-in {
  animation: phrase-fade-in 0.3s ease-in-out forwards;
}

.msg.typing .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9ca3af;
  opacity: 0.45;
  animation: typing-dot 1.15s infinite ease-in-out;
}

.msg.typing .dot:nth-child(2) {
  animation-delay: 0.14s;
}

.msg.typing .dot:nth-child(3) {
  animation-delay: 0.28s;
}

@keyframes typing-dot {
  0%, 80%, 100% {
    transform: translateY(0);
    opacity: 0.35;
  }

  40% {
    transform: translateY(-4px);
    opacity: 1;
  }
}

@keyframes typing-pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(96, 165, 250, 0.55);
  }

  70% {
    box-shadow: 0 0 0 9px rgba(96, 165, 250, 0);
  }

  100% {
    box-shadow: 0 0 0 0 rgba(96, 165, 250, 0);
  }
}

@keyframes typing-text-reveal {
  from {
    max-width: 0;
  }

  to {
    max-width: 28ch;
  }
}

@keyframes typing-caret {
  from, to {
    border-right-color: transparent;
  }

  50% {
    border-right-color: rgba(142, 142, 147, 0.75);
  }
}

@keyframes phrase-fade-out {
  0% {
    opacity: 1;
  }

  100% {
    opacity: 0;
  }
}

@keyframes phrase-fade-in {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@keyframes reply-reveal {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.992);
    filter: blur(1.6px);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: blur(0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .msg,
  .msg.assistant.reveal,
  .msg.typing .dot,
  .msg.typing .agent-typing-badge,
  .msg.typing .typing-phrase.animate {
    animation: none;
  }
}

footer {
  background: var(--panel-bg);
  padding: 12px 20px 24px;
  border-top: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  gap: 12px;
  z-index: 10;
}

.badge-container {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  font-size: 13px;
}

.pdf-badge {
  display: none;
  align-items: center;
  gap: 6px;
  background: var(--bg-color);
  color: var(--text-muted);
  padding: 4px 10px;
  border-radius: 12px;
  font-size: 12px;
  border: 1px solid var(--border-color);
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-badge.visible {
  display: inline-flex;
}

#status {
  color: var(--text-muted);
  font-size: 12px;
}

.input-wrapper {
  display: flex;
  align-items: center;
  background: var(--bg-color);
  border-radius: 24px;
  padding: 8px 8px 8px 16px;
  border: 1px solid var(--border-color);
  transition: border 0.2s;
}

.input-wrapper:focus-within {
  border-color: #c6c6c8;
  background: #ffffff;
}

.input-wrapper.pending textarea {
  opacity: 0.5;
}

textarea {
  flex: 1;
  border: none;
  background: transparent;
  resize: none;
  max-height: 120px;
  min-height: 40px;
  padding: 8px 0;
  font-family: inherit;
  font-size: 15px;
  color: var(--text-main);
  outline: none;
}

.actions-panel {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  margin-left: 10px;
  flex-shrink: 0;
}

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

textarea::placeholder {
  color: var(--text-muted);
}

.send-btn {
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 12px;
  height: 40px;
  min-width: 126px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.send-btn:hover {
  background: var(--accent-hover);
  color: #ffffff;
}

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

.action-btn {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid var(--border-color);
}

.attach-btn {
  margin-left: 0;
}

svg {
  width: 20px;
  height: 20px;
  fill: currentColor;
}

.pdf-icon {
  width: 14px;
  height: 14px;
}

.send-icon {
  width: 16px;
  height: 16px;
}
