/* ===== Telegram Chat Widget — Base CSS ===== */

/*
 * Skin-specific colours are injected by the active skin library
 * (telegram_chat/skin.mawenix, telegram_chat/skin.wise, etc.).
 * This file only defines fallback values; a skin should override all of them.
 */
:root {
  --tg-color-primary:      #2B77CC;
  --tg-color-secondary:    #8455D4;
  --tg-color-gradient:     linear-gradient(135deg, #2B77CC, #8455D4);
  --tg-color-bg:           #f5f6fa;
  --tg-color-text:         #454754;
  --tg-color-border:       #dbe0f0;
  --tg-color-btn-shadow:   rgba(43, 119, 204, 0.45);
  --tg-color-btn-shadow-h: rgba(43, 119, 204, 0.5);
  --tg-color-online:       #35CC24;
  --tg-color-offline:      #999999;
  --tg-color-author:       #8455D4;
  --tg-color-focus-ring:   rgba(132, 85, 212, 0.45);

  /* Structural tokens — overridden by skin files */
  --tg-font-family:         'Poppins', sans-serif;
  --tg-panel-radius:        10px;
  --tg-header-bg:           var(--tg-color-gradient);
  --tg-header-text-color:   #ffffff;
    --tg-header-close-color:  var(--tg-header-text-color);
    --tg-header-close-bg:     transparent;
    --tg-header-close-border: transparent;
  --tg-header-close-hover:  rgba(255, 255, 255, 0.15);
    --tg-header-close-hover-color: var(--tg-header-close-color);
    --tg-header-close-shadow: none;
    --tg-header-close-hover-shadow: var(--tg-header-close-shadow);
  --tg-avatar-border-color: rgba(255, 255, 255, 0.5);
  --tg-bubble-radius:       18px;
  --tg-input-radius:        14px;
  --tg-send-bg:             var(--tg-color-gradient);
  --tg-send-radius:         38px;
}

/* Floating button — round avatar */
#tg-chat-btn {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 4px 20px var(--tg-color-btn-shadow);
    z-index: 9998;
    overflow: visible;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    border: none;
    padding: 0;
    background: transparent;
    appearance: none;
}

#tg-chat-btn img {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    object-fit: cover;
    display: block;
    border: 3px solid #ffffff;
}

#tg-chat-btn:hover {
    transform: scale(1.08);
    box-shadow: 0 6px 28px var(--tg-color-btn-shadow-h);
}

#tg-chat-btn:focus-visible,
.tg-chat-close:focus-visible,
#tg-send:focus-visible,
.tg-chat-field input:focus-visible,
.tg-chat-field textarea:focus-visible {
    outline: 3px solid var(--tg-color-focus-ring);
    outline-offset: 2px;
}

#tg-chat-btn.tg-hidden {
    transform: scale(0);
    pointer-events: none;
}

/* Online / Offline dot */
.tg-online-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--tg-color-online);
    flex-shrink: 0;
}

.tg-offline-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--tg-color-offline);
    flex-shrink: 0;
}

#tg-chat-btn .tg-online-dot,
#tg-chat-btn .tg-offline-dot {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    border: 2px solid #ffffff;
    box-sizing: border-box;
}

/* Chat panel */
#tg-chat-panel {
    position: fixed;
    bottom: 30px;
    right: 30px;
    width: 350px;
    max-height: calc(100vh - 100px);
    max-height: calc(100dvh - 100px);
    background: var(--tg-color-bg);
    border-radius: var(--tg-panel-radius);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.18);
    z-index: 9999;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    transform: scale(0);
    transform-origin: bottom right;
    opacity: 0;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.3s ease;
}

#tg-chat-panel.tg-open {
    transform: scale(1);
    opacity: 1;
}

/* Header */
.tg-chat-header {
    background: var(--tg-header-bg);
    color: var(--tg-header-text-color);
    padding: 14px 16px;
    border-radius: var(--tg-panel-radius) var(--tg-panel-radius) 0 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.tg-agent-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.tg-agent-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--tg-avatar-border-color);
    flex-shrink: 0;
}

.tg-agent-meta {
    display: flex;
    flex-direction: column;
}

.tg-agent-name {
    font-family: var(--tg-font-family);
    font-size: var(--font-size-small, 15px);
    font-weight: 600;
    line-height: 1.4;
}

.tg-agent-position {
    font-family: var(--tg-font-family);
    font-size: var(--font-size-min, 13px);
    opacity: 0.75;
    margin-top: 1px;
    line-height: 1.4;
}

.tg-status-line {
    font-family: var(--tg-font-family);
    font-size: var(--font-size-min, 13px);
    opacity: 0.85;
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 2px;
    line-height: 1.4;
}

.tg-chat-close {
    background: var(--tg-header-close-bg);
    border: 1px solid var(--tg-header-close-border);
    color: var(--tg-header-close-color);
    font-size: 26px;
    cursor: pointer;
    width: 40px;
    height: 40px;
    min-width: 40px;
    min-height: 40px;
    max-width: 40px;
    max-height: 40px;
    aspect-ratio: 1 / 1;
    box-sizing: border-box;
    padding: 0;
    line-height: 1;
    opacity: 0.8;
    transition: opacity 0.2s, background-color 0.2s, border-color 0.2s, color 0.2s;
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 9999px;
    box-shadow: var(--tg-header-close-shadow);
}

