:root {
    --fg: #111;
    --muted: #666;
    --bg: #fafafa;
    --card: #fff;
    --br: #eaeaea;
}

* { 
    box-sizing: border-box; 
}

body { 
    margin: 0; 
    font: 16px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial; 
    color: var(--fg); 
    background: var(--bg); 
}

header { 
    padding: 20px 24px; 
    display: flex; 
    align-items: center; 
    justify-content: center;
    width: 100%;
    border-bottom: 1px solid var(--br); 
    background: #fff; 
    position: sticky; 
    top: 0; 
    z-index: 100;
}

.ancho {
    width: 80%;
    padding: 0 16px; 
    justify-content: space-between;
}

.logo {
    width: 220px;
}

img#logo-cdti {
    width: 25%;
}

.wrap { 
    max-width: 80%; 
    margin: 24px auto; 
    padding: 0 16px; 
    display: grid; 
    gap: 16px; 
}

canvas {
  max-height: 640px;
  width: auto;
  height: auto;
  display: block;
}

.card { 
    background: var(--card); 
    width: 100%;
    border: 1px solid var(--br); 
    border-radius: 16px; 
    padding: 16px; 
}

.info {
    display: flex;
    gap: 12px;
    width: 100%;
}

.title { 
    font-weight: 600; 
    margin: 0 0 8px; 
}

.muted { 
    color: var(--muted); 
    font-size: 14px; 
}

.act {
    align-items: center;
}

.row { 
    display: flex; 
    gap: 6px;
    flex-wrap: wrap; 
}

.stat-label { 
    color: var(--muted); 
    font-size: 14px; 
}

.stat-value { 
    font-size: 16px; 
    font-weight: 600; 
    line-height: 1.1; 
}

#uploadInput { 
    display: none; 
}
#refreshBtn {
    display: none;
}
.card-img {
    display: flex;
    flex-direction: column;
    width: fit-content;
    min-width: min-content;
    height: fit-content;
    background: var(--card); 
    border: 1px solid var(--br); 
    border-radius: 16px;
    padding: 16px; 
    gap: 12px;
}

.card-stats {
    display: flex;
    flex-direction: column;
    width: 50%;
    height: fit-content;
    background: var(--card); 
    border: 1px solid var(--br); 
    border-radius: 16px; 
    padding: 16px; 
    gap: 12px;
}

button { 
    background: #e61166; 
    color: #212121; 
    border: 0; 
    padding: 10px 14px; 
    border-radius: 10px; 
    cursor: pointer; 
}

button:disabled { 
    opacity: .6; 
    cursor: default; 
}

button:hover { 
    background: #8bb559; 
}
.menu{
    display: flex;
    align-items: center;
    justify-content: center;
}

#estadisticas {
    background: none;
    text-decoration: none;
    color: var(--fg);
    font-size: 14px;
    font-weight: 600;
}
#estadisticas:hover { 
    background: none;
    color: #8bb559;
}

#impropios_chart { width: 100%; display: block; }

#upload {
    font-size: 20px;
    padding: 8px 12px;
    line-height: 1;
}

/* === Histórico: columnas con el mismo ancho === */
#table {
  width: 100%;
  table-layout: fixed;           /* reparte el ancho según las primeras celdas/ancho forzado */
  border-collapse: collapse;
  --cols: 4;                     /* nº de columnas (ajusta a 3 si tu tabla tiene 3) */
}

/* Contenedor con scroll para la tabla */
#table {
  display: block;
  max-height: 300px;
  overflow-y: auto;
}

/* Mantener el encabezado fijo */
#table thead {
  position: sticky;
  top: 0;
  background: var(--card);
  z-index: 1;
}

#table thead th,
#table tbody td {
  width: calc(100% / var(--cols));   /* todas las columnas iguales */
  padding: 0.6rem 0.8rem;
  text-align: left;
  vertical-align: middle;
  overflow: hidden;                  /* evita desbordes feos */
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Ajustes visuales opcionales */
#table thead th {
  font-weight: 600;
  border-bottom: 1px solid rgba(0,0,0,.1);
}

#table tbody tr + tr td {
  border-top: 1px solid rgba(0,0,0,.06);
}

/* Imágenes dentro de la columna 'img' */
#table td img {
  
  max-width: 100%;
  height: auto;
  margin: 0 auto;
  object-fit: contain;
}
/* Card a ancho completo en el grid */
.card-full { grid-column: 1 / -1; }

/* Contenedor del gráfico: evita que se encoja y permite responsive */
.chart-wrap {
  width: 100%;
  overflow-x: hidden; /* cambia a auto si quieres scroll horizontal cuando hay MUCHAS barras */
}

/* Canvas responsive */
#impropios_chart_v {
  display: block;
  padding: 20px;
  
  width: 100%;   /* ocupa todo el ancho disponible */
  height: auto; /* alto visual; el script ajusta el tamaño real en píxeles */
}

.pie-row {
  display: flex;
  align-items: stretch;
  gap: 16px;
}
#impropios_pie {
  display: block;
  width: 50%;
  height: auto;            /* alto visual; JS ajusta píxeles reales (HiDPI) */
  flex: 1 1 auto;
}
.pie-legend {
  list-style: none;
  margin: 0;
  padding: 4px 0;
  width: 260px;             /* leyenda a la derecha */
  overflow-y: auto;
  font-size: 12px;          /* etiquetas pequeñas */
  line-height: 1.2;
}
.pie-legend li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
}
.pie-legend .swatch {
  width: 12px;
  height: 12px;
  border-radius: 2px;
  flex: 0 0 12px;
}
.pie-legend .label {
  
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pie-legend .val {
  flex: 0 0 auto;
  color: #6b7280;
}

/* (Opcional) en móviles, apila */
@media (max-width: 720px) {
  .pie-row { flex-direction: column; }
  .pie-legend { width: 100%; max-height: 180px; }
}
.uno {
    width: 25%;
}
.dos {
    width: 100%;
}




/* Responsive: en pantallas pequeñas, permitimos cortar líneas para que no se rompa el layout */
@media (max-width: 640px) {
  #table thead th,
  #table tbody td {
    white-space: normal;       /* permite salto de línea */
    line-height: 1.2;
  }
}


.section-divider {
    width: 100%;
    height: 1px;
    background-color: #e0e0e0;
    border: none;
    margin: 0;
}

.title-container {
    width: 100%;
}

@media (max-width: 520px) {
    .wrap {
        max-width: 100%;
    }
    
    .info {
        flex-direction: column;
    }
    
    .card-stats {
        width: 100%;
    }
}