/* ═══════════════════════════════════════════════
   CHAT WIDGET STYLES
   ═══════════════════════════════════════════════ */

.jv-widget {
  position: fixed;
  z-index: 9999;
  font-family: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

.jv-widget * {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.jv-widget--right {
  bottom: 32px;
  right: 32px;
}

.jv-widget--left {
  bottom: 32px;
  left: 32px;
}

/* Launcher Button */
.jv-launcher {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: #E30613;
  box-shadow: 0 4px 20px rgba(227, 6, 19, 0.4);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  border: none;
  outline: none;
  position: relative;
}

.jv-launcher:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(227, 6, 19, 0.5);
}

.jv-launcher svg {
  width: 28px;
  height: 28px;
  fill: white;
  transition: transform 0.3s ease;
}

.jv-launcher--open svg {
  transform: rotate(90deg);
}

.jv-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  background: #22c55e;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #fff;
  display: none;
}

.jv-badge--show {
  display: block;
}

/* Chat Window */
.jv-window {
  position: absolute;
  bottom: 80px;
  right: 0;
  width: 380px;
  max-width: calc(100vw - 64px);
  height: 560px;
  max-height: calc(100vh - 120px);
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  opacity: 0;
  visibility: hidden;
  transform: translateY(20px) scale(0.95);
  transition: all 0.3s ease;
  overflow: hidden;
}

.jv-widget--left .jv-window {
  right: auto;
  left: 0;
}

.jv-window--open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

/* Header */
.jv-header {
  background: #2b2b2f;
  padding: 20px;
  color: #fff;
}

.jv-header-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.jv-header-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}

.jv-header-subtitle {
  font-size: 13px;
  opacity: 0.7;
  display: flex;
  align-items: center;
  gap: 6px;
}

.jv-online-dot {
  width: 8px;
  height: 8px;
  background: #22c55e;
  border-radius: 50%;
  animation: jv-pulse 2s infinite;
}

.jv-offline-dot {
  width: 8px;
  height: 8px;
  background: #ef4444;
  border-radius: 50%;
}

.jv-typing-indicator {
  display: none;
  align-items: center;
  gap: 4px;
}

.jv-typing-indicator span {
  width: 6px;
  height: 6px;
  background: #22c55e;
  border-radius: 50%;
  animation: jv-typing 1.4s infinite;
}

.jv-typing-indicator span:nth-child(2) {
  animation-delay: 0.2s;
}

.jv-typing-indicator span:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes jv-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

@keyframes jv-typing {
  0%, 60%, 100% { transform: translateY(0); }
  30% { transform: translateY(-4px); }
}

/* Body */
.jv-body {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  background: #fafaf8;
}

.jv-messages {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: 8px;
}

.jv-message {
  padding: 10px 14px;
  border-radius: 12px;
  max-width: 85%;
  font-size: 14px;
  animation: jv-msg-in 0.3s ease;
}

@keyframes jv-msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.jv-message--bot {
  background: #fff;
  color: #2F2F2F;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

.jv-message--user {
  background: #E30613;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 4px;
}

/* Ответ оператора (polling / Telegram) */
.jv-message--operator {
  background: #fff;
  color: #2F2F2F;
  align-self: flex-start;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  border-left: 3px solid #E30613;
}

.jv-message--system {
  background: #f4f4f2;
  color: #9A9A95;
  align-self: center;
  font-size: 12px;
  text-align: center;
  box-shadow: none;
}

.jv-message-time {
  font-size: 10px;
  opacity: 0.6;
  margin-top: 4px;
}

.jv-file-attachment {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(255,255,255,0.15);
  padding: 8px 12px;
  border-radius: 8px;
  margin-top: 8px;
}

.jv-file-attachment svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.jv-file-name {
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 150px;
}

/* Input Area */
.jv-input-area {
  background: #fff;
  border-top: 1px solid #eee;
  padding: 12px;
}

.jv-chat-input {
  display: flex;
  align-items: center;
  gap: 8px;
}

.jv-chat-input .jv-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid #e8e8e4;
  border-radius: 20px;
  font-size: 14px;
  font-family: inherit;
  outline: none;
  background: #f8f8f8;
  transition: border-color 0.2s ease;
}

.jv-chat-input .jv-input:focus {
  border-color: #E30613;
  background: #fff;
}

.jv-send-btn {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--jv-primary, #E30613);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
}

.jv-send-btn:hover {
  background: #bd0913;
  transform: scale(1.05);
}

.jv-send-btn:active {
  transform: scale(0.95);
}

.jv-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.jv-form-title {
  font-size: 13px;
  font-weight: 600;
  color: #2F2F2F;
  text-align: center;
}

.jv-input-group {
  position: relative;
}

.jv-input {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid #e8e8e4;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s ease;
  outline: none;
  background: #fff;
}

.jv-input:focus {
  border-color: #E30613;
}

.jv-input::placeholder {
  color: #9A9A95;
}

.jv-textarea {
  min-height: 70px;
  resize: vertical;
}

/* File Upload */
.jv-file-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.jv-file-input {
  display: none;
}

