/* QLMX Chat frontend — responsive desktop / tablet / mobile */
.qlmx-chat {
  --qlmx-accent: #4699cd;
  --qlmx-panel-width: 400px;
  --qlmx-panel-height: 640px;
  --qlmx-edge: 20px;
  --qlmx-radius: 20px;
  /* Keep the plugin itself out of document flow. The interactive children are
     viewport-fixed below. This also minimizes interference from theme CSS. */
  position: fixed !important;
  top: 0 !important;
  left: 0 !important;
  width: 0 !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  z-index: 2147483000 !important;
  pointer-events: none !important;
  transform: none !important;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #182230;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

.qlmx-chat *, .qlmx-chat *::before, .qlmx-chat *::after { box-sizing: border-box; }

/* Launcher */
.qlmx-launcher {
  position: fixed !important;
  bottom: var(--qlmx-edge) !important;
  pointer-events: auto !important;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 54px;
  max-width: min(320px, calc(100vw - 40px));
  border: 0;
  border-radius: 999px;
  background: var(--qlmx-accent) !important;
  color: #fff !important;
  padding: 9px 17px 9px 9px;
  box-shadow: 0 12px 34px rgba(16, 24, 40, .22);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .18s ease, box-shadow .18s ease;
}
.qlmx-launcher:hover { transform: translateY(-1px); box-shadow: 0 16px 40px rgba(16, 24, 40, .26); }
.qlmx-launcher:focus-visible { outline: 3px solid color-mix(in srgb, var(--qlmx-accent) 30%, white); outline-offset: 3px; }
.qlmx-launcher-icon {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: rgba(255, 255, 255, .18);
  font-size: 20px;
}
.qlmx-launcher-logo-wrap {
  width: 50px;
  height: 36px;
  flex: 0 0 50px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 5px;
  background: #fff;
  border-radius: 9px;
  box-shadow: 0 1px 3px rgba(16, 24, 40, .12);
  overflow: hidden;
}
.qlmx-launcher-logo {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
}
.qlmx-launcher-label {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.qlmx-chat.is-open .qlmx-launcher {
  opacity: 0 !important;
  visibility: hidden !important;
  pointer-events: none !important;
}

/* Panel: flex layout removes hard-coded content-height calculations. */
.qlmx-panel {
  position: fixed !important;
  bottom: var(--qlmx-edge) !important;
  pointer-events: auto !important;
  width: min(var(--qlmx-panel-width), calc(100vw - 32px));
  height: min(var(--qlmx-panel-height), calc(100dvh - 40px));
  min-height: 420px;
  display: flex;
  flex-direction: column;
  background: #fff !important;
  border: 1px solid rgba(16, 24, 40, .10) !important;
  border-radius: var(--qlmx-radius) !important;
  box-shadow: 0 26px 80px rgba(16, 24, 40, .28);
  overflow: hidden;
  isolation: isolate;
}
.qlmx-chat--right .qlmx-launcher, .qlmx-chat--right .qlmx-panel { right: var(--qlmx-edge) !important; left: auto !important; }
.qlmx-chat--left .qlmx-launcher, .qlmx-chat--left .qlmx-panel { left: var(--qlmx-edge) !important; right: auto !important; }
.qlmx-panel[hidden] { display: none !important; }

/* Header */
.qlmx-header {
  flex: 0 0 auto;
  min-height: 74px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 13px;
  background: var(--qlmx-accent) !important;
  color: #fff !important;
}
.qlmx-header-logo-wrap {
  width: 66px;
  height: 46px;
  flex: 0 0 66px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 5px 7px;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 3px rgba(16, 24, 40, .12);
}
.qlmx-header-logo {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  object-position: center;
}
.qlmx-avatar-wrap { flex: 0 0 auto; }
.qlmx-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: contain;
  background: #fff;
  border: 2px solid rgba(255, 255, 255, .42);
}
.qlmx-avatar--fallback {
  display: grid;
  place-items: center;
  color: var(--qlmx-accent);
  font-weight: 800;
}
.qlmx-header-copy {
  min-width: 0;
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.qlmx-header-copy strong {
  display: block;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  line-height: 1.25;
}
.qlmx-close, .qlmx-clear {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  touch-action: manipulation;
  line-height: 1;
}
.qlmx-close { font-size: 26px; }
.qlmx-clear { font-size: 18px; }
.qlmx-close:hover, .qlmx-clear:hover,
.qlmx-close:focus-visible, .qlmx-clear:focus-visible { background: rgba(255, 255, 255, .15); outline: none; }

/* Conversation body */
.qlmx-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 18px;
  background: #f7f8fa;
  scroll-behavior: smooth;
  scrollbar-gutter: stable;
}
.qlmx-message {
  width: fit-content;
  max-width: 86%;
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.qlmx-message a { color: inherit; text-decoration: underline; font-weight: 650; }
.qlmx-message--assistant {
  margin-right: auto;
  background: #fff;
  border: 1px solid rgba(16, 24, 40, .08);
  border-top-left-radius: 4px;
}
.qlmx-message--user {
  margin-left: auto;
  background: var(--qlmx-accent);
  color: #fff;
  border-top-right-radius: 4px;
}

/* Typing indicator participates in layout instead of floating over content. */
.qlmx-typing {
  flex: 0 0 auto;
  align-self: flex-start;
  margin: 8px 16px 0;
  padding: 9px 11px;
  background: #fff;
  border: 1px solid rgba(16, 24, 40, .08);
  border-radius: 13px;
  box-shadow: 0 2px 8px rgba(16, 24, 40, .05);
}
.qlmx-typing[hidden] { display: none !important; }
.qlmx-typing span {
  display: inline-block;
  width: 7px;
  height: 7px;
  margin: 0 2px;
  border-radius: 50%;
  background: #98a2b3;
  animation: qlmxBounce 1.2s infinite ease-in-out;
}
.qlmx-typing span:nth-child(2) { animation-delay: .15s; }
.qlmx-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes qlmxBounce { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-4px); } }

