/* ============================================================
   Telegram Live Chat Widget — chat.css
   ============================================================ */

:root {
    --tlc-primary:     #2AABEE;   /* Telegram blue */
    --tlc-primary-dk:  #1a8cc7;
    --tlc-success:     #27ae60;
    --tlc-danger:      #e74c3c;
    --tlc-gray:        #f0f2f5;
    --tlc-border:      #e1e4e8;
    --tlc-text:        #1c1e21;
    --tlc-text-light:  #65676b;
    --tlc-white:       #ffffff;
    --tlc-radius:      16px;
    --tlc-shadow:      0 8px 40px rgba(0,0,0,.18);
    --tlc-font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --tlc-z:           99999;
}

/* ── Toggle button ── */
#tlc-toggle {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: var(--tlc-z);
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: var(--tlc-primary);
    color: var(--tlc-white);
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(42,171,238,.45);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s, background .2s;
    font-size: 0;
}
#tlc-toggle:hover { background: var(--tlc-primary-dk); transform: scale(1.08); }
#tlc-toggle svg   { width: 28px; height: 28px; }

/* Unread badge */
#tlc-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    background: var(--tlc-danger);
    color: #fff;
    font: 700 11px var(--tlc-font);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    display: none;
}

/* ── Chat window ── */
#tlc-window {
    position: fixed;
    bottom: 100px;
    right: 28px;
    z-index: var(--tlc-z);
    width: 370px;
    max-height: 580px;
    background: var(--tlc-white);
    border-radius: var(--tlc-radius);
    box-shadow: var(--tlc-shadow);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    font-family: var(--tlc-font);
    opacity: 0;
    transform: translateY(12px) scale(.97);
    pointer-events: none;
    transition: opacity .22s, transform .22s;
}
#tlc-window.tlc-open {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: all;
}

/* ── Header ── */
#tlc-header {
    background: var(--tlc-primary);
    color: var(--tlc-white);
    padding: 14px 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}
.tlc-avatar {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: rgba(255,255,255,.25);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.tlc-avatar svg { width: 22px; height: 22px; }
.tlc-header-info { flex: 1; }
.tlc-header-title  { font-size: 15px; font-weight: 600; }
.tlc-header-status { font-size: 12px; opacity: .85; margin-top: 2px; }
.tlc-status-dot {
    display: inline-block;
    width: 7px; height: 7px;
    border-radius: 50%;
    background: #4ade80;
    margin-right: 4px;
    vertical-align: middle;
}
#tlc-close-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,.8);
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    border-radius: 50%;
    transition: background .15s;
}
#tlc-close-btn:hover { background: rgba(255,255,255,.15); color: #fff; }
#tlc-close-btn svg { width: 18px; height: 18px; display: block; }

/* ── Panels ── */
.tlc-panel { display: none; flex-direction: column; flex: 1; overflow: hidden; }
.tlc-panel.tlc-active { display: flex; }

/* ── Start Form ── */
#tlc-form-panel {
    padding: 20px;
    gap: 12px;
    overflow-y: auto;
}
.tlc-field-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--tlc-text-light);
    margin-bottom: 5px;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.tlc-input {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--tlc-border);
    border-radius: 10px;
    font-size: 14px;
    font-family: var(--tlc-font);
    color: var(--tlc-text);
    background: var(--tlc-white);
    outline: none;
    transition: border-color .15s;
    box-sizing: border-box;
}
.tlc-input:focus { border-color: var(--tlc-primary); }
.tlc-input.tlc-error { border-color: var(--tlc-danger); }
.tlc-field-error {
    font-size: 12px;
    color: var(--tlc-danger);
    margin-top: 3px;
    display: none;
}
.tlc-field-error.visible { display: block; }

.tlc-privacy {
    font-size: 12px;
    color: var(--tlc-text-light);
    text-align: center;
    line-height: 1.5;
}
.tlc-privacy a { color: var(--tlc-primary); }

.tlc-btn {
    width: 100%;
    padding: 12px;
    background: var(--tlc-primary);
    color: var(--tlc-white);
    border: none;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.tlc-btn:hover   { background: var(--tlc-primary-dk); }
.tlc-btn:disabled { opacity: .65; cursor: not-allowed; }
.tlc-btn svg { width: 18px; height: 18px; }

/* ── Messages ── */
#tlc-messages-panel { gap: 0; }

#tlc-messages {
    flex: 1;
    padding: 14px 14px 8px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}
#tlc-messages::-webkit-scrollbar { width: 4px; }
#tlc-messages::-webkit-scrollbar-thumb { background: var(--tlc-border); border-radius: 2px; }

