/* TechNest Support — telegram-style, dark volvo-tech palette */

#tns-root {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 999999;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.4;
}
/* Глушим глобальные стили темы внутри виджета */
#tns-root *, #tns-root *:hover, #tns-root *:focus, #tns-root *:active {
    outline: none !important;
    box-shadow: none;
    -webkit-tap-highlight-color: transparent;
}

/* --- FAB --- */
#tns-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    background: rgb(40, 45, 62);
    color: #fff;
    box-shadow: 0 4px 16px rgba(20, 24, 40, .5);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    transition: transform .15s, box-shadow .15s;
    padding: 0;
}
#tns-btn:hover { transform: scale(1.06); box-shadow: 0 6px 20px rgba(20, 24, 40, .65) !important; }
#tns-btn:focus, #tns-btn:active { box-shadow: 0 4px 16px rgba(20, 24, 40, .5) !important; }
.tns-badge {
    position: absolute;
    top: -2px;
    right: -2px;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #e53935;
    color: #fff;
    font-size: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* --- Окно --- */
#tns-panel {
    position: absolute;
    right: 0;
    bottom: 70px;
    width: 370px;
    max-width: calc(100vw - 40px);
    height: 520px;
    max-height: calc(100vh - 120px);
    background: #1e1e24;
    border: 1px solid #253050;
    border-radius: 16px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .55);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    animation: tns-up .18s ease-out;
}
@keyframes tns-up { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

/* --- Шапка --- */
.tns-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    background: linear-gradient(135deg, #252a3a, #1e2230);
    border-bottom: 1px solid #253050;
}
.tns-head-ava {
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: linear-gradient(135deg, #3a7bd5, #2a5cae);
    color: #fff;
    font-weight: 700;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}
.tns-head-info { flex: 1; min-width: 0; }
.tns-head-title { color: #c8d0e0; font-weight: 600; font-size: 15px; }
.tns-head-sub { display: flex; align-items: center; gap: 5px; font-size: 12px; color: #7ea8d8; }
.tns-dot { width: 7px; height: 7px; border-radius: 50%; background: #43a047; display: inline-block; }
.tns-head-close {
    background: none;
    border: none;
    color: #8a9cbd;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
}
.tns-head-close:hover { color: #c8d0e0; }

/* --- Гостевая форма --- */
.tns-guest { padding: 18px 16px; overflow-y: auto; }
.tns-guest p { color: #c8d0e0; margin: 0 0 12px; }
.tns-guest input {
    width: 100%;
    box-sizing: border-box;
    margin-bottom: 10px;
    padding: 10px 12px;
    background: #242428;
    border: 1px solid #253050;
    border-radius: 10px;
    color: #c8d0e0;
    font-size: 14px;
}
.tns-guest input:focus { outline: none; border-color: #3a7bd5; }
.tns-guest-go {
    width: 100%;
    padding: 11px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, #3a7bd5, #2a5cae);
    color: #fff;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.tns-guest-go:disabled { opacity: .6; cursor: default; }
.tns-hp { position: absolute; left: -9999px; opacity: 0; height: 0; }
.tns-err { color: #ef5350; font-size: 12px; margin-top: 8px; min-height: 14px; }

/* --- Сообщения --- */
.tns-msgs {
    flex: 1;
    overflow-y: auto;
    padding: 14px 12px;
    background-color: #151720;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120' viewBox='0 0 120 120'%3E%3Cg fill='none' stroke='%234a8fe0' stroke-opacity='0.07' stroke-width='1'%3E%3Cpath d='M30 8L49 19v22L30 52 11 41V19zM90 8l19 11v22L90 52 71 41V19zM60 60l19 11v22L60 104 41 93V71z'/%3E%3Cpath d='M30 52v18l11 7M90 52v18l-11 7M49 30h22M11 30H0M109 30h11M60 104v16M30 0v8M90 0v8'/%3E%3Crect x='26' y='26' width='8' height='8' rx='1'/%3E%3Crect x='86' y='26' width='8' height='8' rx='1'/%3E%3Crect x='56' y='78' width='8' height='8' rx='1'/%3E%3C/g%3E%3Cg fill='%237ec8f8' fill-opacity='0.10'%3E%3Ccircle cx='30' cy='70' r='1.8'/%3E%3Ccircle cx='90' cy='70' r='1.8'/%3E%3Ccircle cx='49' cy='30' r='1.6'/%3E%3Ccircle cx='71' cy='30' r='1.6'/%3E%3Ccircle cx='60' cy='60' r='1.8'/%3E%3Ccircle cx='11' cy='30' r='1.5'/%3E%3Ccircle cx='109' cy='30' r='1.5'/%3E%3C/g%3E%3C/svg%3E");
    background-size: 120px 120px;
}
.tns-msgs::-webkit-scrollbar { width: 6px; }
.tns-msgs::-webkit-scrollbar-thumb { background: #2e3446; border-radius: 3px; }

.tns-m { display: flex; margin-bottom: 8px; align-items: flex-end; gap: 6px; }
.tns-m-user { justify-content: flex-end; }

/* Системные сообщения — центрированная пилюля */
.tns-m-system {
    justify-content: center;
    align-self: center;
    text-align: center;
    margin: 12px auto;
    max-width: 90%;
    padding: 4px 12px;
    color: #7d8db0;
    font-size: 11.5px;
    font-style: normal;
    background: #1d1f29;
    border: 1px solid #262a3a;
    border-radius: 10px;
}

.tns-ava {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
}
.tns-ava-ai { background: #4a5568; font-size: 9px; }
.tns-ava-op { background: linear-gradient(135deg, #6a5acd, #483d8b); }

.tns-b {
    max-width: 78%;
    padding: 8px 10px;
    border-radius: 16px;
    word-break: break-word;
    position: relative;
}
.tns-m-ai .tns-b,
.tns-m-operator .tns-b {
    background: linear-gradient(135deg, #3a4a6b, #31405e);
    border: 1px solid #4e6491;
    color: #ffffff;
    opacity: 1 !important;
    border-bottom-left-radius: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
}
.tns-m-user .tns-b {
    background: linear-gradient(135deg, #3a7bd5, #2f6bc4);
    color: #fff;
    opacity: 1 !important;
    border-bottom-right-radius: 0;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .4);
}
.tns-pending .tns-b { opacity: .55; }

.tns-txt { white-space: pre-wrap; }
.tns-txt a { color: #7ec8f8; text-decoration: none; border-bottom: 1px dotted #7ec8f8; }
.tns-m-user .tns-txt a { color: #d0e8ff; border-bottom-color: #d0e8ff; }
.tns-txt a:hover { text-decoration: underline; }

.tns-img {
    display: block;
    max-width: 100%;
    max-height: 220px;
    border-radius: 10px;
    margin-top: 6px;
    cursor: zoom-in;
}
.tns-file {
    display: inline-block;
    margin-top: 6px;
    padding: 6px 10px;
    background: rgba(0, 0, 0, .25);
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 8px;
    color: #fff !important;
    text-decoration: none !important;
    font-size: 12.5px;
    font-weight: 500;
}
.tns-file:hover { background: rgba(0, 0, 0, .4); }
.tns-attach-name {
    color: #c8d0e0;
    font-size: 12.5px;
    max-width: 240px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.tns-dropzone {
    position: absolute;
    inset: 52px 8px 8px 8px;
    background: rgba(21, 23, 32, .92);
    border: 2px dashed #4a8fe0;
    border-radius: 12px;
    color: #cfe0ff;
    font-size: 14px;
    font-weight: 600;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 16px;
    z-index: 20;
    pointer-events: none;
}

/* --- Лайтбокс --- */
.tns-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(10, 12, 18, .88);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    z-index: 1000001;
    padding: 24px;
    cursor: zoom-out;
}
.tns-lightbox img {
    max-width: 92vw;
    max-height: 90vh;
    border-radius: 10px;
    box-shadow: 0 12px 48px rgba(0, 0, 0, .75);
    cursor: default;
}
.tns-lb-close {
    position: fixed;
    top: 18px;
    right: 22px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid rgba(255, 255, 255, .2);
    background: rgba(30, 34, 48, .85);
    color: #fff;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.tns-lb-close:hover { background: #3a7bd5 !important; }
.tns-who { font-size: 11px; color: #8a9cbd; margin-top: 4px; }
.tns-m-user .tns-who { color: rgba(255, 255, 255, .65); }
.tns-time {
    display: block;
    text-align: right;
    font-size: 10px;
    margin-top: 3px;
    color: rgba(255, 255, 255, .45);
}
.tns-m-ai .tns-time, .tns-m-operator .tns-time { color: #b0c4e4; }

.tns-edit-btn {
    background: none !important;
    border: none !important;
    color: #7ea8d8;
    cursor: pointer;
    padding: 2px 5px;
    font-size: 13px;
    line-height: 1;
    opacity: .55;
    border-radius: 6px;
    align-self: center;
}
.tns-edit-btn:hover { opacity: 1; color: #fff; }

/* --- Печатает --- */
.tns-typing {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px 8px;
    background: #151720;
}
.tns-tdots { display: inline-flex; gap: 3px; padding: 8px 10px; background: #3a4a6b; border: 1px solid #4e6491; border-radius: 12px; }
.tns-tdots i {
    width: 6px; height: 6px; border-radius: 50%;
    background: #7ea8d8; display: block;
    animation: tns-blink 1.2s infinite;
}
.tns-tdots i:nth-child(2) { animation-delay: .2s; }
.tns-tdots i:nth-child(3) { animation-delay: .4s; }
@keyframes tns-blink { 0%, 60%, 100% { opacity: .25; } 30% { opacity: 1; } }

/* --- Превью вложения --- */
.tns-attachbar {
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: #1e1e24;
    border-top: 1px solid #253050;
}
.tns-attachbar img { max-height: 48px; border-radius: 6px; }
.tns-attachbar button {
    background: #2b2b35;
    border: none;
    color: #8a9cbd;
    width: 22px; height: 22px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
}
.tns-attachbar button:hover { color: #fff; }

/* --- Инпут-бар --- */
.tns-input {
    display: flex;
    align-items: flex-end;
    gap: 6px;
    padding: 10px;
    background: #1e1e24;
    border-top: 1px solid #253050;
}
.tns-ibtn {
    background: none;
    border: none;
    color: #7ea8d8;
    cursor: pointer;
    padding: 0;
    border-radius: 8px;
    flex: 0 0 auto;
    width: 32px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    line-height: 1;
    font-family: 'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', sans-serif;
}
.tns-ibtn:hover, .tns-ibtn:focus, .tns-ibtn:active {
    background: none !important;
    background-color: transparent !important;
    background-image: none !important;
    color: #c8d0e0;
}
.tns-ibtn:disabled { opacity: .4; cursor: default; }

.tns-input textarea {
    flex: 1;
    resize: none;
    border: none;
    background: #2b2b35;
    color: #dde3f0;
    border-radius: 12px;
    padding: 9px 12px;
    font-size: 14px;
    font-family: inherit;
    line-height: 1.35;
    height: 38px;
    min-height: 38px;
    max-height: 120px;
    overflow-y: hidden;
    box-sizing: border-box;
}
.tns-input textarea:focus,
.tns-input textarea:active {
    outline: none !important;
    border: none !important;
    background: #2b2b35 !important;
    color: #dde3f0 !important;
    box-shadow: 0 0 0 1px #3a7bd5 !important;
}
.tns-input textarea::placeholder { color: #5a6a8a; }

.tns-send {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: linear-gradient(135deg, #3a7bd5, #2a5cae);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    transition: transform .12s;
    font-size: 16px;
    line-height: 1;
}
.tns-send:hover { transform: scale(1.08); }
.tns-send:focus { box-shadow: none !important; }
.tns-send:disabled { opacity: .5; transform: none; cursor: default; }

/* --- Эмодзи-панель --- */
.tns-emoji {
    position: absolute;
    left: 0; right: 0; bottom: 58px;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    padding: 10px;
    background: #1e1e24;
    border-top: 1px solid #253050;
    max-height: 190px;
    overflow-y: auto;
    z-index: 5;
}
.tns-emoji button {
    background: none;
    border: none;
    font-size: 20px;
    padding: 5px;
    cursor: pointer;
    border-radius: 8px;
    font-family: 'Segoe UI Emoji', 'Apple Color Emoji', 'Noto Color Emoji', sans-serif;
}
.tns-emoji button:hover { background: #2b2b35 !important; }

/* --- Мобильная адаптация --- */
@media (max-width: 480px) {
    #tns-panel {
        position: fixed;
        left: 0; right: 0; bottom: 0; top: 0;
        width: auto;
        height: auto;
        max-height: none;
        border-radius: 0;
        border: none;
    }
    #tns-btn { position: fixed; right: 16px; bottom: 16px; }
}

/* --- Позиция слева (настройка виджета) --- */
#tns-root.tns-pos-left { left: 20px; right: auto; }
#tns-root.tns-pos-left #tns-panel { left: 0; right: auto; }
#tns-root.tns-pos-left .tns-badge { left: -2px; right: auto; }
@media (max-width: 520px) {
    #tns-root.tns-pos-left #tns-btn { left: 16px; right: auto; }
}

/* --- Attention Effect: периодический bounce кнопки --- */
@keyframes tns-bounce {
    0%, 72%, 100% { transform: translateY(0); }
    76%  { transform: translateY(-8px); }
    80%  { transform: translateY(0); }
    84%  { transform: translateY(-5px); }
    88%  { transform: translateY(0); }
    92%  { transform: translateY(-2px); }
    96%  { transform: translateY(0); }
}
#tns-btn { animation: tns-bounce 6s ease-in-out infinite; }
#tns-btn:hover { animation-play-state: paused; }
@media (prefers-reduced-motion: reduce) {
    #tns-btn { animation: none; }
}

/* --- Разделитель дня (Telegram-style) --- */
.tns-day {
    align-self: center;
    margin: 10px 0 6px;
    padding: 3px 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.12);
    color: #9fb2d8;
    font-size: 12px;
    max-width: fit-content;
}
