:root {
  color-scheme: dark;
  --bg: #212121;
  --surface: #2f2f2f;
  --sidebar: #171717;
  --sidebar-hover: #242424;
  --sidebar-active: #2f2f2f;
  --text: #ececec;
  --muted: #b4b4b4;
  --muted-strong: #d7d7d7;
  --line: #3d3d3d;
  --line-strong: #565656;
  --composer: #303030;
  --accent: #19c37d;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

html {
  font-size: 90%;
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  background: #171717;
}

.login-panel {
  width: min(380px, calc(100% - 32px));
  display: grid;
  gap: 14px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #242424;
  box-shadow: var(--shadow);
}

.login-panel h1,
.login-panel p {
  margin: 0;
}

.login-panel p {
  color: var(--muted);
}

.login-panel label {
  display: grid;
  gap: 6px;
  color: var(--muted-strong);
  font-size: 0.9rem;
}

.login-panel input {
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 11px 12px;
  color: var(--text);
  background: #171717;
  outline: none;
}

.login-panel button,
.logout-button,
.admin-link {
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  color: #171717;
  background: #ffffff;
  cursor: pointer;
  font-weight: 650;
  text-align: center;
  text-decoration: none;
}

.login-error {
  min-height: 20px;
  color: #ffb4a8;
  font-size: 0.86rem;
}

button,
textarea,
select {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
}

.sidebar {
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  overflow: auto;
  background: var(--sidebar);
  color: #ececec;
}

.sidebar-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 40px;
  gap: 8px;
}

.new-chat-button,
.database-button,
.icon-button,
.history-item,
.account-button,
.send-button,
.model-chip,
.mobile-menu,
.suggestion {
  border: 0;
  cursor: pointer;
}

.new-chat-button,
.database-button,
.icon-button,
.history-item,
.account-button {
  border-radius: 10px;
  color: #ececec;
  background: transparent;
  transition: background-color 140ms ease;
}

.admin-link,
.logout-button {
  width: 100%;
  color: #ececec;
  background: #2f2f2f;
}

.logout-button {
  margin-top: -6px;
}

.new-chat-button {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  text-align: left;
  font-size: 0.94rem;
}

.database-button {
  width: 100%;
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  text-align: left;
  font-size: 0.94rem;
}

.sidebar-icon,
.icon-button {
  display: grid;
  place-items: center;
}

.sidebar-icon {
  width: 21px;
  height: 21px;
  border: 1px solid #ececec;
  border-radius: 7px;
  line-height: 1;
}

.icon-button {
  width: 40px;
  height: 40px;
  font-size: 1.25rem;
}

.new-chat-button:hover,
.database-button:hover,
.icon-button:hover,
.history-item:hover,
.account-button:hover {
  background: var(--sidebar-hover);
}

.chat-history {
  display: grid;
  gap: 2px;
}

.conversation-list {
  display: grid;
  gap: 2px;
}

.history-label {
  margin: 10px 8px 6px;
  color: #9b9b9b;
  font-size: 0.74rem;
}

.history-item {
  width: 100%;
  min-height: 36px;
  padding: 9px 10px;
  overflow: hidden;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9rem;
}

.conversation-history-item {
  display: grid;
  gap: 3px;
  white-space: normal;
}

.conversation-history-item span,
.conversation-history-item small {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-history-item small,
.history-empty,
.settings-kicker {
  color: #9b9b9b;
  font-size: 0.74rem;
}

.history-empty {
  margin: 4px 8px;
}

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

.database-button.active {
  background: var(--sidebar-active);
}

.sidebar-spacer {
  flex: 1;
}

.sidebar-settings {
  display: grid;
  gap: 6px;
  padding: 8px 0;
  border-top: 1px solid #2f2f2f;
  border-bottom: 1px solid #2f2f2f;
}

.settings-kicker {
  padding: 0 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.compact-toggle,
.model-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  color: #d8d8d8;
  font-size: 0.84rem;
}

.compact-toggle input {
  accent-color: var(--accent);
}

.model-row {
  justify-content: space-between;
}

.model-selector {
  max-width: 136px;
  border: 1px solid #3a3a3a;
  border-radius: 8px;
  padding: 6px 8px;
  color: #ececec;
  background: #212121;
  outline: none;
}

.account-button {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px;
  text-align: left;
}

.account-avatar,
.avatar {
  flex: none;
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 650;
}

.account-avatar {
  background: #6d5dd3;
  color: white;
}

.account-button strong,
.account-button small {
  display: block;
}

.account-button small {
  margin-top: 1px;
  color: #9b9b9b;
  font-size: 0.75rem;
}

.main-panel {
  min-width: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: var(--bg);
}

.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 18px;
  background: rgba(33, 33, 33, 0.92);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.model-chip,
.mobile-menu {
  height: 38px;
  border-radius: 10px;
  color: var(--text);
  background: transparent;
  font-weight: 600;
}

.model-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0 11px;
  font-size: 1.05rem;
}

