:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --primary: #0b5ed7;
  --accent: #0b66c2;
  --muted: #6b7280;
  --glass: rgba(11, 94, 215, 0.06);
  --radius: 10px;
  --maxwidth: 1200px;
  --banner-blue: #0b66c2;
  --banner-blue-dark: #084a86;
  --banner-height: 84px;
  --border-light: #eef3fb;
  font-family: Inter, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html { min-height: 100%; }
body { min-height: 100vh; }

body {
  margin: 0;
  background-color: #f5f7fa;
  background-image: linear-gradient(180deg, #f7fbff 0%, #f5f7fa 100%);
  background-repeat: no-repeat;
  background-attachment: fixed;
  color: #0f1724;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  padding: 24px;
  display: flex;
  justify-content: center;
  font-size: 15px;
  padding-top: calc(var(--banner-height) + 24px);
}

/* Links */
a {
  text-decoration: none;
  color: inherit;
  transition: color 0.2s;
}

/* Top banner azul */
.top-banner {
  width: 100%;
  background: linear-gradient(180deg, var(--banner-blue), #0a5fb8);
  color: #fff;
  box-shadow: 0 6px 18px rgba(11, 102, 194, 0.12);
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  height: var(--banner-height);
  display: flex;
  align-items: center;
}
.top-banner-inner {
  max-width: var(--maxwidth);
  margin: 0 auto;
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  width: 100%;
}
.banner-left { display: flex; align-items: center; gap: 12px; }
.banner-texts .banner-title { font-weight: 700; font-size: 16px; line-height: 1; }
.banner-texts .banner-sub { font-size: 13px; opacity: 0.92; margin-top: 2px; color: rgba(255, 255, 255, 0.92); }

/* Container & Sidebar */
.container {
  width: 100%;
  max-width: var(--maxwidth);
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

/* Main area */
.main { flex: 1; display: flex; flex-direction: column; gap: 14px; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; }
.title { font-size: 18px; font-weight: 700; }
.subtitle { color: var(--muted); font-size: 13px; }

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 6px 24px rgba(16, 24, 40, 0.06);
}

.section-title {
  margin: 0 0 10px 0;
  font-size: 16px;
  color: #0f1724;
}

/* Search form layout */
.search-row { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.search-field { flex: 1; min-width: 180px; }
.search-field-year { max-width: 220px; }
.search-field-wide { flex-basis: 360px; }

/* Grade do formulario de pesquisa de protocolos: 4 colunas fixas para que todos
   os campos alinhem em colunas, em vez de escorrerem com flex-wrap. */
.search-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px 16px;
  align-items: end;
}
.search-grid .search-field { flex: none; min-width: 0; }
.search-grid .span-2 { grid-column: span 2; }
.search-grid input { min-width: 0; }

/* Par de datas sob um rotulo unico */
.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.date-range { display: grid; grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr); align-items: center; gap: 8px; }
.date-range-sep { font-size: 13px; color: var(--muted); }

.req { color: #c02626; }

.search-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 2px;
  padding-top: 14px;
  border-top: 1px solid var(--border-light);
}
.search-actions-buttons { display: flex; gap: 8px; }
.search-hint { margin: 0; font-size: 12px; color: var(--muted); }

label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
input[type="text"], input[type="number"], input[type="date"], select {
  width: 100%; padding: 10px 12px; border-radius: 8px; border: 1px solid #e6eef7; background: #fbfdff; font-size: 14px; color: #0f1724;
}
input[type="text"]:focus, input[type="number"]:focus, input[type="date"]:focus, select:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(11, 102, 194, 0.15);
}

