:root {
    --primary: #2f7d3c;
    --primary-dark: #235c2c;
    --bg: #f4f6f4;
    --card-bg: #ffffff;
    --border: #dfe3df;
    --text: #22291f;
    --muted: #6b7568;
    --danger: #c0392b;
    --warning: #b8860b;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.app-layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 230px;
    flex-shrink: 0;
    background: var(--primary);
    color: #fff;
    padding: 1.25rem 1rem;
    display: flex;
    flex-direction: column;
    gap: 1.1rem;
    position: sticky;
    top: 0;
    align-self: flex-start;
    height: 100vh;
    overflow-y: auto;
}
.brand { color: #fff; text-decoration: none; font-weight: 700; font-size: 1.15rem; display: block; flex: 1; }
/* Escritorio: el logo completo, lo más grande que permite el ancho del menú,
   sobre un panel blanco para que no se funda con el verde. */
.brand-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: #fff;
    border-radius: 12px;
    padding: 0.3rem;
}
.brand-logo-lg { width: 100%; height: auto; display: block; }
/* Celular: el menú es una barra delgada arriba, ahí va la versión compacta. */
.brand-compact { display: none; align-items: center; gap: 0.5rem; }
.brand-logo {
    width: 44px;
    height: 44px;
    flex-shrink: 0;
    padding: 2px;
    background: #fff;
    border-radius: 50%;
}
@media (max-width: 720px) {
    .brand-panel { display: none; }
    .brand-compact { display: inline-flex; }
}
/* Login / Crear cuenta: el logo va afuera y arriba de la tarjeta. */
.login-logo { display: block; width: 320px; max-width: 80%; height: auto; margin: 0 auto 1.25rem; }

.sidebar-user {
    font-size: 0.85rem;
    opacity: 0.9;
    border-top: 1px solid rgba(255, 255, 255, 0.2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.75rem 0;
}
.sidebar-user-meta { opacity: 0.85; margin-top: 0.2rem; }

.impersonate-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
}

.sidebar-nav { display: flex; flex-direction: column; gap: 0.15rem; }
.sidebar-nav a {
    display: flex;
    align-items: center;
    color: #fff;
    text-decoration: none;
    opacity: 0.92;
    padding: 0.55rem 0.6rem;
    border-radius: 8px;
    font-size: 0.95rem;
}
.sidebar-nav a:hover { background: rgba(255, 255, 255, 0.14); opacity: 1; }

/* Enlace de la página en la que el usuario está parado: antes solo cambiaba
   un poco el tono de fondo (translúcido sobre el verde del sidebar) y no se
   notaba lo suficiente. Ahora usa el mismo criterio que ya se usó para las
   pestañas de grupo del inventario: color sólido y de alto contraste
   (blanco sobre verde), no solo un tinte, más un "✓" y ligero relieve. */
.sidebar-nav a.is-active {
    background: #fff;
    color: var(--primary-dark);
    opacity: 1;
    font-weight: 700;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.28);
}
.sidebar-nav a.is-active::before {
    content: "✓";
    margin-right: 0.4rem;
    font-weight: 700;
}
.sidebar-nav a.is-active:hover { background: #fff; }

.sidebar-nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    margin-right: 0.5rem;
    font-size: 1.05rem;
    flex-shrink: 0;
}

.sidebar-nav-top { font-weight: 600; }

/* Antes eran <details>/<summary> plegables; como siempre se mostraban
   abiertas, el triángulo de "colapsar" solo confundía (un clic sin querer
   ocultaba todo un módulo). Ahora son bloques fijos, siempre visibles. */
.sidebar-nav-group {
    margin-top: 0.6rem;
    background: rgba(255, 255, 255, 0.1);
    border-left: 3px solid rgba(255, 255, 255, 0.55);
    border-radius: 0 8px 8px 0;
    padding: 0.3rem 0.4rem 0.6rem;
}
.sidebar-nav-group-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-weight: 700;
    opacity: 0.85;
    padding: 0.2rem 0.2rem 0.2rem 0;
    margin: 0 0 0.15rem 0.6rem;
}
.sidebar-nav-sub {
    padding-left: 0.6rem !important;
    font-size: 0.9rem;
    margin-top: 0.15rem;
}

/* padding-bottom deja espacio libre para que el botón flotante de
   "Regresar al Menú Principal" no tape los últimos botones de la página al
   hacer scroll hasta abajo. */
.container { flex: 1; min-width: 0; max-width: 960px; margin: 2rem auto; padding: 0 1.25rem 4.5rem; }
@media (max-width: 720px) {
    /* En celular el menú va arriba (flex en columna) y los márgenes auto
       impedían que el contenido tomara el ancho de la pantalla: una tabla
       ancha ensanchaba toda la página en vez de deslizarse en su recuadro. */
    .container { width: 100%; }
}

.sidebar-top { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; }
.sidebar-toggle {
    display: none;
    align-items: center;
    gap: 0.4rem;
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 0.4rem 0.7rem;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
}
.sidebar-toggle-icon { font-size: 1.1rem; line-height: 1; }

/* Computadora: el logo y el usuario quedan fijos arriba; solo la lista de
   opciones se desplaza cuando no cabe en la pantalla. */
@media (min-width: 721px) {
    .sidebar { overflow: hidden; }
    .sidebar-body { flex: 1; min-height: 0; display: flex; flex-direction: column; gap: 1.1rem; }
    .sidebar-nav { flex: 1; min-height: 0; overflow-y: auto; margin: 0 -0.5rem; padding: 0.3rem 0.5rem 0.6rem; }
}

/* Opción 2: en móvil el sidebar se vuelve una barra sticky (siempre visible arriba,
   sin importar el scroll) con la navegación colapsada detrás de un botón tipo
   "hamburguesa" — evita que el menú tape toda la pantalla pero sigue siempre
   alcanzable con un solo toque, sin tener que subir hasta el inicio de la página. */
@media (max-width: 720px) {
    .app-layout { flex-direction: column; }
    .sidebar {
        width: 100%;
        height: auto;
        position: sticky;
        top: 0;
        z-index: 40;
        box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
        gap: 0;
    }
    .sidebar-toggle { display: flex; }
    .sidebar-body { display: none; }
    .sidebar.is-open .sidebar-body { display: block; margin-top: 1rem; }
}

@media (max-width: 480px) {
    .container { padding: 0 0.75rem 4rem; margin: 1rem auto; }
    .card { padding: 1rem; }
    h1 { font-size: 1.2rem; }
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}
.card-narrow { max-width: 440px; margin-left: auto; margin-right: auto; }
.card-header { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.6rem; }

.link-volver {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 0.8rem;
}
.link-volver:hover { color: var(--primary-dark); text-decoration: underline; }

h1 { margin-top: 0; font-size: 1.4rem; }
h2 { font-size: 1.1rem; margin-top: 2rem; }

label { display: block; margin: 0.9rem 0 0.3rem; font-size: 0.9rem; font-weight: 600; }

/* Opción "+ Agregar/Nueva..." dentro de un <select>, para que se note
   distinta de las opciones normales del catálogo (crear un elemento
   nuevo sin salir de la pantalla). */
