/* SITE-8E — Telemarket Live Chat widget (mobile messenger UX) */
:root {
  --tm-chat-z: 140;
  --tm-chat-fab-size: 56px;
  --tm-chat-gap: 16px;
  --tm-chat-reserved-bottom: var(--bottom-nav-h, 64px);
  --tm-chat-offset-bottom: calc(
    env(safe-area-inset-bottom, 0px) + var(--tm-chat-reserved-bottom) + var(--tm-chat-gap)
  );
  --tm-chat-offset-right: max(12px, env(safe-area-inset-right, 0px));
  --tm-chat-accent: var(--accent, #1a5cff);
  --tm-chat-accent-hover: var(--accent-hover, #1248d4);
  --tm-chat-navy: var(--navy, #0b1f4d);
  --tm-chat-panel-z: 1100; /* above --z-header (1000) for true fullscreen */
}

body.tm-page-home,
body.tm-store-v0 {
  --tm-chat-reserved-bottom: 88px;
  --tm-chat-offset-right: 18px;
  --tm-chat-gap: 10px;
  --tm-chat-accent: #f4512a;
  --tm-chat-accent-hover: #d9431f;
}

.tm-chat-fab {
  position: fixed;
  right: var(--tm-chat-offset-right);
  bottom: var(--tm-chat-offset-bottom);
  z-index: var(--tm-chat-z);
  min-width: 56px;
  min-height: 56px;
  height: auto;
  padding: 0 14px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: var(--tm-chat-accent);
  color: #fff;
  box-shadow:
    0 10px 28px rgba(26, 92, 255, 0.38),
    0 2px 8px rgba(11, 31, 77, 0.16);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform .18s ease, box-shadow .18s ease, bottom .18s ease, background .18s ease;
}
body.tm-chat-open .tm-chat-fab { display: none !important; }
.tm-chat-fab:hover {
  transform: translateY(-2px);
  background: var(--tm-chat-accent-hover);
  box-shadow:
    0 14px 32px rgba(26, 92, 255, 0.42),
    0 4px 12px rgba(11, 31, 77, 0.18);
}
.tm-chat-fab:focus-visible {
  outline: 3px solid #fff;
  outline-offset: 3px;
  box-shadow: 0 0 0 6px rgba(26, 92, 255, 0.35);
}
.tm-chat-fab__icon {
  width: 24px;
  height: 24px;
  display: block;
  flex-shrink: 0;
  filter: brightness(0) invert(1);
}
.tm-chat-fab__label {
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
  line-height: 1;
}
.tm-chat-fab__badge {
  position: absolute;
  top: -4px;
  right: -2px;
  min-width: 20px;
  height: 20px;
  padding: 0 5px;
  border-radius: 999px;
  background: #e11d48;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
  border: 2px solid #fff;
}
@media (max-width: 767px) {
  .tm-chat-fab {
    min-width: 52px;
    min-height: 52px;
    padding: 0 12px;
    border-radius: 18px;
    gap: 8px;
  }
  .tm-chat-fab__label {
    display: inline;
    font-size: 0.85rem;
  }
}
@media (max-width: 380px) {
  .tm-chat-fab {
    width: var(--tm-chat-fab-size);
    height: var(--tm-chat-fab-size);
    padding: 0;
  }
  .tm-chat-fab__label { display: none; }
}

.tm-chat-header-trigger {
  display: none;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  min-width: 48px;
  padding: 8px 14px;
  margin: 0 0 12px;
  border: 1px solid rgba(26, 92, 255, 0.25);
  border-radius: 12px;
  background: var(--tm-chat-accent);
  color: #fff;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.tm-chat-header-trigger img {
  width: 20px;
  height: 20px;
  filter: brightness(0) invert(1);
}
body.tm-page-checkout .tm-chat-fab { display: none !important; }
body.tm-page-checkout.tm-chat-fab-compact .tm-chat-fab { display: none !important; }
body.tm-page-checkout.tm-chat-fab-compact .tm-chat-header-trigger { display: inline-flex; }
body.tm-page-checkout.tm-chat-fab-compact.tm-chat-open .tm-chat-header-trigger { visibility: hidden; }

.tm-chat-panel {
  position: fixed;
  z-index: var(--tm-chat-panel-z);
  display: flex;
  flex-direction: column;
  background: #eef2f7;
  border: 1px solid rgba(11, 31, 77, 0.14);
  box-shadow: 0 22px 56px rgba(11, 31, 77, 0.28);
  overflow: hidden;
  overflow-x: hidden;
  max-width: 100vw;
}
.tm-chat-panel[hidden] { display: none !important; }

@media (min-width: 768px) {
  .tm-chat-panel {
    right: var(--tm-chat-offset-right);
    bottom: calc(var(--tm-chat-offset-bottom) + var(--tm-chat-fab-size) + 12px);
    width: min(440px, calc(100vw - 24px));
    height: min(680px, calc(100dvh - 120px));
    max-height: min(680px, calc(100dvh - 120px));
    border-radius: 20px;
  }
}

/* SITE-8E — full-screen messenger on mobile */
@media (max-width: 767px) {
  .tm-chat-panel {
    left: 0;
    right: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    max-width: none;
    height: 100vh;
    max-height: none;
    border-radius: 0;
    border: 0;
    padding-top: env(safe-area-inset-top, 0px);
    padding-bottom: 0;
    background: #eef2f7;
    box-shadow: none;
  }
  body.tm-chat-open {
    overflow: hidden;
    overflow-x: hidden;
  }
  body.tm-chat-open .tm-bottom-nav,
  body.tm-chat-open .tm-sticky-buy {
    visibility: hidden !important;
    pointer-events: none !important;
  }
}

@supports (height: 100dvh) {
  @media (max-width: 767px) {
    .tm-chat-panel {
      height: 100dvh;
      max-height: 100dvh;
    }
  }
}

.tm-chat-panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  background: #fff;
  border-bottom: 1px solid rgba(11, 31, 77, 0.1);
  flex-shrink: 0;
}
.tm-chat-panel__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.tm-chat-panel__status {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #16a34a;
  box-shadow: 0 0 0 3px rgba(22, 163, 74, 0.2);
  flex-shrink: 0;
}
.tm-chat-panel__title {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
  color: var(--tm-chat-navy);
  line-height: 1.2;
}
.tm-chat-panel__sub {
  margin: 2px 0 0;
  font-size: 0.8rem;
  color: #5b6b86;
  line-height: 1.3;
}
.tm-chat-panel__hint {
  margin: 2px 0 0;
  font-size: 0.72rem;
  color: #7a879c;
  line-height: 1.3;
}
.tm-chat-panel__actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.tm-chat-panel__close,
.tm-chat-panel__minimize {
  border: 0;
  background: transparent;
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  color: var(--tm-chat-navy);
  min-width: 44px;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
}
.tm-chat-panel__close:hover,
.tm-chat-panel__minimize:hover {
  background: rgba(11, 31, 77, 0.06);
}
.tm-chat-panel__close:focus-visible,
.tm-chat-panel__minimize:focus-visible {
  outline: 2px solid var(--tm-chat-accent);
  outline-offset: 2px;
}

.tm-chat-panel__main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.tm-chat-panel__body {
  position: relative;
  flex: 1 1 auto;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  background: #e8eef6;
  min-height: 0;
}
.tm-chat-loading {
  margin: 24px auto;
  max-width: 260px;
  text-align: center;
  color: #5b6b86;
  font-size: 0.9rem;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(11, 31, 77, 0.08);
  border-radius: 12px;
  padding: 14px 12px;
}
.tm-chat-welcome {
  display: grid;
  gap: 6px;
  margin: 0 0 12px;
  max-width: 92%;
}
/* SITE-8E.1: author display must not defeat [hidden] (Safari/iOS). */
.tm-chat-welcome[hidden],
.tm-chat-thread[hidden],
.tm-chat-fallback[hidden],
.tm-chat-closed[hidden],
.tm-chat-loading[hidden],
.tm-chat-quick[hidden],
.tm-chat-panel__footer[hidden] {
  display: none !important;
}
.tm-chat-welcome__bubble {
  margin: 0;
  padding: 10px 12px;
  border-radius: 14px;
  border-bottom-left-radius: 6px;
  background: #fff;
  color: var(--tm-chat-navy);
  box-shadow: 0 1px 2px rgba(11, 31, 77, 0.08);
  border: 1px solid rgba(11, 31, 77, 0.06);
  font-size: 0.95rem;
  line-height: 1.4;
}
.tm-chat-welcome__secondary {
  margin: 0;
  padding: 0 4px;
  color: #5b6b86;
  font-size: 0.82rem;
  line-height: 1.35;
}

.tm-chat-quick {
  flex-shrink: 0;
  padding: 8px 10px;
  background: #f8fafc;
  border-top: 1px solid rgba(11, 31, 77, 0.08);
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.tm-chat-topics {
  display: flex;
  flex-wrap: nowrap;
  gap: 8px;
  width: max-content;
  max-width: none;
}
@media (min-width: 768px) {
  .tm-chat-topics {
    flex-wrap: wrap;
    width: auto;
  }
}
.tm-chat-topic {
  border: 1px solid rgba(11, 31, 77, 0.12);
  background: #fff;
  border-radius: 999px;
  padding: 8px 12px;
  font-size: 0.8rem;
  cursor: pointer;
  min-height: 40px;
  white-space: nowrap;
  flex-shrink: 0;
}
.tm-chat-topic:focus-visible { outline: 2px solid var(--tm-chat-accent); }

.tm-chat-thread {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-height: 0;
}
.tm-chat-msg {
  max-width: 88%;
  margin: 0 0 10px;
  padding: 10px 12px;
  border-radius: 14px;
  background: #fff;
  color: #13233f;
  box-shadow: 0 1px 2px rgba(11, 31, 77, 0.08);
  word-break: break-word;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
  border: 1px solid rgba(11, 31, 77, 0.06);
}
.tm-chat-msg--visitor {
  margin-left: auto;
  background: #dbeafe;
  border-color: rgba(26, 92, 255, 0.18);
  border-bottom-right-radius: 6px;
}
.tm-chat-msg--manager {
  margin-right: auto;
  border-bottom-left-radius: 6px;
}
.tm-chat-msg--system {
  margin: 0 auto 10px;
  background: transparent;
  box-shadow: none;
  border: 0;
  color: #5b6b86;
  font-size: 0.8rem;
  text-align: center;
}
.tm-chat-msg a {
  color: var(--tm-chat-accent);
  text-decoration: underline;
  word-break: break-word;
}
.tm-chat-msg__text {
  display: block;
  white-space: pre-wrap;
}
.tm-chat-msg__meta {
  display: block;
  margin-top: 6px;
  font-size: 0.72rem;
  color: #6b7c95;
  white-space: normal;
}
.tm-chat-msg--failed { border: 1px solid #e11d48; }

.tm-chat-panel__footer {
  flex-shrink: 0;
  padding: 10px 12px;
  background: #fff;
  border-top: 2px solid rgba(26, 92, 255, 0.12);
  box-shadow: 0 -8px 24px rgba(11, 31, 77, 0.06);
}
@media (max-width: 767px) {
  .tm-chat-panel__footer {
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0px), var(--tm-chat-keyboard-inset, 0px));
    position: sticky;
    bottom: 0;
    z-index: 2;
  }
  .tm-chat-panel__main {
    flex: 1 1 auto;
    min-height: 0;
  }
  .tm-chat-panel__body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
}
.tm-chat-privacy {
  font-size: 0.72rem;
  color: #5b6b86;
  margin: 0 0 8px;
  line-height: 1.35;
}
.tm-chat-privacy a { color: var(--tm-chat-accent); }
.tm-chat-compose {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: end;
}
.tm-chat-compose textarea {
  width: 100%;
  min-height: 48px;
  max-height: 120px;
  resize: none;
  border-radius: 12px;
  border: 1px solid rgba(11, 31, 77, 0.18);
  padding: 12px;
  font: inherit;
  font-size: 16px; /* avoid iOS zoom */
  background: #f8fafc;
  color: var(--tm-chat-navy);
  box-sizing: border-box;
}
.tm-chat-compose textarea:focus {
  outline: 2px solid rgba(26, 92, 255, 0.35);
  border-color: var(--tm-chat-accent);
  background: #fff;
}
.tm-chat-compose button,
#tm-chat-send {
  min-width: 96px;
  min-height: 48px;
  border-radius: 12px;
  border: 0;
  background: var(--tm-chat-accent);
  color: #fff;
  font-weight: 700;
  cursor: pointer;
  padding: 0 14px;
}
.tm-chat-compose button:hover,
#tm-chat-send:hover { background: var(--tm-chat-accent-hover); }
.tm-chat-compose button:disabled,
#tm-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

/* Contact — collapsed below primary composer */
.tm-chat-contact {
  margin-top: 8px;
  border-top: 1px solid rgba(11, 31, 77, 0.08);
  padding-top: 8px;
}
.tm-chat-contact__toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid rgba(11, 31, 77, 0.12);
  border-radius: 10px;
  background: #f8fafc;
  color: var(--tm-chat-navy);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
.tm-chat-contact__toggle[aria-expanded="true"] {
  border-color: rgba(26, 92, 255, 0.35);
  background: #eff6ff;
}
.tm-chat-contact__fields {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}
.tm-chat-contact__fields[hidden] {
  display: none !important;
}
.tm-chat-contact input[type="text"],
.tm-chat-contact input:not([type]) {
  border: 1px solid rgba(11, 31, 77, 0.15);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-size: 16px;
  min-height: 44px;
  width: 100%;
  box-sizing: border-box;
}
.tm-chat-contact__consent {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  font-size: 0.78rem;
  color: #5b6b86;
  line-height: 1.35;
}
.tm-chat-contact__consent input {
  margin-top: 3px;
  min-width: 18px;
  min-height: 18px;
}
.tm-chat-contact-saved {
  margin: 0;
  font-size: 0.8rem;
  color: #0d8a4f;
  padding: 6px 2px;
}

.tm-chat-closed {
  text-align: center;
  padding: 16px;
  color: #5b6b86;
  background: #fff;
  border-radius: 12px;
}
.tm-chat-cta {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
#tm-chat-status-hint {
  min-height: 1.1em;
  color: #5b6b86;
  margin: 0.4rem 0 0;
  font-size: 0.75rem;
}
.tm-chat-status-hint--error { color: #b91c1c !important; }
.tm-chat-status-hint--ok { color: #0d8a4f !important; }

@media (display-mode: standalone) {
  :root { --tm-chat-gap: 16px; }
}

.tm-chat-fallback { display: grid; gap: 12px; }
.tm-chat-fallback__links { display: flex; flex-wrap: wrap; gap: 8px; }
.tm-chat-fallback__links .tm-btn { min-height: 44px; }
