/* =========================================================================
   SEBS HR CHATBOT - ISOLATED WIDGET STYLESHEET
   All custom properties, classes, IDs, and keyframes are prefixed with
   "sebs-rag-" and scoped to #sebs-rag-root to prevent collisions with the
   host Rutgers website (static HTML, WordPress, or Drupal).
   ========================================================================= */

#sebs-rag-root {
    --sebs-rag-scarlet: #cc0033;
    --sebs-rag-dark-scarlet: #a30029;
    --sebs-rag-dark-grey: #5f6a72;
    --sebs-rag-chat-bg: #ffffff;
    --sebs-rag-bot-msg-bg: #f0f0f0;
    --sebs-rag-user-msg-bg: #cc0033;
    --sebs-rag-focus-ring: #005fcc;

    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-family: Arial, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    color: #333333;
    text-align: left;
}

#sebs-rag-root,
#sebs-rag-root * {
    box-sizing: border-box;
    font-family: inherit;
}

/* Scoped Focus Outline for Accessibility */
#sebs-rag-root *:focus-visible {
    outline: 3px solid var(--sebs-rag-focus-ring) !important;
    outline-offset: 2px !important;
}

/* Screen Reader Only Utility Class */
.sebs-rag-sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Chat Toggle Button */
.sebs-rag-toggle-btn {
    background-color: var(--sebs-rag-scarlet);
    border: none;
    border-radius: 50%;
    width: 60px;
    height: 60px;
    margin: 0;
    padding: 0;
    box-shadow: 0 4px 12px rgba(204, 0, 51, 0.4);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    transition: transform 0.2s, background-color 0.2s;
}

.sebs-rag-toggle-btn:hover {
    transform: scale(1.05);
    background-color: var(--sebs-rag-dark-scarlet);
}

/* Chat Window */
.sebs-rag-window {
    width: 360px;
    height: 520px;
    max-width: calc(100vw - 32px);
    max-height: calc(100vh - 100px);
    background-color: var(--sebs-rag-chat-bg);
    border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    margin-bottom: 16px;
    transition:
        opacity 0.25s ease,
        transform 0.25s ease,
        visibility 0.25s,
        width 0.4s cubic-bezier(0.25, 1, 0.5, 1),
        height 0.4s cubic-bezier(0.25, 1, 0.5, 1),
        max-width 0.4s cubic-bezier(0.25, 1, 0.5, 1),
        max-height 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    transform-origin: bottom right;
    visibility: visible;
}

.sebs-rag-window.sebs-rag-hidden {
    opacity: 0;
    transform: scale(0.9);
    pointer-events: none;
    visibility: hidden;
}

.sebs-rag-window.sebs-rag-expanded {
    width: 80vw !important;
    height: 85vh !important;
    max-width: 1000px !important;
    max-height: calc(100vh - 120px) !important;
}

