@import './general.css';

/**
 * Estilos Modernos y Exclusivos para el Módulo de Gestión de Linaje (TKD Pro Manager)
 * Nivel de Acceso: 4+ (Jefe de Grupo, Maestro, Administrador)
 */

:root {
  --bg-body: #F8FAFC;
  --bg-surface: #FFFFFF;
  --text-main: #0F172A;
  --text-muted: #64748B;
  --border-color: #E2E8F0;
  --accent-blue: #2563EB;
  --accent-green: #16A34A;
  --accent-amber: #D97706;
  --danger-text: #DC2626;
  --radius-md: 16px;
  --radius-lg: 20px;
  --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
}

body {
  font-family: 'Outfit', -apple-system, BlinkMacSystemFont, sans-serif;
  background-color: var(--bg-body);
  color: var(--text-main);
  margin: 0;
  padding: 0;
  min-height: 100vh;
}

/* Navbar Header */
.navbar {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 100;
}

.navbar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--text-main);
  font-weight: 800;
  font-size: 1.15rem;
}

.navbar-brand img {
  height: 36px;
}

.navbar-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

/* App Container */
.app-container {
  max-width: 1320px;
  margin: 0 auto;
  padding: 1.5rem;
}

/* Page Header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.page-title-group h1 {
  font-size: 1.5rem;
  font-weight: 800;
  margin: 0;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-title-group p {
  margin: 4px 0 0 0;
  color: var(--text-muted);
  font-size: 0.88rem;
}

/* Toolbar de Linaje y Switch de Orientación */
.linaje-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 1.25rem;
}

.orientation-switch-container {
  display: flex;
  align-items: center;
  gap: 8px;
}

.switch-label {
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text-muted);
}

.orientation-switch {
  display: inline-flex;
  background: #E2E8F0;
  padding: 3px;
  border-radius: 10px;
  gap: 2px;
}

