:root {
  --primary: #1a5276;
  --secondary: #2e86c1;
  --gradient: linear-gradient(135deg, #1a5276 0%, #2e86c1 100%);
  --bg: #f0f2f5;
  --panel: #ffffff;
  --line: #e2eaf2;
  --text: #1f2a37;
  --muted: #6b7f94;
  --title: #133a57;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
}

.btn-primary-custom {
  background: var(--gradient);
  border: none;
  border-radius: 10px;
  padding: 8px 18px;
  font-weight: 600;
  color: #fff;
  font-size: 0.85rem;
  transition: all 0.2s;
}
.btn-primary-custom:hover {
  color: #fff;
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(26,82,118,0.28);
}
.btn-outline-secondary {
  border-radius: 10px;
}
.form-control, .form-select {
  border-radius: 8px;
  border: 1px solid #dde6ef;
  padding: 6px 12px;
  font-size: 0.85rem;
  background: #fafcfe;
}
.form-control:focus, .form-select:focus {
  border-color: var(--secondary);
  box-shadow: 0 0 0 0.2rem rgba(46,134,193,0.22);
  outline: none;
}
.table > :not(caption) > * > * {
  vertical-align: middle;
}
.table thead th {
  background: #f4f8fe;
  color: #1f3a5f;
  font-weight: 600;
  font-size: 0.65rem;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  padding: 8px 10px;
  border-bottom: 2px solid #e2ecf5;
}
.table td {
  padding: 8px 10px;
  font-size: 0.85rem;
  color: #1d334a;
}
.table-hover tbody tr:hover {
  background: #f8fbfe;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  position: relative;
}
.min-vh-100 { min-height: 100vh; }
.sidebar {
  width: 270px;
  background: var(--gradient);
  color: #e6edf5;
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
  box-shadow: 4px 0 18px rgba(0,0,0,0.08);
  flex-shrink: 0;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 1000;
}
.sidebar-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 1200;
  border: none;
  border-radius: 999px;
  width: 42px;
  height: 42px;
  background: var(--gradient);
  color: white;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.18);
}
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.35);
  z-index: 1050;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}