/* Header */
.sebs-rag-header {
    background: linear-gradient(135deg, #222222 0%, #111111 100%);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
    color: #ffffff;
    padding: 14px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sebs-rag-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: bold;
    font-size: 16px;
    color: #ffffff;
}

.sebs-rag-header-controls {
    display: flex;
    align-items: center;
    gap: 12px;
}

.sebs-rag-header-btn {
    background: transparent;
    border: 1px solid #777777;
    border-radius: 4px;
    color: #ffffff;
    padding: 4px 8px;
    margin: 0;
    font-size: 13px;
    line-height: 1.2;
    cursor: pointer;
    transition: background-color 0.2s;
}

.sebs-rag-header-btn:hover {
    background-color: #444444;
}

.sebs-rag-icon-btn {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 2px 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.sebs-rag-icon-btn:hover {
    opacity: 0.7;
    transform: scale(1.1);
    background-color: transparent;
}

.sebs-rag-maximize-icon {
    vertical-align: middle;
}

.sebs-rag-status-dot {
    width: 10px;
    height: 10px;
    background-color: #4caf50;
    border-radius: 50%;
    flex-shrink: 0;
}

.sebs-rag-close-btn {
    background: none;
    border: none;
    color: #ffffff;
    font-size: 26px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
    margin: 0;
}

/* Chat Area */
.sebs-rag-chat-box {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    background-color: #fafafa;
}

.sebs-rag-chat-box::-webkit-scrollbar {
    width: 6px;
}

.sebs-rag-chat-box::-webkit-scrollbar-track {
    background: transparent;
}

.sebs-rag-chat-box::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 10px;
}

.sebs-rag-chat-box::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

/* Message Bubbles */
.sebs-rag-message {
    max-width: 88%;
    padding: 12px 16px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.45;
    word-break: break-word;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.sebs-rag-bot-message {
    background-color: var(--sebs-rag-bot-msg-bg);
    color: #111111;
    align-self: flex-start;
    border-bottom-left-radius: 4px;
    border-top-left-radius: 4px;
}

/* Markdown Styles inside Bot Message */
.sebs-rag-bot-message p {
    margin: 0 0 8px 0;
}

.sebs-rag-bot-message p:last-child {
    margin-bottom: 0;
}

.sebs-rag-bot-message ul,
.sebs-rag-bot-message ol {
    padding-left: 22px;
    margin: 8px 0 12px 0;
}

.sebs-rag-bot-message li {
    margin-bottom: 8px;
    line-height: 1.5;
}

.sebs-rag-bot-message li:last-child {
    margin-bottom: 0;
}

.sebs-rag-bot-message ul li::marker,
.sebs-rag-bot-message ol li::marker {
    color: var(--sebs-rag-scarlet);
    font-size: 1.1em;
}

.sebs-rag-bot-message ol li::marker {
    font-weight: 600;
}

.sebs-rag-bot-message ul ul,
.sebs-rag-bot-message ol ol,
.sebs-rag-bot-message ul ol,
.sebs-rag-bot-message ol ul {
    margin-top: 6px;
    margin-bottom: 0;
}

.sebs-rag-bot-message li p {
    margin-bottom: 4px;
    display: inline-block;
}

.sebs-rag-bot-message a {
    color: #0056b3;
    text-decoration: underline;
    font-weight: bold;
}

.sebs-rag-user-message {
    background-color: var(--sebs-rag-user-msg-bg);
    color: #ffffff;
    align-self: flex-end;
    border-bottom-right-radius: 4px;
    border-top-right-radius: 4px;
}

/* Input Area */
.sebs-rag-input-area {
    display: flex;
    padding: 12px;
    margin: 0;
    background: #ffffff;
    border-top: 1px solid #dddddd;
    gap: 8px;
}

.sebs-rag-input {
    flex: 1;
    padding: 10px 14px;
    margin: 0;
    border: 1px solid #bbbbbb;
    border-radius: 20px;
    font-size: 15px;
    color: #222222;
    background-color: #ffffff;
}

.sebs-rag-input:focus {
    border-color: var(--sebs-rag-scarlet);
}

.sebs-rag-send-btn {
    background-color: var(--sebs-rag-scarlet);
    border: none;
    border-radius: 50%;
    width: 42px;
    height: 42px;
    padding: 0;
    margin: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: background-color 0.2s;
}

.sebs-rag-send-btn:hover {
    background-color: var(--sebs-rag-dark-scarlet);
}

.sebs-rag-send-btn:disabled {
    background-color: #cccccc;
    cursor: not-allowed;
}

/* Typing Indicator */
.sebs-rag-typing-indicator {
    display: flex;
    gap: 4px;
    padding: 12px 16px;
    background-color: var(--sebs-rag-bot-msg-bg);
    border-radius: 16px;
    align-self: flex-start;
    width: fit-content;
    margin-bottom: 10px;
}

.sebs-rag-typing-indicator.sebs-rag-hidden {
    display: none;
}

.sebs-rag-typing-indicator span {
    width: 8px;
    height: 8px;
    background-color: #666666;
    border-radius: 50%;
    animation: sebs-rag-bounce 1.4s infinite ease-in-out both;
}

.sebs-rag-typing-indicator span:nth-child(1) {
    animation-delay: -0.32s;
}

.sebs-rag-typing-indicator span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes sebs-rag-bounce {
    0%, 80%, 100% {
        transform: scale(0);
    }
    40% {
        transform: scale(1);
    }
}

/* Feedback Buttons */
.sebs-rag-feedback-container {
    display: flex;
    gap: 8px;
    margin-top: 8px;
    justify-content: flex-end;
}

.sebs-rag-feedback-btn {
    background: #ffffff;
    border: 1px solid #bbbbbb;
    border-radius: 6px;
    padding: 6px 10px;
    margin: 0;
    cursor: pointer;
    font-size: 14px;
    color: #333333;
    transition: all 0.2s;
    min-width: 36px;
    min-height: 36px;
}

.sebs-rag-feedback-btn:hover {
    background-color: #eeeeee;
    border-color: #888888;
}

.sebs-rag-feedback-btn.sebs-rag-active-up {
    background-color: #e8f5e9;
    border-color: #2e7d32;
    color: #2e7d32;
    font-weight: bold;
}

.sebs-rag-feedback-btn.sebs-rag-active-down {
    background-color: #ffebee;
    border-color: #c62828;
    color: #c62828;
    font-weight: bold;
}

.sebs-rag-feedback-btn.sebs-rag-feedback-dimmed {
    opacity: 0.5;
}

/* Quick Starter Chips */
.sebs-rag-quick-chips {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 10px;
    align-items: flex-start;
}

.sebs-rag-quick-chips.sebs-rag-hidden {
    display: none;
}

.sebs-rag-chip {
    background-color: #ffffff;
    border: 1.5px solid var(--sebs-rag-scarlet);
    color: var(--sebs-rag-scarlet);
    padding: 8px 14px;
    margin: 0;
    border-radius: 20px;
    font-size: 13.5px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: left;
    width: 100%;
    line-height: 1.35;
}

.sebs-rag-chip:hover,
.sebs-rag-chip:focus-visible {
    background-color: var(--sebs-rag-scarlet);
    color: #ffffff;
}

/* Collapsible Sources Accordion */
.sebs-rag-sources-accordion {
    margin-top: 12px;
    border-top: 1px solid rgba(0, 0, 0, 0.1);
    padding-top: 8px;
    font-size: 0.85em;
}

.sebs-rag-sources-accordion summary {
    cursor: pointer;
    font-weight: 600;
    color: #cc0033;
    user-select: none;
    outline: none;
    transition: color 0.2s ease;
    display: inline-block;
}

.sebs-rag-sources-accordion summary:hover {
    color: #990022;
}

.sebs-rag-sources-content {
    margin-top: 8px;
    padding: 8px 12px;
    background-color: #f9f9f9;
    border-left: 3px solid #cc0033;
    border-radius: 0 4px 4px 0;
    animation: sebs-rag-slideDown 0.3s ease-out forwards;
}

.sebs-rag-source-item {
    margin-bottom: 4px;
}

.sebs-rag-source-item:last-child {
    margin-bottom: 0;
}

@keyframes sebs-rag-slideDown {
    from {
        opacity: 0;
        transform: translateY(-5px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =======================================================
   RESPONSIVE MEDIA QUERIES (TABLET & MOBILE)
   ======================================================= */

@media (max-width: 768px) {
    .sebs-rag-window.sebs-rag-expanded {
        width: 95vw !important;
        height: 90vh !important;
        max-height: calc(100vh - 120px) !important;
    }
}

@media (max-width: 480px) {
    #sebs-rag-root {
        bottom: env(safe-area-inset-bottom, 16px);
        right: 16px;
    }

    .sebs-rag-window {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100vw !important;
        height: 100vh !important;
        max-width: 100vw !important;
        max-height: 100vh !important;
        margin: 0;
        border-radius: 0;
        z-index: 100000;
    }

    .sebs-rag-input-area {
        padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    }

    #sebs-rag-maximize-btn {
        display: none !important;
    }

    .sebs-rag-window:not(.sebs-rag-hidden) ~ #sebs-rag-toggle-btn {
        display: none;
    }
}