.model-chip:hover,
.mobile-menu:hover {
  background: var(--surface);
}

.mobile-menu {
  display: none;
  width: 38px;
  font-size: 1.12rem;
}

.topbar-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.86rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--accent);
}

.chat-stage {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 0 0 26px;
}

.database-stage {
  min-height: 0;
  overflow: auto;
  padding: 22px 16px 34px;
}

.database-browser {
  width: min(1080px, 100%);
  margin: 0 auto;
  display: grid;
  gap: 14px;
}

.database-browser-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.database-browser-head h1,
.database-browser-head p {
  margin: 0;
}

.database-browser-head p,
.database-row span,
.database-row small,
.database-pager {
  color: var(--muted);
}

.database-browser-head button,
.database-filters button,
.database-pager button {
  border: 0;
  border-radius: 9px;
  padding: 9px 12px;
  color: #171717;
  background: #ffffff;
  cursor: pointer;
  font-weight: 650;
}

.database-filters {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) 170px 110px auto;
  gap: 8px;
}

.database-filters input,
.database-filters select {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  padding: 8px 10px;
  color: var(--text);
  background: #171717;
}

.database-results {
  display: grid;
  gap: 8px;
}

.database-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  background: #292929;
}

.database-row strong,
.database-row span,
.database-row small {
  display: block;
}

.database-row small {
  margin-top: 4px;
  word-break: break-word;
}

.database-snippet {
  margin: 9px 0 0;
  color: var(--muted-strong);
  line-height: 1.55;
}

.database-snippet mark {
  border-radius: 4px;
  padding: 0 3px;
  color: #171717;
  background: #f7d774;
}

.database-row a {
  border-radius: 8px;
  padding: 8px 10px;
  color: #171717;
  background: #ffffff;
  text-decoration: none;
  font-weight: 650;
  white-space: nowrap;
}

.database-pager {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 12px;
}

.empty-state,
.messages {
  width: min(768px, calc(100% - 32px));
  margin: 0 auto;
}

.empty-state {
  min-height: calc(100vh - 210px);
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 14px;
  text-align: center;
}

.empty-mark {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text);
  font-size: 1.6rem;
}

.empty-state h1 {
  margin: 0;
  font-size: clamp(1.85rem, 4vw, 2.25rem);
  line-height: 1.15;
  font-weight: 600;
  letter-spacing: 0;
}

.empty-subtitle {
  width: min(560px, 100%);
  margin: 0 0 10px;
  color: var(--muted);
  line-height: 1.55;
}

.suggestions {
  width: min(650px, 100%);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.suggestion {
  min-height: 58px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #2a2a2a;
  color: #ececec;
  text-align: left;
  line-height: 1.35;
  transition: background-color 140ms ease, border-color 140ms ease;
}

.suggestion:hover {
  background: var(--surface);
  border-color: var(--line-strong);
}

.messages {
  display: none;
  padding: 12px 0 24px;
}

.messages.has-messages {
  display: block;
}

.message {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr);
  gap: 16px;
  padding: 22px 0;
  animation: message-in 170ms ease;
}

.avatar {
  color: #ffffff;
  background: #10a37f;
}

.user-avatar {
  background: #6d5dd3;
}

.message-body {
  min-width: 0;
}

.message-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
}

.role {
  font-weight: 650;
}

.role,
.stamp {
  font-size: 0.88rem;
}

.stamp,
.composer-note {
  color: var(--muted);
}

.activity-block,
.evidence-block {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #2a2a2a;
}

.user-text {
  margin: 0;
  line-height: 1.68;
}

.activity-block {
  margin-bottom: 16px;
  overflow: hidden;
  background: #262626;
}

.activity-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  cursor: pointer;
  list-style: none;
}

.activity-summary::-webkit-details-marker,
.activity-entry summary::-webkit-details-marker {
  display: none;
}

.activity-summary-text {
  font-size: 0.92rem;
  font-weight: 650;
}

.activity-summary-state {
  color: var(--muted);
  font-size: 0.83rem;
}

.activity-body {
  padding: 0 14px 14px;
  border-top: 1px solid var(--line);
}

.activity-feed {
  margin: 0;
  padding: 12px 0 0;
  display: grid;
  gap: 8px;
}

.activity-entry {
  list-style: none;
}

.activity-entry details {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #303030;
}

.activity-entry summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 11px;
  cursor: pointer;
  list-style: none;
}

.activity-entry-title {
  display: block;
  font-size: 0.88rem;
  font-weight: 650;
}

.activity-entry-detail {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.45;
  word-break: break-word;
}

