/* ============================================================
   Chat Page — Notification Bell & Dropdown
   Zero hardcoded colors — all values from CSS custom properties
   defined in frontend/css/main-chat.css (light + dark-theme).
   ============================================================ */

/* ---------------------------------- Outer container (icon + label) ---------------------------------- */
/* Matches the .header-action-container pattern used by Dark Mode / New Chat */
.chat-notif-container {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* ---------------------------------- Bell wrapper (button + dropdown anchor) ---------------------------------- */
.chat-notif-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

/* Mirrors .new-session-button / .theme-toggle sizing so the bell matches Dark Mode & New Chat */
.chat-notif-bell-btn {
    position: relative;
    background: none;
    border: none;
    cursor: pointer;
    /* Match .new-session-button / .theme-toggle */
    font-size: 18px;
    padding: 5px;
    color: var(--icon-color);
    /* display: flex; */
    align-items: center;
    justify-content: center;
    transition: color 0.2s;
}

.chat-notif-bell-btn:hover {
    color: var(--text-color);
}

/* Mark-as-read flash animation */
@keyframes chat-notif-mark-read {
    0%   { background: color-mix(in srgb, var(--accent-color) 20%, transparent); }
    100% { background: transparent; }
}

.chat-notif-dropdown .notif-item--just-read {
    animation: chat-notif-mark-read 0.8s ease-out forwards;
}

/* ---------------------------------- Detail Modal (full notification view) ---------------------------------- */
.notif-detail-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    animation: notif-detail-overlay-in 0.15s ease-out;
}

@keyframes notif-detail-overlay-in {
    from { opacity: 0; }
    to   { opacity: 1; }
}

.notif-detail-modal {
    background: var(--header-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    width: 880px;
    max-width: 92vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 40px rgba(0, 0, 0, 0.25);
    animation: notif-detail-modal-in 0.18s ease-out;
}

@keyframes notif-detail-modal-in {
    from { transform: translateY(-14px); opacity: 0; }
    to   { transform: translateY(0);     opacity: 1; }
}

.notif-detail-modal__header {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 18px 18px 14px;
    border-bottom: 1px solid var(--border-color);
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
}

.notif-detail-modal__icon {
    font-size: 22px;
    flex-shrink: 0;
    line-height: 1;
    margin-top: 1px;
}

.notif-detail-modal__title {
    flex: 1;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-color);
    line-height: 1.4;
}

.notif-detail-modal__close {
    background: none;
    border: none;
    font-size: 18px;
    color: var(--icon-color);
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
    flex-shrink: 0;
    transition: color 0.15s;
}

.notif-detail-modal__close:hover { color: var(--text-color); }

.notif-detail-modal__body {
    padding: 30px;
    font-size: 14px;
    color: var(--text-color);
    line-height: 1.6;
    overflow-y: auto;
    word-break: break-word;
    flex: 1;
}

/* Markdown-rendered content */
.notif-detail-modal__body--markdown h1,
.notif-detail-modal__body--markdown h2,
.notif-detail-modal__body--markdown h3 {
    margin: 8px 0 4px;
    font-size: 15px;
    font-weight: 700;
    color: var(--text-color);
}

.notif-detail-modal__body--markdown p {
    margin: 0 0 8px;
}

.notif-detail-modal__body--markdown ul,
.notif-detail-modal__body--markdown ol {
    padding-left: 20px;
    margin: 4px 0 8px;
}

.notif-detail-modal__body--markdown strong { font-weight: 700; }
.notif-detail-modal__body--markdown em     { font-style: italic; }

.notif-detail-modal__section {
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--border-color);
}

.notif-detail-modal__section-title {
    margin: 0 0 12px;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--icon-color);
}

.notif-detail-modal__kv {
    display: grid;
    grid-template-columns: minmax(140px, 180px) minmax(0, 1fr);
    gap: 8px 14px;
    margin: 0;
}

.notif-detail-modal__kv dt {
    margin: 0;
    font-weight: 600;
    color: var(--text-color);
}

.notif-detail-modal__kv dd {
    margin: 0;
    color: var(--text-color);
    opacity: 0.88;
}

.notif-detail-modal__bullets {
    margin: 0;
    padding-left: 18px;
}

.notif-detail-modal__table-wrap {
    overflow-x: auto;
}

.notif-detail-modal__table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.notif-detail-modal__table th,
.notif-detail-modal__table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border-color);
    text-align: left;
    vertical-align: top;
}

.notif-detail-modal__table th {
    font-weight: 700;
    color: var(--text-color);
    background: color-mix(in srgb, var(--header-bg) 92%, var(--border-color) 8%);
}

.notif-detail-modal__footer {
    padding: 10px 18px 14px;
    border-top: 1px solid var(--border-color);
    font-size: 12px;
    color: var(--icon-color);
    opacity: 0.75;
}

/* Subtle ring animation when there are unread items */
.chat-notif-bell-btn:has(.chat-notif-badge:not(.notif-badge--hidden)) i {
    animation: chat-notif-bell-ring 3s ease-in-out infinite;
}

@keyframes chat-notif-bell-ring {
    0%, 100% { transform: rotate(0deg); }
    8%        { transform: rotate(-18deg); }
    16%       { transform: rotate(18deg); }
    24%       { transform: rotate(-12deg); }
    32%       { transform: rotate(12deg); }
    40%       { transform: rotate(0deg); }
}

