/* Régua de prazos, filtros e tabela de documentos. */

/* Régua de prazos: a composição da carteira de documentos. */
.overview {
  display: grid;
  gap: 16px;
  margin-bottom: 36px;
  padding: 22px 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
.overview-total {
  display: flex;
  align-items: baseline;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}
.overview-number {
  color: var(--ink);
  font-size: 34px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
  line-height: 1;
}
.deadline-bar {
  display: flex;
  gap: 3px;
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-2);
}
.deadline-bar span {
  min-width: 0;
  transition: flex-grow 400ms ease;
}
.deadline-bar span:first-child {
  border-radius: 999px 0 0 999px;
}
.deadline-bar span:last-child {
  border-radius: 0 999px 999px 0;
}
.bar-overdue {
  background: var(--overdue);
}
.bar-soon {
  background: var(--soon);
}
.bar-ok {
  background: var(--ok);
}
.bar-none {
  background: var(--line-strong);
}
.overview-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 28px;
}
.overview-legend > div {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}
.overview-legend > div::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.legend-overdue::before {
  background: var(--overdue);
}
.legend-soon::before {
  background: var(--soon);
}
.legend-ok::before {
  background: var(--ok);
}
.legend-none::before {
  background: var(--line-strong);
}

/* Aviso pessoal: prazos pelos quais a pessoa conectada responde. */
.due-notice[hidden] {
  display: none;
}
.due-notice {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: -12px 0 28px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--soon-soft);
  color: var(--ink);
}
.due-notice.is-overdue {
  background: var(--overdue-soft);
}
.due-notice p {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
}
.due-notice .button {
  flex-shrink: 0;
}
.overview-legend dt {
  color: var(--muted);
}
.overview-legend dd {
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

/* Lista */
.list-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}
.list-heading-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.list-heading h2 {
  font-size: 18px;
}
.result-count {
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}
.search-wrap {
  position: relative;
  flex: 1;
  min-width: 160px;
}
.search-icon {
  position: absolute;
  top: 50%;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--faint);
  transform: translateY(-50%);
  pointer-events: none;
}
.search-input,
.category-select {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-small);
  background: var(--surface);
  font-size: 14px;
}
.search-input {
  width: 100%;
  padding: 0 12px 0 36px;
  text-overflow: ellipsis;
}
.search-input::placeholder {
  color: var(--faint);
}
/* Os filtros não crescem com o nome mais longo da lista (uma unidade de
   nome comprido espremia a busca e a tabela). */
