/* ============ MERSA Chat — page styles ============ */

.chat-page{
  min-height:calc(100vh - 90px);
  padding:120px 0 60px;
  background:
    radial-gradient(circle at 20% 10%, rgba(243,213,154,.06), transparent 50%),
    radial-gradient(circle at 80% 80%, rgba(26,58,102,.4), transparent 60%),
    var(--navy-900);
}

.chat-shell{
  max-width:920px;margin:0 auto;
  display:flex;flex-direction:column;
  height:calc(100vh - 180px);
  min-height:560px;
  position:relative;
  background:
    radial-gradient(120% 80% at 12% 0%, rgba(107,92,255,.14), transparent 55%),
    radial-gradient(120% 80% at 90% 100%, rgba(34,193,255,.10), transparent 55%),
    radial-gradient(90% 60% at 100% 8%, rgba(224,85,180,.08), transparent 50%),
    linear-gradient(180deg, rgba(10,42,82,.55), rgba(0,17,39,.78));
  border:1px solid rgba(207,214,224,.08);
  border-radius:20px;
  box-shadow:var(--shadow-lg), 0 0 50px rgba(120,90,255,.18);
  overflow:hidden;
  backdrop-filter:blur(8px);
}
/* Faint animated gradient ring around the whole window */
.chat-shell::before{
  content:'';
  position:absolute;inset:0;
  border-radius:inherit;
  padding:1.5px;
  background:linear-gradient(135deg,#1f6feb,#6b5cff,#a855f7,#e055b4,#22c1ff);
  background-size:260% 100%;
  -webkit-mask:linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite:xor;
          mask:linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
          mask-composite:exclude;
  opacity:.55;
  pointer-events:none;
  z-index:2;
  animation:ai-flow 8s ease infinite;
}

.chat-head{
  display:flex;align-items:center;gap:14px;
  padding:18px 22px;
  border-bottom:1px solid rgba(207,214,224,.1);
  background:rgba(0,17,39,.5);
}
.chat-head-avatar{
  width:42px;height:42px;border-radius:50%;
  background:linear-gradient(135deg,#1f6feb,#6b5cff,#a855f7,#e055b4,#22c1ff);
  background-size:260% 100%;
  animation:ai-flow 7s ease infinite;
  display:flex;align-items:center;justify-content:center;
  border:1px solid rgba(168,140,255,.5);
  box-shadow:0 0 18px rgba(120,90,255,.45);
  flex-shrink:0;
}
.chat-head-avatar svg{width:22px;height:22px;color:#fff}
.chat-head-meta{flex:1;min-width:0}
.chat-head-meta strong{
  font-family:'Space Grotesk',sans-serif;
  font-size:15px;font-weight:700;letter-spacing:.5px;display:inline-block;
  background:linear-gradient(110deg,#5b9dff,#8b7bff,#c071ff,#ff6fcf,#4fd6ff);
  background-size:260% 100%;
  -webkit-background-clip:text;background-clip:text;
  -webkit-text-fill-color:transparent;color:transparent;
  animation:ai-flow 7s ease infinite;
}
@keyframes ai-flow{
  0%{background-position:0% 50%}
  50%{background-position:100% 50%}
  100%{background-position:0% 50%}
}
.chat-head-meta span{
  font-size:12px;color:var(--silver-300);
  display:inline-flex;align-items:center;gap:6px;
}
.chat-head-meta .pulse{
  width:7px;height:7px;border-radius:50%;background:var(--ok);
  box-shadow:0 0 0 0 rgba(86,224,160,.6);
  animation:chat-pulse 2s infinite;
}
@keyframes chat-pulse{
  0%{box-shadow:0 0 0 0 rgba(86,224,160,.5)}
  70%{box-shadow:0 0 0 8px rgba(86,224,160,0)}
  100%{box-shadow:0 0 0 0 rgba(86,224,160,0)}
}
.chat-head-clear{
  background:transparent;border:1px solid rgba(207,214,224,.2);
  color:var(--silver-200);
  font-family:'Space Grotesk',sans-serif;font-size:11px;letter-spacing:.8px;
  padding:8px 14px;border-radius:999px;cursor:pointer;
  transition:all .2s var(--ease);
}
.chat-head-clear:hover{border-color:var(--gold);color:var(--gold)}

.chat-body{
  flex:1;overflow-y:auto;
  padding:24px 22px;
  display:flex;flex-direction:column;gap:18px;
  scroll-behavior:smooth;
}
.chat-body::-webkit-scrollbar{width:6px}
.chat-body::-webkit-scrollbar-track{background:transparent}
.chat-body::-webkit-scrollbar-thumb{background:rgba(207,214,224,.15);border-radius:3px}

.chat-msg{display:flex;align-items:flex-start;gap:12px;max-width:88%;animation:msg-in .3s var(--ease)}
@keyframes msg-in{from{opacity:0;transform:translateY(8px)}to{opacity:1;transform:none}}
.chat-msg-avatar{
  width:32px;height:32px;border-radius:50%;flex-shrink:0;
  display:flex;align-items:center;justify-content:center;
  font-family:'Space Grotesk',sans-serif;font-size:12px;font-weight:700;
}
.chat-msg.bot .chat-msg-avatar{
  background:linear-gradient(135deg,#1f6feb,#6b5cff,#a855f7,#e055b4);
  border:1px solid rgba(168,140,255,.4);
  color:#fff;
  box-shadow:0 0 12px rgba(120,90,255,.35);
}
.chat-msg.user{align-self:flex-end;flex-direction:row-reverse}
.chat-msg.user .chat-msg-avatar{
  background:linear-gradient(135deg, #f3d59a, #c9a86a);
  color:var(--navy-900);
}
.chat-msg-bubble{
  padding:12px 16px;border-radius:14px;
  font-size:14.5px;line-height:1.6;
  white-space:pre-wrap;word-wrap:break-word;
}
.chat-msg.bot .chat-msg-bubble{
  background:rgba(207,214,224,.08);
  border:1px solid rgba(207,214,224,.1);
  color:var(--silver-100);
  border-top-left-radius:4px;
}
.chat-msg.user .chat-msg-bubble{
  background:linear-gradient(135deg, rgba(243,213,154,.18), rgba(243,213,154,.08));
  border:1px solid rgba(243,213,154,.25);
  color:var(--white);
  border-top-right-radius:4px;
}

/* Rendered markdown inside bot bubbles */
.chat-msg-bubble.rendered{white-space:normal}
.chat-msg-bubble.rendered p{margin:0 0 9px}
.chat-msg-bubble.rendered p:last-child{margin-bottom:0}
.chat-msg-bubble.rendered ul,
.chat-msg-bubble.rendered ol{margin:6px 0 9px;padding-inline-start:20px}
.chat-msg-bubble.rendered ul:last-child,
.chat-msg-bubble.rendered ol:last-child{margin-bottom:0}
.chat-msg-bubble.rendered li{margin:3px 0}
.chat-msg-bubble.rendered strong{color:#fff;font-weight:700}
.chat-msg-bubble.rendered em{font-style:italic;color:var(--silver-100)}
.chat-msg-bubble.rendered code{
  background:rgba(255,255,255,.1);
  padding:1px 6px;border-radius:5px;
  font-family:'JetBrains Mono',ui-monospace,monospace;
  font-size:.88em;
}
.chat-msg-bubble.rendered a{color:var(--gold);text-decoration:underline}

.chat-msg-bubble.streaming::after{
  content:'';
  display:inline-block;
  width:7px;height:15px;
  margin-inline-start:2px;
  vertical-align:-2px;
  background:linear-gradient(180deg,#6b5cff,#a855f7);
  border-radius:1px;
  box-shadow:0 0 8px rgba(140,110,255,.7);
  animation:caret-blink 1s steps(1) infinite;
}
@keyframes caret-blink{50%{opacity:0}}

.chat-msg-bubble.is-typing{
  padding:11px 14px;
  width:auto;
  white-space:normal;
  font-size:0;
}
.chat-typing{display:inline-flex;gap:5px;align-items:center;line-height:1}
.chat-typing span{
  width:6px;height:6px;border-radius:50%;background:var(--silver-300);
  animation:typing 1.3s infinite;
}
.chat-typing span:nth-child(2){animation-delay:.15s}
.chat-typing span:nth-child(3){animation-delay:.3s}
@keyframes typing{
  0%,60%,100%{opacity:.3;transform:translateY(0)}
  30%{opacity:1;transform:translateY(-3px)}
}

/* Quick-action chips under relevant bot replies (added by chat.js) */
.chat-actions{
  display:flex;flex-wrap:wrap;gap:8px;
  padding-left:44px;            /* align under the bot bubble (avatar 32 + gap 12) */
  margin-top:-8px;              /* tuck under its message (body gap is 18px) */
  max-width:88%;
  animation:msg-in .3s var(--ease);
}
.chat-action{
  display:inline-flex;align-items:center;gap:7px;
  font-family:inherit;font-size:12.5px;font-weight:500;
  padding:7px 13px;border-radius:999px;
  text-decoration:none;cursor:pointer;
  border:1px solid rgba(207,214,224,.2);
  color:var(--silver-200);
  background:rgba(207,214,224,.06);
  transition:all .2s var(--ease);
}
.chat-action:hover{border-color:var(--gold);color:var(--gold)}
.chat-action svg{width:14px;height:14px;flex-shrink:0}
.chat-action.is-wa{
  color:#7fe3b0;
  border-color:rgba(37,211,102,.38);
  background:rgba(37,211,102,.10);
}
.chat-action.is-wa:hover{
  color:#d6f7e6;
  border-color:rgba(37,211,102,.7);
  background:rgba(37,211,102,.18);
}

.chat-suggestions{
  display:flex;flex-wrap:wrap;gap:8px;
  padding:0 22px 16px;
}
.chat-suggestion{
  background:rgba(207,214,224,.06);
  border:1px solid rgba(207,214,224,.15);
  color:var(--silver-200);
  font-size:12.5px;
  padding:8px 14px;border-radius:999px;
  cursor:pointer;
  transition:all .2s var(--ease);
  font-family:inherit;
}
.chat-suggestion:hover{
  border-color:rgba(140,110,255,.6);
  color:#cdbcff;
  background:rgba(120,90,255,.1);
}

.chat-input-wrap{
  padding:16px 22px 22px;
  border-top:1px solid rgba(207,214,224,.1);
  background:rgba(0,17,39,.5);
}
.chat-input-row{
  display:flex;gap:10px;align-items:flex-end;
  background:rgba(207,214,224,.06);
  border:1px solid rgba(207,214,224,.15);
  border-radius:14px;
  padding:8px 8px 8px 16px;
  transition:border-color .2s var(--ease);
}
.chat-input-row:focus-within{
  border-color:rgba(140,110,255,.6);
  box-shadow:0 0 0 3px rgba(120,90,255,.15);
}
.chat-input{
  flex:1;background:transparent;border:0;outline:0;
  color:var(--white);font-family:inherit;font-size:16px;
  resize:none;padding:10px 0;
  max-height:160px;line-height:1.5;
}
.chat-input::placeholder{color:var(--silver-400)}
.chat-send{
  width:40px;height:40px;border-radius:10px;border:0;
  background:linear-gradient(135deg,#1f6feb,#6b5cff,#a855f7,#e055b4);
  background-size:200% 100%;
  color:#fff;
  cursor:pointer;flex-shrink:0;
  display:flex;align-items:center;justify-content:center;
  box-shadow:0 4px 14px rgba(120,90,255,.4);
  transition:transform .15s var(--ease), opacity .2s, background-position .5s var(--ease), box-shadow .2s;
}
.chat-send:hover{transform:translateY(-1px);background-position:100% 0;box-shadow:0 6px 20px rgba(120,90,255,.6)}
.chat-send:disabled{opacity:.4;cursor:not-allowed;transform:none}
.chat-send svg{width:18px;height:18px}

.chat-disclaimer{
  text-align:center;margin-top:12px;
  font-size:11px;color:var(--silver-400);letter-spacing:.3px;
}
.chat-disclaimer a{color:var(--silver-300);text-decoration:underline}

@media (max-width:720px){
  .chat-page{padding:90px 10px 24px}
  .chat-shell{height:calc(100vh - 120px);min-height:520px;border-radius:14px}
  .chat-head{padding:12px 14px;gap:10px}
  .chat-head-avatar{width:36px;height:36px}
  .chat-head-avatar svg{width:18px;height:18px}
  .chat-head-meta strong{font-size:13.5px;line-height:1.2}
  .chat-head-meta span{font-size:11px}
  .chat-head-clear{padding:6px 11px;font-size:10.5px;letter-spacing:.6px}
  .chat-body{padding:16px 14px;gap:14px}
  .chat-msg{max-width:96%}
  .chat-msg-avatar{width:28px;height:28px;font-size:10.5px}
  .chat-msg-bubble{font-size:14px;padding:10px 13px}
  .chat-suggestions{padding:0 14px 10px;gap:6px}
  .chat-suggestion{font-size:11.5px;padding:6px 11px}
  .chat-actions{padding-left:40px;max-width:96%;gap:6px}
  .chat-action{font-size:11.5px;padding:6px 11px}
  .chat-input-wrap{padding:10px 14px 14px}
  .chat-input{font-size:16px} /* must stay >=16px to stop iOS auto-zoom on focus */
  .chat-disclaimer{font-size:10.5px;line-height:1.45}
}
@media (max-width:400px){
  .chat-head-meta span{display:none}
  .chat-head-meta strong{font-size:13px}
}

/* ===== Mobile keyboard mode (toggled by chat.js while the input is focused) =====
   Locks the page so iOS can't scroll it, and pins the chat to the visible
   viewport so the input stays above the keyboard. Only the message list scrolls. */
html.kb-open, html.kb-open body{
  overflow:hidden;
  height:100%;
  /* iOS pull-to-refresh / rubber-banding off while typing */
  overscroll-behavior:none;
}
html.kb-open .nav,
html.kb-open .footer{display:none}
html.kb-open .chat-page{
  position:fixed;
  top:var(--kb-top, 0px);
  left:0;right:0;
  height:var(--kb-height, 100vh);
  min-height:0;
  padding:8px;
  z-index:100;
}
html.kb-open .chat-shell{
  height:100%;
  min-height:0;
}
