/*
 * Estrutura visual comum aos 3 portais. Só consome variáveis — nenhuma cor, logo ou nome de marca
 * aqui. O que muda por portal está em /theme/theme.css.
 */

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

/*
 * O atributo hidden só vale enquanto ninguém declarar display no elemento: o `display: none`
 * dele vem da folha do user-agent, que perde para QUALQUER regra de autor. Sem isto, um
 * elemento com hidden e com display próprio continua na tela — foi o que expôs o
 * "Emular usuário" (de `.user-menu a { display: block }`) para não-admin.
 * Regra global para o hidden valer sempre; não repita remendos por seletor.
 */
[hidden] {
  display: none !important;
}

body {
  font-family: var(--portal-font, 'Roboto', system-ui, -apple-system, 'Segoe UI', sans-serif);
}

/* ==========================================================================
   Login
   ========================================================================== */

.login-page {
  background-image: var(--portal-background);
  /* Cor sob a imagem: aparece enquanto ela carrega e nas bordas que o cover não cobre. */
  background-color: var(--portal-login-backdrop);
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  overflow: hidden;
}

.login-header {
  height: 70px;
}

.login-header .brand-mark {
  width: 100px;
  padding: 20px 0 0 15px;
}

.main-login {
  display: flex;
  flex-direction: row-reverse;
  justify-content: center;
  align-items: center;
  height: 100vh;
}

.left-login,
.right-login {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  height: 100vh;
  width: 50%;
  padding-top: 4%;
}

.left-login {
  margin-right: 60px;
}

.right-login {
  align-items: center;
}

.left-login .brand-logo {
  display: none;
}

.left-login h1 {
  color: #fff;
  font-size: 35px;
  font-weight: 400;
  letter-spacing: -0.375px;
  padding: 0 10px 0 20px;
  text-align: justify;
}

.left-login p {
  color: #fff;
  font-size: 20px;
  line-height: 30.856px;
  letter-spacing: 0.3px;
  padding: 0 10px 0 20px;
  text-align: justify;
}

.brand-rule {
  width: 32%;
  padding: 2px 0;
  margin: 10px 0 10px 20px;
  background: var(--portal-button, var(--portal-accent-gradient));
  border-radius: 3px;
}

/* O tom do vidro é por portal: um véu claro pede fundo colorido claro, e sobre o quase-preto do
   D1000 vira cinza lama. As legendas são brancas nos dois casos, então o véu escuro só melhora. */
.card-login,
.modal-content {
  width: 65%;
  padding: 30px 35px;
  background: var(--portal-card-bg);
  border-radius: 10px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(25px);
  display: flex;
  flex-direction: column;
}

.card-login h2 {
  color: #fff;
  margin: 10px 0;
}

.card-login small {
  font-size: x-small;
  color: var(--portal-card-footnote);
  text-align: center;
  margin-top: 1rem;
}

.textfield {
  width: 100%;
  display: flex;
  flex-direction: column;
  margin: 15px 0;
}

.textfield label {
  color: #fff;
  margin-bottom: 10px;
}

.textfield input {
  width: 100%;
  border: none;
  border-radius: 8px;
  padding: 15px;
  margin-top: 0.5rem;
  background: #f5f5f5;
  font-size: 12pt;
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.3);
  outline: none;
}

.textfield input:focus-visible {
  outline: 2px solid var(--portal-accent);
  outline-offset: 2px;
}

.login-row {
  display: flex;
  justify-content: flex-end;
}

.login-row a {
  color: #fff;
}

