:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --sidebar: #101828;
  --sidebar-hover: #1d2939;
  --sidebar-active: #1e3a5f;
  --text: #101828;
  --muted: #667085;
  --border: #e4e7ec;
  --accent: #1d4ed8;
  --accent-soft: #e8efff;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
}

#app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

/* ---------- Sidebar ---------- */

#sidebar {
  width: 280px;
  min-width: 280px;
  background: var(--sidebar);
  color: #eaecf0;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  gap: 8px;
  padding: 12px;
}

.sidebar-header .primary {
  flex: 1;
}

#chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px 8px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 4px;
  border-radius: 8px;
  margin-bottom: 2px;
  padding: 2px 4px;
}

.chat-item:hover {
  background: var(--sidebar-hover);
}

.chat-item.active {
  background: var(--sidebar-active);
}

.chat-title {
  flex: 1;
  min-width: 0;
  background: none;
  border: none;
  color: inherit;
  text-align: left;
  padding: 8px 6px;
  font-size: 14px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-action {
  background: none;
  border: none;
  color: #98a2b3;
  cursor: pointer;
  font-size: 13px;
  padding: 4px 5px;
  border-radius: 6px;
  opacity: 0;
}

.chat-item:hover .chat-action {
  opacity: 1;
}

.chat-action:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.vote-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  background: none;
  border: none;
  padding: 3px;
  border-radius: 5px;
  color: #98a2b3;
  opacity: 0.75;
  cursor: pointer;
}

.vote-btn:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.08);
}

.vote-btn.up.active {
  color: #22c55e;
  opacity: 1;
}

.vote-btn.down.active {
  color: #ef4444;
  opacity: 1;
}

.vote-btn.neutral.active {
  color: #eab308;
  opacity: 1;
}

.vote-btn svg {
  display: block;
}

.sidebar-footer {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  font-size: 12px;
  color: #98a2b3;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* ---------- Main ---------- */

#main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

#chat-header {
  padding: 14px 24px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

#chat-title {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#messages {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.msg {
  display: flex;
}

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

.msg.assistant {
  justify-content: flex-start;
}

.bubble {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 15px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}

.msg.user .bubble {
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
  white-space: pre-wrap;
}

.msg.assistant .bubble {
  background: var(--panel);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.bubble.error {
  border-color: #fecdca;
  background: #fef3f2;
  color: var(--danger);
}

/* Markdown */

.bubble .content > *:first-child {
  margin-top: 0;
}

.bubble .content > *:last-child {
  margin-bottom: 0;
}

.bubble .content p,
.bubble .content ul,
.bubble .content ol,
.bubble .content pre,
.bubble .content blockquote,
.bubble .content table {
  margin: 0.55em 0;
}

.bubble .content h1,
.bubble .content h2,
.bubble .content h3 {
  font-size: 1.05em;
  margin: 0.8em 0 0.4em;
}

.bubble .content pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: hidden;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-size: 13px;
}

.bubble .content code {
  background: rgba(16, 24, 40, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

.bubble .content pre code {
  background: none;
  padding: 0;
  white-space: inherit;
  overflow-wrap: inherit;
}

.code-block {
  position: relative;
}

.bubble .content .code-block pre {
  padding-top: 34px;
}

.copy-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 3px 10px;
  font-size: 12px;
  line-height: 1.4;
  border: 1px solid rgba(226, 232, 240, 0.3);
  border-radius: 6px;
  background: rgba(226, 232, 240, 0.12);
  color: #e2e8f0;
  cursor: pointer;
  opacity: 0.9;
}

.copy-btn:hover {
  opacity: 1;
  background: rgba(226, 232, 240, 0.22);
}

.copy-btn.copied {
  background: #16a34a;
  border-color: #16a34a;
  color: #fff;
}

.bubble .content blockquote {
  border-left: 3px solid var(--border);
  margin-left: 0;
  padding-left: 12px;
  color: var(--muted);
}

.bubble .content table {
  border-collapse: collapse;
}

.bubble .content th,
.bubble .content td {
  border: 1px solid var(--border);
  padding: 4px 8px;
}

.bubble .content a {
  color: var(--accent);
}

.msg.user .bubble .content a,
.msg.user .bubble a {
  color: #dbe7ff;
}

/* Raciocínio e busca */

.reasoning {
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--muted);
}

.reasoning summary {
  cursor: pointer;
  user-select: none;
}

.reasoning-text {
  margin-top: 6px;
  padding: 8px 10px;
  background: rgba(16, 24, 40, 0.04);
  border-radius: 8px;
  white-space: pre-wrap;
  max-height: 220px;
  overflow-y: auto;
}

.tool-status {
  font-size: 13px;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 6px 10px;
  margin-bottom: 8px;
}

