/* ==========================================================
   ICYLAB OS
   05-layout.css
   Fixed sidebar + independent main scroll
   Optimized for Collapsible Gemini-Style Menu & 5-KPI Grid
========================================================== */

/* Base */

html,
body {
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.app-shell {
    width: 100%;
    height: 100vh;
    min-height: 100vh;
    display: block;
    background: var(--surface-0);
    overflow: hidden;
}

/* Sidebar */

.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 999; /* 🔥 Elevado para quedar por sobre todo el contenido y las tarjetas en móvil */

    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    max-width: var(--sidebar-width);
    height: 100vh;

    background: var(--surface-1);
    border-right: 1px solid var(--border-default);

    overflow: visible; /* 🔥 Cambiado de hidden a visible para permitir que el dropdown flote hacia arriba/afuera */
    transition: width 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), min-width 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), max-width 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sidebar-inner {
    height: 100%;
    width: 100%;

    padding: 18px;

    display: flex;
    flex-direction: column;

    overflow: visible; /* 🔥 Permitir que elementos absolutos internos floten libres sin recortes */
}

.sidebar-brand-logo-only {
    width: 100%;
    padding-bottom: 18px;
    margin-bottom: 4px;
}

.sidebar-brand-logo-only a {
    display: block;
    width: 100%;
}

.sidebar-brand-logo-only img {
    width: 100%;
    max-width: 205px;
    height: auto;
    display: block;
    filter: var(--logo-filter);
}

.sidebar-section {
    margin-bottom: 12px;
}

.sidebar-title {
    margin-bottom: 6px;
    padding-left: 10px;

    font-size: 0.62rem;
    font-weight: 700;

    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.14em;
}

.sidebar-nav {
    display: grid;
    gap: 3px;
}

.sidebar-link {
    position: relative;

    width: 100%;
    min-height: 36px;

    display: flex;
    align-items: center;
    gap: 10px;

    padding: 0 12px;

    color: var(--text-secondary);
    border-radius: 12px;

    font-size: 0.9rem;

    transition:
        background var(--motion-fast),
        color var(--motion-fast);
}

.sidebar-link:hover,
.sidebar-link.is-active {
    color: var(--text-primary);
    background: var(--surface-2);
}

.sidebar-link.is-active::before {
    content: "";
    position: absolute;
    left: 0;
    top: 8px;
    bottom: 8px;

    width: 3px;

    border-radius: 999px;
    background: var(--color-primary);
}

.sidebar-icon {
    width: 18px;
    height: 18px;

    flex: 0 0 18px;

    display: flex;
    align-items: center;
    justify-content: center;

    color: var(--text-muted);
}

.sidebar-icon svg {
    width: 16px;
    height: 16px;
    stroke-width: 2;
}

.sidebar-link:hover .sidebar-icon,
.sidebar-link.is-active .sidebar-icon {
    color: var(--color-primary);
}

/* Sombra / Fondo oscuro interceptor */
.sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 998; /* 🔥 Justo por debajo de la Sidebar (999) pero por sobre todo el contenido del Main */
    display: none;
    background: rgba(0, 0, 0, 0.58);
    backdrop-filter: blur(4px);
}

.sidebar-backdrop.is-open {
    display: block;
}

/* Main */

.app-main {
    position: relative;

    width: calc(100% - var(--sidebar-width));
    height: 100vh;

    margin-left: var(--sidebar-width);

    display: flex;
    flex-direction: column;

    overflow-y: auto;
    overflow-x: hidden;
    
    /* 🔥 Transición fluida para absorber el colapso del menú lateral en PC */
    transition: width 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), margin-left 0.4s cubic-bezier(0.2, 0.8, 0.2, 1), transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);
}

/* Topbar */

.topbar {
    position: sticky;
    top: 0;
    z-index: var(--z-topbar);

    flex: 0 0 auto;

    min-height: var(--topbar-height);

    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-4);

    padding: 0 var(--space-8);

    background: color-mix(in srgb, var(--surface-0) 88%, transparent);
    border-bottom: 1px solid var(--border-subtle);

    backdrop-filter: blur(16px);
}