.btn-primary {
  margin: 0.6rem 0 0 0;
  transition: filter 0.2s ease-in-out;
  padding: 10px;
  border: none;
  border-radius: 5px;
  outline: none;
  font-weight: 400;
  font-size: 11pt;
  cursor: pointer;
  box-shadow: 1px 1px 2px rgba(0, 0, 0, 0.25);
  width: 100%;
  /* O botão fica sempre sobre o véu escuro do card ou do modal: o portal pode trocar a cor. */
  color: var(--portal-button-text, #f5f5f5);
  background: var(--portal-button, var(--portal-accent-gradient));
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn-primary:active {
  box-shadow: inset 1px 1px 2px rgba(0, 0, 0, 0.25);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: progress;
}

/* Mensagem de erro/aviso do login. role="alert" no HTML: leitores de tela anunciam. */
.form-message {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 10pt;
  line-height: 1.4;
  color: #fff;
  background: rgba(176, 0, 32, 0.85);
}

.form-message:empty {
  display: none;
}

.form-message[data-tone='success'] {
  background: rgba(0, 105, 62, 0.9);
}

/* ==========================================================================
   Dashboard
   ========================================================================== */

.dashboard-page {
  background-color: #fff;
}

.head {
  height: 72px;
  width: 100%;
  padding: 10px 10px 0 10px;
  display: inline-flex;
  align-items: center;
  color: #fff;
  position: fixed;
  z-index: 1000;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  background: var(--portal-gradient);
}

/* Largura é por portal: as marcas têm proporções bem diferentes (a da Distribuição é quase
   quadrada, a do D1000 é um logotipo deitado e some se receber os mesmos 50px). */
.head .brand-mark {
  width: var(--portal-mark-width);
}

.head h1 {
  width: 100%;
  margin: 0;
  padding-left: 15px;
  color: #fff;
  font-size: 20px;
  font-weight: 600;
}

/* A faixa de 9px logo abaixo do header — assinatura visual herdada. */
.gradient-rule {
  height: 9px;
  background: var(--portal-gradient);
  position: fixed;
  top: 71px;
  left: 0;
  right: 0;
  z-index: 999;
}

.user-profile {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  position: relative;
}

.avatar-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background-color: #bebebe;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #232629;
  font-size: 16px;
  font-weight: 600;
}

.user-menu-toggle {
  background: none;
  border: none;
  cursor: pointer;
  color: #fff;
  font-size: 16px;
  padding: 5px 10px;
}

.user-menu {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  min-width: 200px;
  background: rgba(35, 38, 41, 0.85);
  backdrop-filter: blur(10px);
  border-radius: 6px;
  padding: 5px;
  z-index: 1001;
}

.user-menu[data-open='true'] {
  display: block;
}

.user-menu a {
  text-decoration: none;
  color: #fff;
  display: block;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 10pt;
}

.user-menu a:hover,
.user-menu a:focus-visible {
  background: #fff;
  color: var(--portal-accent);
}

.user-menu hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.2);
  margin: 5px 0;
}

.dashboard-container {
  position: absolute;
  left: 0;
  right: 0;
  top: 80px;
  bottom: 0;
  display: flex;
  flex-direction: column;
}

.report-container {
  width: 100%;
  flex: 1;
  min-height: 0;
}

/* Menu de relatórios: só aparece quando o portal tem mais de um. */
.report-tabs {
  display: flex;
  gap: 4px;
  padding: 0 12px;
  background: #fff;
  border-bottom: 1px solid #ddd;
}

.report-tabs[hidden] {
  display: none;
}

.report-tabs button {
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  padding: 10px 16px;
  font: inherit;
  font-size: 10pt;
  color: #444;
  cursor: pointer;
}

.report-tabs button[aria-current='true'] {
  border-bottom-color: var(--portal-accent);
  color: var(--portal-accent);
  font-weight: 600;
}

.report-container iframe {
  border: none;
}

/* Estado de carregamento/erro do embed, no lugar do relatório. */
.report-status {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  padding: 24px;
  text-align: center;
  color: #444;
  font-size: 11pt;
  line-height: 1.5;
}

/* ==========================================================================
   Painel de administração
   ========================================================================== */

.admin-page {
  background-color: #fff;
}

.admin-container {
  padding: 96px 32px 32px;
}

.admin-tabs {
  display: flex;
  gap: 4px;
  border-bottom: 2px solid #e4e4e4;
  margin-bottom: 20px;
}

.admin-tab {
  border: none;
  background: none;
  padding: 10px 18px;
  font-size: 11pt;
  cursor: pointer;
  color: #666;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
}

.admin-tab.active {
  color: var(--portal-accent);
  border-bottom-color: var(--portal-accent);
  font-weight: 600;
}

/* Barra de portal + busca no topo das seções de catálogo. */
.section-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  margin-bottom: 16px;
}

.section-bar .filter {
  margin: 0;
}

.section-bar .spacer {
  flex: 1;
}

