/**
 * Syndic Tunisie - Notifications System Styles
 * Bell icon, dropdown panel, badges, and animations
 */

/* ============================================
   CSS Variables
   ============================================ */
:root {
    --notif-primary: #1f4f5f;
    --notif-accent: #e67e22;
    --notif-danger: #7b1e35;
    --notif-success: #4f5d2f;
    --notif-info: #1f4f5f;
    --notif-warning: #e67e22;

    --notif-bg: #ffffff;
    --notif-bg-hover: #f5f7f6;
    --notif-bg-unread: #edf3f5;
    --notif-border: rgba(31, 79, 95, 0.15);
    --notif-text: #1f2937;
    --notif-text-muted: #6b7280;

    --notif-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    --notif-transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

[data-theme="dark"] {
    --notif-bg: #1f2937;
    --notif-bg-hover: #273445;
    --notif-bg-unread: rgba(95, 139, 154, 0.18);
    --notif-border: rgba(255, 255, 255, 0.1);
    --notif-text: #f1f5f9;
    --notif-text-muted: #94a3b8;
    --notif-accent: #f39a45;
    --notif-success: #93a86b;
    --notif-danger: #d78396;
    --notif-info: #8ab7c7;
}

/* ============================================
   Notification Bell Container
   ============================================ */
.notif-bell-container {
    position: relative;
    display: inline-flex;
    align-items: center;
    margin-right: 16px;
    z-index: 10000;
}

/* Bell Button */
.notif-bell-btn {
    position: relative;
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: none;
    background: rgba(15, 52, 96, 0.08);
    color: var(--notif-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--notif-transition);
}

[data-theme="dark"] .notif-bell-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #f1f5f9;
}

.notif-bell-btn:hover {
    background: rgba(15, 52, 96, 0.15);
    transform: scale(1.05);
}

[data-theme="dark"] .notif-bell-btn:hover {
    background: rgba(255, 255, 255, 0.15);
}

.notif-bell-btn.active {
    background: var(--notif-primary);
    color: #ffffff;
}

.notif-bell-btn svg {
    width: 22px;
    height: 22px;
    transition: transform 0.3s ease;
}

/* Bell Animation when new notification */
.notif-bell-btn.has-new svg {
    animation: bell-ring 0.5s ease-in-out;
}

@keyframes bell-ring {
    0%, 100% { transform: rotate(0); }
    20% { transform: rotate(15deg); }
    40% { transform: rotate(-15deg); }
    60% { transform: rotate(10deg); }
    80% { transform: rotate(-10deg); }
}

/* Notification Badge */
.notif-badge {
    position: absolute;
    top: 4px;
    right: 4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 9px;
    background: var(--notif-danger);
    color: #ffffff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 2px solid var(--notif-bg);
    animation: badge-pulse 2s infinite;
    z-index: 1;
}

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

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

/* ============================================
   Notification Dropdown Panel
   ============================================ */
.notif-dropdown {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    width: 380px;
    max-width: calc(100vw - 32px);
    background: var(--notif-bg);
    border-radius: 16px;
    box-shadow: var(--notif-shadow);
    border: 1px solid var(--notif-border);
    overflow: hidden;
    z-index: 10001;
    opacity: 0;
    visibility: hidden;
    transform: translateY(-10px);
    transition: var(--notif-transition);
}

.app-topbar {
    position: relative;
    z-index: 50;
}

.notif-dropdown.show {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

/* Dropdown Header */
.notif-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--notif-border);
    background: var(--notif-bg);
}

.notif-header-title {
    font-size: 16px;
    font-weight: 700;
    color: var(--notif-text);
    display: flex;
    align-items: center;
    gap: 8px;
}

.notif-header-count {
    font-size: 12px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 10px;
    background: var(--notif-danger);
    color: #ffffff;
}

.notif-header-actions {
    display: flex;
    gap: 8px;
}

.notif-action-btn {
    padding: 6px 12px;
    border-radius: 8px;
    border: none;
    background: transparent;
    color: var(--notif-primary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--notif-transition);
}

.notif-action-btn:hover {
    background: rgba(15, 52, 96, 0.1);
}

[data-theme="dark"] .notif-action-btn {
    color: var(--notif-accent);
}

[data-theme="dark"] .notif-action-btn:hover {
    background: rgba(255, 255, 255, 0.1);
}

/* Notification List */
.notif-list {
    max-height: 400px;
    overflow-y: auto;
}

.notif-list::-webkit-scrollbar {
    width: 6px;
}

.notif-list::-webkit-scrollbar-thumb {
    background: rgba(15, 52, 96, 0.2);
    border-radius: 3px;
}

