/* ── Urbexia · Asistente Mercado Reformas ──────────────────────────────── */

/* ── Toggle button ─────────────────────────────────────────────────────── */
#uchat-btn {
  position: fixed;
  bottom: 24px; right: 24px;
  width: 62px; height: 62px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e05a00 0%, #b84800 100%);
  border: none; cursor: pointer;
  box-shadow: 0 4px 20px rgba(224,90,0,.50);
  display: flex; align-items: center; justify-content: center;
  z-index: 9998;
  transition: transform .18s, box-shadow .18s;
}
#uchat-btn:hover { transform: scale(1.08); box-shadow: 0 6px 28px rgba(224,90,0,.65); }
#uchat-btn svg   { width: 28px; height: 28px; fill: #fff; }

/* pulse ring */
#uchat-btn.has-badge::after {
  content: '';
  position: absolute; inset: -7px;
  border-radius: 50%;
  border: 2px solid rgba(224,90,0,.6);
  animation: uping 1.8s ease-out infinite;
}
@keyframes uping {
  0%   { opacity:.8; transform:scale(1); }
  100% { opacity:0;  transform:scale(1.65); }
}

/* badge dot */
#uchat-badge {
  position: absolute; top: -3px; right: -3px;
  width: 20px; height: 20px;
  background: #ef4444;
  border-radius: 50%;
  font-size: 11px; font-weight: 700; color: #fff;
  display: none; align-items: center; justify-content: center;
  border: 2px solid #fff;
}

/* ── Proactive bubble ───────────────────────────────────────────────────── */
#uchat-proactive {
  position: fixed; bottom: 100px; right: 20px;
  background: #fff; color: #111827;
  font-family: 'Inter', sans-serif; font-size: 13px; line-height: 1.5;
  padding: 12px 36px 12px 14px;
  border-radius: 14px 14px 4px 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.18);
  max-width: 240px; z-index: 9997;
  display: none;
  animation: uslide-up .28s ease;
  cursor: pointer;
  border-left: 3px solid #e05a00;
}
#uchat-proactive .upro-close {
  position: absolute; top: 7px; right: 10px;
  font-size: 14px; color: #9ca3af;
  background: none; border: none; cursor: pointer; padding: 0; line-height: 1;
}
#uchat-proactive::after {
  content: '';
  position: absolute; bottom: -8px; right: 20px;
  border: 8px solid transparent;
  border-top-color: #fff; border-bottom: 0;
}
@keyframes uslide-up {
  from { opacity:0; transform:translateY(12px); }
  to   { opacity:1; transform:translateY(0); }
}

/* ── Chat window ────────────────────────────────────────────────────────── */
#uchat-win {
  position: fixed;
  bottom: 100px; right: 24px;
  width: 380px;
  max-height: 600px;
  background: #f8fafc;
  border-radius: 20px;
  box-shadow: 0 16px 64px rgba(0,0,0,.25), 0 0 0 1px rgba(0,0,0,.06);
  display: flex; flex-direction: column;
  z-index: 9999; overflow: hidden;
  font-family: 'Inter', sans-serif; font-size: 14px;
  transform: scale(.82) translateY(24px);
  opacity: 0; pointer-events: none;
  transform-origin: bottom right;
  transition: transform .24s cubic-bezier(.34,1.56,.64,1), opacity .2s ease;
}
#uchat-win.open {
  transform: scale(1) translateY(0);
  opacity: 1; pointer-events: auto;
}

/* ── Header ─────────────────────────────────────────────────────────────── */
#uchat-header {
  background: linear-gradient(160deg, #0d1b2a 0%, #162032 100%);
  padding: 13px 13px 11px;
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
  position: relative;
}

