/* EITCA Support Messaging - Chat Widget */
#eitca-sm-widget.eitca-sm-widget {
  position: fixed;
  right: 18px;
  bottom: 18px;
  width: 340px;
  max-width: calc(100vw - 36px);
  z-index: 999999;
  font-family: Arial, sans-serif;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  border-radius: 10px;
  overflow: hidden;
  background: #fff;

  /* Needed for maximize + mobile modal layouts */
  display: flex;
  flex-direction: column;
}

#eitca-sm-widget .eitca-sm-header {
  display: flex;  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  cursor: pointer;
  background: rgba(0, 51, 153, 0.9);
  color: #fff;
  user-select: none;
}

#eitca-sm-widget .eitca-sm-header i { font-size: 16px; }
#eitca-sm-widget .eitca-sm-header span { font-weight: 700; font-size: 13px; letter-spacing: .4px; }

/* Right-side header controls wrapper (injected by JS) */
#eitca-sm-widget .eitca-sm-header-actions{
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

/* Toggle arrow */
#eitca-sm-widget .eitca-sm-toggle{
  opacity: .9;
  transition: transform 160ms ease, opacity 160ms ease;
}

/* Arrow points DOWN when expanded (your requirement #2) */
#eitca-sm-widget .eitca-sm-header[aria-expanded="true"] .eitca-sm-toggle{
  transform: rotate(180deg);
  opacity: 1;
}

/* FIX #1: remove ugly grey button chrome (theme styles) */
#eitca-sm-widget .eitca-sm-max-btn{
  appearance: none !important;
  -webkit-appearance: none !important;
  background: transparent !important;
  border: 0 !important;
  box-shadow: none !important;

  color: #fff !important;
  width: 30px;
  height: 30px;
  padding: 0 !important;
  margin: 0 !important;

  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;

  cursor: pointer;
  line-height: 1;
}

#eitca-sm-widget .eitca-sm-max-btn:hover{
  background: rgba(255,255,255,0.14) !important;
}

#eitca-sm-widget .eitca-sm-max-btn i{
  font-size: 15px;
}

/* Default hidden; shown when open */
#eitca-sm-widget .eitca-sm-max-btn{
  display: none;
}
#eitca-sm-widget.is-open .eitca-sm-max-btn{
  display: inline-flex;
}


/* Body must be column when JS sets display:flex (FIX #3 two columns) */
#eitca-sm-widget .eitca-sm-body {
  padding: 12px 12px 10px;
  flex-direction: column; /* critical */
  align-items: stretch;
}

/* Thread */
#eitca-sm-widget .eitca-sm-thread {
  max-height: 220px;
  overflow: auto;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 10px;
  margin-bottom: 10px;
  background: #fafafa;
}

#eitca-sm-widget .eitca-sm-thread .msg { margin-bottom: 10px; }
#eitca-sm-widget .eitca-sm-thread .msg:last-child { margin-bottom: 0; }

#eitca-sm-widget .eitca-sm-thread .msg .meta {
  font-size: 11px;
  color: #6b7280;
  margin-bottom: 2px;
}
#eitca-sm-widget .eitca-sm-thread .msg .bubble {
  display: inline-block;
  padding: 8px 10px;
  border-radius: 10px;
  max-width: 100%;
  white-space: normal;
  word-wrap: break-word;
  font-size: 13px;
}
#eitca-sm-widget .eitca-sm-thread .msg.in .bubble {
  background: #fff;
  border: 1px solid #e5e7eb;
}
#eitca-sm-widget .eitca-sm-thread .msg.out .bubble {
  background: #e0f2fe;
  border: 1px solid #bae6fd;
}

#eitca-sm-widget .eitca-sm-lead {
  font-weight: 700;
  margin-bottom: 8px;
  color: #111827;
}

#eitca-sm-widget label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  margin-top: 8px;
  margin-bottom: 4px;
  color: #374151;
}

#eitca-sm-widget input[type="text"],
#eitca-sm-widget input[type="email"],
#eitca-sm-widget textarea {
  width: 100%;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
  box-sizing: border-box;
}

#eitca-sm-widget textarea {
  min-height: 80px;
  resize: vertical;
}

