* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: 'Segoe UI', Tahoma, sans-serif;
  background: #eef3f1;
  color: #1f2d27;
  min-height: 100vh;
}

/* ================= LOGIN ================= */
body.logged-out header,
body.logged-out main { display: none; }

.login-overlay {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #134e3a, #289672);
  display: flex; justify-content: center; align-items: center;
  z-index: 2000; padding: 1rem;
}
body.logged-in .login-overlay { display: none; }

.login-box {
  background: white; padding: 2.2rem 2rem; border-radius: 14px;
  width: 100%; max-width: 360px; text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-box h1 { color: #134e3a; font-size: 1.9rem; letter-spacing: 2px; }
.login-box > p { color: #718096; margin: 0.3rem 0 1.6rem; font-size: 0.85rem; }
.login-box .field { text-align: left; margin-bottom: 1rem; }
.login-box button { width: 100%; padding: 0.8rem; font-size: 1rem; }
.login-box small { color: #718096; }

/* ================= HEADER ================= */
header {
  background: linear-gradient(135deg, #134e3a, #289672);
  color: white;
  padding: 1.3rem 2rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  position: relative; /* Para posicionar el user-info */
}
.logo h1 { font-size: 1.7rem; letter-spacing: 2px; }
.logo p { font-size: 0.9rem; opacity: 0.95; margin-top: 2px; }
.logo small { font-size: 0.75rem; opacity: 0.75; }

.user-info {
  display: flex; align-items: center; gap: 1rem;
  position: absolute; top: 1.3rem; right: 2rem; /* Fijado a la derecha */
}
#userBadge {
  background: rgba(255,255,255,0.15);
  padding: 5px 12px; border-radius: 20px;
  font-size: 0.82rem; font-weight: 600;
}

/* Estilos para el estado de conexión en el header */
#estadoConexion {
  padding: 5px 12px !important;
  border-radius: 20px !important;
  font-size: 0.78rem !important;
  font-weight: 600 !important;
}

.btn-logout {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.35);
  color: white; padding: 5px 12px; border-radius: 6px;
  cursor: pointer; font-size: 0.82rem; font-weight: 600;
  transition: all 0.2s;
}
.btn-logout:hover { background: #e53e3e; border-color: #e53e3e; }

/* ================= NAVEGACIÓN RESPONSIVE ================= */
nav { margin-top: 1.5rem; }

/* Botón hamburguesa (oculto por defecto en PC) */
.nav-toggle {
  display: none;
  background: rgba(255,255,255,0.15);
  color: white;
  border: 1px solid rgba(255,255,255,0.3);
  padding: 0.6rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 600;
  width: 100%;
  text-align: left;
}

.nav-links {
  display: flex; gap: 0.4rem; flex-wrap: wrap; align-items: center;
}

.tab-btn {
  background: rgba(255,255,255,0.12);
  color: white;
  border: 1px solid rgba(255,255,255,0.25);
  padding: 0.55rem 1rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.88rem;
  transition: all 0.2s;
  white-space: nowrap;
}
.tab-btn:hover { background: rgba(255,255,255,0.22); }
.tab-btn.active { background: white; color: #134e3a; font-weight: 700; }

main { padding: 2rem; max-width: 1450px; margin: 0 auto; }
.tab-content { display: none; }
.tab-content.active { display: block; animation: fade 0.3s; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

h2 { color: #134e3a; margin-bottom: 1.2rem; border-bottom: 3px solid #289672; padding-bottom: 0.5rem; }
h3 { color: #289672; margin: 1.3rem 0 0.7rem; font-size: 1.05rem; border-left: 4px solid #289672; padding-left: 8px; }

.card-form {
  background: white;
  padding: 1.5rem 1.8rem;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.07);
  margin-bottom: 1.5rem;
}
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.field { display: flex; flex-direction: column; margin-bottom: 0.6rem; }
.field label { font-size: 0.83rem; font-weight: 600; margin-bottom: 4px; color: #374151; }
.field input, .field select, .field textarea {
  padding: 0.55rem 0.7rem;
  border: 1px solid #cbd5e0;
  border-radius: 6px;
  font-size: 0.92rem;
  font-family: inherit;
  transition: border 0.2s;
  background: #f9fbfa;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: #289672;
  box-shadow: 0 0 0 3px rgba(40,150,114,0.15);
  background: white;
}
.field input[readonly] { background: #edf2f7; color: #4a5568; font-weight: 600; }

.checklist {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 0.5rem; margin-bottom: 1rem;
}
.checklist label {
  background: #f7fafc; padding: 0.55rem 0.7rem;
  border-radius: 6px; cursor: pointer; font-size: 0.88rem;
  display: flex; align-items: center; gap: 8px;
  border: 1px solid #e2e8f0; transition: all 0.15s;
}
.checklist label:hover { background: #edf2f7; border-color: #289672; }
.checklist input[type="checkbox"] { width: 17px; height: 17px; accent-color: #289672; flex-shrink: 0; }

.check-grande {
  display: flex; align-items: center; gap: 10px;
  background: #f0fff4; padding: 0.8rem;
  border-radius: 8px; border: 2px dashed #289672;
  cursor: pointer; margin-bottom: 1rem; font-size: 0.92rem;
}
.check-grande input { width: 20px; height: 20px; accent-color: #289672; }

.nota { font-size: 0.85rem; color: #744210; background: #fefcbf; padding: 0.6rem 0.8rem; border-radius: 6px; margin-bottom: 1rem; border-left: 4px solid #d69e2e; }

.alert-info {
  background: #ebf8ff; border-left: 4px solid #3182ce;
  padding: 0.8rem; border-radius: 6px; font-size: 0.88rem;
  margin: 1rem 0; color: #2c5282;
}

.actions { display: flex; gap: 0.8rem; margin-top: 1.2rem; flex-wrap: wrap; }
.btn-primary, .btn-secondary {
  padding: 0.7rem 1.4rem; border: none; border-radius: 6px;
  font-size: 0.92rem; font-weight: 600; cursor: pointer; transition: all 0.2s;
}
.btn-primary { background: #289672; color: white; }
.btn-primary:hover { background: #134e3a; transform: translateY(-1px); }
.btn-primary:disabled { opacity: 0.6; cursor: not-allowed; transform: none; }
.btn-secondary { background: #e2e8f0; color: #1f2d27; }
.btn-secondary:hover { background: #cbd5e0; }

.search-bar { margin-bottom: 1rem; }
.search-bar input {
  width: 100%; max-width: 500px;
  padding: 0.7rem 1rem; border: 1px solid #cbd5e0;
  border-radius: 6px; font-size: 0.92rem;
}

.table-wrap { overflow-x: auto; background: white; border-radius: 12px; box-shadow: 0 2px 10px rgba(0,0,0,0.07); margin-bottom: 1rem; }
table { width: 100%; border-collapse: collapse; min-width: 800px; }
th {
  background: #134e3a; color: white; padding: 0.75rem 0.8rem;
  text-align: left; font-size: 0.78rem; text-transform: uppercase;
  letter-spacing: 0.5px;
}
td { padding: 0.65rem 0.8rem; border-bottom: 1px solid #edf2f7; font-size: 0.86rem; }
tr:hover td { background: #f7fafc; }

.badge { padding: 3px 10px; border-radius: 12px; font-size: 0.72rem; font-weight: 700; }
.badge-ok { background: #c6f6d5; color: #22543d; }
.badge-warn { background: #fefcbf; color: #744210; }
.badge-danger { background: #fed7d7; color: #822727; }
.badge-info { background: #bee3f8; color: #2a4365; }

.btn-sm {
  padding: 4px 10px; font-size: 0.75rem; border: none;
  border-radius: 4px; cursor: pointer; margin-right: 4px; font-weight: 600;
}
.btn-del { background: #fed7d7; color: #822727; }
.btn-del:hover { background: #fc8181; color: white; }
.btn-view { background: #bee3f8; color: #2a4365; }
.btn-view:hover { background: #63b3ed; color: white; }
.btn-ok { background: #c6f6d5; color: #22543d; }
.btn-ok:hover { background: #68d391; color: white; }

.total-box {
  text-align: right; padding: 1.2rem 1.5rem;
  background: linear-gradient(135deg, #f0fff4, #e6ffed);
  border-radius: 10px; margin: 1rem 0;
  border-left: 5px solid #289672;
}
.total-box h3 { color: #134e3a; font-size: 1.5rem; border: none; padding: 0; margin: 0.5rem 0 0; }
.desglose { text-align: left; font-size: 0.88rem; line-height: 1.9; color: #374151; }
.desglose .linea { display: flex; justify-content: space-between; border-bottom: 1px dashed #cbd5e0; padding: 3px 0; }
.desglose .linea.total { border-bottom: none; font-weight: bold; color: #134e3a; }

.modal {
  display: none; position: fixed; top: 0; left: 0;
  width: 100%; height: 100%; background: rgba(0,0,0,0.6);
  z-index: 1000; justify-content: center; align-items: center; padding: 1rem;
}
.modal.active { display: flex; }
.modal-content {
  background: white; padding: 2rem; border-radius: 12px;
  max-width: 750px; width: 100%; max-height: 92vh; overflow-y: auto;
  position: relative;
}
.close {
  position: absolute; top: 10px; right: 18px;
  font-size: 28px; cursor: pointer; color: #718096; font-weight: bold;
}
.close:hover { color: #e53e3e; }

/* ================= MODAL DETALLE ANIMAL ================= */
.modal-animal { max-width: 780px; }
.detalle-animal { font-family: 'Segoe UI', Tahoma, sans-serif; }
.detalle-header {
  display: flex; align-items: center; gap: 1rem;
  padding-bottom: 1rem; margin-bottom: 1.2rem;
  border-bottom: 3px solid #289672;
}
.detalle-header .avatar {
  width: 60px; height: 60px; border-radius: 50%;
  background: linear-gradient(135deg, #134e3a, #289672);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; color: white; flex-shrink: 0;
}
.detalle-header h2 { margin: 0; border: none; padding: 0; color: #134e3a; font-size: 1.3rem; }
.detalle-header p { margin: 3px 0 0; color: #718096; font-size: 0.85rem; }

.detalle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
}
.detalle-seccion {
  background: #f7fafc; border-radius: 10px;
  padding: 1rem 1.1rem; border-left: 4px solid #289672;
}
.detalle-seccion h3 {
  margin: 0 0 0.7rem; border: none; padding: 0;
  color: #134e3a; font-size: 0.95rem;
  display: flex; align-items: center; gap: 6px;
}
.detalle-seccion .item {
  display: flex; justify-content: space-between;
  font-size: 0.85rem; padding: 4px 0;
  border-bottom: 1px dashed #e2e8f0;
}
.detalle-seccion .item:last-child { border-bottom: none; }
.detalle-seccion .item span:first-child { color: #4a5568; font-weight: 600; }
.detalle-seccion .item span:last-child { color: #1f2d27; text-align: right; }

.detalle-obs {
  background: #fffaf0; border-left: 4px solid #d69e2e;
  padding: 0.8rem 1rem; border-radius: 8px;
  margin-top: 1rem; font-size: 0.88rem; color: #744210;
}
.detalle-obs strong { display: block; margin-bottom: 4px; color: #744210; }
.detalle-badges { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }

/* ================= DASHBOARD ================= */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-top: 1.5rem;
}

.dash-card {
  background: white;
  border-radius: 16px;
  padding: 2rem 1.5rem;
  text-align: center;
  box-shadow: 0 4px 15px rgba(0,0,0,0.05);
  border: 1px solid #edf2f7;
  transition: transform 0.2s, box-shadow 0.2s;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.dash-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 25px rgba(0,0,0,0.1);
}

.dash-icon { font-size: 2.5rem; margin-bottom: 1rem; }

.dash-card h3 {
  color: #1f2d27;
  font-size: 1rem;
  margin-bottom: 0.5rem;
  border: none;
  padding: 0;
}

.dash-number {
  font-size: 2.2rem;
  font-weight: 800;
  color: #134e3a;
  margin-bottom: 1rem;
  line-height: 1;
}

.dash-card .btn-primary {
  padding: 0.5rem 1rem;
  font-size: 0.85rem;
  border-radius: 8px;
}

/* ================= RESPONSIVE (Móviles y Tablets) ================= */
@media (max-width: 900px) {
  header { padding: 1rem; }
  
  .user-info {
    position: relative;
    top: 0; right: 0;
    justify-content: flex-start;
    margin-top: 0.8rem;
    flex-wrap: wrap;
  }

  nav { margin-top: 1rem; }
  
  /* Mostrar botón hamburguesa */
  .nav-toggle { display: block; }
  
  /* Ocultar enlaces por defecto en móvil */
  .nav-links {
    display: none;
    flex-direction: column;
    margin-top: 0.5rem;
    background: rgba(0,0,0,0.1);
    padding: 0.5rem;
    border-radius: 8px;
  }
  
  /* Mostrar enlaces cuando tienen la clase 'show' */
  .nav-links.show { display: flex; }

  .tab-btn {
    width: 100%;
    text-align: left;
    padding: 0.7rem 1rem;
    font-size: 0.9rem;
  }
  
  main { padding: 1rem; }
  .card-form { padding: 1rem; }
}

@media (max-width: 600px) {
  .dashboard-grid { grid-template-columns: 1fr; }
}

@media print {
  body * { visibility: hidden; }
  .modal-content, .modal-content * { visibility: visible; }
  .modal-content { position: absolute; left: 0; top: 0; box-shadow: none; }
  .modal-content .actions { display: none; }
}

.dash-subtext {
  font-size: 0.85rem;
  color: #718096;
  margin-top: -0.5rem;
  margin-bottom: 1.2rem;
}
.dash-subtext strong {
  color: #289672;
  font-weight: 700;
}