/* ==========================================================================
   PatrimônioPRO - Design System com Topbar Fixa e Rodapé de Segurança
   Desenvolvido por Jaikon Araújo & E-Codes Tecnologia
   ========================================================================== */

:root {
  --primary-color: #059669;
  --primary-hover: #047857;
  --secondary-color: #10b981;
  --bg-main: #f8fafc;
  --bg-card: #ffffff;
  --bg-sidebar: #0b1329;
  --sidebar-text: #e2e8f0;
  --sidebar-muted: #94a3b8;
  --sidebar-hover: #172554;
  --sidebar-active: rgba(5, 150, 105, 0.22);
  --sidebar-active-text: #34d399;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --input-bg: #ffffff;
  --table-hover: #f1f5f9;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --info: #0284c7;
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.06);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

/* Modo Escuro (Dark Mode) */
[data-theme="dark"] {
  --bg-main: #0b0f19;
  --bg-card: #111827;
  --bg-sidebar: #030712;
  --sidebar-text: #f3f4f6;
  --sidebar-muted: #9ca3af;
  --sidebar-hover: #1f2937;
  --sidebar-active: rgba(16, 185, 129, 0.25);
  --sidebar-active-text: #34d399;
  --text-main: #f9fafb;
  --text-muted: #9ca3af;
  --border-color: #1f2937;
  --input-bg: #1f2937;
  --table-hover: #1e293b;
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

body {
  background-color: var(--bg-main);
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
}

/* Estrutura Principal */
.app-wrapper {
  display: flex;
  width: 100%;
  min-height: 100vh;
  height: 100vh;
  overflow: hidden;
}

/* ==========================================================================
   Barra Lateral Esquerda (Sidebar) - Focada em Navegação e Sem Rolagem
   ========================================================================== */

.sidebar {
  width: 240px;
  background-color: var(--bg-sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 40;
  overflow-y: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.sidebar::-webkit-scrollbar {
  display: none;
}

/* Header da Sidebar (Marca do Sistema) */
.sidebar-header {
  padding: 1rem 0.85rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.brand-icon-box {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  color: white;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  box-shadow: 0 2px 8px rgba(5, 150, 105, 0.3);
  flex-shrink: 0;
  overflow: hidden;
}

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

.brand-name {
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: #ffffff;
  line-height: 1.1;
}

.brand-sub {
  font-size: 0.64rem;
  color: var(--sidebar-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Menu de Navegação Vertical */
.sidebar-nav {
  flex: 1;
  padding: 0.5rem 0.55rem;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  overflow-y: auto;
  scrollbar-width: none;
}

.sidebar-nav::-webkit-scrollbar {
  display: none;
}

.nav-section-title {
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--sidebar-muted);
  padding: 0.4rem 0.55rem 0.15rem;
  font-weight: 800;
  opacity: 0.8;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.44rem 0.65rem;
  border-radius: 6px;
  font-size: 0.81rem;
  font-weight: 500;
  color: var(--sidebar-muted);
  cursor: pointer;
  transition: all 0.12s ease;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-nav-item:hover {
  background-color: var(--sidebar-hover);
  color: #ffffff;
}

.sidebar-nav-item.active {
  background-color: var(--sidebar-active);
  color: var(--sidebar-active-text);
  font-weight: 700;
}

.sidebar-nav-item .nav-icon {
  font-size: 1.05rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  flex-shrink: 0;
}

.sidebar-bottom-action {
  padding: 0.65rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

.btn-qr-scan-sidebar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  padding: 0.45rem;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--primary-color), var(--secondary-color));
  border: none;
  color: #ffffff;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(5, 150, 105, 0.25);
}

/* ==========================================================================
   Topbar Superior Fixa (Sempre Alinhada e Conectada ao Scroll)
   ========================================================================== */

.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow-y: auto;
}

.topbar-fixed {
  position: sticky;
  top: 0;
  z-index: 100;
  background-color: var(--bg-card);
  border-bottom: 1px solid var(--border-color);
  padding: 0.5rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: var(--shadow-sm);
  backdrop-filter: blur(8px);
  min-height: 58px;
  gap: 1rem;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 1.25rem;
  flex-shrink: 0;
}

.topbar-page-title {
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.01em;
  white-space: nowrap;
}

/* Caixa Seletora de Instituição na Topbar */
.topbar-institution-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.28rem 0.65rem;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.topbar-inst-emblem {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  overflow: hidden;
  flex-shrink: 0;
  background: rgba(0,0,0,0.05);
}

.topbar-inst-emblem img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.topbar-inst-select-wrapper {
  display: flex;
  flex-direction: column;
}

.topbar-inst-label {
  font-size: 0.58rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 700;
  line-height: 1;
}

.topbar-institution-select {
  background: transparent;
  border: none;
  color: var(--text-main);
  font-size: 0.8rem;
  font-weight: 800;
  outline: none;
  cursor: pointer;
  max-width: 220px;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.topbar-institution-select option {
  background: var(--bg-card);
  color: var(--text-main);
}

/* Lado Direito da Topbar: Ações, Perfil e Botão Sair */
.topbar-right {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex-shrink: 0;
}

.topbar-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.65rem;
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  color: var(--text-main);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.12s ease;
  white-space: nowrap;
}

.topbar-btn:hover {
  background: var(--border-color);
}

.topbar-divider {
  width: 1px;
  height: 26px;
  background: var(--border-color);
  margin: 0 0.25rem;
}

/* Seção de Perfil do Usuário na Barra Superior */
.topbar-user-section {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-main);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.25rem 0.55rem;
}

.topbar-user-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 800;
  flex-shrink: 0;
}

.topbar-user-info {
  display: flex;
  flex-direction: column;
}

.topbar-user-name {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-main);
  max-width: 150px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.1;
}

