/* ================================
   HISTORY (tabla de históricos)
   ================================ */

:root{
  --hist-card-radius: 18px;
  --hist-th-weight: 600;
  --hist-cell-px: 14px;
  --hist-cell-py: 12px;
  --hist-row-gap: 8px;

  --hist-border: rgba(255,255,255,.08);
  --hist-th-bg: rgba(255,255,255,.06);
  --hist-row-alt: rgba(255,255,255,.04);
  --hist-row-hover: rgba(255,255,255,.08);
  --hist-shadow: 0 10px 30px rgba(0,0,0,.25);

  --hist-files-bg: rgba(255,255,255,.03);
  --hist-files-icon-w: 160px;
  --hist-files-icon-max: 140px;
  --hist-files-gap: 18px;
}

html[data-theme="light"],
body[data-theme="light"],
.theme-light{
  --hist-border: rgba(0,0,0,.08);
  --hist-th-bg: rgba(0,0,0,.04);
  --hist-row-alt: rgba(0,0,0,.03);
  --hist-row-hover: rgba(0,0,0,.06);
  --hist-shadow: 0 10px 30px rgba(0,0,0,.1);
  --hist-files-bg: rgba(0,0,0,.02);
}

@media (prefers-color-scheme: light){
  :root:not([data-theme]):not(.theme-dark){
    --hist-border: rgba(0,0,0,.08);
    --hist-th-bg: rgba(0,0,0,.04);
    --hist-row-alt: rgba(0,0,0,.03);
    --hist-row-hover: rgba(0,0,0,.06);
    --hist-shadow: 0 10px 30px rgba(0,0,0,.1);
    --hist-files-bg: rgba(0,0,0,.02);
  }
}

/* Cabecera propia de página */
.history-head{
  display:flex;
  align-items:center;
  justify-content:flex-start;
  gap:14px;
  margin-bottom:10px;
  flex-wrap:wrap;
}

.history-head .page-title{
  margin:0;
}

.history-table-top{
  display:flex;
  justify-content:flex-end;
  align-items:center;
  margin: 2px 0 10px;
}

.history-episodes-btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  min-height:38px;
  padding: 0 16px;
  border-radius:999px;
  border:1px solid color-mix(in oklab, var(--brand) 38%, var(--hist-border)) !important;
  background:
    linear-gradient(180deg,
      color-mix(in oklab, var(--brand) 92%, white 8%),
      color-mix(in oklab, var(--brand) 84%, black 16%)
    ) !important;
  color:#fff !important;
  font-weight:600;
  font-size:.95rem;
  line-height:1;
  white-space:nowrap;
  box-shadow:
    0 6px 16px color-mix(in oklab, var(--brand) 22%, transparent),
    inset 0 1px 0 rgba(255,255,255,.14);
  transition:
    transform .16s ease,
    box-shadow .16s ease,
    filter .16s ease;
}

.history-episodes-btn:hover{
  transform:translateY(-1px);
  filter:saturate(1.04);
  box-shadow:
    0 8px 18px color-mix(in oklab, var(--brand) 28%, transparent),
    inset 0 1px 0 rgba(255,255,255,.16);
}

.history-episodes-btn:focus-visible{
  outline:none;
  box-shadow:
    0 0 0 3px color-mix(in oklab, var(--brand) 20%, transparent),
    0 8px 18px color-mix(in oklab, var(--brand) 28%, transparent),
    inset 0 1px 0 rgba(255,255,255,.16);
}

/* Contenedor principal */
#hist-output.card{
  border-radius: var(--hist-card-radius);
  box-shadow: var(--hist-shadow);
  overflow: hidden;
  border: 1px solid var(--hist-border);
  background: transparent;
}

/* Skeleton */
#hist-skel{
  padding: 16px;
  font-size: .95rem;
  opacity: .8;
}

/* Wrapper con scroll horizontal en móvil */
.table-wrap{
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.table-wrap table{
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  min-width: 840px;
}

.table-wrap thead th{
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--hist-th-bg);
  backdrop-filter: saturate(140%) blur(6px);
  font-weight: var(--hist-th-weight);
  text-align: center;
  padding: calc(var(--hist-cell-py) + 2px) var(--hist-cell-px);
  white-space: nowrap;
  border-bottom: 1px solid var(--hist-border);
}

.table-wrap thead th:nth-child(1)::before{content:"📅"; margin-right:.45rem;}
.table-wrap thead th:nth-child(2)::before{content:"🌡️"; margin-right:.35rem;}
.table-wrap thead th:nth-child(3)::before{content:"🌡️"; margin-right:.35rem;}
.table-wrap thead th:nth-child(4)::before{content:"💧"; margin-right:.35rem;}
.table-wrap thead th:nth-child(5)::before{content:"💧"; margin-right:.35rem;}
.table-wrap thead th:nth-child(6)::before{content:"🌬️"; margin-right:.35rem;}
.table-wrap thead th:nth-child(7)::before{content:"🔼"; margin-right:.35rem;}
.table-wrap thead th:nth-child(8)::before{content:"🔽"; margin-right:.35rem;}
.table-wrap thead th:nth-child(9)::before{content:"☀️"; margin-right:.35rem;}
.table-wrap thead th:nth-child(10)::before{content:"🟣"; margin-right:.35rem;}
.table-wrap thead th:nth-child(11)::before{content:"🌧️"; margin-right:.35rem;}

