/* ============================================================
   SINOCLOUD.IT - TELEGRAM CHAT WIDGET (PREMIUM REDESIGN)
   ============================================================ */

/* ── FAB BUTTON ─────────────────────────────────────────── */
.telegram-widget-button {
    position: fixed;
    bottom: 28px;
    right: 28px;
    z-index: 9990;
    width: 62px;
    height: 62px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0088cc 0%, #00b4d8 60%, #29d9f5 100%);
    box-shadow:
        0 4px 20px rgba(0, 136, 204, 0.55),
        0 1px 4px rgba(0, 0, 0, 0.2);
    transition: transform 0.25s cubic-bezier(0.34,1.56,0.64,1),
                box-shadow 0.25s ease;
    color: #fff;
    font-size: 26px;
}
.telegram-widget-button::before {
    content: '';
    position: absolute;
    inset: -3px;
    border-radius: 50%;
    background: transparent;
    border: 2px solid rgba(0,180,216,0.35);
    animation: tg-ring-pulse 2.4s ease-in-out infinite;
    pointer-events: none;
}
.telegram-widget-button:hover {
    transform: scale(1.12) translateY(-2px);
    box-shadow:
        0 8px 32px rgba(0, 136, 204, 0.7),
        0 2px 8px rgba(0,0,0,0.2);
}
.telegram-widget-button:active {
    transform: scale(0.95);
}
@keyframes tg-ring-pulse {
    0%,100%  { transform: scale(1);    opacity: 0.5; }
    50%      { transform: scale(1.25); opacity: 0; }
}

/* ── OVERLAY ─────────────────────────────────────────────── */
.telegram-chat-overlay {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 9995;
    padding: 0;
}
.telegram-chat-overlay.active {
    display: block;
    animation: tg-overlay-in 0.25s ease;
}
@keyframes tg-overlay-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}
/* backdrop semi-trasparente */
.telegram-chat-overlay::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

/* ── MODAL PANEL ─────────────────────────────────────────── */
.telegram-chat-modal {
    position: absolute;
    bottom: 24px;
    right: 24px;
    width: min(420px, calc(100vw - 48px));
    height: min(640px, calc(100svh - 48px));
    border-radius: 22px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #0e1929;
    box-shadow:
        0 24px 80px rgba(0,0,0,0.6),
        0 0 0 1px rgba(0,180,216,0.18);
    animation: tg-panel-in 0.4s cubic-bezier(0.34,1.42,0.64,1);
}
@keyframes tg-panel-in {
    from { transform: translateY(40px) scale(0.93); opacity: 0; }
    to   { transform: translateY(0)    scale(1);    opacity: 1; }
}

/* ── HEADER ──────────────────────────────────────────────── */
.telegram-chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: linear-gradient(135deg, #0b1422 0%, #0f2035 100%);
    border-bottom: 1px solid rgba(0,180,216,0.15);
    flex-shrink: 0;
}
.telegram-chat-header > span {
    font-size: 15px;
    font-weight: 700;
    color: #e8f4ff;
    letter-spacing: -0.01em;
    display: flex;
    align-items: center;
    gap: 8px;
}
.telegram-chat-header > span::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #29f5a0;
    box-shadow: 0 0 6px #29f5a0;
    animation: tg-green-pulse 1.6s ease-in-out infinite;
}
@keyframes tg-green-pulse {
    0%,100% { opacity: 1; }
    50%     { opacity: 0.4; }
}
.telegram-header-buttons {
    display: flex;
    gap: 8px;
    align-items: center;
}
.telegram-header-buttons button {
    border: none;
    cursor: pointer;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    padding: 5px 10px;
    transition: all 0.2s ease;
}
#deleteConversationBtn {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239,68,68,0.25) !important;
}
#deleteConversationBtn:hover {
    background: rgba(239,68,68,0.3);
    color: #fca5a5;
}
.telegram-chat-close {
    background: rgba(255,255,255,0.08);
    color: #94a3b8;
    border: 1px solid rgba(255,255,255,0.1) !important;
    font-size: 18px !important;
    padding: 2px 8px !important;
    line-height: 1.3;
}
.telegram-chat-close:hover {
    background: rgba(255,255,255,0.18);
    color: #e2e8f0;
}

