/* ═══ TEAM ZHEN AI SUPPORT WIDGET ═══════════════════════════════════════ */

#tz-chat {
  --tz-gold: #C9A84C;
  --tz-gold-light: #E8C96D;
  --tz-gold-deep: #A8872F;
  --tz-ink: #080808;
  --tz-panel: #0d0d0d;
  --tz-panel-2: #111111;
  --tz-panel-3: #161616;
  --tz-line: rgba(201, 168, 76, 0.24);
  --tz-line-strong: rgba(201, 168, 76, 0.5);
  --tz-text: #F2EEE4;
  --tz-muted: #8C8679;
  --tz-muted-2: #6B665D;
  --tz-green: #7FBF8A;
  position: relative;
  z-index: 9995;
  font-family: 'Space Mono', ui-monospace, monospace;
  color: var(--tz-text);
}

#tz-chat,
#tz-chat *,
#tz-chat *::before,
#tz-chat *::after {
  box-sizing: border-box;
}

body.is-loading #tz-chat {
  display: none;
}

/* ── Floating launcher ─────────────────────────────────────────────────── */

.tz-chat-toggle {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 9995;
  width: 62px;
  height: 62px;
  padding: 0;
  border: 1px solid var(--tz-line-strong);
  border-radius: 50%;
  background:
    radial-gradient(circle at 32% 22%, rgba(201, 168, 76, 0.2), transparent 58%),
    linear-gradient(145deg, #151515 0%, #080808 58%, #050505 100%);
  color: var(--tz-gold-light);
  cursor: pointer;
  display: grid;
  place-items: center;
  box-shadow:
    0 0 0 1px rgba(8, 8, 8, 0.9),
    0 12px 32px rgba(0, 0, 0, 0.55),
    0 0 30px rgba(201, 168, 76, 0.2);
  transition: transform 0.28s ease, box-shadow 0.28s ease, border-color 0.28s ease;
  -webkit-tap-highlight-color: transparent;
}

.tz-chat-toggle::after {
  content: '';
  position: absolute;
  inset: -6px;
  border: 1px solid rgba(201, 168, 76, 0.16);
  border-radius: 50%;
  animation: tzChatRing 3.2s ease-in-out infinite;
  pointer-events: none;
}

.tz-chat-toggle:hover {
  transform: translateY(-3px);
  border-color: var(--tz-gold-light);
  box-shadow:
    0 0 0 1px rgba(8, 8, 8, 0.9),
    0 16px 38px rgba(0, 0, 0, 0.62),
    0 0 42px rgba(201, 168, 76, 0.34);
}

.tz-chat-toggle:focus-visible,
.tz-chat-panel button:focus-visible,
.tz-chat-panel textarea:focus-visible,
.tz-chat-panel a:focus-visible {
  outline: 2px solid var(--tz-gold-light);
  outline-offset: 3px;
}

.tz-chat-toggle svg {
  width: 26px;
  height: 26px;
  display: block;
}

.tz-chat-toggle-dot {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--tz-gold-light);
  border: 2px solid #080808;
  box-shadow: 0 0 10px rgba(232, 201, 109, 0.8);
}

.tz-chat-toggle-dot::after {
  content: '';
  position: absolute;
  inset: -3px;
  border-radius: 50%;
  border: 1px solid rgba(232, 201, 109, 0.5);
  animation: tzChatDot 2.4s ease-out infinite;
}

@keyframes tzChatRing {
  0%, 100% { opacity: 0.45; transform: scale(1); }
  50%      { opacity: 0.9;  transform: scale(1.06); }
}

@keyframes tzChatDot {
  0%   { opacity: 0.8; transform: scale(0.7); }
  70%  { opacity: 0;   transform: scale(1.8); }
  100% { opacity: 0;   transform: scale(1.8); }
}

/* ── Panel shell ───────────────────────────────────────────────────────── */

.tz-chat-panel {
  position: fixed;
  right: 24px;
  bottom: 100px;
  z-index: 9996;
  width: min(398px, calc(100vw - 32px));
  height: min(620px, calc(100vh - 132px));
  min-height: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(circle at 100% 0%, rgba(201, 168, 76, 0.09), transparent 38%),
    linear-gradient(180deg, #101010 0%, #0a0a0a 54%, #080808 100%);
  border: 1px solid var(--tz-line);
  border-radius: 4px;
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.7),
    0 36px 90px rgba(0, 0, 0, 0.7),
    0 0 60px rgba(201, 168, 76, 0.08);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateY(16px) scale(0.985);
  transform-origin: bottom right;
  transition:
    opacity 0.28s ease,
    transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1),
    visibility 0.32s;
}

