/* Diálogos modais, listas de gestão e avisos do sistema. */

/* Diálogos */
dialog {
  /* Devolve a centralização nativa, que o reset de margem removeria. */
  margin: auto;
  width: min(640px, calc(100% - 32px));
  max-height: min(92vh, 900px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-dialog);
  opacity: 0;
  transform: translateY(8px) scale(0.98);
  transition-property: opacity, transform, display, overlay;
  transition-duration: 180ms;
  transition-timing-function: ease-out;
  transition-behavior: allow-discrete;
}
dialog[open] {
  opacity: 1;
  transform: none;
  @starting-style {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
}
dialog::backdrop {
  background-color: transparent;
  transition:
    display 180ms allow-discrete,
    overlay 180ms allow-discrete,
    background-color 180ms ease-out;
}
dialog[open]::backdrop {
  background-color: var(--backdrop);
  @starting-style {
    background-color: transparent;
  }
}
/* Os formulários maiores (documento e empresa) usam mais largura. */
#document-dialog,
#company-dialog {
  width: min(820px, calc(100% - 32px));
}
.dialog-head {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 28px 34px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.dialog-head h2 {
  font-size: 20px;
}
/* Títulos longos sem espaços (nomes de arquivo) quebram em vez de alargar a
   janela além da tela. */
.dialog-head h2,
.dialog-head p {
  overflow-wrap: anywhere;
}
.dialog-head p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}
.close-button {
  display: grid;
  flex-shrink: 0;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-small);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}
.close-button:hover {
  background: var(--surface-2);
  color: var(--ink);
}

.section-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
  padding: 24px 34px 8px;
}
.section-head h3 {
  font-size: 16px;
}
.section-head p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}
/* Tipo da unidade ao lado do nome: a sede se destaca das filiais. */
.unit-name {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.unit-tag {
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
.unit-tag-headquarters {
  background: var(--brand-soft);
  color: var(--brand);
}
.unit-tag-inactive {
  background: var(--soon-soft);
  color: var(--soon);
}
#units-summary {
  color: var(--muted);
  font-size: 13px;
}
.management-list {
  display: grid;
  max-height: 340px;
  overflow: auto;
  padding: 0 34px 22px;
}
.management-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-top: 1px solid var(--line);
}
.management-row strong {
  display: block;
  font-weight: 600;
  overflow-wrap: anywhere;
}
.management-row small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}
.management-row select {
  max-width: 170px;
  min-height: 34px;
  padding: 4px 8px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-small);
  background: var(--surface);
  font-size: 13px;
}
.management-row .row-actions {
  flex-shrink: 0;
}
/* Usuário inativo: nome apagado e a situação em destaque. */
.management-row.is-inactive strong {
  color: var(--muted);
}
.management-row small.member-inactive {
  color: var(--overdue);
  font-weight: 600;
}
.presence-list {
  display: grid;
  margin: 0;
  padding: 0 34px;
  list-style: none;
}
.presence-person {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}
.presence-person strong {
  font-weight: 600;
}
.presence-person strong::before {
  content: "";
  display: inline-block;
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--ok);
  vertical-align: 0.05em;
}
.presence-person span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
  text-align: right;
}
.management-row small.member-present {
  color: var(--ok);
  font-weight: 600;
}
/* Na lista de pessoas, o nome fica em cima e as ações embaixo, para o perfil
   e os botões não cortarem o e-mail. */
#members-dialog .management-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: start;
  gap: 8px;
}
#members-dialog .management-row .row-actions {
  flex-wrap: wrap;
  justify-content: flex-start;
}