.topbar-left,
.topbar-actions {
    display: flex;
    align-items: center;
    gap: var(--space-3);
}

.icon-btn {
    width: 40px;
    height: 40px;

    display: inline-grid;
    place-items: center;

    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);

    color: var(--text-primary);
    background: var(--surface-1);

    cursor: pointer;
}

.icon-btn:hover {
    background: var(--surface-2);
}

.mobile-only {
    display: none;
}

/* User menu */

.user-menu {
    position: relative;
}

.user-pill {
    min-height: 42px;

    display: flex;
    align-items: center;
    gap: 10px;

    padding: 4px 10px 4px 4px;

    border: 1px solid var(--border-default);
    border-radius: 999px;

    color: var(--text-primary);
    background: var(--surface-1);

    cursor: pointer;
}

.user-pill:hover {
    background: var(--surface-2);
}

.user-pill strong {
    display: block;
    font-size: 0.85rem;
    line-height: 1.1;
}

.user-pill span {
    display: block;
    font-size: 0.72rem;
    color: var(--text-muted);
}

.user-menu-chevron,
.user-menu-chevron svg {
    width: 16px;
    height: 16px;
}

.user-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 10px);

    width: 260px;

    display: none;

    padding: 8px;

    background: var(--surface-1);
    border: 1px solid var(--border-default);
    border-radius: 18px;

    box-shadow: var(--shadow-lg);

    z-index: 100;
}

.user-dropdown.is-open {
    display: block;
}

.user-dropdown-header {
    padding: 12px;
    margin-bottom: 6px;

    border-bottom: 1px solid var(--border-subtle);
}

.user-dropdown-header strong {
    display: block;
    font-size: 0.9rem;
}

.user-dropdown-header span {
    display: block;
    margin-top: 4px;

    color: var(--text-muted);
    font-size: 0.78rem;
}

.user-dropdown-link {
    min-height: 40px;

    display: flex;
    align-items: center;
    gap: 10px;

    padding: 0 12px;

    color: var(--text-secondary);
    border-radius: 12px;
}

.user-dropdown-link:hover {
    color: var(--text-primary);
    background: var(--surface-2);
}

.user-dropdown-link svg {
    width: 17px;
    height: 17px;
}

.user-dropdown-link.is-danger {
    color: var(--color-error);
}

/* Content */

.content {
    width: 100%;
    max-width: var(--container-max);

    margin: 0 auto;

    padding: var(--space-6);

    flex: 1 0 auto;
}

.page-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;

    gap: var(--space-4);

    margin-bottom: var(--space-4);
}

.page-header-content {
    display: grid;
    gap: var(--space-3);
}

/* Layout utilities */

.grid {
    display: grid;
    gap: var(--space-5);
}

.grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.grid-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

