/* Telegram Quiz Widget — Стандарт загородной жизни */
.tgq-host,
.tgq-host * { box-sizing: border-box; }

.tgq-host {
  --tgq-bg: #dcecc9;
  --tgq-chat-overlay: rgba(221, 238, 204, 0.78);
  --tgq-option-bg: rgba(255, 255, 255, 0.46);
  --tgq-option-bg-hover: rgba(99, 163, 75, 0.22);
  --tgq-option-border: rgba(72, 143, 61, 0.32);
  --tgq-option-text: #225f2b;
  --tgq-header: #ffffff;
  --tgq-text: #0e1621;
  --tgq-muted: #5a6b7d;  /* было #6b7c8f, не проходило WCAG AA */
  --tgq-border: rgba(15, 35, 55, 0.10);
  --tgq-blue: #0088cc;
  --tgq-blue-dark: #0077b3;
  --tgq-user: #dcf8c6;
  --tgq-manager: #ffffff;
  --tgq-control-bg: rgba(232, 244, 222, 0.82);
  --tgq-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
  --tgq-error: #c62828;
  --tgq-focus: 0 0 0 3px rgba(0, 136, 204, 0.18);
  display: block;
  width: 100%;
  padding: 60px 16px;
  color: var(--tgq-text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  .tgq-host[data-theme="auto"] {
    --tgq-bg: #0e1621;
    --tgq-chat-overlay: rgba(14, 22, 33, 0.18);
    --tgq-option-bg: rgba(255, 255, 255, 0.08);
    --tgq-option-bg-hover: rgba(42, 171, 238, 0.16);
    --tgq-option-border: rgba(255, 255, 255, 0.16);
    --tgq-option-text: #d7eefb;
    --tgq-header: #17212b;
    --tgq-text: #f2f6fa;
    --tgq-muted: #8d9aaa;
    --tgq-border: rgba(255, 255, 255, 0.12);
    --tgq-user: #2b5278;
    --tgq-manager: #182533;
    --tgq-control-bg: rgba(23, 33, 43, 0.92);
    --tgq-shadow: 0 10px 34px rgba(0, 0, 0, 0.35);
    --tgq-error: #ff8a80;
  }
}

.tgq-host[data-theme="dark"] {
  --tgq-bg: #0e1621;
  --tgq-chat-overlay: rgba(14, 22, 33, 0.18);
  --tgq-option-bg: rgba(255, 255, 255, 0.08);
  --tgq-option-bg-hover: rgba(42, 171, 238, 0.16);
  --tgq-option-border: rgba(255, 255, 255, 0.16);
  --tgq-option-text: #d7eefb;
  --tgq-header: #17212b;
  --tgq-text: #f2f6fa;
  --tgq-muted: #8d9aaa;
  --tgq-border: rgba(255, 255, 255, 0.12);
  --tgq-user: #2b5278;
  --tgq-manager: #182533;
  --tgq-control-bg: rgba(23, 33, 43, 0.92);
  --tgq-shadow: 0 10px 34px rgba(0, 0, 0, 0.35);
  --tgq-error: #ff8a80;
}

.tgq {
  width: 100%;
  max-width: 460px;
  height: 640px;
  margin: 0 auto;
  display: grid;
  grid-template-rows: 64px 1fr auto;
  border-radius: 16px;
  overflow: hidden;
  background: var(--tgq-bg);
  box-shadow: var(--tgq-shadow);
  border: 1px solid var(--tgq-border);
}

.tgq-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  padding: 10px 12px;
  background: var(--tgq-header);
  border-bottom: 1px solid var(--tgq-border);
}

.tgq-person {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.tgq-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: #cfd8dc;
  flex: 0 0 auto;
}