.switch-btn {
  border: none;
  background: transparent;
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 0.82rem;
  font-weight: 700;
  color: #475569;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

.switch-btn:hover {
  color: #0F172A;
}

.switch-btn.active {
  background: #FFFFFF;
  color: var(--accent-blue);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
}

/* Tree Canvas Container */
.tree-canvas-wrapper {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem;
  box-shadow: var(--shadow-md);
  overflow-x: auto;
  overflow-y: auto;
  min-height: 500px;
}

/* Hierarchy CSS Tree System - Modo Vertical (Conectores T-Bar en Organigrama Clásico) */
.tree-root-container {
  display: flex;
  flex-direction: column;
  gap: 3rem;
  align-items: center;
}

.tree-branch {
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  padding: 0;
}

/* 1. Línea vertical descendiente desde la tarjeta del padre hacia el riel horizontal */
.tree-branch.has-children:not(.branch-collapsed)>.tree-node-card::after {
  content: '';
  position: absolute;
  bottom: -24px;
  left: 50%;
  width: 2px;
  height: 24px;
  background: #94A3B8;
  transform: translateX(-50%);
  z-index: 2;
}

:root {
  --tree-children-gap: 1.5rem;
}

/* 2. Contenedor de hijos separado a 48px de la tarjeta padre */
.tree-children {
  display: flex;
  justify-content: center;
  gap: var(--tree-children-gap);
  position: relative;
  margin-top: 48px;
  padding-top: 0;
}

/* Desactivar pseudo-elemento legacy en .tree-children::before */
.tree-children::before {
  display: none;
}

/* 3. Línea vertical ascendente desde cada tarjeta hija hacia el riel horizontal */
.tree-children>.tree-branch::before {
  content: '';
  position: absolute;
  top: -24px;
  left: 50%;
  width: 2px;
  height: 24px;
  background: #94A3B8;
  transform: translateX(-50%);
  z-index: 2;
}

/* 4. Riel horizontal continuo que une a todos los hermanos cubriendo los gaps */
.tree-children>.tree-branch:not(:only-child)::after {
  content: '';
  position: absolute;
  top: -24px;
  height: 2px;
  background: #94A3B8;
  z-index: 1;
}

/* Para el primer hermano: arranca en su centro y se extiende a la derecha cubriendo el gap */
.tree-children>.tree-branch:first-child:not(:only-child)::after {
  left: 50%;
  right: calc(-1 * var(--tree-children-gap));
  width: auto;
}

/* Para el último hermano: arranca cubriendo el gap izquierdo y termina en su centro */
.tree-children>.tree-branch:last-child:not(:only-child)::after {
  left: calc(-1 * var(--tree-children-gap));
  right: 50%;
  width: auto;
}

/* Para hermanos intermedios: cubre de extremo a extremo cubriendo ambos gaps */
.tree-children>.tree-branch:not(:first-child):not(:last-child)::after {
  left: calc(-1 * var(--tree-children-gap));
  right: calc(-1 * var(--tree-children-gap));
  width: auto;
}

/* Botón de Colapsar / Expandir Rama (Opción 4) */
.tree-branch.branch-collapsed>.tree-children {
  display: none !important;
}

.tree-branch-toggle-btn {
  position: absolute;
  bottom: -13px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  background: #0F172A;
  color: #FFFFFF;
  border: 2px solid #FFFFFF;
  border-radius: 12px;
  padding: 1px 9px;
  font-size: 0.72rem;
  font-weight: 800;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(15, 23, 42, 0.3);
  display: flex;
  align-items: center;
  gap: 4px;
  transition: all 0.2s ease;
  white-space: nowrap;
}

.tree-branch-toggle-btn:hover {
  background: var(--accent-blue);
  transform: translateX(-50%) scale(1.08);
}

/* Modo Horizontal para el Árbol Jerárquico (De Izquierda a Derecha) */
.tree-canvas-wrapper.horizontal-mode .tree-root-container {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
  align-items: flex-start;
}

.tree-canvas-wrapper.horizontal-mode .tree-branch {
  display: flex;
  flex-direction: row;
  align-items: center;
  position: relative;
  padding: 0;
}

.tree-canvas-wrapper.horizontal-mode .tree-branch.has-children:not(.branch-collapsed)>.tree-node-card::after {
  content: '';
  position: absolute;
  right: -24px;
  top: 50%;
  bottom: auto;
  left: auto;
  width: 24px;
  height: 2px;
  background: #94A3B8;
  transform: translateY(-50%);
  z-index: 2;
}

.tree-canvas-wrapper.horizontal-mode .tree-children {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: var(--tree-children-gap);
  position: relative;
  margin-top: 0;
  padding-top: 0;
  margin-left: 48px;
  padding-left: 0;
}

.tree-canvas-wrapper.horizontal-mode .tree-children::before {
  display: none;
}

.tree-canvas-wrapper.horizontal-mode .tree-children>.tree-branch::before {
  content: '';
  position: absolute;
  left: -24px;
  top: 50%;
  width: 24px;
  height: 2px;
  background: #94A3B8;
  transform: translateY(-50%);
  z-index: 2;
}

.tree-canvas-wrapper.horizontal-mode .tree-children>.tree-branch:not(:only-child)::after {
  content: '';
  position: absolute;
  left: -24px;
  width: 2px;
  background: #94A3B8;
  z-index: 1;
}

.tree-canvas-wrapper.horizontal-mode .tree-children>.tree-branch:first-child:not(:only-child)::after {
  top: 50%;
  bottom: calc(-1 * var(--tree-children-gap));
  height: auto;
}

.tree-canvas-wrapper.horizontal-mode .tree-children>.tree-branch:last-child:not(:only-child)::after {
  top: calc(-1 * var(--tree-children-gap));
  bottom: 50%;
  height: auto;
}

.tree-canvas-wrapper.horizontal-mode .tree-children>.tree-branch:not(:first-child):not(:last-child)::after {
  top: calc(-1 * var(--tree-children-gap));
  bottom: calc(-1 * var(--tree-children-gap));
  height: auto;
}

.tree-canvas-wrapper.horizontal-mode .tree-branch-toggle-btn {
  bottom: auto;
  right: -13px;
  left: auto;
  top: 50%;
  transform: translateY(-50%);
}

/* Card de Linaje Colapsable / Expandible */
.tree-node-card {
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  border-radius: 14px;
  width: 145px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.06);
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  position: relative;
  overflow: visible;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  user-select: none;
}

