:root {
  --bg-color: #ffffff;
  --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;
  padding-bottom: 132px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  scroll-behavior: smooth;
  position: relative;
}

.msg {
  max-width: 85%;
  padding: 12px 16px;
  border-radius: 20px;
  border: 1px solid var(--border-color);
  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-color: rgba(255, 255, 255, 0.28);
  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 .md-content {
  white-space: normal;
}

.msg.assistant .md-content h1,
.msg.assistant .md-content h2,
.msg.assistant .md-content h3 {
  margin: 0 0 8px;
  line-height: 1.25;
}

.msg.assistant .md-content h1 {
  font-size: 20px;
}

.msg.assistant .md-content h2 {
  font-size: 18px;
}

.msg.assistant .md-content h3 {
  font-size: 16px;
}

.msg.assistant .md-content p {
  margin: 0 0 8px;
}

.msg.assistant .md-content p:last-child {
  margin-bottom: 0;
}

.msg.assistant .md-content hr {
  border: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.18);
  margin: 10px 0;
}

.msg.assistant .md-content ul,
.msg.assistant .md-content ol {
  margin: 0 0 8px 20px;
}

.msg.assistant .md-content li {
  margin: 4px 0;
}

.msg.assistant .md-content code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  background: rgba(0, 0, 0, 0.08);
  padding: 1px 4px;
  border-radius: 6px;
}

.msg.assistant .md-content pre {
  margin: 0 0 8px;
  background: rgba(0, 0, 0, 0.08);
  padding: 10px 12px;
  border-radius: 10px;
  overflow-x: auto;
}

.msg.assistant .md-content pre code {
  background: transparent;
  padding: 0;
}

.msg.assistant .md-content a {
  color: #0b57d0;
  text-decoration: underline;
}

.msg.assistant .md-content table {
  width: 100%;
  border-collapse: collapse;
  margin: 0 0 10px;
  font-size: 14px;
}

.msg.assistant .md-content th,
.msg.assistant .md-content td {
  border: 1px solid rgba(0, 0, 0, 0.15);
  padding: 6px 8px;
  vertical-align: top;
}

.msg.assistant .md-content thead th {
  background: rgba(0, 0, 0, 0.06);
  font-weight: 600;
}

.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 .typing-phrase {
  margin-left: 6px;
  color: var(--text-muted);
  font-size: 14px;
  display: inline-block;
  white-space: nowrap;
  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 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 .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;
}

.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;
}

#pdfInfoText {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.gate-action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  min-height: 24px;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  text-decoration: none;
  color: var(--accent);
  font-size: 12px;
  background: #ffffff;
}

.gate-action-btn.hidden {
  display: none;
}

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

.role-prompt {
  position: sticky;
  right: 0;
  bottom: 12px;
  margin-top: auto;
  width: max-content;
  align-self: flex-end;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  padding: 10px;
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid var(--border-color);
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.08);
  z-index: 20;
}

.role-prompt.hidden {
  display: none;
}

.role-prompt-title {
  font-size: 16px;
  font-weight: 700;
  color: #2f3a4f;
  text-align: right;
}

.role-prompt-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 6px;
  max-width: 100%;
}

.role-chip {
  border: 2px solid #b8c6e8;
  background: #f6f9ff;
  color: var(--text-main);
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease, box-shadow 0.2s ease;
  flex: 0 0 auto;
}

.role-chip:hover {
  border-color: #7f9ad6;
  background: #eef4ff;
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.12);
}

.role-chip:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.role-chip:focus-visible {
  outline: 2px solid rgba(0, 122, 255, 0.55);
  outline-offset: 1px;
}

.role-chip_skip {
  color: var(--text-muted);
}

.input-wrapper:focus-within,
.input-wrapper.pending,
.input-wrapper.has-attachment {
  border-color: var(--border-color);
  background: var(--bg-color);
  box-shadow: none;
}

.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;
  align-items: center;
  gap: 8px;
  margin-left: 2px;
  flex-shrink: 0;
}

.input-wrapper.has-attachment .actions-panel {
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}

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

.send-stack {
  position: relative;
  display: flex;
  align-items: center;
}

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;
}

.send-btn.gate-disabled {
  opacity: 0.45;
}

.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;
  flex-shrink: 0;
}

.pdf-remove-btn {
  width: 18px;
  height: 18px;
  min-width: 18px;
  border: none;
  border-radius: 50%;
  background: transparent;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.pdf-remove-btn:hover {
  background: rgba(0, 0, 0, 0.08);
  color: var(--text-main);
}

.pdf-remove-btn svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}

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