/* ============================================================
   Organigrama Policial - Estilos
   Inspirado en Notion: limpio, tipografía Inter, bordes sutiles
   ============================================================ */

/* ---------- Reset & Base ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-bg: #ffffff;
  --color-surface: #ffffff;
  --color-border: #e5e5e5;
  --color-border-hover: #cfcfcf;
  --color-text: #37352f;
  --color-text-secondary: #6b6b6b;
  --color-text-muted: #9b9a97;
  --color-accent: #2383e2;
  --color-accent-light: #e8f0fe;
  --color-badge-bg: #f1f1ef;
  --color-badge-text: #5a5a5a;
  --color-overlay: rgba(15, 15, 15, 0.6);
  --color-whatsapp: #25d366;
  --color-card-shadow: rgba(15, 15, 15, 0.05);
  --color-card-shadow-hover: rgba(15, 15, 15, 0.1);
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --transition-fast: 150ms ease;
  --transition-normal: 250ms ease;
  --max-width: 1200px;
}

html {
  scroll-behavior: smooth;
}

body {
  font-family: var(--font-family);
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.mobile-only-br {
  display: none;
}

/* ---------- Hero Header ---------- */
.hero-header {
  position: relative;
  overflow: hidden;
  margin-bottom: 0;
}

.hero-gradient {
  height: 200px;
  background-image: url('degradee.png');
  background-size: cover;
  background-position: center;
  position: relative;
}

.hero-gradient::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: linear-gradient(transparent, var(--color-bg));
}

.hero-content {
  position: relative;
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 40px;
  margin-top: -80px;
}

.hero-icon {
  width: 100px;
  height: 100px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
}

.hero-logo {
  width: 100%;
  height: 100%;
  object-fit: contain;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, 0.15));
}

.hero-title {
  font-size: 3.5rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  color: var(--color-text);
  line-height: 1.1;
  margin-bottom: 8px;
}

.hidden-admin-link {
  color: inherit;
  text-decoration: none;
  cursor: default;
}

.hidden-admin-link:hover {
  color: inherit;
}

/* ---------- Navigation Buttons ---------- */
.nav-actions {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 40px;
  display: flex;
  gap: 12px;
  margin-top: 24px;
}

.secondary-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  text-decoration: none;
  transition: all var(--transition-fast);
  cursor: pointer;
}

.secondary-btn:hover {
  border-color: var(--color-border-hover);
  background: var(--color-badge-bg);
  color: var(--color-text);
  transform: translateY(-1px);
}

.secondary-btn svg {
  color: var(--color-accent);
}

.hero-subtitle {
  font-size: 1.1rem;
  color: var(--color-text-secondary);
  font-weight: 400;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--color-border);
}

/* ---------- Search ---------- */
.search-container {
  max-width: var(--max-width);
  margin: 24px auto 8px;
  padding: 0 40px;
}

.search-box {
  position: relative;
  max-width: 480px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--color-text-muted);
  pointer-events: none;
}

.search-box input {
  width: 100%;
  padding: 10px 40px 10px 40px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  font-family: var(--font-family);
  font-size: 0.9rem;
  color: var(--color-text);
  background: var(--color-surface);
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.search-box input::placeholder {
  color: var(--color-text-muted);
}

.search-box input:focus {
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px var(--color-accent-light);
}

.search-clear {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: 50%;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-fast), background var(--transition-fast);
}

.search-clear:hover {
  background: var(--color-badge-bg);
  color: var(--color-text);
}

.search-clear.active {
  opacity: 1;
  pointer-events: auto;
}

/* ---------- Main Content ---------- */
.main-content {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px 40px 60px;
}

/* ---------- Loading Spinner ---------- */
.loading-spinner {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 80px 0;
  color: var(--color-text-muted);
  font-size: 0.95rem;
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--color-border);
  border-top: 3px solid var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

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

.loading-spinner.hidden {
  display: none;
}

/* ---------- Section ---------- */
.org-section {
  margin-bottom: 40px;
  animation: fadeInUp 0.4s ease both;
}