/* Logo square */
.uavatar {
  width: 44px; height: 44px;
  border-radius: 10px;
  background: linear-gradient(135deg, #1e3050 0%, #0d1b2a 100%);
  border: 1.5px solid rgba(255,255,255,.14);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; overflow: hidden;
}
.uavatar svg { width: 44px; height: 44px; }

/* Title block */
.uinfo { flex: 1; min-width: 0; }
.uname {
  font-size: 15px; font-weight: 700; color: #fff;
  line-height: 1.2; margin-bottom: 5px;
  letter-spacing: -.01em;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Status + badge row — all on one line */
.ustatus-row {
  display: flex; align-items: center; gap: 5px; flex-wrap: wrap;
}
.ustatus-dot {
  width: 7px; height: 7px;
  background: #22c55e; border-radius: 50%;
  box-shadow: 0 0 0 2px rgba(34,197,94,.25);
  animation: upulse-dot 2s infinite; flex-shrink: 0;
}
@keyframes upulse-dot {
  0%,100% { box-shadow: 0 0 0 2px rgba(34,197,94,.25); }
  50%      { box-shadow: 0 0 0 5px rgba(34,197,94,.10); }
}
.ustatus-txt { font-size: 11px; color: #94a3b8; margin-right: 2px; }
.ubadge {
  font-size: 9.5px; font-weight: 700; letter-spacing: .04em;
  padding: 1.5px 6px; border-radius: 20px; line-height: 1.65;
  text-transform: uppercase; flex-shrink: 0;
}
.ubadge-itec { background: #16a34a; color: #fff; }
.ubadge-cype { background: #4f46e5; color: #fff; }

/* Controls — 2 rows of 3 */
#uchat-controls {
  display: flex; flex-direction: column; gap: 4px;
  flex-shrink: 0; align-items: flex-end;
}
.uctl-row {
  display: flex; align-items: center; gap: 3px;
}
.uchat-ctrl-btn {
  background: rgba(255,255,255,.10);
  border: 1px solid rgba(255,255,255,.12);
  color: #cbd5e1;
  font-size: 10.5px; font-weight: 600;
  padding: 3px 6px; border-radius: 6px;
  cursor: pointer; transition: background .15s;
  font-family: inherit; line-height: 1.5; white-space: nowrap;
}
.uchat-ctrl-btn:hover  { background: rgba(255,255,255,.20); color: #fff; }
.uchat-ctrl-btn.active { background: rgba(255,255,255,.22); color: #fff; border-color: rgba(255,255,255,.3); }
#uchat-sound-btn { font-size: 13px; padding: 2px 5px; }
#uchat-close {
  background: none; border: none;
  color: #94a3b8; cursor: pointer;
  font-size: 16px; line-height: 1;
  padding: 3px 4px; border-radius: 6px;
  transition: color .15s, background .15s;
}
#uchat-close:hover { color: #fff; background: rgba(255,255,255,.12); }

/* ── Messages area ──────────────────────────────────────────────────────── */
#uchat-msgs {
  flex: 1; overflow-y: auto;
  padding: 16px 14px 8px;
  display: flex; flex-direction: column; gap: 10px;
  background: #f8fafc;
  scroll-behavior: smooth;
}
#uchat-msgs::-webkit-scrollbar { width: 4px; }
#uchat-msgs::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }

/* Message rows (bot has avatar) */
.umsg-row {
  display: flex; align-items: flex-end; gap: 7px;
}
.umsg-row.user { justify-content: flex-end; }

/* Bot avatar mini */
.umsg-avatar {
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, #1e3050 0%, #0d1b2a 100%);
  border: 1px solid rgba(13,27,42,.18);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
}
.umsg-avatar img { width: 18px; height: 18px; object-fit: contain; }
.umsg-avatar svg { width: 16px; height: 16px; fill: #e8a020; }

/* Bubbles */
.umsg {
  max-width: 80%;
  padding: 11px 14px;
  border-radius: 16px;
  line-height: 1.62;
  word-break: break-word;
  animation: umsg-in .2s ease;
  font-size: 14px;
}
@keyframes umsg-in {
  from { opacity:0; transform:translateY(6px); }
  to   { opacity:1; transform:translateY(0); }
}
.umsg.bot {
  background: #fff;
  color: #1e293b;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 4px rgba(0,0,0,.08), 0 0 0 1px rgba(0,0,0,.04);
}
.umsg.user {
  background: linear-gradient(135deg, #e05a00, #c44800);
  color: #fff;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(224,90,0,.30);
}
.umsg a            { color: inherit; text-decoration: underline; }
.umsg.bot a        { color: #e05a00; }
.umsg strong       { font-weight: 600; }

/* Typing dots */
.utyping { display:flex; align-items:center; gap:5px; padding:4px 2px; }
.utyping span {
  width:7px; height:7px; background:#cbd5e1; border-radius:50%;
  animation: ubounce 1.1s infinite ease-in-out;
}
.utyping span:nth-child(2) { animation-delay:.16s; }
.utyping span:nth-child(3) { animation-delay:.32s; }
@keyframes ubounce {
  0%,80%,100% { transform:translateY(0); background:#cbd5e1; }
  40%         { transform:translateY(-7px); background:#e05a00; }
}

/* ── Starter option grid (welcome flow) ────────────────────────────────── */
.ustart-label {
  font-size: 12px; color: #64748b; margin-bottom: 8px; font-weight: 500;
}
.ustart-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: 7px; margin-top: 4px;
}
.ustart-btn {
  display: flex; align-items: center; gap: 8px;
  background: #f8fafc;
  border: 1.5px solid #e2e8f0;
  border-radius: 12px;
  padding: 10px 10px;
  cursor: pointer; font-family: inherit;
  text-align: left; transition: all .18s;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.ustart-btn:hover {
  background: #fff7f0; border-color: #e05a00;
  box-shadow: 0 2px 8px rgba(224,90,0,.15);
  transform: translateY(-1px);
}
.ustart-btn:active { transform: translateY(0); }
.ustart-e { font-size: 20px; line-height: 1; flex-shrink: 0; }
.ustart-l { font-size: 12px; font-weight: 500; color: #334155; line-height: 1.3; }

/* ── Quick-reply chips ──────────────────────────────────────────────────── */
#uchat-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
  padding: 6px 14px 6px;
  background: #f8fafc;
  flex-shrink: 0;
}
.uchip {
  background: #fff;
  border: 1.5px solid #e2e8f0;
  color: #334155;
  font-size: 12px; font-weight: 500;
  padding: 5px 11px; border-radius: 20px;
  cursor: pointer; font-family: inherit;
  transition: all .15s; white-space: nowrap;
  box-shadow: 0 1px 3px rgba(0,0,0,.06);
}
.uchip:hover { background: #e05a00; color: #fff; border-color: #e05a00; box-shadow: 0 2px 8px rgba(224,90,0,.25); }

/* ── WhatsApp strip ─────────────────────────────────────────────────────── */
#uchat-wa-strip {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  background: #f0fdf4;
  border-top: 1px solid #dcfce7;
  flex-shrink: 0;
  cursor: pointer;
  transition: background .15s;
  text-decoration: none;
}
#uchat-wa-strip:hover { background: #dcfce7; }
#uchat-wa-strip .uwa-icon {
  width: 32px; height: 32px;
  background: #25d366;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
#uchat-wa-strip .uwa-icon svg { width: 18px; height: 18px; fill: #fff; }
#uchat-wa-strip .uwa-text { flex: 1; }
#uchat-wa-strip .uwa-text strong { display:block; font-size:12px; font-weight:600; color:#15803d; line-height:1.3; }
#uchat-wa-strip .uwa-text span   { font-size:11px; color:#4ade80; }
#uchat-wa-strip .uwa-arr { color: #22c55e; font-size: 16px; }

/* ── Input area ─────────────────────────────────────────────────────────── */
#uchat-input-wrap {
  display: flex; align-items: center; gap: 6px;
  padding: 10px 10px;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  flex-shrink: 0;
}
#uchat-input {
  flex: 1;
  border: 1.5px solid #e2e8f0;
  border-radius: 22px;
  padding: 9px 14px;
  font-size: 13.5px; font-family: inherit;
  outline: none; resize: none;
  max-height: 80px; overflow-y: auto;
  background: #f8fafc;
  transition: border-color .15s, background .15s;
  color: #1e293b;
}
#uchat-input:focus { border-color: #e05a00; background: #fff; }
#uchat-input::placeholder { color: #94a3b8; }

/* Send button */
#uchat-send {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #e05a00, #c44800);
  color: #fff; border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: transform .12s, box-shadow .15s;
  box-shadow: 0 2px 8px rgba(224,90,0,.35);
}
#uchat-send:hover  { transform: scale(1.07); box-shadow: 0 4px 12px rgba(224,90,0,.45); }
#uchat-send:active { transform: scale(.92); }
#uchat-send svg    { width: 17px; height: 17px; fill: #fff; }

/* ── File attachment button ─────────────────────────────────────────────── */
#uchat-attach,
#uchat-mic {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: #f1f5f9;
  border: 1.5px solid #e2e8f0;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0; cursor: pointer;
  transition: background .15s, border-color .15s, box-shadow .15s;
}
#uchat-attach:hover,
#uchat-mic:hover { background: #e8edf3; border-color: #cbd5e1; }
#uchat-attach svg,
#uchat-mic svg { width: 16px; height: 16px; fill: #64748b; pointer-events: none; }
#uchat-file { display: none; }

/* Recording state */
#uchat-mic.recording {
  background: #fee2e2;
  border-color: #ef4444;
  animation: umic-pulse 1.1s ease-in-out infinite;
}
#uchat-mic.recording svg { fill: #ef4444; }
@keyframes umic-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.35); }
  55%       { box-shadow: 0 0 0 7px rgba(239,68,68,.0); }
}

/* Image preview in user bubble */
.umsg-img-preview {
  max-width: 220px; max-height: 190px;
  border-radius: 10px; display: block;
  object-fit: cover;
}

/* PDF preview in user bubble */
.umsg-pdf-preview {
  display: flex; align-items: center; gap: 8px; padding: 2px 0;
}
.umsg-pdf-preview svg {
  width: 22px; height: 22px;
  fill: rgba(255,255,255,.9); flex-shrink: 0;
}
.umsg-pdf-preview span {
  font-size: 12.5px; font-weight: 500;
  color: rgba(255,255,255,.95); word-break: break-all;
}

/* ── Accessibility: font size classes ───────────────────────────────────── */
#uchat-win.fs-large .umsg         { font-size: 16px; line-height: 1.70; }
#uchat-win.fs-large .uchip        { font-size: 13.5px; padding: 6px 13px; }
#uchat-win.fs-large .ustart-l    { font-size: 13.5px; }
#uchat-win.fs-large .ustart-label { font-size: 13px; }
#uchat-win.fs-large #uchat-input  { font-size: 15px; }
#uchat-win.fs-large .ustart-btn   { padding: 12px 10px; }

#uchat-win.fs-xl .umsg         { font-size: 19px; line-height: 1.76; }
#uchat-win.fs-xl .uchip        { font-size: 15px; padding: 8px 14px; }
#uchat-win.fs-xl .ustart-l    { font-size: 15px; }
#uchat-win.fs-xl .ustart-label { font-size: 14px; }
#uchat-win.fs-xl #uchat-input  { font-size: 17px; }
#uchat-win.fs-xl .ustart-btn   { padding: 14px 10px; min-height: 58px; }
#uchat-win.fs-xl .umsg-avatar  { width: 32px; height: 32px; }

/* ── Tablets portrait: 481 – 768 px ─────────────────────────────────────── */
@media (min-width: 481px) and (max-width: 768px) {
  #uchat-win {
    width: min(430px, calc(100vw - 32px));
    right: 16px; bottom: 100px;
    max-height: calc(100svh - 120px);
  }
  #uchat-btn       { bottom: 22px; right: 22px; }
  #uchat-proactive { right: 14px; bottom: 96px; }
}