.tz-chat-panel.is-open {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: translateY(0) scale(1);
}

.tz-chat-panel::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--tz-gold) 22%, var(--tz-gold-light) 50%, var(--tz-gold) 78%, transparent);
  z-index: 2;
}

/* ── Header ────────────────────────────────────────────────────────────── */

.tz-chat-header {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 16px 14px 18px;
  background: rgba(8, 8, 8, 0.42);
  border-bottom: 1px solid rgba(201, 168, 76, 0.14);
}

.tz-chat-mark {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--tz-line-strong);
  background: linear-gradient(145deg, #171717, #090909);
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: 1px;
  color: var(--tz-gold-light);
  box-shadow: inset 0 0 18px rgba(201, 168, 76, 0.08);
}

.tz-chat-heading {
  min-width: 0;
  flex: 1 1 auto;
}

.tz-chat-title {
  margin: 0;
  font-family: 'Bebas Neue', 'Arial Narrow', sans-serif;
  font-size: 20px;
  font-weight: 400;
  letter-spacing: 2.4px;
  line-height: 1;
  color: var(--tz-text);
}

.tz-chat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin: 6px 0 0;
  font-size: 8px;
  letter-spacing: 1.8px;
  text-transform: uppercase;
  color: var(--tz-muted);
}

.tz-chat-status-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--tz-green);
  box-shadow: 0 0 7px rgba(127, 191, 138, 0.8);
}

.tz-chat-head-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 4px;
}

.tz-chat-icon-btn {
  width: 34px;
  height: 34px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
  color: var(--tz-muted);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.tz-chat-icon-btn:hover {
  color: var(--tz-gold-light);
  border-color: rgba(201, 168, 76, 0.2);
  background: rgba(201, 168, 76, 0.06);
}

.tz-chat-icon-btn svg {
  width: 16px;
  height: 16px;
  display: block;
}

.tz-chat-close {
  display: grid;
}

/* ── Messages ──────────────────────────────────────────────────────────── */

.tz-chat-messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 22px 18px 12px;
  scroll-behavior: smooth;
  scrollbar-width: thin;
  scrollbar-color: rgba(201, 168, 76, 0.3) transparent;
}

.tz-chat-messages::-webkit-scrollbar {
  width: 5px;
}

.tz-chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.tz-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(201, 168, 76, 0.28);
  border-radius: 8px;
}

.tz-chat-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0 0 14px;
  animation: tzChatMessageIn 0.3s ease both;
}

.tz-chat-row--user {
  justify-content: flex-end;
}

.tz-chat-avatar {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(201, 168, 76, 0.3);
  background: #0b0b0b;
  font-family: 'Cormorant Garamond', Georgia, serif;
  font-size: 10px;
  font-weight: 700;
  color: var(--tz-gold);
}

.tz-chat-bubble {
  max-width: 84%;
  padding: 11px 14px;
  border: 1px solid rgba(201, 168, 76, 0.16);
  border-radius: 3px;
  background: linear-gradient(160deg, rgba(24, 24, 24, 0.96), rgba(15, 15, 15, 0.96));
  color: #E7E2D7;
  font-family: 'Space Mono', ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.68;
  letter-spacing: 0.1px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: 0 8px 22px rgba(0, 0, 0, 0.24);
}

.tz-chat-row--user .tz-chat-bubble {
  border-color: rgba(232, 201, 109, 0.55);
  background: linear-gradient(135deg, #E8C96D 0%, #C9A84C 58%, #B3923D 100%);
  color: #0A0A0A;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(201, 168, 76, 0.16);
}

.tz-chat-bubble--error {
  border-color: rgba(194, 104, 88, 0.4);
  background: rgba(45, 22, 18, 0.65);
  color: #E5BCB2;
}

.tz-chat-bubble a {
  color: var(--tz-gold-light);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.tz-chat-meta {
  margin: 6px 2px 0;
  font-size: 8px;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--tz-muted-2);
}

.tz-chat-row--user .tz-chat-meta {
  text-align: right;
}

/* Typing indicator */

.tz-chat-typing {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 14px 16px;
  border: 1px solid rgba(201, 168, 76, 0.16);
  border-radius: 3px;
  background: rgba(20, 20, 20, 0.96);
}

.tz-chat-typing span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--tz-gold);
  animation: tzChatTyping 1.2s ease-in-out infinite;
}

.tz-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.tz-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

/* ── Suggested questions ───────────────────────────────────────────────── */

.tz-chat-suggestions {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0 18px 14px;
}

.tz-chat-suggestions[hidden] {
  display: none;
}