/* Avisos do sistema: janela própria, acima de qualquer outro diálogo. */
.notice-dialog {
  width: min(440px, calc(100% - 32px));
}
.notice-body {
  display: flex;
  gap: 14px;
  padding: 22px 22px 6px;
}
.notice-mark {
  flex: 0 0 auto;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  display: grid;
  place-items: center;
  font-size: 17px;
  font-weight: 700;
}
.notice-mark::before {
  content: "i";
}
.notice-dialog[data-tone="success"] .notice-mark {
  background: var(--ok-soft);
  color: var(--ok);
}
.notice-dialog[data-tone="success"] .notice-mark::before {
  content: "✓";
}
.notice-dialog[data-tone="error"] .notice-mark,
.notice-dialog[data-tone="danger"] .notice-mark {
  background: var(--overdue-soft);
  color: var(--overdue);
}
.notice-dialog[data-tone="error"] .notice-mark::before,
.notice-dialog[data-tone="danger"] .notice-mark::before {
  content: "!";
}
.notice-dialog[data-tone="question"] .notice-mark::before {
  content: "?";
}
.notice-text {
  display: grid;
  gap: 6px;
  min-width: 0;
  padding-top: 5px;
}
.notice-text h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}
.notice-text p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  white-space: pre-line;
}
.notice-field input {
  width: 100%;
  margin-top: 6px;
}
.notice-actions {
  display: flex;
  flex-direction: row-reverse;
  gap: 8px;
  padding: 16px 22px 20px;
}
.button-danger {
  border-color: var(--overdue);
  background: var(--overdue);
  color: var(--surface);
}
.button-danger:hover {
  border-color: var(--overdue);
  background: var(--overdue);
  filter: brightness(0.92);
}

@media (max-width: 720px) {
  .dialog-head,
  .section-head {
    padding-inline: 18px;
  }
  .close-button {
    width: 44px;
    height: 44px;
  }
  .form-footer {
    padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  }
  .management-list,
  .presence-list {
    padding-inline: 18px;
  }
  .management-row {
    flex-wrap: wrap;
  }
}

@media (prefers-reduced-motion: reduce) {
  dialog {
    transform: none;
    transition-duration: 80ms;
  }
  dialog[open] {
    @starting-style {
      transform: none;
    }
  }
}

/* Backups: ação principal, andamento e lista. */
.backups-toolbar {
  display: grid;
  gap: 10px;
  padding: 20px 34px 8px;
}
.backups-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.backups-status {
  padding: 10px 12px;
  border-radius: var(--radius-small);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
}
.backups-status.ok {
  background: var(--ok-soft);
  color: var(--ok);
  font-weight: 550;
}
.backups-status.error {
  background: var(--overdue-soft);
  color: var(--overdue);
  font-weight: 550;
}
.backup-progress {
  display: grid;
  gap: 6px;
}
.backup-timeline {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 2px 0 8px;
}
.backup-timeline li {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-width: 0;
  text-align: center;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
}
.backup-timeline li:not(:last-child)::after {
  content: "";
  position: absolute;
  z-index: 0;
  top: 6px;
  left: calc(50% + 8px);
  width: calc(100% - 16px);
  height: 2px;
  background: var(--line);
}
.backup-timeline-track {
  position: absolute;
  z-index: 0;
  top: 6px;
  left: calc(50% + 8px);
  width: calc(100% - 16px);
  height: 2px;
  background: var(--line);
}
.backup-timeline li.is-done:not(:last-child)::after {
  background: var(--brand);
}
.backup-timeline li[data-phase="anexos"]::after {
  content: none;
}
.backup-timeline-track > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--brand);
}
.backup-timeline-dot {
  position: relative;
  z-index: 1;
  width: 14px;
  height: 14px;
  box-sizing: border-box;
  border: 2px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
}
.backup-timeline li.is-done .backup-timeline-dot,
.backup-timeline li.is-current .backup-timeline-dot {
  border-color: var(--brand);
  background: var(--brand);
}
.backup-timeline li.is-current .backup-timeline-dot {
  box-shadow: 0 0 0 4px var(--brand-soft);
}
.backup-timeline li.is-done,
.backup-timeline li.is-current {
  color: var(--ink);
}
.backup-timeline li.is-current {
  font-weight: 600;
}
.backup-progress-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--ink);
  font-size: 13px;
}
.backup-progress-meta strong {
  font-variant-numeric: tabular-nums;
}
.backup-progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}
.backup-progress-track > span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--brand);
}
.backup-progress p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}
.backup-progress-inline {
  margin-top: 8px;
}
.backups-list {
  max-height: 420px;
}
.backup-row small + small {
  margin-top: 2px;
}
.backup-error {
  color: var(--overdue) !important;
}
.backup-warning {
  color: var(--soon) !important;
}
@media (max-width: 720px) {
  .backups-toolbar {
    padding-inline: 18px;
  }
  .backup-timeline {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding-bottom: 2px;
  }
  .backup-timeline li {
    flex-direction: row;
    justify-content: flex-start;
    text-align: left;
  }
  .backup-timeline li:not(:last-child)::after,
  .backup-timeline-track {
    display: none;
  }
}