.tgq-person-text {
  min-width: 0;
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.tgq-name {
  overflow: hidden;
  color: var(--tgq-text);
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 15px;
  font-weight: 700;
}

.tgq-status {
  margin-top: 3px;
  color: var(--tgq-muted);
  font-size: 12px;
}

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

.tgq-icon-btn {
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--tgq-muted);
  cursor: pointer;
  font: inherit;
  font-size: 19px;
  line-height: 38px;
  text-align: center;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.tgq-icon-btn:hover,
.tgq-icon-btn:focus-visible {
  color: var(--tgq-blue);
  background: rgba(0, 136, 204, 0.10);
  outline: none;
}

.tgq-icon-btn:active { transform: scale(0.94); }

.tgq-body {
  position: relative;
  min-height: 0;
  background-color: var(--tgq-bg);
  background-image: linear-gradient(var(--tgq-chat-overlay), var(--tgq-chat-overlay)), url('./assets/pattern.svg');
  background-size: 260px 260px;
}

.tgq-messages {
  height: 100%;
  overflow: auto;
  overscroll-behavior-y: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 16px 12px calc(18px + env(safe-area-inset-bottom));
  scrollbar-width: thin;
}

.tgq-row {
  display: flex;
  width: 100%;
  margin: 7px 0;
  animation: tgqBubbleIn 300ms ease-out both;
}

.tgq-row.tgq-no-anim { animation: none !important; }

.tgq-row-manager { justify-content: flex-start; }
.tgq-row-user { justify-content: flex-end; }

.tgq-bubble {
  position: relative;
  max-width: min(78%, 340px);
  min-width: 64px;
  padding: 9px 56px 8px 12px;
  border-radius: 14px;
  color: var(--tgq-text);
  font-size: 15px;
  line-height: 1.34;
  box-shadow: 0 1px 1px rgba(0,0,0,.08);
  word-wrap: break-word;
  white-space: pre-wrap;
}

.tgq-bubble-manager { background: var(--tgq-manager); border-bottom-left-radius: 6px; }
.tgq-bubble-user { background: var(--tgq-user); border-bottom-right-radius: 6px; }

.tgq-msg-link {
  color: var(--tgq-blue);
  text-decoration: none;
  border-bottom: 1px solid rgba(0, 136, 204, 0.35);
  word-break: break-all;
  transition: border-color 150ms ease;
}
.tgq-msg-link:hover,
.tgq-msg-link:focus-visible {
  border-bottom-color: var(--tgq-blue);
  outline: none;
}

.tgq-bubble-first.tgq-bubble-manager::before,
.tgq-bubble-first.tgq-bubble-user::before {
  content: '';
  position: absolute;
  bottom: 0;
  width: 12px;
  height: 14px;
}

.tgq-bubble-first.tgq-bubble-manager::before {
  left: -6px;
  background: radial-gradient(circle at 0 0, transparent 0 10px, var(--tgq-manager) 10.5px);
}

.tgq-bubble-first.tgq-bubble-user::before {
  right: -6px;
  background: radial-gradient(circle at 12px 0, transparent 0 10px, var(--tgq-user) 10.5px);
}

.tgq-time {
  position: absolute;
  right: 9px;
  bottom: 5px;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  color: var(--tgq-muted);
  font-size: 11px;
  line-height: 1;
  white-space: nowrap;
}

.tgq-checks {
  color: #2aabee;
  font-size: 11px;
  letter-spacing: -3px;
  padding-left: 2px;
}

.tgq-typing {
  position: absolute;
  left: 12px;
  bottom: 12px;
  width: 54px;
  height: 31px;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 14px 14px 14px 6px;
  background: var(--tgq-manager);
  box-shadow: 0 1px 1px rgba(0,0,0,.08);
}

.tgq-typing:not([hidden]) { display: flex; }
.tgq-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--tgq-muted);
  opacity: 0.3;
  animation: tgqTyping 1.4s infinite;
}
.tgq-typing span:nth-child(2) { animation-delay: .18s; }
.tgq-typing span:nth-child(3) { animation-delay: .36s; }