/* 🔥 Nueva Utilidad: Grilla de 5 Columnas Nativas */
.grid-5 {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

/* 🔥 Nueva Utilidad: Elemento de Ancho Completo en Grillas */
.col-span-full {
    grid-column: 1 / -1 !important;
}

.cluster {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    flex-wrap: wrap;
}

/* ==========================================================
   SISTEMA DE COLAPSO NATIVO (Escritorio)
   ========================================================== */
body.is-sidebar-collapsed {
    --sidebar-width: 84px !important;
}

/* Tablet */

@media (max-width: 1024px) {
    :root {
        --sidebar-width: 240px;
    }

    .content {
        padding: var(--space-6);
    }

    .grid-3,
    .grid-4 {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    
    /* Adaptación de Grilla de 5 a 3 columnas en pantallas medianas */
    .grid-5 {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

/* Compact height */

@media (max-height: 760px) {
    .sidebar-inner {
        padding: 14px;
    }

    .sidebar-brand-logo-only img {
        max-width: 175px;
    }

    .sidebar-section {
        margin-bottom: 8px;
    }

    .sidebar-link {
        min-height: 32px;
        font-size: 0.84rem;
    }
}

/* Mobile */

@media (max-width: 760px) {
    .app-shell {
        width: 100%;
        height: 100vh;
        min-height: 100vh;

        display: block;

        overflow: hidden;
    }

    .sidebar {
        position: fixed;

        inset: 0 auto 0 0;

        width: min(86vw, 320px);
        min-width: 0;
        max-width: 320px;

        height: 100dvh;

        transform: translateX(-100%);
        transition: transform 0.4s cubic-bezier(0.2, 0.8, 0.2, 1);

        box-shadow: var(--shadow-lg);
        z-index: 999; /* Mantener la prioridad máxima sobre la sombra */
    }

    .sidebar.is-open {
        transform: translateX(0);
    }

    /* Nota: .sidebar-backdrop ya está configurada globalmente con z-index 998 */

    .app-main {
        width: 100%;
        height: 100vh;
        padding-bottom: env(safe-area-inset-bottom);

        margin-left: 0;

        overflow-y: auto;
        overflow-x: hidden;
    }

    .mobile-only {
        display: inline-grid;
    }

    .mobile-hidden {
        display: none !important;
    }

    .topbar {
        min-height: 64px;
        padding: 0 var(--space-4);
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: center;
        gap: 10px;
        overflow: visible;
    }

    .topbar-left {
        min-width: 0;
        overflow: hidden;
    }

    .topbar-left > div {
        min-width: 0;
        overflow: hidden;
    }

    .topbar-left strong {
        display: block;
        max-width: 48vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .topbar-actions {
        justify-self: end;
        flex: 0 0 auto;
        min-width: max-content;
        margin-left: auto;
    }

    .content {
        padding: var(--space-5) var(--space-4);
        padding-bottom: calc(var(--space-20) + env(safe-area-inset-bottom));
    }

    .page-header {
        flex-direction: column;
    }

    .grid-2,
    .grid-3,
    .grid-4 {
        grid-template-columns: 1fr;
    }
    
    /* 🔥 Excepción para Grilla de 5 en Móvil: Forzar 2 Columnas exactas */
    .grid-5 {
        grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
        gap: var(--space-3) !important;
    }

    /* 🔥 Efecto Push en Móvil */
    body.is-mobile-sidebar-open .app-main {
        transform: translateX(min(86vw, 320px));
        opacity: 0.8; /* Le da un leve oscurecimiento al fondo para mayor inmersión */
    }

}

/* Header móvil */

.sidebar-mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding-bottom: 20px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--border-subtle);
}

.sidebar-mobile-header img {
    width: 150px;
    height: auto;
    filter: var(--logo-filter);
}

.sidebar-close {
    flex-shrink: 0;
}

@media (max-width: 760px) {
    .sidebar-mobile-header {
        display: flex;
    }

    .sidebar-brand-logo-only {
        display: none;
    }
}

.sidebar-tools {
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--border-subtle);
}

.sidebar-theme-toggle {
    width: 100%;
    min-height: 36px;

    display: flex;
    align-items: center;
    gap: 10px;

    padding: 0 12px;

    border: 1px solid var(--border-default);
    border-radius: 12px;

    color: var(--text-secondary);
    background: transparent;

    font-size: 0.9rem;
    cursor: pointer;
}

.sidebar-theme-toggle:hover {
    color: var(--text-primary);
    background: var(--surface-2);
}

.sidebar-theme-toggle:hover .sidebar-icon {
    color: var(--color-primary);
}

/* ==========================================================================
   Notification Center
   ========================================================================== */

.notification-menu {
    position: relative;
}

.notification-bell-btn {
    position: relative;
}

.notification-count-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    display: none;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: var(--color-error);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1;
    border: 2px solid var(--surface-0);
}

.notification-count-badge.is-visible {
    display: inline-flex;
}

.notification-dropdown {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: min(390px, calc(100vw - 24px));
    max-height: min(560px, calc(100vh - 96px));
    display: none !important;
    flex-direction: column;
    overflow: hidden;
    background: var(--surface-1);
    border: 1px solid var(--border-default);
    border-radius: 18px;
    box-shadow: var(--shadow-lg);
    z-index: 1200;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.notification-dropdown.is-open {
    display: flex !important;
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.notification-dropdown-header,
.notification-dropdown-footer {
    flex: 0 0 auto;
    padding: 14px;
    border-bottom: 1px solid var(--border-subtle);
}

.notification-dropdown-footer {
    border-bottom: none;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

.notification-dropdown-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.notification-dropdown-header strong {
    display: block;
    font-size: 0.95rem;
}

.notification-dropdown-header span {
    display: block;
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 0.76rem;
}

.notification-dropdown-list {
    flex: 1 1 auto;
    overflow-y: auto;
    padding: 6px;
}

.notification-item {
    display: grid;
    grid-template-columns: 32px minmax(0, 1fr);
    gap: 10px;
    padding: 11px 10px;
    border-radius: 14px;
    color: var(--text-primary);
    text-decoration: none;
    border: 1px solid transparent;
}

.notification-item:hover {
    background: var(--surface-2);
}

.notification-item.is-unread {
    background: color-mix(in srgb, var(--color-primary) 9%, transparent);
    border-color: color-mix(in srgb, var(--color-primary) 25%, transparent);
}

.notification-item-icon {
    width: 32px;
    height: 32px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-secondary);
}

.notification-item-icon svg,
.notification-row-icon svg {
    width: 17px;
    height: 17px;
}

.notification-item h4 {
    margin: 0;
    font-size: 0.84rem;
    line-height: 1.25;
}

.notification-item p {
    margin: 4px 0 0;
    color: var(--text-secondary);
    font-size: 0.76rem;
    line-height: 1.4;
}

.notification-item time {
    display: block;
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 0.7rem;
}

.notification-empty,
.notification-loading {
    padding: 28px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.84rem;
}

.notification-priority-critical .notification-item-icon,
.notification-row.notification-priority-critical .notification-row-icon {
    color: var(--color-error);
    background: color-mix(in srgb, var(--color-error) 12%, transparent);
}

.notification-priority-warning .notification-item-icon,
.notification-row.notification-priority-warning .notification-row-icon {
    color: var(--color-warning);
    background: color-mix(in srgb, var(--color-warning) 14%, transparent);
}

.notification-priority-success .notification-item-icon,
.notification-row.notification-priority-success .notification-row-icon {
    color: var(--color-success);
    background: color-mix(in srgb, var(--color-success) 12%, transparent);
}

.notifications-layout-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 380px;
    gap: var(--space-5);
    align-items: start;
}

.notifications-full-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: var(--space-4);
}

.notification-row {
    display: grid;
    grid-template-columns: 38px minmax(0, 1fr) auto;
    gap: 12px;
    align-items: start;
    padding: 14px;
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    background: var(--surface-1);
}

.notification-row.is-unread {
    border-color: color-mix(in srgb, var(--color-primary) 35%, var(--border-subtle));
    background: color-mix(in srgb, var(--color-primary) 7%, var(--surface-1));
}

.notification-row-icon {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    border-radius: 999px;
    background: var(--surface-2);
}

.notification-row-head {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.notification-row-content p {
    margin: 6px 0 0;
    color: var(--text-secondary);
    line-height: 1.45;
}

.notification-row-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 8px;
    color: var(--text-muted);
    font-size: 0.76rem;
}

.notification-priority-badge {
    display: inline-flex;
    align-items: center;
    min-height: 22px;
    padding: 0 8px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 600;
}

.notification-row-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.notification-preferences-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: var(--space-4);
}