.option-agregar { font-weight: 700; color: var(--primary-dark); background-color: #eaf4ec; }

/* Marca notoriamente el selector de "misma fecha para todos" cuando esa
   opción está activa, para que sea obvio que esa es la fecha que se va
   a usar (Bajas Grupales). */
.fecha-compartida-activa {
    border-color: var(--primary) !important;
    background: #eaf7ec;
    box-shadow: 0 0 0 3px rgba(47, 125, 60, 0.25);
    font-weight: 700;
}

/* Tooltip que explica por qué el campo de fecha de una fila no se puede
   editar mientras "Misma fecha para todos" está activa. */
.fecha-tip {
    position: fixed;
    z-index: 60;
    max-width: 260px;
    background: var(--text);
    color: #fff;
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    font-size: 0.82rem;
    line-height: 1.35;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

/* Panel de filtros con recuadro propio y cada campo con su label
   visible encima, para que se note claramente que son filtros y no
   parte del contenido de la tabla. */
.filtros-box {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.9rem 1.2rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.9rem 1rem;
    margin: 0.7rem 0 1.3rem;
}
.filtros-box-title {
    flex-basis: 100%;
    font-weight: 700;
    font-size: 0.85rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.filtro-campo { display: flex; flex-direction: column; min-width: 170px; }
.filtro-campo label { margin: 0 0 0.3rem; font-size: 0.85rem; }
.filtro-campo select, .filtro-campo input { width: auto; min-width: 170px; }
/* Botón (p. ej. "Ver todos") en el panel de filtros: tamaño de botón, alineado con los campos. */
.filtro-campo-boton { min-width: 0; }
.filtros-box .filtro-campo .btn { align-self: flex-start; margin: 0; padding: 0.55rem 1rem; font-size: 0.95rem; border-color: var(--primary); color: var(--primary-dark); white-space: nowrap; }
.filtros-box .filtro-campo .btn:hover { background: var(--primary); color: #fff; }

input, select, textarea {
    width: 100%;
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
}

.btn {
    display: inline-block;
    padding: 0.55rem 1rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: #fff;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    font-size: 0.95rem;
}
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
form .btn { margin-top: 1.2rem; margin-right: 0.4rem; }

.btn-sm { padding: 0.3rem 0.7rem; font-size: 0.85rem; }
.btn-editar { border-color: var(--primary); color: var(--primary-dark); white-space: nowrap; }
.btn-editar:hover { background: var(--primary); color: #fff; }
.btn.btn-editar, .btn.btn-aviso { margin-top: 0; margin-bottom: 0; }
.btn-aviso { margin-left: 0.5rem; white-space: nowrap; }
.acciones-fila { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.acciones-fila form { display: inline; margin: 0; }
.acciones-fila .btn { margin: 0; white-space: nowrap; }

/* Enlaces de texto (aretes, folios): en negritas del color del texto; se subrayan al pasar el mouse. */
:where(.container) a:not([class]) { color: var(--text); text-decoration: none; font-weight: 600; }
:where(.container) a:not([class]):hover { color: var(--primary-dark); text-decoration: underline; }
.acciones-tabla { display: flex; flex-direction: column; align-items: stretch; gap: 0.35rem; }
.acciones-tabla form { margin: 0; }
.acciones-tabla .btn { display: block; width: 100%; margin: 0; text-align: center; white-space: nowrap; }

.alert { padding: 0.75rem 1rem; border-radius: 6px; margin-bottom: 1rem; font-size: 0.95rem; }
.alert-error { background: #fdecea; color: var(--danger); border: 1px solid #f5c6c1; }
.alert-success { background: #eaf7ec; color: var(--primary-dark); border: 1px solid #c8e6cb; }
.alert-info { background: #eaf2fb; color: #2c5d8f; border: 1px solid #c7dcf2; }
.alert-aviso { background: #fdf3e0; color: #8a5a00; border: 1px solid #f0d9a6; }

.muted { color: var(--muted); font-size: 0.9rem; }
.text-danger { color: var(--danger); font-weight: 600; }

.label-row { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin: 0.9rem 0 0.3rem; }
.label-row label { margin: 0; }
.label-row .btn { margin-top: 0; }

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    z-index: 100;
}
.modal-backdrop[hidden] { display: none; }
.modal {
    background: var(--card-bg);
    border-radius: 10px;
    padding: 1.5rem;
    width: 100%;
    max-width: 380px;
    max-height: 90vh;
    overflow-y: auto;
}
.modal h2 { margin-top: 0; font-size: 1.1rem; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.2rem; }
.modal-actions .btn { margin-top: 0; }

.foto-grande-backdrop { cursor: zoom-out; }
.foto-grande {
    max-width: 90vw;
    max-height: 90vh;
    display: block;
    border-radius: 10px;
    cursor: default;
}
.foto-grande-cerrar {
    position: absolute;
    top: 1rem;
    right: 1.2rem;
    background: rgba(0, 0, 0, 0.55);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 2.2rem;
    height: 2.2rem;
    font-size: 1.3rem;
    line-height: 1;
    cursor: pointer;
}

.parto-grupo-a { background: #eaf7ec; }
.parto-grupo-b { background: #eaf2fb; }
th.parto-grupo-a, th.parto-grupo-b { text-align: center; }
.parto-inicio { border-left: 2px solid var(--border); }

.input-con-prefijo { position: relative; }
.input-con-prefijo .prefijo {
    position: absolute;
    left: 0.7rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}
.input-con-prefijo input { padding-left: 1.6rem; }

.intervalo-col { text-align: center; background: #fdf3e2; vertical-align: middle; }
th.intervalo-col { color: #8a6414; font-size: 0.82rem; }
.intervalo-visual { display: flex; flex-direction: column; align-items: center; gap: 0.05rem; line-height: 1.15; }
.intervalo-visual .intervalo-arrow { font-size: 1.1rem; color: var(--warning); }
.intervalo-visual .intervalo-dias { font-size: 1.1rem; color: #8a6414; }
.intervalo-visual .intervalo-unidad { font-size: 0.68rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.04em; }

/* Árbol genealógico (ficha del animal): árbol clásico con conectores en CSS puro. */
.arbol-genealogico { padding: 1rem 0.5rem; min-width: max-content; }
.arbol-genealogico ul {
    padding-top: 20px;
    position: relative;
    display: flex;
    justify-content: center;
    margin: 0;
}
.arbol-genealogico li {
    list-style-type: none;
    position: relative;
    padding: 20px 12px 0 12px;
    text-align: center;
}
.arbol-genealogico li::before,
.arbol-genealogico li::after {
    content: '';
    position: absolute;
    top: 0;
    right: 50%;
    width: 50%;
    height: 20px;
    border-top: 2px solid var(--border);
}
.arbol-genealogico li::after {
    right: auto;
    left: 50%;
    border-left: 2px solid var(--border);
}
.arbol-genealogico li:only-child { padding-top: 0; }
.arbol-genealogico li:only-child::before,
.arbol-genealogico li:only-child::after { display: none; }
.arbol-genealogico li:first-child::before { border: none; }
.arbol-genealogico li:last-child::after { border: none; }
.arbol-genealogico li:last-child::before {
    border-right: 2px solid var(--border);
    border-radius: 0 6px 0 0;
}
.arbol-genealogico li:first-child::after {
    border-radius: 6px 0 0 0;
}
.arbol-genealogico ul ul::before {
    content: '';
    position: absolute;
    top: 0;
    left: 50%;
    width: 0;
    height: 20px;
    border-left: 2px solid var(--border);
}
.arbol-genealogico .nodo-animal {
    display: inline-block;
    padding: 0.45rem 0.8rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    text-decoration: none;
    color: var(--text);
    font-size: 0.85rem;
    font-weight: 600;
    white-space: nowrap;
}
.arbol-genealogico a.nodo-animal:hover { border-color: var(--primary); color: var(--primary-dark); }
.arbol-genealogico .nodo-hembra { border-left: 3px solid #c2549a; }
.arbol-genealogico .nodo-macho { border-left: 3px solid #2f6fa3; }
.arbol-genealogico .nodo-desconocido { color: var(--muted); font-weight: 400; font-style: italic; background: var(--bg); }
.arbol-genealogico .nodo-contenido { display: inline-block; }
.arbol-genealogico .btn-crear-ancestro { display: block; margin: 0.3rem auto 0; }
.arbol-genealogico .nodo-rol {
    font-size: 0.65rem;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    margin-bottom: 0.2rem;
    white-space: nowrap;
}

/* Copia invertida (ancestros arriba, animal abajo): se voltea el árbol completo y luego se
   voltea cada tarjeta de vuelta, para que las líneas queden invertidas pero el texto se lea normal. */
.arbol-genealogico-invertido { transform: scaleY(-1); }
.arbol-genealogico-invertido .nodo-contenido { transform: scaleY(-1); }

/* Copia horizontal (animal a la izquierda, ancestros hacia la derecha): mismo patrón de
   conectores que la vertical, con los ejes intercambiados (padding-left en vez de padding-top,
   border-left en vez de border-top y viceversa). */
.arbol-genealogico-horizontal.arbol-genealogico { min-width: 0; }
.arbol-genealogico-horizontal ul {
    padding-top: 0;
    padding-left: 24px;
    flex-direction: column;
}
.arbol-genealogico-horizontal li {
    padding: 10px 0 10px 24px;
    text-align: left;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}
.arbol-genealogico-horizontal li::before,
.arbol-genealogico-horizontal li::after {
    top: auto;
    right: auto;
    left: 0;
    bottom: 50%;
    width: 24px;
    height: 50%;
    border-top: none;
    border-left: 2px solid var(--border);
}
.arbol-genealogico-horizontal li::after {
    bottom: auto;
    top: 50%;
    border-left: 2px solid var(--border);
    border-top: 2px solid var(--border);
}
.arbol-genealogico-horizontal li:only-child { padding-left: 0; }
.arbol-genealogico-horizontal li:last-child::before {
    border-right: none;
    border-bottom: 2px solid var(--border);
    border-radius: 0 0 0 6px;
}
.arbol-genealogico-horizontal li:first-child::after {
    border-radius: 6px 0 0 0;
}
.arbol-genealogico-horizontal ul ul::before {
    top: 50%;
    left: 0;
    width: 24px;
    height: 0;
    border-left: none;
    border-top: 2px solid var(--border);
}
.arbol-genealogico-horizontal .nodo-contenido { text-align: center; }

.table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
.table th, .table td { text-align: left; padding: 0.6rem 0.5rem; border-bottom: 1px solid var(--border); font-size: 0.92rem; }
.table th { color: var(--muted); font-weight: 600; }
.table th.th-num, .table td.td-num { text-align: center; padding-left: 0.3rem; padding-right: 0.3rem; }
.table th.th-num { font-size: 0.8rem; line-height: 1.2; }

.fila-filtros td { padding: 0.3rem 0.5rem; background: var(--bg); }
.fila-filtros input.col-filter,
.fila-filtros input.col-filter-num,
.fila-filtros select.col-filter-select {
    width: 100%;
    padding: 0.3rem 0.5rem;
    font-size: 0.8rem;
    border: 1px solid var(--border);
    border-radius: 5px;
}
.table th a { color: var(--muted); text-decoration: none; }
.table th a:hover { color: var(--primary-dark); text-decoration: underline; }
.table th.th-sortable { cursor: pointer; user-select: none; white-space: nowrap; }
.table th.th-sortable:hover { color: var(--text); }
.table th.th-sortable .sort-arrow { color: var(--primary-dark); }

.badge { display: inline-block; padding: 0.15rem 0.55rem; border-radius: 999px; background: #eef1ee; color: var(--text); font-size: 0.8rem; }
.badge + .badge { margin-left: 0.35rem; }
.badge-activo { background: #eaf7ec; color: var(--primary-dark); }
.badge-inactivo { background: #f1f1f1; color: var(--muted); }
.badge-suspendido { background: #fdecea; color: var(--danger); }
.badge-hito { background: #eaf2fb; color: var(--primary-dark); margin-left: 0.5rem; }
.badge-lactando { background: #f6ead9; color: #6e4520; border: 1px solid #e2c9a6; font-size: 0.72rem; font-weight: 700; padding: 0.05rem 0.45rem; margin-left: 0.3rem; white-space: nowrap; vertical-align: middle; }
.card-lactando { border-left: 5px solid #6e4520; }
.lactando-parto { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; margin: 0.2rem 0 0.4rem; }
.lactando-parto .btn { margin: 0; }
.tabla-lactando { margin-top: 0.3rem; }
.lactando-parto + .tabla-lactando ~ .lactando-parto { margin-top: 1rem; }
.hito-form { display: inline-block; margin: 0.3rem 0 0 0.5rem; }
.btn-hito { border-style: dashed; font-size: 0.78rem; padding: 0.15rem 0.55rem; }
.btn-link-hito { background: none; border: 0; padding: 0; color: var(--muted); font-size: 0.8rem; text-decoration: underline; cursor: pointer; }
.btn-link-hito:hover { color: var(--danger); }

.grupo-tabs-wrap { margin-bottom: 1rem; }
.grupo-tabs { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.grupo-tab {
    display: inline-block;
    padding: 0.45rem 1rem;
    border-radius: 999px;
    background: #eef1ee;
    color: var(--muted);
    font-size: 0.9rem;
    font-weight: 600;
    text-decoration: none;
    transition: background 0.15s ease, color 0.15s ease;
}
.grupo-tab:hover { background: #e2e6e2; }
.grupo-tab.is-active {
    background: var(--text);
    color: #fff;
    font-weight: 700;
    padding: 0.45rem 1.2rem;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
    transform: scale(1.06);
}
.grupo-tab.is-active::before { content: "✓ "; }

.card-salida { border-left: 5px solid var(--border); }
.card-salida-venta { border-left-color: #1d4f8f; }
.card-salida-baja { border-left-color: var(--danger); }
.card-salida .table th { width: 40%; }

.badge-historico-vendido { background: #eaf2fb; color: #1d4f8f; }
.badge-historico-muerto,
.badge-historico-baja { background: #fdecea; color: var(--danger); }

.grupo-tabs-count { margin: 0.5rem 0 0; font-size: 0.9rem; color: var(--muted); }

/* Inventario: cuadro con el total de animales del grupo seleccionado (y
   filtros aplicados), número grande para verlo de un vistazo. El color
   sigue al de la pestaña activa. */
.grupo-tabs-fila { display: flex; align-items: center; gap: 1.25rem; }
.grupo-tabs-fila .grupo-tabs { flex: 1; }
.conteo-grupo {
    --conteo-color: var(--primary);
    flex-shrink: 0;
    min-width: 130px;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.7rem 1rem 0.8rem;
    border: 2px solid var(--conteo-color);
    border-top-width: 6px;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    text-align: center;
}
.conteo-grupo-numero { font-size: 2.8rem; font-weight: 800; line-height: 1; color: var(--conteo-color); }
.conteo-grupo-texto { font-size: 0.95rem; font-weight: 600; color: var(--text); margin-top: 0.2rem; }
.conteo-grupo-nombre { font-size: 0.75rem; color: var(--muted); margin-top: 0.15rem; max-width: 150px; }
@media (max-width: 600px) {
    .grupo-tabs-fila { flex-direction: column; align-items: stretch; gap: 0.9rem; }
}

.intervalo-indicador {
    display: inline-flex;
    align-items: center;
    margin: 0 0.3rem;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    background: #eaf2fb;
    color: #1d4f8f;
    font-size: 0.8rem;
    font-weight: 700;
}
.intervalo-indicador-verde { background: var(--primary); color: #fff; }
.intervalo-indicador-amarillo { background: #d9a300; color: #fff; }
.intervalo-indicador-rojo { background: var(--danger); color: #fff; }

/* Intervalo entre partos, Detalle por hembra: cerrada, cada hembra muestra su
   promedio; al abrirla, cada intervalo es un renglón con sus días alineados
   debajo del promedio. */
.tabla-intervalos .intervalo-indicador { margin: 0; }
/* El promedio es el dato principal: etiqueta grande, sólida y con relieve. */
.ic-promedio { display: inline-flex; align-items: baseline; gap: 0.3rem; padding: 0.3rem 0.75rem; border-radius: 8px; font-size: 0.85rem; font-weight: 600; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18); white-space: nowrap; }
.ic-promedio strong { font-size: 0.95rem; font-weight: 800; }
/* Los intervalos de cada parto son el detalle: estilo suave del mismo color. */
.ic-dias { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.82rem; font-weight: 700; white-space: nowrap; }
.ic-dias-verde { background: #e1f0e3; color: var(--primary-dark); }
.ic-dias-amarillo { background: #fbefcc; color: #855f00; }
.ic-dias-rojo { background: #fbe1de; color: #9c2a1e; }
.tabla-intervalos tr.fila-intervalo .ic-dias { margin-left: 0.8rem; }
.tabla-intervalos tr.fila-intervalo td { background: var(--bg); border-bottom-color: #e3e7e3; padding-top: 0.35rem; padding-bottom: 0.35rem; font-size: 0.88rem; }
.fi-partos { display: inline-block; min-width: 6.5rem; margin-left: 1.4rem; font-weight: 600; }
.fi-fechas { color: var(--muted); }
@media (max-width: 600px) {
    .fi-partos { min-width: 0; margin-left: 0.3rem; }
    .fi-fechas { display: block; margin-left: 0.3rem; font-size: 0.78rem; }
    .ic-promedio { padding: 0.3rem 0.6rem; font-size: 0.78rem; }
    .ic-promedio strong { font-size: 0.88rem; }
    .tabla-intervalos tr.fila-intervalo .ic-dias { margin-left: 0.4rem; }
}

.table tr.fila-macho { background: #eaf2fb; }
.table tr.fila-hembra { background: #fdeaf3; }

.license-box { background: #eaf7ec; border: 1px solid #c8e6cb; padding: 1rem; border-radius: 8px; }
.license-warning { background: #fdf3e0; border-color: #f0d9a6; color: var(--warning); }

.filters { display: flex; gap: 0.6rem; flex-wrap: wrap; margin: 1rem 0; align-items: center; }
.filters input, .filters select { width: auto; }

.form-narrow { max-width: 440px; }

.table-scroll { overflow-x: auto; margin-top: 1rem; }
.table-scroll .table { margin-top: 0; }

/* Tablas con .tabla-movil: en celular las columnas .col-escritorio se ocultan
   y su dato (.dato-movil) va debajo de otra columna. Ej.: Historial de bajas,
   Reporte de Ingresos. */
.tabla-movil .dato-movil { display: none; }
.tabla-movil .fila-movil { display: none; }
@media (max-width: 600px) {
    .tabla-movil .col-escritorio { display: none; }
    .tabla-movil .fila-escritorio { display: none; }
    .tabla-movil .fila-movil { display: table-row; }
    .tabla-movil .dato-movil { display: block; font-size: 0.8rem; color: var(--muted); }
    .tabla-movil th, .tabla-movil td { padding: 0.5rem 0.2rem; font-size: 0.85rem; }
    .tabla-movil .btn-sm { white-space: normal; padding: 0.3rem 0.4rem; font-size: 0.8rem; line-height: 1.2; text-align: center; }
}
#crias-table th, #crias-table td { white-space: nowrap; }
#crias-table input, #crias-table select { width: auto; min-width: 110px; }
#crias-table input.input-peso { min-width: 0; width: 85px; }
#crias-table input[type="date"] { min-width: 150px; }
#crias-table input[type="checkbox"] { min-width: 0; width: auto; }

/* Bajas Grupales: sin un ancho mínimo, el navegador aplasta los campos
   de Fecha/Causa/Nota hasta volverlos ilegibles en vez de dejar que la
   tabla se desborde con scroll horizontal (que es lo que sí queremos,
   mismo criterio que #crias-table). */
#tabla-baja-masiva th, #tabla-baja-masiva td { white-space: nowrap; }
#tabla-baja-masiva input, #tabla-baja-masiva select { width: auto; }
#tabla-baja-masiva .in-fecha-baja { min-width: 150px; }
#tabla-baja-masiva .sel-causa-baja, #tabla-baja-masiva .in-nueva-causa { min-width: 170px; }
#tabla-baja-masiva .in-nota-baja { min-width: 150px; }

/* Altas Grupales: 9 columnas no caben en 960px sin aplastar los campos, y
   un scroll horizontal esconde columnas al usuario. Cada animal se muestra
   como una tarjeta con sus campos en cuadrícula (etiqueta arriba de cada
   campo, tomada de data-label), que se acomoda sola al ancho disponible. */
#alta-masiva-table { counter-reset: alta-animal; }
#alta-masiva-table thead { display: none; }
#alta-masiva-table tbody { display: block; }
#alta-masiva-table tr:not(.fila-alta-error) {
    counter-increment: alta-animal;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.75rem 1rem;
    position: relative;
    border: 2px solid #b9cdb9;
    border-left: 6px solid var(--primary);
    border-radius: 8px;
    padding: 0 1rem 1rem;
    margin-bottom: 1.4rem;
    background: #fff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
    overflow: hidden;
}
/* Tarjetas alternadas con otro tono para distinguir dónde acaba una y
   empieza la siguiente al recorrer muchas filas. */
#alta-masiva-table tr:nth-child(even of :not(.fila-alta-error)):not(.fila-alta-con-error) { border-left-color: #6a9f72; }
#alta-masiva-table tr:not(.fila-alta-error)::before {
    content: "Animal " counter(alta-animal);
    grid-column: 1 / -1;
    margin: 0 -1rem 0.1rem;
    padding: 0.55rem 7rem 0.55rem 1rem; /* derecha: espacio para el botón Quitar */
    background: #e6efe6;
    border-bottom: 1px solid #b9cdb9;
    font-weight: 700;
    font-size: 1rem;
    color: var(--primary-dark);
}
#alta-masiva-table td { display: block; padding: 0; border: none; min-width: 0; }
#alta-masiva-table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    margin-bottom: 0.25rem;
}
#alta-masiva-table td.celda-quitar { position: absolute; top: 0.4rem; right: 0.75rem; }
#alta-masiva-table td.celda-quitar .btn { padding: 0.3rem 0.7rem; font-size: 0.85rem; margin: 0; }
#alta-masiva-table .raza-nueva-field { margin-top: 0.35rem; }
#alta-masiva-table tr.fila-alta-error { display: block; margin: -1rem 0 1.4rem; }
#alta-masiva-table tr.fila-alta-error td { display: block; padding: 0.6rem 0.9rem; border: 1px solid #f5c6c1; border-radius: 6px; }
#alta-masiva-table tr.fila-alta-con-error { border-color: #e0a3a3; border-left-color: var(--danger); }
#alta-masiva-table tr.fila-alta-con-error::before { background: #fdecea; color: var(--danger); border-bottom-color: #f5c6c1; }

/* Checkboxes para seleccionar animales de una lista (Bajas Grupales,
   Ventas): el tamaño por default del navegador es muy chico y cuesta
   trabajo darles clic con precisión — se agrandan y se les da el
   color de acento del sitio para que se vean intencionales. */
.chk-baja, .chk-vender {
    width: 1.4rem;
    height: 1.4rem;
    min-width: 1.4rem;
    cursor: pointer;
    accent-color: var(--primary);
}

.camada-block { border: 1px solid var(--border); border-radius: 8px; margin-top: 1rem; overflow: hidden; }
.camada-block:first-child { margin-top: 0; }
.camada-header { display: flex; align-items: center; gap: 0.7rem; flex-wrap: wrap; background: #f6f8f6; padding: 0.7rem 0.9rem; border-bottom: 1px solid var(--border); }
.camada-info { display: flex; flex-direction: column; gap: 0.1rem; }
.camada-total { margin-left: auto; font-weight: 700; color: var(--primary-dark); font-size: 1.02rem; white-space: nowrap; }
.camada-block .table-scroll { margin-top: 0; }
.camada-block .table { margin-top: 0; }
.camada-block .table th, .camada-block .table td:first-child { padding-left: 0.9rem; }
.camada-block .table th:last-child, .camada-block .table td:last-child { padding-right: 0.9rem; }

/* Contraste fuerte entre "incluido" y "no incluido" en las tablas de
   selección masiva (Ventas, Bajas Grupales): la fila marcada resalta
   con fondo verde y opacidad completa; la no marcada se atenúa, para
   que sea obvio de un vistazo cuáles animales quedarán afectados. */
.fila-venta-animal, .fila-baja-animal { transition: opacity 0.15s ease; }
.fila-venta-animal:not(.fila-venta-activa),
.fila-baja-animal:not(.fila-baja-activa) { opacity: 0.55; }
.fila-venta-activa td { background: #eaf7ec; }
.fila-baja-activa td { background: #eaf7ec; }
.modo-hint { font-size: 0.76rem; margin-top: 0.25rem; max-width: 220px; }

/* Tabla de Nueva venta. En celular: los disponibles van en una línea
   compacta (sin campos de precio) y los seleccionados como tarjeta. */
.tabla-venta .td-modo { min-width: 190px; }
@media (max-width: 600px) {
    .tabla-venta thead { display: none; }
    .tabla-venta, .tabla-venta tbody { display: block; }
    .tabla-venta tr { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.6rem; padding: 0.6rem 0.4rem; border-bottom: 1px solid var(--border); }
    .tabla-venta td { border: 0; padding: 0; font-size: 0.88rem; }
    .tabla-venta .td-arete { font-weight: 700; }
    #tabla-disponibles .td-captura { display: none; }
    .tabla-venta .td-modo { min-width: 0; flex: 1 1 100%; }
    .tabla-venta .td-modo select { width: 100%; }
    .tabla-venta .modo-hint { max-width: none; }
    .tabla-venta td[data-label] { flex: 1 1 0; min-width: 0; }
    .tabla-venta td[data-label]::before { content: attr(data-label); display: block; font-size: 0.75rem; color: var(--muted); margin-bottom: 0.15rem; }
    .tabla-venta td[data-label] input { width: 100%; min-width: 0; }
}

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 0.9rem; margin-top: 0.5rem; }
.stat { background: #f6f8f6; border: 1px solid var(--border); border-radius: 8px; padding: 0.8rem; text-align: center; }
.stat-value { display: block; font-size: 1.4rem; font-weight: 700; color: var(--primary-dark); }
.stat-label { display: block; font-size: 0.78rem; color: var(--muted); margin-top: 0.2rem; }

.highlight-value { color: var(--primary-dark); font-size: 1.05rem; }

.folio-sello {
    display: inline-block;
    font-family: 'Courier New', Courier, monospace;
    font-weight: 700;
    font-size: 1.3rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #b3242f;
    border: 3px double #b3242f;
    border-radius: 4px;
    padding: 0.2rem 0.7rem;
    opacity: 0.85;
    mix-blend-mode: multiply;
}

.gdp-range { font-size: 0.78rem; color: var(--muted); margin-top: 0.2rem; }
.gdp-arrow { color: var(--primary); font-weight: 700; }

.gdp-total { font-weight: 700; font-size: 1.05rem; }
.gdp-total.gdp-pos { color: var(--primary-dark); }
.gdp-total.gdp-neg { color: var(--danger); }
.gdp-total.gdp-flat { color: var(--muted); }
.gdp-rate { font-size: 0.85rem; color: var(--muted); margin-top: 0.1rem; }
.gdp-total.gdp-semaforo-verde, .gdp-rate.gdp-semaforo-verde { color: var(--primary); }
.gdp-total.gdp-semaforo-amarillo, .gdp-rate.gdp-semaforo-amarillo { color: #b38600; }
.gdp-total.gdp-semaforo-rojo, .gdp-rate.gdp-semaforo-rojo { color: var(--danger); }
.gdp-rate[class*="gdp-semaforo-"] { font-weight: 700; }

.weight-chart { position: relative; margin: 1rem 0 1.5rem; }
.weight-chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.wc-grid { stroke: var(--border); stroke-width: 1; }
.wc-axis-text { fill: var(--muted); font-size: 11px; }
.wc-area { fill: var(--primary); fill-opacity: 0.1; }
.wc-seg { stroke-width: 3; stroke-linecap: round; }
.wc-seg-verde { stroke: var(--primary); }
.wc-seg-amarillo { stroke: #d9a300; }
.wc-seg-rojo { stroke: var(--danger); }
.wc-seg-lactancia, .wc-seg-neutro { stroke: var(--muted); stroke-dasharray: 5 4; }
.wc-swatch-lactancia { background: var(--muted); }
.wc-dot { fill: var(--primary); stroke: var(--card-bg); stroke-width: 2; }
.wc-end-label { fill: var(--text); font-size: 12px; font-weight: 700; }
.wc-overlay { fill: transparent; cursor: crosshair; }
.wc-crosshair { stroke: var(--muted); stroke-width: 1; opacity: 0; pointer-events: none; }
.wc-hover-dot { fill: var(--primary); stroke: var(--card-bg); stroke-width: 2; opacity: 0; pointer-events: none; }
.table tr.fila-resaltada td {
    background: #fff4de;
    transition: background 0.15s ease;
}
.table tr.fila-resaltada td:first-child { box-shadow: inset 4px 0 0 #b8790a; font-weight: 700; }

.wc-tooltip {
    position: absolute;
    pointer-events: none;
    background: var(--text);
    color: #fff;
    font-size: 0.78rem;
    line-height: 1.3;
    padding: 0.35rem 0.6rem;
    border-radius: 6px;
    transform: translate(-50%, calc(-100% - 10px));
    white-space: nowrap;
    opacity: 0;
    transition: opacity 0.08s ease;
    z-index: 5;
}
.wc-tooltip strong { font-weight: 700; }
.wc-tooltip span { display: block; opacity: 0.75; font-size: 0.72rem; margin-top: 0.1rem; }

.intervalos-chart { position: relative; margin: 0.5rem 0 1.5rem; }
.intervalos-chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.gastos-chart { position: relative; margin: 0.5rem 0 1.5rem; }
.gastos-chart svg { width: 100%; height: auto; display: block; overflow: visible; }
.ic-axis-text { fill: var(--muted); font-size: 11px; }
.ic-axis-text-parto { fill: var(--text); font-weight: 700; }
.ic-bar { fill: var(--primary); cursor: pointer; transition: fill 0.08s ease; }
.ic-bar.is-hover { fill: var(--primary-dark); }
.ic-bar-verde { fill: var(--primary); }
.ic-bar-verde.is-hover { fill: var(--primary-dark); }
.ic-bar-amarillo { fill: #d9a300; }
.ic-bar-amarillo.is-hover { fill: #a67a00; }
.ic-bar-rojo { fill: var(--danger); }
.ic-bar-rojo.is-hover { fill: #8f251a; }
.ic-swatch-verde { background: var(--primary); }
.ic-swatch-amarillo { background: #d9a300; }
.ic-swatch-rojo { background: var(--danger); }
.ic-bar-gasto { fill: var(--danger); cursor: pointer; transition: fill 0.08s ease; }
.ic-bar-gasto.is-hover { fill: #8f251a; }
/* Balance: franja de fondo en meses alternos para que se vea a qué mes es cada par de barras. */
.wc-mes-banda { fill: #eef1ee; opacity: 0.6; }
.bc-monto { fill: var(--text); font-size: 10px; font-weight: 700; pointer-events: none; }
.bc-monto-dentro { fill: #fff; }
/* Gráficas por mes de finanzas (Balance, Reporte de Ventas y de Gastos) en celular:
   la gráfica de columnas se cambia por una lista de meses con barras
   horizontales (htmlGraficaMesesMovil). La tabla del Balance se compacta. */
.balance-chart-movil { display: none; }
@media (max-width: 600px) {
    .balance-chart-escritorio { display: none; }
    .balance-chart-movil { display: block; margin: 0.5rem 0 1.5rem; }
    .bm-mes { display: flex; align-items: center; gap: 0.6rem; padding: 0.45rem 0.4rem; border-radius: 4px; }
    .bm-mes:nth-child(odd) { background: #f3f5f3; }
    .bm-nombre { width: 2.4rem; font-size: 0.85rem; color: var(--muted); }
    .bm-barras { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
    .bm-fila { display: flex; align-items: center; gap: 0.4rem; height: 12px; }
    .bm-pista { flex: 1; height: 100%; background: rgba(0, 0, 0, 0.06); border-radius: 2px; }
    .bm-barra { display: block; height: 100%; border-radius: 2px; }
    .bm-barra.entrada { background: var(--primary); }
    .bm-barra.gasto { background: var(--danger); }
    .bm-monto { width: 4.2rem; text-align: right; font-size: 0.75rem; color: var(--text); white-space: nowrap; }
    .tabla-balance th, .tabla-balance td { padding: 0.5rem 0.25rem; font-size: 0.82rem; }
}

.chart-legend { display: flex; gap: 1.2rem; margin: 0.4rem 0 0.6rem; font-size: 0.85rem; color: var(--muted); }
.chart-legend-item { display: inline-flex; align-items: center; gap: 0.4rem; }
.chart-legend-swatch { width: 0.8rem; height: 0.8rem; border-radius: 3px; display: inline-block; }
.chart-legend-swatch.entrada { background: var(--primary); }
.chart-legend-swatch.gasto { background: var(--danger); }

.balance-pos { color: var(--primary-dark); }
.balance-neg { color: var(--danger); }

.fila-mes-resumen { cursor: pointer; }
.fila-mes-resumen:hover { background: var(--bg); }
.btn-expandir-mes {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--muted);
    font-size: 0.75rem;
    padding: 0 0.4rem 0 0;
    display: inline-block;
    transition: transform 0.12s ease;
}
.btn-expandir-mes[aria-expanded="true"] { transform: rotate(90deg); }
.detalle-mes-fila td { background: var(--bg); }
.detalle-mes-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.2rem; padding: 0.4rem 0; }
@media (max-width: 640px) { .detalle-mes-grid { grid-template-columns: 1fr; } }
.detalle-mes-grid h4 { margin: 0 0 0.4rem; font-size: 0.78rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.detalle-mes-grid ul { list-style: none; margin: 0; padding: 0; }
.detalle-mes-grid li {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.6rem;
    padding: 0.35rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.87rem;
}
.detalle-mes-grid li:last-child { border-bottom: none; }
.detalle-mes-grid li strong { white-space: nowrap; }

.fila-parto-resumen:hover { background: var(--bg); }
.fila-parto-resumen.is-highlight { background: #fff4de; box-shadow: inset 3px 0 0 #d9a300; }
.badge-sexo-macho { background: #eaf2fb; color: #1d4f8f; }
.badge-sexo-hembra { background: #fdeaf3; color: #a3225a; }
.crias-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.crias-chips a.badge { text-decoration: none; }
.crias-chips a.badge:hover { text-decoration: underline; }
.ic-bar-label-inside { fill: #fff; font-size: 12px; font-weight: 700; text-anchor: middle; pointer-events: none; }
.ic-bar-label-outside { fill: var(--text); font-size: 12px; font-weight: 700; text-anchor: middle; pointer-events: none; }
.ic-dot-star { fill: #1d4f8f; stroke: var(--card-bg); stroke-width: 1.5; transition: fill 0.08s ease; }
.ic-point { cursor: pointer; }
.ic-point:hover .ic-dot-star { fill: #163a69; }
.ic-point:hover .ic-axis-text-parto { fill: #1d4f8f; }
.ic-label-bg { fill: transparent; transition: fill 0.08s ease; }
.ic-point.is-highlight .ic-label-bg { fill: #ffd873; }

.hembra-select-wrap { display: flex; align-items: center; gap: 0.5rem; }
.hembra-select-wrap label { margin: 0; font-weight: 600; white-space: nowrap; }
.select-destacado {
    width: auto;
    min-width: 160px;
    padding: 0.5rem 2rem 0.5rem 0.8rem;
    border: 2px solid #a3225a;
    border-radius: 8px;
    background: #fdeaf3;
    color: #a3225a;
    font-weight: 700;
    font-size: 0.95rem;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(163, 34, 90, 0.2);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath fill='%23a3225a' d='M4 6l4 4 4-4'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    background-size: 12px;
}
.select-destacado:hover { background-color: #fbd7e6; }
.select-destacado:focus { outline: none; box-shadow: 0 0 0 3px rgba(163, 34, 90, 0.3); }

/* Menú principal (dashboard.php): bloques grandes con ícono, pensados para
   usuarios sin mucha experiencia en computadora — prioriza tamaño y claridad
   visual sobre densidad de información. */
.menu-titulo { margin-bottom: 0.4rem; }
.menu-seccion { margin: 1.6rem 0; }
.menu-seccion:first-of-type { margin-top: 0.8rem; }
.menu-seccion-titulo {
    margin: 0 0 0.8rem;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    padding-bottom: 0.4rem;
}
.menu-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
}
.menu-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.3rem 0.8rem;
    text-decoration: none;
    color: var(--text);
    text-align: center;
    min-height: 110px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    transition: transform 0.1s ease, box-shadow 0.1s ease, border-color 0.1s ease;
}
.menu-card:hover, .menu-card:focus-visible {
    border-color: var(--primary);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.1);
    transform: translateY(-2px);
}
.menu-card-icon { font-size: 2.4rem; line-height: 1; }
.menu-card-label { font-size: 0.95rem; font-weight: 700; }
.menu-card-desc { font-size: 0.8rem; color: var(--muted); line-height: 1.25; }

@media (max-width: 480px) {
    .menu-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 0.7rem; }
    .menu-card { min-height: 95px; padding: 1rem 0.6rem; }
    .menu-card-icon { font-size: 2rem; }
    .menu-card-label { font-size: 0.85rem; }
    .menu-card-desc { font-size: 0.75rem; }
}

/* Opción 1: botón flotante fijo, siempre visible sin importar el scroll,
   para volver al menú principal desde cualquier módulo sin depender del sidebar. */
.btn-menu-flotante {
    position: fixed;
    right: 1.2rem;
    bottom: 1.2rem;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 0.45rem;
    background: var(--primary);
    color: #fff;
    text-decoration: none;
    padding: 0.75rem 1.1rem;
    border-radius: 999px;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.25);
    font-weight: 700;
    font-size: 0.95rem;
}
.btn-menu-flotante:hover { background: var(--primary-dark); }
.btn-menu-flotante-icon { font-size: 1.3rem; line-height: 1; }
.btn-menu-flotante-label-corta { display: none; }

/* En celular se mantiene el texto (más corto) en vez de dejar solo el ícono
   suelto — un círculo con un emoji chiquito no dejaba claro para qué era. */
@media (max-width: 480px) {
    .btn-menu-flotante { right: 0.7rem; bottom: 0.7rem; padding: 0.65rem 1rem; gap: 0.35rem; font-size: 0.88rem; }
    .btn-menu-flotante-icon { font-size: 1.2rem; }
    .btn-menu-flotante-label-larga { display: none; }
    .btn-menu-flotante-label-corta { display: inline; }
}

/* Botón flotante específico de ventas/form.php: lleva directo a la tabla de
   animales ya marcados para el folio (que vive más arriba en la página, antes
   de la lista de disponibles) — la flecha hacia arriba dejar claro hacia
   dónde lleva. Centrado abajo, aparte del botón de "Regresar al Menú
   Principal" que se queda en su esquina, sin encimarse. */
.flotante-seleccionados-wrap {
    position: fixed;
    left: 50%;
    bottom: 1.2rem;
    transform: translateX(-50%);
    z-index: 50;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.2rem;
}
.flotante-seleccionados-flecha {
    font-size: 1.3rem;
    line-height: 1;
    color: #1d4f8f;
    animation: flotante-seleccionados-rebote 1.2s ease-in-out infinite;
}
@keyframes flotante-seleccionados-rebote {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}
.btn-flotante-seleccionados { position: static; transform: none; background: #1d4f8f; }
.btn-flotante-seleccionados:hover { background: #163a69; }

/* En celular, con las dos etiquetas visibles, el botón "Ver seleccionados"
   centrado se empalmaba con "Regresar al Menú Principal" en la esquina: se
   apila arriba de este, cada uno en su propia fila, en vez de compartir la
   misma línea horizontal. */
@media (max-width: 480px) {
    .flotante-seleccionados-wrap { bottom: 4.6rem; }
}

/* "Registrar venta"/"Cancelar" van antes de los disponibles. La lista de
   disponibles es lo último de la página: este margen evita que los botones
   flotantes (menú + ver seleccionados, apilados en celular) tapen sus
   últimos animales. */
.venta-form-acciones { margin-top: 1rem; }
.venta-disponibles { margin-bottom: 5rem; }
@media (max-width: 480px) {
    .venta-disponibles { margin-bottom: 9.5rem; }
}

/* ---------- Tablero de corrales (animales/corrales.php) ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.corrales-vista { display: flex; gap: 0.5rem; margin: 0.8rem 0 0.2rem; }
.corrales-vista .grupo-tab { border: 0; cursor: pointer; font-family: inherit; }
.corral-seccion { margin-bottom: 1.6rem; background: #fff; border: 1px solid var(--border); border-radius: 10px; overflow: clip; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); }
.corral-seccion-head { padding: 0.7rem 0.9rem; background: #6e4520; color: #fff; }
@media (min-width: 721px) {
    /* En computadora el nombre del corral se queda arriba al bajar por una lista larga. */
    .corral-seccion-head { position: sticky; top: 0; z-index: 2; }
}
.corral-seccion-head h2 { margin: 0; font-size: 1.1rem; color: #fff; }
/* Nombre a la izquierda y el total centrado en la barra. */
.corral-seccion-fila { display: grid; grid-template-columns: 1fr auto 1fr; align-items: baseline; gap: 0.6rem; }
.corral-seccion-total { white-space: nowrap; font-size: 1.1rem; font-weight: 700; }
.corral-seccion-resumen { margin-top: 0.25rem; font-size: 0.85rem; color: #f6ead9; }
.corral-seccion .corral-vacio { margin: 0.7rem 0.9rem; }
.tabla-corral { table-layout: fixed; margin: 0; }
.tabla-corral th { background: var(--bg); color: var(--text); font-size: 0.82rem; border-bottom: 1px solid var(--border); }
.tabla-corral td { border-bottom: 2px solid #fff; }
.table.tabla-corral tr.is-selected { background: #d6ecd6; }
.tabla-corral .col-check { width: 2.6rem; text-align: center; }
.tabla-corral .col-check input { width: auto; margin: 0; cursor: pointer; }
.tabla-corral th:nth-child(2) { width: 18%; }
.tabla-corral th:nth-child(3) { width: 20%; }
.tabla-corral th:nth-child(4), .tabla-corral th:nth-child(5) { width: 17%; }
.tabla-corral th.th-sortable { white-space: normal; }
.corrales-filtros { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 0.6rem 0 1rem; }
.corrales-filtros select, .corrales-filtros input { width: auto; min-width: 12rem; flex: 1 1 12rem; max-width: 20rem; margin: 0; }
.corrales-tablero { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; align-items: start; }
.corrales-tablero[hidden] { display: none; }
.corral-tarjeta { border: 2px solid var(--border); border-radius: 10px; background: var(--card-bg); display: flex; flex-direction: column; transition: border-color 0.12s ease, box-shadow 0.12s ease; }
.corral-tarjeta-sin { border-style: dashed; background: #fafbfa; }
.corral-tarjeta.is-drop { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(47, 125, 60, 0.18); }
.corral-tarjeta.is-encontrado { border-color: #b8790a; }
.corral-tarjeta-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 0.5rem; padding: 0.75rem 0.85rem; border-bottom: 1px solid var(--border); }
.corral-tarjeta-head h2 { margin: 0; font-size: 1.05rem; }
.corral-tarjeta-meta { font-size: 0.82rem; color: var(--muted); margin-top: 0.15rem; }
.corral-tarjeta-acciones { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.35rem; }
.corral-tarjeta-acciones .btn { margin: 0; padding: 0.2rem 0.55rem; font-size: 0.78rem; }
.corral-tarjeta-resumen { list-style: none; margin: 0.45rem 0 0; padding: 0; font-size: 0.82rem; color: var(--text); }
.corral-tarjeta-resumen li { display: flex; align-items: baseline; gap: 0.4rem; line-height: 1.5; }
.corral-resumen-n { min-width: 1.6rem; text-align: right; font-weight: 700; color: var(--primary-dark); }
.corrales-eliminados { margin-top: 1.2rem; font-size: 0.9rem; }
.corrales-eliminados summary { cursor: pointer; color: var(--muted); font-weight: 600; }
.corrales-eliminados ul { list-style: none; padding: 0; margin: 0.5rem 0 0; }
.corrales-eliminados li { display: flex; align-items: center; justify-content: space-between; gap: 0.6rem; padding: 0.35rem 0; border-bottom: 1px solid var(--border); }
.corrales-eliminados form { margin: 0; }
.corrales-eliminados .btn { margin: 0; }
.corral-total { flex-shrink: 0; display: flex; flex-direction: column; align-items: center; min-width: 4.2rem; padding: 0.35rem 0.6rem; border: 2px solid var(--primary); border-radius: 10px; }
.corral-conteo { font-size: 2rem; font-weight: 800; line-height: 1; color: var(--primary); }
/* En la barra café de la vista Tabla el total va del mismo tamaño que el nombre del corral. */
.corral-seccion-total .corral-conteo { font-size: 1em; font-weight: 700; line-height: normal; color: #fff; }
.corral-total-texto { font-size: 0.75rem; font-weight: 600; color: var(--muted); margin-top: 0.1rem; }
.corral-sel-todos { margin-top: 0.5rem; }
.corral-animales { list-style: none; margin: 0; padding: 0.35rem; max-height: 22rem; overflow-y: auto; overflow-x: hidden; }
.corral-animal { display: flex; align-items: center; justify-content: space-between; gap: 0.4rem; border-radius: 6px; padding: 0.15rem 0.4rem; cursor: grab; }
.corral-animal[hidden] { display: none; }
.corral-animal + .corral-animal { margin-top: 3px; }
.corral-animal-hembra { background: #fdeef5; }
.corral-animal-hembra:hover { background: #f9dcea; }
.corral-animal-macho { background: #eaf2fb; }
.corral-animal-macho:hover { background: #d8e7f7; }
.corral-animal.is-selected { box-shadow: inset 0 0 0 2px var(--primary); }
.corral-animal.is-selected strong { color: var(--primary-dark); }
.corral-animal.is-dragging { opacity: 0.45; }
.corral-animal label { display: flex; align-items: center; gap: 0.5rem; flex: 1; min-width: 0; margin: 0; padding: 0.35rem 0; cursor: pointer; font-weight: normal; }
.corral-animal input[type="checkbox"] { width: 1.15rem; height: 1.15rem; margin: 0; flex: none; }
.corral-animal-info { display: flex; flex-direction: column; min-width: 0; gap: 0.05rem; }
.corral-animal-l1 { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem; }
.corral-animal-l1 strong { overflow-wrap: anywhere; }
.corral-animal-l2 { font-size: 0.75rem; color: var(--muted); }
.corral-animal-lact { line-height: 1.3; }
.corral-animal .badge-lactando { margin-left: 0; }
.corral-sexo { color: var(--muted); }
.icono-sexo { font-size: 1.15em; font-weight: 700; line-height: 1; -webkit-text-stroke: 0.45px currentColor; vertical-align: -0.05em; cursor: help; }
.icono-sexo-hembra { color: #c2185b; }
.icono-sexo-macho { color: #1d5fae; }
.corral-animal-hembra .corral-sexo { color: #a3225a; }
.corral-animal-macho .corral-sexo { color: #1d4f8f; }
.corral-ver { flex-shrink: 0; font-size: 0.75rem; line-height: 1; padding: 0.25rem 0.5rem; border-radius: 999px; border: 1px solid var(--border); background: #fff; color: var(--primary-dark); text-decoration: none; white-space: nowrap; }
.corral-ver:hover { background: var(--primary); border-color: var(--primary); color: #fff; }
.corral-familia { font-size: 0.8rem; white-space: nowrap; cursor: help; }
.corral-vacio { margin: 0.6rem 0.85rem 0.8rem; font-size: 0.88rem; }
.corral-barra { position: sticky; bottom: 0; z-index: 20; margin-top: 1rem; padding: 0.8rem 1rem; background: var(--card-bg); border: 2px solid var(--primary); border-radius: 10px; box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.12); }
.corral-barra-info { margin-bottom: 0.5rem; }
.corral-barra-info #corral-limpiar { margin: 0 0 0 0.3rem; }
#corral-sel-aretes { font-weight: 600; }
.corral-barra-campos { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: flex-end; }
.corral-barra-campos label { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.85rem; margin: 0; }
.corral-barra-campos select, .corral-barra-campos input { margin: 0; }
.corral-barra-nota { flex: 1 1 12rem; }
.btn-link { background: none; border: 0; padding: 0; color: var(--primary-dark); text-decoration: underline; cursor: pointer; font: inherit; }
body.corral-seleccion-activa .btn-menu-flotante { display: none; }
.corral-deshacer { display: flex; align-items: center; justify-content: space-between; gap: 0.8rem; flex-wrap: wrap; }
@media (max-width: 600px) {
    .corral-barra-campos > * { flex: 1 1 100%; }
    .corral-barra-campos .btn { width: 100%; }
}
.destete-corral-todas { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; margin-top: 0.6rem; font-size: 0.9rem; }
.destete-corral-todas label { margin: 0; }
.destete-corral-todas select { width: auto; margin: 0; }
.corral-anulados { margin-top: 0.8rem; font-size: 0.88rem; }
.corral-anulados summary { cursor: pointer; color: var(--muted); }
.corral-anulados ul { margin: 0.4rem 0 0; padding-left: 1.2rem; }
.corral-anulados s { color: var(--muted); }
.corral-conflicto ul { margin: 0.4rem 0 0; padding-left: 1.2rem; }

/* Manejo Sanitario */
.tabla-sanitaria td { vertical-align: middle; white-space: nowrap; }
.tabla-sanitaria .col-aplicacion { text-align: center; }
.semaforo-punto { display: inline-block; width: 0.8rem; height: 0.8rem; border-radius: 50%; margin-right: 0.4rem; vertical-align: middle; }
.semaforo-rojo { background: var(--danger); }
.semaforo-amarillo { background: #d9a300; }
.semaforo-verde { background: var(--primary); }
.casilla { display: inline-flex; align-items: center; justify-content: center; width: 2rem; height: 2rem; margin: 0; padding: 0; border: 2px solid var(--border); border-radius: 6px; background: #fff; color: #fff; font-size: 1.1rem; font-weight: 700; line-height: 1; }
button.casilla { cursor: pointer; }
button.casilla:hover { border-color: var(--primary); }
.casilla.is-marcada { background: var(--primary); border-color: var(--primary); }
.casilla-fecha { font-size: 0.72rem; color: var(--muted); margin-top: 0.15rem; }
.fecha-aplicacion { display: inline-flex; align-items: center; gap: 0.6rem; margin: 0 0 1rem; font-weight: 600; }
.fecha-aplicacion input { width: auto; margin: 0; }
input.casilla-fecha-editable { width: 7.5rem; margin: 0; padding: 0; border: none; background: none; text-align: center; cursor: pointer; }
input.casilla-fecha-editable:hover { color: var(--primary); text-decoration: underline; }
.tabla-sanitaria tr.is-guardando { opacity: 0.5; pointer-events: none; }
/* Destete: mismas columnas en todas las camadas; porcentajes para que siempre quepa sin scroll */
.tabla-destete { table-layout: fixed; }
.tabla-destete .c-arete { width: 18%; }
.tabla-destete .c-dias { width: 12%; }
.tabla-destete .c-peso { width: 11%; }
.tabla-destete .c-peso-destete { width: 13%; }
.tabla-destete .c-corral { width: 24%; }
.tabla-destete .c-sanitario { width: 10%; }
.tabla-destete th { vertical-align: bottom; line-height: 1.25; }
.tabla-destete td { vertical-align: middle; overflow-wrap: anywhere; }
.tabla-destete td input.input-peso, .tabla-destete td select { width: 100%; min-width: 0; margin: 0; }
.tabla-destete .col-sanitario { text-align: center; }
.tabla-destete th.col-sanitario label { display: flex; flex-direction: column; align-items: center; gap: 0.3rem; margin: 0; cursor: pointer; }
.tabla-destete .col-sanitario input[type="checkbox"] { width: 1.1rem; height: 1.1rem; margin: 0; padding: 0; vertical-align: middle; }

/* Texto guía al inicio de un módulo: la instrucción principal de la pantalla */
.texto-guia { display: flex; align-items: center; gap: 0.6rem; margin: 0 0 1rem; padding: 0.7rem 0.9rem; background: #e9f4eb; border: 1px solid #c3e0c8; border-left: 4px solid var(--primary); border-radius: 8px; color: var(--primary-dark); font-size: 1.05rem; font-weight: 600; line-height: 1.3; }
.texto-guia::before { content: "🔎"; font-size: 1.25rem; flex: 0 0 auto; }

/* Historial de empadres (ficha de la hembra) */
.tabla-empadres tr.fila-archivada td { color: var(--muted); }
.stat-value.stat-texto { font-size: 1.05rem; line-height: 1.3; }
.tabla-empadres .acciones-empadre { white-space: nowrap; }
.tabla-empadres .acciones-empadre .btn { margin: 0 0.2rem 0.2rem 0; }
@media (max-width: 600px) {
    .tabla-empadres .acciones-empadre { white-space: normal; }
    .tabla-empadres .acciones-empadre .btn { display: block; margin: 0 0 0.3rem; padding: 0.25rem 0.3rem; font-size: 0.75rem; }
}