.tgq-controls {
  min-height: 92px;
  padding: 12px;
  background: var(--tgq-control-bg);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--tgq-border);
}

.tgq-controls[hidden] {
  display: none !important;
  min-height: 0 !important;
  padding: 0 !important;
  border-top: 0 !important;
}

.tgq-controls:empty {
  display: none;
  min-height: 0;
  padding: 0;
  border-top: 0;
}


.tgq-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.tgq-option,
.tgq-submit,
.tgq-chip,
.tgq-final-link {
  min-height: 44px;
  border-radius: 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: transform 150ms ease, background 150ms ease, color 150ms ease, border-color 150ms ease, opacity 250ms ease;
}

.tgq-option {
  padding: 10px 12px;
  border: 1px solid var(--tgq-option-border);
  background: var(--tgq-option-bg);
  color: var(--tgq-option-text);
  cursor: pointer;
  text-align: center;
}

.tgq-option:hover,
.tgq-option:focus-visible {
  background: var(--tgq-option-bg-hover);
  color: var(--tgq-option-text);
  border-color: rgba(72, 143, 61, 0.55);
  outline: none;
  box-shadow: var(--tgq-focus);
}

.tgq-option:active { transform: translateY(1px) scale(.99); }
.tgq-option:disabled { cursor: default; opacity: .6; }
.tgq-option.is-leaving { animation: tgqOptionLeave 250ms ease both; }

.tgq-form {
  display: grid;
  gap: 9px;
}

.tgq-field {
  display: grid;
  gap: 5px;
  color: var(--tgq-muted);
  font-size: 12px;
  font-weight: 600;
}

.tgq-input {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--tgq-border);
  border-radius: 12px;
  background: var(--tgq-bg);
  color: var(--tgq-text);
  font: inherit;
  font-size: 16px;
  outline: none;
}

.tgq-input:focus { border-color: var(--tgq-blue); box-shadow: var(--tgq-focus); }

.tgq-error {
  min-height: 14px;
  color: var(--tgq-error);
  font-size: 11px;
  font-weight: 500;
}

.tgq-chips {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.tgq-chip {
  min-height: 40px;
  padding: 8px 9px;
  border: 1px solid var(--tgq-option-border);
  background: var(--tgq-option-bg);
  color: var(--tgq-text);
  cursor: pointer;
  font-size: 13px;
}

.tgq-chip:hover,
.tgq-chip:focus-visible,
.tgq-chip.is-active {
  border-color: var(--tgq-blue);
  background: var(--tgq-option-bg-hover);
  color: var(--tgq-option-text);
  outline: none;
}

.tgq-consent {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 8px;
  align-items: start;
  color: var(--tgq-muted);
  font-size: 12px;
  line-height: 1.3;
}

.tgq-consent input {
  width: 16px;
  height: 16px;
  margin: 1px 0 0;
  accent-color: var(--tgq-blue);
}

.tgq-consent a { color: var(--tgq-blue); }

.tgq-hp {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  opacity: 0 !important;
  pointer-events: none !important;
}

.tgq-submit,
.tgq-final-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--tgq-blue);
  background: var(--tgq-blue);
  color: #fff;
  cursor: pointer;
}

.tgq-submit:hover:not(:disabled),
.tgq-final-link:hover,
.tgq-submit:focus-visible,
.tgq-final-link:focus-visible {
  background: var(--tgq-blue-dark);
  border-color: var(--tgq-blue-dark);
  outline: none;
  box-shadow: var(--tgq-focus);
}

.tgq-submit:disabled {
  opacity: .55;
  cursor: not-allowed;
}

.tgq-spinner {
  width: 16px;
  height: 16px;
  margin-right: 8px;
  border: 2px solid rgba(255,255,255,.45);
  border-top-color: #fff;
  border-radius: 50%;
  animation: tgqSpin 700ms linear infinite;
}


.tgq-fallback {
  display: grid;
  gap: 8px;
}