.tz-chat-chip {
  padding: 8px 11px;
  border: 1px solid rgba(201, 168, 76, 0.22);
  border-radius: 2px;
  background: rgba(201, 168, 76, 0.035);
  color: #C7C1B3;
  font-family: 'Space Mono', ui-monospace, monospace;
  font-size: 9px;
  line-height: 1.4;
  letter-spacing: 0.2px;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.tz-chat-chip:hover {
  border-color: rgba(232, 201, 109, 0.55);
  background: rgba(201, 168, 76, 0.09);
  color: var(--tz-gold-light);
}

/* ── Composer ──────────────────────────────────────────────────────────── */

.tz-chat-form {
  flex: 0 0 auto;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin: 0 18px;
  padding: 10px 10px 10px 13px;
  border: 1px solid rgba(201, 168, 76, 0.26);
  background: rgba(6, 6, 6, 0.72);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.tz-chat-form:focus-within {
  border-color: rgba(232, 201, 109, 0.58);
  box-shadow: 0 0 0 3px rgba(201, 168, 76, 0.08);
}

.tz-chat-input {
  flex: 1 1 auto;
  min-width: 0;
  max-height: 104px;
  padding: 4px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--tz-text);
  font-family: 'Space Mono', ui-monospace, monospace;
  font-size: 12px;
  line-height: 1.6;
  scrollbar-width: thin;
}

.tz-chat-input::placeholder {
  color: var(--tz-muted);
  opacity: 1;
}

.tz-chat-send {
  flex: 0 0 auto;
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid rgba(232, 201, 109, 0.6);
  border-radius: 50%;
  background: linear-gradient(135deg, #E8C96D, #C9A84C 62%, #A8872F);
  color: #090909;
  cursor: pointer;
  transition: filter 0.2s, opacity 0.2s, transform 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.tz-chat-send:hover:not(:disabled) {
  filter: brightness(1.08);
  transform: translateY(-1px);
}

.tz-chat-send:disabled {
  opacity: 0.36;
  cursor: not-allowed;
}

.tz-chat-send svg {
  width: 15px;
  height: 15px;
  display: block;
}

.tz-chat-footnote {
  flex: 0 0 auto;
  margin: 10px 18px 14px;
  font-size: 8px;
  line-height: 1.6;
  letter-spacing: 0.3px;
  text-align: center;
  color: var(--tz-muted-2);
}

.tz-chat-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@keyframes tzChatMessageIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes tzChatTyping {
  0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
  30%           { opacity: 1;   transform: translateY(-3px); }
}

/* ── Tablet / mobile ───────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .tz-chat-toggle {
    right: 16px;
    bottom: calc(92px + env(safe-area-inset-bottom, 0px));
    width: 56px;
    height: 56px;
  }

  .tz-chat-toggle svg {
    width: 23px;
    height: 23px;
  }

  .tz-chat-panel {
    top: 0;
    right: 0;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100%;
    height: 100dvh;
    min-height: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    transform: translateY(100%);
    transform-origin: bottom center;
  }

  .tz-chat-panel.is-open {
    transform: translateY(0);
  }

  .tz-chat-header {
    padding-top: calc(14px + env(safe-area-inset-top, 0px));
    padding-left: 16px;
    padding-right: 12px;
    padding-bottom: 13px;
  }

  .tz-chat-mark {
    width: 38px;
    height: 38px;
    font-size: 17px;
  }

  .tz-chat-title {
    font-size: 19px;
  }

  .tz-chat-status {
    font-size: 7.5px;
  }

  .tz-chat-close {
    display: grid;
  }

  .tz-chat-head-actions {
    gap: 2px;
  }

  .tz-chat-icon-btn {
    width: 38px;
    height: 38px;
  }

  .tz-chat-messages {
    padding: 18px 16px 10px;
  }

  .tz-chat-bubble {
    max-width: 86%;
    font-size: 12px;
    line-height: 1.66;
  }

  .tz-chat-suggestions {
    padding: 0 16px 12px;
  }

  .tz-chat-form {
    margin: 0 16px;
  }

  .tz-chat-footnote {
    margin: 9px 16px calc(10px + env(safe-area-inset-bottom, 0px));
  }

  .tz-chat-input {
    font-size: 16px;
  }

  body.tz-chat-open {
    overflow: hidden;
  }
}

@media (max-width: 380px) {
  .tz-chat-chip {
    width: 100%;
  }

  .tz-chat-bubble {
    max-width: 88%;
  }
}

@media (prefers-reduced-motion: reduce) {
  #tz-chat *,
  #tz-chat *::before,
  #tz-chat *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}
