:root {
  /* Sidebar */
  --sidebar-bg: #111827;
  --sidebar-text: #9ca3af;
  --sidebar-text-active: #ffffff;
  --sidebar-hover: #1f2937;
  --sidebar-active-bg: #3b82f6;

  /* Main Content Light Theme */
  --bg: #f9fafb;
  --surface: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-muted: #6b7280;

  /* Status Colors */
  --total: #3b82f6;
  --total-bg: #eff6ff;
  
  --ok: #22c55e;
  --ok-bg: #f0fdf4;
  
  --expired: #ef4444;
  --expired-bg: #fef2f2;
  
  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  
  --accent: #3b82f6;
  
  font-family: "Segoe UI", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  display: flex;
}

/* Sidebar */
.sidebar {
  width: 250px;
  background-color: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 10;
}

.sidebar-header {
  padding: 1.5rem 1.25rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-icon {
  width: 2.25rem;
  height: 2.25rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.brand-icon img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.brand-icon svg {
  width: 1.4rem;
  height: 1.4rem;
}

.brand-text h2 {
  color: white;
  margin: 0;
  font-size: 1.1rem;
  font-weight: 600;
  line-height: 1.2;
}

.brand-text span {
  font-size: 0.75rem;
  color: var(--sidebar-text);
}

.sidebar-nav {
  padding: 1.25rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 1rem;
  color: var(--sidebar-text);
  text-decoration: none;
  border-radius: 8px;
  font-weight: 500;
  font-size: 0.95rem;
  transition: all 0.2s;
}

.sidebar-nav a svg {
  width: 1.3rem;
  height: 1.3rem;
}

.sidebar-nav a:hover {
  background-color: var(--sidebar-hover);
  color: var(--sidebar-text-active);
}

.sidebar-nav a.active {
  background-color: var(--sidebar-active-bg);
  color: var(--sidebar-text-active);
}

/* Main Content */
.main-content {
  flex: 1;
  margin-left: 250px;
  padding: 2.5rem 3rem;
  min-height: 100vh;
}

.page-header {
  margin-bottom: 2rem;
}

.page-header h1 {
  font-size: 1.8rem;
  font-weight: 600;
  color: var(--text);
  margin: 0 0 0.5rem;
}

.page-header p {
  color: var(--text-muted);
  margin: 0;
  font-size: 0.95rem;
}

/* Cards */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}

.dashboard-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.card-info {
  display: flex;
  flex-direction: column;
}

.card-title {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 0.5rem;
}

.card-number {
  font-size: 2rem;
  font-weight: 600;
  color: var(--text);
  line-height: 1;
}

.card-subtitle {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 0.5rem;
}

.card-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card-icon svg {
  width: 22px;
  height: 22px;
}

.card-total .card-icon {
  background-color: var(--total-bg);
  color: var(--total);
}

.card-validos .card-icon {
  background-color: var(--ok-bg);
  color: var(--ok);
}

.card-expirando .card-icon {
  background-color: var(--warning-bg);
  color: var(--warning);
}

.card-vencidos .card-icon {
  background-color: var(--expired-bg);
  color: var(--expired);
}

.card-erros .card-icon {
  background-color: #fff7ed;
  color: #ea580c;
}

.card-sem-padrao .card-icon {
  background-color: #f5f3ff;
  color: #7c3aed;
}

/* Table Area */
.table-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
  margin-bottom: 2rem;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  padding-bottom: 1.25rem;
  border-bottom: 1px dashed var(--border);
  flex-wrap: wrap;
  gap: 1rem;
}

.toolbar__actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

