/* ================================================================
   PRECIOLUZ — Estilos
   ================================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:           #f1f5f9;
  --surface:      #ffffff;
  --border:       #e2e8f0;
  --text:         #0f172a;
  --text-muted:   #64748b;

  --punta:        #dc2626;
  --punta-bg:     #fef2f2;
  --punta-border: #fecaca;

  --llano:        #d97706;
  --llano-bg:     #fffbeb;
  --llano-border: #fde68a;

  --valle:        #059669;
  --valle-bg:     #ecfdf5;
  --valle-border: #a7f3d0;

  --cheap:        #059669;
  --cheap-bg:     #ecfdf5;
  --cheap-border: #6ee7b7;

  --expensive:        #dc2626;
  --expensive-bg:     #fef2f2;
  --expensive-border: #fca5a5;

  --radius:    12px;
  --radius-sm: 8px;
  --shadow:    0 1px 3px rgba(0,0,0,.06), 0 4px 12px rgba(0,0,0,.04);
  --font:      -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.container {
  max-width: 1300px;
  margin: 0 auto;
  padding: 0 1.25rem;
}

/* ── Header ──────────────────────────────────────────────── */

.site-header {
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
  color: #fff;
  padding: 1.75rem 0 1.5rem;
}

.site-header h1 {
  font-size: clamp(1.4rem, 2.5vw, 1.9rem);
  font-weight: 800;
  letter-spacing: -0.025em;
}

.site-header .subtitle {
  color: #94a3b8;
  font-size: 0.82rem;
  margin-top: 0.2rem;
}

.header-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 0.9rem;
  flex-wrap: wrap;
}

.header-meta .badge {
  background: rgba(255,255,255,.08);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 100px;
  padding: 0.25rem 0.8rem;
  font-size: 0.78rem;
  color: #cbd5e1;
}

