<?php  include 'concha.php';?>  
<?php  $titulo = "$nombresitio / Resultados de Loterias"; include 'arriba_full.php' ?> 
<?php
  $m = date('m');
  $d = date('d');
  $a = date('Y');
?>

<style>
  /* ===== Estética SOLO para esta vista (scoped) ===== */
  #content > div{
    background:#fff;
    border:1px solid rgba(0,0,0,.06);
    border-radius:16px;
    box-shadow:0 10px 30px rgba(0,0,0,.05);
    padding:16px 16px 10px;
  }

  /* Título / widget */
  #content .widget-head{ margin-bottom:18px !important; }
  #content .widget-head h3,
  #content .widget-title{
    letter-spacing:.4px;
  }

  /* Grilla de tapas */
  #content .grid{ margin-top:8px; }

  /* Convertimos la tabla en grid sin romper el HTML existente */
  #content #table3{
    width:100% !important;
    margin:0;
  }
  #content #table3,
  #content #table3 tbody{
    display:grid;
    grid-template-columns:repeat(auto-fit, minmax(190px, 1fr));
    gap:16px;
    align-items:start;
  }
  #content #table3 tr{ display:contents; }
  #content #table3 td{
    padding:0 !important;
    border:none !important;
    background:transparent !important;
  }

  /* “Tarjeta” de cada tapa */
  #content #table3 a#imagensidebar{
    display:block;
    background:#fff;
    border-radius:14px;
    overflow:hidden;
    border:1px solid rgba(0,0,0,.06);
    box-shadow:0 10px 25px rgba(0,0,0,.08);
    transition:transform .18s ease, box-shadow .18s ease;
  }
  #content #table3 a#imagensidebar:hover{
    transform:translateY(-3px);
    box-shadow:0 16px 40px rgba(0,0,0,.14);
  }
  #content #table3 a#imagensidebar img{
    width:100%;
    height:auto;
    display:block;
  }

  /* Mobile: 2 columnas prolijas */
  @media (max-width: 575.98px){
    #content #table3,
    #content #table3 tbody{
      grid-template-columns:repeat(2, minmax(0, 1fr));
      gap:12px;
    }
  }
</style>

<div id="content" class="news-summary content <? if ($estiloweb == 4 || 61) { ?> col-lg-8 col-md-8<? } else { ?>col-lg-9 col-md-9 <? } ?> col-sm-12 col-12 p-0" >
  <div>
    <div class="widget-head" style="margin-bottom:43px;">
      <h3 <? if ($estiloweb <= 3){echo 'style="padding: 1px 5px 1px 5px; background-color:'; echo $d_color_fondo_menu; echo ';font-family:'; echo $style_titulo; echo ';font-size:25px;color:#ffffff;"'; } else {echo 'class="widget-title"';} ?>>
        <span><? echo $lang_100084 ?></span>
      </h3>
    </div>

    <div class="grid">
      <!-- TABLE CONSTRUCTION-->
      <table id='table3' style="text-align:center; width: 100%;">
        <script>
          // Intenta reemplazar una fecha embebida en la URL por la del día anterior.
          // Si no detecta una fecha en la URL, devuelve '' (sin fallback).
          function diarioPrevUrl(url){
            if(!url) return '';
            url = String(url);

            // YYYY-MM-DD o YYYY/MM/DD
            var m = url.match(/(\d{4})([\/\-])(\d{2})([\/\-])(\d{2})/);
            if (m){
              var y = parseInt(m[1],10), mon = parseInt(m[3],10), d = parseInt(m[5],10);
              var dt = new Date(Date.UTC(y, mon-1, d));
              dt.setUTCDate(dt.getUTCDate()-1);
              var yy = dt.getUTCFullYear();
              var mm = ('0'+(dt.getUTCMonth()+1)).slice(-2);
              var dd = ('0'+dt.getUTCDate()).slice(-2);
              return url.replace(m[0], ''+yy+m[2]+mm+m[4]+dd);
            }

            // DD-MM-YYYY o DD/MM/YYYY
            m = url.match(/(\d{2})([\/\-])(\d{2})([\/\-])(\d{4})/);
            if (m){
              var d2 = parseInt(m[1],10), mon2 = parseInt(m[3],10), y2 = parseInt(m[5],10);
              var dt2 = new Date(Date.UTC(y2, mon2-1, d2));
              dt2.setUTCDate(dt2.getUTCDate()-1);
              var dd2 = ('0'+dt2.getUTCDate()).slice(-2);
              var mm2 = ('0'+(dt2.getUTCMonth()+1)).slice(-2);
              var yy2 = dt2.getUTCFullYear();
              return url.replace(m[0], ''+dd2+m[2]+mm2+m[4]+yy2);
            }

            // YYYYMMDD (limitado a 20xx para evitar reemplazar otras cosas)
            m = url.match(/(20\d{2})(\d{2})(\d{2})/);
            if (m){
              var y3 = parseInt(m[1],10), mon3 = parseInt(m[2],10), d3 = parseInt(m[3],10);
              var dt3 = new Date(Date.UTC(y3, mon3-1, d3));
              dt3.setUTCDate(dt3.getUTCDate()-1);
              var yy3 = dt3.getUTCFullYear();
              var mm3 = ('0'+(dt3.getUTCMonth()+1)).slice(-2);
              var dd3 = ('0'+dt3.getUTCDate()).slice(-2);
              return url.replace(m[0], ''+yy3+mm3+dd3);
            }

            return '';
          }

          // 1er error: prueba con URL del día anterior
          // 2do error: elimina la tarjeta (nada)
          function diarioFallback(img){
            try{
              var $img = $(img);
              var prev = $img.attr('data-prev-src') || '';
              var tried = $img.attr('data-tried') || '';

              if (!prev){
                $img.closest('.grid-item').remove();
                return;
              }

              if (tried === '1'){
                $img.closest('.grid-item').remove();
                return;
              }

              $img.attr('data-tried','1');

              // También actualiza el href (imagen grande del lightbox)
              var $a = $img.closest('a');
              var prevHref = $a.attr('data-prev-href') || '';
              if (prevHref) $a.attr('href', prevHref);

              $img.attr('src', prev);
            }catch(e){
              try{ $(img).closest('.grid-item').remove(); }catch(_e){}
            }
          }

          $(document).ready(function () {
            $.getJSON("https://diarios.x7.com.ar/api/v1/preferencias/diarios_json.php", function (data3) {

              var student3 = '';

              $.each(data3, function (key, value3) {

                function card(chico, grande){
                  var prevCh = diarioPrevUrl(chico);
                  var prevGr = diarioPrevUrl(grande);

                  student3 += '<div class="grid-item" style="padding-bottom: 14px;"><tr><td>';
                  student3 +=   '<a class="" data-lightbox="example-set" id="imagensidebar" href="' + grande + '" data-prev-href="' + (prevGr || '') + '">';
                  student3 +=     '<img src="' + chico + '" data-prev-src="' + (prevCh || '') + '" onerror="diarioFallback(this)">';
                  student3 +=   '</a>';
                  student3 += '</td></tr></div>';
                }

                card(value3.clarin_chico,   value3.clarin_grande);
                card(value3.nacion_chico,   value3.nacion_grande);
                card(value3.pagina12_chico, value3.pagina12_grande);
                card(value3.la_voz_chico,   value3.la_voz_grande);
                card(value3.ole_chico,      value3.ole_grande);

              });

              $('#table3').append(student3);
            });
          });
        </script>
      </table>
    </div>
  </div>
</div>

<?php include 'abajo_full.php' ;?>