/* ============================================================
   Table View — High-Density Professional Layout
   Broto Design Principles: Soft Minimalist, Alta Densidade
   Referência: Linear, Notion, Jira
   ============================================================ */

/* ── Container ─────────────────────────────────────────────── */
#sectionsGrid,
.table-view-container {
  display: block;
  border-radius: var(--radius-md);
  background: var(--sidebar-bg);
  width: 100%;
}

.table-container {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-md);
  contain: content;
}

/* ── Tabela Base ────────────────────────────────────────────── */
.items-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--font-size-sm); /* 13px — única fonte de verdade para td */
  font-family: var(--font-family);
  table-layout: fixed;
  margin-top: var(--space-5); /* 20px — reduzido de 30px */
}

.items-table b {
  font-weight: 500;
}

/* ── Cabeçalho ──────────────────────────────────────────────── */
.items-table thead {
  background: var(--background);
  z-index: 90;
}

.items-table th {
  padding: 8px 12px;          /* Alta densidade: reduzido de 12px 16px */
  text-align: left;
  font-size: 10px;             /* Cabeçalho menor que o corpo — hierarquia intencional */
  font-weight: 600;
  color: var(--muted-foreground);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
  position: sticky;
  top: 0;
  background: var(--background);
  z-index: 90;
  transition: background-color 0.15s ease;
}

/* Separador vertical entre colunas — pseudo-elemento limpo */
.items-table th:not(:last-child) {
  position: relative;
}

.items-table th:not(:last-child)::after {
  content: '';
  position: absolute;
  right: 0;
  top: 20%;
  height: 60%;
  width: 1px;
  background: var(--border);
  opacity: 0.7;
  pointer-events: none;
}

/* ── Cabeçalho — Interações ─────────────────────────────────── */
.items-table th.sortable {
  cursor: pointer;
  position: relative;
  transition: background-color 0.15s ease;
}

.items-table th.sortable:hover {
  background: var(--accent);
}

.items-table th .th-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
}

.items-table th .th-icons {
  display: flex;
  align-items: center;
  gap: 4px;
  opacity: 0;
  transform: translateX(3px);
  transition: opacity 0.15s ease, transform 0.15s ease;
  pointer-events: none;
  flex-shrink: 0;
}

.items-table th:hover .th-icons,
.items-table th.active .th-icons,
.items-table th:has(.filter-icon.active) .th-icons {
  opacity: 1;
  transform: translateX(0);
  pointer-events: auto;
}

/* Ícone de sort */
.items-table th .sort-icon {
  display: inline-block;
  font-size: 10px;
  color: var(--muted-foreground);
  opacity: 0.5;
  line-height: 1;
}

.items-table th.active .sort-icon {
  opacity: 1;
  color: var(--foreground);
}

/* Ícone de filtro */
.items-table th .filter-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--muted-foreground);
  opacity: 0.5;
  cursor: pointer;
  transition: opacity 0.15s, color 0.15s;
  user-select: none;
  line-height: 1;
}

.items-table th .filter-icon svg {
  display: block;
  width: 11px;
  height: 11px;
}

.items-table th .filter-icon:hover,
.items-table th .filter-icon.active {
  opacity: 1;
  color: var(--primary);
}

/* ── Linhas do Corpo ────────────────────────────────────────── */
.items-table tbody tr {
  /* border-bottom: 1px solid var(--border); */
  transition: background-color 0.1s ease;
  content-visibility: auto;
  contain-intrinsic-size: auto 36px; /* Alta densidade */
}

.items-table tbody tr:hover {
  background: var(--accent);
}

.items-table tbody tr.table-row-clickable {
  cursor: pointer;
}

/* ── Células ────────────────────────────────────────────────── */
.items-table td {
  padding: 7px 12px;           /* Alta densidade: 7px vertical, 12px horizontal */
  color: var(--foreground);
  vertical-align: middle;
  font-size: var(--font-size-sm); /* 13px — uniforme em todas as células */
  font-weight: 400;
  line-height: 1.4;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Estado vazio */
.items-table td.table-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--muted-foreground);
  font-style: italic;
  font-size: var(--font-size-sm);
  background: var(--background);
  white-space: normal;
}

.table-empty-row {
  background: var(--background) !important;
}

.table-empty-row:hover {
  background: var(--background) !important;
}

