/* ============================================
   NOTIFICATION SYSTEM - APPLE-STYLE POPOVER
   Elegant popover with smooth animations
   ============================================ */

/* ============================================
   SIDEBAR UTILITY SECTION
   ============================================ */

.sidebar-utility {
    margin-top: auto;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color, #e2e8f0);
    overflow: visible !important;
    position: relative;
    z-index: 1051;
}

.sidebar-btn {
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: inherit;
}

.sidebar-btn:hover {
    background-color: var(--bg-card-hover, #f1f5f9);
}

/* Logout button - subtle but distinct */
.logout-link {
    margin-top: 0.25rem;
    border-top: 1px solid var(--border-color, #e2e8f0);
    padding-top: 0.5rem !important;
}

.logout-link .sidebar-icon {
    color: var(--text-muted, #94a3b8);
    transition: color 0.2s ease;
}

.logout-link:hover {
    background-color: rgba(239, 68, 68, 0.08) !important;
}

.logout-link:hover .sidebar-icon,
.logout-link:hover .sidebar-text {
    color: #ef4444 !important;
}

[data-theme="dark"] .logout-link:hover {
    background-color: rgba(239, 68, 68, 0.12) !important;
}

/* Notification badge - server-side rendered with .visible class if count > 0 */
.sidebar-notification-badge {
    position: absolute;
    top: -4px;
    right: -6px;
    min-width: 16px;
    height: 16px;
    padding: 0 4px;
    background: #ef4444;
    color: white;
    font-size: 0.625rem;
    font-weight: 600;
    border-radius: 8px;
    /* Hidden by default - .visible class shows it (rendered server-side or via JS) */
    display: none;
    align-items: center;
    justify-content: center;
    line-height: 1;
    font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', system-ui, sans-serif;
    box-shadow: 0 1px 3px rgba(239, 68, 68, 0.4);
    /* Smooth transition for sidebar collapse */
    transition:
        width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        min-width 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        height 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        padding 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        font-size 0.2s cubic-bezier(0.4, 0, 0.2, 1),
        top 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        right 0.3s cubic-bezier(0.4, 0, 0.2, 1),
        border-radius 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Show badge only when has .visible class (count > 0) */
.sidebar-notification-badge.visible {
    display: flex;
}

/* Collapsed state - small dot without number */
html[data-sidebar-collapsed="true"] .sidebar-notification-badge {
    min-width: 8px;
    width: 8px;
    height: 8px;
    padding: 0;
    font-size: 0;
    color: transparent;
    top: 0px;
    right: 2px;
    border-radius: 50%;
    box-shadow: 0 0 0 2px var(--bg-sidebar, #ffffff);
}

.sidebar-btn .sidebar-icon {
    position: relative;
}

/* Hover effects */
#themeToggle:hover .sidebar-icon {
    color: #f59e0b;
}

[data-theme="dark"] #themeToggle:hover .sidebar-icon {
    color: #fbbf24;
}

#notificationBell:hover .sidebar-icon {
    color: var(--primary-color, #059669);
}

#notificationBell.active {
    background-color: var(--bg-card-hover, #f1f5f9);
}

#notificationBell.active .sidebar-icon {
    color: var(--primary-color, #059669);
}

#notificationBell.has-notifications .sidebar-icon {
    color: var(--text-primary, #1e293b);
}


/* ============================================
   NOTIFICATION POPOVER - APPLE STYLE
   Clean, minimal, connected to button
   ============================================ */

.notification-dropdown {
    position: fixed;
    /* Positioned to appear from the bell button */
    bottom: 90px;
    left: 224px;
    width: 320px;
    max-height: 400px;
    background: var(--bg-card, #ffffff);
    border-radius: 14px;
    box-shadow:
        0 0 0 1px rgba(0, 0, 0, 0.04),
        0 8px 32px rgba(0, 0, 0, 0.12),
        0 24px 60px rgba(0, 0, 0, 0.08);
    z-index: 9999;
    overflow: hidden;
    display: flex;
    flex-direction: column;

    /* Initial hidden state */
    opacity: 0;
    visibility: hidden;
    transform: scale(0.95) translateX(-8px);
    transform-origin: left bottom;

    /* Apple-style spring animation */
    transition:
        opacity 0.2s cubic-bezier(0.4, 0, 0.2, 1),
        transform 0.35s cubic-bezier(0.34, 1.3, 0.64, 1),
        visibility 0.2s;
}

/* Arrow pointer - pointing left toward button */
.notification-dropdown::before {
    content: '';
    position: absolute;
    left: -7px;
    bottom: 16px;
    width: 14px;
    height: 14px;
    background: var(--bg-card, #ffffff);
    border-radius: 2px;
    transform: rotate(45deg);
    box-shadow: -2px 2px 4px rgba(0, 0, 0, 0.04);
}

/* Collapsed sidebar positioning - use html data attribute */
html[data-sidebar-collapsed="true"] .notification-dropdown {
    left: 72px;
}

/* Show state - smooth spring animation */
.notification-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: scale(1) translateX(0);
}

/* Closing animation - smooth fade out */
.notification-dropdown.closing {
    opacity: 0;
    transform: scale(0.96) translateX(-4px);
    transition:
        opacity 0.15s cubic-bezier(0.4, 0, 1, 1),
        transform 0.2s cubic-bezier(0.4, 0, 1, 1),
        visibility 0.2s;
}

/* ============================================
   POPOVER HEADER
   ============================================ */

.notification-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px 10px;
    border-bottom: 1px solid var(--border-color, rgba(0, 0, 0, 0.06));
    background: var(--bg-card, #ffffff);
    position: relative;
    z-index: 2;
}

.notification-header h6 {
    margin: 0;
    font-weight: 600;
    font-size: 0.8125rem;
    color: var(--text-primary, #1e293b);
    letter-spacing: -0.01em;
}

.notification-header button {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--primary-color, #059669);
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 6px;
    transition: all 0.15s ease;
}

.notification-header button:hover {
    background: rgba(5, 150, 105, 0.08);
}

/* ============================================
   NOTIFICATION LIST
   ============================================ */

.notification-list {
    flex: 1;
    overflow-y: auto;
    overscroll-behavior: contain;
}

.notification-list::-webkit-scrollbar {
    width: 4px;
}

.notification-list::-webkit-scrollbar-track {
    background: transparent;
}

.notification-list::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.1);
    border-radius: 2px;
}

/* ============================================
   NOTIFICATION ITEMS
   ============================================ */

.notification-item {
    position: relative;
    display: flex;
    gap: 10px;
    padding: 12px 14px;
    cursor: pointer;
    transition: background-color 0.15s ease;
    text-decoration: none;
    color: inherit;
    background: transparent;
    border-bottom: 1px solid var(--border-color, rgba(0, 0, 0, 0.04));
}

.notification-item:last-child {
    border-bottom: none;
}

.notification-item:hover {
    background-color: var(--bg-card-hover, rgba(0, 0, 0, 0.02));
}

/* Unread indicator */
.notification-item.unread {
    background-color: rgba(5, 150, 105, 0.04);
}

.notification-item.unread::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--primary-color, #059669);
}

/* ============================================
   NOTIFICATION ICON
   ============================================ */

.notification-icon {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 0.75rem;
}

.notification-icon.success {
    background: rgba(5, 150, 105, 0.12);
    color: #059669;
}

.notification-icon.info {
    background: rgba(37, 99, 235, 0.12);
    color: #2563eb;
}

.notification-icon.warning {
    background: rgba(217, 119, 6, 0.12);
    color: #d97706;
}

.notification-icon.error {
    background: rgba(220, 38, 38, 0.12);
    color: #dc2626;
}

/* ============================================
   NOTIFICATION CONTENT
   ============================================ */

.notification-content {
    flex: 1;
    min-width: 0;
}

.notification-title {
    font-weight: 600;
    font-size: 0.75rem;
    color: var(--text-primary, #1e293b);
    line-height: 1.35;
    margin-bottom: 2px;
}

.notification-message {
    font-size: 0.6875rem;
    color: var(--text-secondary, #64748b);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.notification-time {
    font-size: 0.625rem;
    color: var(--text-muted, #94a3b8);
    margin-top: 4px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

/* ============================================
   EMPTY STATE
   ============================================ */

.notification-empty {
    padding: 40px 20px;
    text-align: center;
    color: var(--text-muted, #94a3b8);
}

.notification-empty i {
    font-size: 1.5rem;
    margin-bottom: 8px;
    opacity: 0.4;
}

.notification-empty p {
    margin: 0;
    font-size: 0.8125rem;
    color: var(--text-secondary, #64748b);
}

/* ============================================
   PUSH PERMISSION PROMPT
   ============================================ */

.push-permission-prompt-wrapper {
    position: fixed;
    bottom: 20px;
    left: 240px;
    z-index: 9999;
}

html[data-sidebar-collapsed="true"] .push-permission-prompt-wrapper {
    left: 80px;
}

.push-permission-prompt {
    background: var(--bg-card, #ffffff);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    padding: 14px;
    max-width: 280px;
    animation: promptSlideIn 0.3s ease-out;
}

@keyframes promptSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.push-permission-prompt .prompt-content {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
    align-items: flex-start;
}

.push-permission-prompt .prompt-content i {
    color: var(--primary-color, #059669);
    font-size: 1.125rem;
    margin-top: 2px;
}

.push-permission-prompt .prompt-content span {
    font-size: 0.8125rem;
    color: var(--text-secondary, #64748b);
    line-height: 1.4;
}

.push-permission-prompt .prompt-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

/* ============================================
   MOBILE - BOTTOM SHEET
   ============================================ */

@media (max-width: 992px) {
    .notification-dropdown {
        position: fixed;
        top: auto;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 75vh;
        border-radius: 20px 20px 0 0;
        transform: translateY(100%);
        transform-origin: bottom center;
        box-shadow:
            0 -4px 32px rgba(0, 0, 0, 0.15);
    }

    .notification-dropdown::before {
        display: none;
    }

    .notification-dropdown.show {
        transform: translateY(0);
        animation: mobileSlideUp 0.4s cubic-bezier(0.32, 0.72, 0, 1);
    }

    /* Closing animation class */
    .notification-dropdown.closing {
        animation: mobileSlideDown 0.3s cubic-bezier(0.4, 0, 1, 1) forwards;
    }

    @keyframes mobileSlideUp {
        from { transform: translateY(100%); }
        to { transform: translateY(0); }
    }

    @keyframes mobileSlideDown {
        from { transform: translateY(0); opacity: 1; }
        to { transform: translateY(100%); opacity: 0; }
    }

    /* Drag handle */
    .notification-dropdown::after {
        content: '';
        position: absolute;
        top: 8px;
        left: 50%;
        transform: translateX(-50%);
        width: 36px;
        height: 4px;
        background: rgba(0, 0, 0, 0.15);
        border-radius: 2px;
    }

    .notification-header {
        padding: 20px 16px 12px;
    }

    .notification-item {
        padding: 14px 16px;
    }

    .push-permission-prompt-wrapper {
        left: 16px;
        right: 16px;
        bottom: 16px;
    }

    .push-permission-prompt {
        max-width: none;
    }
}

/* ============================================
   DARK MODE
   ============================================ */

[data-theme="dark"] .sidebar-utility {
    border-top-color: var(--border-color, #1f2937);
}

[data-theme="dark"] .sidebar-notification-badge {
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

[data-theme="dark"] html[data-sidebar-collapsed="true"] .sidebar-notification-badge,
html[data-sidebar-collapsed="true"][data-theme="dark"] .sidebar-notification-badge {
    box-shadow: 0 0 0 2px var(--bg-sidebar, #0f172a);
}

[data-theme="dark"] .notification-dropdown {
    background: var(--bg-card, #1f2937);
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.05),
        0 8px 32px rgba(0, 0, 0, 0.4),
        0 24px 60px rgba(0, 0, 0, 0.3);
}

[data-theme="dark"] .notification-dropdown::before {
    background: var(--bg-card, #1f2937);
}

[data-theme="dark"] .notification-header {
    border-color: rgba(255, 255, 255, 0.06);
}

[data-theme="dark"] .notification-item {
    border-color: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .notification-item:hover {
    background-color: rgba(255, 255, 255, 0.03);
}

[data-theme="dark"] .notification-item.unread {
    background-color: rgba(16, 185, 129, 0.08);
}

[data-theme="dark"] .notification-icon.success {
    background: rgba(16, 185, 129, 0.15);
    color: #10b981;
}

[data-theme="dark"] .notification-icon.info {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
}

[data-theme="dark"] .notification-icon.warning {
    background: rgba(245, 158, 11, 0.15);
    color: #f59e0b;
}

[data-theme="dark"] .notification-icon.error {
    background: rgba(239, 68, 68, 0.15);
    color: #ef4444;
}

[data-theme="dark"] .push-permission-prompt {
    background: var(--bg-card, #1f2937);
}

@media (max-width: 992px) {
    [data-theme="dark"] .notification-dropdown::after {
        background: rgba(255, 255, 255, 0.2);
    }
}

/* ============================================
   ANIMATIONS
   ============================================ */

@keyframes badgePulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.1); }
}

.sidebar-notification-badge.pulse {
    animation: badgePulse 0.3s ease-out;
}

@keyframes bellRing {
    0%, 100% { transform: rotate(0); }
    15%, 45%, 75% { transform: rotate(8deg); }
    30%, 60%, 90% { transform: rotate(-8deg); }
}

#notificationBell.ring .sidebar-icon i {
    animation: bellRing 0.5s ease-in-out;
}

/* Item stagger animation */
.notification-dropdown.show .notification-item {
    animation: itemFadeIn 0.25s ease-out backwards;
}

.notification-dropdown.show .notification-item:nth-child(1) { animation-delay: 0.05s; }
.notification-dropdown.show .notification-item:nth-child(2) { animation-delay: 0.08s; }
.notification-dropdown.show .notification-item:nth-child(3) { animation-delay: 0.11s; }
.notification-dropdown.show .notification-item:nth-child(4) { animation-delay: 0.14s; }
.notification-dropdown.show .notification-item:nth-child(5) { animation-delay: 0.17s; }

@keyframes itemFadeIn {
    from {
        opacity: 0;
        transform: translateY(-6px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================================
   ACCESSIBILITY
   ============================================ */

.sidebar-btn:focus-visible {
    outline: 2px solid var(--primary-color, #059669);
    outline-offset: -2px;
    border-radius: 6px;
}

.notification-item:focus-visible {
    outline: none;
    background-color: var(--bg-card-hover, #f8fafc);
    box-shadow: inset 0 0 0 2px var(--primary-color, #059669);
}

@media (prefers-reduced-motion: reduce) {
    .notification-dropdown,
    .notification-dropdown.show,
    .notification-dropdown.show .notification-item {
        animation: none;
        transition: opacity 0.15s ease, visibility 0.15s;
    }
}