.notification-preference-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 12px;
    border: 1px solid var(--border-subtle);
    border-radius: 14px;
    cursor: pointer;
}

.notification-preference-item strong,
.notification-preference-item span,
.notification-preference-item em {
    display: block;
}

.notification-preference-item strong {
    font-size: 0.86rem;
}

.notification-preference-item span {
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 0.74rem;
    line-height: 1.35;
}

.notification-preference-item em {
    margin-top: 5px;
    color: var(--color-error);
    font-size: 0.72rem;
    font-style: normal;
    font-weight: 600;
}

.notification-preference-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--color-primary);
}

@media (max-width: 980px) {
    .notifications-layout-grid {
        grid-template-columns: 1fr;
    }

    .notification-row {
        grid-template-columns: 38px minmax(0, 1fr);
    }

    .notification-row-actions {
        grid-column: 2 / -1;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
}

@media (max-width: 760px) {
    .topbar-actions {
        gap: 8px;
    }

    .notification-menu {
        position: static;
        flex: 0 0 auto;
    }

    .notification-dropdown {
        position: fixed !important;
        top: calc(64px + env(safe-area-inset-top) + 8px) !important;
        right: 12px !important;
        left: 12px !important;
        width: auto !important;
        max-height: min(72dvh, calc(100dvh - 88px)) !important;
        border-radius: 18px !important;
        background: var(--surface-1) !important;
        border: 1px solid var(--border-default) !important;
        box-shadow: var(--shadow-lg) !important;
        overflow: hidden !important;
        z-index: 1600 !important;
    }

    .notification-dropdown-header,
    .notification-dropdown-footer {
        padding: 12px !important;
    }

    .notification-dropdown-footer .btn {
        min-height: 38px;
        flex: 1 1 0;
        justify-content: center;
    }

    .notification-dropdown-list {
        max-height: calc(min(72dvh, 100dvh - 88px) - 108px);
    }

    .notification-row {
        padding: 12px;
    }
}

/* ==========================================================================
   Notification Center refinements - unified topbar action and page UX
   ========================================================================== */

.topbar-actions .notification-bell-btn {
    width: 40px;
    min-width: 40px;
    height: 40px;
    min-height: 40px;
    padding: 0;
    border: 1px solid var(--border-default);
    border-radius: var(--radius-md);
    background: transparent;
    color: var(--text-primary);
    box-shadow: none;
}

.topbar-actions .notification-bell-btn:hover,
.topbar-actions .notification-bell-btn:focus-visible {
    background: var(--surface-2);
    border-color: var(--border-strong);
}

.topbar-actions .notification-bell-btn svg,
.topbar-actions .notification-bell-btn i {
    width: 20px;
    height: 20px;
}

.topbar-actions #forceSyncFacto {
    min-height: 40px;
    border-color: var(--border-default);
    background: transparent;
    box-shadow: none;
}