.tg-chat-close:hover {
    opacity: 1;
    background: var(--tg-header-close-hover);
    border-color: var(--tg-header-close-border);
    color: var(--tg-header-close-hover-color);
    box-shadow: var(--tg-header-close-hover-shadow);
}

/* Messages area */
.tg-messages {
    padding: 14px 14px 6px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    background: var(--tg-color-bg);
    overflow-y: auto;
    flex: 1;
}

/* Message bubbles */
.tg-bubble {
    max-width: 82%;
    padding: 10px 14px 6px;
    border-radius: var(--tg-bubble-radius);
    font-family: var(--tg-font-family);
    font-size: var(--font-size-small, 15px);
    line-height: 1.6;
    animation: tg-bubble-in 0.3s ease;
    position: relative;
}

.tg-bubble-time {
    display: block;
    font-size: 11px;
    opacity: 0.55;
    margin-top: 4px;
    line-height: 1;
}

.tg-bubble-out .tg-bubble-time {
    text-align: left;
}

.tg-bubble-in .tg-bubble-time {
    text-align: right;
}

.tg-bubble-in {
    background: #ffffff;
    color: var(--tg-color-text);
    border-bottom-right-radius: 4px;
    align-self: flex-end;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.tg-bubble-out {
    background: var(--tg-color-gradient);
    color: #ffffff;
    border-bottom-left-radius: 4px;
    align-self: flex-start;
}

.tg-bubble-row-out {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    width: 100%;
}

.tg-bubble-row-in {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    width: 100%;
}

.tg-bubble-author {
    font-size: var(--font-size-min, 13px);
    font-weight: 600;
    color: var(--tg-color-author);
    padding-bottom: 4px;
}

.tg-bubble-author-out {
    text-align: left;
    padding-left: 2px;
}

.tg-bubble-author-in {
    text-align: right;
    padding-right: 2px;
}

@keyframes tg-bubble-in {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Typing indicator */
.tg-typing {
    display: flex;
    align-items: center;
    gap: 4px;
    background: #ffffff;
    border-radius: var(--tg-bubble-radius);
    border-bottom-left-radius: 4px;
    padding: 12px 16px;
    width: fit-content;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.tg-typing span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--tg-color-secondary);
    animation: tg-bounce 1.2s infinite ease-in-out;
}

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

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

@keyframes tg-bounce {

    0%,
    60%,
    100% {
        transform: translateY(0);
        opacity: 0.4;
    }

    30% {
        transform: translateY(-6px);
        opacity: 1;
    }
}

/* Reply form */
.tg-chat-body {
    padding: 10px 14px 14px;
    background: var(--tg-color-bg);
    border-top: 1px solid var(--tg-color-border);
}

.tg-chat-field {
    margin-bottom: 8px;
}

.tg-chat-field input,
.tg-chat-field textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--tg-color-border);
    border-radius: var(--tg-input-radius);
    font-family: var(--tg-font-family);
    font-size: var(--font-size-small, 15px);
    color: var(--tg-color-text);
    outline: none;
    background: #ffffff;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s;
    box-sizing: border-box;
    resize: none;
    line-height: 1.5;
}

.tg-chat-field input:focus,
.tg-chat-field textarea:focus {
    border-color: var(--tg-color-secondary);
    box-shadow: 0 0 0 4px var(--tg-color-focus-ring);
}

.tg-chat-field textarea {
    min-height: 60px;
}

/* Send button */
#tg-send {
    width: 100%;
    padding: 11px;
    border: none;
    border-radius: var(--tg-send-radius);
    background: var(--tg-send-bg);
    color: #ffffff;
    font-family: var(--tg-font-family);
    font-size: var(--form-button-font-size, 15px);
    font-weight: 400;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.2s, box-shadow 0.2s;
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0;
    line-height: 1.4;
}

#tg-send:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

#tg-chat-btn:focus-visible,
.tg-chat-close:focus-visible,
#tg-send:focus-visible {
    box-shadow: 0 0 0 4px var(--tg-color-focus-ring);
}

#tg-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Status */
.tg-status {
    margin-top: 10px;
    font-family: var(--tg-font-family);
    font-size: var(--font-size-min, 13px);
    text-align: center;
    min-height: 16px;
    line-height: 1.4;
}

.tg-status.tg-success {
    color: var(--tg-color-online);
}

.tg-status.tg-error {
    color: #D65050;
}

.tg-status.tg-sending {
    color: #86889A;
}

/* Mobile */
@media (max-width: 640px) {
    #tg-chat-panel {
        width: calc(100% - 20px);
        right: 10px;
        bottom: 10px;
        max-height: calc(100vh - 20px);
        max-height: calc(100dvh - 20px);
    }

    #tg-chat-btn {
        bottom: 15px;
        right: 15px;
    }
}

@media (prefers-reduced-motion: reduce) {
    #tg-chat-btn,
    #tg-chat-panel,
    #tg-send,
    .tg-chat-close,
    .tg-bubble,
    .tg-typing span {
        animation: none !important;
        transition: none !important;
    }
}