@layer components {
  .notification-wrap {
    position: relative;
    z-index: 3200;
    pointer-events: none;
  }

  .notification-bell {
    position: relative;
    width: 38px;
    height: 36px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.45);
    background: rgba(255, 255, 255, 0.65);
    backdrop-filter: blur(8px);
    cursor: pointer;
    pointer-events: auto;
  }

  .notification-bell:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(15, 23, 42, 0.15);
  }

  .notification-bell-icon {
    font-size: 16px;
  }

  .notification-badge {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 18px;
    height: 18px;
    border-radius: 999px;
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
  }

  .notification-dropdown,
  #notificationDropdown,
  #notificationPanel.notification-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    width: min(392px, calc(100vw - 20px));
    max-height: min(520px, calc(100vh - 84px));
    overflow: hidden;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(203, 213, 225, 0.85);
    backdrop-filter: blur(2px);
    box-shadow: 0 18px 44px rgba(15, 23, 42, 0.14);
    z-index: 3201;
    animation: notificationDropdownIn 140ms ease-out;
    pointer-events: auto;
  }

  .notification-dropdown.hidden,
  #notificationDropdown.hidden,
  #notificationPanel.hidden {
    display: none !important;
    pointer-events: none;
  }

  .notification-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.26);
    background: rgba(255, 255, 255, 0.98);
  }

  .notification-head-title {
    display: flex;
    flex-direction: column;
    gap: 2px;
  }

  .notification-head strong {
    color: #111827;
    font-size: 15px;
    line-height: 1.35;
  }

  .notification-head-count {
    color: #9ca3af;
    font-size: 12px;
    line-height: 1.35;
  }

  .notification-head-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    justify-content: flex-end;
    align-items: center;
    flex-shrink: 0;
  }

  .notification-subbar {
    padding: 8px 12px 10px;
    border-bottom: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(248, 250, 252, 0.65);
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .notification-prefs {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
    font-size: 11px;
    color: #64748b;
  }

  .notification-prefs-label {
    font-weight: 700;
    color: #475569;
    margin-right: 2px;
  }

  .notification-segment {
    display: inline-flex;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.45);
    overflow: hidden;
    background: #fff;
  }

  .notification-seg-btn {
    border: 0;
    background: transparent;
    padding: 5px 10px;
    font-size: 11px;
    font-weight: 650;
    color: #64748b;
    cursor: pointer;
    line-height: 1.2;
  }

  .notification-seg-btn:hover {
    background: rgba(241, 245, 249, 0.9);
    color: #1e293b;
  }

  .notification-seg-btn.is-active {
    background: rgba(59, 130, 246, 0.14);
    color: #1d4ed8;
  }

  .notification-mute-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
    margin-left: auto;
    font-weight: 600;
    color: #475569;
  }

  .notification-mute-label input {
    width: 14px;
    height: 14px;
    accent-color: #2563eb;
  }

  .notification-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
  }

  .notification-tab {
    border: 1px solid rgba(148, 163, 184, 0.4);
    background: rgba(255, 255, 255, 0.85);
    color: #475569;
    font-size: 11px;
    font-weight: 650;
    padding: 5px 11px;
    border-radius: 999px;
    cursor: pointer;
    line-height: 1.2;
  }

  .notification-tab:hover {
    border-color: #94a3b8;
    color: #0f172a;
  }

  .notification-tab.is-active {
    border-color: #3b82f6;
    background: rgba(59, 130, 246, 0.12);
    color: #1d4ed8;
  }

  .notification-list {
    max-height: calc(min(520px, calc(100vh - 84px)) - 118px);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 10px;
    display: grid;
    gap: 10px;
    scrollbar-width: thin;
    scrollbar-color: #cbd5e1 #f1f5f9;
  }

  .notification-item {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    min-height: 68px;
    padding: 12px 13px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    background: #ffffff;
    transition: background-color 140ms ease, border-color 140ms ease;
    cursor: pointer;
    width: 100%;
    box-sizing: border-box;
    font: inherit;
    color: inherit;
    text-align: left;
  }

  .notification-item:hover {
    background: #f8fbff;
    border-color: rgba(148, 163, 184, 0.34);
  }

  .notification-item:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.28);
  }

  .notification-item.unread {
    border-left: 3px solid rgba(59, 130, 246, 0.55);
    padding-left: 10px;
  }

  .notification-item.notification-item--sev-danger {
    border-color: rgba(248, 113, 113, 0.35);
  }

  .notification-item.notification-item--sev-warning {
    border-color: rgba(251, 191, 36, 0.45);
  }

  .notification-item.notification-item--sev-success {
    border-color: rgba(52, 211, 153, 0.4);
  }

  .notification-item.notification-item--sev-info {
    border-color: rgba(148, 163, 184, 0.22);
  }

  .notification-type {
    width: 24px;
    height: 24px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
  }

  .notification-type.red { background: #fee2e2; }
  .notification-type.orange { background: #ffedd5; }
  .notification-type.blue { background: #dbeafe; }

  .notification-body {
    min-width: 0;
    flex: 1;
  }

  .notification-title {
    font-weight: 700;
    font-size: 13px;
    color: #111827;
    line-height: 1.4;
  }

  .notification-message {
    margin-top: 2px;
    font-size: 12px;
    color: #4b5563;
    line-height: 1.45;
    opacity: 1;
    word-break: break-word;
  }

  .notification-time {
    margin-top: 4px;
    font-size: 11px;
    color: #9ca3af;
    line-height: 1.35;
  }

  .notification-item-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
    flex-shrink: 0;
  }

  .notification-dot {
    width: 8px;
    height: 8px;
    border-radius: 999px;
    background: #22c55e;
  }

  .notification-read-btn {
    white-space: nowrap;
  }

  .notification-empty {
    text-align: center;
    padding: 28px 16px 26px;
    color: #64748b;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    line-height: 1.45;
    border-radius: 12px;
    border: 1px dashed rgba(148, 163, 184, 0.45);
    margin: 4px 2px 6px;
    background: linear-gradient(165deg, rgba(248, 250, 252, 0.95), rgba(255, 255, 255, 0.5));
  }

  .notification-empty--filter {
    border-color: rgba(251, 191, 36, 0.45);
    background: linear-gradient(165deg, rgba(255, 251, 235, 0.55), rgba(255, 255, 255, 0.65));
  }

  .notification-empty-title {
    font-weight: 700;
    font-size: 13px;
    color: #334155;
  }

  .notification-empty-desc {
    font-size: 12px;
    color: #64748b;
    max-width: 280px;
  }

  .notification-empty-icon {
    font-size: 22px;
    opacity: 0.88;
  }

  .notification-empty--filter .btn {
    margin-top: 6px;
  }

  .notification-list::-webkit-scrollbar {
    width: 8px;
  }

  .notification-list::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 999px;
  }

  .notification-list::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
  }

  .notification-list::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
  }

  .notification-bell.has-new {
    animation: bellShake 160ms ease-in-out 2;
  }

  .notification-bell.notification-bell--alert-once {
    animation: bellRingOnce 420ms ease-in-out 1, bellGlowPulse 3s ease-out 1;
  }

  @keyframes notificationDropdownIn {
    from {
      opacity: 0;
      transform: translateY(-8px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @keyframes bellShake {
    0% {
      transform: rotate(0deg);
    }
    33% {
      transform: rotate(10deg);
    }
    66% {
      transform: rotate(-8deg);
    }
    100% {
      transform: rotate(0deg);
    }
  }

  @keyframes bellRingOnce {
    0%,
    100% {
      transform: rotate(0deg);
    }
    22% {
      transform: rotate(11deg);
    }
    52% {
      transform: rotate(-9deg);
    }
    78% {
      transform: rotate(4deg);
    }
  }

  @keyframes bellGlowPulse {
    0% {
      box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.38);
    }
    55% {
      box-shadow: 0 0 0 12px rgba(239, 68, 68, 0);
    }
    100% {
      box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
  }
}

body.dark .notification-dropdown,
body.dark #notificationDropdown,
body.dark #notificationPanel.notification-panel {
  background: rgba(15, 23, 42, 0.96);
  border-color: rgba(71, 85, 105, 0.65);
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.45);
}