.org-section:nth-child(2) {
  animation-delay: 0.05s;
}

.org-section:nth-child(3) {
  animation-delay: 0.1s;
}

.org-section:nth-child(4) {
  animation-delay: 0.15s;
}

.org-section:nth-child(5) {
  animation-delay: 0.2s;
}

.org-section:nth-child(6) {
  animation-delay: 0.25s;
}

.org-section:nth-child(7) {
  animation-delay: 0.3s;
}

.org-section:nth-child(8) {
  animation-delay: 0.35s;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(12px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Section header (toggle) */
.section-header {
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  padding: 16px 24px;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: 0 2px 8px var(--color-card-shadow);
  user-select: none;
  margin-bottom: 0;
  position: relative;
  z-index: 2;
  transition: all var(--transition-normal);
}

.section-header:hover {
  border-color: var(--color-border-hover);
  box-shadow: 0 6px 16px var(--color-card-shadow-hover);
  transform: translateY(-2px);
}

.section-header:hover .section-title {
  color: var(--color-text);
}

.section-toggle {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--color-text-secondary);
  transition: transform var(--transition-normal), background var(--transition-fast);
  flex-shrink: 0;
  background: var(--color-badge-bg);
}

.section-toggle.collapsed {
  transform: rotate(-90deg);
}

.section-toggle.collapsed svg {
  transform: translateY(-2px);
  /* Mueve hacia "arriba" el SVG original, lo que es la izquierda al rotarlo -90deg */
}

.section-header:hover .section-toggle {
  background: var(--color-border);
  color: var(--color-text);
}

.section-title {
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--color-text);
  transition: color var(--transition-fast);
}

/* View badge */
.section-view-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--color-badge-bg);
  color: var(--color-badge-text);
  font-size: 0.78rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: var(--radius-sm);
  margin-left: 4px;
}

.section-view-badge svg {
  width: 14px;
  height: 14px;
}

/* Section body */
.section-body {
  position: relative;
  z-index: 1;
  margin-top: -16px;
  padding: 36px 20px 20px 20px;
  background: #fcfcfc;
  border: 1px solid var(--color-border);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  box-shadow: 0 4px 12px var(--color-card-shadow);
  overflow: hidden;
  transition: max-height 0.4s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.3s ease, margin-top 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

.section-body.collapsed {
  max-height: 0 !important;
  opacity: 0;
  pointer-events: none;
  margin-top: -40px;
  border-color: transparent;
  box-shadow: none;
}


/* ---------- Cards Grid (Galería) ---------- */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 12px;
}

.org-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 20px;
  cursor: pointer;
  transition: border-color var(--transition-fast), box-shadow var(--transition-normal), transform var(--transition-fast);
  position: relative;
}

.org-card:hover {
  border-color: var(--color-border-hover);
  box-shadow: 0 4px 16px var(--color-card-shadow-hover);
  transform: translateY(-1px);
}

.org-card:active {
  transform: translateY(0);
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 10px;
  line-height: 1.35;
}

.card-rank {
  font-size: 0.82rem;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.card-name {
  font-size: 0.85rem;
  color: var(--color-text);
  margin-bottom: 8px;
}

.card-phone {
  font-size: 0.8rem;
  color: var(--color-text-secondary);
  margin-bottom: 4px;
}

.card-email {
  font-size: 0.8rem;
  color: var(--color-accent);
  text-decoration: none;
  overflow-wrap: anywhere;
  word-break: normal;
  line-height: 1.4;
  display: block;
}

.card-email:hover {
  text-decoration: underline;
}

/* ---------- List View ---------- */
.org-list {
  list-style: none;
}

.org-list-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background var(--transition-fast);
  font-size: 0.9rem;
  color: var(--color-text);
  position: relative;
}

.org-list-item:hover {
  background: var(--color-badge-bg);
}

.org-list-item::before {
  content: '';
  width: 6px;
  height: 6px;
  background: var(--color-border-hover);
  border-radius: 50%;
  flex-shrink: 0;
}

