#tgchat-root {
  position: fixed;
  right: 14px;
  bottom: 18px;
  z-index: 99999;
  font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, sans-serif;
  box-sizing: border-box;
}
#tgchat-root *, #tgchat-root *::before, #tgchat-root *::after { box-sizing: border-box; }

#tgchat-launcher {
  width: 58px; height: 58px; border-radius: 50%; border: none; cursor: pointer;
  background: linear-gradient(145deg, #a67c52, #7a5635);
  box-shadow: 0 8px 24px rgba(61,41,20,.28);
  display: flex; align-items: center; justify-content: center;
  transition: transform .15s ease;
  padding: 0;
}
#tgchat-launcher:hover { transform: scale(1.05); }
#tgchat-launcher.tgchat-pulse { animation: tgchatPulse 1.4s infinite; }

  100% { transform: scale(1.55); opacity: 0; }
}

#tgchat-fab {
  position: relative;
  display: block;
  width: 58px;
  height: 58px;
  overflow: visible;
}
#tgchat-hide {
  position: absolute;
  top: -12px;
  right: -12px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.28);
  color: rgba(255, 255, 255, 0.8);
  cursor: pointer;
  font-size: 12px;
  line-height: 18px;
  text-align: center;
  padding: 0;
  opacity: 0.5;
  z-index: 3;
}

#tgchat-root.tgchat-hidden #tgchat-fab,
#tgchat-root.tgchat-hidden #tgchat-panel { display: none !important; }

#tgchat-restore {
  display: none; position: fixed; right: 0; bottom: 120px; z-index: 99998;
  writing-mode: vertical-rl; border: none; cursor: pointer;
  background: #a67c52; color: #fff; padding: 12px 6px; border-radius: 8px 0 0 8px;
  font-size: 12px; font-weight: 600;
}
#tgchat-root.tgchat-hidden ~ #tgchat-restore { display: block; }

#tgchat-panel {
  position: absolute;
  right: 0;
  bottom: calc(100% + 12px);
  width: min(360px, calc(100vw - 28px));
  height: min(480px, calc(100vh - 120px));
  max-height: calc(100vh - 100px);
  background: #faf6f1;
  border: 1px solid #c4a484;
  border-radius: 3px;
  box-shadow: 0 16px 40px rgba(61,41,20,.2);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
#tgchat-panel[hidden] { display: none !important; }

.tgchat-head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 14px; background: #3d2914; color: #f5ebe0;
  flex-shrink: 0;
}
.tgchat-head strong { font-size: 15px; }
.tgchat-sub { font-size: 12px; opacity: .8; margin-top: 2px; }
#tgchat-close {
  border: none; background: transparent; color: #f5ebe0; font-size: 22px; cursor: pointer; line-height: 1;
  padding: 0 4px;
}

#tgchat-msgs {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  background: #f3e8dc;
}
.tgchat-msg {
  max-width: 88%;
  margin: 8px 0;
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.tgchat-msg.me { margin-left: auto; background: #fff; border: 1px solid #e0d4c8; color: #3d2914; }
.tgchat-msg.admin { margin-right: auto; background: #2AABEE; color: #fff; }
.tgchat-msg .tgchat-who { font-size: 11px; opacity: .85; margin-bottom: 2px; }
.tgchat-sys { font-size: 13px; color: #8b7355; text-align: center; padding: 16px 8px; }

.tgchat-footer {
  flex-shrink: 0;
  background: #faf6f1;
  border-top: 1px solid #e8dccf;
  padding: 8px 10px 10px;
}

.tgchat-meta {
  display: flex;
  gap: 6px;
  margin-bottom: 8px;
}
.tgchat-meta input {
  flex: 1 1 0;
  min-width: 0;
  width: 100%;
  border: 1px solid #d4c4b0;
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  background: #fff;
  color: #3d2914;
}

#tgchat-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
}
#tgchat-input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  resize: none;
  border: 1px solid #d4c4b0;
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: #3d2914;
  max-height: 88px;
}
#tgchat-send {
  flex: 0 0 auto;
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  background: #a67c52;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  max-width: 40%;
}
#tgchat-send:disabled { opacity: .6; cursor: wait; }

/* Mobile: clear UniShop bottom bar, full-width panel */
@media (max-width: 767px) {
  #tgchat-root {
    right: 12px;
    left: auto;
  }
  #tgchat-panel {
    position: fixed;
    left: 10px;
    right: 10px;
    width: auto;
    bottom: calc(var(--tgchat-bottom, 18px) + 70px);
    height: min(58vh, 440px);
    max-height: calc(100vh - 140px);
    border-radius: 3px;
  }
  #tgchat-root.tgchat-pos-left {
    left: 12px;
    right: auto;
  }
  .tgchat-meta {
    flex-direction: column;
  }
  #tgchat-send {
    max-width: 34%;
    padding: 10px 8px;
    font-size: 13px;
  }
}

.tgchat-contact-bar {
  flex-shrink: 0;
  padding: 8px 12px;
  font-size: 12px;
  color: #5c4030;
  background: #efe4d6;
  border-bottom: 1px solid #e0d4c8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tgchat-contact-bar:not([hidden])::before {
  content: "👤 ";
}