/* ── BODY ────────────────────────────────────────────────── */
.telegram-chat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    padding: 20px;
    gap: 12px;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,180,216,0.25) transparent;
    background: #0e1929;
}
.telegram-chat-body::-webkit-scrollbar { width: 5px; }
.telegram-chat-body::-webkit-scrollbar-thumb { background: rgba(0,180,216,0.25); border-radius: 10px; }

/* ── FORM CONTAINER ──────────────────────────────────────── */
.telegram-form-title {
    font-size: 20px;
    font-weight: 800;
    color: #e8f4ff;
    letter-spacing: -0.02em;
    margin-bottom: 4px;
}
.telegram-form-subtitle {
    font-size: 13px;
    color: #64748b;
    margin-bottom: 16px;
}
.telegram-form-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 10px;
}
.telegram-form-group label {
    font-size: 12px;
    font-weight: 600;
    color: #7dd3f0;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}
.telegram-form-group input,
.telegram-form-group textarea {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(0,180,216,0.2);
    border-radius: 10px;
    padding: 10px 14px;
    color: #e2e8f0;
    font-size: 13.5px;
    transition: border-color 0.2s ease, background 0.2s ease;
    outline: none;
    width: 100%;
    box-sizing: border-box;
    font-family: inherit;
    resize: vertical;
}
.telegram-form-group input::placeholder,
.telegram-form-group textarea::placeholder { color: #334155; }
.telegram-form-group input:focus,
.telegram-form-group textarea:focus {
    border-color: #00b4d8;
    background: rgba(0,180,216,0.07);
}
.telegram-form-group textarea { min-height: 80px; }

.telegram-error-msg {
    font-size: 11px;
    color: #f87171;
    display: none;
    margin-top: 2px;
}

/* ── CONSENT ─────────────────────────────────────────────── */
.telegram-consent-group {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    background: rgba(0,180,216,0.06);
    border: 1px solid rgba(0,180,216,0.15);
    border-radius: 10px;
    padding: 10px 12px;
    margin-top: 4px;
}
.telegram-consent-group input[type="checkbox"] {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
    margin-top: 2px;
    accent-color: #00b4d8;
}
.telegram-consent-group label {
    font-size: 11.5px;
    color: #64748b;
    line-height: 1.5;
    text-transform: none;
    letter-spacing: 0;
}

/* ── PRIMARY BUTTON ──────────────────────────────────────── */
.telegram-btn-start button {
    width: 100%;
    padding: 13px 20px;
    border-radius: 12px;
    border: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    background: linear-gradient(135deg, #0088cc 0%, #00b4d8 100%);
    box-shadow: 0 4px 16px rgba(0,136,204,0.4);
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s;
    letter-spacing: 0.01em;
}
.telegram-btn-start button:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(0,136,204,0.55);
}
.telegram-btn-start button:active { transform: scale(0.97); }
.telegram-btn-start button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* ── STATUS MESSAGE ──────────────────────────────────────── */
#telegramStatusMessage {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 40px 20px;
    text-align: center;
    flex: 1;
}
#telegramStatusMessage.show { display: flex; }

.status-title {
    font-size: 18px;
    font-weight: 800;
    color: #4ade80;
    letter-spacing: -0.01em;
}
.status-subtitle {
    font-size: 13px;
    color: #64748b;
}
.status-spinner {
    width: 36px;
    height: 36px;
    border: 3px solid rgba(0,180,216,0.15);
    border-top-color: #00b4d8;
    border-radius: 50%;
    animation: tg-spin 0.8s linear infinite;
}
@keyframes tg-spin { to { transform: rotate(360deg); } }

/* ── MESSAGES AREA ───────────────────────────────────────── */
.telegram-messages-container {
    display: flex;
    flex-direction: column;
    gap: 14px;
    flex: 1;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,180,216,0.2) transparent;
}
.telegram-messages-container::-webkit-scrollbar { width: 4px; }
.telegram-messages-container::-webkit-scrollbar-thumb { background: rgba(0,180,216,0.2); border-radius: 10px; }