.category-select {
  min-width: 170px;
  max-width: 240px;
  padding: 0 10px;
  text-overflow: ellipsis;
}
.list-frame {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
}
th {
  height: 42px;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
}
td {
  padding: 14px 16px;
  vertical-align: middle;
}
tbody tr + tr td {
  border-top: 1px solid var(--line);
}
tbody tr:hover {
  background: var(--surface-2);
}
.doc-name {
  display: block;
  max-width: 340px;
  /* Nomes sem espaços (como os de arquivo) quebram em qualquer ponto, para
     não alargar o cartão nem a página no celular. */
  overflow-wrap: anywhere;
  font-weight: 600;
}
/* O nome do documento não se espreme demais, mas cabe em telas médias. */
tbody td:first-child {
  min-width: 200px;
}
/* O nome do documento é um botão que abre o visualizador. */
.doc-open {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-weight: 600;
  text-align: left;
}
.doc-open:hover {
  color: var(--brand);
  text-decoration: underline;
  text-underline-offset: 3px;
}
.doc-category,
.date-days {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
}
.doc-number {
  display: inline-block;
  margin-right: 8px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
/* Resumo dos arquivos: nome do principal e quantidade de anexos. */
.doc-files {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 8px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}
/* Cada documento principal numa linha, numa lista com rolagem própria a
   partir de umas 5 linhas; a contagem de anexos vem depois. */
.doc-file-list {
  display: flex;
  flex-basis: 100%;
  flex-direction: column;
  max-height: calc(5 * 1.6em);
  overflow-y: auto;
  overscroll-behavior: contain;
  line-height: 1.6;
}
/* Nome de arquivo que abre o visualizador já nele. */
.doc-file-open {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  text-align: left;
  overflow-wrap: anywhere;
}
.doc-file-open:hover {
  color: var(--brand);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.doc-file-open:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}
.doc-file-tag {
  flex: none;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  text-decoration: none;
}
.doc-file-list:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
}
.doc-files-count {
  padding: 0 7px;
  /* Pode quebrar em duas linhas no celular: canto suave, não pílula. */
  border-radius: var(--radius-small);
  background: var(--brand-soft);
  color: var(--brand);
  font-weight: 600;
}
/* Pasta do documento, ao lado da categoria. */
.doc-folder {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  margin-left: 10px;
}
.doc-folder::before {
  content: "";
  width: 12px;
  height: 11px;
  background: currentColor;
  opacity: 0.7;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 14'%3E%3Cpath d='M1.5 2.5A1.5 1.5 0 0 1 3 1h3.3l1.6 1.8H13a1.5 1.5 0 0 1 1.5 1.5v7.2A1.5 1.5 0 0 1 13 13H3a1.5 1.5 0 0 1-1.5-1.5z'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 14'%3E%3Cpath d='M1.5 2.5A1.5 1.5 0 0 1 3 1h3.3l1.6 1.8H13a1.5 1.5 0 0 1 1.5 1.5v7.2A1.5 1.5 0 0 1 13 13H3a1.5 1.5 0 0 1-1.5-1.5z'/%3E%3C/svg%3E") center / contain no-repeat;
}
.no-units th:nth-child(2),
.no-units td:nth-child(2) {
  display: none;
}
/* A unidade quebra a linha e o responsável (muitas vezes um e-mail, sem
   espaços) termina em reticências: sobra espaço para o documento. */
.unit-cell,
.owner-cell {
  min-width: 96px;
  color: var(--muted);
}
.owner-cell {
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.actions-cell {
  padding-left: 4px;
  padding-right: 8px;
}
.date-cell {
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.status {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 550;
  white-space: nowrap;
}
.status::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.status-ok {
  background: var(--ok-soft);
  color: var(--ok);
}
.status-soon {
  background: var(--soon-soft);
  color: var(--soon);
}
.status-overdue {
  background: var(--overdue-soft);
  color: var(--overdue);
}
.status-none {
  background: var(--surface-2);
  color: var(--muted);
}
.date-none {
  color: var(--faint);
}
.row-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
}
/* Menu "⋯" com Histórico, Editar e Excluir. */
.row-menu {
  position: relative;
}
.row-menu-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  font-size: 18px;
  line-height: 1;
  list-style: none;
}
.row-menu-toggle::-webkit-details-marker {
  display: none;
}
.row-menu[open] .row-menu-toggle {
  background: var(--brand-soft);
}
.row-menu-list {
  position: fixed;
  z-index: 50;
  display: grid;
  min-width: 150px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--radius-small);
  background: var(--surface);
  box-shadow: var(--shadow-dialog);
}
/* Invisível até ser posicionado junto ao botão (evita piscar fora do lugar). */
.row-menu-list:not([data-placed]) {
  visibility: hidden;
}
.row-menu-item {
  padding: 8px 12px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 13px;
  text-align: left;
}
.row-menu-item:hover,
.row-menu-item:focus-visible {
  background: var(--surface-2);
}
.row-menu-item.delete {
  color: var(--overdue);
}
.row-action {
  min-height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: var(--radius-small);
  background: transparent;
  color: var(--brand);
  cursor: pointer;
  font-size: 13px;
  font-weight: 550;
}
.row-action:hover {
  background: var(--brand-soft);
}
.row-action.delete {
  color: var(--muted);
}
.row-action.delete:hover {
  background: var(--overdue-soft);
  color: var(--overdue);
}
.row-action:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}
.empty-state {
  padding: 56px 24px;
  text-align: center;
}
.empty-symbol {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  margin: 0 auto 16px;
  border-radius: 50%;
  background: var(--brand-soft);
  color: var(--brand);
  font-size: 22px;
}
.empty-state h3 {
  margin-bottom: 6px;
  font-size: 16px;
}
.empty-state p {
  max-width: 42ch;
  margin: 0 auto 20px;
  color: var(--muted);
}