#eitca-sm-widget input:focus,
#eitca-sm-widget textarea:focus {
  border-color: #60a5fa;
  box-shadow: 0 0 0 3px rgba(96,165,250,.25);
}

#eitca-sm-widget .eitca-sm-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}

#eitca-sm-widget .eitca-sm-btn {
  border: 0;
  border-radius: 8px;
  padding: 10px 12px;
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  background: rgba(0, 51, 153, 0.9);
  text-transform: uppercase;
}

#eitca-sm-widget .eitca-sm-btn:hover{
  background: rgba(0, 51, 153, 1);
}

#eitca-sm-widget .eitca-sm-btn.eitca-sm-escalate { background: #f59e0b; }

#eitca-sm-widget .eitca-sm-ntf {
  flex: 1;
  min-width: 120px;
  font-size: 12px;
  color: #374151;
}

#eitca-sm-widget .eitca-sm-small {
  margin-top: 10px;
  font-size: 11px;
  color: #6b7280;
}

#eitca-sm-widget .btn-loader {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,.55);
  border-top-color: rgba(255,255,255,1);
  animation: eitca-sm-spin 0.9s linear infinite;
  display: inline-block;
  vertical-align: middle;
}

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

#eitca-sm-widget .eitca-sm-btn.eitca-sm-escalate.is-disabled{
  opacity: .65;
  cursor: not-allowed;
}

/* FIX #3: real maximize mode (desktop) */
#eitca-sm-widget.eitca-sm-maximized{
  top: 18px;
  left: 18px;
  right: 18px;
  bottom: 18px;

  width: auto;
  max-width: none;

  height: auto;
  border-radius: 12px;
}

/* Let body fill height when maximized */
#eitca-sm-widget.eitca-sm-maximized .eitca-sm-body{
  flex: 1 1 auto;
  overflow: hidden;
}

/* Thread becomes the main scroll area */
#eitca-sm-widget.eitca-sm-maximized .eitca-sm-thread{
  flex: 1 1 auto;
  max-height: none;
}

/* Bigger typing area when maximized */
#eitca-sm-widget.eitca-sm-maximized textarea{
  min-height: 140px;
}

/* =========================================================
   Widget UI fixes
   ========================================================= */

/* Header layout: keep icons stable and arrow on the right */
#eitca-sm-widget .eitca-sm-header{
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Push the toggle arrow to the far right (and keep it there) */
#eitca-sm-widget .eitca-sm-header .eitca-sm-toggle{
  margin-left: auto;
  flex: 0 0 auto;
}

/* CLOSE (X) icon: mobile only */
@media (min-width: 641px){
  #eitca-sm-widget .eitca-sm-close,
  #eitca-sm-widget .eitca-sm-x,
  #eitca-sm-widget .eitca-sm-dismiss{
    display: none !important;
  }
}

@media (max-width: 640px){
  #eitca-sm-widget .eitca-sm-close,
  #eitca-sm-widget .eitca-sm-x,
  #eitca-sm-widget .eitca-sm-dismiss{
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
  }
}

/* Desktop fullscreen expansion: reduce size a bit */
@media (min-width: 641px){
  #eitca-sm-widget.eitca-sm-fullscreen,
  #eitca-sm-widget.is-fullscreen,
  #eitca-sm-widget.fullscreen{
    /* Smaller than typical 90vw/90vh */
    width: min(600px, calc(100vw - 40px));
    height: min(720px, calc(100vh - 40px));
    max-width: 600px;
    max-height: 720px;
  }
}


#eitca-sm-widget .bubble a { text-decoration: underline; }
#eitca-sm-widget .bubble a:hover { text-decoration: none; }
#eitca-sm-widget .bubble a { cursor: pointer; }


#eitca-sm-widget .eitca-sm-new-msg{
  width: 100%;
  border: 1px solid #e5e7eb;
  background: #fff;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 12px;
  cursor: pointer;
  margin: 0 0 10px;
}


/* =========================================================
   MOBILE FIX PACK (circle button + usable scrolling)
   Paste at END of chat.css
   ========================================================= */

/* Make flex scrolling reliable (critical on mobile/iOS) */
#eitca-sm-widget .eitca-sm-body,
#eitca-sm-widget .eitca-sm-thread {
  min-height: 0; /* allows inner overflow:auto to work in flex layouts */
}