.tlc-msg {
    max-width: 80%;
    padding: 9px 12px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.45;
    word-break: break-word;
    position: relative;
}
.tlc-msg-meta {
    font-size: 11px;
    opacity: .65;
    margin-top: 3px;
    display: block;
    text-align: right;
}
.tlc-msg.user {
    align-self: flex-end;
    background: var(--tlc-primary);
    color: var(--tlc-white);
    border-bottom-right-radius: 4px;
}
.tlc-msg.operator {
    align-self: flex-start;
    background: var(--tlc-gray);
    color: var(--tlc-text);
    border-bottom-left-radius: 4px;
}
.tlc-msg.system {
    align-self: center;
    background: none;
    color: var(--tlc-text-light);
    font-size: 12px;
    text-align: center;
    max-width: 100%;
    padding: 4px 0;
}

/* Typing indicator */
#tlc-typing {
    display: none;
    align-self: flex-start;
    padding: 10px 14px;
    background: var(--tlc-gray);
    border-radius: 14px;
    border-bottom-left-radius: 4px;
}
#tlc-typing span {
    display: inline-block;
    width: 7px; height: 7px;
    background: var(--tlc-text-light);
    border-radius: 50%;
    animation: tlc-bounce .9s infinite;
}
#tlc-typing span:nth-child(2) { animation-delay: .15s; }
#tlc-typing span:nth-child(3) { animation-delay: .3s; }
@keyframes tlc-bounce {
    0%,80%,100% { transform: translateY(0); }
    40%         { transform: translateY(-6px); }
}

/* ── Input area ── */
#tlc-input-area {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-top: 1px solid var(--tlc-border);
    flex-shrink: 0;
}
#tlc-msg-input {
    flex: 1;
    border: 1.5px solid var(--tlc-border);
    border-radius: 22px;
    padding: 9px 14px;
    font-size: 14px;
    font-family: var(--tlc-font);
    resize: none;
    outline: none;
    max-height: 100px;
    overflow-y: auto;
    transition: border-color .15s;
    line-height: 1.4;
}
#tlc-msg-input:focus { border-color: var(--tlc-primary); }

#tlc-send-btn {
    width: 38px; height: 38px;
    border-radius: 50%;
    background: var(--tlc-primary);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background .15s, transform .15s;
}
#tlc-send-btn:hover   { background: var(--tlc-primary-dk); transform: scale(1.05); }
#tlc-send-btn:disabled { opacity: .5; cursor: default; transform: none; }
#tlc-send-btn svg { width: 18px; height: 18px; }

/* ── Footer ── */
#tlc-footer {
    padding: 6px 12px 8px;
    text-align: center;
    border-top: 1px solid var(--tlc-border);
    flex-shrink: 0;
}
#tlc-end-chat {
    background: none;
    border: none;
    color: var(--tlc-text-light);
    font-size: 12px;
    cursor: pointer;
    text-decoration: underline;
    padding: 2px 4px;
}
#tlc-end-chat:hover { color: var(--tlc-danger); }

/* ── Closed state ── */
#tlc-closed-panel {
    align-items: center;
    justify-content: center;
    padding: 32px 24px;
    text-align: center;
    gap: 12px;
}
.tlc-closed-icon svg { width: 52px; height: 52px; color: var(--tlc-success); }
.tlc-closed-title { font-size: 17px; font-weight: 600; color: var(--tlc-text); }
.tlc-closed-sub   { font-size: 14px; color: var(--tlc-text-light); line-height: 1.5; }
.tlc-new-chat-btn {
    margin-top: 8px;
    padding: 10px 24px;
    background: var(--tlc-primary);
    color: #fff;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s;
}
.tlc-new-chat-btn:hover { background: var(--tlc-primary-dk); }

/* ── Toast notifications ── */
#tlc-toast {
    position: fixed;
    bottom: 100px;
    right: 28px;
    z-index: calc(var(--tlc-z) + 1);
    background: #333;
    color: #fff;
    padding: 10px 18px;
    border-radius: 10px;
    font-size: 14px;
    font-family: var(--tlc-font);
    opacity: 0;
    transform: translateY(6px);
    pointer-events: none;
    transition: opacity .25s, transform .25s;
    max-width: 320px;
}
#tlc-toast.visible {
    opacity: 1;
    transform: translateY(0);
}

/* ── Spinner ── */
.tlc-spinner {
    width: 18px; height: 18px;
    border: 2.5px solid rgba(255,255,255,.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: tlc-spin .7s linear infinite;
    flex-shrink: 0;
}
@keyframes tlc-spin { to { transform: rotate(360deg); } }

/* ── Mobile ── */
@media (max-width: 480px) {
    #tlc-window {
        width: calc(100vw - 16px);
        right: 8px;
        bottom: 86px;
        max-height: calc(100dvh - 110px);
    }
    #tlc-toggle { right: 16px; bottom: 20px; }
}
