/* Shared Study Hub top-bar actions, search, and notifications */

.topbar-sr-only {
    position: absolute !important;
    width: 1px !important;
    height: 1px !important;
    padding: 0 !important;
    margin: -1px !important;
    overflow: hidden !important;
    clip: rect(0, 0, 0, 0) !important;
    white-space: nowrap !important;
    border: 0 !important;
}

.study-topbar__right {
    position: relative;
    gap: 8px;
}

.study-topbar__icon-btn {
    --topbar-action-accent: #64748b;
    --topbar-action-tint: rgba(100, 116, 139, 0.1);
    position: relative;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 12px;
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.96), rgba(248, 250, 252, 0.82));
    color: var(--text-secondary, #475569);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    font: inherit;
    font-size: 1.16rem;
    line-height: 1;
    cursor: pointer;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), inset 0 1px 0 rgba(255, 255, 255, 0.7);
    transition: transform 160ms ease, border-color 160ms ease, color 160ms ease, background 160ms ease, box-shadow 160ms ease;
}

[data-theme="dark"] .study-topbar__icon-btn {
    background: linear-gradient(145deg, rgba(30, 41, 59, 0.92), rgba(15, 23, 42, 0.88));
    border-color: rgba(148, 163, 184, 0.18);
    box-shadow: 0 3px 14px rgba(2, 6, 23, 0.18), inset 0 1px 0 rgba(255, 255, 255, 0.035);
}

.study-topbar__icon-btn[data-study-action="search"] {
    --topbar-action-accent: #2563eb;
    --topbar-action-tint: rgba(37, 99, 235, 0.11);
}

.study-topbar__icon-btn[data-study-action="notifications"] {
    --topbar-action-accent: #7c3aed;
    --topbar-action-tint: rgba(124, 58, 237, 0.11);
}

.study-topbar__icon-btn:hover,
.study-topbar__icon-btn.is-active {
    transform: translateY(-1px);
    border-color: var(--topbar-action-accent);
    background: var(--topbar-action-tint);
    color: var(--topbar-action-accent);
    box-shadow: 0 8px 18px rgba(15, 23, 42, 0.1);
}

.study-topbar__icon-btn:active {
    transform: translateY(0) scale(0.97);
}

.study-topbar__icon-btn:focus-visible {
    outline: 3px solid rgba(59, 130, 246, 0.24);
    outline-offset: 2px;
    border-color: var(--topbar-action-accent);
}

.study-topbar__icon-btn > i {
    transition: transform 160ms ease;
}

.study-topbar__icon-btn:hover > i,
.study-topbar__icon-btn.is-active > i {
    transform: scale(1.06);
}

.study-topbar__notif-badge {
    position: absolute;
    top: -5px;
    right: -5px;
    min-width: 19px;
    height: 19px;
    padding: 0 5px;
    border: 2px solid var(--bg-surface, #fff);
    border-radius: 999px;
    background: #e11d48;
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.63rem;
    font-weight: 800;
    line-height: 1;
    letter-spacing: -0.02em;
    box-shadow: 0 3px 8px rgba(225, 29, 72, 0.3);
}

.study-topbar__notif-badge[hidden] {
    display: none !important;
}

[data-theme="dark"] .study-topbar__notif-badge {
    border-color: #0f172a;
}

.topbar-notif-dropdown {
    position: fixed;
    top: var(--topbar-notif-top, 72px);
    right: var(--topbar-notif-right, 24px);
    width: min(390px, calc(100vw - 28px));
    max-height: min(620px, calc(100vh - 92px));
    overflow: hidden;
    padding: 0;
    background: var(--bg-surface, #fff);
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 20px;
    box-shadow: 0 24px 70px rgba(15, 23, 42, 0.18), 0 2px 8px rgba(15, 23, 42, 0.08);
    z-index: 10020;
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translateY(-7px) scale(0.985);
    transform-origin: top right;
    transition: opacity 170ms ease, visibility 170ms ease, transform 170ms cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] .topbar-notif-dropdown {
    border-color: rgba(148, 163, 184, 0.16);
    box-shadow: 0 26px 80px rgba(2, 6, 23, 0.62), 0 2px 8px rgba(2, 6, 23, 0.36);
}

.topbar-notif-dropdown.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
    transform: translateY(0) scale(1);
}

.topbar-notif-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 19px 16px;
    border-bottom: 1px solid var(--border-glass, rgba(148, 163, 184, 0.2));
}