.admin-container h2 {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.admin-hint {
  color: #666;
  font-size: 11pt;
  margin-bottom: 16px;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: flex-end;
  padding: 16px;
  background: #f7f7f7;
  border-radius: 8px;
  margin-bottom: 16px;
}

.filter {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter label {
  font-size: 10pt;
  color: #444;
}

.filter select,
.filter input {
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 7px 9px;
  font-size: 10pt;
  background: #fff;
  min-width: 150px;
}

.filter select:focus-visible,
.filter input:focus-visible {
  outline: 2px solid var(--portal-accent);
  outline-offset: 1px;
}

.filter-actions {
  display: flex;
  gap: 8px;
}

.btn-filter {
  border: none;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 10pt;
  cursor: pointer;
  color: #fff;
  background: var(--portal-accent-gradient);
}

.btn-clear {
  border: 1px solid #ccc;
  border-radius: 6px;
  padding: 8px 16px;
  font-size: 10pt;
  cursor: pointer;
  background: #fff;
  color: #333;
}

/* Tabelas largas rolam dentro do próprio container: a página nunca rola na horizontal. */
.table-wrap {
  overflow-x: auto;
  border: 1px solid #e4e4e4;
  border-radius: 8px;
}

.user-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 10pt;
}

.user-table th,
.user-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid #eee;
  white-space: nowrap;
}

.user-table th {
  background: #fafafa;
  font-weight: 600;
  color: #333;
}

.user-table tbody tr:hover {
  background: #fbfbfb;
}

.user-table .col-email {
  white-space: normal;
  word-break: break-all;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 9pt;
  background: #eee;
  color: #333;
}

.badge[data-active='true'] {
  background: #e2f3e8;
  color: #0a6b3d;
}

.badge[data-active='false'] {
  background: #f6e2e2;
  color: #8c1c1c;
}

.muted {
  color: #999;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 12px 4px;
  font-size: 10pt;
  color: #444;
}

.pagination button {
  border: 1px solid #ccc;
  background: #fff;
  border-radius: 6px;
  padding: 5px 12px;
  cursor: pointer;
  font-size: 10pt;
}

.pagination button:disabled {
  opacity: 0.45;
  cursor: default;
}

.table-status {
  padding: 24px;
  text-align: center;
  color: #666;
  font-size: 10pt;
}

.admin-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.btn-new {
  border: none;
  border-radius: 6px;
  padding: 9px 18px;
  font-size: 10pt;
  cursor: pointer;
  color: #fff;
  background: var(--portal-accent-gradient);
}

.row-actions {
  display: flex;
  gap: 10px;
  white-space: nowrap;
}

.row-actions button {
  border: none;
  background: none;
  padding: 0;
  font-size: 10pt;
  color: var(--portal-accent);
  cursor: pointer;
  text-decoration: underline;
}

.row-actions button.danger {
  color: #b00020;
}

.row-actions button:disabled {
  color: #bbb;
  cursor: default;
  text-decoration: none;
}

/* ==========================================================================
   Formulário de usuário e seletor de códigos/grupos
   ========================================================================== */

.modal-content.form-modal {
  width: 100%;
  max-width: 620px;
  max-height: 85vh;
  overflow-y: auto;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px 16px;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  color: #fff;
  font-size: 10pt;
}

.field input,
.field select {
  border: none;
  border-radius: 6px;
  padding: 9px;
  font-size: 10pt;
  background: #f5f5f5;
}

.field input:disabled {
  background: #d8d8d8;
  color: #595959;
}

.field input:focus-visible,
.field select:focus-visible {
  outline: 2px solid var(--portal-accent);
  outline-offset: 1px;
}

/* Seletor com chips + busca. Serve códigos (busca no servidor) e grupos (filtro local). */
.picker {
  border: 1px solid #555;
  border-radius: 6px;
  background: #f5f5f5;
  padding: 6px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 6px;
}

.chips:empty {
  margin-bottom: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--portal-accent);
  color: #fff;
  border-radius: 12px;
  padding: 2px 6px 2px 10px;
  font-size: 9pt;
}

.chip button {
  border: none;
  background: rgba(0, 0, 0, 0.25);
  color: #fff;
  border-radius: 50%;
  width: 16px;
  height: 16px;
  line-height: 1;
  cursor: pointer;
  font-size: 10px;
}

.picker-search {
  width: 100%;
  border: none;
  border-radius: 4px;
  padding: 7px;
  font-size: 10pt;
  background: #fff;
  outline: none;
}

.picker-results {
  margin-top: 4px;
  max-height: 140px;
  overflow-y: auto;
}

.picker-results:empty {
  display: none;
}