.org-list-item-text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.org-list-item-arrow {
  width: 16px;
  height: 16px;
  color: var(--color-text-muted);
  flex-shrink: 0;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.org-list-item:hover .org-list-item-arrow {
  opacity: 1;
}

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--color-overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  padding: 24px;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  background: var(--color-surface);
  border-radius: var(--radius-xl);
  max-width: 520px;
  width: 100%;
  padding: 48px;
  padding-top: 60px;
  position: relative;
  box-shadow: 0 32px 80px -12px rgba(0, 0, 0, 0.15);
  transform: scale(0.95) translateY(10px);
  transition: transform var(--transition-normal);
  border: 1px solid var(--color-border);
  overflow: hidden;
}

.modal-top-bar {
  height: 14px;
  background: url('degradee.png');
  background-size: cover;
  background-position: center;
  width: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.modal-overlay.active .modal-card {
  transform: scale(1) translateY(0);
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 32px;
  height: 32px;
  border: none;
  background: transparent;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text-muted);
  transition: all var(--transition-fast);
  z-index: 100;
}

.modal-close svg {
  pointer-events: none;
  width: 18px;
  height: 18px;
}

.modal-close:hover {
  background: var(--color-badge-bg);
  color: var(--color-text);
}

.modal-header {
  margin-bottom: 28px;
  padding-bottom: 24px;
  border-bottom: 1px solid #e8e8e8;
}

.modal-title {
  font-size: 2rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
  margin-bottom: 12px;
  letter-spacing: -0.02em;
}

.modal-badge {
  display: inline-block;
  background: #e7f3f8;
  color: #337ea9;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 20px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-field {
  display: flex;
  align-items: center;
  gap: 16px;
}

.modal-field.hidden {
  display: none;
}

.field-icon {
  width: 44px;
  height: 44px;
  background: #f5f5f5;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #8c8c8c;
  flex-shrink: 0;
}

.field-icon-whatsapp {
  background: #dcf8e8;
  color: var(--color-whatsapp);
}

.field-label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #a0a09a;
  margin-bottom: 2px;
}

.field-value {
  display: block;
  font-size: 1.05rem;
  font-weight: 500;
  color: var(--color-text);
  line-height: 1.4;
}

.jerarquia-text {
  display: block;
  font-size: 0.92rem;
  color: var(--color-text-secondary);
  font-weight: 400;
  margin-bottom: 2px;
}

.nombre-text {
  display: block;
  font-size: 1.05rem;
  color: var(--color-text);
  font-weight: 500;
}

.field-link {
  color: var(--color-accent);
  text-decoration: none;
  overflow-wrap: anywhere;
}

.field-link:hover {
  text-decoration: underline;
}

/* ---------- Footer ---------- */
.app-footer {
  text-align: center;
  padding: 32px 40px;
  font-size: 0.8rem;
  color: var(--color-text-muted);
  border-top: 1px solid var(--color-border);
  max-width: var(--max-width);
  margin: 0 auto;
}

/* ---------- No Results ---------- */
.no-results {
  text-align: center;
  padding: 60px 20px;
  color: var(--color-text-muted);
  font-size: 0.95rem;
}

.no-results svg {
  margin-bottom: 16px;
  opacity: 0.4;
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
  .hero-content {
    padding: 0 20px;
    margin-top: -60px;
  }

  .hero-icon {
    width: 64px;
    height: 64px;
  }

  .hero-icon svg {
    width: 36px;
    height: 36px;
  }

  .hero-title {
    font-size: clamp(2.2rem, 10vw, 3rem);
    /* Escala dinámicamente hasta llenar el ancho */
    line-height: 1;
    font-weight: 800;
    letter-spacing: -0.03em;
    margin-bottom: 8px;
  }

  .mobile-only-br {
    display: block;
  }

  .hero-subtitle {
    font-size: 0.95rem;
  }

  .search-container {
    padding: 0 20px;
  }

  .main-content {
    padding: 16px 20px 60px;
  }

  .section-title {
    font-size: 1.2rem;
  }

  .cards-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  .modal-card {
    padding: 56px 24px 24px 24px;
  }

  .modal-title {
    font-size: 1.15rem;
  }

  .app-footer {
    padding: 24px 20px;
  }
}

