/**
 * Уведомления: липкий колокольчик (fixed) + выпадающая панель.
 * Подключается после theme.css на всех страницах с header_actions.
 */

:root {
    --notifications-top: calc(44px + env(safe-area-inset-top, 0px));
    --notifications-right: max(16px, calc(var(--layout-gutter, 54px) * 0.35));
    --notifications-z: 1100;
}

body.has-email-verification-banner {
    --notifications-top: calc(58px + env(safe-area-inset-top, 0px));
}

/* Якорь в шапке не занимает место в потоке — кнопка fixed */
.header-actions {
    position: static;
    width: 0;
    height: 0;
    overflow: visible;
    pointer-events: none;
}

.app-notifications {
    position: fixed;
    top: var(--notifications-top);
    right: var(--notifications-right);
    z-index: var(--notifications-z);
    pointer-events: auto;
}

.content-header {
    padding-right: 56px;
}

.content-header .header-top {
    padding-right: 56px;
}

/* Кнопка */
.notification-button {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    padding: 0;
    border: 1px solid #EEF1F5;
    border-radius: 12px;
    background: #FFFFFF;
    color: #52A0FF;
    cursor: pointer;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
    transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.notification-button:hover {
    border-color: #93C5FD;
    box-shadow: 0 4px 16px rgba(82, 160, 255, 0.18);
}

.notification-button:focus-visible {
    outline: 2px solid #52A0FF;
    outline-offset: 2px;
}

.notification-button[aria-expanded="true"] {
    border-color: #52A0FF;
    background: #F0F7FF;
}

.notification-button__icon {
    display: block;
    flex-shrink: 0;
}

.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #EF4444;
    color: #FFFFFF;
    font-family: var(--font-primary, 'Manrope', sans-serif);
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
    box-shadow: 0 1px 4px rgba(239, 68, 68, 0.45);
}

.notification-badge:empty,
.notification-badge.is-hidden {
    display: none;
}

/* Панель */
.notifications-panel {
    position: absolute;
    top: calc(100% + 10px);
    right: 0;
    width: min(360px, calc(100vw - 32px));
    max-height: min(420px, calc(100vh - 120px));
    display: flex;
    flex-direction: column;
    border: 1px solid #EEF1F5;
    border-radius: 16px;
    background: #FFFFFF;
    box-shadow: 0 12px 40px rgba(15, 23, 42, 0.14);
    overflow: hidden;
}

.notifications-panel[hidden] {
    display: none !important;
}

.notifications-panel__head {
    flex-shrink: 0;
    padding: 14px 16px 10px;
    border-bottom: 1px solid #EEF1F5;
}

.notifications-panel__title {
    margin: 0;
    font-family: var(--font-primary, 'Manrope', sans-serif);
    font-size: 15px;
    font-weight: 700;
    color: #111827;
}

.notifications-panel__list {
    flex: 1;
    margin: 0;
    padding: 6px 0;
    list-style: none;
    overflow-y: auto;
}

.notifications-panel__item {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.12s ease;
}

.notifications-panel__item:hover {
    background: #F8FAFC;
}

.notifications-panel__item.is-read {
    opacity: 0.72;
}

.notifications-panel__item.is-read .notifications-panel__dot {
    background: transparent;
}

.notifications-panel__icon {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 10px;
    font-size: 0;
    line-height: 0;
}

.notifications-panel__icon svg {
    width: 18px;
    height: 18px;
    display: block;
    flex-shrink: 0;
}

.notifications-panel__icon--request {
    color: #2563EB;
    background: #EFF6FF;
}

.notifications-panel__icon--chat {
    color: #059669;
    background: #ECFDF5;
}

.notifications-panel__icon--system {
    color: #D97706;
    background: #FFF7ED;
}

.notifications-panel__body {
    flex: 1;
    min-width: 0;
}

.notifications-panel__row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 8px;
}

.notifications-panel__label {
    margin: 0 0 4px;
    font-family: var(--font-primary, 'Manrope', sans-serif);
    font-size: 13px;
    font-weight: 600;
    color: #111827;
    line-height: 1.35;
}

.notifications-panel__text {
    margin: 0;
    font-size: 12px;
    color: #64748B;
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.notifications-panel__time {
    flex-shrink: 0;
    font-size: 11px;
    color: #94A3B8;
    white-space: nowrap;
}

.notifications-panel__dot {
    flex-shrink: 0;
    width: 8px;
    height: 8px;
    margin-top: 6px;
    border-radius: 50%;
    background: #52A0FF;
}

.notifications-panel__empty {
    padding: 24px 16px;
    text-align: center;
    font-size: 13px;
    color: #94A3B8;
}

.notifications-panel__footer {
    flex-shrink: 0;
    padding: 10px 16px 14px;
    border-top: 1px solid #EEF1F5;
}

.notifications-panel__mark-all {
    width: 100%;
    height: 36px;
    border: 1px solid #E2E8F0;
    border-radius: 10px;
    background: #F8FAFC;
    color: #334155;
    font-family: var(--font-primary, 'Manrope', sans-serif);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.12s ease, border-color 0.12s ease;
}

.notifications-panel__mark-all:hover {
    background: #EFF6FF;
    border-color: #93C5FD;
    color: #1D4ED8;
}

/* Тёмная тема */
[data-theme="dark"] .notification-button {
    background: var(--tg-bg-card, #1e293b);
    border-color: var(--tg-border, #334155);
    color: #60A5FA;
}

[data-theme="dark"] .notification-button[aria-expanded="true"] {
    background: rgba(96, 165, 250, 0.12);
}

[data-theme="dark"] .notifications-panel {
    background: var(--tg-bg-card, #1e293b);
    border-color: var(--tg-border, #334155);
}

[data-theme="dark"] .notifications-panel__title,
[data-theme="dark"] .notifications-panel__label {
    color: var(--tg-text-primary, #f1f5f9);
}

[data-theme="dark"] .notifications-panel__text {
    color: var(--tg-text-secondary, #94a3b8);
}

[data-theme="dark"] .notifications-panel__item:hover {
    background: rgba(255, 255, 255, 0.04);
}

[data-theme="dark"] .notifications-panel__icon--request {
    color: #60A5FA;
    background: rgba(96, 165, 250, 0.12);
}

[data-theme="dark"] .notifications-panel__icon--chat {
    color: #34D399;
    background: rgba(52, 211, 153, 0.12);
}

[data-theme="dark"] .notifications-panel__icon--system {
    color: #FBBF24;
    background: rgba(251, 191, 36, 0.12);
}

[data-theme="dark"] .notifications-panel__mark-all {
    background: rgba(255, 255, 255, 0.06);
    border-color: var(--tg-border, #334155);
    color: var(--tg-text-primary, #f1f5f9);
}

/* Баннер email — mobile */
@media (max-width: 1100px) {
    body.has-email-verification-banner {
        --notifications-top: calc(72px + env(safe-area-inset-top, 0px));
    }
}

@media (max-width: 768px) {
    :root {
        --notifications-top: calc(var(--m-header-h, 72px) + env(safe-area-inset-top, 0px) + 8px);
        --notifications-right: var(--m-content-pad, 16px);
    }

    body.has-email-verification-banner {
        --notifications-top: calc(var(--m-header-h, 72px) + var(--m-banner-h, 48px) + env(safe-area-inset-top, 0px) + 8px);
    }

    .notifications-panel {
        width: min(360px, calc(100vw - var(--m-content-pad, 16px) * 2));
        max-height: min(420px, calc(100vh - var(--notifications-top) - 80px));
    }
}