/* ── Célula: Label (título da tarefa) ───────────────────────── */
.cell-label {
  max-width: 350px;
  min-width: 200px;
  width: 350px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-label-text {
  font-size: var(--font-size-sm); /* 13px — mesmo do td, sem destaque excessivo */
  font-weight: 500;               /* Médio: distingue do metadata, não grita */
  color: var(--foreground);
  letter-spacing: 0;
}

/* ── Célula: ID ─────────────────────────────────────────────── */
.cell-id {
  width: 90px;
  max-width: 90px;
  min-width: 60px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.label-id-badge {
  font-size: 11px;               /* Levemente menor — é metadado, não conteúdo */
  font-weight: 500;
  color: var(--muted-foreground);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  letter-spacing: 0.03em;
  background: transparent;
  padding: 0;
  border: none;
}

/* ── Célula: Seção ──────────────────────────────────────────── */
.cell-section {
  width: 140px;
  min-width: 80px;
}

.chip-section {
  font-size: 11px;
  font-weight: 400;
  color: var(--muted-foreground);
  background: transparent;
  padding: 0;
  border: none;
  opacity: 0.85;
  letter-spacing: 0;
}

/* ── Célula: Status e Categorias ─────────────────────────────── */
.items-table td.cell-status,
.items-table td.cell-categories {
  padding: 5px 12px;
  vertical-align: middle;
  min-width: 110px;
}

.cell-meta-wrapper {
  display: flex;
  width: 100%;
  height: 100%;
  align-items: center;
  justify-content: flex-start;
  gap: 2px;
  flex-wrap: nowrap;
  overflow: hidden;
}

/* Pills/badges dentro da tabela — tamanho unificado */
.cell-meta-wrapper > * {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
  border: none !important;
  border-radius: var(--radius-sm);
  margin: 0 !important;
  box-sizing: border-box;
  padding: 2px 8px;            /* Compacto: 2px vertical */
  font-size: 11px;             /* Badges: levemente menor que o texto da linha */
  font-weight: 500;
  text-align: center;
  white-space: nowrap;
  min-width: 0;
  max-width: 100%;
  flex-shrink: 1;
}

/* ── Célula: Projeto ────────────────────────────────────────── */
.cell-project {
  width: 140px;
  min-width: 100px;
  overflow: hidden;
}

.chip {
  display: inline-block;
  padding: 2px 7px;
  background: var(--muted);
  color: var(--muted-foreground);
  border-radius: var(--radius-md);
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  border: 1px solid var(--border);
}

.chip-project {
  background: var(--soft-bg);
  color: var(--primary);
  border: 1px solid var(--border);
  font-weight: 500;
}

/* ── Célula: Assignee ───────────────────────────────────────── */
.cell-assignee,
.cell-approver {
  width: 110px;
  min-width: 80px;
}

/* ── Célula: Data ───────────────────────────────────────────── */
.cell-date {
  width: 110px;
  min-width: 80px;
  font-size: 11px;             /* Data: metadado — ligeiramente menor */
  font-weight: 400;
  color: var(--muted-foreground);
}

/* ── Célula: Comentários ────────────────────────────────────── */
.cell-comments {
  width: 72px;
  text-align: center;
}

.comment-count-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: var(--muted);
  padding: 2px 6px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 500;
  color: var(--muted-foreground);
  transition: background 0.15s, color 0.15s;
  border: 1px solid var(--border);
}

.comment-count-badge svg {
  flex-shrink: 0;
  opacity: 0.6;
}

.item-row:hover .comment-count-badge {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: transparent;
}

/* ── Célula: Checklist ──────────────────────────────────────── */
.cell-checklist {
  width: 90px;
  min-width: 70px;
}

.checklist-progress-wrapper {
  display: flex;
  flex-direction: column;
  gap: 3px;
  align-items: flex-end;
}

.pct-text {
  font-size: 11px;
  font-weight: 500;
  color: var(--muted-foreground);
  text-align: right;
  line-height: 1;
}

.checklist-progress-mini {
  height: 3px;
  background: var(--muted);
  border-radius: var(--radius-full);
  overflow: hidden;
  width: 52px;
  border: 1px solid var(--border);
}

.checklist-progress-mini .progress-bar {
  height: 100%;
  background: var(--primary);
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Avatar Stack ───────────────────────────────────────────── */
.table-avatar-stack,
.user-avatars-group {
  display: flex;
  align-items: center;
}

.table-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  border: 2px solid var(--background);
  margin-left: -6px;
  position: relative;
  flex-shrink: 0;
}

.table-avatar:first-child {
  margin-left: 0;
}

.table-avatar-more {
  background: var(--muted);
  color: var(--muted-foreground);
  border-color: var(--background);
  font-size: 9px;
}

/* ── Célula vazia (traço) ───────────────────────────────────── */
/* Colunas sem valor mostram traço no tom muted */
.items-table td:is(.cell-id, .cell-section, .cell-assignee, .cell-date, .cell-comments, .cell-checklist):not(:has(*)):empty::after,
.checklist-sub-row td.cell-id,
.checklist-sub-row td.cell-assignee,
.checklist-sub-row td.cell-comments,
.checklist-sub-row td.cell-checklist {
  color: var(--muted-foreground);
  opacity: 0.5;
}

/* ── Sub-linha de Checklist ─────────────────────────────────── */
.checklist-sub-row td {
  padding-top: 4px !important;
  padding-bottom: 4px !important;
  background: transparent !important;
  border-bottom: 1px solid transparent;
}

/* Borda inferior sutil apenas na última sub-linha do grupo */
/* .checklist-sub-row--last td {
  border-bottom-color: var(--border);
} */

.checklist-sub-row:hover td {
  background: var(--accent);
}

.checklist-sub-row {
  cursor: pointer;
}

/* Células vazias: sem conteúdo, sem traços — espaço limpo */
.checklist-sub-row .checklist-sub-empty {
  color: transparent;
  pointer-events: none;
}

/* Label da sub-tarefa: indentação com árvore visual */
.checklist-sub-label {
  padding-left: 12px !important;
  display: flex !important;
  align-items: center;
  gap: 0;
  white-space: nowrap;
  overflow: hidden;
}

/* Conector em árvore SVG */
.checklist-tree-line {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 16px;
  height: 20px;
  color: var(--muted-foreground);
  margin-right: 2px;
  opacity: 0.4;
  transition: opacity 0.15s ease;
}

.checklist-sub-row:hover .checklist-tree-line {
  opacity: 1;
  color: var(--muted-foreground);
}

.checklist-sub-text {
  font-size: 12px;
  color: var(--muted-foreground);
  font-weight: 400;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: color 0.15s ease;
}

.checklist-sub-row:hover .checklist-sub-text {
  color: var(--foreground);
}

.checklist-indent-icon {
  opacity: 0.35;
  margin-right: 5px;
  flex-shrink: 0;
  transition: opacity 0.15s ease;
}

.checklist-sub-row:hover .checklist-indent-icon {
  opacity: 0.6;
}

/* ── Shared Badge Styles ────────────────────────────────────── */
.step-pill,
.category-badge,
.item-type-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  border-radius: var(--radius-sm);
  padding: 2px 8px;
  border: 1px solid transparent;
  box-sizing: border-box;
  text-align: center;
}