.topbar-actions #forceSyncFacto:hover,
.topbar-actions #forceSyncFacto:focus-visible {
    background: var(--surface-2);
    border-color: var(--border-strong);
}

.notifications-page-header {
    align-items: flex-start;
}

.notifications-actions {
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 10px;
}

.notifications-actions .notification-mark-all-form {
    display: inline-flex;
    margin: 0;
}

.notifications-actions .notification-action-btn {
    min-height: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    white-space: nowrap;
}

.notifications-actions .notification-action-btn.is-active {
    background: var(--surface-2);
    border-color: var(--border-strong);
}

.notifications-actions .notification-action-btn svg,
.notifications-actions .notification-action-btn i {
    width: 18px;
    height: 18px;
}

.notifications-layout-single {
    grid-template-columns: minmax(0, 1fr);
}

.notifications-list-card-wide {
    background:
        linear-gradient(180deg, color-mix(in srgb, var(--surface-1) 96%, var(--surface-2)), var(--surface-1));
}

.notifications-card-header {
    align-items: flex-start;
    gap: 16px;
}

.notification-summary-pills {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

.notification-summary-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 30px;
    padding: 0 10px;
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 0.74rem;
    font-weight: 600;
}

.notification-summary-pill strong {
    color: var(--text-primary);
    font-size: 0.82rem;
}

