/* =========================================================
   CollegeLive Support - chatbot widget
   Scoped under .cgi-chat-root to avoid theme conflicts.
   ========================================================= */

.cgi-chat-root {
    position: fixed;
    right: 24px;
    bottom: 24px;
    z-index: 2147483000;
    font-family: 'Segoe UI', 'Inter', 'Roboto', Arial, sans-serif;
    color: #0f172a;
    line-height: 1.5;
}

.cgi-chat-root *,
.cgi-chat-root *::before,
.cgi-chat-root *::after {
    box-sizing: border-box;
}

/* ---------- Launcher ---------- */

.cgi-chat-launcher {
    position: relative;
    width: 62px;
    height: 62px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    cursor: pointer;
    color: #fff;
    background: linear-gradient(135deg, #4f46e5 0%, #3730a3 100%);
    box-shadow: 0 14px 30px rgba(79, 70, 229, .35), 0 6px 14px rgba(55, 48, 163, .25);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .2s ease, box-shadow .2s ease;
}

.cgi-chat-launcher:hover {
    transform: translateY(-2px) scale(1.03);
    box-shadow: 0 18px 36px rgba(79, 70, 229, .42), 0 8px 18px rgba(55, 48, 163, .3);
}

.cgi-chat-launcher:focus-visible {
    outline: 3px solid rgba(79, 70, 229, .45);
    outline-offset: 3px;
}

.cgi-chat-launcher::before {
    content: '';
    position: absolute;
    inset: -5px;
    border-radius: 50%;
    border: 2px solid rgba(79, 70, 229, .4);
    animation: cgi-chat-pulse 2.4s ease-out infinite;
}

.cgi-chat-launcher-icon,
.cgi-chat-launcher-icon svg {
    width: 28px;
    height: 28px;
    display: block;
}

.cgi-chat-launcher .icon-close {
    display: none;
}

.cgi-chat-root.is-open .cgi-chat-launcher .icon-chat {
    display: none;
}

.cgi-chat-root.is-open .cgi-chat-launcher .icon-close {
    display: block;
}

@keyframes cgi-chat-pulse {
    0%   { transform: scale(.94); opacity: .8; }
    70%  { transform: scale(1.16); opacity: 0; }
    100% { transform: scale(1.16); opacity: 0; }
}

/* ---------- Panel ---------- */

.cgi-chat-panel {
    position: absolute;
    right: 0;
    bottom: 78px;
    width: 392px;
    height: 620px;
    max-height: calc(100vh - 120px);
    background: #fff;
    border: 1px solid rgba(79, 70, 229, .1);
    border-radius: 20px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 24px 70px rgba(15, 23, 42, .28);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(18px) scale(.97);
    transform-origin: bottom right;
    transition: opacity .22s ease, transform .22s ease, visibility .22s;
}

.cgi-chat-root.is-open .cgi-chat-panel {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: none;
}

/* ---------- Header ---------- */

.cgi-chat-header {
    position: relative;
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 15px 18px;
    color: #fff;
    background: linear-gradient(135deg, #3730a3 0%, #4f46e5 58%, #06b6d4 100%);
}

.cgi-chat-header::after {
    content: '';
    position: absolute;
    top: -30px;
    right: -20px;
    width: 110px;
    height: 110px;
    border-radius: 50%;
    background: rgba(255, 255, 255, .08);
    pointer-events: none;
}

.cgi-chat-header-avatar {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .4px;
    background: rgba(255, 255, 255, .18);
    border: 1.5px solid rgba(255, 255, 255, .55);
}

.cgi-chat-header-text {
    flex: 1 1 auto;
    min-width: 0;
    position: relative;
    z-index: 1;
}

.cgi-chat-header-text h3 {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
    color: #fff;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.cgi-chat-header-text p {
    margin: 3px 0 0;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 11.5px;
    color: rgba(255, 255, 255, .85);
}

.cgi-chat-status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #34d399;
    box-shadow: 0 0 0 3px rgba(52, 211, 153, .22);
}

.cgi-chat-close {
    position: relative;
    z-index: 1;
    flex: 0 0 auto;
    width: 32px;
    height: 32px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    color: #fff;
    cursor: pointer;
    background: rgba(255, 255, 255, .16);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .18s ease;
}

.cgi-chat-close:hover {
    background: rgba(255, 255, 255, .3);
}

.cgi-chat-close svg {
    width: 15px;
    height: 15px;
}

/* ---------- College selector ---------- */

.cgi-chat-collegebar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
}

