/**
 * Notification Center Styles
 * Issue #26
 */

/* Notification Wrapper - positions the panel relative to the bell */
.notification-wrapper {
    position: relative;
}

/* Notification Backdrop - full screen overlay to block background scroll on mobile */
.notification-backdrop {
    display: none;
}

.notification-backdrop[hidden] {
    display: none;
}

/* Bell Button */
#notification-bell {
    position: relative;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md, 8px);
    transition: background-color 0.2s ease;
}

#notification-bell:hover,
#notification-bell.active {
    background-color: rgba(255, 255, 255, 0.1);
}

#notification-bell .notification-icon {
    font-size: 1.25rem;
    line-height: 1;
}

/* Badge */
#notification-badge {
    position: absolute;
    top: 0;
    right: 0;
    background-color: var(--color-error, #D32F2F);
    color: white;
    font-size: 0.65rem;
    font-weight: 600;
    min-width: 18px;
    height: 18px;
    padding: 0 4px;
    border-radius: 9px;
    display: flex;
    align-items: center;
    justify-content: center;
    transform: translate(25%, -25%);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

#notification-badge[hidden] {
    display: none;
}

/* Notification Panel */
#notification-panel {
    position: absolute;
    top: 100%;
    right: 0;
    width: 360px;
    max-width: calc(100vw - 2rem);
    max-height: 480px;
    background: var(--color-surface, #fff);
    border-radius: var(--radius-lg, 12px);
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    display: none;
    flex-direction: column;
    overflow: hidden;
}

#notification-panel.open {
    display: flex;
}

/* Panel Header */
.notification-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--color-border, #e0e0e0);
    background: var(--color-surface, #fff);
}

/* Close button - hidden on desktop, shown on mobile */
.notification-close-btn {
    display: none;
    background: none;
    border: none;
    font-size: 1.75rem;
    line-height: 1;
    padding: 0.5rem;
    color: var(--color-text-secondary, #666);
    cursor: pointer;
    margin-right: 0.5rem;
    /* Ensure good touch target */
    min-width: 44px;
    min-height: 44px;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0.1);
}

.notification-close-btn:hover,
.notification-close-btn:active {
    color: var(--color-text, #333);
    background: rgba(0, 0, 0, 0.05);
    border-radius: 4px;
}

@media screen and (max-width: 768px) {
    .notification-close-btn {
        display: flex !important;
        align-items: center;
        justify-content: center;
    }
}

.notification-panel-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--color-text, #333);
}

.notification-panel-actions {
    display: flex;
    gap: 0.5rem;
}

.notification-panel-actions button {
    background: none;
    border: none;
    color: var(--color-primary, #1976D2);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm, 4px);
    transition: background-color 0.2s ease;
}

.notification-panel-actions button:hover {
    background-color: var(--color-primary-light, rgba(25, 118, 210, 0.1));
}

/* Notification List */
#notification-list {
    flex: 1;
    overflow-y: auto;
    padding: 0.5rem 0;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    touch-action: pan-y;
    min-height: 0; /* Ensures flex item can shrink and scroll */
}

/* Individual Notification Item */
.notification-item {
    display: flex;
    padding: 0.75rem 1rem;
    gap: 0.75rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
    border-left: 3px solid transparent;
}

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