.tgq-messenger-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.tgq-messenger-link,
.tgq-copy {
  min-height: 44px;
  border-radius: 12px;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  text-decoration: none;
  transition: transform 150ms ease, background 150ms ease, color 150ms ease, border-color 150ms ease, opacity 250ms ease;
}

.tgq-messenger-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  padding: 11px 12px;
  color: #fff;
  border: 1px solid var(--tgq-blue);
  background: var(--tgq-blue);
}

.tgq-messenger-link:hover,
.tgq-messenger-link:focus-visible {
  outline: none;
  box-shadow: var(--tgq-focus);
  transform: translateY(-1px);
}

.tgq-messenger-telegram { background: #2AABEE; border-color: #2AABEE; }
.tgq-messenger-telegram:hover,
.tgq-messenger-telegram:focus-visible { background: #229ED9; border-color: #229ED9; }
.tgq-messenger-max { background: #1E74FF; border-color: #1E74FF; }
.tgq-messenger-max:hover,
.tgq-messenger-max:focus-visible { background: #105BDB; border-color: #105BDB; }

.tgq-messenger-icon {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  object-fit: contain;
}

.tgq-messenger-icon-text {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(255,255,255,.18);
  color: #fff;
  font-size: 10px;
}

.tgq-copy {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--tgq-border);
  background: transparent;
  color: var(--tgq-text);
  cursor: pointer;
}

.tgq-copy:hover,
.tgq-copy:focus-visible {
  border-color: var(--tgq-blue);
  color: var(--tgq-blue);
  outline: none;
  box-shadow: var(--tgq-focus);
}

.tgq-fallback-text {
  width: 100%;
  min-height: 86px;
  resize: vertical;
  padding: 9px 10px;
  border: 1px solid var(--tgq-border);
  border-radius: 12px;
  background: var(--tgq-bg);
  color: var(--tgq-text);
  font: inherit;
  font-size: 12px;
  line-height: 1.35;
}


/* Мобильный UX: разрешаем естественную прокрутку страницы, когда пользователь
   дошёл до верхней/нижней границы внутреннего чата. */
.tgq-messages { scroll-behavior: smooth; }

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

@keyframes tgqOptionLeave {
  to { opacity: 0; transform: translateY(-8px); }
}

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

@keyframes tgqSpin { to { transform: rotate(360deg); } }

@media (max-width: 767px) {
  .tgq-host { padding: 32px 16px; }
  .tgq { height: 74vh; height: min(74svh, 600px); min-height: 500px; }
  .tgq-messages { overscroll-behavior-y: auto; }
  .tgq-options { grid-template-columns: 1fr; }
  .tgq-option,
  .tgq-submit,
  .tgq-final-link,
  .tgq-messenger-link,
  .tgq-copy { min-height: 48px; }
}

@media (max-width: 479px) {
  .tgq-host { padding: 18px 8px 34px; }
  .tgq {
    height: 72vh;
    height: min(72svh, 610px);
    min-height: 460px;
    border-radius: 12px 12px 0 0;
  }
  .tgq-header { padding-left: max(10px, env(safe-area-inset-left)); padding-right: max(10px, env(safe-area-inset-right)); }
  .tgq-messages { padding-left: 9px; padding-right: 9px; }
  .tgq-bubble { max-width: 86%; font-size: 14px; }
  .tgq-chips,
  .tgq-messenger-list { grid-template-columns: 1fr; }
}

@media (max-width: 340px) {
  .tgq { min-height: 480px; }
  .tgq-name { font-size: 14px; }
  .tgq-bubble { max-width: 89%; padding-right: 51px; }
}

@media (prefers-reduced-motion: reduce) {
  .tgq-row,
  .tgq-option,
  .tgq-chip,
  .tgq-submit,
  .tgq-final-link,
  .tgq-spinner,
  .tgq-messenger-link,
  .tgq-copy,
  .tgq-typing span {
    animation: none !important;
    transition: none !important;
  }
}