.jv-file-btn {
  width: 40px;
  height: 40px;
  border: 1.5px dashed #ccc;
  border-radius: 8px;
  background: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s ease;
  flex-shrink: 0;
}

.jv-file-btn:hover {
  border-color: #E30613;
  background: rgba(227, 6, 19, 0.05);
}

.jv-file-btn svg {
  width: 20px;
  height: 20px;
  fill: #9A9A95;
}

.jv-file-preview {
  flex: 1;
  padding: 8px 12px;
  background: #f4f4f2;
  border-radius: 8px;
  font-size: 12px;
  color: #5A5A56;
  display: none;
  align-items: center;
  gap: 8px;
}

.jv-file-preview--show {
  display: flex;
}

.jv-file-remove {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  display: flex;
}

.jv-file-remove svg {
  width: 14px;
  height: 14px;
  fill: #ef4444;
}

.jv-submit {
  width: 100%;
  padding: 14px;
  background: #E30613;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s ease;
}

.jv-submit:hover {
  background: #B8040F;
}

.jv-submit:disabled {
  background: #ccc;
  cursor: not-allowed;
}

/* Success */
.jv-success {
  text-align: center;
  padding: 30px 20px;
}

.jv-success-icon {
  width: 60px;
  height: 60px;
  background: #22c55e;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 16px;
}

.jv-success-icon svg {
  width: 32px;
  height: 32px;
  fill: #fff;
}

.jv-success-title {
  font-size: 18px;
  font-weight: 600;
  color: #2F2F2F;
  margin-bottom: 8px;
}

.jv-success-text {
  font-size: 14px;
  color: #5A5A56;
}

/*
 * Телефоны и планшеты (max-width:1024).
 * #jvWidget — запасная специфичность; простые px — чтобы старые WebKit не отбрасывали весь блок из-за max()/env().
 */
@media (max-width: 1024px) {
  #jvWidget.jv-widget,
  .jv-widget {
    z-index: 999999 !important;
  }

  #jvWidget.jv-widget--right,
  .jv-widget--right {
    bottom: 16px !important;
    right: 16px !important;
    left: auto !important;
    top: auto !important;
    width: 56px !important;
    height: 56px !important;
    max-width: none !important;
    overflow: visible !important;
  }

  #jvWidget.jv-widget--left,
  .jv-widget--left {
    bottom: 16px !important;
    left: 16px !important;
    right: auto !important;
    top: auto !important;
    width: 56px !important;
    height: 56px !important;
    max-width: none !important;
    overflow: visible !important;
  }

  #jvWidget .jv-launcher,
  .jv-launcher {
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    right: auto !important;
    bottom: auto !important;
    width: 56px !important;
    height: 56px !important;
    min-width: 56px !important;
    min-height: 56px !important;
    z-index: 2 !important;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    opacity: 1 !important;
    visibility: visible !important;
  }

  .jv-launcher svg {
    width: 24px;
    height: 24px;
  }

  .jv-window.jv-window--open ~ .jv-launcher {
    position: fixed !important;
    left: auto !important;
    top: 12px !important;
    right: 12px !important;
    bottom: auto !important;
    z-index: 1000000 !important;
  }

  #jvWidget .jv-window,
  .jv-window {
    position: fixed !important;
    left: 0 !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: 100% !important;
    height: 100% !important;
    max-width: 100% !important;
    max-height: 100% !important;
    min-height: 100vh !important;
    border-radius: 0 !important;
    display: none !important;
    z-index: 999999 !important;
    margin: 0 !important;
  }

  .jv-window.jv-window--open {
    display: flex !important;
    flex-direction: column !important;
  }

  .jv-header {
    padding-top: 20px;
    padding-left: 16px;
    padding-right: 16px;
    flex-shrink: 0;
  }

  .jv-body {
    flex: 1;
    min-height: 0;
    -webkit-overflow-scrolling: touch;
  }

  .jv-input-area {
    padding-bottom: 16px;
    padding-left: 12px;
    padding-right: 12px;
    flex-shrink: 0;
  }

  .jv-send-btn {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
  }

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

@supports (padding: max(0px, 1px)) {
  @media (max-width: 1024px) {
    #jvWidget.jv-widget--right,
    .jv-widget--right {
      bottom: max(16px, env(safe-area-inset-bottom, 0px)) !important;
      right: max(16px, env(safe-area-inset-right, 0px)) !important;
    }
    #jvWidget.jv-widget--left,
    .jv-widget--left {
      bottom: max(16px, env(safe-area-inset-bottom, 0px)) !important;
      left: max(16px, env(safe-area-inset-left, 0px)) !important;
    }
    .jv-window.jv-window--open ~ .jv-launcher {
      top: max(12px, env(safe-area-inset-top, 0px)) !important;
      right: max(12px, env(safe-area-inset-right, 0px)) !important;
    }
    .jv-header {
      padding-top: max(20px, env(safe-area-inset-top, 0px));
      padding-left: max(16px, env(safe-area-inset-left, 0px));
      padding-right: max(16px, env(safe-area-inset-right, 0px));
    }
    .jv-input-area {
      padding-bottom: max(16px, env(safe-area-inset-bottom, 0px));
    }
  }
}