.header-meta .badge strong { color: #fff; }

.btn-refresh {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 100px;
  padding: 0.4rem 0.9rem;
  min-height: 36px;
  font-size: 0.78rem;
  color: #e2e8f0;
  cursor: pointer;
  transition: background .15s;
}

.btn-refresh:hover { background: rgba(255,255,255,.18); }

.btn-whatsapp {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #25d366;
  border: 1px solid rgba(255,255,255,.2);
  border-radius: 100px;
  padding: 0.4rem 0.9rem;
  min-height: 36px;
  font-size: 0.78rem;
  font-weight: 600;
  color: #fff;
  text-decoration: none;
  transition: background .15s;
}

.btn-whatsapp:hover { background: #1ebe5d; }

/* ── Main ────────────────────────────────────────────────── */

main { padding: 1.5rem 0 3rem; }

/* ── Notice banner ───────────────────────────────────────── */

.notice-banner {
  display: flex;
  gap: 0.875rem;
  align-items: flex-start;
  padding: 1rem 1.25rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1.5rem;
  border: 1px solid transparent;
  animation: fadeIn .3s ease;
}

.notice-banner.info {
  background: #eff6ff;
  border-color: #bfdbfe;
  color: #1e40af;
}

.notice-banner.warning {
  background: #fffbeb;
  border-color: #fde68a;
  color: #92400e;
}

.notice-icon { font-size: 1.15rem; flex-shrink: 0; padding-top: 1px; }

.notice-title {
  font-weight: 700;
  font-size: 0.875rem;
  margin-bottom: 0.2rem;
}

.notice-message { font-size: 0.82rem; line-height: 1.55; }

.notice-hint {
  font-size: 0.78rem;
  margin-top: 0.35rem;
  opacity: .85;
  font-style: italic;
}

/* ── Loading ─────────────────────────────────────────────── */

.loading-state {
  text-align: center;
  padding: 5rem 1rem;
  color: var(--text-muted);
}

.spinner {
  width: 2rem;
  height: 2rem;
  border: 3px solid #e2e8f0;
  border-top-color: #3b82f6;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 0 auto 1rem;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error ───────────────────────────────────────────────── */

.error-state {
  background: var(--expensive-bg);
  border: 1px solid var(--expensive-border);
  border-radius: var(--radius-sm);
  padding: 1.25rem;
  color: var(--expensive);
  margin-bottom: 1.5rem;
}

/* ── Periods grid — mobile first ─────────────────────────── */

.periods-grid {
  display: grid;
  grid-template-columns: 1fr;       /* móvil: una columna */
  gap: 1rem;
  margin-bottom: 2rem;
  animation: fadeIn .35s ease;
}

@media (min-width: 1024px) {
  .periods-grid                { grid-template-columns: repeat(3, 1fr); gap: 1.25rem; }
  .periods-grid.all-valle      { grid-template-columns: 1fr; max-width: 600px; }
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ── Period card ─────────────────────────────────────────── */

.period-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Headers */
.period-header {
  padding: 1rem 1.25rem 0.875rem;
  color: #fff;
}

.period-punta .period-header { background: var(--punta); }
.period-llano .period-header { background: var(--llano); }
.period-valle .period-header { background: var(--valle); }

.period-title {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.05rem;
  font-weight: 800;
  letter-spacing: -0.01em;
}

.period-badge {
  background: rgba(255,255,255,.22);
  border-radius: 100px;
  padding: 0.15rem 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.period-subtitle {
  font-size: 0.75rem;
  color: rgba(255,255,255,.78);
  margin-top: 0.2rem;
}

/* ── Extreme cards ───────────────────────────────────────── */

.extreme-cards {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  padding: 0.875rem;
  border-bottom: 1px solid var(--border);
}

.extreme-card {
  border-radius: var(--radius-sm);
  padding: 0.75rem 0.625rem;
  text-align: center;
  border: 1px solid transparent;
}

.extreme-card.cheap {
  background: var(--cheap-bg);
  border-color: var(--cheap-border);
}

.extreme-card.expensive {
  background: var(--expensive-bg);
  border-color: var(--expensive-border);
}

.card-label {
  font-size: 0.67rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 0.4rem;
}

.cheap .card-label   { color: var(--cheap); }
.expensive .card-label { color: var(--expensive); }

.card-time {
  font-size: 1.6rem;
  font-weight: 800;
  line-height: 1;
  color: var(--text);
  letter-spacing: -0.03em;
}

.card-price {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

.card-price strong { color: var(--text); font-weight: 700; }

/* ── Hours table ─────────────────────────────────────────── */

.hours-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
  flex: 1;
}

.hours-table thead tr {
  border-bottom: 1px solid var(--border);
}

.hours-table thead th {
  padding: 0.45rem 0.75rem;
  text-align: left;
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

@media (min-width: 640px) {
  .hours-table thead th { padding: 0.45rem 1rem; }
}

.hours-table thead th:last-child { text-align: right; }

.hours-table tbody tr {
  border-bottom: 1px solid #f1f5f9;
  transition: background .1s;
}

.hours-table tbody tr:last-child { border-bottom: none; }
.hours-table tbody tr:hover { background: #f8fafc; }

/* Separador de subgrupos (mañana / tarde / noche) */
.hours-table tr.sub-group-sep td {
  padding: 0.35rem 0.75rem;
  background: #f1f5f9;
  border-top: 2px solid var(--border);
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.hours-table tr.sub-group-sep:first-child td {
  border-top: none;  /* el primero no necesita borde superior */
}

.sub-group-label {
  font-size: 0.67rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
}

.sub-group-range {
  font-size: 0.67rem;
  color: #94a3b8;
  margin-left: 0.4rem;
}

@media (min-width: 640px) {
  .hours-table tr.sub-group-sep td { padding: 0.35rem 1rem; }
}

.hours-table tbody tr.current-hour { background: #fefce8; }

.hours-table tbody tr.current-hour .td-hour::after {
  content: ' ◀';
  font-size: 0.62rem;
  color: #ca8a04;
}

.hours-table td {
  padding: 0.5rem 0.75rem;      /* móvil: padding más ajustado */
  vertical-align: middle;
}

@media (min-width: 640px) {
  .hours-table td { padding: 0.5rem 1rem; }
}

.td-hour {
  font-weight: 700;
  white-space: nowrap;
  width: 4rem;
}

.td-bar { padding-right: 0.75rem; }

.price-bar-wrapper {
  height: 5px;
  background: #f1f5f9;
  border-radius: 100px;
  overflow: hidden;
  min-width: 40px;
}

.price-bar {
  height: 100%;
  border-radius: 100px;
  transition: width .5s ease;
}

.td-price {
  font-weight: 700;
  text-align: right;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

/* ── FAB (botón flotante) ────────────────────────────────── */

.ai-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 100;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #3b82f6;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px rgba(59,130,246,.45), 0 2px 4px rgba(0,0,0,.15);
  transition: background .15s, transform .15s, box-shadow .15s;
}

.ai-fab:hover {
  background: #2563eb;
  transform: scale(1.08);
  box-shadow: 0 6px 18px rgba(59,130,246,.5), 0 3px 6px rgba(0,0,0,.15);
}

.ai-fab:active { transform: scale(.96); }

/* Gira a X cuando el panel está abierto */
.ai-fab.open svg {
  transform: rotate(90deg);
  transition: transform .2s ease;
}
.ai-fab svg { transition: transform .2s ease; }

/* ── Panel flotante ──────────────────────────────────────── */

.ai-panel {
  position: fixed;
  bottom: 5rem;
  right: 1rem;
  left: 1rem;           /* móvil: ocupa casi todo el ancho */
  z-index: 99;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 30px rgba(0,0,0,.14), 0 2px 8px rgba(0,0,0,.08);
  display: flex;
  flex-direction: column;
  max-height: 70vh;
  /* Estado cerrado */
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity .22s ease, transform .22s ease;
}

.ai-panel.open {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

@media (min-width: 480px) {
  .ai-panel {
    left: auto;
    width: 360px;
    bottom: 5.25rem;
    right: 1.5rem;
  }
}

/* Header del panel */
.ai-panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 1rem 1rem 0.875rem;
  background: linear-gradient(135deg, #1e293b, #0f172a);
  border-radius: var(--radius) var(--radius) 0 0;
  color: #fff;
  flex-shrink: 0;
}

.ai-panel-title {
  font-size: 0.9rem;
  font-weight: 700;
}

.ai-panel-desc {
  font-size: 0.75rem;
  color: #94a3b8;
  margin-top: 0.15rem;
}

.ai-panel-close {
  background: rgba(255,255,255,.1);
  border: none;
  color: #cbd5e1;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s;
}

.ai-panel-close:hover { background: rgba(255,255,255,.2); color: #fff; }

/* Área de mensajes */
.ai-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 80px;
}

.ai-welcome {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.55;
  background: #f8fafc;
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  border: 1px solid var(--border);
}

.ai-msg-user {
  align-self: flex-end;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.875rem;
  font-size: 0.82rem;
  color: #1e40af;
  max-width: 90%;
}

.ai-msg-bot {
  align-self: flex-start;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.875rem;
  font-size: 0.82rem;
  line-height: 1.6;
  max-width: 95%;
}

.ai-msg-bot.thinking {
  color: var(--text-muted);
  font-style: italic;
}

/* Estilos para el HTML que devuelve la IA */
.ai-msg-bot strong { color: var(--text); font-weight: 700; }
.ai-msg-bot ul     { padding-left: 1.1rem; margin: 0.4rem 0; }
.ai-msg-bot li     { margin-bottom: 0.25rem; }
.ai-msg-bot br     { display: block; margin-bottom: 0.3rem; content: ''; }

/* Input area dentro del panel */
.ai-input-area {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.ai-input-area textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.625rem 0.75rem;
  font-family: var(--font);
  font-size: 0.82rem;
  resize: none;
  outline: none;
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  background: #fafafa;
}

.ai-input-area textarea:focus {
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59,130,246,.1);
  background: #fff;
}

.ai-input-area textarea::placeholder { color: #94a3b8; }

.btn-primary {
  width: 100%;
  min-height: 40px;
  background: #3b82f6;
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 700;
  cursor: pointer;
  transition: background .15s, transform .1s;
}

.btn-primary:hover:not(:disabled) { background: #2563eb; }
.btn-primary:active:not(:disabled) { transform: scale(.98); }
.btn-primary:disabled { opacity: .45; cursor: not-allowed; }

/* ── Footer ──────────────────────────────────────────────── */

footer {
  border-top: 1px solid var(--border);
  padding: 1.5rem 0;
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-muted);
}

footer a { color: #3b82f6; text-decoration: none; }
footer a:hover { text-decoration: underline; }

/* ── Utils ───────────────────────────────────────────────── */

.hidden { display: none !important; }

/* ── Botón instalación PWA en el header ──────────────────── */
.btn-install {
  background: rgba(251, 191, 36, .15);
  color: #fbbf24 !important;
  border: 1px solid rgba(251, 191, 36, .4);
}
.btn-install:hover { background: rgba(251, 191, 36, .25); }