.telegram-message-group {
    display: flex;
    align-items: flex-end;
    gap: 10px;
}
.telegram-message-group.user { flex-direction: row-reverse; }

.telegram-message-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    flex-shrink: 0;
    overflow: hidden;
    background: linear-gradient(135deg, #0088cc, #00d4ff);
    display: flex;
    align-items: center;
    justify-content: center;
}
.avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}
.avatar-initials {
    font-size: 12px;
    font-weight: 700;
    color: #fff;
    letter-spacing: 0;
}

.telegram-message-content-wrapper {
    max-width: 78%;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.telegram-message-name {
    font-size: 10.5px;
    font-weight: 600;
    color: #475569;
    padding: 0 4px;
}
.telegram-message-group.user .telegram-message-name { text-align: right; }

.telegram-message-text {
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 13.5px;
    line-height: 1.5;
    word-break: break-word;
}
.telegram-message-group.assistant .telegram-message-text {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.07);
    color: #cbd5e1;
    border-bottom-left-radius: 4px;
}
.telegram-message-group.user .telegram-message-text {
    background: linear-gradient(135deg, #0088cc, #00b4d8);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 3px 10px rgba(0,136,204,0.3);
}
.telegram-message-attachment {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: #7dd3f0;
    margin-top: 4px;
}

/* Typing dots */
.typing-indicator .telegram-message-text { padding: 12px 16px; }
.typing-dots { display: flex; align-items: center; gap: 4px; }
.typing-dots span:not(.dot) { font-size: 12px; color: #64748b; }
.typing-dots .dot {
    width: 5px;
    height: 5px;
    background: #7dd3f0;
    border-radius: 50%;
    animation: tg-dot-bounce 1.2s ease-in-out infinite;
}
.typing-dots .dot:nth-child(3) { animation-delay: 0.2s; }
.typing-dots .dot:nth-child(4) { animation-delay: 0.4s; }
@keyframes tg-dot-bounce {
    0%,80%,100% { transform: translateY(0); }
    40%         { transform: translateY(-5px); }
}

/* ── RESPONSE CONTAINER ──────────────────────────────────── */
#telegramResponseContainer {
    border-top: 1px solid rgba(255,255,255,0.06);
    padding-top: 14px;
    margin-top: 8px;
}
#telegramResponseContainer .telegram-form-group textarea {
    min-height: 56px;
}

.telegram-btn-group {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 6px;
}
.telegram-btn-upload {
    border: 1px solid rgba(0,180,216,0.25);
    background: rgba(0,180,216,0.08);
    color: #7dd3f0;
    border-radius: 10px;
    padding: 10px 13px;
    font-size: 15px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}
.telegram-btn-upload:hover {
    background: rgba(0,180,216,0.18);
    border-color: rgba(0,180,216,0.5);
    color: #29d9f5;
}

#telegramFilePreview {
    display: flex;
    align-items: center;
    gap: 8px;
    background: rgba(0,180,216,0.08);
    border: 1px solid rgba(0,180,216,0.2);
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 12px;
    color: #7dd3f0;
    margin-top: 8px;
}
#telegramFilePreview #telegramFileName { flex: 1; }
#telegramRemoveFile {
    background: none;
    border: none;
    color: #f87171;
    cursor: pointer;
    padding: 0;
    font-size: 14px;
    line-height: 1;
}