.activity-badge {
  flex: none;
  border-radius: 999px;
  padding: 4px 8px;
  background: #3d3d3d;
  color: var(--muted-strong);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.activity-command {
  margin: 0;
  padding: 0 11px 11px;
  color: #d7d7d7;
  font-size: 0.78rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.prose p,
.prose ul {
  margin: 0 0 14px;
}

.prose p,
.prose li,
.evidence-list li,
.evidence-snippets li {
  line-height: 1.74;
}

.prose ul,
.evidence-list {
  padding-left: 20px;
}

.prose a,
.evidence-list a,
.artifact-list a {
  color: #0f7a5f;
  text-decoration: none;
}

.prose a:hover,
.evidence-list a:hover,
.artifact-list a:hover {
  text-decoration: underline;
}

.evidence-block {
  margin-top: 18px;
  padding: 14px;
}

.evidence-summary {
  cursor: pointer;
  list-style: none;
}

.evidence-summary::-webkit-details-marker {
  display: none;
}

.evidence-block:not([open]) .evidence-summary {
  margin-bottom: 0;
}

.evidence-toggle {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.evidence-block[open] .evidence-toggle {
  color: var(--muted-strong);
}

.evidence-block[open] .evidence-toggle::before {
  content: "Ocultar";
}

.evidence-block[open] .evidence-toggle {
  font-size: 0;
}

.evidence-block[open] .evidence-toggle::before {
  font-size: 0.82rem;
}

.evidence-list {
  display: grid;
  gap: 12px;
  padding-left: 0;
  list-style: none;
}

.evidence-source {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #242424;
}

.evidence-source-head {
  display: grid;
  gap: 2px;
  margin-bottom: 8px;
}

.evidence-source-title {
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 700;
  text-decoration: none;
}

.evidence-source-title:hover {
  color: #0f7a5f;
  text-decoration: underline;
}

.evidence-source-head span {
  color: var(--muted);
  font-size: 0.82rem;
}

.evidence-snippets {
  display: grid;
  gap: 6px;
  margin: 0;
  padding-left: 18px;
}

.evidence-page {
  color: var(--muted);
  font-weight: 650;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.section-head h4 {
  margin: 0;
  font-size: 0.94rem;
}

.icon-button:disabled {
  opacity: 0.5;
  cursor: wait;
}

.artifact-block {
  margin: 0 0 14px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #242424;
}

.artifact-block h4 {
  margin: 0 0 8px;
  font-size: 0.9rem;
}

.artifact-list {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 0;
  list-style: none;
}

.artifact-list li {
  line-height: 1.6;
  font-size: 0.92rem;
}

.artifact-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.artifact-item-pdf {
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.artifact-icon {
  width: 34px;
  height: 34px;
  object-fit: contain;
}

.artifact-meta {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.artifact-meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.artifact-meta span,
.artifact-unavailable {
  color: var(--muted);
  font-size: 0.82rem;
}

.artifact-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.artifact-actions a {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 5px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  color: var(--text);
  background: #303030;
  font-weight: 650;
  text-decoration: none;
}

.artifact-actions a:hover {
  background: #3a3a3a;
  text-decoration: none;
}

.snippet {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.composer-wrap {
  padding: 14px 16px 18px;
  background: linear-gradient(180deg, rgba(33, 33, 33, 0) 0%, #212121 32%);
}

.composer {
  width: min(768px, calc(100% - 32px));
  margin: 0 auto;
  padding: 12px;
  border: 1px solid var(--line-strong);
  border-radius: 26px;
  background: var(--composer);
  box-shadow: var(--shadow);
}

textarea {
  width: 100%;
  min-height: 28px;
  max-height: 220px;
  resize: none;
  border: 0;
  padding: 4px 4px 0;
  background: transparent;
  color: var(--text);
  line-height: 1.55;
  outline: none;
}

textarea::placeholder {
  color: #b4b4b4;
}

.composer-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34px;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}

.send-button {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  font-weight: 700;
}

.send-button {
  background: #ffffff;
  color: #171717;
  font-size: 1.02rem;
  transition: opacity 140ms ease, transform 140ms ease;
}

.send-button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.send-button:disabled {
  opacity: 0.45;
  cursor: wait;
}

.composer-note {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.78rem;
}

.footer-note {
  margin: 8px auto 0;
  width: min(768px, calc(100% - 32px));
  color: #9b9b9b;
  font-size: 0.75rem;
  text-align: center;
}

.message.pending .evidence-block {
  display: none;
}

@keyframes message-in {
  from {
    opacity: 0;
    transform: translateY(5px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    display: none;
  }

  .mobile-menu {
    display: grid;
    place-items: center;
  }

  .topbar {
    padding: 0 12px;
  }

  .empty-state,
  .messages,
  .composer,
  .footer-note {
    width: min(768px, calc(100% - 24px));
  }
}

@media (max-width: 720px) {
  .topbar-status {
    max-width: 38%;
  }

  .topbar-status span:last-child {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .suggestions {
    grid-template-columns: 1fr;
  }

  .message {
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 12px;
  }

  .avatar {
    width: 30px;
    height: 30px;
  }

  .section-head,
  .message-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .composer-note {
    visibility: hidden;
  }

  .database-browser-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .database-filters,
  .database-row {
    grid-template-columns: 1fr;
  }
}
