/* Marca Nexa1: a versão escura já traz fundo azul. Não colocar caixa branca em volta. */
.nexa1-brand-mark {
  height: 72px;
  width: auto;
  max-width: 100%;
  object-fit: contain;
  display: inline-block;
}
.nexa1-brand-mark--sidebar {
  height: 88px;
  display: block;
}
/* Marca compacta da barra superior: só entra no mobile (o desktop já tem a marca na lateral). */
.nexa1-brand-mark--topbar {
  height: 2rem;
}
.app-topbar-brand {
  display: inline-flex;
  align-items: center;
  flex-shrink: 0;
  line-height: 0;
  text-decoration: none;
}
.nexa1-brand-mark--dark { display: none; }
[data-bs-theme="dark"] .nexa1-brand-mark--light { display: none; }
[data-bs-theme="dark"] .nexa1-brand-mark--dark { display: inline-block; }
.app-sidebar-brand-link {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  margin: 0;
  padding: 0;
  line-height: 0;
  text-decoration: none;
}

.app-help-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  margin: 0;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.app-help-toggle-text {
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--tblr-secondary, #6b7280);
  line-height: 1;
}
.app-help-toggle-track {
  position: relative;
  display: inline-block;
  width: 2rem;
  height: 1.125rem;
  flex-shrink: 0;
}
.app-help-toggle-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
  z-index: 2;
}
.app-help-toggle-thumb {
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: var(--tblr-border-color, #d1d5db);
  transition: background 0.15s ease;
}
.app-help-toggle-thumb::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: calc(1.125rem - 4px);
  height: calc(1.125rem - 4px);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.18);
  transition: transform 0.15s ease;
}
.app-help-toggle-input:checked + .app-help-toggle-thumb {
  background: var(--tblr-primary, #066fd1);
}
.app-help-toggle-input:checked + .app-help-toggle-thumb::after {
  transform: translateX(0.875rem);
}
.app-admin-shell.app-help-expanded .app-help-toggle-text {
  color: var(--tblr-primary, #066fd1);
}
.popover.app-hint-wide {
  max-width: 28rem;
}
.popover.app-hint-wide .popover-body {
  max-height: 16rem;
  overflow: auto;
  white-space: pre-wrap;
}

.app-ctx-menu {
  position: fixed;
  z-index: 2000;
  display: none;
  min-width: 220px;
  background: #fff;
  color: #1e293b;
  border: 1px solid #dee2e6;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 0.35rem 0;
}
.app-ctx-menu.is-open { display: block; }
.app-ctx-menu .app-ctx-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  padding: 0.45rem 1rem;
  color: #1f2937;
  text-decoration: none;
}
.app-ctx-menu .app-ctx-item.danger { color: #d63939; }
.app-ctx-menu .app-ctx-item:hover { background: #f1f5f9; }

.code-preview {
  display: block;
  background: #ffffff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 0.75rem 1rem;
  font-size: 0.8125rem;
  line-height: 1.45;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.code-preview-scroll { max-height: 16rem; }

.chat-copy-block {
  margin: 0.35rem 0 0.55rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #ffffff;
  overflow: hidden;
}
.chat-copy-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.2rem 0.35rem 0.2rem 0.75rem;
  background: #f8fafc;
  color: #1e293b;
}
.chat-copy-lang {
  font-size: 0.75rem;
  color: #475569;
}
.chat-copy-btn {
  border: 0;
  background: transparent;
  color: #1e293b;
  font-size: 0.75rem;
  line-height: 1.2;
  padding: 0.2rem 0.45rem;
  border-radius: 4px;
  cursor: pointer;
}
.chat-copy-btn:hover { background: #e2e8f0; }
.chat-copy-btn .ti { font-size: 1rem; line-height: 1; }
.chat-table-block {
  position: relative;
  margin: 0.35rem 0 0.55rem;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  background: #ffffff;
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
}
.chat-table-block .chat-md-table-wrap { margin: 0; }
.chat-table-block .chat-copy-bar { border-bottom: 1px solid #e2e8f0; }
.chat-bubble.assistant .chat-copy-block pre.code-preview,
.chat-copy-block pre.code-preview {
  margin: 0;
  border: 0;
  border-radius: 0;
  border-top: 1px solid #e2e8f0;
}

.chat-log { min-height: 240px; }
/* Só o histórico rola. O compositor fica preso no fim da área útil. */
html:has(.chat-screen),
body:has(.chat-screen) {
  height: 100%;
  overflow: hidden;
}
.app-admin-shell:has(.chat-screen) {
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}
.app-admin-shell:has(.chat-screen) > .page-wrapper {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-height: 100dvh;
  min-height: 0;
  overflow: hidden;
}
.app-admin-shell:has(.chat-screen) > .page-wrapper > .app-topbar {
  flex: 0 0 auto;
}
.app-admin-shell:has(.chat-screen) .page-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.app-admin-shell:has(.chat-screen) .page-body > .container-xl {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.app-admin-shell:has(.chat-screen) .page-body > .container-xl > :not(.chat-screen) {
  flex: 0 0 auto;
}
.chat-screen {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.chat-screen > .chat-log {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  margin-bottom: 0;
  overflow-x: hidden;
  overflow-y: auto;
  scroll-padding-bottom: 1.5rem;
  padding-bottom: 0.75rem;
}
.chat-composer {
  flex: 0 0 auto;
  /* Folga para a borda e o anel de foco não serem cortados pelo overflow da tela. */
  padding: 0.65rem 0.45rem 0.2rem;
}
.chat-composer-box {
  display: flex;
  align-items: flex-end;
  gap: 0.45rem;
  border: 1px solid var(--tblr-border-color, #d1d5db);
  border-radius: 1.6rem;
  padding: 0.4rem 0.4rem 0.4rem 0.95rem;
  background: var(--tblr-bg-surface, #fff);
}
.chat-composer-box:focus-within {
  border-color: var(--tblr-primary, #066fd1);
  box-shadow: 0 0 0 0.15rem rgba(6, 111, 209, 0.16);
}
.chat-composer-box textarea {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  resize: none;
  overflow-y: hidden;
  line-height: 1.5;
  max-height: calc(1.5em * 6 + 0.7rem);
  padding: 0.4rem 0;
  background: transparent;
  box-shadow: none;
  field-sizing: fixed;
}
.chat-composer-box textarea:focus {
  outline: none;
  box-shadow: none;
}
.chat-send {
  flex: 0 0 auto;
  width: 2.05rem;
  height: 2.05rem;
  margin-bottom: 0.05rem;
  border: 0;
  border-radius: 999px;
  background: var(--tblr-primary, #066fd1);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.chat-send .ti { font-size: 1.15rem; line-height: 1; }
.chat-send:disabled {
  opacity: 0.4;
  cursor: default;
}
.chat-send.is-stop {
  background: #1f2937;
}
[data-bs-theme="dark"] .chat-send.is-stop {
  background: #e5e7eb;
  color: #111827;
}
.improve-panel {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 1040;
  width: min(34rem, calc(100vw - 2rem));
  height: min(32rem, calc(100vh - 5rem));
  min-width: 20rem;
  min-height: 18rem;
  max-width: calc(100vw - 1rem);
  max-height: calc(100vh - 1rem);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 0.5rem 1.5rem rgba(15, 23, 42, 0.18);
}
.improve-panel[hidden] { display: none !important; }
.improve-panel.is-minimized {
  height: auto;
  min-height: 0;
  max-height: none;
}
.improve-panel.is-minimized .improve-panel-body,
.improve-panel.is-minimized .improve-panel-resize { display: none; }
.improve-panel-header {
  cursor: grab;
  touch-action: none;
  user-select: none;
  flex: 0 0 auto;
}
.improve-panel.is-dragging .improve-panel-header { cursor: grabbing; }
.improve-panel.is-dragging,
.improve-panel.is-resizing { user-select: none; }
.improve-panel-body {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: auto;
}
.improve-panel .chat-composer,
.improve-panel #improve-refresh { flex: 0 0 auto; }
.improve-panel .chat-composer { padding: 0.15rem 0 0; }
.improve-panel .chat-log {
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  min-height: 8rem;
  max-height: none;
  overflow-x: hidden;
  overflow-y: auto;
  margin-bottom: 0.5rem;
}
.improve-panel-resize {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 1.15rem;
  height: 1.15rem;
  padding: 0;
  border: 0;
  background: transparent;
  cursor: nwse-resize;
  touch-action: none;
}
.improve-panel-resize::before {
  content: "";
  position: absolute;
  right: 0.28rem;
  bottom: 0.28rem;
  width: 0.55rem;
  height: 0.55rem;
  border-right: 2px solid var(--tblr-secondary, #6b7280);
  border-bottom: 2px solid var(--tblr-secondary, #6b7280);
}
.chat-bubble {
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
  margin-bottom: 0.5rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
  min-width: 0;
  max-width: 100%;
}
.chat-bubble-body {
  min-width: 0;
  max-width: 100%;
}
.chat-bubble.user {
  background: var(--tblr-primary-lt, #e7f1ff);
  white-space: pre-wrap;
}
/* O pre-wrap fica no texto. No balão, quebra de linha do HTML vira faixa vazia. */
.chat-bubble.user:has(.chat-bubble-body) { white-space: normal; }
.chat-bubble.user .chat-bubble-body { white-space: pre-wrap; }
.chat-bubble.assistant { background: var(--tblr-bg-surface-secondary, #f6f8fb); }
.chat-working {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
}
.chat-working-mark {
  height: 48px;
  width: auto;
  max-width: 7.5rem;
  object-fit: contain;
  animation: nexa1-working 1.1s ease-in-out infinite;
}
.chat-working-mark--dark { display: none; }
[data-bs-theme="dark"] .chat-working-mark--light { display: none; }
[data-bs-theme="dark"] .chat-working-mark--dark { display: inline-block; }
.chat-bubble.has-trace { position: relative; padding-right: 1.85rem; }
.chat-trace-open {
  position: absolute;
  top: 0.28rem;
  right: 0.28rem;
  width: 1.4rem;
  height: 1.4rem;
  border: 0;
  background: transparent;
  color: #64748b;
  padding: 0;
  border-radius: 4px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.chat-trace-open:hover { background: var(--tblr-bg-surface, #e2e8f0); color: var(--tblr-body-color, #1e293b); }
.chat-trace-open .ti { font-size: 0.95rem; line-height: 1; }
.chat-trace[hidden] { display: none !important; }
.chat-bubble.assistant pre.chat-trace { margin: 0 0 0.45rem; max-height: 16rem; }
.chat-turn-meta {
  margin: -0.2rem 0.15rem 0.7rem;
  font-size: 0.75rem;
  line-height: 1.35;
  color: #64748b;
}
.chat-working-label { color: var(--tblr-secondary, #6b7280); }
@keyframes nexa1-working {
  0%, 100% { transform: scale(0.92); opacity: 0.45; }
  50% { transform: scale(1); opacity: 1; }
}
.chat-bubble.assistant:not(.is-formatted) { white-space: pre-wrap; }
.chat-bubble.assistant:has(.chat-bubble-body) { white-space: normal; }
.chat-bubble.assistant:not(.is-formatted) .chat-bubble-body { white-space: pre-wrap; }
.chat-bubble.assistant.is-formatted,
.chat-bubble.assistant.is-formatted .chat-bubble-body { white-space: normal; }
.chat-bubble.assistant p { margin: 0 0 0.55rem; }
.chat-bubble.assistant h1,
.chat-bubble.assistant h2,
.chat-bubble.assistant h3 {
  font-size: 1rem;
  font-weight: 650;
  margin: 0.15rem 0 0.45rem;
  line-height: 1.35;
}
.chat-bubble.assistant ul,
.chat-bubble.assistant ol {
  margin: 0.15rem 0 0.55rem;
  padding-left: 1.35rem;
}
.chat-bubble.assistant ul { list-style: disc; }
.chat-bubble.assistant ol { list-style: decimal; }
.chat-bubble.assistant li + li { margin-top: 0.2rem; }
.chat-bubble.assistant li > ul,
.chat-bubble.assistant li > ol { margin: 0.25rem 0 0.15rem; }
.chat-bubble.assistant blockquote {
  margin: 0.3rem 0 0.55rem;
  padding-left: 0.75rem;
  border-left: 3px solid #cbd5e1;
  color: #334155;
}
.chat-bubble.assistant hr {
  margin: 0.6rem 0;
  border: 0;
  border-top: 1px solid #e2e8f0;
}
.chat-bubble.assistant a { color: var(--tblr-primary, #066fd1); }
.chat-bubble.assistant code {
  background: #fff;
  color: #1e293b;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 0.05em 0.35em;
  font-size: 0.85em;
}
.chat-bubble.assistant pre.code-preview { margin: 0.35rem 0 0.55rem; }
.chat-bubble.assistant.is-formatted > :last-child,
.chat-bubble.assistant.is-formatted .chat-bubble-body > :last-child { margin-bottom: 0; }
.chat-md-table-wrap {
  display: block;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  margin: 0.35rem 0 0.55rem;
  scrollbar-width: thin;
  scrollbar-color: #64748b #e2e8f0;
}
.chat-md-table-wrap::-webkit-scrollbar { height: 8px; }
.chat-md-table-wrap::-webkit-scrollbar-track { background: #e2e8f0; }
.chat-md-table-wrap::-webkit-scrollbar-thumb {
  background: #64748b;
  border-radius: 4px;
}
.chat-bubble.assistant .chat-md-table-wrap .table {
  width: max-content;
  min-width: 100%;
  margin-bottom: 0;
  background: #fff;
}
.chat-bubble.assistant .chat-md-table-wrap th,
.chat-bubble.assistant .chat-md-table-wrap td {
  vertical-align: top;
  white-space: nowrap;
  overflow-wrap: normal;
  word-break: normal;
}

/* Shell: lateral fixa, faixa de ícones no desktop, gaveta no mobile (mesmo arranjo do portal). */
.app-admin-shell {
  --app-sidebar-w: 15rem;
}
.app-nav-icon {
  font-size: 1.25rem;
  line-height: 1;
  flex-shrink: 0;
}
.app-sidebar-head {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.75rem 0.5rem 0.35rem;
}
.app-sidebar-nav .nav-section-label {
  display: block;
  padding: 0.85rem 1rem 0.3rem;
  font-size: 0.6875rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.55);
}
.app-sidebar-nav .nav-link {
  border-radius: 6px;
  margin: 0 0.5rem;
  color: rgba(255, 255, 255, 0.86);
}
.app-sidebar-nav .nav-link:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.06);
}
.app-sidebar-nav .nav-link.active {
  color: #fff;
  background: rgba(6, 111, 209, 0.35);
}
.app-recent-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.app-recent-empty {
  font-size: 0.75rem;
  color: rgba(255, 255, 255, 0.55);
  padding-bottom: 0.5rem;
}
.app-sidebar-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
}
.app-sidebar-footer {
  margin-top: auto;
  flex-shrink: 0;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding: 0.65rem 0.75rem 0.85rem;
}
.app-sidebar-version {
  font-size: 0.65rem;
  text-align: center;
  color: rgba(255, 255, 255, 0.42);
  padding-bottom: 0.25rem;
}
.app-topbar {
  background: var(--tblr-bg-surface, #fff);
  border-bottom: 1px solid var(--tblr-border-color, #e6e7e9);
}

@media (min-width: 992px) {
  .app-admin-shell > .navbar-vertical.navbar-expand-lg {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--app-sidebar-w) !important;
    height: 100vh;
    overflow: hidden;
    transform: none !important;
    transition: width 0.2s ease;
  }
  /* !important: o Tabler fixa margin-left: 15rem no irmão da lateral e ganha da variável. */
  .app-admin-shell > .page-wrapper {
    margin-left: var(--app-sidebar-w) !important;
    min-width: 0;
    min-height: 100vh;
    transition: margin-left 0.2s ease;
  }
  .app-admin-shell > .navbar-vertical > .container-fluid {
    display: flex;
    flex-direction: column;
    height: 100vh;
    min-height: 0;
    overflow: hidden;
  }
  .app-admin-shell > .navbar-vertical .navbar-collapse {
    display: flex !important;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }
  .app-admin-shell.sidebar-collapsed {
    --app-sidebar-w: 4.5rem;
  }
  .app-admin-shell.sidebar-collapsed .nexa1-brand-mark--sidebar {
    height: 2.25rem;
  }
  .app-admin-shell.sidebar-collapsed .nav-link-title,
  .app-admin-shell.sidebar-collapsed .nav-section-label,
  .app-admin-shell.sidebar-collapsed .app-sidebar-logout-text,
  .app-admin-shell.sidebar-collapsed .app-sidebar-version,
  .app-admin-shell.sidebar-collapsed .app-recent-empty {
    display: none !important;
  }
  .app-admin-shell.sidebar-collapsed .app-sidebar-nav .nav-link,
  .app-admin-shell.sidebar-collapsed .app-sidebar-footer .nav-link {
    justify-content: center;
    padding-left: 0.45rem;
    padding-right: 0.45rem;
  }
}

@media (max-width: 991.98px) {
  .app-admin-shell {
    --app-sidebar-w: 0rem;
  }
  .app-admin-shell > .navbar-vertical {
    position: fixed !important;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(18rem, 88vw) !important;
    height: 100vh;
    height: 100dvh;
    z-index: 1040;
    margin: 0;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    overflow: hidden;
  }
  .app-admin-shell.sidebar-mobile-open > .navbar-vertical {
    transform: none;
    box-shadow: 0 0.5rem 1.5rem rgba(0, 0, 0, 0.28);
  }
  .app-admin-shell > .page-wrapper {
    margin-left: 0 !important;
  }
  /* Abaixo de lg o Tabler não empilha o container: flex-wrap joga o menu
     e o Sair para uma segunda coluna, cortada pelo overflow da gaveta. */
  #app-sidebar > .container-fluid {
    display: flex !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    align-items: stretch !important;
    justify-content: flex-start !important;
    width: 100% !important;
    height: 100%;
    max-height: 100dvh;
    overflow: hidden;
    padding: 0;
  }
  #app-sidebar > .container-fluid > .navbar-collapse {
    display: flex !important;
    flex: 1 1 auto !important;
    flex-direction: column !important;
    align-items: stretch !important;
    min-height: 0;
    width: 100% !important;
    overflow: hidden;
  }
  #app-sidebar > .container-fluid > .app-sidebar-footer {
    width: 100%;
    max-width: 100%;
    align-self: stretch;
    flex: 0 0 auto;
    margin-top: auto;
    margin-left: 0;
  }
  #app-sidebar .app-sidebar-footer .navbar-nav {
    flex-direction: column;
    width: 100%;
  }
  #app-sidebar .app-sidebar-footer .nav-link {
    width: 100%;
    justify-content: flex-start;
  }
  .app-sidebar-head {
    width: 100%;
    justify-content: space-between;
    padding-right: 0.35rem;
  }
  .app-topbar > .container-xl {
    flex-wrap: nowrap !important;
    justify-content: flex-start !important;
  }
  .app-topbar .page-title {
    min-width: 0;
    flex: 1 1 auto;
  }
  .app-topbar .navbar-nav {
    flex-shrink: 0;
  }
  .app-sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1035;
    background: rgba(15, 23, 42, 0.45);
  }
  .app-sidebar-backdrop[hidden] {
    display: none !important;
  }
}

.list-mark { font-size: 1.15rem; vertical-align: middle; }