button {
  background: var(--surface);
  border: 1px solid #d1d5db;
  color: var(--text);
  padding: 0.45rem 1rem;
  border-radius: 6px;
  font-weight: 500;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

button:hover {
  background-color: #f3f4f6;
}

button.primary {
  background-color: var(--accent);
  color: white;
  border-color: var(--accent);
}

button.primary:hover {
  background-color: #2563eb;
}

button.danger {
  color: var(--expired);
  border-color: #fca5a5;
  background-color: var(--surface);
}

button.danger:hover {
  background-color: var(--expired-bg);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th, td {
  padding: 0.85rem 0.5rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

th {
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.05em;
  padding-top: 0;
}

tr:last-child td {
  border-bottom: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.6rem;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.badge-ok {
  background-color: var(--ok-bg);
  color: var(--ok);
  border: 1px solid #bbf7d0;
}

.badge-warning {
  background-color: var(--warning-bg);
  color: var(--warning);
  border: 1px solid #fde68a;
}

.badge-expired {
  background-color: var(--expired-bg);
  color: var(--expired);
  border: 1px solid #fecaca;
}

.badge-bad {
  background-color: #f3f4f6;
  color: #4b5563;
  border: 1px solid #d1d5db;
}

.td-doc {
  min-width: 9rem;
}

.doc-type-label {
  font-weight: 600;
  color: var(--accent);
  display: block;
}

.doc-type-num {
  color: var(--text-muted);
  font-size: 0.8rem;
}

.hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0;
}

.status-line {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 500;
}

.error-cell {
  color: #b91c1c;
  font-size: 0.82rem;
}

/* Configuracao Page Styles */
.config-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 2rem;
  align-items: start;
}

.doc-block {
  margin-bottom: 2.5rem;
}

.doc-block h2 {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0 0 0.5rem;
}

.doc-block > p {
  color: var(--text-muted);
  margin-bottom: 1rem;
}

.panel--nested {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.row, .row-inline {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.row label {
  min-width: 140px;
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.9rem;
}

.path-input {
  flex: 1;
  min-width: 200px;
  background: #f9fafb;
  border: 1px solid #d1d5db;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--text);
  outline: none;
}
.path-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2);
}

.side-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.side-card h3 {
  font-size: 0.95rem;
  margin: 0 0 0.5rem;
}

.side-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0 0 0.75rem;
}

.path-summary-title {
  font-size: 1rem;
  font-weight: 600;
  margin: 1.5rem 0 0.5rem;
}

.path-line {
  margin-bottom: 0.5rem;
}

.path-label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.path-value {
  display: block;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-family: monospace;
  font-size: 0.85rem;
  color: #1f2937;
  word-break: break-all;
}

.tag {
  display: inline-block;
  background: #f3f4f6;
  border: 1px solid #e5e7eb;
  padding: 0.25rem 0.6rem;
  border-radius: 4px;
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 500;
}

select {
  background: #f9fafb;
  border: 1px solid #d1d5db;
  padding: 0.4rem 0.5rem;
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--text);
}

.hint-warn {
  background: var(--expired-bg);
  border: 1px solid #fecaca;
  color: #991b1b;
  padding: 0.75rem;
  border-radius: 8px;
}

.cmd-pre {
  background: #111827;
  color: #e5e7eb;
  padding: 1rem;
  border-radius: 8px;
  font-family: monospace;
  font-size: 0.8rem;
  overflow-x: auto;
}

.doc-list {
  padding-left: 1.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.doc-list li {
  margin-bottom: 0.5rem;
}

/* Sidebar toggle */
.sidebar-toggle-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  width: 40px;
  height: 36px;
  border-radius: 8px;
  font-size: 1.05rem;
  line-height: 1;
  margin-bottom: 1rem;
}

body.sidebar-collapsed .sidebar {
  width: 76px;
}

body.sidebar-collapsed .main-content {
  margin-left: 76px;
}

body.sidebar-collapsed .brand-text {
  display: none;
}

body.sidebar-collapsed .sidebar-header {
  justify-content: center;
}

body.sidebar-collapsed .sidebar-nav a {
  justify-content: center;
  font-size: 0;
  gap: 0;
  padding-left: 0.7rem;
  padding-right: 0.7rem;
}

@media (max-width: 900px) {
  .sidebar {
    width: 76px;
  }
  .brand-text {
    display: none;
  }
  .sidebar-header {
    justify-content: center;
  }
  .sidebar-nav a {
    justify-content: center;
    font-size: 0;
    gap: 0;
    padding-left: 0.7rem;
    padding-right: 0.7rem;
  }
  .main-content {
    margin-left: 76px;
    padding: 1.25rem;
  }
}

/* Duplicidades — tabelas criptográficas com paginação */
.dup-crypto-table-block {
  margin-bottom: 2rem;
}

.dup-crypto-table-block h2 {
  font-size: 1.1rem;
  margin: 0 0 0.5rem;
}

.dup-crypto-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
}

.dup-crypto-table-wrap table {
  margin: 0;
  width: 100%;
  min-width: 420px;
}

.dup-igual-row,
.dup-doc-row {
  cursor: help;
}

.dup-igual-row:hover,
.dup-crypto-table-wrap tbody tr.dup-data-row:hover {
  background: rgba(59, 130, 246, 0.06);
}

.dup-igual-status {
  color: #b45309;
  font-size: 0.95rem;
}

.dup-crypto-table-wrap th,
.dup-crypto-table-wrap td {
  padding: 0.5rem 0.65rem;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

.dup-crypto-table-wrap tr:last-child td {
  border-bottom: none;
}

.dup-crypto-table-wrap tbody tr.hint-only td {
  border-bottom: none;
  padding: 0.9rem 0.75rem;
}

/* Tooltip — ficheiros duplicados (mesma linha) */
.dup-path-tooltip {
  position: fixed;
  z-index: 2000;
  min-width: 12rem;
  max-width: min(92vw, 36rem);
  padding: 0.7rem 0.85rem 0.75rem;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 10px 24px -4px rgba(15, 23, 42, 0.12);
  font-size: 0.8125rem;
  line-height: 1.45;
  pointer-events: auto;
  transition: opacity 0.12s ease;
}

.dup-path-tooltip[hidden] {
  display: none !important;
  pointer-events: none;
}

.dup-path-tooltip__head {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0 0 0.45rem;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--accent);
  letter-spacing: 0.01em;
}