.actions { display: flex; gap: 8px; align-items: center; }
.btn { display: inline-flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 8px; border: 0; cursor: pointer; font-weight: 700; }
.btn-search { background: #2f9a3f; color: #fff; box-shadow: 0 6px 18px rgba(47, 154, 63, 0.12); }
.btn-search:hover { background: #288c37; }
.btn-clear { background: transparent; border: 1px solid rgba(0, 0, 0, 0.06); color: var(--muted); }
.btn-clear:hover { background: #f0f4f8; }

/* Content Layout */
.content { display: flex; flex-direction: column; gap: 16px; }
.protocol-result { margin-top: 16px; }
.protocol-results-table { margin-top: 16px; }
.protocol-list-grid .grid-header,
.protocol-list-grid .protocol-list-row {
  grid-template-columns:
    minmax(0, 15fr)
    minmax(0, 12fr)
    minmax(0, 28fr)
    minmax(0, 30fr)
    minmax(0, 15fr);
}

.protocol-list-grid .grid-header > div,
.protocol-list-grid .protocol-list-row > div {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: normal;
}

.protocol-list-grid .protocol-list-row > div:last-child {
  white-space: nowrap;
}

.protocol-list-row {
  color: inherit;
  text-decoration: none;
  transition: background-color 0.15s ease;
}

.protocol-list-row:hover {
  background: #f3f8fd;
}
.left-column { width: 100%; display: flex; flex-direction: column; gap: 12px; }

.results-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Details Card */
.details-card {
  border: 1px solid var(--border-light);
  background: #fff;
  border-radius: 8px;
  padding: 12px;
  margin-top: 14px;
}

.details-grid {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
}

.details-col { flex: 1; min-width: 160px; }
.details-col.flex-grow { flex: 2; min-width: 260px; } /* Coluna do meio maior */

.details-value { font-weight: 700; font-size: 16px; margin-top: 6px; }
.details-value-mt { margin-top: 6px; }

.print-actions {
  display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap;
}

/* =========================================
   GRID TABLE SYSTEM (Substituindo Tabelas)
   ========================================= */

.grid-table-container {
    margin-top: 12px;
    width: 100%;
}

.grid-table {
    display: flex;
    flex-direction: column;
    width: 100%;
    font-size: 14px;
    border-radius: 8px;
    overflow: hidden; /* Para bordas arredondadas funcionarem no header */
}

/* Headers e Rows comuns */
.grid-header {
    display: grid;
    background: #fbfdff;
    color: var(--muted);
    font-weight: 600;
    font-size: 13px;
    border-bottom: 1px solid var(--border-light);
}

.grid-row {
    display: grid;
    border-bottom: 1px solid var(--border-light);
    transition: background-color 160ms ease, transform 120ms ease, box-shadow 160ms ease;
    background: #fff;
}

.grid-header > div,
.grid-row > div {
    padding: 10px 12px;
    text-align: left;
    display: flex;
    align-items: center; /* Alinhamento vertical central */
    overflow-wrap: break-word;
}

/* Definição das Colunas para cada tabela específica */

/* 1. Tabela de Resultados: UJ | Classe | Data */
.results-grid .grid-header,
.results-grid .grid-row {
    grid-template-columns: 2fr 2fr 1fr;
}

/* 2. Tabela de Tramitações: Origem | Destino | Entrada | Saída */
.tram-grid .grid-header,
.tram-grid .grid-row {
    grid-template-columns: 2fr 2fr 1fr 1fr;
}

/* 3. Tabela de Peças: Icone | Nome */
.interessados-grid .grid-header,
.interessados-grid .grid-row {
    display: grid !important;
    grid-template-columns: minmax(260px, 2fr) minmax(150px, 1fr) minmax(240px, 2fr) 120px !important;
    min-width: 760px;
}

.interessados-grid .grid-body {
    max-height: 215px;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-gutter: stable;
}

.pecas-grid .grid-header,
.pecas-grid .grid-row {
    grid-template-columns: 60px 1fr;
}

/* Estilos de Interação e Estados */
.grid-row:hover {
    background: linear-gradient(90deg, rgba(11, 102, 194, 0.06), rgba(11, 102, 194, 0.03));
    transform: translateY(-2px);
    box-shadow: 0 6px 18px rgba(11, 102, 194, 0.06);
    z-index: 1; /* Sobrepor bordas ao flutuar */
}

.grid-row.latest {
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    border-left: 4px solid var(--banner-blue-dark);
    box-shadow: 0 8px 24px rgba(11, 102, 194, 0.12);
}

.grid-row.latest:hover {
    filter: brightness(1.03);
    transform: translateY(-3px);
    box-shadow: 0 10px 28px rgba(11, 102, 194, 0.14);
}

/* Tramitações Container */
.tram {
    margin-top: 14px;
    border-radius: 8px;
    background: #fbfdff;
    padding: 12px;
    border: 1px solid var(--border-light);
    width: 100%;
}
.section-label { display: block; margin-bottom: 8px; }

.pecas-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.pecas-section-header .section-label { margin-bottom: 0; }
.pecas-section-header form { margin: 0; }
.btn-logout {
  padding: 7px 11px;
  background: #dc2626;
  border-color: #dc2626;
  color: #fff;
}
.btn-logout:hover {
  background: #b91c1c;
  border-color: #b91c1c;
  color: #fff;
}

/* Mensagens de erro e avisos */
.empty, .empty-row { text-align: center; padding: 32px; color: var(--muted); font-size: 15px; width: 100%; display: block; }

.alert-warning {
  background-color: #fff8e1;
  color: #9c6f00;
  padding: 10px;
  border: 1px solid #ffecb3;
  border-radius: 5px;
  font-size: 14px;
  text-align: center;
}

.error {
  background: #fff4f4;
  border: 1px solid #ffd6d6;
  color: #9b1c1c;
  padding: 10px;
  border-radius: 8px;
  margin-bottom: 12px;
}

.pdf-icon {
    font-size: 18px;
    color: var(--primary);
    display: block;
    text-align: center;
    width: 100%;
}
.grid-row.latest .pdf-icon { color: #fff; }

.footer-version {
  font-size: 10px;
  margin-top: 20px;
  color: var(--muted);
}

/* Responsividade */
@media (max-width: 980px) {
  .search-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 620px) {
  .search-grid { grid-template-columns: minmax(0, 1fr); }
  .search-grid .span-2 { grid-column: span 1; }
  .search-actions { flex-direction: column; align-items: stretch; }
  .search-actions-buttons { flex-direction: column-reverse; }
  .search-actions .btn { width: 100%; justify-content: center; }
}

@media (max-width: 420px) {
  .date-range { grid-template-columns: minmax(0, 1fr); }
  .date-range-sep { display: none; }
}

@media (max-width: 1100px) {
  .container { padding: 12px; }
  .sidebar { display: none; }
  .banner-nav { display: none; }
}

@media (max-width: 600px) {
  .search-row { flex-direction: column; align-items: stretch; }
  .actions { justify-content: flex-end; }
  .banner-logo { width: 44px; height: 44px; font-size: 15px; }
  .banner-texts .banner-title { font-size: 14px; }
  .search-field-year { max-width: 100%; }

  /* Transforma a Grid em Cards no Mobile (opcional, mas recomendado para muitas colunas) */
  .grid-header { display: none; } /* Esconde cabeçalho da tabela */

  .grid-row {
    grid-template-columns: 1fr !important; /* Uma coluna só */
    padding: 10px;
    gap: 4px;
    border: 1px solid var(--border-light);
    margin-bottom: 8px;
    border-radius: 6px;
  }

  .grid-row > div {
    padding: 4px 0;
    display: flex;
    justify-content: space-between;
  }

  /* Label simulado via atributo data-label para mobile */
  .grid-row > div::before {
    content: attr(data-label);
    font-weight: 600;
    color: var(--muted);
    margin-right: 10px;
    font-size: 12px;
  }

  .pecas-grid .grid-row {
     flex-direction: row;
     display: flex;
     align-items: center;
  }

  .interessados-grid {
    overflow-x: auto;
  }

  .interessados-grid .grid-header {
    display: grid !important;
    grid-template-columns: minmax(260px, 2fr) minmax(150px, 1fr) minmax(240px, 2fr) 120px !important;
  }

  .interessados-grid .grid-row {
    display: grid !important;
    grid-template-columns: minmax(260px, 2fr) minmax(150px, 1fr) minmax(240px, 2fr) 120px !important;
    padding: 0;
    gap: 0;
  }

  .interessados-grid .grid-row > div {
    padding: 10px 12px;
    justify-content: flex-start;
  }

  .interessados-grid .grid-row > div::before {
    content: none;
  }
}

/* =========================
   SIDEBAR (Menu Lateral)
   ========================= */
.sidebar {
  width: 260px;
  background: #ffffff; /* Garante fundo branco */
  border-radius: 12px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05); /* Sombra suave */
  border: 1px solid #eef3fb; /* Borda sutil */
  height: fit-content;
  display: block; /* Garante que o aside se comporte como bloco */
}

/* Títulos das seções (Opções de Consulta, Documentos) */
.nav-title {
  font-weight: 700;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #6b7280; /* Cinza médio */
  margin-bottom: 10px;
}

/* Remove as bolinhas e recuos da lista */
.nav-list {
  list-style: none !important; /* Remove os bullets */
  padding: 0 !important;       /* Remove padding padrão */
  margin: 0 !important;        /* Remove margin padrão */
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Estilo dos Links */
.nav-list li a,
.nav-link {
  display: block;
  padding: 10px 14px;
  border-radius: 8px;
  color: #4b5563; /* Cor do texto normal */
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.2s ease;
  border: 1px solid transparent;
  background-color: transparent;
}

/* Hover (ao passar o mouse) */
.nav-list li a:hover,
.nav-link:hover {
  background-color: rgba(11, 94, 215, 0.04);
  color: #0b5ed7; /* Azul primário */
}

/* Item Ativo (página atual) */
.nav-submenu-title {
  display: block;
  padding: 10px 14px 6px 14px;
  color: #374151;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
}

.nav-sublist {
  list-style: none !important;
  list-style-type: none !important;
  margin: 2px 0 8px 0;
  padding: 0 0 0 14px;
  border-left: 1px solid #e5edf7;
}

.nav-sublist > li,
.nav-sublist li {
  list-style: none !important;
  list-style-type: none !important;
  display: block;
  margin: 0;
  padding: 0;
}

.nav-sublist > li::before {
  content: none !important;
}

.nav-sublist li::marker {
  content: "" !important;
  display: none;
}

.nav-sublist li + li {
  margin-top: 2px;
}

.nav-sublist .nav-sublink {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  color: #64748b;
  font-size: 13px;
  line-height: 1.25;
  text-decoration: none;
}

.nav-sublist .nav-sublink:hover {
  background-color: rgba(11, 94, 215, 0.04);
  color: #0b5ed7;
}

.nav-sublist .nav-sublink i {
  flex: 0 0 auto;
  font-size: 11px;
  opacity: 0.65;
}

.nav-list li a.active,
.nav-link.active {
  background-color: rgba(11, 94, 215, 0.1);
  color: #0b5ed7;
  font-weight: 700;
}

/* Ícone externo (se houver) */
.nav-link i {
  opacity: 0.7;
}

/* Espaçamento entre os grupos (Opções de Consulta vs Documentos) */
.nav-group + .nav-group {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #eef3fb;
}

/* =========================
   MENU SUPERIOR (Banner)
   ========================= */
.banner-nav {
  display: flex;
  gap: 8px; /* Espaço entre os botões */
  align-items: center;
  height: 100%;
}

.banner-nav .nav-link {
  color: rgba(255, 255, 255, 0.85); /* Branco com leve transparência */
  text-decoration: none;
  padding: 8px 12px;
  border-radius: 6px;
  font-weight: 500;
  font-size: 14px;
  transition: all 0.2s ease;
  white-space: nowrap; /* Impede que o texto quebre linha */
}

/* Efeito Hover (passar o mouse) */
.banner-nav .nav-link:hover {
  background-color: rgba(255, 255, 255, 0.1); /* Fundo branco translúcido */
  color: #ffffff;
  transform: translateY(-1px); /* Leve subida */
}

/* Item Ativo (Página atual) */
.banner-nav .nav-link.active {
  background-color: rgba(255, 255, 255, 0.2); /* Fundo mais forte */
  color: #ffffff;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Responsividade: Esconder menu superior em telas menores
   (pois já existe o menu lateral ou o layout quebraria) */
@media (max-width: 1000px) {
  .banner-nav {
    display: none;
  }
}


/* Configuracoes para o modal e loading */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline;
}

.htmx-request .normal-text {
    display: none;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin: 20px 0;
}

.pagination-status {
  color: #64748b;
  font-size: 14px;
  font-weight: 600;
}

.pagination .btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