/* ── Mobile phones: ≤ 480 px ────────────────────────────────────────────── */
@media (max-width: 480px) {
  #uchat-win {
    width: calc(100vw - 12px);
    right: 6px; left: 6px; bottom: 86px;
    max-height: calc(100svh - 100px);
    border-radius: 20px 20px 14px 14px;
  }
  #uchat-btn        { bottom: 14px; right: 14px; width: 60px; height: 60px; }
  #uchat-proactive  { right: 8px; bottom: 88px; max-width: 210px; }

  /* Larger tap targets for thumbs */
  .uchip        { padding: 7px 13px; font-size: 13px; }
  .ustart-btn   { padding: 11px 9px; }
  #uchat-send   { width: 44px; height: 44px; }
  #uchat-attach { width: 40px; height: 40px; }

  /* Keep header controls legible but compact */
  .uchat-ctrl-btn { font-size: 10.5px; padding: 2px 5px; }
}

/* ── Landscape phones (wide but short) ──────────────────────────────────── */
@media (max-height: 520px) and (orientation: landscape) {
  #uchat-win {
    max-height: calc(100svh - 68px);
    bottom: 60px;
    border-radius: 14px;
  }
  #uchat-btn { bottom: 8px; width: 52px; height: 52px; }
  #uchat-btn svg { width: 24px; height: 24px; }
}