/* Composer */
.qlmx-form {
  flex: 0 0 auto;
  min-height: 72px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  padding: 11px 12px;
  border-top: 1px solid rgba(16, 24, 40, .08);
  background: #fff;
}
.qlmx-form textarea {
  flex: 1 1 auto;
  width: 100%;
  min-width: 0;
  min-height: 46px;
  max-height: 120px;
  resize: none;
  overflow-y: auto;
  border: 1px solid #d0d5dd;
  border-radius: 13px;
  padding: 11px 12px;
  background: #fff;
  color: #101828;
  font: inherit;
  font-size: 16px; /* prevents iOS focus zoom */
  line-height: 1.4;
  outline: none;
}
.qlmx-form textarea::placeholder { color: #98a2b3; }
.qlmx-form textarea:focus {
  border-color: var(--qlmx-accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--qlmx-accent) 16%, transparent);
}
.qlmx-send {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 13px;
  background: var(--qlmx-accent);
  color: #fff;
  font-size: 19px;
  cursor: pointer;
  touch-action: manipulation;
}
.qlmx-send:disabled { opacity: .52; cursor: not-allowed; }
.qlmx-send:focus-visible { outline: 3px solid color-mix(in srgb, var(--qlmx-accent) 25%, white); outline-offset: 2px; }