body.dark .notification-head {
  background: rgba(15, 23, 42, 0.98);
  border-bottom-color: rgba(71, 85, 105, 0.55);
}

body.dark .notification-head strong {
  color: #f1f5f9;
}

body.dark .notification-head-count {
  color: #94a3b8;
}

body.dark .notification-item {
  background: rgba(30, 41, 59, 0.55);
  border-color: rgba(71, 85, 105, 0.55);
}

body.dark .notification-item:hover {
  background: rgba(30, 41, 59, 0.88);
  border-color: rgba(100, 116, 139, 0.55);
}

body.dark .notification-title {
  color: #f8fafc;
}

body.dark .notification-message {
  color: #cbd5e1;
}

body.dark .notification-time {
  color: #64748b;
}

body.dark .notification-bell {
  background: rgba(30, 41, 59, 0.75);
  border-color: rgba(71, 85, 105, 0.65);
}

body.dark .notification-subbar {
  background: rgba(15, 23, 42, 0.55);
  border-bottom-color: rgba(71, 85, 105, 0.5);
}

body.dark .notification-prefs,
body.dark .notification-mute-label {
  color: #94a3b8;
}

body.dark .notification-prefs-label {
  color: #e2e8f0;
}

body.dark .notification-segment {
  border-color: rgba(71, 85, 105, 0.65);
  background: rgba(15, 23, 42, 0.45);
}