.topbar-notif-eyebrow {
    display: block;
    margin-bottom: 2px;
    color: #7c3aed;
    font-size: 0.67rem;
    font-weight: 800;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.topbar-notif-header h2 {
    margin: 0;
    color: var(--text-primary, #0f172a);
    font-size: 1.05rem;
    font-weight: 750;
    line-height: 1.25;
}

.topbar-notif-count {
    flex: 0 0 auto;
    padding: 5px 9px;
    border-radius: 999px;
    background: rgba(124, 58, 237, 0.1);
    color: #7c3aed;
    font-size: 0.72rem;
    font-weight: 750;
}

.topbar-notif-count.is-clear {
    background: rgba(16, 185, 129, 0.1);
    color: #059669;
}

.topbar-notif-list {
    max-height: min(450px, calc(100vh - 218px));
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.topbar-notif-item {
    position: relative;
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-height: 82px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border-glass, rgba(148, 163, 184, 0.16));
    color: inherit;
    text-decoration: none;
    transition: background 150ms ease;
}

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

.topbar-notif-item:hover,
.topbar-notif-item:focus-visible {
    background: rgba(148, 163, 184, 0.09);
    outline: none;
}

.topbar-notif-item.is-unread {
    background: linear-gradient(90deg, rgba(124, 58, 237, 0.07), transparent 70%);
}

.topbar-notif-item.is-unread:hover,
.topbar-notif-item.is-unread:focus-visible {
    background: linear-gradient(90deg, rgba(124, 58, 237, 0.12), rgba(148, 163, 184, 0.06));
}

.topbar-notif-icon {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.14rem;
}

.topbar-notif-icon--purple { color: #7c3aed; background: rgba(124, 58, 237, 0.11); }
.topbar-notif-icon--blue { color: #2563eb; background: rgba(37, 99, 235, 0.11); }
.topbar-notif-icon--green { color: #059669; background: rgba(5, 150, 105, 0.11); }
.topbar-notif-icon--amber { color: #d97706; background: rgba(217, 119, 6, 0.11); }

.topbar-notif-content {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.topbar-notif-title {
    color: var(--text-primary, #0f172a);
    font-size: 0.88rem;
    font-weight: 700;
    line-height: 1.3;
}

.topbar-notif-desc {
    color: var(--text-secondary, #64748b);
    font-size: 0.77rem;
    line-height: 1.42;
}

.topbar-notif-time {
    margin-top: 2px;
    color: var(--text-muted, #94a3b8);
    font-size: 0.69rem;
    font-weight: 600;
}

.topbar-notif-unread-dot {
    width: 7px;
    height: 7px;
    flex: 0 0 7px;
    margin-top: 7px;
    border-radius: 50%;
    background: #7c3aed;
    box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.1);
}

.topbar-notif-arrow {
    align-self: center;
    color: var(--text-muted, #94a3b8);
    font-size: 0.85rem;
    transition: transform 150ms ease, color 150ms ease;
}

.topbar-notif-item:hover .topbar-notif-arrow {
    color: #7c3aed;
    transform: translateX(2px);
}

.topbar-notif-footer {
    padding: 10px 12px;
    border-top: 1px solid var(--border-glass, rgba(148, 163, 184, 0.16));
    background: rgba(148, 163, 184, 0.045);
}

.topbar-notif-footer[hidden] {
    display: none;
}

.topbar-notif-footer button {
    width: 100%;
    min-height: 38px;
    border: 0;
    border-radius: 10px;
    background: transparent;
    color: var(--text-secondary, #475569);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    font: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 150ms ease, color 150ms ease;
}

.topbar-notif-footer button:hover,
.topbar-notif-footer button:focus-visible {
    background: rgba(124, 58, 237, 0.09);
    color: #7c3aed;
    outline: none;
}

.topbar-notif-empty {
    min-height: 245px;
    padding: 34px 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    text-align: center;
}

.topbar-notif-empty__icon,
.topbar-search-empty__icon {
    width: 54px;
    height: 54px;
    margin-bottom: 14px;
    border-radius: 17px;
    background: rgba(124, 58, 237, 0.1);
    color: #7c3aed;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.55rem;
}

.topbar-notif-empty strong,
.topbar-search-empty strong {
    color: var(--text-primary, #0f172a);
    font-size: 0.94rem;
}

.topbar-notif-empty > span:last-child,
.topbar-search-empty > span:last-child {
    max-width: 270px;
    margin-top: 6px;
    color: var(--text-secondary, #64748b);
    font-size: 0.78rem;
    line-height: 1.45;
}

.topbar-modal-open {
    overflow: hidden;
}

.topbar-search-overlay {
    position: fixed;
    inset: 0;
    z-index: 10010;
    padding: max(10vh, 72px) 20px 24px;
    background: rgba(15, 23, 42, 0.48);
    -webkit-backdrop-filter: blur(10px) saturate(0.85);
    backdrop-filter: blur(10px) saturate(0.85);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 180ms ease, visibility 180ms ease;
}

.topbar-search-overlay.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

.topbar-search-modal {
    width: min(700px, 100%);
    max-height: min(720px, calc(100vh - max(18vh, 112px)));
    margin: 0 auto;
    overflow: hidden;
    padding: 0;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface, #fff);
    border: 1px solid rgba(255, 255, 255, 0.38);
    border-radius: 22px;
    box-shadow: 0 34px 100px rgba(15, 23, 42, 0.34), 0 4px 16px rgba(15, 23, 42, 0.16);
    transform: translateY(-10px) scale(0.975);
    transform-origin: top center;
    transition: transform 200ms cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] .topbar-search-modal {
    border-color: rgba(148, 163, 184, 0.16);
    box-shadow: 0 38px 110px rgba(2, 6, 23, 0.72);
}

.topbar-search-overlay.active .topbar-search-modal {
    transform: translateY(0) scale(1);
}

.topbar-search-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 20px 8px;
    color: var(--text-primary, #0f172a);
    font-size: 0.76rem;
    font-weight: 780;
    letter-spacing: 0.07em;
    text-transform: uppercase;
}

.topbar-search-shortcut {
    padding: 4px 8px;
    border: 1px solid var(--border-glass, rgba(148, 163, 184, 0.22));
    border-radius: 7px;
    background: var(--bg-dark, #f8fafc);
    color: var(--text-muted, #94a3b8);
    font-size: 0.65rem;
    letter-spacing: 0;
    text-transform: none;
}

.topbar-search-input-wrap {
    display: flex;
    align-items: center;
    gap: 13px;
    margin: 0 12px 10px;
    padding: 11px 12px 11px 15px;
    border: 1px solid rgba(37, 99, 235, 0.18);
    border-radius: 14px;
    background: rgba(37, 99, 235, 0.055);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.18);
    transition: border-color 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.topbar-search-input-wrap:focus-within {
    border-color: rgba(37, 99, 235, 0.48);
    background: rgba(37, 99, 235, 0.075);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.11);
}

.topbar-search-input-wrap > i {
    flex: 0 0 auto;
    color: #2563eb;
    font-size: 1.35rem;
}

#topbarSearchInput {
    min-width: 0;
    flex: 1;
    border: 0;
    outline: 0;
    background: transparent;
    color: var(--text-primary, #0f172a);
    font: inherit;
    font-size: 1rem;
    line-height: 1.4;
}

#topbarSearchInput::placeholder {
    color: var(--text-muted, #94a3b8);
}

#topbarSearchInput::-webkit-search-cancel-button {
    display: none;
}

.topbar-search-close {
    min-width: 42px;
    height: 34px;
    padding: 0 9px;
    border: 1px solid var(--border-glass, rgba(148, 163, 184, 0.24));
    border-radius: 9px;
    background: var(--bg-surface, #fff);
    color: var(--text-muted, #64748b);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    font: inherit;
    font-size: 0.64rem;
    font-weight: 750;
    cursor: pointer;
    transition: color 150ms ease, border-color 150ms ease, background 150ms ease;
}

.topbar-search-close i {
    display: none;
}

.topbar-search-close:hover,
.topbar-search-close:focus-visible {
    border-color: #2563eb;
    background: rgba(37, 99, 235, 0.08);
    color: #2563eb;
    outline: none;
}

.topbar-search-results {
    min-height: 210px;
    max-height: min(475px, calc(100vh - 265px));
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 4px 10px 10px;
    scrollbar-width: thin;
}

.topbar-search-group + .topbar-search-group {
    margin-top: 9px;
}

.topbar-search-group {
    margin: 0;
    padding: 0;
}

.topbar-search-group-label {
    padding: 8px 10px 6px;
    color: var(--text-muted, #94a3b8);
    font-size: 0.67rem;
    font-weight: 800;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.topbar-search-result-item {
    --result-accent: #2563eb;
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 62px;
    padding: 9px 11px;
    border: 1px solid transparent;
    border-radius: 13px;
    color: var(--text-primary, #0f172a);
    text-decoration: none;
    transition: background 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.topbar-search-result-item:hover,
.topbar-search-result-item:focus-visible,
.topbar-search-result-item.active {
    border-color: rgba(148, 163, 184, 0.15);
    background: rgba(148, 163, 184, 0.09);
    outline: none;
}

.topbar-search-result-icon {
    width: 40px;
    height: 40px;
    flex: 0 0 40px;
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: 12px;
    background: var(--bg-dark, #f8fafc);
    color: var(--result-accent);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.16rem;
    transition: background 140ms ease, color 140ms ease, border-color 140ms ease, transform 140ms ease;
}

.topbar-search-result-item:hover .topbar-search-result-icon,
.topbar-search-result-item:focus-visible .topbar-search-result-icon,
.topbar-search-result-item.active .topbar-search-result-icon {
    border-color: var(--result-accent);
    background: var(--result-accent);
    color: #fff;
    transform: scale(1.03);
}

.topbar-search-result-text {
    min-width: 0;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.topbar-search-result-title {
    overflow: hidden;
    color: var(--text-primary, #0f172a);
    font-size: 0.88rem;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-search-result-desc {
    overflow: hidden;
    color: var(--text-secondary, #64748b);
    font-size: 0.74rem;
    line-height: 1.3;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.topbar-search-result-badge {
    flex: 0 0 auto;
    padding: 4px 8px;
    border-radius: 999px;
    background: var(--bg-dark, #f8fafc);
    color: var(--text-muted, #64748b);
    font-size: 0.64rem;
    font-weight: 700;
}

.topbar-search-result-arrow {
    display: none;
    flex: 0 0 auto;
    color: var(--result-accent);
    font-size: 0.9rem;
}

.topbar-search-result-item.active .topbar-search-result-badge,
.topbar-search-result-item:hover .topbar-search-result-badge {
    display: none;
}

.topbar-search-result-item.active .topbar-search-result-arrow,
.topbar-search-result-item:hover .topbar-search-result-arrow {
    display: block;
}

.topbar-search-empty {
    min-height: 250px;
    padding: 38px 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    text-align: center;
}

.topbar-search-empty__icon {
    background: rgba(37, 99, 235, 0.1);
    color: #2563eb;
}

.topbar-search-footer {
    min-height: 44px;
    padding: 9px 18px;
    border-top: 1px solid var(--border-glass, rgba(148, 163, 184, 0.16));
    background: rgba(148, 163, 184, 0.045);
    color: var(--text-muted, #94a3b8);
    display: flex;
    align-items: center;
    gap: 18px;
    font-size: 0.67rem;
    font-weight: 600;
}

.topbar-search-footer span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.topbar-search-footer kbd {
    min-width: 22px;
    height: 22px;
    padding: 0 5px;
    border: 1px solid var(--border-glass, rgba(148, 163, 184, 0.22));
    border-bottom-width: 2px;
    border-radius: 6px;
    background: var(--bg-surface, #fff);
    color: var(--text-secondary, #64748b);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    font-size: 0.63rem;
}

@media (max-width: 640px) {
    .study-topbar__right {
        gap: 6px;
    }

    .study-topbar__icon-btn {
        width: 40px;
        height: 40px;
        flex-basis: 40px;
        border-radius: 11px;
    }

    .topbar-notif-dropdown {
        position: fixed;
        top: auto !important;
        right: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom, 0px));
        left: 12px;
        width: auto;
        max-height: min(76vh, 620px);
        border-radius: 20px;
        transform: translateY(14px) scale(0.99);
        transform-origin: bottom center;
    }

    .topbar-notif-dropdown.active {
        transform: translateY(0) scale(1);
    }

    .topbar-notif-list {
        max-height: calc(min(76vh, 620px) - 128px);
    }

    .topbar-search-overlay {
        padding: 12px;
        padding-top: calc(12px + env(safe-area-inset-top, 0px));
        display: flex;
        align-items: flex-end;
    }

    .topbar-search-modal {
        width: 100%;
        max-height: min(86vh, 720px);
        margin: 0;
        border-radius: 20px;
        transform: translateY(18px) scale(0.99);
        transform-origin: bottom center;
    }

    .topbar-search-overlay.active .topbar-search-modal {
        transform: translateY(0) scale(1);
    }

    .topbar-search-heading {
        padding: 14px 15px 7px;
    }

    .topbar-search-input-wrap {
        gap: 10px;
        margin: 0 9px 8px;
        padding: 9px 9px 9px 12px;
    }

    #topbarSearchInput {
        font-size: 0.95rem;
    }

    .topbar-search-close {
        width: 38px;
        min-width: 38px;
        height: 36px;
        padding: 0;
    }

    .topbar-search-close span {
        display: none;
    }

    .topbar-search-close i {
        display: block;
        font-size: 1rem;
    }

    .topbar-search-results {
        max-height: calc(min(86vh, 720px) - 150px);
        padding: 3px 7px 9px;
    }

    .topbar-search-result-item {
        min-height: 58px;
        padding: 8px 9px;
        gap: 10px;
    }

    .topbar-search-result-desc,
    .topbar-search-result-badge {
        display: none !important;
    }

    .topbar-search-result-item.active .topbar-search-result-arrow,
    .topbar-search-result-item:hover .topbar-search-result-arrow {
        display: block;
    }

    .topbar-search-footer {
        display: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    .study-topbar__icon-btn,
    .study-topbar__icon-btn > i,
    .topbar-notif-dropdown,
    .topbar-search-overlay,
    .topbar-search-modal,
    .topbar-search-result-item,
    .topbar-search-result-icon {
        transition: none !important;
    }
}