@media (max-width: 1279px) {
  .overview {
    padding: 18px;
  }
  .toolbar {
    flex-wrap: wrap;
  }
  .search-wrap {
    flex-basis: 100%;
  }
  .category-select {
    flex: 1;
    min-width: 0;
    max-width: none;
  }
  .list-frame {
    overflow: visible;
    border: 0;
    background: transparent;
  }
  table,
  tbody {
    display: block;
  }
  thead {
    display: none;
  }
  tbody {
    display: grid;
    gap: 10px;
  }
  tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px 12px;
    padding: 14px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
  }
  tbody tr:hover {
    background: var(--surface);
  }
  tbody tr + tr td {
    border-top: 0;
  }
  td {
    padding: 0;
  }
  /* Documento | Unidade | Responsável | Vencimento | Situação | Ações */
  td:nth-child(1) {
    grid-column: 1 / -1;
  }
  td:nth-child(2),
  td:nth-child(3) {
    grid-column: 1 / -1;
    font-size: 13px;
  }
  td:nth-child(4) {
    grid-column: 1;
  }
  td:nth-child(5) {
    grid-column: 2;
    grid-row: 4;
    align-self: start;
  }
  td:nth-child(6) {
    grid-column: 1 / -1;
    padding-top: 6px;
    border-top: 1px solid var(--line);
  }
  .unit-cell:empty {
    display: none;
  }
  .unit-cell::before {
    content: "Unidade: ";
  }
  /* No cartão há largura de sobra: o responsável aparece inteiro. */
  .owner-cell {
    max-width: none;
    white-space: normal;
    overflow-wrap: anywhere;
  }
  .owner-cell::before {
    content: "Responsável: ";
  }
  .doc-name {
    max-width: none;
  }
  .row-actions {
    justify-content: flex-start;
  }
  .empty-state {
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
  }
}

@media (prefers-reduced-motion: reduce) {
  .deadline-bar span {
    transition: none;
  }
}

/* Celular: resumo em grade, busca e filtros em coluna, e cada documento
   num cartão com a situação no canto e as ações na mesma linha da data. */
@media (max-width: 720px) {
  .overview {
    gap: 12px;
    margin-bottom: 20px;
    padding: 14px;
  }
  .overview-number {
    font-size: 28px;
  }
  .overview-legend {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 12px;
  }
  .due-notice {
    flex-direction: column;
    align-items: stretch;
    margin: 0 0 16px;
  }
  .due-notice .button {
    min-height: 44px;
  }
  .list-heading {
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
  }
  .list-heading-actions {
    flex-wrap: wrap;
    width: 100%;
    gap: 8px;
  }
  .list-heading-actions .button {
    flex: 1 1 auto;
    min-height: 40px;
    white-space: normal;
    text-align: center;
  }
  .list-heading-actions .result-count {
    flex: 1 1 100%;
    margin-left: 0;
  }
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .search-wrap,
  .category-select {
    width: 100%;
    max-width: none;
  }
  .search-input,
  .category-select {
    min-height: 44px;
    font-size: 16px;
  }
  tbody tr {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "doc status"
      "unit unit"
      "owner owner"
      "when when"
      "actions actions";
    gap: 6px 10px;
    padding: 12px 14px;
  }
  td:nth-child(1) {
    grid-area: doc;
  }
  td:nth-child(2),
  td:nth-child(3) {
    grid-column: auto;
  }
  td:nth-child(2) {
    grid-area: unit;
  }
  td:nth-child(3) {
    grid-area: owner;
  }
  td:nth-child(4) {
    grid-area: when;
  }
  td:nth-child(5) {
    grid-area: status;
    grid-row: auto;
    align-self: start;
    justify-self: end;
  }
  td:nth-child(6) {
    grid-area: actions;
    padding-top: 8px;
    border-top: 1px solid var(--line);
  }
  .date-cell {
    white-space: normal;
  }
  .row-actions {
    flex-wrap: wrap;
    justify-content: flex-start;
    gap: 4px;
  }
  .row-action {
    min-height: 40px;
  }
  .empty-state {
    padding: 36px 16px;
  }
}
