/* =====================================================================
   ChronoCore: live support chat (floating widget + chat thread)
   Self-contained: works in ANY layout (public site, Admin area, Reports...).
   Loaded by Pages/Shared/_SupportChat.cshtml. Needs only Bootstrap + bootstrap-icons.
   ===================================================================== */

/* Colours used by the chat (scoped, so they never change the rest of an admin page) */
.cc-chat,
.chat-thread {
    --cc-ink: #0b0b0b;
    --cc-muted: #6b7280;
    --cc-border: #e5e7eb;
    --cc-accent: #2563eb;
    --cc-accent-soft: #eff6ff;
    --cc-radius-lg: 20px;
    --cc-shadow-sm: 0 4px 18px rgba(15, 23, 42, .06);
    --cc-gradient: linear-gradient(135deg, #2563eb, #7c3aed);
}
.cc-chat { font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif; line-height: 1.5; text-align: left; }
.cc-chat *, .cc-chat *::before, .cc-chat *::after { box-sizing: border-box; }

/* ---------- Chat thread (ticket pages + widget) ---------- */
.chat-thread {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--cc-border);
    border-radius: var(--cc-radius-lg);
    box-shadow: var(--cc-shadow-sm);
}
.chat-messages {
    flex: 1 1 auto;          /* keeps the fixed height: long chats scroll inside, the box never grows */
    min-height: 0;
    height: 520px;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: .75rem;
    overflow-y: auto;
    background-color: #f8fafc;
    background-image: radial-gradient(rgba(15, 23, 42, .05) 1px, transparent 1px);
    background-size: 18px 18px;
}
.chat-msg { max-width: 78%; }
.chat-msg-mine { align-self: flex-end; text-align: right; }
.chat-msg-theirs { align-self: flex-start; }
.chat-msg-system { align-self: center; max-width: 90%; text-align: center; }
.chat-msg-name { margin-bottom: .2rem; font-size: .75rem; font-weight: 700; color: var(--cc-muted); }
.chat-msg-body {
    display: inline-block;
    padding: .65rem .9rem;
    border-radius: 16px;
    font-size: .94rem;
    line-height: 1.45;
    text-align: left;
    white-space: pre-wrap;
    word-break: break-word;
}
.chat-msg-mine .chat-msg-body { color: #fff; background: var(--cc-gradient); border-bottom-right-radius: 4px; }
.chat-msg-theirs .chat-msg-body { color: var(--cc-ink); background: #fff; border: 1px solid var(--cc-border); border-bottom-left-radius: 4px; }
.chat-msg-system .chat-msg-body {
    padding: .35rem .8rem;
    font-size: .8rem;
    color: #475569;
    background: #eef2f7;
    border-radius: 999px;
}
.chat-msg-time { display: block; margin-top: .2rem; font-size: .7rem; color: #94a3b8; }
.chat-msg-new { animation: chat-pop .25s ease; }
@keyframes chat-pop {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

.chat-typing { display: flex; align-items: center; gap: .25rem; padding: .35rem 1.25rem; font-size: .78rem; color: var(--cc-muted); background: #f8fafc; }
.chat-typing[hidden] { display: none; }
.chat-typing span { width: 6px; height: 6px; border-radius: 50%; background: #94a3b8; animation: chat-dot 1s infinite ease-in-out; }
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s; }
.chat-typing em { margin-left: .4rem; font-style: normal; }
@keyframes chat-dot {
    0%, 80%, 100% { transform: translateY(0); opacity: .5; }
    40% { transform: translateY(-4px); opacity: 1; }
}

.chat-composer {
    display: flex;
    align-items: flex-end;
    gap: .6rem;
    padding: .85rem;
    background: #fff;
    border-top: 1px solid var(--cc-border);
}
.chat-composer textarea {
    flex: 1;
    min-height: 44px;
    max-height: 140px;
    padding: .65rem .9rem;
    resize: none;
    font-size: .94rem;
    background: #f8fafc;
    border: 1.5px solid #e2e8f0;
    border-radius: 14px;
    outline: none;
    transition: border-color .2s ease, box-shadow .2s ease, background-color .2s ease;
}
.chat-composer textarea:focus { background: #fff; border-color: var(--cc-accent); box-shadow: 0 0 0 4px rgba(37, 99, 235, .12); }
.chat-send {
    flex-shrink: 0;
    width: 44px;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 50%;
    color: #fff;
    background: var(--cc-gradient);
    box-shadow: 0 6px 16px rgba(37, 99, 235, .3);
    transition: transform .15s ease;
}
.chat-send:hover { transform: scale(1.06); }
.chat-error { padding: 0 1rem .6rem; }
.chat-closed { padding: .9rem 1.1rem; font-size: .9rem; color: var(--cc-muted); background: #f1f5f9; border-top: 1px solid var(--cc-border); }

/* Support Desk ticket page: fills the screen height, scrolls inside */
.chat-thread[data-mode="agent"] .chat-messages { height: clamp(360px, calc(100vh - 360px), 680px); }
.chat-msg-system .chat-msg-body { white-space: normal; }

/* ---------- Floating chat widget ---------- */
.cc-chat { position: fixed; right: 22px; bottom: 22px; z-index: 1085; }
.cc-chat-launcher {
    position: relative;
    height: 58px;
    padding: 0 1.2rem 0 1.05rem;
    display: inline-flex;
    align-items: center;
    gap: .55rem;
    border: 0;
    border-radius: 999px;
    color: #fff;
    font-weight: 700;
    font-size: .95rem;
    background: var(--cc-gradient);
    box-shadow: 0 12px 28px rgba(37, 99, 235, .4);
    transition: transform .2s ease, box-shadow .2s ease;
}
.cc-chat-launcher:hover { transform: translateY(-3px); box-shadow: 0 16px 34px rgba(37, 99, 235, .5); }
.cc-chat-launcher i { font-size: 1.45rem; }
.cc-chat .cc-icon-close { display: none; }
.cc-chat.is-open .cc-icon-open { display: none; }
.cc-chat.is-open .cc-icon-close { display: inline-block; font-size: 1.2rem; }
.cc-chat-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    border-radius: 999px;
    font-size: .72rem;
    color: #fff;
    background: #dc2626;
}
.cc-chat-badge[hidden] { display: none; }

.cc-chat-panel {
    position: absolute;
    right: 0;
    bottom: 72px;
    width: 370px;
    max-height: min(620px, calc(100vh - 120px));
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--cc-border);
    border-radius: 22px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, .25);
    animation: chat-pop .2s ease;
}
.cc-chat-panel[hidden] { display: none; }

.cc-chat-header {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 1rem 1.1rem;
    color: #fff;
    background: radial-gradient(circle at 90% 0%, rgba(124, 58, 237, .55), transparent 55%), var(--cc-ink);
}
.cc-chat-header strong { display: block; font-size: 1rem; }
.cc-chat-avatar {
    flex-shrink: 0;
    width: 42px;
    height: 42px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 1.2rem;
    background: var(--cc-gradient);
}
.cc-chat-presence { display: flex; align-items: center; gap: .35rem; font-size: .75rem; color: rgba(255, 255, 255, .75); }
.cc-chat-presence .dot { width: 8px; height: 8px; border-radius: 50%; background: #9ca3af; }
.cc-chat-presence.online .dot { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .25); }
.cc-chat-icon-btn {
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 10px;
    color: #fff;
    background: rgba(255, 255, 255, .1);
    transition: background .2s ease;
}
.cc-chat-icon-btn:hover { background: rgba(255, 255, 255, .2); }
.cc-chat-icon-btn.confirm { background: #dc2626; }
.cc-chat-icon-btn[hidden] { display: none; }

.cc-chat-start { display: flex; flex-direction: column; gap: .6rem; padding: 1.1rem; overflow-y: auto; }
.cc-chat-start[hidden] { display: none; }
.cc-chat-start .form-control { padding: .55rem .8rem; background: #f8fafc; border: 1.5px solid #e2e8f0; border-radius: 10px; }
.cc-chat-start .form-control:focus { background: #fff; border-color: var(--cc-accent); box-shadow: 0 0 0 4px rgba(37, 99, 235, .12); }
.cc-chat-intro { margin: 0 0 .25rem; padding: .75rem .9rem; font-size: .88rem; background: var(--cc-accent-soft); border-radius: 14px; }
.cc-chat-loggedin { margin: 0; font-size: .85rem; color: var(--cc-muted); }
.cc-chat-alt { display: flex; justify-content: center; gap: 1.25rem; font-size: .82rem; }
.cc-chat-alt a { color: var(--cc-muted); text-decoration: none; }
.cc-chat-alt a:hover { color: var(--cc-accent); }

.cc-chat-body { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.cc-chat-body[hidden] { display: none; }
.chat-thread-widget { flex: 1; min-height: 0; border: 0; border-radius: 0; box-shadow: none; }
.chat-thread-widget .chat-messages { height: 360px; padding: 1rem; }
.chat-thread-widget .chat-msg { max-width: 85%; }
.cc-chat-footer-link { padding: .45rem; text-align: center; font-size: .75rem; border-top: 1px solid var(--cc-border); }
.cc-chat-footer-link a { color: var(--cc-muted); text-decoration: none; }

/* Start button (own style, so it looks the same in every layout) */
.cc-chat-submit {
    padding: .6rem 1rem;
    font-weight: 700;
    border: 0;
    border-radius: 12px;
    color: #fff;
    background: var(--cc-gradient);
    box-shadow: 0 10px 24px rgba(37, 99, 235, .3);
    transition: transform .2s ease, box-shadow .2s ease;
}
.cc-chat-submit:hover,
.cc-chat-submit:focus { color: #fff; transform: translateY(-2px); box-shadow: 0 16px 30px rgba(37, 99, 235, .38); }
.cc-chat-submit:disabled { opacity: .7; transform: none; }

/* Spam honeypot (hidden from people) */
.cc-chat .hp-field { position: absolute !important; left: -10000px; width: 1px; height: 1px; overflow: hidden; }

/* Keep the widget above admin sidebars, sticky footers and modals' backdrops */
.cc-chat { z-index: 1085; }

@media (max-width: 575.98px) {
    .cc-chat { right: 14px; bottom: 14px; }
    .cc-chat-launcher { width: 56px; height: 56px; padding: 0; justify-content: center; }
    .cc-chat-launcher-label { display: none; }
    .cc-chat-panel { position: fixed; left: 10px; right: 10px; bottom: 80px; width: auto; }
    .chat-messages { height: 420px; }
    .chat-msg { max-width: 90%; }
}

/* =====================================================================
   Agent notifications (Super Admin): bell, pop-ups per chat, unread list
   ===================================================================== */
.cc-alerts {
    --cc-ink: #0b0b0b;
    --cc-muted: #6b7280;
    --cc-border: #e5e7eb;
    --cc-accent: #2563eb;
    --cc-gradient: linear-gradient(135deg, #2563eb, #7c3aed);
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 1090;
    font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
    line-height: 1.45;
    text-align: left;
}
.cc-alerts *, .cc-alerts *::before, .cc-alerts *::after { box-sizing: border-box; }

/* bell */
.cc-bell {
    position: relative;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    border: 0;
    border-radius: 50%;
    font-size: 1.35rem;
    color: #fff;
    background: var(--cc-ink);
    box-shadow: 0 12px 28px rgba(15, 23, 42, .35);
    transition: transform .2s ease;
}
.cc-bell:hover { transform: translateY(-3px); }
.cc-bell.has-unread { background: var(--cc-gradient); animation: cc-bell-ring 2.4s ease-in-out infinite; }
@keyframes cc-bell-ring {
    0%, 86%, 100% { transform: rotate(0); }
    89% { transform: rotate(-12deg); }
    92% { transform: rotate(10deg); }
    95% { transform: rotate(-6deg); }
}
.cc-bell-badge {
    position: absolute;
    top: -3px;
    right: -3px;
    min-width: 22px;
    height: 22px;
    padding: 0 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid #fff;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 700;
    background: #dc2626;
}
.cc-bell-badge[hidden] { display: none; }

/* pop-ups (one per chat, newest on top) */
.cc-toasts {
    position: absolute;
    right: 0;
    bottom: 70px;
    width: 340px;
    display: flex;
    flex-direction: column;
    gap: .6rem;
    pointer-events: none;
}
.cc-toast {
    display: flex;
    gap: .7rem;
    padding: .8rem .85rem;
    cursor: pointer;
    pointer-events: auto;
    background: #fff;
    border: 1px solid var(--cc-border);
    border-left: 4px solid var(--cc-accent);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(15, 23, 42, .2);
    animation: cc-toast-in .25s ease;
}
.cc-toast:hover { border-color: #c7d2fe; border-left-color: var(--cc-accent); }
.cc-toast-new { border-left-color: #16a34a; }
.cc-toast-bump { animation: cc-toast-in .25s ease; }
.cc-toast-out { opacity: 0; transform: translateX(20px); transition: opacity .2s ease, transform .2s ease; }
@keyframes cc-toast-in {
    from { opacity: 0; transform: translateY(10px) scale(.98); }
    to   { opacity: 1; transform: none; }
}
.cc-toast-icon {
    flex-shrink: 0;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    color: #fff;
    background: var(--cc-gradient);
}
.cc-toast-new .cc-toast-icon { background: #16a34a; }
.cc-toast-main { flex: 1; min-width: 0; }
.cc-toast-top { display: flex; align-items: center; gap: .4rem; }
.cc-toast-top strong { overflow: hidden; font-size: .9rem; color: var(--cc-ink); white-space: nowrap; text-overflow: ellipsis; }
.cc-toast-count { flex-shrink: 0; padding: 0 .45rem; font-size: .7rem; font-weight: 700; color: #fff; background: #dc2626; border-radius: 999px; }
.cc-toast-count[hidden] { display: none; }
.cc-toast-text {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin: .1rem 0 .15rem;
    font-size: .86rem;
    color: #374151;
    word-break: break-word;
}
.cc-toast-meta { font-size: .72rem; color: var(--cc-muted); }
.cc-toast-close {
    align-self: flex-start;
    width: 26px;
    height: 26px;
    flex-shrink: 0;
    border: 0;
    border-radius: 8px;
    font-size: .75rem;
    color: var(--cc-muted);
    background: transparent;
}
.cc-toast-close:hover { color: var(--cc-ink); background: #f1f5f9; }

/* bell panel */
.cc-alert-panel {
    position: absolute;
    right: 0;
    bottom: 70px;
    width: 340px;
    overflow: hidden;
    background: #fff;
    border: 1px solid var(--cc-border);
    border-radius: 18px;
    box-shadow: 0 24px 60px rgba(15, 23, 42, .25);
    animation: cc-toast-in .2s ease;
}
.cc-alert-panel[hidden] { display: none; }
.cc-alerts.panel-open .cc-toasts { display: none; }   /* list open: no pop-ups on top of it */
.cc-alert-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: .8rem 1rem;
    color: #fff;
    background: var(--cc-ink);
}
.cc-alert-live { display: flex; align-items: center; gap: .35rem; font-size: .75rem; color: rgba(255, 255, 255, .75); }
.cc-alert-live .dot { width: 8px; height: 8px; border-radius: 50%; background: #f59e0b; }
.cc-alert-live.online .dot { background: #22c55e; box-shadow: 0 0 0 3px rgba(34, 197, 94, .25); }
.cc-alert-list { max-height: 320px; overflow-y: auto; }
.cc-alert-empty { padding: 1.4rem 1rem; text-align: center; font-size: .88rem; color: var(--cc-muted); }
.cc-alert-item {
    display: flex;
    align-items: center;
    gap: .7rem;
    padding: .7rem 1rem;
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid #f1f5f9;
}
.cc-alert-item:hover { color: inherit; background: #f8fafc; }
.cc-alert-item > .bi { font-size: 1.15rem; color: var(--cc-accent); }
.cc-alert-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.cc-alert-item-main strong { font-size: .88rem; color: var(--cc-ink); }
.cc-alert-item-main small { overflow: hidden; font-size: .76rem; color: var(--cc-muted); white-space: nowrap; text-overflow: ellipsis; }
.cc-alert-item-side { display: flex; flex-direction: column; align-items: flex-end; gap: .15rem; }
.cc-alert-unread { min-width: 20px; padding: 0 6px; font-size: .72rem; font-weight: 700; text-align: center; color: #fff; background: #dc2626; border-radius: 999px; }
.cc-alert-item-side time { font-size: .7rem; color: var(--cc-muted); white-space: nowrap; }
.cc-alert-settings {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .35rem .9rem;
    padding: .65rem 1rem;
    font-size: .8rem;
    background: #f8fafc;
    border-top: 1px solid var(--cc-border);
}
.cc-switch { display: inline-flex; align-items: center; gap: .35rem; margin: 0; cursor: pointer; }
.cc-switch input { width: 16px; height: 16px; accent-color: var(--cc-accent); }
.cc-alert-link { padding: 0; border: 0; font-size: .8rem; color: var(--cc-accent); background: none; }
.cc-alert-link:disabled { color: var(--cc-muted); cursor: default; }
.cc-alert-link[hidden] { display: none; }
.cc-alert-desk {
    display: block;
    padding: .7rem 1rem;
    text-align: center;
    font-size: .85rem;
    font-weight: 700;
    color: var(--cc-accent);
    text-decoration: none;
    border-top: 1px solid var(--cc-border);
}
.cc-alert-desk:hover { background: #eff6ff; }

@media (max-width: 575.98px) {
    .cc-alerts { right: 14px; bottom: 14px; }
    .cc-toasts, .cc-alert-panel { position: fixed; left: 10px; right: 10px; bottom: 80px; width: auto; }
}

/* =====================================================================
   Busy status, quick answers, ended / assigned pop-ups
   ===================================================================== */
.cc-chat-presence.busy .dot { background: #f59e0b; box-shadow: 0 0 0 3px rgba(245, 158, 11, .25); }
.cc-chat [hidden] { display: none !important; }

.cc-faq { display: flex; flex-direction: column; gap: .4rem; }
.cc-faq-title { font-size: .75rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; color: var(--cc-muted); }
.cc-faq-list { display: flex; flex-wrap: wrap; gap: .35rem; }
.cc-faq-q {
    padding: .35rem .7rem;
    font-size: .8rem;
    text-align: left;
    color: var(--cc-accent);
    background: #fff;
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    transition: background .15s ease;
}
.cc-faq-q:hover { background: var(--cc-accent-soft); }
.cc-faq-answer { display: flex; flex-direction: column; gap: .5rem; }
.cc-faq-q-bubble {
    align-self: flex-end;
    max-width: 85%;
    padding: .55rem .8rem;
    font-size: .88rem;
    color: #fff;
    background: var(--cc-gradient);
    border-radius: 14px 14px 4px 14px;
}
.cc-faq-a-bubble {
    align-self: flex-start;
    max-width: 92%;
    padding: .6rem .85rem;
    font-size: .88rem;
    white-space: pre-wrap;
    color: var(--cc-ink);
    background: #f1f5f9;
    border-radius: 14px 14px 14px 4px;
}
.cc-faq-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; margin-top: .25rem; }
.cc-faq-link { padding: 0; border: 0; font-size: .8rem; color: var(--cc-muted); background: none; }
.cc-faq-link:hover { color: var(--cc-accent); }
.cc-faq-actions .cc-chat-submit { padding: .4rem .8rem; font-size: .82rem; }

.cc-toast-ended { border-left-color: #9ca3af; }
.cc-toast-ended .cc-toast-icon { background: #9ca3af; }
.cc-toast-assigned { border-left-color: #7c3aed; }
.cc-toast-assigned .cc-toast-icon { background: #7c3aed; }

.cc-alert-busy {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: .35rem .7rem;
    padding: .65rem 1rem;
    font-size: .82rem;
    border-top: 1px solid var(--cc-border);
}
.cc-alert-busy small { flex-basis: 100%; font-size: .72rem; color: var(--cc-muted); }
.cc-alert-select { padding: .15rem .4rem; font-size: .8rem; border: 1px solid var(--cc-border); border-radius: 8px; }
.cc-alerts.is-busy .cc-bell::after {
    content: "";
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 14px;
    height: 14px;
    background: #f59e0b;
    border: 2px solid #fff;
    border-radius: 50%;
}
.cc-alerts.is-busy .cc-alert-busy { background: #fffbeb; }