.qlmx-footer {
  flex: 0 0 auto;
  min-height: 25px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px 10px;
  border-top: 1px solid rgba(16, 24, 40, .06);
  background: #fff;
  color: #667085;
  font-size: 10px;
}
.qlmx-footer strong { margin-left: 3px; color: #344054; }

.screen-reader-text {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* Job result cards */
.qlmx-job-results {
  display: grid;
  gap: 9px;
  width: min(94%, 520px);
  max-width: 100%;
  margin: -2px 0 14px;
}
.qlmx-job-card {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 0;
  padding: 12px 13px;
  background: #fff;
  border: 1px solid rgba(16, 24, 40, .10);
  border-left: 3px solid var(--qlmx-accent);
  border-radius: 12px;
  text-decoration: none !important;
  color: #182230 !important;
  box-shadow: 0 2px 8px rgba(16, 24, 40, .05);
  transition: transform .15s ease, box-shadow .15s ease;
}
.qlmx-job-card:hover { transform: translateY(-1px); box-shadow: 0 5px 16px rgba(16, 24, 40, .10); }
.qlmx-job-title { font-size: 14px; line-height: 1.3; color: #101828; overflow-wrap: anywhere; }
.qlmx-job-meta { font-size: 11px; line-height: 1.4; color: #667085; overflow-wrap: anywhere; }
.qlmx-job-excerpt {
  font-size: 12px;
  line-height: 1.45;
  color: #475467;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.qlmx-job-cta { margin-top: 2px; font-size: 12px; font-weight: 750; color: var(--qlmx-accent); }

/* Tablet: comfortable floating panel, scaled for portrait/landscape tablets. */
@media (min-width: 768px) and (max-width: 1100px) {
  .qlmx-chat { --qlmx-edge: 16px; --qlmx-panel-width: 430px; --qlmx-panel-height: 700px; }
  .qlmx-panel { height: min(var(--qlmx-panel-height), calc(100dvh - 32px)); }
  .qlmx-header { min-height: 72px; }
  .qlmx-messages { padding: 17px; }
}

/* Mobile: compact bottom-sheet chat window, approximately half the viewport. */
@media (max-width: 767px) {
  .qlmx-chat {
    --qlmx-edge: max(10px, env(safe-area-inset-bottom));
  }
  .qlmx-chat--right .qlmx-launcher {
    right: max(10px, env(safe-area-inset-right)) !important;
    left: auto !important;
  }
  .qlmx-chat--left .qlmx-launcher {
    left: max(10px, env(safe-area-inset-left)) !important;
    right: auto !important;
  }
  .qlmx-launcher { bottom: max(10px, env(safe-area-inset-bottom)) !important; }

  .qlmx-launcher {
    width: 60px;
    height: 60px;
    min-height: 60px;
    max-width: 60px;
    padding: 8px;
    border-radius: 50%;
    gap: 0;
    box-shadow: 0 10px 28px rgba(16, 24, 40, .24);
  }
  .qlmx-launcher-label { display: none; }
  .qlmx-launcher-logo-wrap {
    width: 44px;
    height: 38px;
    flex-basis: 44px;
    padding: 4px;
    border-radius: 8px;
  }
  .qlmx-launcher-icon { width: 42px; height: 42px; flex-basis: 42px; }

  .qlmx-panel {
    position: fixed !important;
    top: auto !important;
    bottom: max(10px, env(safe-area-inset-bottom)) !important;
    left: max(10px, env(safe-area-inset-left)) !important;
    right: max(10px, env(safe-area-inset-right)) !important;
    width: auto !important;
    max-width: none !important;
    height: clamp(340px, 56dvh, 520px);
    max-height: calc(var(--qlmx-visual-height, 100dvh) - max(20px, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
    min-height: 0;
    border-radius: 18px;
  }

  .qlmx-header {
    min-height: 62px;
    gap: 7px;
    padding: 8px 10px;
  }
  .qlmx-header-logo-wrap {
    width: 54px;
    height: 38px;
    flex-basis: 54px;
    padding: 4px 5px;
    border-radius: 9px;
  }
  .qlmx-header-copy strong { font-size: 14px; }
  .qlmx-close, .qlmx-clear { width: 33px; height: 33px; flex-basis: 33px; }
  .qlmx-close { font-size: 24px; }

  .qlmx-messages {
    padding: 12px 11px 10px;
    scrollbar-gutter: auto;
  }
  .qlmx-message {
    max-width: 90%;
    margin-bottom: 9px;
    padding: 9px 10px;
    border-radius: 13px;
    font-size: 14px;
    line-height: 1.45;
  }

  .qlmx-typing { margin: 6px 11px 0; }

  .qlmx-form {
    min-height: 62px;
    gap: 8px;
    padding: 8px 9px max(8px, env(safe-area-inset-bottom));
  }
  .qlmx-form textarea {
    min-height: 44px;
    max-height: 90px;
    padding: 10px 11px;
    border-radius: 12px;
  }
  .qlmx-send { width: 44px; height: 44px; flex-basis: 44px; border-radius: 12px; }
  .qlmx-footer { min-height: 20px; padding: 2px 8px; }

  .qlmx-job-results { width: 100%; margin-bottom: 10px; }
  .qlmx-job-card { padding: 10px 11px; }
  .qlmx-job-title { font-size: 14px; }
  .qlmx-job-meta, .qlmx-job-cta { font-size: 12px; }
  .qlmx-job-excerpt { font-size: 12px; }
}

/* Small phones: keep the same compact bottom-sheet model with tighter chrome. */
@media (max-width: 390px) {
  .qlmx-panel {
    left: max(7px, env(safe-area-inset-left)) !important;
    right: max(7px, env(safe-area-inset-right)) !important;
    bottom: max(7px, env(safe-area-inset-bottom)) !important;
    height: clamp(330px, 57dvh, 480px);
    max-height: calc(var(--qlmx-visual-height, 100dvh) - max(14px, env(safe-area-inset-top) + env(safe-area-inset-bottom)));
    border-radius: 15px;
  }
  .qlmx-header { min-height: 58px; padding: 7px 8px; gap: 5px; }
  .qlmx-header-logo-wrap { width: 49px; height: 34px; flex-basis: 49px; padding: 4px; }
  .qlmx-header-copy strong { font-size: 13px; }
  .qlmx-close, .qlmx-clear { width: 30px; height: 30px; flex-basis: 30px; }
  .qlmx-messages { padding: 10px 9px 8px; }
  .qlmx-message { max-width: 92%; font-size: 14px; }
  .qlmx-form { min-height: 58px; padding-left: 7px; padding-right: 7px; gap: 7px; }
  .qlmx-form textarea { min-height: 42px; }
  .qlmx-send { width: 42px; height: 42px; flex-basis: 42px; }
}

/* Very short screens / landscape phones need extra vertical room to remain usable. */
@media (max-width: 767px) and (max-height: 520px) {
  .qlmx-panel {
    height: min(78dvh, calc(var(--qlmx-visual-height, 100dvh) - 12px));
    max-height: calc(var(--qlmx-visual-height, 100dvh) - 12px);
    bottom: 6px !important;
  }
  .qlmx-header { min-height: 54px; padding-top: 6px; padding-bottom: 6px; }
  .qlmx-header-logo-wrap { height: 34px; }
  .qlmx-form { min-height: 56px; padding-top: 6px; padding-bottom: 6px; }
  .qlmx-form textarea { min-height: 40px; max-height: 72px; }
  .qlmx-send { width: 40px; height: 40px; flex-basis: 40px; }
  .qlmx-footer { display: none; }
}

/* Respect reduced-motion preferences. */
@media (prefers-reduced-motion: reduce) {
  .qlmx-chat *, .qlmx-chat *::before, .qlmx-chat *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
