/* ============================================================
   RSI COATINGS — Chat Assistant Widget
   ============================================================ */

.rsi-chat-btn{
  position:fixed;right:24px;bottom:152px;z-index:150;
  width:52px;height:52px;border-radius:50%;border:none;cursor:pointer;padding:0;
  display:flex;align-items:center;justify-content:center;
  background:var(--green-900,#0B4A38);color:#fff;
  box-shadow:var(--shadow,0 24px 56px -24px rgba(11,74,56,.28));
  transition:transform .25s ease, box-shadow .25s ease, opacity .2s ease;
}
.rsi-chat-btn:hover{transform:translateY(-3px) scale(1.05);box-shadow:0 18px 34px -14px rgba(11,74,56,.5);}
.rsi-chat-btn:focus-visible{outline:2px solid var(--green-500,#14A085);outline-offset:3px;}
.rsi-chat-btn[hidden]{display:none;}

/* Small "1" badge that fades in once, to invite the first click */
.rsi-chat-btn::after{
  content:"";position:absolute;top:2px;right:2px;width:11px;height:11px;border-radius:50%;
  background:var(--green-500,#14A085);border:2px solid #fff;
  transform:scale(0);transition:transform .3s ease .8s;
}
.rsi-chat-btn.is-new::after{transform:scale(1);}

/* ---------- Panel ---------- */
.rsi-chat{
  position:fixed;right:24px;bottom:24px;z-index:200;
  width:384px;max-width:calc(100vw - 32px);
  height:min(600px,calc(100vh - 48px));height:min(600px,calc(100dvh - 48px));
  display:flex;flex-direction:column;overflow:hidden;
  background:var(--paper,#fff);border:1px solid var(--line,#E4E7E3);
  border-radius:20px;
  box-shadow:0 32px 70px -20px rgba(11,74,56,.42);
  font-family:'Inter',system-ui,sans-serif;color:var(--ink,#14181B);
  transform-origin:bottom right;
  animation:rsiPanelIn .22s cubic-bezier(.2,.8,.3,1);
}
.rsi-chat[hidden]{display:none;}
@keyframes rsiPanelIn{from{opacity:0;transform:translateY(14px) scale(.97);}to{opacity:1;transform:none;}}
@media (prefers-reduced-motion:reduce){.rsi-chat{animation:none;}}

/* ---------- Header ---------- */
.rsi-chat-head{
  display:flex;align-items:center;gap:12px;padding:16px 18px;
  background:linear-gradient(135deg,var(--green-900,#0B4A38),var(--green-700,#116B4E));
  color:#fff;flex:none;
}
.rsi-chat-avatar{
  position:relative;width:40px;height:40px;border-radius:50%;flex:none;
  background:#fff;box-shadow:0 0 0 2px rgba(255,255,255,.25);
  display:flex;align-items:center;justify-content:center;
}
.rsi-chat-avatar img{width:30px;height:30px;object-fit:contain;}
.rsi-chat-avatar .rsi-chat-dot{
  position:absolute;right:0;bottom:1px;width:10px;height:10px;border:2px solid var(--green-900,#0B4A38);
}
.rsi-chat-head-txt{flex:1;min-width:0;}
.rsi-chat-title{font-family:'Poppins',sans-serif;font-weight:600;font-size:15px;line-height:1.25;letter-spacing:.01em;}
.rsi-chat-status{
  display:flex;align-items:center;gap:6px;margin-top:3px;
  font-size:11.5px;color:rgba(255,255,255,.72);letter-spacing:.01em;
}
.rsi-chat-dot{width:6px;height:6px;border-radius:50%;background:#4ADE80;flex:none;}
.rsi-chat-close{
  background:none;border:none;color:rgba(255,255,255,.8);cursor:pointer;
  width:30px;height:30px;border-radius:8px;display:flex;align-items:center;justify-content:center;flex:none;
  transition:background .2s ease,color .2s ease;
}
.rsi-chat-close:hover{background:rgba(255,255,255,.16);color:#fff;}

/* ---------- Message log ---------- */
.rsi-chat-log{
  flex:1;overflow-y:auto;overscroll-behavior:contain;
  padding:18px 18px 8px;display:flex;flex-direction:column;gap:12px;
  background:var(--gray-100,#F4F5F3);
  scrollbar-width:thin;scrollbar-color:#CBD2CD transparent;
}
.rsi-chat-log::-webkit-scrollbar{width:6px;}
.rsi-chat-log::-webkit-scrollbar-thumb{background:#CBD2CD;border-radius:3px;}

.rsi-msg{max-width:88%;font-size:13.5px;line-height:1.6;overflow-wrap:anywhere;}
.rsi-msg--bot{
  align-self:flex-start;background:var(--paper,#fff);
  border:1px solid var(--line,#E4E7E3);border-radius:14px 14px 14px 4px;
  padding:11px 14px;box-shadow:0 2px 6px -4px rgba(11,74,56,.25);
}
.rsi-msg--user{
  align-self:flex-end;background:var(--green-900,#0B4A38);color:#fff;
  border-radius:14px 14px 4px 14px;padding:11px 14px;white-space:pre-wrap;
}
.rsi-msg--error{
  align-self:flex-start;background:#FDECEA;color:#8A1F17;border:1px solid #F3C6C1;
  border-radius:14px 14px 14px 4px;padding:11px 14px;
}

/* ---------- Rich content inside bot replies ---------- */
.rsi-msg--bot > *:first-child{margin-top:0;}
.rsi-msg--bot > *:last-child{margin-bottom:0;}
.rsi-msg p{margin:0 0 8px;}
.rsi-msg p:last-child{margin-bottom:0;}
.rsi-msg strong{font-weight:600;color:var(--green-900,#0B4A38);}
.rsi-msg ul,.rsi-msg ol{margin:6px 0 8px;padding-left:18px;}
.rsi-msg ul{list-style:disc;}
.rsi-msg ol{list-style:decimal;}
.rsi-msg li{margin:0 0 5px;padding-left:2px;}
.rsi-msg li::marker{color:var(--green-500,#14A085);}
.rsi-msg a{color:var(--green-700,#116B4E);font-weight:500;text-decoration:underline;text-underline-offset:2px;}
.rsi-msg code{
  background:var(--gray-150,#EEF0EC);border-radius:4px;padding:1px 5px;
  font-family:ui-monospace,SFMono-Regular,Menlo,monospace;font-size:12px;
}

/* Price tables: compact, scrollable, easy to scan */
.rsi-table-wrap{margin:8px -4px;overflow-x:auto;-webkit-overflow-scrolling:touch;}
.rsi-msg table{border-collapse:collapse;width:100%;font-size:12.5px;line-height:1.4;}
.rsi-msg thead th{
  background:var(--green-100,#E9F4EF);color:var(--green-900,#0B4A38);
  font-weight:600;font-size:11px;text-transform:uppercase;letter-spacing:.04em;
  text-align:left;padding:7px 10px;white-space:nowrap;
}
.rsi-msg thead th:first-child{border-radius:6px 0 0 0;}
.rsi-msg thead th:last-child{border-radius:0 6px 0 0;}
.rsi-msg tbody td{padding:7px 10px;border-bottom:1px solid var(--line,#E4E7E3);white-space:nowrap;}
.rsi-msg tbody tr:last-child td{border-bottom:none;}
.rsi-msg tbody td:first-child{font-weight:600;color:var(--ink,#14181B);}
.rsi-msg tbody td+td{color:var(--ink-soft,#5B6560);text-align:right;}
.rsi-msg thead th+th{text-align:right;}

/* ---------- Typing indicator ---------- */
.rsi-typing{display:inline-flex;gap:4px;align-items:center;padding:2px 0;}
.rsi-typing i{width:6px;height:6px;border-radius:50%;background:var(--ink-faint,#8B948F);animation:rsiBlink 1.3s infinite ease-in-out;}
.rsi-typing i:nth-child(2){animation-delay:.18s;}
.rsi-typing i:nth-child(3){animation-delay:.36s;}
@keyframes rsiBlink{0%,80%,100%{opacity:.25;transform:translateY(0);}40%{opacity:1;transform:translateY(-2px);}}

/* ---------- Suggested questions ---------- */
.rsi-chips{display:flex;flex-wrap:wrap;gap:7px;padding:2px 18px 14px;background:var(--gray-100,#F4F5F3);flex:none;}
.rsi-chips[hidden]{display:none;}
.rsi-chip{
  font:inherit;font-size:12px;font-weight:500;cursor:pointer;
  background:var(--paper,#fff);color:var(--green-900,#0B4A38);
  border:1px solid #CFE0D7;border-radius:999px;padding:7px 13px;
  transition:background .18s ease,border-color .18s ease,transform .18s ease;
}
.rsi-chip:hover{background:var(--green-100,#E9F4EF);border-color:var(--green-500,#14A085);transform:translateY(-1px);}

/* ---------- Composer ---------- */
.rsi-chat-form{
  display:flex;align-items:flex-end;gap:9px;padding:12px 14px;flex:none;
  border-top:1px solid var(--line,#E4E7E3);background:var(--paper,#fff);
}
.rsi-chat-input{
  flex:1;min-width:0;resize:none;overflow-y:auto;max-height:96px;
  padding:11px 15px;border:1px solid var(--line,#E4E7E3);border-radius:20px;
  font:inherit;font-size:13.5px;line-height:1.5;color:inherit;background:var(--gray-100,#F4F5F3);
  transition:border-color .2s ease,background .2s ease;
}
.rsi-chat-input::placeholder{color:var(--ink-faint,#8B948F);}
.rsi-chat-input:focus{outline:none;border-color:var(--green-500,#14A085);background:var(--paper,#fff);}
.rsi-chat-send{
  flex:none;width:40px;height:40px;border:none;border-radius:50%;cursor:pointer;
  background:var(--green-900,#0B4A38);color:#fff;
  display:flex;align-items:center;justify-content:center;
  transition:background .2s ease,transform .2s ease,opacity .2s ease;
}
.rsi-chat-send:hover:not(:disabled){background:var(--green-700,#116B4E);transform:scale(1.06);}
.rsi-chat-send:disabled{opacity:.4;cursor:default;}

.rsi-chat-foot{
  flex:none;text-align:center;font-size:10.5px;color:var(--ink-faint,#8B948F);
  padding:0 14px 10px;background:var(--paper,#fff);letter-spacing:.01em;
}

/* ---------- Touch devices ----------
   Hover lifts "stick" after a tap on touch screens, so only apply them
   where a real pointer can hover. */
@media (hover:none){
  .rsi-chat-btn:hover,
  .rsi-chip:hover,
  .rsi-chat-send:hover:not(:disabled){transform:none;}
  .rsi-chat-btn:active{transform:scale(.94);}
  .rsi-chip:active{background:var(--green-100,#E9F4EF);border-color:var(--green-500,#14A085);}
  .rsi-chat-send:active:not(:disabled){transform:scale(.92);}
}
.rsi-chat,.rsi-chat button{-webkit-tap-highlight-color:transparent;touch-action:manipulation;}

/* Page behind the chat stays still while the full-screen chat is open */
html.rsi-chat-lock,html.rsi-chat-lock body{overflow:hidden;}

/* ---------- Mobile ---------- */
@media (max-width:520px){
  .rsi-chat-btn{
    right:calc(16px + env(safe-area-inset-right));
    bottom:calc(148px + env(safe-area-inset-bottom));
    width:56px;height:56px;
  }

  /* Full-screen chat. --rsi-vh is set from visualViewport in chatbot.js so
     the composer stays above the on-screen keyboard (iOS doesn't shrink
     100dvh for the keyboard). */
  .rsi-chat{
    top:var(--rsi-top,0px);right:0;left:0;bottom:auto;
    width:100%;max-width:100%;
    height:100vh;height:100dvh;height:var(--rsi-vh,100dvh);
    border:none;border-radius:0;box-shadow:none;
    transform-origin:bottom center;
    animation-name:rsiSheetIn;animation-duration:.26s;
  }

  .rsi-chat-head{
    padding:12px 12px 12px 16px;
    padding-top:calc(12px + env(safe-area-inset-top));
    padding-left:calc(16px + env(safe-area-inset-left));
    padding-right:calc(12px + env(safe-area-inset-right));
  }
  .rsi-chat-avatar{width:38px;height:38px;}
  .rsi-chat-avatar img{width:28px;height:28px;}
  .rsi-chat-title{font-size:16px;}
  .rsi-chat-status{font-size:12px;}
  .rsi-chat-close{width:44px;height:44px;border-radius:12px;background:rgba(255,255,255,.1);}
  .rsi-chat-close svg{width:20px;height:20px;}

  .rsi-chat-log{
    padding:16px 14px 8px;gap:10px;
    padding-left:calc(14px + env(safe-area-inset-left));
    padding-right:calc(14px + env(safe-area-inset-right));
    -webkit-overflow-scrolling:touch;
  }
  .rsi-msg{max-width:88%;font-size:15px;line-height:1.55;}
  .rsi-msg--bot,.rsi-msg--user,.rsi-msg--error{padding:10px 14px;}
  .rsi-msg table{font-size:13.5px;}
  .rsi-msg code{font-size:13px;}
  .rsi-table-wrap{margin:8px -6px;}

  /* Suggestions become one swipeable row instead of stacking */
  .rsi-chips{
    flex-wrap:nowrap;overflow-x:auto;gap:8px;
    padding:4px 14px 12px;
    scrollbar-width:none;-webkit-overflow-scrolling:touch;
    scroll-padding:0 14px;
  }
  .rsi-chips::-webkit-scrollbar{display:none;}
  .rsi-chip{flex:none;font-size:14px;padding:10px 16px;white-space:nowrap;}

  .rsi-chat-form{
    gap:8px;padding:10px 10px 8px 12px;
    padding-left:calc(12px + env(safe-area-inset-left));
    padding-right:calc(10px + env(safe-area-inset-right));
  }
  .rsi-chat-input{
    font-size:16px; /* keeps iOS from zooming on focus */
    padding:11px 16px;border-radius:22px;max-height:120px;
  }
  .rsi-chat-send{width:44px;height:44px;}
  .rsi-chat-send svg{width:19px;height:19px;}

  .rsi-chat-foot{
    font-size:11px;padding:0 16px 8px;
    padding-bottom:calc(8px + env(safe-area-inset-bottom));
  }
  /* While typing, the keyboard already covers the home-bar area */
  .rsi-chat.is-typing .rsi-chat-foot{display:none;}
  .rsi-chat.is-typing .rsi-chat-form{padding-bottom:10px;}
}
@keyframes rsiSheetIn{from{opacity:0;transform:translateY(24px);}to{opacity:1;transform:none;}}

/* Short landscape phones: reclaim vertical space for messages */
@media (max-width:920px) and (max-height:480px) and (orientation:landscape){
  .rsi-chat{
    top:var(--rsi-top,0px);right:0;left:0;bottom:auto;width:100%;max-width:100%;
    height:100vh;height:100dvh;height:var(--rsi-vh,100dvh);
    border:none;border-radius:0;
  }
  .rsi-chat-head{padding-top:8px;padding-bottom:8px;}
  .rsi-chat-status,.rsi-chat-foot{display:none;}
  .rsi-chat-avatar{width:32px;height:32px;}
  .rsi-chat-avatar img{width:24px;height:24px;}
  .rsi-chat-log{padding-top:10px;}
  .rsi-chat-input{font-size:16px;max-height:64px;}
}
