/* ==== Predicción Climática — identidad visual Bytelink ==== */

/* Tipografía corporativa: Poppins (servida localmente) */
@font-face {
  font-family: "Poppins"; font-style: normal; font-weight: 300;
  src: url("fonts/poppins-latin-300-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Poppins"; font-style: normal; font-weight: 400;
  src: url("fonts/poppins-latin-400-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Poppins"; font-style: normal; font-weight: 500;
  src: url("fonts/poppins-latin-500-normal.woff2") format("woff2");
}
@font-face {
  font-family: "Poppins"; font-style: normal; font-weight: 600;
  src: url("fonts/poppins-latin-600-normal.woff2") format("woff2");
}

/* Paleta según el Manual de Identidad Visual Bytelink */
:root {
  --bg: #170041;            /* violeta oscuro corporativo */
  --bg-soft: #0022af33;
  --card: #ffffff;
  --surface: #F6F9FB;
  --text: #161B27;
  --muted: #7E838E;
  --border: #D1D6DB;
  --cyan: #00B3FF;
  --primary: #006DFF;
  --primary-dark: #0022AF;
  --grad: linear-gradient(135deg, #00B3FF 0%, #006DFF 89%, #0022AF 100%);
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --warning: #d97706;
  --warning-bg: #fffbeb;
  --ok: #16a34a;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(22, 27, 39, .1), 0 4px 14px rgba(22, 27, 39, .06);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: "Poppins", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  background: var(--surface);
  color: var(--text);
  min-height: 100vh;
}

/* ---- Login ---- */
.login-body {
  display: flex; align-items: center; justify-content: center; flex-direction: column;
  min-height: 100vh;
  background: linear-gradient(160deg, #170041 0%, #1A0350 55%, #0022AF 170%);
}
.login-card {
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow);
  padding: 40px 36px; width: 100%; max-width: 380px; text-align: center;
}
.login-logo-img { width: 250px; max-width: 88%; margin-bottom: 10px; }
.login-card h1 { margin: 8px 0 4px; font-size: 21px; font-weight: 600; color: #170041; }
.login-footer {
  margin-top: 22px; color: #B5BAC1; font-size: 12px; text-align: center;
}
.login-sub { color: var(--muted); margin: 0 0 24px; font-size: 14px; }
.login-card form { text-align: left; }
.login-card label { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 4px; }
.login-card input {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border);
  border-radius: 8px; font-size: 15px;
}
.login-error {
  margin-top: 14px; background: var(--danger-bg); color: var(--danger);
  border: 1px solid #fecaca; border-radius: 8px; padding: 10px 12px; font-size: 14px;
}

/* ---- Botones e inputs ---- */
.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text);
  padding: 9px 16px; border-radius: 8px; font-size: 14px; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--surface); }