.table-wrap td{
  padding: var(--hist-cell-py) var(--hist-cell-px);
  border-bottom: 1px solid var(--hist-border);
  text-align: center;
  vertical-align: middle;
  white-space: nowrap;
}

.table-wrap td:first-child,
.table-wrap thead th:first-child{
  text-align: left;
}

.table-wrap tbody tr:nth-child(even) td{
  background: var(--hist-row-alt);
}

.table-wrap tbody tr:hover td{
  background: var(--hist-row-hover);
}

.table-wrap tbody tr:first-child td:first-child{ border-top-left-radius: calc(var(--hist-card-radius) - 2px); }
.table-wrap tbody tr:first-child td:last-child{ border-top-right-radius: calc(var(--hist-card-radius) - 2px); }
.table-wrap tbody tr:last-child  td:first-child{ border-bottom-left-radius: calc(var(--hist-card-radius) - 2px); }
.table-wrap tbody tr:last-child  td:last-child{ border-bottom-right-radius: calc(var(--hist-card-radius) - 2px); }

.table-wrap td{
  font-variant-numeric: tabular-nums;
}

/* Controles y nav */
#hist-nav{
  display: flex;
  gap: 8px;
  margin: 8px 0 14px;
}

.controls{
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-bottom: 14px;
}

.controls .ctrl{
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 10px;
}

.controls .lbl{ opacity: .8; font-size: .95rem; }

#hist-nav .btn.active{
  transform: translateY(-1px);
}

/* Responsivo */
@media (max-width: 920px){
  .table-wrap table{
    min-width: 760px;
  }

  .history-table-top{
    justify-content:flex-start;
  }

  .history-episodes-btn{
    width:auto;
    text-align:center;
  }
}

@media (max-width: 600px){
  .table-wrap table{
    min-width: 720px;
  }
  .table-wrap td,
  .table-wrap thead th{
    padding: 10px 12px;
  }
}

@media print{
  #site-header,
  #site-footer,
  #hist-nav,
  .controls,
  #hist-files,
  .history-episodes-btn{
    display: none !important;
  }
  #history{ padding: 0 !important; }
  #hist-output.card{ border: 0; box-shadow: none; }
  .table-wrap thead th{ position: static; backdrop-filter: none; }
}

/* ===== TXT historics (extra) ===== */
.hist-files{
  margin-top: 12px;
  padding: 14px 16px;
  border: 1px solid var(--hist-border);
  border-radius: 14px;
  background: var(--hist-files-bg);
  box-shadow: var(--hist-shadow);
}

.hist-files-grid{
  display: grid;
  grid-template-columns: 1fr var(--hist-files-icon-w);
  gap: var(--hist-files-gap);
  align-items: start;
}

.hist-files-left{ order: 1; min-width: 0; }
.hist-files-right{ order: 2; display:flex; justify-content:center; align-items:flex-start; }

.hist-files-row{
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  padding: 6px 0;
}

.hist-files-row .lbl{
  opacity: .85;
  font-size: .95rem;
  margin-right: 6px;
  min-width: 190px;
}

#hf-month,
#hf-year{
  min-width: 420px;
  max-width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--hist-border);
  background: rgba(255,255,255,.04);
  color: inherit;
}

.hist-files-note{
  margin-top: 8px;
  opacity: .65;
  font-size: .85rem;
}

.hist-davis-icon{
  width: 100%;
  max-width: var(--hist-files-icon-max);
  height: auto;
  display: block;
  object-fit: contain;
  border-radius: 12px;
  opacity: .95;
}

.hist-noaa-wrap{
  margin-top: 14px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.hist-noaa-img{
  display: block;
  max-width: 100%;
  height: auto;
  object-fit: contain;
  border-radius: 12px;
}

@media (max-width: 760px){
  :root{
    --hist-files-icon-w: 120px;
    --hist-files-icon-max: 90px;
    --hist-files-gap: 12px;
  }

  .hist-files{
    padding: 12px 12px;
  }

  .hist-files-grid{
    grid-template-columns: 1fr var(--hist-files-icon-w);
    gap: var(--hist-files-gap);
    align-items: start;
  }

  .hist-files-row .lbl{
    min-width: 100%;
    margin-right: 0;
  }

  #hf-month,
  #hf-year{
    min-width: 0;
    width: min(52vw, 320px);
  }

  .hist-files-row .btn{
    padding-left: 14px;
    padding-right: 14px;
  }

  .hist-noaa-wrap{
    margin-top: 12px;
  }
}

@media (max-width: 390px){
  :root{
    --hist-files-icon-w: 108px;
    --hist-files-icon-max: 82px;
  }

  #hf-month,
  #hf-year{
    width: min(56vw, 300px);
  }
}

.hist-noaa-info{
  margin-top: 12px;
  padding: 12px 14px;
  border: 1px solid var(--hist-border);
  border-radius: 14px;
  background: rgba(255,255,255,.03);
}

.hist-noaa-info-title{
  font-weight: 600;
  opacity: .92;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.hist-noaa-info-title::before{
  content: "ℹ️";
  font-size: 1rem;
  line-height: 1;
}

.hist-noaa-info-text{
  margin: 0;
  opacity: .82;
  line-height: 1.45;
  font-size: .95rem;
}

@media (max-width: 760px){
  .hist-noaa-info{
    padding: 12px 12px;
  }
  .hist-noaa-info-text{
    font-size: .95rem;
  }
}