body.dark .notification-seg-btn {
  color: #cbd5e1;
}

body.dark .notification-seg-btn:hover {
  background: rgba(30, 41, 59, 0.85);
  color: #f8fafc;
}

body.dark .notification-seg-btn.is-active {
  background: rgba(37, 99, 235, 0.28);
  color: #e0f2fe;
}

body.dark .notification-tab {
  background: rgba(15, 23, 42, 0.45);
  border-color: rgba(71, 85, 105, 0.55);
  color: #cbd5e1;
}

body.dark .notification-tab.is-active {
  border-color: #60a5fa;
  background: rgba(37, 99, 235, 0.22);
  color: #e0f2fe;
}

body.dark .notification-empty {
  border-color: rgba(71, 85, 105, 0.55);
  background: linear-gradient(165deg, rgba(15, 23, 42, 0.75), rgba(30, 41, 59, 0.35));
}

body.dark .notification-empty-title {
  color: #e2e8f0;
}

body.dark .notification-empty-desc {
  color: #94a3b8;
}

/* Body-level overlay + panel (outside topbar transform containing block) */
.notification-backdrop,
.notification-mobile-backdrop {
  position: fixed;
  inset: 0;
  z-index: 9000;
  background: rgba(15, 23, 42, 0.42);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  opacity: 1;
  transition: opacity 160ms ease;
}

.notification-backdrop.hidden,
.notification-mobile-backdrop.hidden {
  display: none !important;
  pointer-events: none !important;
  opacity: 0;
}

#notificationPanel.notification-panel {
  position: fixed;
  z-index: 9001;
  top: 72px;
  right: 24px;
  left: auto;
  bottom: auto;
  width: 360px;
  max-width: calc(100vw - 32px);
  max-height: 70dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid rgba(203, 213, 225, 0.85);
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.18);
  pointer-events: auto;
  animation: notificationDropdownIn 140ms ease-out;
}

#notificationPanel.notification-panel.hidden {
  display: none !important;
  pointer-events: none !important;
}

#notificationPanel .notification-list {
  flex: 1 1 auto;
  min-height: 0;
  max-height: calc(70dvh - 132px);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

body.notification-panel-open,
html.notification-panel-open {
  overflow: hidden;
}

body.notification-panel-open #app {
  overflow: hidden;
}

/* Mobile owner: bell panel as bottom sheet */
@media (max-width: 768px) {
  body.use-new-ui .notification-wrap {
    position: relative;
    z-index: calc(var(--z-mobile-sheet, 6200) + 2);
    pointer-events: auto;
  }

  body.use-new-ui .notification-bell,
  body.use-new-ui .notification-badge {
    pointer-events: auto;
  }

  #notificationPanel.notification-panel {
    left: 12px;
    right: 12px;
    top: auto;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-width: none;
    max-height: min(70dvh, 520px);
    border-radius: 24px;
    box-shadow: 0 -12px 40px rgba(15, 23, 42, 0.22);
    animation: notificationSheetIn 160ms ease-out;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  #notificationPanel .notification-list {
    max-height: min(52dvh, 420px);
  }

  body.use-new-ui .notification-head-actions .notification-close-btn {
    min-width: 36px;
    min-height: 36px;
    padding: 0;
    border-radius: 10px;
    font-size: 18px;
    line-height: 1;
  }

  @keyframes notificationSheetIn {
    from {
      opacity: 0;
      transform: translateY(12px);
    }
    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  body.use-new-ui .notification-seg-btn,
  body.use-new-ui .notification-tab {
    min-height: 40px;
    padding: 8px 10px;
  }
}

@media (max-width: 640px) {
  #notificationPanel.notification-panel {
    left: 12px;
    right: 12px;
    bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }
}