#tgchat-launcher.tgchat-pulse {
  animation: tgchatPulse 1.4s infinite;
}
@keyframes tgchatPulse {
  0% { box-shadow: 0 0 0 0 rgba(166,124,82,.55), 0 8px 24px rgba(61,41,20,.28); }
  70% { box-shadow: 0 0 0 14px rgba(166,124,82,0), 0 8px 24px rgba(61,41,20,.28); }
  100% { box-shadow: 0 0 0 0 rgba(166,124,82,0), 0 8px 24px rgba(61,41,20,.28); }
}


.tgchat-contact-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.tgchat-contact-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.tgchat-edit-contact {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: #8b6914;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
  text-decoration: underline;
}
.tgchat-edit-contact:hover {
  color: #5c4030;
}


.tgchat-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  align-items: center;
}
.tgchat-meta input {
  flex: 1 1 calc(50% - 6px);
  min-width: 0;
}
.tgchat-save-contact {
  flex: 0 0 auto;
  border: none;
  border-radius: 8px;
  background: #a67c52;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  padding: 8px 12px;
  cursor: pointer;
  white-space: nowrap;
}
.tgchat-save-contact:hover { background: #8b6914; }
.tgchat-contact-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.tgchat-contact-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.tgchat-edit-contact {
  flex-shrink: 0;
  border: none;
  background: transparent;
  color: #8b6914;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 2px 4px;
  text-decoration: underline;
}
.tgchat-edit-contact:hover { color: #5c4030; }

/* Inline message editing */
.tgchat-who {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.tgchat-edited {
  margin-left: 5px;
  opacity: .58;
  font-size: 10px;
  font-weight: 500;
}
.tgchat-edit-message {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  color: inherit;
  opacity: .72;
  padding: 0;
  font-size: 11px;
  font-weight: 600;
  text-decoration: underline;
  cursor: pointer;
}
.tgchat-edit-message:hover { opacity: 1; }
.tgchat-edit-box { width: 100%; }
.tgchat-edit-textarea {
  display: block;
  width: 100%;
  min-height: 76px;
  max-height: 180px;
  resize: vertical;
  border: 1px solid rgba(92, 64, 48, .24);
  border-radius: 3px;
  background: #fff;
  color: #3f2a20;
  font: inherit;
  line-height: 1.4;
  padding: 10px 11px;
  outline: none;
}
.tgchat-edit-textarea:focus {
  border-color: #8a604b;
  box-shadow: 0 0 0 2px rgba(138, 96, 75, .12);
}
.tgchat-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 7px;
  margin-top: 7px;
}
.tgchat-edit-save,
.tgchat-edit-cancel {
  border: 0;
  border-radius: 3px;
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.tgchat-edit-save {
  background: #5c4030;
  color: #fff;
}
.tgchat-edit-cancel {
  background: rgba(92, 64, 48, .09);
  color: #5c4030;
}
.tgchat-edit-save:disabled,
.tgchat-edit-cancel:disabled {
  opacity: .55;
  cursor: wait;
}
  

/* Unified chat actions and configurable messages background */
#tgchat-msgs {
  background: var(--tgchat-messages-bg, #f3e8dc);
}
.tgchat-edit-contact,
.tgchat-edit-message,
.tgchat-delete-message {
  flex: 0 0 auto;
  border: 0;
  background: transparent;
  padding: 2px 4px;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  text-decoration: underline;
  cursor: pointer;
  color: #7a604f;
  opacity: .88;
}
.tgchat-edit-contact:hover,
.tgchat-edit-message:hover {
  color: #4a2f1b;
  opacity: 1;
}
.tgchat-delete-message {
  color: #c94f49;
}
.tgchat-delete-message:hover {
  color: #a72f2a;
  opacity: 1;
}
.tgchat-edit-contact:disabled,
.tgchat-edit-message:disabled,
.tgchat-delete-message:disabled {
  cursor: wait;
  opacity: .45;
}
.tgchat-message-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}


/* Configurable store message bubble */
.tgchat-msg.admin {
  background: var(--tgchat-store-message-bg, #2AABEE);
}

.tgchat-msg.me {
  background: var(--tgchat-customer-message-bg, #ffffff);
}

#tgchat-root #tgchat-panel .tgchat-msg.me,
#tgchat-root #tgchat-panel .tgchat-msg.admin {
  box-shadow: 0 8px 24px rgba(61, 41, 20, 0.20) !important;
}


/* Ensure configured bubble colors override theme custom styles */
#tgchat-root #tgchat-panel .tgchat-msg.me {
  background: var(--tgchat-customer-message-bg, #ffffff) !important;
}
#tgchat-root #tgchat-panel .tgchat-msg.admin {
  background: var(--tgchat-store-message-bg, #2AABEE) !important;
}


/* Protected Sumkova chat geometry and primary action. */
#tgchat-root #tgchat-panel,
#tgchat-root #tgchat-panel .tgchat-msg,
#tgchat-root #tgchat-panel .tgchat-meta input,
#tgchat-root #tgchat-panel #tgchat-input,
#tgchat-root #tgchat-panel #tgchat-send {
	border-radius: 3px !important;
}

#tgchat-root #tgchat-panel #tgchat-send,
#tgchat-root #tgchat-panel #tgchat-send:hover,
#tgchat-root #tgchat-panel #tgchat-send:focus {
	background: #3a2418 !important;
	color: #fff !important;
}

#tgchat-restore {
	border-radius: 3px 0 0 3px !important;
}