/* Individual Notification Item */
.notif-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 14px 20px;
    border-bottom: 1px solid var(--notif-border);
    cursor: pointer;
    transition: var(--notif-transition);
    text-decoration: none;
    color: inherit;
}

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

.notif-item.unread {
    background: var(--notif-bg-unread);
}

.notif-item.unread:hover {
    background: rgba(31, 79, 95, 0.14);
}

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

/* Notification Icon */
.notif-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

.notif-icon.message { background: rgba(14, 165, 233, 0.15); color: var(--notif-info); }
.notif-icon.facture { background: rgba(245, 158, 11, 0.15); color: var(--notif-warning); }
.notif-icon.reclamation { background: rgba(233, 75, 60, 0.15); color: var(--notif-danger); }
.notif-icon.success { background: rgba(34, 197, 94, 0.15); color: var(--notif-success); }
.notif-icon.ag { background: rgba(31, 79, 95, 0.15); color: var(--notif-primary); }
.notif-icon.travaux { background: rgba(230, 126, 34, 0.15); color: var(--notif-accent); }
.notif-icon.sinistre { background: rgba(123, 30, 53, 0.15); color: var(--notif-danger); }
.notif-icon.rappel { background: rgba(79, 93, 47, 0.15); color: var(--notif-success); }
.notif-icon.systeme { background: rgba(100, 116, 139, 0.15); color: var(--notif-text-muted); }
.notif-icon.annonce { background: rgba(31, 79, 95, 0.15); color: var(--notif-info); }

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

.notif-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--notif-text);
    margin-bottom: 4px;
    line-height: 1.3;
}

.notif-item.unread .notif-title {
    color: var(--notif-primary);
}

[data-theme="dark"] .notif-item.unread .notif-title {
    color: var(--notif-info);
}

.notif-text {
    font-size: 13px;
    color: var(--notif-text-muted);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.notif-time {
    font-size: 11px;
    color: var(--notif-text-muted);
    margin-top: 6px;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Unread Indicator */
.notif-unread-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--notif-primary);
    flex-shrink: 0;
    margin-top: 4px;
}

[data-theme="dark"] .notif-unread-dot {
    background: var(--notif-accent);
}

/* Empty State */
.notif-empty {
    padding: 40px 20px;
    text-align: center;
}

.notif-empty-icon {
    width: 64px;
    height: 64px;
    margin: 0 auto 16px;
    border-radius: 50%;
    background: rgba(15, 52, 96, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}

[data-theme="dark"] .notif-empty-icon {
    background: rgba(255, 255, 255, 0.08);
}

.notif-empty-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--notif-text);
    margin-bottom: 4px;
}

.notif-empty-text {
    font-size: 13px;
    color: var(--notif-text-muted);
}

/* Dropdown Footer */
.notif-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--notif-border);
    background: var(--notif-bg);
    text-align: center;
}

.notif-footer a {
    font-size: 13px;
    font-weight: 600;
    color: var(--notif-primary);
    text-decoration: none;
    transition: var(--notif-transition);
}

.notif-footer a:hover {
    color: var(--notif-accent);
}

[data-theme="dark"] .notif-footer a {
    color: var(--notif-accent);
}

/* ============================================
   Loading State
   ============================================ */
.notif-loading {
    padding: 40px 20px;
    text-align: center;
}

.notif-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--notif-border);
    border-top-color: var(--notif-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}

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

/* ============================================
   Toast Notifications
   ============================================ */
.notif-toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 99999;
    display: flex;
    flex-direction: column;
    gap: 12px;
    pointer-events: none;
}

.notif-toast {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 16px 20px;
    background: var(--notif-bg);
    border-radius: 12px;
    box-shadow: var(--notif-shadow);
    border-left: 4px solid var(--notif-primary);
    max-width: 380px;
    pointer-events: auto;
    animation: toast-slide-in 0.3s ease-out;
    cursor: pointer;
    transition: var(--notif-transition);
}

.notif-toast:hover {
    transform: translateX(-4px);
}

.notif-toast.toast-success { border-left-color: var(--notif-success); }
.notif-toast.toast-warning { border-left-color: var(--notif-warning); }
.notif-toast.toast-danger { border-left-color: var(--notif-danger); }
.notif-toast.toast-info { border-left-color: var(--notif-info); }

@keyframes toast-slide-in {
    from {
        opacity: 0;
        transform: translateX(100px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.notif-toast.removing {
    animation: toast-slide-out 0.3s ease-in forwards;
}

@keyframes toast-slide-out {
    to {
        opacity: 0;
        transform: translateX(100px);
    }
}

.notif-toast-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}

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

.notif-toast-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--notif-text);
    margin-bottom: 2px;
}

.notif-toast-text {
    font-size: 13px;
    color: var(--notif-text-muted);
    line-height: 1.4;
}