/* Visualizador: dados e arquivos à esquerda, o arquivo aberto à direita. */
dialog.viewer-dialog {
  width: min(1280px, calc(100% - 32px));
  height: min(90vh, 900px);
  max-height: none;
  overflow: hidden;
}
dialog.viewer-dialog[open] {
  display: flex;
  flex-direction: column;
}
/* Atalho para a lista de arquivos: só no celular (veja abaixo). */
.viewer-files-jump {
  display: none;
}
.viewer-body {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  flex: 1;
  min-height: 0;
}
.viewer-sidebar {
  display: grid;
  align-content: start;
  gap: 20px;
  padding: 18px 20px 24px;
  overflow: auto;
  border-right: 1px solid var(--line);
}
.viewer-details {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 8px 12px;
  font-size: 13px;
}
.viewer-details dt {
  color: var(--muted);
}
.viewer-details dd {
  margin: 0;
  overflow-wrap: anywhere;
}
.viewer-group h3 {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.viewer-files {
  display: grid;
  gap: 2px;
  margin: 0;
  padding: 0;
  list-style: none;
}
.viewer-file {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-small);
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  text-align: left;
}
.viewer-file:hover {
  background: var(--surface-2);
}
.viewer-file[aria-current="true"] {
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}
.viewer-file.is-static {
  cursor: default;
}
.viewer-file-name {
  min-width: 0;
  overflow-wrap: anywhere;
}
.viewer-file-size,
.viewer-none {
  flex: none;
  color: var(--muted);
  font-size: 12px;
  font-weight: 400;
}
.viewer-none {
  padding: 4px 10px;
}
.viewer-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 56px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--line);
}
.viewer-toolbar strong {
  display: block;
  overflow-wrap: anywhere;
  font-size: 14px;
}
.viewer-toolbar small {
  color: var(--muted);
  font-size: 12px;
}
.viewer-toolbar-actions {
  display: flex;
  flex: none;
  gap: 8px;
}
.viewer-stage {
  position: relative;
  display: grid;
  flex: 1;
  min-height: 0;
  place-items: center;
  overflow: auto;
  background: var(--surface-2);
}
.viewer-frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: var(--surface);
}
.viewer-image {
  max-width: calc(100% - 32px);
  max-height: calc(100% - 32px);
  object-fit: contain;
  box-shadow: var(--shadow-dialog);
}
.viewer-text {
  align-self: stretch;
  justify-self: stretch;
  margin: 0;
  padding: 20px 24px;
  overflow: auto;
  background: var(--surface);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
/* PDF desenhado pela página (celular e tablet): barra de zoom e páginas
   numa rolagem própria, que ocupa a área do arquivo. */
.viewer-pdf {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.viewer-pdf-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.viewer-pdf-count {
  color: var(--muted);
  font-size: 13px;
}
.viewer-pdf-zoom-group {
  display: flex;
  gap: 6px;
}
.viewer-pdf-zoom-group .button {
  min-width: 44px;
  min-height: 40px;
  padding: 0 10px;
  font-variant-numeric: tabular-nums;
}
.viewer-pdf-zoom-group .viewer-pdf-zoom {
  min-width: 76px;
}
.viewer-pdf-pages {
  display: grid;
  flex: 1;
  align-content: start;
  justify-content: safe center;
  gap: 12px;
  min-height: 0;
  padding: 12px;
  overflow: auto;
}
.viewer-pdf-page {
  display: grid;
  place-items: center;
  background: #ffffff;
  box-shadow: 0 1px 4px rgb(16 22 38 / 18%);
}
.viewer-pdf-page canvas {
  display: block;
  width: 100%;
  height: 100%;
}
.viewer-pdf-error {
  margin: 0;
  padding: 16px;
  color: #5d6677;
  font-size: 13px;
  text-align: center;
}
/* Tabelas dos arquivos abertos: desfaz as regras da lista de documentos
   (que no celular vira cartões) e volta ao desenho de tabela comum. */
#viewer-stage table {
  display: table;
  width: auto;
}
#viewer-stage thead {
  display: table-header-group;
}
#viewer-stage tbody {
  display: table-row-group;
}
#viewer-stage tr {
  display: table-row;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
}
#viewer-stage :is(td, th) {
  display: table-cell;
  height: auto;
  min-width: 0;
  padding: 4px 8px;
  border-top: 0;
  font-size: inherit;
  white-space: normal;
}
/* Documentos (DOCX, ODT, DOC): o texto numa folha branca, com rolagem
   própria; o aviso de visualização simplificada fica em cima. */