/* Better momentum scrolling on iOS */
#eitca-sm-widget .eitca-sm-thread {
  -webkit-overflow-scrolling: touch;
}

@media (max-width: 640px) {

  /* ---------- CLOSED: smaller circular launcher + no “1px ring” ---------- */
  #eitca-sm-widget.eitca-sm-widget:not(.is-open){
    width: 42px !important;
    height: 42px !important;
    max-width: none !important;
    border-radius: 9999px !important;

    /* remove ring caused by widget bg/shadow and focus outlines */
    background: transparent !important;
    box-shadow: none !important;
    border: 0 !important;
    outline: none !important;

    overflow: hidden !important;
  }

  /* Header fills the circle */
  #eitca-sm-widget:not(.is-open) .eitca-sm-header{
    width: 42px !important;
    height: 42px !important;
    padding: 0 !important;
    border-radius: 9999px !important;
    justify-content: center !important;
    gap: 0 !important;

    box-shadow: none !important;
    border: 0 !important;
    outline: none !important;
  }

  /* Remove browser focus ring on the “button-like” header */
  #eitca-sm-widget:not(.is-open) .eitca-sm-header:focus,
  #eitca-sm-widget:not(.is-open) .eitca-sm-header:active{
    outline: none !important;
    box-shadow: none !important;
  }

  /* Only keep the left chat icon when closed */
  #eitca-sm-widget:not(.is-open) .eitca-sm-header span{ display:none !important; }
  #eitca-sm-widget:not(.is-open) .eitca-sm-header-actions{ display:none !important; }
  #eitca-sm-widget:not(.is-open) .eitca-sm-toggle{ display:none !important; }

  /* Icon sizing/centering inside smaller circle */
  #eitca-sm-widget:not(.is-open) .eitca-sm-header > i:first-child{
    font-size: 18px !important;
    line-height: 1 !important;
  }

  /* Keep widget anchored nicely above safe-area + mobile bars */
  #eitca-sm-widget.eitca-sm-widget{
    right: 12px !important;
    bottom: calc(12px + env(safe-area-inset-bottom)) !important;
  }

  /* ---------- OPEN: real modal with correct height + scroll ---------- */
  #eitca-sm-widget.is-open{
    top: calc(12px + env(safe-area-inset-top)) !important;
    left: 12px !important;
    right: 12px !important;
    bottom: calc(12px + env(safe-area-inset-bottom)) !important;

    width: auto !important;
    max-width: none !important;

    /* Real viewport-based height so it doesn’t overflow small screens */
    height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;
    /* fallback for browsers without dvh */
    height: calc(100svh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom)) !important;

    border-radius: 12px !important;
  }

  /* Body uses full available height */
  #eitca-sm-widget.is-open .eitca-sm-body{
    display: flex !important;
    flex: 1 1 auto !important;
    overflow: hidden !important; /* keep the modal stable; thread scrolls */
  }

  /* Thread becomes the scroll container */
  #eitca-sm-widget.is-open .eitca-sm-thread{
    flex: 1 1 auto !important;
    max-height: none !important;
    overflow: auto !important;
  }

  /* Keep the form visible; allow it to wrap but not push the modal */
  #eitca-sm-widget.is-open .eitca-sm-form-wrap{
    flex: 0 0 auto !important;
  }

  /* Optional: reduce textarea height on very small screens */
  #eitca-sm-widget.is-open textarea{
    min-height: 96px !important;
    resize: none !important;
  }
}

/* =========================================================
   LOW-HEIGHT MOBILE: make the whole widget body scroll
   (prevents clipped footer + cut bubbles)
   ========================================================= */
@media (max-width: 640px) and (max-height: 620px) {

  /* Let the BODY scroll (single scroll container) */
  #eitca-sm-widget.is-open .eitca-sm-body{
    overflow: auto !important;
    -webkit-overflow-scrolling: touch;
    padding-bottom: calc(14px + env(safe-area-inset-bottom)) !important;
  }

  /* Thread becomes normal content (no inner scroll) */
  #eitca-sm-widget.is-open .eitca-sm-thread{
    flex: 0 0 auto !important;
    overflow: visible !important;
    max-height: none !important;
  }
}