.notif-toast-close {
    width: 24px;
    height: 24px;
    border-radius: 6px;
    border: none;
    background: transparent;
    color: var(--notif-text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    transition: var(--notif-transition);
}

.notif-toast-close:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* ============================================
   Push Notification Permission Banner
   Positionnée en bas-à-gauche, 50% de largeur,
   au-dessus des chat widgets (z-index > 9999)
   ============================================ */
.notif-permission-banner {
    position: fixed;
    bottom: 24px;
    left: 24px;
    width: calc(50% - 24px);
    z-index: 100000;
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 20px 24px;
    background: var(--notif-primary);
    color: #ffffff;
    border-radius: 16px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    animation: slide-up 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes slide-up {
    from {
        opacity: 0;
        transform: translateY(40px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.notif-permission-banner.hidden {
    display: none;
}

.notif-permission-top {
    display: flex;
    align-items: flex-start;
    gap: 14px;
}

.notif-permission-icon {
    font-size: 28px;
    flex-shrink: 0;
    margin-top: 2px;
}

.notif-permission-text {
    flex: 1;
}

.notif-permission-title {
    font-size: 16px;
    font-weight: 700;
    margin-bottom: 4px;
}

.notif-permission-desc {
    font-size: 13px;
    opacity: 0.85;
    line-height: 1.5;
}

.notif-permission-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.notif-permission-btn {
    padding: 10px 22px;
    border-radius: 10px;
    border: none;
    font-size: 13px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--notif-transition);
}

.notif-permission-btn.primary {
    background: var(--notif-accent);
    color: #ffffff;
}

.notif-permission-btn.primary:hover {
    background: #cc6f1d;
    transform: translateY(-1px);
}

.notif-permission-btn.secondary {
    background: rgba(255, 255, 255, 0.15);
    color: #ffffff;
    border: 1px solid rgba(255, 255, 255, 0.25);
}

.notif-permission-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.25);
}

@media (max-width: 768px) {
    .notif-permission-banner {
        left: 12px;
        right: 12px;
        bottom: 12px;
        width: auto;
    }
}

/* ============================================
   Responsive
   ============================================ */
@media (max-width: 768px) {
    /* position:fixed pour échapper à tout overflow:hidden parent (topbar, shell...) */
    .notif-dropdown {
        position: fixed !important;
        top: 72px !important;
        right: 8px !important;
        left: 8px !important;
        bottom: auto !important;
        width: auto !important;
        max-width: none !important;
        border-radius: 16px;
        max-height: calc(100vh - 90px);
        transform: translateY(-10px);
        z-index: 99999 !important;
    }

    .notif-dropdown.show {
        transform: translateY(0);
    }

    .notif-list {
        max-height: calc(100vh - 230px);
    }

    /* Réduire la marge du container cloche sur mobile */
    .notif-bell-container {
        margin-right: 4px;
    }

    .notif-toast-container {
        top: auto;
        bottom: 20px;
        left: 16px;
        right: 16px;
    }

    .notif-toast {
        max-width: 100%;
    }
}

/* ============================================
   Notification Type Colors in Items
   ============================================ */
.notif-item[data-type="MESSAGE"] .notif-icon { background: rgba(14, 165, 233, 0.15); color: var(--notif-info); }
.notif-item[data-type="FACTURE"] .notif-icon { background: rgba(245, 158, 11, 0.15); color: var(--notif-warning); }
.notif-item[data-type="AG"] .notif-icon { background: rgba(31, 79, 95, 0.15); color: var(--notif-primary); }
.notif-item[data-type="TRAVAUX"] .notif-icon { background: rgba(230, 126, 34, 0.15); color: var(--notif-accent); }
.notif-item[data-type="SINISTRE"] .notif-icon { background: rgba(123, 30, 53, 0.15); color: var(--notif-danger); }
.notif-item[data-type="RAPPEL"] .notif-icon { background: rgba(79, 93, 47, 0.15); color: var(--notif-success); }
.notif-item[data-type="SYSTEME"] .notif-icon { background: rgba(100, 116, 139, 0.15); color: var(--notif-text-muted); }
.notif-item[data-type="ANNONCE"] .notif-icon { background: rgba(31, 79, 95, 0.15); color: var(--notif-info); }
.notif-item[data-type="RECLAMATION"] .notif-icon { background: rgba(233, 75, 60, 0.15); color: var(--notif-danger); }
.notif-item[data-type="PAIEMENT"] .notif-icon { background: rgba(34, 197, 94, 0.15); color: var(--notif-success); }

/* ============================================
   Animation Utilities
   ============================================ */
.notif-shake {
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-5px); }
    40%, 80% { transform: translateX(5px); }
}

.notif-bounce {
    animation: bounce 0.5s ease;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}