.viewer-doc {
  position: absolute;
  inset: 0;
  padding: 0 12px 16px;
  overflow: auto;
}
.viewer-doc-note {
  margin: 0;
  padding: 10px 4px;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}
.viewer-doc-page {
  max-width: 820px;
  margin: 0 auto;
  padding: 40px 48px;
  background: #ffffff;
  box-shadow: 0 1px 4px rgb(16 22 38 / 18%);
  color: #1d2433;
  font-size: 15px;
  line-height: 1.55;
  overflow-wrap: anywhere;
}
.viewer-doc-page :is(h1, h2, h3, h4, h5, h6) {
  margin: 1.2em 0 0.5em;
  line-height: 1.3;
}
.viewer-doc-page h1 {
  font-size: 1.6em;
}
.viewer-doc-page h2 {
  font-size: 1.35em;
}
.viewer-doc-page :is(h3, h4, h5, h6) {
  font-size: 1.1em;
}
.viewer-doc-page p {
  min-height: 1em;
  margin: 0 0 0.6em;
}
.viewer-doc-page :is(ul, ol) {
  margin: 0 0 0.6em;
  padding-left: 1.6em;
}
#viewer-stage .viewer-doc-page table {
  width: 100%;
  margin: 0 0 1em;
  border-collapse: collapse;
}
#viewer-stage .viewer-doc-page :is(td, th) {
  padding: 4px 8px;
  border: 1px solid #c9ced8;
  vertical-align: top;
}
#viewer-stage .viewer-doc-page :is(td, th) p:last-child {
  margin-bottom: 0;
}
.viewer-doc-page img {
  max-width: 100%;
  height: auto;
}
.viewer-doc-page a[href] {
  color: var(--brand);
}
.viewer-doc-plain p,
#viewer-stage .viewer-doc-plain td {
  white-space: pre-wrap;
  tab-size: 4;
}
/* Planilhas: abas em cima e a tabela com letras e números fixos. */
.viewer-sheet {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
}
.viewer-sheet-tabs {
  display: flex;
  flex: none;
  gap: 4px;
  padding: 8px 12px 0;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}
.viewer-sheet-tab {
  flex: none;
  min-height: 36px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-bottom: 0;
  border-radius: var(--radius-small) var(--radius-small) 0 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  white-space: nowrap;
}
.viewer-sheet-tab[aria-selected="true"] {
  border-color: var(--line);
  background: #ffffff;
  color: var(--ink);
  font-weight: 600;
}
.viewer-sheet-area {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: #ffffff;
}
#viewer-stage .viewer-sheet-table {
  border-collapse: separate;
  border-spacing: 0;
  color: #1d2433;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