.notification-summary-pill.has-unread {
    border-color: color-mix(in srgb, var(--color-primary) 35%, var(--border-subtle));
    background: color-mix(in srgb, var(--color-primary) 8%, var(--surface-2));
}

.notifications-full-list {
    gap: 12px;
    padding: var(--space-4);
    background: color-mix(in srgb, var(--surface-0) 64%, transparent);
}

.notification-row {
    position: relative;
    grid-template-columns: 42px minmax(0, 1fr) auto;
    gap: 14px;
    padding: 14px 16px;
    border-color: var(--border-subtle);
    border-radius: 18px;
    background: var(--surface-1);
    box-shadow: 0 1px 0 color-mix(in srgb, var(--text-primary) 4%, transparent);
    transition: background var(--motion-fast), border-color var(--motion-fast), transform var(--motion-fast);
}

.notification-row::before {
    content: "";
    position: absolute;
    top: 14px;
    bottom: 14px;
    left: 0;
    width: 3px;
    border-radius: 0 var(--radius-full) var(--radius-full) 0;
    background: var(--border-strong);
    opacity: 0.55;
}

.notification-row:hover {
    background: var(--surface-2);
    border-color: var(--border-default);
}

.notification-row.is-unread {
    border-color: color-mix(in srgb, var(--color-primary) 38%, var(--border-subtle));
    background:
        linear-gradient(90deg, color-mix(in srgb, var(--color-primary) 8%, transparent), transparent 48%),
        var(--surface-1);
}

.notification-row.is-unread::before {
    background: var(--color-primary);
    opacity: 1;
}

.notification-row.notification-priority-critical::before {
    background: var(--color-error);
    opacity: 1;
}

.notification-row.notification-priority-warning::before {
    background: var(--color-warning);
    opacity: 1;
}

.notification-row.notification-priority-success::before {
    background: var(--color-success);
    opacity: 1;
}

.notification-row-icon {
    width: 42px;
    height: 42px;
    border-radius: 14px;
    color: var(--text-secondary);
    background: var(--surface-2);
    border: 1px solid var(--border-subtle);
}

.notification-row-icon svg {
    width: 18px;
    height: 18px;
}

.notification-row-head {
    gap: 10px;
}

.notification-row-head strong {
    font-size: 0.95rem;
    line-height: 1.3;
}

.notification-row-content {
    min-width: 0;
    padding-right: 6px;
}

.notification-row-content p {
    max-width: 920px;
    margin: 7px 0 0;
    color: var(--text-secondary);
    font-size: 0.88rem;
}

.notification-row-meta {
    gap: 10px;
    margin: 10px 0 0;
}

.notification-row-meta span {
    display: inline-flex;
    align-items: center;
    gap: 5px;
}

.notification-row-meta svg,
.notification-row-meta i {
    width: 13px;
    height: 13px;
}

.notification-priority-badge {
    min-height: 24px;
    padding: 0 9px;
    border: 1px solid var(--border-subtle);
    background: var(--surface-2);
    font-size: 0.68rem;
    letter-spacing: 0.01em;
}

.notification-row-actions {
    gap: 8px;
}

.notification-row-actions .notification-row-action {
    min-height: 36px;
    height: 36px;
}

.notification-empty-state {
    min-height: 180px;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 28px 24px;
    border: 1px dashed var(--border-default);
    border-radius: 18px;
    background: var(--surface-1);
}