.cgi-chat-collegebar label {
    font-size: 10.5px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .08em;
    color: #64748b;
    white-space: nowrap;
}

.cgi-chat-collegebar select {
    flex: 1 1 auto;
    min-width: 0;
    padding: 7px 10px;
    border: 1px solid #cbd5e1;
    border-radius: 9px;
    background: #fff;
    color: #0f172a;
    font-family: inherit;
    font-size: 12.5px;
    font-weight: 600;
    outline: none;
    cursor: pointer;
}

.cgi-chat-collegebar select:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}

/* ---------- Messages ---------- */

.cgi-chat-body {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 18px 16px 14px;
    background:
        radial-gradient(circle at 100% 0, rgba(79, 70, 229, .07), transparent 42%),
        #f4f7fb;
    display: flex;
    flex-direction: column;
    gap: 12px;
    scroll-behavior: smooth;
}

.cgi-chat-body::-webkit-scrollbar {
    width: 8px;
}

.cgi-chat-body::-webkit-scrollbar-track {
    background: transparent;
}

.cgi-chat-body::-webkit-scrollbar-thumb {
    background: rgba(79, 70, 229, .18);
    border-radius: 999px;
}

.cgi-chat-msg {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    animation: cgi-chat-in .22s ease both;
}

.cgi-chat-msg.is-user {
    flex-direction: row-reverse;
}

.cgi-chat-avatar {
    flex: 0 0 auto;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 800;
    color: #fff;
    background: linear-gradient(135deg, #4f46e5, #3730a3);
    box-shadow: 0 3px 8px rgba(79, 70, 229, .25);
}

.cgi-chat-msg.is-user .cgi-chat-avatar {
    display: none;
}

.cgi-chat-bubble {
    max-width: 78%;
    padding: 11px 14px;
    border-radius: 16px;
    border-bottom-left-radius: 5px;
    background: #fff;
    color: #1f2937;
    font-size: 13px;
    line-height: 1.55;
    white-space: pre-line;
    word-break: break-word;
    box-shadow: 0 4px 14px rgba(15, 23, 42, .08);
    border: 1px solid rgba(15, 23, 42, .05);
}

.cgi-chat-msg.is-user .cgi-chat-bubble {
    border-radius: 16px;
    border-bottom-right-radius: 5px;
    border-bottom-left-radius: 16px;
    background: linear-gradient(135deg, #4f46e5, #3730a3);
    color: #fff;
    border-color: transparent;
    box-shadow: 0 4px 14px rgba(79, 70, 229, .25);
}

@keyframes cgi-chat-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

/* ---------- Links and suggestions ---------- */

.cgi-chat-links {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-left: 38px;
    margin-top: -2px;
    animation: cgi-chat-in .22s ease both;
}

.cgi-chat-link {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 7px 12px;
    border-radius: 999px;
    background: #eef2ff;
    color: #3730a3 !important;
    border: 1px solid #c7d2fe;
    font-size: 12px;
    font-weight: 700;
    text-decoration: none !important;
    transition: background .18s ease, color .18s ease, border-color .18s ease;
}

.cgi-chat-link::after {
    content: '\203A';
    font-size: 15px;
    line-height: 1;
}

.cgi-chat-link:hover {
    background: #4f46e5;
    border-color: #4f46e5;
    color: #fff !important;
}

.cgi-chat-suggestions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding-left: 38px;
    animation: cgi-chat-in .22s ease both;
}

.cgi-chat-chip {
    padding: 7px 12px;
    border-radius: 999px;
    border: 1px solid rgba(79, 70, 229, .2);
    background: #fff;
    color: #3730a3;
    font-size: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: background .18s ease, color .18s ease, border-color .18s ease;
}

.cgi-chat-chip:hover {
    background: #3730a3;
    border-color: #3730a3;
    color: #fff;
}

/* ---------- Typing indicator ---------- */

.cgi-chat-typing .cgi-chat-bubble {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 14px 16px;
}

.cgi-chat-typing .cgi-chat-bubble span {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #94a3b8;
    animation: cgi-chat-bounce 1.2s infinite ease-in-out;
}

.cgi-chat-typing .cgi-chat-bubble span:nth-child(2) { animation-delay: .15s; }
.cgi-chat-typing .cgi-chat-bubble span:nth-child(3) { animation-delay: .3s; }

@keyframes cgi-chat-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: .55; }
    30%           { transform: translateY(-5px); opacity: 1; }
}