.topbar-user-role {
  display: inline-block;
  font-size: 0.58rem;
  font-weight: 800;
  padding: 0.05rem 0.3rem;
  border-radius: 3px;
  text-transform: uppercase;
  margin-top: 0.1rem;
  align-self: flex-start;
}

.role-admin { background: #fef2f2; color: #dc2626; }
.role-gestor { background: #eff6ff; color: #2563eb; }
.role-responsavel { background: #ecfdf5; color: #059669; }

/* Botão Sair ao Lado do Nome da Pessoa */
.topbar-btn-logout {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: #ef4444;
  background: rgba(239, 68, 68, 0.08);
  border: 1px solid rgba(239, 68, 68, 0.2);
  border-radius: 6px;
  padding: 0.32rem 0.6rem;
  font-size: 0.76rem;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
  margin-left: 0.25rem;
  white-space: nowrap;
}

.topbar-btn-logout:hover {
  background: #ef4444;
  color: #ffffff;
}

/* ==========================================================================
   Container Principal de Conteúdo
   ========================================================================== */

.container {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1.5rem;
  flex: 1;
}

/* Métricas e Dashboard Cards */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.metric-card {
  background: var(--bg-card);
  border-radius: 10px;
  padding: 1rem 1.15rem;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  position: relative;
  overflow: hidden;
}

.metric-card::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--primary-color);
}

.metric-card.indigo::before { background: #6366f1; }
.metric-card.amber::before { background: var(--warning); }
.metric-card.teal::before { background: #0d9488; }

.metric-title {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
}

.metric-value {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1.2;
  margin: 0.35rem 0;
}

.metric-subtext {
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* Cards & Tabelas */
.card {
  background: var(--bg-card);
  border-radius: 10px;
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  margin-bottom: 1.25rem;
  overflow: hidden;
}

.card-header {
  padding: 0.85rem 1.15rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.card-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
}

.table-responsive {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.82rem;
}

th {
  background-color: var(--bg-main);
  padding: 0.65rem 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border-color);
  color: var(--text-main);
  vertical-align: middle;
}

tr:hover td {
  background-color: var(--table-hover);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: 9999px;
  font-size: 0.7rem;
  font-weight: 700;
}

.badge-success { background: rgba(16, 185, 129, 0.15); color: #059669; }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: #d97706; }
.badge-danger { background: rgba(239, 68, 68, 0.15); color: #dc2626; }
.badge-info { background: rgba(2, 132, 199, 0.15); color: #0284c7; }
.badge-neutral { background: var(--bg-main); color: var(--text-muted); border: 1px solid var(--border-color); }

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.45rem 0.85rem;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.12s ease;
  text-decoration: none;
}

.btn-primary {
  background-color: var(--primary-color);
  color: white;
}
.btn-primary:hover {
  background-color: var(--primary-hover);
}

.btn-secondary {
  background-color: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-color);
}
.btn-secondary:hover {
  background-color: var(--bg-main);
}

.btn-sm {
  padding: 0.25rem 0.55rem;
  font-size: 0.75rem;
  border-radius: 5px;
}

/* Ícones de Ajuda para Leigos (?) */
.help-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: rgba(5, 150, 105, 0.15);
  color: var(--primary-color);
  font-size: 0.68rem;
  font-weight: 800;
  cursor: pointer;
  margin-left: 0.35rem;
  transition: transform 0.12s, background-color 0.12s;
  vertical-align: middle;
  border: 1px solid rgba(5, 150, 105, 0.3);
}

.help-icon:hover {
  transform: scale(1.2);
  background-color: var(--primary-color);
  color: white;
}

/* Modais */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background-color: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(3px);
  z-index: 110;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-content {
  background: var(--bg-card);
  border-radius: 12px;
  width: 100%;
  max-width: 650px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4);
  border: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
}

.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.modal-close {
  background: transparent;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--text-muted);
}

.modal-body {
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.modal-footer {
  padding: 0.85rem 1.15rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  background-color: var(--bg-main);
}

/* Formulários */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 0.82rem;
  color: var(--text-main);
  background-color: var(--input-bg);
  outline: none;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.2);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.85rem;
}