.notification-empty-state svg,
.notification-empty-state i {
    width: 28px;
    height: 28px;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.notification-empty-state strong {
    display: block;
    margin: 0;
}

.notification-empty-state p {
    max-width: 560px;
    margin: 6px auto 0;
}

.notification-dropdown {
    background: var(--surface-1);
}

.notification-item {
    border-radius: 14px;
    background: transparent;
}

.notification-item:hover {
    background: var(--surface-2);
}

.notification-item.is-unread {
    background: color-mix(in srgb, var(--color-primary) 8%, var(--surface-1));
}

.notification-preferences-modal .notification-preferences-box {
    width: min(720px, 94vw);
    max-height: min(88dvh, 780px);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.notification-preferences-modal .notification-preferences-box > form {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

.notification-preferences-modal .product-modal-header {
    align-items: flex-start;
    gap: 16px;
    flex: 0 0 auto;
}

.notification-preferences-body {
    padding: 0;
    background: color-mix(in srgb, var(--surface-0) 60%, transparent);
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
}

.notification-preferences-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: var(--space-5);
}

.notification-preference-item {
    grid-template-columns: minmax(0, 1fr) 28px;
    gap: 16px;
    padding: 14px 16px;
    border-color: var(--border-subtle);
    border-radius: 16px;
    background: var(--surface-1);
    transition: background var(--motion-fast), border-color var(--motion-fast);
}

.notification-preference-item:hover {
    background: var(--surface-2);
    border-color: var(--border-default);
}

.notification-preference-item.is-critical {
    border-color: color-mix(in srgb, var(--color-error) 22%, var(--border-subtle));
}

.notification-preference-item input[type="checkbox"] {
    width: 20px;
    height: 20px;
    justify-self: end;
    accent-color: var(--color-primary);
}

.notification-preferences-footer {
    gap: 10px;
    flex: 0 0 auto;
}

@media (max-width: 760px) {
    .topbar-actions .notification-bell-btn,
    .topbar-actions #forceSyncFacto {
        width: 40px;
        min-width: 40px;
        height: 40px;
        min-height: 40px;
        padding: 0;
    }

    .notifications-page .notifications-page-header {
        flex-direction: row;
        align-items: flex-start;
        gap: 12px;
    }

    .notifications-page-header .page-header-content {
        min-width: 0;
        flex: 1 1 auto;
    }

    .notifications-page-header .page-header-content h2 {
        font-size: clamp(1.35rem, 7vw, 1.9rem);
        line-height: 1.05;
    }

    .notifications-page-header .page-header-content p {
        display: none;
    }

    .notifications-actions {
        flex: 0 0 auto;
        align-self: flex-start;
        justify-content: flex-end;
        gap: 6px;
    }

    .notifications-actions .notification-action-btn {
        width: 40px;
        min-width: 40px;
        height: 40px;
        min-height: 40px;
        padding: 0;
    }

    .notifications-actions .notification-action-markall {
        width: 40px;
        min-width: 40px;
    }

    .notifications-actions .action-label,
    .notification-row-action span {
        display: none !important;
    }

    .notifications-card-header {
        flex-direction: column;
        align-items: stretch;
    }

    .notification-summary-pills {
        justify-content: flex-start;
    }

    .notifications-full-list {
        padding: 12px;
    }

    .notification-row {
        grid-template-columns: 38px minmax(0, 1fr);
        gap: 12px;
        padding: 12px 12px 12px 14px;
        border-radius: 16px;
    }

    .notification-row-content {
        padding-right: 0;
    }

    .notification-row-icon {
        width: 38px;
        height: 38px;
        border-radius: 13px;
    }

    .notification-row-actions {
        grid-column: 2 / -1;
        justify-content: flex-start;
        flex-wrap: nowrap;
    }

    .notification-row-actions .notification-row-action {
        width: 36px;
        min-width: 36px;
        height: 36px;
        min-height: 36px;
        padding: 0;
    }

    .notification-row-meta {
        flex-direction: column;
        align-items: flex-start;
        gap: 6px;
    }

    .notification-preferences-modal .notification-preferences-box {
        width: calc(100vw - 24px);
        max-height: calc(100dvh - 24px);
    }

    .notification-preferences-modal .product-modal-header {
        padding: 16px;
    }

    .notification-preferences-body {
        min-height: 0;
    }

    .notification-preferences-list {
        padding: 12px;
    }

    .notification-preferences-footer {
        flex-direction: row !important;
        justify-content: space-between !important;
        align-items: center !important;
        padding: 12px 16px !important;
    }

    .notification-preferences-footer .btn {
        min-height: 40px;
    }
}

/* Mobile topbar notification hardening
   Root cause fixed: the dropdown must never participate in topbar flow. */
@media (max-width: 760px) {
    .topbar {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .topbar-actions {
        position: relative;
        display: inline-flex;
        align-items: center;
        justify-content: flex-end;
    }

    .topbar-actions .notification-bell-btn,
    .topbar-actions #forceSyncFacto {
        display: inline-grid !important;
        place-items: center !important;
        flex: 0 0 40px !important;
    }

    .notification-dropdown:not(.is-open) {
        display: none !important;
    }

    .notification-dropdown.is-open {
        display: flex !important;
        position: fixed !important;
    }
}

/* Notification recipient groups */
.notification-groups-box {
    width: min(960px, 96vw) !important;
}

.notification-groups-body {
    background: var(--surface-0);
}

.notification-groups-intro {
    margin: var(--space-5) var(--space-5) 0;
    padding: 14px 16px;
    border: 1px solid var(--border-subtle);
    border-radius: 16px;
    background: color-mix(in srgb, var(--color-primary) 7%, var(--surface-1));
    display: flex;
    flex-direction: column;
    gap: 4px;
    color: var(--text-primary);
}

.notification-groups-intro span {
    color: var(--text-secondary);
    font-size: 0.88rem;
    line-height: 1.45;
}

.notification-groups-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px;
    padding: var(--space-5);
}