#viewer-stage .viewer-sheet-table :is(td, th) {
  max-width: 320px;
  padding: 4px 8px;
  border-right: 1px solid #e1e4ea;
  border-bottom: 1px solid #e1e4ea;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  vertical-align: top;
}
#viewer-stage .viewer-sheet-table td.is-number {
  text-align: right;
}
#viewer-stage .viewer-sheet-table th {
  position: sticky;
  background: #f3f4f7;
  color: #5d6677;
  font-weight: 500;
  text-align: center;
}
#viewer-stage .viewer-sheet-table thead th {
  top: 0;
  z-index: 1;
}
#viewer-stage .viewer-sheet-table tbody th {
  left: 0;
}
#viewer-stage .viewer-sheet-table .viewer-sheet-corner {
  left: 0;
  z-index: 2;
}
.viewer-sheet .viewer-doc-note {
  padding-inline: 12px;
  text-align: left;
}
@media (max-width: 720px) {
  .viewer-doc {
    padding-inline: 8px;
  }
  .viewer-doc-page {
    padding: 20px 18px;
    font-size: 14px;
  }
}
.viewer-empty {
  display: grid;
  justify-items: center;
  gap: 8px;
  max-width: 360px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}
.viewer-empty strong {
  color: var(--ink);
}
.viewer-empty .button {
  margin-top: 8px;
}
/* No celular (em pé ou deitado), o visualizador ocupa a tela inteira e o
   arquivo vem primeiro, com toda a altura; os dados e a lista de arquivos
   ficam numa segunda tela, logo abaixo. A rolagem encaixa numa das duas,
   para as barras do arquivo nunca ficarem cortadas pela metade. */
@media (max-width: 720px), (max-height: 520px) {
  dialog.viewer-dialog {
    width: 100%;
    max-width: none;
    height: 100dvh;
    border: 0;
    border-radius: 0;
  }
  /* Título, arquivo e dados alinhados pela mesma margem. */
  .viewer-dialog .dialog-head,
  .viewer-toolbar {
    padding-inline: 18px;
  }
  .viewer-body {
    grid-template-columns: 1fr;
    grid-template-rows: 100% minmax(100%, auto);
    overflow: auto;
    scroll-snap-type: y mandatory;
  }
  .viewer-main {
    order: -1;
    border-bottom: 1px solid var(--line);
    scroll-snap-align: start;
  }
  .viewer-sidebar {
    scroll-snap-align: start;
    padding-inline: 18px;
    overflow: visible;
    border-right: 0;
  }
  .viewer-toolbar {
    flex-wrap: wrap;
    padding-inline: 18px;
  }
  .viewer-files-jump {
    display: inline-flex;
  }
}

/* Celular deitado: pouca altura, então cabeçalho e barras ficam compactos
   para sobrar espaço para o arquivo. */
@media (max-height: 520px) {
  .viewer-dialog .dialog-head {
    padding-block: 8px;
  }
  .viewer-dialog .dialog-head h2 {
    font-size: 17px;
  }
  #viewer-subtitle,
  .viewer-toolbar small {
    display: none;
  }
  .viewer-toolbar {
    flex-wrap: nowrap;
    min-height: 0;
    padding-block: 6px;
  }
  .viewer-toolbar .button,
  .viewer-pdf-zoom-group .button {
    min-height: 32px;
  }
  .viewer-pdf-bar {
    padding-block: 4px;
  }
}

/* Subpastas no cadastro de pastas: recuo por nível. */
.management-row.is-subfolder {
  padding-left: calc(var(--depth, 0) * 22px);
}
.management-row.is-subfolder strong::before {
  content: "↳ ";
  color: var(--faint);
}
