/* ═══ Fase 7: asistente IA flotante + clima ═══ */

/* ───── Botón flotante (abajo a la izquierda: WhatsApp va a la derecha) ───── */
.ai-float {
  position: fixed; left: 16px; bottom: 24px; z-index: 960; width: 60px; height: 60px; padding: 0; border-radius: 50%;
  border: 3px solid #fff; background: var(--brand-1); box-shadow: 0 10px 28px rgba(10,111,194,.35), 0 2px 6px rgba(0,0,0,.15);
  overflow: hidden; cursor: pointer; transition: transform .2s cubic-bezier(.3,1.4,.6,1);
  animation: ai-entra .5s cubic-bezier(.3,1.4,.6,1) both .6s;
}
.ai-float img { width: 100%; height: 100%; object-fit: cover; display: block; transition: opacity .2s, transform .2s; }
.ai-float-x { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; opacity: 0; transform: rotate(-90deg); transition: opacity .2s, transform .2s; }
.ai-float.activo img { opacity: 0; transform: scale(.6); }
.ai-float.activo .ai-float-x { opacity: 1; transform: none; }
.ai-float:active { transform: scale(.92); }
.ai-float::after { content: ''; position: absolute; top: 4px; right: 4px; width: 12px; height: 12px; border-radius: 50%; background: #22c55e; border: 2px solid #fff; }
.ai-float.activo::after { display: none; }
@keyframes ai-entra { from { transform: scale(0) rotate(-30deg); opacity: 0; } to { transform: none; opacity: 1; } }

.ai-panel {
  position: fixed; left: 16px; bottom: 96px; z-index: 961; width: 390px; height: min(600px, calc(100vh - 140px));
  display: flex; flex-direction: column; background: var(--bg-primary); border: 1px solid var(--border); border-radius: var(--radius-l);
  box-shadow: 0 24px 60px rgba(0,0,0,.22); overflow: hidden;
  opacity: 0; transform: translateY(16px) scale(.97); transform-origin: bottom left; pointer-events: none; visibility: hidden;
  transition: opacity .22s, transform .22s, visibility 0s .22s;
}
.ai-panel.abierto { opacity: 1; transform: none; pointer-events: auto; visibility: visible; transition: opacity .22s, transform .22s; }
.ai-head { display: flex; align-items: center; gap: .6rem; padding: .7rem .6rem .7rem .9rem; color: #fff;
  background: linear-gradient(120deg, var(--brand-1) 0%, var(--brand-1-dark) 70%, var(--brand-3) 140%); }
.ai-head img { width: 40px; height: 40px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); object-fit: cover; }
.ai-head div { flex: 1; min-width: 0; line-height: 1.25; }
.ai-head strong { display: block; font-size: 15px; }
.ai-head small { font-size: 12px; opacity: .85; display: inline-flex; align-items: center; gap: .35rem; }
.ai-dot { width: 8px; height: 8px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,.25); }
.ai-head .icon-btn { color: #fff; background: transparent; border-color: transparent; }
.ai-head .icon-btn:hover { background: rgba(255,255,255,.14); }
.ai-cuerpo { flex: 1; min-height: 0; display: flex; }

/* ───── Chat (panel y página) ───── */
.ai-chat { display: flex; flex-direction: column; flex: 1; min-height: 0; width: 100%; }
.ai-lista { flex: 1; min-height: 0; overflow-y: auto; padding: 1rem .9rem; display: flex; flex-direction: column; gap: .65rem;
  -webkit-overflow-scrolling: touch; overscroll-behavior: contain; background:
  radial-gradient(circle at 0 0, var(--accent-soft), transparent 45%), var(--bg-secondary); }
.ai-fila { display: flex; align-items: flex-end; gap: .45rem; max-width: 92%; }
.ai-mini { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
.ai-msg { padding: .6rem .85rem; border-radius: 18px; font-size: 14px; line-height: 1.5; word-wrap: break-word; overflow-wrap: anywhere;
  -webkit-user-select: text; user-select: text; }
.ai-msg p { margin: 0 0 .4rem; } .ai-msg p:last-child { margin: 0; }
.ai-msg ul { margin: .2rem 0 .4rem; padding-left: 1.1rem; } .ai-msg li { margin: .15rem 0; }
.ai-msg--bot { background: var(--surface); color: var(--text-primary); border: 1px solid var(--border); border-bottom-left-radius: 6px; }
.ai-msg--yo { align-self: flex-end; max-width: 85%; background: var(--accent); color: #fff; border-bottom-right-radius: 6px; white-space: pre-wrap; }
.ai-msg--error { border-color: var(--danger); color: var(--danger); }
.ai-link { color: var(--accent); font-weight: 600; text-decoration: underline; text-underline-offset: 2px; }
.ai-escribiendo .ai-msg { display: inline-flex; gap: 4px; padding: .8rem .9rem; }
.ai-escribiendo span { width: 7px; height: 7px; border-radius: 50%; background: var(--text-muted); animation: ai-pulso 1.1s infinite; }
.ai-escribiendo span:nth-child(2) { animation-delay: .15s; } .ai-escribiendo span:nth-child(3) { animation-delay: .3s; }
@keyframes ai-pulso { 0%, 60%, 100% { opacity: .3; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }
.ai-sugs { display: flex; gap: .4rem; overflow-x: auto; padding: .5rem .75rem; border-top: 1px solid var(--border); scrollbar-width: none; background: var(--bg-primary); }
.ai-sugs::-webkit-scrollbar { display: none; }
.ai-sugs .chip { padding: .35rem .85rem; font-size: 13px; font-weight: 500; }
.ai-sugs[hidden] { display: none; }
.ai-form { display: flex; align-items: flex-end; gap: .5rem; padding: .6rem .75rem; border-top: 1px solid var(--border); background: var(--bg-primary); }
.ai-form textarea { flex: 1; resize: none; min-height: 44px; max-height: 120px; padding: .65rem .9rem; border-radius: 22px; border: 1px solid var(--border);
  background: var(--bg-secondary); color: var(--text-primary); font: inherit; font-size: 15px; line-height: 1.4; }
.ai-form textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ai-enviar { width: 44px; height: 44px; min-height: 44px; padding: 0; border-radius: 50%; flex-shrink: 0; justify-content: center; }
.ai-legal { margin: 0; padding: 0 .9rem .55rem; font-size: 12px; color: var(--text-muted); background: var(--bg-primary); }

/* Página ?page=asistente */
.ai-pagina { padding-top: 1.5rem; padding-bottom: 1.5rem; max-width: 860px; }
.ai-pag-head { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.ai-pag-head img { width: 72px; height: 72px; border-radius: 22px; object-fit: cover; box-shadow: 0 10px 24px rgba(10,111,194,.28); transform: rotate(-4deg); }
.ai-pag-head div { flex: 1; min-width: 0; }
.ai-pag-head h1 { margin: .1rem 0; font-size: clamp(24px, 4vw, 34px); letter-spacing: -.03em; }
.ai-pag-head p { margin: 0; color: var(--text-secondary); }
.ai-pag-chat { display: flex; height: calc(100vh - 260px); min-height: 420px; border: 1px solid var(--border); border-radius: var(--radius-l); overflow: hidden; box-shadow: 0 12px 34px var(--shadow); }

@media (max-width: 768px) {
  .ai-float { width: 54px; height: 54px; bottom: calc(var(--footer-h) + 16px + env(safe-area-inset-bottom)); }
  .ai-panel { left: 0; right: 0; bottom: 0; width: auto; height: calc(100% - 56px); border-radius: 22px 22px 0 0; transform: translateY(40px); z-index: 1001; }
  .ai-panel .ai-legal { padding-bottom: calc(.55rem + env(safe-area-inset-bottom)); }
  .ai-float.activo { display: none; }
  .ai-pagina { padding-top: 1rem; }
  .ai-pag-head img { width: 56px; height: 56px; border-radius: 18px; }
  .ai-pag-chat { height: calc(100vh - 250px - env(safe-area-inset-bottom)); min-height: 360px; }
}

/* ───── Admin del asistente ───── */
.aia-form { display: flex; flex-direction: column; gap: 1rem; }
.aia-form .ap-fieldset { border: 1px solid var(--border); border-radius: var(--radius-m); padding: 1rem 1.1rem; margin: 0; background: var(--surface); }
.aia-form .ap-fieldset h3 { margin: 0 0 .75rem; font-size: 16px; }
.aia-estado { display: flex; align-items: center; gap: .9rem; padding: 1rem 1.1rem; border-radius: var(--radius-m); background: var(--bg-secondary); border: 1px solid var(--border); }
.aia-estado.on { background: rgba(31,138,59,.08); border-color: rgba(31,138,59,.4); }
.aia-estado img { width: 52px; height: 52px; border-radius: 50%; object-fit: cover; }
.aia-estado div { flex: 1; min-width: 0; } .aia-estado small { display: block; color: var(--text-secondary); }
.aia-switch { font-weight: 700; }
.aia-switch input { width: 22px; height: 22px; accent-color: var(--brand-3); }
.aia-ident { display: flex; gap: 1.25rem; align-items: flex-start; }
.aia-avatar { display: flex; flex-direction: column; align-items: center; gap: .5rem; width: 150px; flex-shrink: 0; }
.aia-avatar img { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; border: 3px solid var(--surface); box-shadow: 0 8px 22px var(--shadow); }
.aia-ident-campos { flex: 1; min-width: 0; }
.aia-borrar { color: var(--danger); }
.aia-form .form-acciones { display: flex; justify-content: flex-end; gap: .6rem; flex-wrap: wrap; }
.aia-form textarea { resize: vertical; }
@media (max-width: 768px) {
  .aia-ident { flex-direction: column; align-items: stretch; }
  .aia-avatar { width: auto; }
  .aia-estado { flex-wrap: wrap; }
  .aia-form .form-acciones .btn { flex: 1 1 auto; }
}

/* ───── Clima ───── */
.clima-pagina { padding-top: 1.25rem; padding-bottom: 2rem; }
.clima-locs { display: flex; gap: .5rem; overflow-x: auto; padding: .25rem 0 .9rem; scrollbar-width: none; }
.clima-locs::-webkit-scrollbar { display: none; }
.clima-locs .chip { padding: .35rem 1rem; }
.clima-locs .chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

.clima-hero { position: relative; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1.75rem 2rem;
  border-radius: 28px 28px 28px 8px; color: #fff; overflow: hidden; min-height: 220px;
  background: linear-gradient(135deg, #0A6FC2 0%, #2b8fe0 55%, #FEAA13 160%); box-shadow: 0 18px 40px rgba(10,111,194,.28); }
.clima-hero::before { content: ''; position: absolute; left: -10%; right: -10%; bottom: -1px; height: 42%; opacity: .22;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,.25)), url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 400 80' preserveAspectRatio='none'%3E%3Cpath d='M0 80 L0 50 L60 20 L110 45 L170 8 L230 40 L290 18 L350 42 L400 25 L400 80Z' fill='white'/%3E%3C/svg%3E") bottom/100% 100% no-repeat; }
.clima-hero--noche { background: linear-gradient(135deg, #0b1f3d 0%, #173a6b 60%, #3b4d8f 130%); }
.clima-hero.clima-nublado, .clima-hero.clima-niebla, .clima-hero.clima-llovizna, .clima-hero.clima-lluvia { background: linear-gradient(135deg, #3d5a78 0%, #5f7f9e 60%, #8aa2b8 130%); }
.clima-hero.clima-tormenta { background: linear-gradient(135deg, #1f2a3d 0%, #3b4a63 60%, #FEAA13 180%); }
.clima-hero-info { position: relative; z-index: 1; min-width: 0; }
.clima-hero .label { color: rgba(255,255,255,.85); display: inline-flex; align-items: center; gap: .3rem; }
.clima-hero .label .lucide { width: 14px; height: 14px; }
.clima-temp { font-size: clamp(64px, 12vw, 104px); font-weight: 800; letter-spacing: -.06em; line-height: 1; margin: .25rem 0 .1rem; }
.clima-temp sup { font-size: .3em; font-weight: 600; vertical-align: top; position: relative; top: .5em; letter-spacing: 0; margin-left: .15em; }
.clima-hero h1 { margin: 0; font-size: clamp(20px, 3vw, 26px); }
.clima-hero p { margin: .3rem 0 .4rem; opacity: .92; }
.clima-hero small { font-size: 12px; opacity: .8; }
.clima-hero-ico { position: relative; z-index: 1; width: clamp(130px, 22vw, 210px); height: auto; filter: drop-shadow(0 16px 26px rgba(0,0,0,.25)); animation: clima-flota 6s ease-in-out infinite; }
@keyframes clima-flota { 50% { transform: translateY(-8px); } }

.clima-alertas { margin-top: 1rem; display: flex; flex-direction: column; gap: .6rem; }
.clima-alerta { display: flex; align-items: center; gap: .8rem; padding: .85rem 1rem; border-radius: var(--radius-m); border: 1px solid; }
.clima-alerta .ico { width: 40px; height: 40px; border-radius: 12px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.clima-alerta div { flex: 1; min-width: 0; } .clima-alerta p { margin: .1rem 0 0; font-size: 14px; color: var(--text-secondary); }
.clima-alerta--alto { border-color: rgba(192,57,43,.45); background: rgba(192,57,43,.07); } .clima-alerta--alto .ico { background: var(--danger); color: #fff; }
.clima-alerta--medio { border-color: rgba(254,170,19,.6); background: rgba(254,170,19,.1); } .clima-alerta--medio .ico { background: var(--sun); color: var(--sun-text); }
.clima-alerta--bajo { border-color: var(--border); background: var(--bg-secondary); } .clima-alerta--bajo .ico { background: var(--accent-soft); color: var(--accent); }
.clima-nota { margin: 0; font-size: 12px; color: var(--text-muted); }

.clima-bloque { margin-top: 1.5rem; }
.clima-h { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin: 0 0 .7rem; font-weight: 700; }
.clima-horas { display: flex; gap: .5rem; overflow-x: auto; padding-bottom: .5rem; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
.clima-hora { flex: 0 0 74px; display: flex; flex-direction: column; align-items: center; gap: .2rem; padding: .7rem .3rem; border-radius: 18px;
  background: var(--surface); border: 1px solid var(--border); font-size: 13px; }
.clima-hora.ahora { background: var(--accent); color: #fff; border-color: var(--accent); }
.clima-hora img { width: 40px; height: 40px; }
.clima-hora strong { font-size: 17px; }
.clima-hora small { display: inline-flex; align-items: center; gap: 2px; font-size: 12px; color: var(--text-muted); }
.clima-hora.ahora small { color: rgba(255,255,255,.85); }
.clima-hora small .lucide { width: 12px; height: 12px; }
.clima-hora small.lluvia { color: var(--accent); font-weight: 700; } .clima-hora.ahora small.lluvia { color: #fff; }

.clima-cols { display: grid; grid-template-columns: 1.15fr 1fr; gap: 0 1.5rem; }
.clima-dias { list-style: none; margin: 0; padding: .3rem 1rem; border-radius: var(--radius-l); background: var(--surface); border: 1px solid var(--border); }
.clima-dias li { display: grid; grid-template-columns: 74px 36px 40px 34px 1fr 34px; align-items: center; gap: .5rem; padding: .55rem 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.clima-dias li:last-child { border-bottom: 0; }
.clima-dias .dia { font-weight: 600; }
.clima-dias img { width: 34px; height: 34px; }
.clima-dias .prob { font-size: 12px; color: var(--text-muted); } .clima-dias .prob.lluvia { color: var(--accent); font-weight: 700; }
.clima-dias .min { color: var(--text-muted); text-align: right; } .clima-dias .max { font-weight: 700; }
.clima-dias .barra { position: relative; height: 6px; border-radius: 99px; background: var(--bg-tertiary, var(--bg-secondary)); }
.clima-dias .barra i { position: absolute; top: 0; bottom: 0; border-radius: 99px; background: linear-gradient(90deg, #4ea8e8, var(--brand-2)); }
.clima-det { display: grid; grid-template-columns: repeat(2, 1fr); gap: .6rem; }
.clima-det > div { padding: .85rem 1rem; border-radius: var(--radius-m); background: var(--surface); border: 1px solid var(--border); display: grid; grid-template-columns: auto 1fr; gap: 0 .6rem; align-items: center; }
.clima-det .lucide { grid-row: span 2; width: 22px; height: 22px; color: var(--accent); }
.clima-det strong { font-size: 17px; }
.clima-fuente { margin: 1rem 0 0; font-size: 12px; color: var(--text-muted); }

.clima-region { margin-top: 2.25rem; }
.clima-region-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.clima-mini { display: flex; align-items: center; gap: .6rem; padding: .7rem .9rem; border-radius: var(--radius-m); background: var(--surface); border: 1px solid var(--border);
  color: var(--text-primary); font: inherit; text-align: left; cursor: pointer; position: relative; overflow: hidden; min-height: 64px; }
.clima-mini.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.clima-mini img { width: 42px; height: 42px; flex-shrink: 0; }
.clima-mini > span:nth-of-type(1) { flex: 1; min-width: 0; }
.clima-mini strong { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.clima-mini small { font-size: 12px; color: var(--text-muted); }
.clima-mini .clima-aviso { color: var(--danger); font-weight: 700; display: inline-flex; align-items: center; gap: 2px; }
.clima-mini .clima-aviso .lucide { width: 12px; height: 12px; }
.clima-mini .t { font-size: 22px; font-weight: 800; letter-spacing: -.03em; text-align: right; line-height: 1.1; }
.clima-mini .t small { display: block; font-size: 11px; font-weight: 500; letter-spacing: 0; }
.clima-skel { display: flex; flex-direction: column; gap: 1rem; }
.clima-skel .skel { height: 220px; border-radius: 28px; background: linear-gradient(90deg, var(--bg-secondary), var(--bg-tertiary, #eaecf0), var(--bg-secondary)); background-size: 200% 100%; animation: clima-skel 1.2s infinite; }
.clima-skel .skel + .skel { height: 120px; }
@keyframes clima-skel { to { background-position: -200% 0; } }

/* Widget del home */
.home-clima { display: flex; align-items: center; gap: .4rem; color: inherit; text-decoration: none; }
.home-clima img { width: 30px; height: 30px; margin: -4px 0; }

@media (max-width: 1024px) { .clima-region-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px) {
  .clima-hero { padding: 1.25rem 1.25rem 1.5rem; border-radius: 24px 24px 24px 8px; min-height: 190px; }
  .clima-hero-ico { width: 118px; }
  .clima-cols { grid-template-columns: 1fr; }
  .clima-dias li { grid-template-columns: 62px 32px 36px 30px 1fr 30px; gap: .35rem; }
  .clima-region-grid { grid-template-columns: 1fr; }
  .clima-alerta { flex-wrap: wrap; }
  .clima-alerta .btn { width: 100%; }
}
@media (prefers-reduced-motion: reduce) { .clima-hero-ico, .ai-float { animation: none; } }