/* Badge — positioned cleanly outside the circular button area */
.chat-notif-badge {
    position: absolute;
    top: -5px;
    right: -10px;
    background: #e74c3c;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    line-height: 1;
    /* White border makes it pop against any background */
    border: 2px solid var(--header-bg);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
}

.chat-notif-badge.notif-badge--hidden {
    display: none;
}

/* ---------------------------------- Dropdown ---------------------------------- */
.chat-notif-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: -130px;;
    width: 450px;
    max-height: 90vh;
    overflow-y: auto;
    background: var(--header-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    box-shadow: 0 4px 20px var(--shadow-color);
    z-index: 900;
    /* Prevent inherited text-align: center from header containers */
    text-align: left;
}

.chat-notif-dropdown.notif-dropdown--visible {
    display: block;
}

/* Header row inside dropdown */
.chat-notif-dropdown .notif-dropdown__header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 11px 13px 8px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--header-bg);
    z-index: 1;
}

.chat-notif-dropdown .notif-dropdown__header-main {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.chat-notif-dropdown .notif-dropdown__title {
    font-weight: 600;
    font-size: 13px;
    color: var(--text-color);
}

.chat-notif-dropdown .notif-dropdown__toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
}

.chat-notif-dropdown .notif-dropdown__toggle input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.chat-notif-dropdown .notif-dropdown__toggle-ui {
    width: 30px;
    height: 17px;
    border-radius: 999px;
    background: color-mix(in srgb, var(--icon-color) 26%, transparent);
    position: relative;
    transition: background 0.18s ease;
}

.chat-notif-dropdown .notif-dropdown__toggle-ui::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 13px;
    height: 13px;
    border-radius: 50%;
    background: var(--header-bg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
    transition: transform 0.18s ease;
}

.chat-notif-dropdown .notif-dropdown__toggle input:checked + .notif-dropdown__toggle-ui {
    background: color-mix(in srgb, var(--accent-color) 78%, white 22%);
}

.chat-notif-dropdown .notif-dropdown__toggle input:checked + .notif-dropdown__toggle-ui::after {
    transform: translateX(13px);
}

.chat-notif-dropdown .notif-dropdown__toggle-label {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--icon-color);
}

.chat-notif-dropdown .notif-dropdown__mark-all {
    background: none;
    border: none;
    font-size: 11px;
    color: var(--accent-color);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: background 0.1s;
}

.chat-notif-dropdown .notif-dropdown__mark-all:hover {
    background: color-mix(in srgb, var(--accent-color) 15%, transparent);
}

.chat-notif-dropdown .notif-dropdown__loading,
.chat-notif-dropdown .notif-dropdown__empty {
    padding: 24px 14px;
    text-align: center;
    color: var(--icon-color);
    font-size: 13px;
}

/* ---------------------------------- Notification items ---------------------------------- */
.chat-notif-dropdown .notif-item {
    display: flex;
    gap: 10px;
    padding: 10px 13px;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.16s ease;
}

.chat-notif-dropdown .notif-item:last-child {
    border-bottom: none;
}

.chat-notif-dropdown .notif-item:hover {
    background: var(--surface-hover-bg);
}

/* Unread items — accent tint that works in both light and dark */
.chat-notif-dropdown .notif-item--unread {
    background: color-mix(in srgb, var(--accent-color) 12%, transparent);
}

.chat-notif-dropdown .notif-item--unread:hover {
    background: color-mix(in srgb, var(--accent-color) 20%, transparent);
}

/* Priority left-border */
.chat-notif-dropdown .notif-item--critical {
    border-left: 3px solid #e74c3c;
}

.chat-notif-dropdown .notif-item--warning {
    border-left: 3px solid #f39c12;
}

/* Item layout */
.chat-notif-dropdown .notif-item__icon {
    font-size: 18px;
    flex-shrink: 0;
    line-height: 1.5;
}

.chat-notif-dropdown .notif-item__content {
    flex: 1;
    min-width: 0;
}

/* Title row — title on the left, time-ago on the right, same line */
.chat-notif-dropdown .notif-item__title-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 6px;
}

.chat-notif-dropdown .notif-item__title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-color);
    min-width: 0;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-notif-dropdown .notif-item__time {
    font-size: 11px;
    color: var(--icon-color);
    opacity: 0.75;
    flex-shrink: 0;
    white-space: nowrap;
}

.chat-notif-dropdown .notif-item__body {
    font-size: 12px;
    color: var(--icon-color);
    margin-top: 2px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

@keyframes chat-notif-dismiss {
    0% {
        opacity: 1;
        transform: translateX(0);
        max-height: 96px;
        margin-bottom: 0;
        padding-top: 10px;
        padding-bottom: 10px;
        border-bottom-width: 1px;
    }
    55% {
        opacity: 0.55;
        transform: translateX(34px);
    }
    100% {
        opacity: 0;
        transform: translateX(52px);
        max-height: 0;
        margin-bottom: 0;
        padding-top: 0;
        padding-bottom: 0;
        border-bottom-width: 0;
    }
}

.chat-notif-dropdown .notif-item--dismissing {
    pointer-events: none;
    overflow: hidden;
    will-change: transform, opacity, max-height, padding;
    animation: chat-notif-dismiss 0.66s cubic-bezier(0.22, 0.7, 0.2, 1) forwards;
}