.btn-primary {
  background: var(--grad); border-color: transparent; color: #fff; font-weight: 500;
}
.btn-primary:hover {
  background: linear-gradient(135deg, #006DFF 0%, #0022AF 100%);
}
.btn-ghost { background: transparent; border-color: rgba(255,255,255,.3); color: #fff; text-decoration: none; }
.btn-ghost:hover { background: rgba(255,255,255,.12); }
.btn-block { width: 100%; margin-top: 22px; }
.btn-small { padding: 5px 12px; font-size: 13px; }
.btn-danger-outline { color: var(--danger); border-color: #fecaca; }
.btn-danger-outline:hover { background: var(--danger-bg); }
.input {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; background: #fff;
}
.input.grow { flex: 1; }
.icon-btn {
  background: transparent; border: none; font-size: 20px; cursor: pointer;
  padding: 4px 8px; border-radius: 8px;
}
.icon-btn:hover { background: rgba(255,255,255,.15); }
button, input, select { font-family: inherit; }
.icon-btn.muted-bell { filter: grayscale(1); opacity: .55; }

/* ---- Barra superior ---- */
.topbar {
  display: flex; align-items: center; gap: 20px; flex-wrap: wrap;
  background: var(--bg); color: #fff; padding: 10px 22px;
  position: sticky; top: 0; z-index: 50;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.logo-icon { height: 30px; width: auto; display: block; }
.logo-word {
  font-weight: 600; font-size: 19px; letter-spacing: -.5px; color: #fff; line-height: 1;
}
.app-title { font-weight: 300; font-size: 19px; letter-spacing: -.3px; color: #fff; line-height: 1; margin-left: 1px; }
.topbar-nav { display: flex; gap: 4px; flex: 1; flex-wrap: wrap; }
.nav-btn {
  background: transparent; color: #B5BAC1; border: none; padding: 8px 14px;
  border-radius: 8px; cursor: pointer; font-size: 14px; font-family: inherit;
}
.nav-btn:hover { background: rgba(255,255,255,.1); color: #fff; }
.nav-btn.active { background: var(--grad); color: #fff; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-chip { font-size: 14px; }
.user-chip small { color: #94a3b8; }

/* ---- Banner de alarma ---- */
.alarm-banner {
  display: flex; align-items: center; gap: 14px; justify-content: center;
  background: var(--danger); color: #fff; padding: 10px 20px;
  font-weight: 600; animation: pulse 1s infinite alternate;
  position: sticky; top: 52px; z-index: 40;
}
@keyframes pulse { from { filter: brightness(1); } to { filter: brightness(1.25); } }
.alarm-banner[hidden] { display: none; }
.alarm-icon { font-size: 20px; }

/* ---- Contenido ---- */
.content { max-width: 1200px; margin: 0 auto; padding: 24px 20px 60px; }
.view-head {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px; margin-bottom: 18px;
}
.view-head h2 { margin: 0; font-size: 22px; }
.view-actions { display: flex; gap: 10px; align-items: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.note {
  background: var(--warning-bg); border: 1px solid #fde68a; color: #92400e;
  border-radius: 8px; padding: 10px 14px; font-size: 14px; margin-bottom: 16px;
}
.ok-msg { color: var(--ok); font-weight: 600; margin-left: 10px; }

/* ---- Selector de sitios ---- */
.site-tabs {
  display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px;
}
.site-tab {
  display: inline-flex; align-items: center; gap: 8px;
  background: var(--card); border: 1px solid var(--border); border-radius: 999px;
  padding: 9px 18px; font-size: 14px; cursor: pointer; font-family: inherit;
  color: var(--text); transition: border-color .15s, box-shadow .15s;
}
.site-tab:hover { border-color: var(--primary); }
.site-tab.active {
  background: var(--grad); color: #fff; border-color: transparent; font-weight: 500;
  box-shadow: 0 2px 10px rgba(0, 109, 255, .35);
}
.tab-dot {
  width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex: none;
}
.tab-dot.danger { background: var(--danger); animation: pulse 1s infinite alternate; }
.tab-dot.warning { background: var(--warning); }
.tab-dot.ok { background: var(--ok); }
.site-tab.active .tab-dot.ok { background: #b7f7cd; }

/* ---- Detalle de sitio (pantalla completa) ---- */
.site-detail {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 22px 24px; border-top: 4px solid var(--primary);
}
.site-detail.has-danger { border-top-color: var(--danger); }
.site-detail.has-warning { border-top-color: var(--warning); }
.site-detail h3 { margin: 0 0 2px; font-size: 21px; }
.sd-head {
  display: flex; justify-content: space-between; align-items: start;
  gap: 14px; flex-wrap: wrap; margin-bottom: 14px;
}
.sd-badges { display: flex; gap: 8px; flex-wrap: wrap; }
.badge.warn { background: var(--warning-bg); color: var(--warning); }
.sd-grid {
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 22px; align-items: start;
}
@media (max-width: 860px) { .sd-grid { grid-template-columns: 1fr; } }
.current-temp.big { font-size: 54px; }
.sd-current .metrics { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.sd-sub {
  margin: 22px 0 10px; font-size: 13px; text-transform: uppercase;
  letter-spacing: .6px; color: var(--primary-dark); font-weight: 600;
}

/* ---- Comportamiento por hora ---- */
.hourly-row {
  display: flex; gap: 6px; overflow-x: auto; padding-bottom: 8px;
  scrollbar-width: thin;
}
.hour-cell {
  flex: 0 0 74px; text-align: center; background: var(--surface);
  border-radius: 8px; padding: 8px 4px; font-size: 12px; border: 1px solid transparent;
}
.hour-cell.hr-warning { background: var(--warning-bg); border-color: #fde68a; }
.hour-cell.hr-danger { background: var(--danger-bg); border-color: #fecaca; }
.hc-time { font-weight: 600; color: var(--primary-dark); }
.hc-ico { font-size: 14px; margin: 2px 0; }
.hc-temp { font-weight: 700; font-size: 14px; }
.hc-rain { color: var(--primary); margin-top: 2px; }
.hc-wind { color: var(--muted); margin-top: 1px; font-size: 11.5px; }

/* Pronóstico de 5 días ampliado */
.forecast-row.big .fc-day { padding: 12px 8px; font-size: 12.5px; }
.forecast-row.big .fc-cond {
  color: var(--muted); font-size: 11.5px; margin-top: 2px; min-height: 28px;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.forecast-row.big .fc-wind { color: var(--muted); margin-top: 2px; }

/* Lista de sitios en el modal de usuario */
.sites-checklist {
  max-height: 180px; overflow-y: auto; border: 1px solid var(--border);
  border-radius: 8px; padding: 8px 12px; margin-top: 4px;
}
.site-check { margin: 6px 0; font-weight: 400; }

/* Utilidades de configuración / modal (evitan estilos inline por la CSP) */
.thr-grid-mt { margin-top: 14px; }
.modal-sep { border: none; border-top: 1px solid var(--border); margin: 16px 0 4px; }

/* ---- Tarjetas de sitios ---- */
.cards-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr));
  gap: 18px;
}
.site-card {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 18px; border-top: 4px solid var(--primary); position: relative;
}
.site-card.has-danger { border-top-color: var(--danger); }
.site-card.has-warning { border-top-color: var(--warning); }
.site-card h3 { margin: 0 0 2px; font-size: 17px; }
.site-meta { color: var(--muted); font-size: 12.5px; margin-bottom: 12px; }
.current-row { display: flex; align-items: center; gap: 14px; margin-bottom: 8px; }
.current-temp { font-size: 38px; font-weight: 700; line-height: 1; }
.current-cond { font-size: 14px; color: var(--muted); }
.wx-icon { width: 48px; height: 48px; }
.metrics {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px 14px;
  font-size: 13px; color: #334155; margin: 10px 0;
}
.metrics b { font-weight: 600; }
.day-summary {
  background: var(--surface); border-radius: 8px; padding: 10px 12px;
  font-size: 13.5px; margin: 10px 0; line-height: 1.45;
}
.day-summary .ds-title { font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); display: block; margin-bottom: 3px; }
.forecast-row { display: flex; gap: 6px; margin-top: 10px; }
.fc-day {
  flex: 1; text-align: center; background: var(--surface); border-radius: 8px;
  padding: 8px 4px; font-size: 12px;
}
.fc-day .fc-name { font-weight: 700; text-transform: capitalize; }
.fc-day .fc-temps { margin-top: 3px; }
.fc-day .fc-rain { color: var(--primary); margin-top: 2px; }
.alerts-list { margin-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.alert-item {
  border-radius: 8px; padding: 8px 12px; font-size: 13px; display: flex; gap: 8px; align-items: start;
}
.alert-item.danger { background: var(--danger-bg); color: #991b1b; border: 1px solid #fecaca; }
.alert-item.warning { background: var(--warning-bg); color: #92400e; border: 1px solid #fde68a; }
.alert-time {
  flex: none; font-weight: 700; font-size: 12px; padding: 1px 8px;
  border-radius: 999px; background: rgba(255,255,255,.75);
  border: 1px solid currentColor; font-variant-numeric: tabular-nums;
}
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
}
.badge.ok { background: #dcfce7; color: var(--ok); }
.badge.err { background: var(--danger-bg); color: var(--danger); }
.badge.demo { background: #EDF2F5; color: var(--primary-dark); }
.empty {
  grid-column: 1 / -1; text-align: center; color: var(--muted);
  padding: 60px 0; font-size: 15px;
}

/* ---- Tablas ---- */
.table {
  width: 100%; border-collapse: collapse; background: var(--card);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.table th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--primary-dark); font-weight: 600; padding: 12px 16px; background: #EDF2F5;
}
.table td { padding: 12px 16px; border-top: 1px solid var(--border); font-size: 14px; }
.table td.actions { text-align: right; white-space: nowrap; }
.table td.actions .btn { margin-left: 6px; }

/* ---- Paneles de configuración ---- */
.panel {
  background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 20px 22px; margin-bottom: 20px;
}
.panel h3 { margin: 0 0 6px; }
.form-row { display: flex; gap: 10px; flex-wrap: wrap; margin: 12px 0; }
.check-row { display: flex; align-items: center; gap: 8px; font-size: 14px; margin-top: 10px; }
.thr-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px; margin: 14px 0 18px;
}
.thr-grid label { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; font-weight: 600; }

/* ---- Modal ---- */
.modal-back {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .55);
  display: flex; align-items: center; justify-content: center; z-index: 100;
}
.modal-back[hidden] { display: none; }
.modal {
  background: #fff; border-radius: 14px; padding: 24px; width: 100%; max-width: 440px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.modal h3 { margin: 0 0 16px; }
.modal label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
.modal .input, .modal select { width: 100%; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; }
  .content { padding: 16px 12px 60px; }
  .forecast-row { flex-wrap: wrap; }
}

/* ==== Impresión del reporte de predicción climática ==== */
.print-only { display: none; }
.ph-logo { height: 44px; width: auto; }
.ph-title {
  font-size: 19px; font-weight: 600; color: #170041; margin-top: 8px;
}
.ph-meta { font-size: 12px; color: #464C5A; margin: 4px 0 14px; }

@media print {
  @page { margin: 14mm; }
  body { background: #fff !important; }
  .topbar, #alarmBanner, .view-head, #sourceNote, .site-tabs,
  #lastUpdate, .modal-back, .demo-ribbon, #demoLoginView { display: none !important; }
  .content { max-width: none; padding: 0; }
  .print-only { display: block !important; }
  #printHeader { border-bottom: 2px solid #006DFF; margin-bottom: 12px; }
  .site-detail {
    box-shadow: none !important; border: 1px solid #D1D6DB;
    border-top: 4px solid #006DFF;
  }
  .sd-grid, .forecast-row, .alert-item, .day-summary { page-break-inside: avoid; }
  .site-detail.has-danger { border-top-color: #dc2626; }
  .site-detail.has-warning { border-top-color: #d97706; }
  .hourly-row { flex-wrap: wrap; overflow: visible; }
  .hour-cell { flex: 0 0 66px; }
  .sd-grid { grid-template-columns: 1fr 1fr; }
  .alert-item, .hour-cell, .fc-day, .day-summary {
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
}