.tree-node-card:hover {
  border-color: var(--accent-blue);
  box-shadow: 0 4px 16px rgba(37, 99, 235, 0.18);
}

.tree-node-card.expanded {
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.2);
  border-color: var(--accent-blue);
}

/* Header de Foto Principal (Compacta 120px) */
.card-photo-header {
  position: relative;
  width: 100%;
  height: 120px;
  background: #1E293B;
  overflow: hidden;
  border-top-left-radius: 13px;
  border-top-right-radius: 13px;
}

.card-photo-header img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center top;
}

/* Badge de Grado / Dan (Esquina Superior Derecha) */
.card-grade-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  font-size: 0.62rem;
  font-weight: 400;
  padding: 2px 6px;
  border-radius: 6px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  letter-spacing: 0px;
  z-index: 2;
}

/* Overlay Gradiente con Título Honorífico en la Foto */
.card-name-overlay {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 14px 4px 4px 4px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0) 0%, rgba(15, 23, 42, 0.8) 60%, rgba(15, 23, 42, 0.95) 100%);
  color: #FFFFFF;
  text-align: center;
  z-index: 1;
}

.card-titulo-honorifico {
  font-size: 0.7rem;
  font-weight: 400;
  color: #F8FAFC;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Franja Divisora de Cinturón */
.linaje-belt-stripe {
  height: 4px;
  width: 100%;
}

/* Bloque Limpio de Nombre y Apellido Debajo de la Foto (Estilo Alumnos) */
.linaje-card-info-clean {
  padding: 6px 6px 2px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  background: #FFFFFF;
}

.linaje-card-name-bold {
  font-size: 0.82rem;
  font-weight: 900;
  color: #0F172A;
  text-transform: uppercase;
  line-height: 1.15;
  word-break: break-word;
}

.linaje-card-surname-light {
  font-size: 0.72rem;
  font-weight: 600;
  color: #475569;
  text-transform: uppercase;
  line-height: 1.15;
  word-break: break-word;
}

/* Nivel Debajo del Nombre */
.linaje-card-nivel-tag {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-blue);
  background: #EFF6FF;
  padding: 3px 4px;
  margin: 3px 6px 6px 6px;
  border-radius: 6px;
  text-align: center;
  border: 1px solid #DBEAFE;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Detalle Desplegable al Clic (Oculto cuando contraída) */
.linaje-card-details {
  max-height: 0;
  opacity: 0;
  overflow: hidden;
  transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  padding: 0 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: #F8FAFC;
}

.tree-node-card.expanded .linaje-card-details {
  max-height: 120px;
  opacity: 1;
  padding: 6px 6px;
  border-top: 1px solid #E2E8F0;
}

.card-stats-row {
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text-main);
  background: #FFFFFF;
  padding: 4px 5px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.card-action-pencil {
  width: 28px;
  height: 28px;
  margin: 2px auto 0 auto;
  border-radius: 8px;
  background: #FFFFFF;
  border: 1px solid var(--border-color);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.85rem;
  transition: all 0.2s ease;
}

.card-action-pencil:hover {
  background: var(--accent-blue);
  color: #FFFFFF;
  border-color: var(--accent-blue);
  transform: scale(1.08);
}

/* Modales */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(15, 23, 42, 0.6);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-overlay.active {
  display: flex;
}

.modal-container {
  background: var(--bg-surface);
  border-radius: var(--radius-lg);
  width: 100%;
  box-shadow: var(--shadow-md);
  animation: modalSlideUp 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  overflow: hidden;
}

@keyframes modalSlideUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }

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

.form-group {
  margin-bottom: 1rem;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
}

.form-control {
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  font-size: 0.9rem;
  outline: none;
  font-family: inherit;
}

.form-control:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.btn {
  padding: 0.6rem 1.25rem;
  font-weight: 700;
  font-size: 0.9rem;
  border-radius: 10px;
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-decoration: none;
  transition: opacity 0.15s ease;
}

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

.btn-secondary {
  background: #F1F5F9;
  color: var(--text-main);
  border: 1px solid var(--border-color);
}

.btn-danger {
  background: #FEE2E2;
  color: #DC2626;
}

.btn:hover {
  opacity: 0.9;
}