.picker-result {
  padding: 6px 8px;
  font-size: 10pt;
  cursor: pointer;
  border-radius: 4px;
}

.picker-result:hover,
.picker-result.highlight {
  background: #e8e8e8;
}

.picker-result[data-disabled='true'] {
  color: #999;
  cursor: default;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 18px;
}

.btn-cancel {
  border: 1px solid #888;
  background: transparent;
  color: #fff;
  border-radius: 6px;
  padding: 9px 18px;
  font-size: 10pt;
  cursor: pointer;
}

.warn-box {
  background: rgba(138, 75, 0, 0.25);
  border: 1px solid #8a4b00;
  border-radius: 6px;
  padding: 10px 12px;
  color: #ffd9a8;
  font-size: 10pt;
  margin-bottom: 12px;
}

/* ==========================================================================
   Banner de emulação (admin visualizando como outro usuário)
   ========================================================================== */

.emulation-banner {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 8px 16px;
  background: #8a4b00;
  color: #fff;
  font-size: 10pt;
  position: fixed;
  top: 80px;
  left: 0;
  right: 0;
  z-index: 998;
}

.emulation-banner[data-visible='true'] {
  display: flex;
}

.emulation-banner button {
  background: #fff;
  color: #8a4b00;
  border: none;
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 9pt;
  font-weight: 600;
  cursor: pointer;
}

/* O relatório desce para não ficar atrás do banner. */
body[data-emulating='true'] .dashboard-container {
  top: 116px;
}

/* Resultados da busca de emulação: fundo claro no modal escuro, para o texto ficar legível. */
#emulate-results {
  background: #fff;
  border-radius: 6px;
}

#emulate-results .picker-result {
  color: #222;
}

/* ==========================================================================
   Modais
   ========================================================================== */

/*
 * <dialog> aberto com showModal(). O próprio elemento ocupa a tela e desenha o fundo escurecido,
 * por isso os estilos padrão do navegador (borda, margem, tamanho máximo, ::backdrop) são zerados:
 * o clique fora do cartão continua chegando ao .modal, que é o que fecha.
 */
.modal {
  display: none;
  position: fixed;
  z-index: 1100;
  inset: 0;
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  margin: 0;
  padding: 100px 0 0;
  border: 0;
  color: inherit;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(10px);
}

.modal[open] {
  display: block;
}

.modal::backdrop {
  background: transparent;
}

.modal-dialog {
  display: flex;
  justify-content: center;
  margin: 0 20%;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #fff;
}

.modal-header h2 {
  color: #fff;
  font-size: 18pt;
}

.modal-close {
  background: transparent;
  border: none;
  color: #fff;
  font-size: 28px;
  font-weight: bold;
  cursor: pointer;
  line-height: 1;
}

/*
 * O vidro translúcido de .card-login é desenhado para o fundo colorido do login. Nas telas de fundo
 * branco (dashboard, admin) ele vira cinza lavado — aqui o cartão é sólido. Legendas seguem brancas.
 */
.dashboard-page .modal-content,
.admin-page .modal-content {
  background: rgba(35, 38, 41, 0.97);
  backdrop-filter: none;
  width: 100%;
  max-width: 460px;
}

.dashboard-page .modal-dialog,
.admin-page .modal-dialog {
  margin: 0;
}

/* ==========================================================================
   Responsivo — herdado do legado
   ========================================================================== */

@media only screen and (max-width: 1024px) {
  .login-page {
    background-image: var(--portal-background-mobile);
    background-color: #000;
    background-position: 0;
  }

  .login-header {
    display: none;
  }

  .main-login {
    width: 100%;
    flex-direction: column;
    align-items: center;
  }

  .left-login {
    width: 100%;
    height: 35%;
    margin-right: 0;
  }

  .left-login .brand-logo {
    display: flex;
    width: 100%;
    height: 22%;
    margin-top: 50px;
  }

  .left-login p,
  .brand-rule {
    display: none;
  }

  .left-login h1 {
    margin-top: 20px;
    width: 100%;
    padding: 0 75px;
    font-size: 24px;
    line-height: 30px;
    text-align: center;
  }

  .right-login {
    width: 100%;
    height: 65%;
  }

  .card-login {
    width: 350px;
  }

  .card-login h2 {
    font-size: 15pt;
  }

  .textfield input {
    padding: 12px;
    font-size: 10pt;
  }

  .modal-dialog {
    margin: 0;
  }
}