.notification-item.unread {
    background-color: var(--color-unread-bg, rgba(25, 118, 210, 0.05));
    border-left-color: var(--notification-color, var(--color-primary, #1976D2));
}

/* Type Indicator */
.notification-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--notification-color, #757575);
    flex-shrink: 0;
    margin-top: 0.5rem;
}

.notification-item:not(.unread) .notification-indicator {
    opacity: 0.3;
}

/* Notification Content */
.notification-content {
    flex: 1;
    min-width: 0;
}

.notification-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.notification-title {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--color-text, #333);
    line-height: 1.3;
}

.notification-time {
    font-size: 0.75rem;
    color: var(--color-text-muted, #666);
    white-space: nowrap;
    flex-shrink: 0;
}

.notification-body {
    font-size: 0.85rem;
    color: var(--color-text-secondary, #555);
    margin: 0 0 0.5rem 0;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

/* Notification Actions */
.notification-actions {
    display: flex;
    gap: 0.75rem;
    margin-top: 0.25rem;
}

.notification-link,
.notification-action {
    font-size: 0.75rem;
    color: var(--color-primary, #1976D2);
    text-decoration: none;
    background: none;
    border: none;
    padding: 0;
    cursor: pointer;
    transition: opacity 0.2s ease;
}

.notification-link:hover,
.notification-action:hover {
    opacity: 0.7;
    text-decoration: underline;
}

.notification-action-delete {
    color: var(--color-text-muted, #666);
}

/* Load More Button */
#notification-load-more {
    display: block;
    width: calc(100% - 2rem);
    margin: 0.5rem 1rem 1rem;
    padding: 0.5rem;
    background: var(--color-background, #f5f5f5);
    border: 1px solid var(--color-border, #e0e0e0);
    border-radius: var(--radius-sm, 4px);
    color: var(--color-text, #333);
    font-size: 0.85rem;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

#notification-load-more:hover {
    background: var(--color-hover, #eee);
}

#notification-load-more[hidden] {
    display: none;
}

/* Empty State */
.notification-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted, #666);
}

.notification-empty-icon {
    font-size: 3rem;
    opacity: 0.3;
    margin-bottom: 0.5rem;
}

.notification-empty p {
    margin: 0;
    font-size: 0.9rem;
}

/* Loading State */
.notification-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1rem;
    color: var(--color-text-muted, #666);
}

.notification-spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--color-border, #e0e0e0);
    border-top-color: var(--color-primary, #1976D2);
    border-radius: 50%;
    animation: notification-spin 0.8s linear infinite;
    margin-bottom: 0.5rem;
}

@keyframes notification-spin {
    to { transform: rotate(360deg); }
}

/* Error State */
.notification-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    color: var(--color-error, #D32F2F);
}

.notification-error p {
    margin: 0 0 1rem 0;
}

.notification-error button {
    background: var(--color-primary, #1976D2);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm, 4px);
    cursor: pointer;
}

/* Type-specific colors (set via --notification-color custom property) */
.notification-type-system_alert {
    --notification-color: #D32F2F;
}

.notification-type-message {
    --notification-color: #1976D2;
}

.notification-type-update {
    --notification-color: #388E3C;
}

.notification-type-reminder {
    --notification-color: #FBC02D;
}

/* Mobile Responsive - Full screen modal approach for iOS */
/* Using 768px to catch all mobile/tablet devices */
@media screen and (max-width: 768px) {
    /* Full-screen backdrop - above bottom nav */
    .notification-backdrop {
        display: none !important;
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        /* Account for bottom nav: 56px + safe area */
        bottom: calc(56px + env(safe-area-inset-bottom, 0px)) !important;
        width: 100% !important;
        height: auto !important;
        background: rgba(0, 0, 0, 0.5) !important;
        z-index: 9998 !important;
        touch-action: none;
        -webkit-tap-highlight-color: transparent;
    }

    .notification-backdrop.visible {
        display: block !important;
    }

    /* Full-screen modal panel - positioned above bottom nav */
    #notification-panel {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        /* Account for bottom nav: 56px + safe area */
        bottom: calc(56px + env(safe-area-inset-bottom, 0px)) !important;
        width: 100% !important;
        height: auto !important;
        max-width: 100% !important;
        max-height: none !important;
        border-radius: 0 !important;
        z-index: 9999 !important;
        display: none !important;
        flex-direction: column !important;
        /* iOS safe areas - only top needed now */
        padding-top: env(safe-area-inset-top, 0);
        padding-bottom: 0 !important;
        background: var(--color-surface, #fff) !important;
        box-shadow: none !important;
    }

    #notification-panel.open {
        display: flex !important;
    }

    /* Panel header with close button */
    .notification-panel-header {
        flex-shrink: 0 !important;
        padding: 1rem !important;
        padding-top: calc(1rem + env(safe-area-inset-top, 0)) !important;
        border-bottom: 1px solid var(--color-border, #e0e0e0) !important;
        background: var(--color-surface, #fff) !important;
    }

    /* Scrollable notification list - takes remaining space */
    #notification-list {
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch;
        overscroll-behavior-y: contain;
        touch-action: pan-y;
        padding-bottom: 1rem !important;
        min-height: 0 !important;
        max-height: none !important;
    }

    /* Load more button at bottom */
    #notification-load-more {
        flex-shrink: 0 !important;
        margin-bottom: 1rem !important;
    }

    /* Lock body scroll when panel is open */
    body.notification-panel-open,
    html.notification-panel-open {
        overflow: hidden !important;
        position: fixed !important;
        width: 100% !important;
        height: 100% !important;
        touch-action: none !important;
    }
}

/* Ensure body scroll lock works at all screen sizes when class is applied */
body.notification-panel-open,
html.notification-panel-open {
    overflow: hidden !important;
}

/* Notification Preferences */
.notification-preferences {
    padding: 1rem;
    display: flex;
    flex-direction: column;
    min-height: min-content;
}

.preferences-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 0.75rem;
}

.preferences-back {
    background: none;
    border: none;
    color: var(--color-primary, #1976D2);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    font-size: 0.9rem;
    border-radius: var(--radius-sm, 4px);
}

.preferences-back:hover {
    background-color: var(--color-primary-light, rgba(25, 118, 210, 0.1));
}

.preferences-header h4 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
}

.preferences-description {
    font-size: 0.85rem;
    color: var(--color-text-muted, #666);
    margin: 0 0 1rem 0;
}

.preferences-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding-bottom: 1rem; /* Extra padding at bottom for better scroll experience */
}

.preference-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem;
    background: var(--color-background, #f5f5f5);
    border-radius: var(--radius-md, 8px);
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.preference-item:hover {
    background: var(--color-hover, #eee);
}

.preference-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
}

.preference-indicator {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--pref-color, #757575);
    flex-shrink: 0;
}

.preference-text {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.preference-label {
    font-weight: 500;
    font-size: 0.9rem;
    color: var(--color-text, #333);
}

.preference-desc {
    font-size: 0.75rem;
    color: var(--color-text-muted, #666);
}

.preference-toggle {
    width: 40px;
    height: 22px;
    appearance: none;
    background: var(--color-border, #ccc);
    border-radius: 11px;
    position: relative;
    cursor: pointer;
    transition: background-color 0.2s ease;
    flex-shrink: 0;
}

.preference-toggle::before {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    background: white;
    border-radius: 50%;
    transition: transform 0.2s ease;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
}

.preference-toggle:checked {
    background: var(--color-primary, #1976D2);
}

.preference-toggle:checked::before {
    transform: translateX(18px);
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    #notification-panel {
        background: var(--color-surface-dark, #1e1e1e);
    }

    .notification-panel-header {
        background: var(--color-surface-dark, #1e1e1e);
        border-bottom-color: var(--color-border-dark, #333);
    }

    .notification-item.unread {
        background-color: rgba(25, 118, 210, 0.1);
    }

    .notification-title {
        color: var(--color-text-dark, #eee);
    }

    #notification-load-more {
        background: var(--color-background-dark, #2a2a2a);
        border-color: var(--color-border-dark, #333);
        color: var(--color-text-dark, #eee);
    }

    .preference-item {
        background: var(--color-background-dark, #2a2a2a);
    }

    .preference-item:hover {
        background: var(--color-hover-dark, #333);
    }

    .preference-label {
        color: var(--color-text-dark, #eee);
    }
}