.notification-group-card {
    min-width: 0;
    padding: 16px;
    border: 1px solid var(--border-subtle);
    border-radius: 18px;
    background: var(--surface-1);
    box-shadow: var(--shadow-sm);
}

.notification-group-card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}

.notification-group-card-head strong {
    font-size: 1rem;
    line-height: 1.2;
}

.notification-group-card-head span {
    flex: 0 0 auto;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--text-secondary);
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: .02em;
}

.notification-group-card > p {
    margin: 0 0 12px;
    color: var(--text-secondary);
    font-size: 0.84rem;
    line-height: 1.45;
}

.notification-group-users {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.notification-group-user {
    display: grid;
    grid-template-columns: 22px minmax(0, 1fr);
    gap: 10px;
    align-items: center;
    padding: 10px 11px;
    border: 1px solid var(--border-subtle);
    border-radius: 14px;
    background: transparent;
    cursor: pointer;
    transition: background var(--motion-fast), border-color var(--motion-fast), transform var(--motion-fast);
}

.notification-group-user:hover {
    background: var(--surface-2);
    border-color: var(--border-default);
}

.notification-group-user.is-selected {
    background: color-mix(in srgb, var(--color-primary) 8%, var(--surface-1));
    border-color: color-mix(in srgb, var(--color-primary) 32%, var(--border-subtle));
}

.notification-group-user input {
    width: 18px;
    height: 18px;
    accent-color: var(--color-primary);
}

.notification-group-user span {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.notification-group-user strong {
    font-size: 0.88rem;
    line-height: 1.2;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.notification-group-user em {
    font-style: normal;
    font-size: 0.76rem;
    line-height: 1.25;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 760px) {
    .notification-groups-box {
        width: calc(100vw - 24px) !important;
        max-height: calc(100dvh - 24px) !important;
    }

    .notification-groups-intro {
        margin: 12px 12px 0;
        padding: 12px;
    }

    .notification-groups-list {
        grid-template-columns: 1fr;
        padding: 12px;
        gap: 12px;
    }

    .notification-group-card {
        padding: 14px;
    }

    .notification-group-card-head {
        flex-direction: column;
        gap: 6px;
    }
}