/* ── Large desktop: ≥ 1440 px ───────────────────────────────────────────── */
@media (min-width: 1440px) {
  #uchat-win { width: 400px; max-height: 640px; }
}

/* ── Lead capture card ───────────────────────────────────────────────────── */
.ulead-card {
  background: #fff;
  border: 1.5px solid #e2e8f0;
  border-radius: 14px;
  padding: 18px 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: 0 2px 12px rgba(0,0,0,.07);
}
.ulead-head {
  font-size: 15px;
  font-weight: 700;
  color: #0d1b2a;
  margin: 0;
  line-height: 1.3;
}
.ulead-sub {
  font-size: 12.5px;
  color: #64748b;
  margin: -4px 0 0;
}
.ulead-inp {
  width: 100%;
  box-sizing: border-box;
  border: 1.5px solid #cbd5e1;
  border-radius: 9px;
  padding: 9px 11px;
  font-size: 14px;
  font-family: inherit;
  color: #0d1b2a;
  outline: none;
  resize: none;
  transition: border-color .18s;
}
.ulead-inp:focus {
  border-color: #e05a00;
}
.ulead-inp::placeholder { color: #94a3b8; }
.ulead-btn {
  background: linear-gradient(135deg, #e05a00, #f07820);
  color: #fff;
  border: none;
  border-radius: 10px;
  padding: 11px 14px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .18s, transform .12s;
  letter-spacing: .01em;
}
.ulead-btn:hover:not(:disabled) { opacity: .9; transform: translateY(-1px); }
.ulead-btn:disabled { opacity: .6; cursor: not-allowed; transform: none; }
.ulead-priv {
  font-size: 11.5px;
  color: #94a3b8;
  margin: 0;
  text-align: center;
}

/* Success state */
.ulead-ok {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 20px 14px;
  text-align: center;
}
.ulead-ok-icon  { font-size: 2.4rem; }
.ulead-ok-title { font-size: 15px; font-weight: 700; color: #0d1b2a; }
.ulead-ok-sub   { font-size: 13px; color: #475569; line-height: 1.5; }

/* Font-size overrides for lead card */
#uchat-win.fs-large .ulead-head { font-size: 16px; }
#uchat-win.fs-large .ulead-inp  { font-size: 15px; }
#uchat-win.fs-large .ulead-btn  { font-size: 15px; }
#uchat-win.fs-xl    .ulead-head { font-size: 18px; }
#uchat-win.fs-xl    .ulead-inp  { font-size: 17px; }
#uchat-win.fs-xl    .ulead-btn  { font-size: 17px; }
