<?php   ?>
<style>
#tpsup, #tpsup * { box-sizing: border-box; }
#tpsup-bubble {
    position: fixed; right: 22px; bottom: 22px; z-index: 99980;
    display: inline-flex; align-items: center; gap: 9px;
    padding: 12px 18px 12px 15px; border: none; cursor: pointer;
    background: #2563eb; color: #fff; border-radius: 999px;
    font: 600 14px/1 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif;
    box-shadow: 0 10px 25px -5px rgba(37,99,235,.5), 0 4px 10px rgba(0,0,0,.12);
    transition: transform .15s ease, box-shadow .15s ease, background .15s ease;
}
#tpsup-bubble:hover { background: #1d4ed8; transform: translateY(-2px); box-shadow: 0 14px 30px -6px rgba(37,99,235,.55); }
#tpsup-bubble i { font-size: 16px; }
#tpsup-bubble .tpsup-dot { position: absolute; top: -3px; right: -3px; min-width: 19px; height: 19px; padding: 0 5px; background: #ef4444; color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; display: none; align-items: center; justify-content: center; border: 2px solid #fff; }
#tpsup-panel {
    position: fixed; right: 22px; bottom: 22px; z-index: 99981;
    width: 390px; max-width: calc(100vw - 28px);
    height: 640px; max-height: calc(100vh - 100px);
    background: #fff; border-radius: 18px; overflow: hidden;
    display: none; flex-direction: column;
    box-shadow: 0 24px 60px -12px rgba(15,23,42,.32), 0 0 0 1px rgba(15,23,42,.05);
    font: 14px/1.5 -apple-system, "Segoe UI", Roboto, system-ui, sans-serif; color: #0f172a;
}
#tpsup.open #tpsup-panel { display: flex; animation: tpsup-in .18s ease; }
#tpsup.open #tpsup-bubble { display: none; }
@keyframes tpsup-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.tpsup-head { background: linear-gradient(135deg,#2563eb,#1d4ed8); color: #fff; padding: 16px 16px 15px; display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.tpsup-head .tpsup-back { background: rgba(255,255,255,.15); border: none; color: #fff; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; display: none; align-items: center; justify-content: center; flex-shrink: 0; }
.tpsup-head .tpsup-back:hover { background: rgba(255,255,255,.28); }
.tpsup-head .tpsup-htxt { flex: 1; min-width: 0; }
.tpsup-head h3 { margin: 0; font-size: 15.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpsup-head p { margin: 2px 0 0; font-size: 12px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpsup-head .tpsup-x { background: rgba(255,255,255,.15); border: none; color: #fff; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; flex-shrink: 0; }
.tpsup-head .tpsup-menu { background: rgba(255,255,255,.15); border: none; color: #fff; width: 30px; height: 30px; border-radius: 8px; cursor: pointer; flex-shrink: 0; display: none; align-items: center; justify-content: center; }
.tpsup-head .tpsup-menu:hover { background: rgba(255,255,255,.28); }
.tpsup-menuwrap { position: relative; flex-shrink: 0; }
.tpsup-dd { position: absolute; top: 38px; right: 0; z-index: 5; min-width: 178px; background: #fff; border: 1px solid #e7ecf3; border-radius: 12px; box-shadow: 0 16px 40px -8px rgba(15,23,42,.28); overflow: hidden; display: none; }
.tpsup-dd.open { display: block; animation: tpsup-dd-in .12s ease; }
@keyframes tpsup-dd-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }
.tpsup-dd button { display: flex; align-items: center; gap: 9px; width: 100%; padding: 10px 13px; border: none; background: #fff; color: #334155; font: inherit; font-size: 13px; text-align: left; cursor: pointer; }
.tpsup-dd button:hover { background: #f4f7fb; }
.tpsup-dd button i { width: 15px; text-align: center; color: #64748b; }
.tpsup-dd .tpsup-dd-danger, .tpsup-dd .tpsup-dd-danger i { color: #dc2626; }
.tpsup-dd hr { margin: 0; border: none; border-top: 1px solid #eef2f7; }
.tpsup-ddconfirm { padding: 12px 13px; }
.tpsup-ddconfirm p { margin: 0 0 10px; font-size: 12.5px; color: #334155; line-height: 1.45; }
.tpsup-ddconfirm .row { display: flex; gap: 7px; }
.tpsup-ddconfirm .row button { flex: 1; padding: 8px 10px; border-radius: 8px; font-size: 12.5px; font-weight: 600; cursor: pointer; border: 1px solid transparent; width: auto; }
.tpsup-ddconfirm .cancel { background: #eef2f7; color: #334155; }
.tpsup-ddconfirm .cancel:hover { background: #e2e8f0; }
.tpsup-ddconfirm .del { background: #dc2626; color: #fff; }
.tpsup-ddconfirm .del:hover { background: #b91c1c; }
.tpsup-ddconfirm .del:disabled { opacity: .6; cursor: default; }
.tpsup-head .tpsup-x:hover { background: rgba(255,255,255,.28); }
.tpsup-body { flex: 1; overflow-y: auto; background: #f8fafc; }
.tpsup-foot { flex-shrink: 0; border-top: 1px solid #e7ecf3; background: #fff; padding: 12px; }
.tpsup-btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; width: 100%; padding: 11px 14px; border: none; border-radius: 10px; background: #2563eb; color: #fff; font-size: 14px; font-weight: 600; cursor: pointer; transition: background .15s; }
.tpsup-btn:hover { background: #1d4ed8; }
.tpsup-btn:disabled { opacity: .6; cursor: default; }
.tpsup-btn-ghost { background: #eef2f7; color: #334155; }
.tpsup-btn-ghost:hover { background: #e2e8f0; }
.tpsup-list { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.tpsup-card { background: #fff; border: 1px solid #e7ecf3; border-radius: 12px; padding: 12px 13px; cursor: pointer; transition: border-color .15s, box-shadow .15s; }
.tpsup-card:hover { border-color: #bfd3f3; box-shadow: 0 4px 14px -6px rgba(37,99,235,.25); }
.tpsup-card h4 { margin: 0 0 4px; font-size: 13.5px; font-weight: 600; color: #0f172a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tpsup-card .tpsup-meta { font-size: 11.5px; color: #94a3b8; display: flex; align-items: center; gap: 6px; }
.tpsup-chip { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; }
.tpsup-chip-blue { background: #eff6ff; color: #2563eb; }
.tpsup-chip-amber { background: #fffbeb; color: #b45309; }
.tpsup-chip-green { background: #ecfdf5; color: #059669; }
.tpsup-chip-gray { background: #f1f5f9; color: #64748b; }
.tpsup-empty { text-align: center; padding: 44px 24px; color: #94a3b8; }
.tpsup-empty i { font-size: 30px; margin-bottom: 12px; color: #cbd5e1; }
.tpsup-empty p { margin: 0; font-size: 13px; }
.tpsup-form { padding: 14px; display: flex; flex-direction: column; gap: 13px; }
.tpsup-field label { display: block; font-size: 12.5px; font-weight: 600; color: #334155; margin-bottom: 5px; }
.tpsup-field .req { color: #ef4444; }
.tpsup-input, .tpsup-textarea, .tpsup-select { width: 100%; padding: 9px 11px; border: 1px solid #d8e0ea; border-radius: 9px; font: inherit; font-size: 13.5px; color: #0f172a; background: #fff; }
.tpsup-input:focus, .tpsup-textarea:focus, .tpsup-select:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.tpsup-input[readonly] { background: #f1f5f9; color: #64748b; }
.tpsup-textarea { resize: vertical; min-height: 92px; }
.tpsup-row { display: flex; gap: 10px; }
.tpsup-row > * { flex: 1; min-width: 0; }
.tpsup-acc { border: 1px solid #e7ecf3; border-radius: 11px; overflow: hidden; background: #fff; }
.tpsup-acc > summary { list-style: none; cursor: pointer; padding: 11px 13px; font-size: 12.8px; font-weight: 600; color: #334155; display: flex; align-items: center; gap: 8px; }
.tpsup-acc > summary::-webkit-details-marker { display: none; }
.tpsup-acc > summary .chev { margin-left: auto; transition: transform .15s; color: #94a3b8; font-size: 12px; }
.tpsup-acc[open] > summary .chev { transform: rotate(180deg); }
.tpsup-acc-body { padding: 4px 13px 14px; display: flex; flex-direction: column; gap: 11px; }
.tpsup-reqbox { border: 1px solid #fcd9a8; background: #fffdf7; border-radius: 11px; padding: 12px 13px; display: flex; flex-direction: column; gap: 11px; }
.tpsup-reqbox-h { font-size: 12.8px; font-weight: 700; color: #92400e; display: flex; align-items: center; gap: 8px; }
.tpsup-reqbox-h .tpsup-reqtag { margin-left: auto; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: #b45309; background: #fef3c7; padding: 2px 7px; border-radius: 999px; }
.tpsup-note { font-size: 11.5px; color: #64748b; background: #f8fafc; border: 1px solid #e7ecf3; border-radius: 8px; padding: 8px 10px; display: flex; gap: 7px; }
.tpsup-note.warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.tpsup-note i { margin-top: 1px; }
.tpsup-drop { border: 1.5px dashed #cbd5e1; border-radius: 10px; padding: 14px; text-align: center; color: #64748b; font-size: 12.5px; cursor: pointer; background: #fff; }
.tpsup-drop:hover { border-color: #2563eb; color: #2563eb; }
.tpsup-thumbs { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 9px; }
.tpsup-thumb { position: relative; width: 58px; height: 58px; border-radius: 8px; overflow: hidden; border: 1px solid #e2e8f0; }
.tpsup-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tpsup-thumb button { position: absolute; top: -6px; right: -6px; width: 18px; height: 18px; border-radius: 50%; background: #ef4444; color: #fff; border: 2px solid #fff; font-size: 9px; cursor: pointer; line-height: 1; padding: 0; }
.tpsup-thread { padding: 14px; display: flex; flex-direction: column; gap: 12px; }
.tpsup-msg { max-width: 86%; }
.tpsup-msg.staff { align-self: flex-start; }
.tpsup-msg.client { align-self: flex-end; }
.tpsup-bubble2 { padding: 9px 12px; border-radius: 13px; font-size: 13.3px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.tpsup-msg.staff .tpsup-bubble2 { background: #fff; border: 1px solid #e7ecf3; color: #1e293b; border-bottom-left-radius: 4px; }
.tpsup-msg.client .tpsup-bubble2 { background: #2563eb; color: #fff; border-bottom-right-radius: 4px; }
.tpsup-msg .tpsup-msg-h { font-size: 11px; color: #94a3b8; margin-bottom: 3px; display: flex; align-items: center; gap: 5px; }
.tpsup-msg.client .tpsup-msg-h { justify-content: flex-end; }
.tpsup-att { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.tpsup-att a { display: block; width: 64px; height: 50px; border-radius: 7px; overflow: hidden; border: 1px solid rgba(0,0,0,.1); }
.tpsup-att img { width: 100%; height: 100%; object-fit: cover; display: block; }
.tpsup-reply { display: flex; gap: 8px; align-items: flex-end; }
.tpsup-reply textarea { flex: 1; min-height: 42px; max-height: 120px; resize: none; }
.tpsup-icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 1px solid #d8e0ea; background: #fff; color: #475569; cursor: pointer; flex-shrink: 0; }
.tpsup-icon-btn:hover { background: #f1f5f9; }
.tpsup-send { width: 40px; height: 40px; border-radius: 10px; border: none; background: #2563eb; color: #fff; cursor: pointer; flex-shrink: 0; }
.tpsup-send:hover { background: #1d4ed8; }
.tpsup-spin { display: inline-block; animation: tpsup-rot 1s linear infinite; }
@keyframes tpsup-rot { to { transform: rotate(360deg); } }
.tpsup-connect { padding: 30px 22px; text-align: center; }
.tpsup-connect .tpsup-cmark { width: 64px; height: 64px; margin: 6px auto 16px; border-radius: 18px; background: linear-gradient(135deg,#2563eb,#1d4ed8); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 26px; box-shadow: 0 12px 24px -8px rgba(37,99,235,.6); }
.tpsup-connect h4 { margin: 0 0 8px; font-size: 17px; font-weight: 700; color: #0f172a; }
.tpsup-connect p { margin: 0 auto 18px; font-size: 13px; color: #64748b; max-width: 280px; }
.tpsup-connect .tpsup-manual { margin-top: 14px; }
.tpsup-connect .tpsup-manual summary { cursor: pointer; font-size: 12px; color: #2563eb; list-style: none; }
.tpsup-connect .tpsup-manual summary::-webkit-details-marker { display: none; }
.tpsup-connect .tpsup-manual .tpsup-field { text-align: left; margin-top: 10px; }
 
.tpsup-card.tpsup-unseen { border-color: #93b8f0; box-shadow: inset 3px 0 0 #2563eb, 0 4px 14px -8px rgba(37,99,235,.35); }
.tpsup-card.tpsup-unseen h4 { font-weight: 700; }
.tpsup-card.tpsup-unseen h4::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #2563eb; margin-right: 6px; }
#tpsup-bubble.tpsup-alert { animation: tpsup-ring 1.8s ease-in-out infinite; }
@keyframes tpsup-ring {
    0%, 100% { box-shadow: 0 10px 25px -5px rgba(37,99,235,.5), 0 4px 10px rgba(0,0,0,.12), 0 0 0 0 rgba(239,68,68,.55); }
    50% { box-shadow: 0 10px 25px -5px rgba(37,99,235,.5), 0 4px 10px rgba(0,0,0,.12), 0 0 0 10px rgba(239,68,68,0); }
}
 
#tpsidebar-chat { position: relative; background: #2563eb; box-shadow: 0 2px 8px -2px rgba(37,99,235,.55); }
#tpsidebar-chat:hover { background: #1d4ed8; }
#tpsidebar-chat .tpsidebar-chat-chip { display: none; position: absolute; top: -5px; right: -5px; min-width: 17px; height: 17px; padding: 0 4px; align-items: center; justify-content: center; background: #ef4444; color: #fff; border-radius: 999px; font-size: 10px; font-weight: 800; line-height: 1; border: 2px solid #111827; }
#tpsidebar-chat.tpsup-alert .tpsidebar-chat-chip { display: inline-flex; }
#tpsidebar-chat.tpsup-alert { animation: tpsup-sidebar-ring 1.8s ease-in-out infinite; }
#tpsidebar-chat.tpsup-alert svg { animation: tpsup-bell 1.8s ease-in-out infinite; transform-origin: 50% 50%; }
@keyframes tpsup-sidebar-ring {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,.65); transform: scale(1); }
    50% { box-shadow: 0 0 0 9px rgba(239,68,68,0); transform: scale(1.03); }
}
@keyframes tpsup-bell {
    0%, 60%, 100% { transform: rotate(0); }
    8% { transform: rotate(12deg); } 16% { transform: rotate(-10deg); } 24% { transform: rotate(7deg); } 32% { transform: rotate(-5deg); } 40% { transform: rotate(0); }
}
.tpsup-toast { position: fixed; right: 22px; bottom: 92px; z-index: 99990; background: #0f172a; color: #fff; padding: 10px 15px; border-radius: 10px; font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.25); display: none; max-width: 320px; }
@media (max-width: 480px) {
    #tpsup-panel { right: 8px; left: 8px; bottom: 8px; width: auto; max-height: calc(100vh - 16px); height: auto; }
    #tpsup-bubble { right: 14px; bottom: 14px; }
}
</style>

<div id="tpsup">
    <button id="tpsup-bubble" type="button" aria-label="Open support">
        <i class="fa-solid fa-headset"></i><span>Support</span>
        <span class="tpsup-dot" id="tpsup-dot">0</span>
    </button>
    <div id="tpsup-panel" role="dialog" aria-label="Support">
        <div class="tpsup-head">
            <button class="tpsup-back" id="tpsup-back" type="button" aria-label="Back"><i class="fa-solid fa-arrow-left"></i></button>
            <div class="tpsup-htxt">
                <h3 id="tpsup-title">Support</h3>
                <p id="tpsup-sub">How can we help?</p>
            </div>
            <div class="tpsup-menuwrap">
                <button class="tpsup-menu" id="tpsup-menu" type="button" aria-label="Ticket actions" aria-haspopup="true"><i class="fa-solid fa-ellipsis-vertical"></i></button>
                <div class="tpsup-dd" id="tpsup-dd"></div>
            </div>
            <button class="tpsup-x" id="tpsup-close" type="button" aria-label="Close"><i class="fa-solid fa-xmark"></i></button>
        </div>
        <div class="tpsup-body" id="tpsup-body"></div>
        <div class="tpsup-foot" id="tpsup-foot" style="display:none"></div>
    </div>
</div>
<div class="tpsup-toast" id="tpsup-toast"></div>

<span id="tp-sup-boot" hidden data-csrf="<?= htmlspecialchars(Router::csrfToken(), ENT_QUOTES) ?>"></span>
<script src="<?= AdminAssets::url('support-widget.js') ?>" defer></script>