.dup-path-tooltip__head svg {
  width: 0.95rem;
  height: 0.95rem;
  flex-shrink: 0;
  opacity: 0.9;
}

.dup-path-tooltip__list {
  margin: 0;
  padding: 0 0 0 1.1rem;
  list-style: disc;
  color: var(--text-muted);
}

.dup-path-tooltip__list li {
  margin: 0.2rem 0;
  padding: 0;
}

.dup-path-tooltip__list li::marker {
  color: var(--border);
}

.dup-path-tooltip__path {
  display: block;
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 0.8rem;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.28rem 0.45rem;
  margin: 0.1rem 0 0;
  word-break: break-all;
  white-space: pre-wrap;
}

/* Tooltip — mesmo documento: bloco vencimento + bloco caminho (mesma linha) */
ul.dup-doc-tooltip__lines {
  list-style: none;
  padding-left: 0;
  margin: 0;
}

ul.dup-doc-tooltip__lines li.dup-doc-tooltip__row {
  list-style: none;
  margin: 0.5rem 0 0;
  padding: 0.5rem 0 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 0.5rem;
}

ul.dup-doc-tooltip__lines li.dup-doc-tooltip__row:first-child {
  border-top: none;
  margin-top: 0;
  padding-top: 0;
}

.dup-doc-tooltip__bloco {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  padding: 0.32rem 0.45rem;
  min-width: 0;
  flex: 1 1 9rem;
}

.dup-doc-tooltip__bloco--venc {
  font-weight: 600;
  font-size: 0.78rem;
  color: var(--text);
  white-space: nowrap;
  flex: 0 1 auto;
  max-width: 100%;
}

.dup-doc-tooltip__bloco--arquivo {
  flex: 2 1 12rem;
}

.dup-doc-tooltip__caminho {
  display: block;
  font-family: ui-monospace, "Cascadia Code", "Consolas", monospace;
  font-size: 0.78rem;
  color: var(--text);
  word-break: break-all;
  white-space: pre-wrap;
  line-height: 1.35;
}

/* Loading overlay global */
.global-loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(17, 24, 39, 0.28);
  backdrop-filter: blur(1px);
  z-index: 3000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.18s ease, visibility 0.18s ease;
}

.global-loading-overlay.is-visible {
  opacity: 1;
  visibility: visible;
}

.global-loading-card {
  min-width: 220px;
  max-width: min(88vw, 420px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.14);
  padding: 1rem 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.global-loading-spinner {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  border: 2px solid #d1d5db;
  border-top-color: var(--accent);
  animation: spin-loader 0.8s linear infinite;
  flex-shrink: 0;
}

.global-loading-text {
  color: var(--text);
  font-weight: 600;
  font-size: 0.92rem;
}

@keyframes spin-loader {
  to {
    transform: rotate(360deg);
  }
}

/* Paginação (estilo “button group”, sem Tailwind) */
.cg-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.cg-page-nav {
  margin-top: 1rem;
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
}

.cg-page-nav.is-visible {
  display: flex;
}

.cg-page-nav__meta {
  font-size: 0.875rem;
  color: var(--text-muted);
  text-align: center;
}

.cg-page-nav__row {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.cg-page-nav__ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: inline-flex;
  flex-direction: row;
  flex-wrap: nowrap;
  align-items: stretch;
  width: auto;
}

.cg-page-nav__ul > li {
  display: flex;
  flex: 0 0 auto;
}

.cg-page-nav__ul > li + li .cg-page-link {
  margin-left: -1px;
}

.cg-page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 0 0.7rem;
  min-height: 2.25rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.25;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.cg-page-link:hover:not(:disabled) {
  background: #f3f4f6;
  color: var(--text);
  z-index: 1;
}

.cg-page-link:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  z-index: 2;
}

.cg-page-link:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.cg-page-link--square {
  min-width: 2.25rem;
  padding-left: 0;
  padding-right: 0;
  border-radius: 0;
}

.cg-page-link--rounded-s {
  border-radius: 6px 0 0 6px;
}

.cg-page-link--rounded-e {
  border-radius: 0 6px 6px 0;
}

.cg-page-link--current {
  color: var(--accent);
  background: #eff6ff;
  border-color: var(--accent);
}

.cg-page-perpage-select {
  min-width: 8.5rem;
  padding: 0.55rem 0.65rem;
  font: inherit;
  font-size: 0.875rem;
  line-height: 1.25;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.05);
}

.cg-page-perpage-select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: var(--accent);
}