/* ── SUCCESS TOAST ───────────────────────────────────────── */
.success-toast {
    position: fixed;
    bottom: 105px;
    right: 28px;
    z-index: 10050;
    background: linear-gradient(135deg, #0f3443, #12526e);
    color: #7dd3f0;
    border: 1px solid rgba(0,180,216,0.3);
    border-radius: 12px;
    padding: 12px 18px;
    font-size: 13px;
    font-weight: 600;
    box-shadow: 0 8px 24px rgba(0,0,0,0.4);
    animation: tg-toast-in 0.3s cubic-bezier(0.34,1.56,0.64,1);
    display: flex;
    align-items: center;
    gap: 8px;
}
@keyframes tg-toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ── DARK MODE (already dark by default, light mode overrides) ─ */
html.light-init .telegram-chat-modal {
    background: #f0f6ff;
    box-shadow: 0 24px 80px rgba(0,0,0,0.25), 0 0 0 1px rgba(0,136,204,0.12);
}
html.light-init .telegram-chat-header {
    background: linear-gradient(135deg, #e0f0ff, #f4f9ff);
    border-bottom: 1px solid rgba(0,136,204,0.12);
}
html.light-init .telegram-chat-header > span { color: #0f2035; }
html.light-init .telegram-form-title { color: #0f2035; }
html.light-init .telegram-form-subtitle { color: #6b7280; }
html.light-init .telegram-form-group label { color: #0088cc; }
html.light-init .telegram-form-group input,
html.light-init .telegram-form-group textarea {
    background: #fff;
    border-color: rgba(0,136,204,0.25);
    color: #0f172a;
}
html.light-init .telegram-form-group input::placeholder,
html.light-init .telegram-form-group textarea::placeholder { color: #94a3b8; }
html.light-init .telegram-form-group input:focus,
html.light-init .telegram-form-group textarea:focus {
    border-color: #0088cc;
    background: #f0f9ff;
}
html.light-init .telegram-chat-body { background: #f8fbff; }
html.light-init .telegram-message-group.assistant .telegram-message-text {
    background: #fff;
    border-color: #e2edf6;
    color: #0f172a;
}
html.light-init .telegram-consent-group {
    background: rgba(0,136,204,0.04);
    border-color: rgba(0,136,204,0.15);
}
html.light-init .telegram-consent-group label { color: #64748b; }
html.light-init #telegramStatusMessage .status-subtitle { color: #64748b; }
html.light-init .telegram-message-name { color: #94a3b8; }
html.light-init .telegram-chat-close {
    background: rgba(0,0,0,0.05);
    color: #64748b;
}
html.light-init .telegram-chat-close:hover {
    background: rgba(0,0,0,0.1);
    color: #0f172a;
}
html.light-init #deleteConversationBtn {
    background: rgba(239,68,68,0.06);
    color: #dc2626;
}
html.light-init .success-toast {
    background: #e0f2fe;
    color: #0369a1;
    border-color: rgba(3,105,161,0.2);
}
html.light-init .telegram-btn-upload {
    background: rgba(0,136,204,0.06);
    border-color: rgba(0,136,204,0.2);
    color: #0088cc;
}

/* ── MOBILE ──────────────────────────────────────────────── */
@media(max-width: 500px) {
    .telegram-chat-modal {
        bottom: 0;
        right: 0;
        width: 100vw;
        height: 93svh;
        border-radius: 20px 20px 0 0;
    }
    .telegram-widget-button {
        bottom: 80px;  /* sopra la mobile bottom bar */
        right: 20px;
    }
    .success-toast {
        bottom: 90px;
        right: 12px;
        left: 12px;
    }
}

/* ── LIGHTBOX & IMAGE DOWNLOAD ──────────────────────────── */
.tg-img-wrapper {
    position: relative;
    display: inline-block;
    overflow: hidden;
    border-radius: 8px;
}
.tg-img-download {
    position: absolute;
    top: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    text-decoration: none;
    opacity: 0;
    transform: translateY(-10px);
    transition: all 0.2s ease;
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    border: 1px solid rgba(255,255,255,0.2);
    z-index: 10;
}
.tg-img-wrapper:hover .tg-img-download {
    opacity: 1;
    transform: translateY(0);
}
.tg-img-download:hover {
    background: rgba(0, 180, 216, 0.9);
    transform: translateY(0) scale(1.1) !important;
}
html.light-init .tg-img-download {
    background: rgba(255, 255, 255, 0.8);
    color: black;
    border: 1px solid rgba(0,0,0,0.1);
}
html.light-init .tg-img-download:hover {
    background: rgba(0, 136, 204, 0.9);
    color: white;
}