.cursor {
  display: inline-block;
  animation: blink 1s steps(1) infinite;
  color: var(--accent);
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

/* Empty state */

#empty-state {
  margin: auto;
  max-width: 520px;
  text-align: center;
  color: var(--muted);
}

#empty-state h2 {
  color: var(--text);
  font-size: 20px;
}

#empty-state .empty-list {
  list-style: none;
  padding: 0;
  margin: 16px 0 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

#empty-state .empty-list li strong {
  color: var(--text);
}

/* Aviso de avaliação (anexo à conversa, mas fora dela) */

#eval-hint {
  align-self: flex-start;
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 14px;
  border-bottom-left-radius: 4px;
  background: var(--panel);
  border: 1px dashed var(--border);
  font-size: 13px;
  line-height: 1.55;
}

#eval-hint p {
  margin: 0;
}

.eval-options {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.eval-option {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--text);
  white-space: nowrap;
}

button.eval-option {
  font: inherit;
  font-size: 13px;
  padding: 4px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: none;
  cursor: pointer;
  opacity: 0.75;
}

button.eval-option:hover {
  opacity: 1;
  background: rgba(16, 24, 40, 0.05);
}

button.eval-option.active {
  opacity: 1;
}

button.eval-option.up.active {
  border-color: #22c55e;
  background: rgba(34, 197, 94, 0.12);
}

button.eval-option.neutral.active {
  border-color: #eab308;
  background: rgba(234, 179, 8, 0.12);
}

button.eval-option.down.active {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.12);
}

.eval-option svg {
  display: block;
}

.eval-option.up svg {
  color: #22c55e;
}

.eval-option.neutral svg {
  color: #eab308;
}

.eval-option.down svg {
  color: #ef4444;
}

/* Composer */

#composer {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  padding: 14px 24px 18px;
  background: var(--panel);
  border-top: 1px solid var(--border);
}

#composer textarea {
  flex: 1;
  resize: none;
  max-height: 180px;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font: inherit;
  font-size: 15px;
  line-height: 1.4;
  outline: none;
  background: var(--bg);
}

#composer textarea:focus {
  border-color: var(--accent);
  background: #fff;
}

button {
  font: inherit;
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 10px 16px;
  cursor: pointer;
  background: #fff;
  color: var(--text);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  color: #fff;
}

button.danger {
  background: var(--danger);
  color: #fff;
}

button.icon {
  font-size: 17px;
  line-height: 1;
  padding: 9px 11px;
  border-color: var(--border);
}

#search-toggle.active {
  background: var(--accent-soft);
  border-color: var(--accent);
}

/* Banner de aviso global */

#banner {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 24px;
  background: #fef3c7;
  color: #92400e;
  border-bottom: 1px solid #fde68a;
  font-size: 14px;
}

#banner[hidden] {
  display: none;
}

#banner-text {
  flex: 1;
  white-space: pre-wrap;
}

#banner-close {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-size: 13px;
  line-height: 1;
  padding: 5px 8px;
  border-radius: 6px;
  opacity: 0.8;
}

#banner-close:hover {
  opacity: 1;
  background: rgba(146, 64, 14, 0.12);
}

body.streaming #chat-list {
  pointer-events: none;
  opacity: 0.6;
}

/* ---------- Celular: sidebar em gaveta ---------- */

#sidebar-toggle {
  display: none;
}

#sidebar-overlay {
  display: none;
}

@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    width: min(84vw, 320px);
    min-width: 0;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: 0 0 40px rgba(16, 24, 40, 0.35);
  }

  body.sidebar-open #sidebar {
    transform: translateX(0);
  }

  body.sidebar-open #sidebar-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 30;
    background: rgba(16, 24, 40, 0.5);
  }

  #chat-header {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
  }

  #sidebar-toggle {
    display: inline-flex;
    flex: none;
    font-size: 17px;
    line-height: 1;
    padding: 7px 11px;
  }

  #chat-title {
    flex: 1;
    min-width: 0;
    font-size: 15px;
  }

  #messages {
    padding: 14px 12px;
    gap: 10px;
  }

  .bubble {
    max-width: 90%;
  }

  #eval-hint {
    max-width: 100%;
  }

  #composer {
    gap: 8px;
    padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  }

  #composer textarea {
    font-size: 16px;
    padding: 10px 12px;
  }

  #composer .icon {
    font-size: 16px;
    padding: 8px 10px;
  }

  #composer button.primary,
  #composer button.danger {
    padding: 10px 14px;
  }

  #banner {
    padding: 10px 12px;
    font-size: 13px;
  }

  #empty-state {
    max-width: 100%;
  }

  .chat-action {
    opacity: 0.7;
  }
}