/* Badges fora da tabela (Drawers) */
.category-badge,
.item-type-badge {
  margin-right: 4px;
  margin-bottom: 4px;
}

/* ── Ações da Tabela ────────────────────────────────────────── */
.table-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: var(--space-4);
  gap: var(--space-2);
}

/* ── Modal de Filtro ────────────────────────────────────────── */
.table-filter-modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.table-filter-modal-content {
  background: var(--background);
  padding: 20px;
  border-radius: var(--radius-xl);
  max-width: 380px;
  width: 90%;
  box-shadow: var(--soft-shadow);
  border: 1px solid var(--border);
}

.table-filter-modal-title {
  margin: 0 0 14px 0;
  font-size: var(--font-size-base);
  font-weight: 600;
}

.table-filter-options {
  max-height: 280px;
  overflow-y: auto;
  margin-bottom: 16px;
  padding-right: 2px;
}

.table-filter-option {
  display: flex;
  align-items: center;
  padding: 7px 10px;
  cursor: pointer;
  border-radius: var(--radius-md);
  transition: background 0.15s;
  font-size: var(--font-size-sm);
}

.table-filter-option:hover {
  background: var(--muted);
}

.table-filter-option input {
  margin-right: 10px;
  flex-shrink: 0;
}

.table-filter-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
}