@media (max-width: 480px) {
  .hero-gradient {
    height: 140px;
  }

  .hero-content {
    margin-top: -50px;
  }

  .hero-title {
    font-size: 1.4rem;
  }

  .section-view-badge {
    display: none;
  }

  .modal-overlay {
    padding: 12px;
  }

  .modal-card {
    padding: 52px 20px 20px 20px;
    border-radius: var(--radius-lg);
  }
}

/* ---------- Table View Styles ---------- */
.table-view-page {
  background: #fdfdfd;
}

.hero-header.mini {
  margin-bottom: 0;
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}

.hero-header.mini .hero-content {
  margin-top: 0;
  padding: 56px 40px 24px 40px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.header-top-nav {
  position: absolute;
  top: 12px;
  left: 40px;
}

.back-link {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--color-text-secondary);
  font-size: 0.8rem;
  text-decoration: none;
  font-weight: 500;
}

.back-link:hover {
  color: var(--color-accent);
}

.hero-icon.small {
  width: 50px;
  height: 50px;
  margin-bottom: 0;
}

.hero-title.small {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0;
}

.table-container-full {
  max-width: var(--max-width);
  margin: 32px auto;
  padding: 0 40px;
  position: relative;
}

.table-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 20px;
}

.results-count {
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.table-wrapper {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  overflow-x: auto;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.02);
  cursor: grab;
  user-select: none;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: var(--color-border) transparent;
  position: relative;
  scroll-behavior: auto !important;
}

.table-wrapper:active,
.table-wrapper.active-dragging {
  cursor: grabbing;
  scroll-behavior: auto !important;
}

/* Scrollbar estética estilo Notion */
.table-wrapper::-webkit-scrollbar {
  height: 8px;
  width: 8px;
}

.table-wrapper::-webkit-scrollbar-track {
  background: transparent;
}

.table-wrapper::-webkit-scrollbar-thumb {
  background: var(--color-border);
  border-radius: 10px;
}

.table-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--color-border-hover);
}

.notion-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  white-space: nowrap;
}

.notion-table th {
  background: #f7f7f5;
  text-align: left;
  padding: 8px 12px;
  border-bottom: 1px solid var(--color-border);
  color: var(--color-text-secondary);
  font-weight: 500;
}

.th-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

.notion-table td {
  padding: 12px;
  border-bottom: 1px solid #f1f1f1;
}

.notion-table tbody tr:nth-child(even) {
  background-color: #f6f6f5;
}

.notion-table tr:last-child td {
  border-bottom: none;
}

.notion-table tr:hover td {
  background-color: #f0f0ee;
}

.table-badge {
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 500;
  font-size: 0.75rem;
}

.badge-purple {
  background: #f5ebfa;
  color: #a15bcc;
}

.badge-yellow {
  background: #fbfae5;
  color: #dfab01;
}

.badge-blue {
  background: #e7f3f8;
  color: #337ea9;
}

.badge-red {
  background: #fdebec;
  color: #eb5757;
}

.badge-green {
  background: #edf3ec;
  color: #448361;
}

.badge-gray {
  background: #f1f1ef;
  color: #787774;
}

.table-link {
  color: var(--color-accent);
  text-decoration: none;
}

.table-link:hover {
  text-decoration: underline;
}

.loading-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255, 255, 255, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10;
  min-height: 200px;
}

.no-data {
  text-align: center;
  padding: 40px !important;
  color: var(--color-text-muted);
}



@media (max-width: 768px) {
  .hero-header.mini .hero-content {
    padding: 20px;
    flex-direction: column;
    align-items: flex-start;
    gap: 12px;
  }

  .header-top-nav {
    position: static;
  }

  .table-container-full {
    padding: 0 10px;
    margin: 16px auto;
  }

  .table-controls {
    flex-direction: column;
    align-items: flex-start;
  }

  .org-section {
    margin-bottom: 20px;
  }

  .section-header {
    margin-bottom: 8px;
    padding: 12px 16px;
  }
}