.sidebar-backdrop.is-visible {
  opacity: 1;
  visibility: visible;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 6px;
}
.brand i { font-size: 1.7rem; color: #d9eeff; }
.brand h5 { color: #fff; font-weight: 700; }
.nav-links { display: flex; flex-direction: column; gap: 6px; }
.nav-link {
  color: #b6cbe0;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 500;
  font-size: 0.85rem;
}
.nav-link:hover, .nav-link.active {
  background: rgba(255,255,255,0.16);
  color: white;
}
.main-content {
  flex: 1;
  padding: 24px;
  margin-left: 270px;
  width: calc(100% - 270px);
  min-height: 100vh;
}
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  background: var(--panel);
  padding: 14px 18px;
  border: 1px solid var(--line);
  border-radius: 15px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  gap: 12px;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.section { display: none; }
.section.active { display: block; }
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 18px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  margin-bottom: 20px;
}
.panel-header { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.flex-between { justify-content: space-between; }
.card-custom {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 15px;
  padding: 18px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.05);
  margin-bottom: 20px;
}
.card-custom .label { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.08em; }
.card-custom .value { font-size: 2rem; font-weight: 700; margin-top: 8px; color: var(--title); }
.table-responsive { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.badge { font-weight: 600; }
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  min-width: 220px;
  border-radius: 12px;
  box-shadow: 0 10px 24px rgba(17, 35, 55, 0.16);
}
@media (min-width: 901px) {
  .sidebar {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    height: 100vh !important;
    transform: none !important;
    overflow-y: auto !important;
  }
  .main-content {
    margin-left: 270px !important;
    width: calc(100% - 270px) !important;
  }
}
@media (max-width: 900px) {
  .app-shell { min-height: 100vh; }
  .sidebar-toggle { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
     position: fixed;
     inset: 0 auto 0 0;
     width: min(86vw, 300px);
     height: 100vh;
     z-index: 1100;
     transform: translateX(-100%);
     transition: transform 0.25s ease;
     overflow-y: auto;
  }
  .sidebar.is-open {
     transform: translateX(0);
  }
  .main-content {
     padding: 16px;
     padding-top: 68px;
     width: 100%;
    margin-left: 0;
  }
  .topbar {
     flex-direction: column;
     align-items: start;
     gap: 10px;
  }
  .topbar-actions {
     width: 100%;
     justify-content: flex-start;
  }
  .panel-header, .flex-between {
     flex-direction: column;
     align-items: flex-start;
     gap: 10px;
  }
  .table-responsive {
     overflow-x: auto;
  }
}

@media (max-width: 600px) {
  .main-content { padding: 12px; padding-top: 64px; }
  .topbar { padding: 12px 14px; }
  .nav-link { padding: 12px 14px; }
  .card-custom .value { font-size: 1.5rem; }
  .topbar-actions .btn,
  .topbar-actions .badge {
     width: 100%;
     justify-content: center;
  }
}

/* Buscador de contadores - fila marcada */
.contador-highlight {
  animation: highlight-pulse 1.5s ease-in-out;
  outline: 2px solid #ffc107;
}
@keyframes highlight-pulse {
  0%   { background-color: #fff3cd; }
  50%  { background-color: #ffe69c; }
  100% { background-color: #fff3cd; }
}

/* ── Boletín imprimible ── */
@media print {
  .no-print, .sidebar, .topbar, .modal-header, nav { display: none !important; }
  .modal-dialog { max-width: 100% !important; margin: 0 !important; }
  .modal-content { border: 0 !important; box-shadow: none !important; }
  body { background: white !important; }
  .boletin-page { page-break-after: always; }
  .boletin-page:last-child { page-break-after: avoid; }
  .sin-lectura-report .sin-lectura-header { border-bottom: 2px solid #dc3545 !important; }
}
.boletin-page { border: 1px solid #dee2e6; border-radius: 8px; padding: 24px; margin-bottom: 20px; }
.boletin-header { border-bottom: 2px solid #0d6efd; margin-bottom: 16px; padding-bottom: 12px; }
.boletin-total { font-size: 1.3rem; font-weight: bold; color: #0d6efd; }

/* Modal de comunidad: estilo similar a PT */
#modalEntidad .modal-content {
  border-radius: 16px;
  border: none;
  box-shadow: 0 16px 36px rgba(16, 35, 61, 0.16);
  overflow: hidden;
}
#modalEntidad .modal-dialog {
  margin: 0.9rem auto;
}
#modalEntidad .modal-lg {
  max-width: 900px;
}
#modalEntidad.modal-comunidad .modal-dialog {
  max-width: min(1080px, 96vw);
  width: min(1080px, 96vw);
}
#modalEntidad .modal-header {
  padding: 1rem 1.1rem;
  background: linear-gradient(90deg, #143b57 0%, #2e86c1 100%);
  color: white;
  border-bottom: 0;
}
#modalEntidad .modal-header .btn-close {
  filter: brightness(0) invert(1);
}
#modalEntidad .modal-title {
  font-weight: 700;
  font-size: 1rem;
}
#modalEntidad .modal-footer {
  padding: 0.8rem 1.1rem 1rem;
  background: #f7fbff;
  border-top: 1px solid #e8eef4;
}
#modalEntidad .modal-body {
  max-height: 70vh;
  overflow-y: auto;
  padding: 1rem 1.1rem 0.8rem;
}
#modalEntidad .form-label {
  margin-bottom: 0.25rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: #49647e;
}
#modalEntidad .form-control,
#modalEntidad .form-select {
  padding: 0.55rem 0.7rem;
  font-size: 0.9rem;
  border-radius: 10px;
}

.community-tabs-wrap {
  margin-bottom: 8px;
}
.community-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  padding: 8px;
  background: #f7fbff;
  border: 1px solid #e8eef4;
  border-radius: 12px;
}
.community-tabs input[type="radio"] {
  display: none;
}
.community-tab {
  border: 1px solid #dce8f2;
  background: #ffffff;
  color: var(--text);
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  font-size: 0.82rem;
}
.community-tabs input[type="radio"]:checked + .community-tab {
  background: var(--gradient);
  color: white;
  border-color: transparent;
  box-shadow: 0 8px 16px rgba(26,82,118,0.2);
}
.community-tab-panel {
  display: none;
  padding-top: 2px;
}
.community-tabs input#comunidad-tab-general:checked ~ .community-tab-panel[data-panel="general"] {
  display: block;
}
.community-tabs input#comunidad-tab-representantes:checked ~ .community-tab-panel[data-panel="representantes"] {
  display: block;
}
.community-tab-panel hr {
  border-color: #e8eef4;
}
.community-tab-panel h6 {
  color: var(--title);
  font-weight: 700;
}