/* ==========================================================================
   Rodapé Oficial de Segurança, Criptografia e Créditos de Desenvolvimento
   ========================================================================== */

.system-footer-security {
  margin-top: auto;
  padding: 1.25rem 1.5rem 1.5rem;
  display: flex;
  justify-content: center;
  width: 100%;
  background: transparent;
}

.security-card {
  max-width: 860px;
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.4rem;
  box-shadow: var(--shadow-sm);
}

.security-badge-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--primary-color);
}

.security-shield-icon {
  font-size: 0.95rem;
}

.security-tag {
  background: rgba(5, 150, 105, 0.15);
  color: var(--primary-color);
  padding: 0.1rem 0.45rem;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 800;
  border: 1px solid rgba(5, 150, 105, 0.3);
  letter-spacing: 0.05em;
}

.security-compliance-line {
  font-size: 0.74rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.security-credits-line {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-weight: 500;
  border-top: 1px solid var(--border-color);
  padding-top: 0.45rem;
  width: 100%;
  margin-top: 0.2rem;
}

.security-credits-line strong {
  color: var(--primary-color);
  font-weight: 700;
}

/* Animação do Scanner Laser */
@keyframes scanLine {
  0% { top: 0%; }
  50% { top: 100%; }
  100% { top: 0%; }
}

/* ==========================================================================
   Ajustes Responsivos Limpos
   ========================================================================== */

@media (max-width: 1100px) {
  .topbar-page-title {
    display: none;
  }
}

@media (max-width: 768px) {
  .topbar-btn-text {
    display: none;
  }
  .topbar-institution-select {
    max-width: 140px;
  }
  .topbar-user-name {
    max-width: 90px;
  }
}