/* ---------- Enquiry form ---------- */

.cgi-chat-enquiry {
    margin-left: 38px;
    padding: 14px;
    background: #fff;
    border: 1px solid rgba(79, 70, 229, .12);
    border-radius: 16px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, .08);
    animation: cgi-chat-in .22s ease both;
}

.cgi-chat-enquiry-title {
    margin: 0 0 4px;
    font-size: 14px;
    font-weight: 800;
    color: #3730a3;
}

.cgi-chat-enquiry-note {
    margin: 0 0 10px;
    font-size: 11.5px;
    color: #6b7280;
}

.cgi-chat-field {
    margin-bottom: 9px;
}

.cgi-chat-field label {
    display: block;
    margin-bottom: 4px;
    font-size: 11px;
    font-weight: 700;
    color: #374151;
}

.cgi-chat-field input,
.cgi-chat-field select,
.cgi-chat-field textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid #d1d5db;
    border-radius: 9px;
    background: #f9fafb;
    color: #0f172a;
    font-family: inherit;
    font-size: 12.5px;
    outline: none;
    transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

.cgi-chat-field textarea {
    resize: vertical;
    min-height: 44px;
}

.cgi-chat-field input:focus,
.cgi-chat-field select:focus,
.cgi-chat-field textarea:focus {
    border-color: #4f46e5;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}

.cgi-chat-enquiry-submit {
    width: 100%;
    padding: 10px 14px;
    border: 0;
    border-radius: 10px;
    background: linear-gradient(135deg, #4f46e5, #3730a3);
    color: #fff;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: opacity .18s ease, transform .18s ease;
}

.cgi-chat-enquiry-submit:hover:not(:disabled) {
    transform: translateY(-1px);
}

.cgi-chat-enquiry-submit:disabled {
    opacity: .65;
    cursor: default;
}

.cgi-chat-form-msg {
    margin-top: 8px;
    font-size: 11.5px;
    line-height: 1.45;
}

.cgi-chat-form-msg.is-error { color: #dc2626; }
.cgi-chat-form-msg.is-success { color: #059669; }

/* ---------- Input bar ---------- */

.cgi-chat-inputbar {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 14px;
    background: #fff;
    border-top: 1px solid rgba(15, 23, 42, .07);
}

.cgi-chat-inputbar input {
    flex: 1 1 auto;
    min-width: 0;
    padding: 11px 16px;
    border: 1px solid #d1d5db;
    border-radius: 999px;
    background: #f9fafb;
    color: #0f172a;
    font-family: inherit;
    font-size: 13px;
    outline: none;
    transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
}

.cgi-chat-inputbar input::placeholder {
    color: #9ca3af;
}

.cgi-chat-inputbar input:focus {
    border-color: #4f46e5;
    background: #fff;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .12);
}

.cgi-chat-inputbar button {
    flex: 0 0 auto;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: linear-gradient(135deg, #4f46e5, #3730a3);
    color: #fff;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform .18s ease, opacity .18s ease;
}

.cgi-chat-inputbar button:hover:not(:disabled) {
    transform: scale(1.05);
}

.cgi-chat-inputbar button:disabled {
    opacity: .55;
    cursor: default;
}

.cgi-chat-inputbar button svg {
    width: 18px;
    height: 18px;
}

/* ---------- Mobile ---------- */

@media (max-width: 520px) {
    .cgi-chat-root {
        right: 16px;
        bottom: 16px;
    }

    .cgi-chat-panel {
        position: fixed;
        inset: 0;
        width: 100%;
        height: 100%;
        max-height: none;
        border: 0;
        border-radius: 0;
    }

    .cgi-chat-root.is-open .cgi-chat-launcher {
        display: none;
    }

    .cgi-chat-header {
        padding-top: max(15px, env(safe-area-inset-top));
    }

    .cgi-chat-inputbar {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }

    .cgi-chat-links,
    .cgi-chat-suggestions {
        padding-left: 0;
    }

    .cgi-chat-enquiry {
        margin-left: 0;
    }

    .cgi-chat-bubble {
        max-width: 84%;
    }
}

@media (prefers-reduced-motion: reduce) {
    .cgi-chat-launcher::before,
    .cgi-chat-msg,
    .cgi-chat-links,
    .cgi-chat-suggestions,
    .cgi-chat-enquiry {
        animation: none;
    }
}
