/* ============================================================
 * user_ui — Notification center chrome (Phase 7 Package I).
 * ============================================================
 *
 * Top-right dropdown panel anchored below the header bell.
 * Theme-aware (uses --surface-2 / --text / --line tokens),
 * matching the Package H help panel's visual language — both
 * are user-content-shaped surfaces sitting over arbitrary
 * page content where light/dark cohesion matters.
 *
 * Section-local classes (no canonical mockup equivalents —
 * the landing-page mockup doesn't spec a notification panel,
 * so this is a fresh design built strictly from
 * DESIGN_SYSTEM.md tokens; the owner-supplied mockup will
 * land alongside Package K and any refinements file into
 * Package NN at the end of Phase 7).
 *
 *   - .site-notifications              outer container (no layout)
 *   - .site-notifications-panel        380-wide popover anchored top-right
 *   - .site-notifications-header       title row + mark-all-read
 *   - .site-notifications-title        panel heading
 *   - .site-notifications-mark-all     mark-all-read button
 *   - .site-notifications-body         scrollable content region
 *   - .site-notifications-loading      loading state
 *   - .site-notifications-empty        empty state
 *   - .site-notifications-error        error state + retry
 *   - .site-notifications-retry        retry button
 *   - .site-notifications-list         <ul> of items
 *   - .site-notifications-li           <li> wrapper — flex row:
 *                                      content (flex:1) + bin column
 *   - .site-notifications-item         single notification row
 *   - .site-notifications-item-delete  always-visible delete (bin)
 *                                      column on the row's right,
 *                                      divider line, full row height
 *   - .site-notifications-item.is-unread
 *                                      unread row tint + dot indicator
 *   - .site-notifications-item-title   item title (Saira 600 / 14)
 *   - .site-notifications-item-body    item body (Work Sans 400 / 13)
 *   - .site-notifications-item-time    item timestamp (mono 11)
 *   - .site-notifications-item-dot     unread indicator
 *   - .is-open                         applied to .site-notifications when panel open
 *   - .is-hidden-by-drawer             applied while a mobile drawer is open
 *
 * Z-index budget (cross-chrome contract, see help.css §0):
 *   - .site-notifications-panel        120  (above help, below menus)
 *   - .site-help-button                100
 *   - .site-help-panel                 110
 *   - .mobile-menus-backdrop           150  (Package G — wins)
 *   - .mobile-drawer                   200  (Package G — wins)
 *
 * The Component force-closes + hides on `menus.opened` so
 * the ordering above is belt-and-braces.
 *
 * Loaded by `base.html` as part of the global cascade after
 * help/help.css, before `{% block extra_css %}`.
 * ============================================================ */

/* ============================================================
 * 1. Container — logical group only, no visual effect.
 *    Panel is position:fixed; container is layout-inert.
 * ============================================================ */
.site-notifications {
    /* No layout — child panel is position:fixed. */
}

/* ============================================================
 * 2. Panel — theme-aware popover anchored directly under the
 *    header BELL (fix pass): the Component measures the bell's
 *    bounding rect on open (+ on resize while open) and writes
 *    `--notif-anchor-top` / `--notif-anchor-right` onto the
 *    panel, so the panel's top-right corner sits 8px below the
 *    bell with right edges aligned — wherever the bell actually
 *    is. The static 72px/24px values remain only as fallbacks
 *    for the pathological case where the bell can't be measured
 *    (missing header partial). Transform-origin top right gives
 *    the scale-in a natural "growing out of the bell" feel.
 *
 *    On phone (≤480px) the media query in §12 overrides with a
 *    full-width sheet — its literal top/right/left declarations
 *    beat the var()-based ones by cascade order, so the anchor
 *    vars are simply ignored there.
 *
 *    Closed state hides via opacity + pointer-events (NOT
 *    display:none) so the open/close transition can play.
 *    `display: none` would skip the transition entirely.
 * ============================================================ */
.site-notifications-panel {
    position: fixed;
    top: var(--notif-anchor-top, 72px);
    right: var(--notif-anchor-right, 24px);
    z-index: 120;
    width: 380px;
    max-width: calc(100vw - 48px);
    max-height: calc(100vh - 96px);
    display: flex;
    flex-direction: column;
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.18);
    opacity: 0;
    transform: scale(0.96) translateY(-8px);
    transform-origin: top right;
    pointer-events: none;
    transition: opacity 200ms ease-out, transform 200ms ease-out;
    overflow: hidden;
}
.site-notifications.is-open .site-notifications-panel {
    opacity: 1;
    transform: scale(1) translateY(0);
    pointer-events: auto;
}

/* ============================================================
 * 3. Header — title + mark-all-read.
 *    Saira 700 / 16, with a small-padding Work Sans 500 / 12
 *    text-button on the right. Bottom border separates from
 *    list to avoid the scrollable region bleeding into the
 *    header on overscroll.
 * ============================================================ */
.site-notifications-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 18px 14px;
    border-bottom: 1px solid var(--line-2);
    flex-shrink: 0;
}
.site-notifications-title {
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 16px;
    line-height: 1.2;
    color: var(--text);
    margin: 0;
}
.site-notifications-mark-all {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--orange);
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 12px;
    padding: 4px 6px;
    border-radius: 6px;
    cursor: pointer;
    transition: background 120ms ease-out, color 120ms ease-out;
}
.site-notifications-mark-all:hover:not(:disabled) {
    background: var(--chip);
    color: var(--orange-2);
}
.site-notifications-mark-all:focus-visible {
    outline: 2px solid var(--orange);
    outline-offset: 2px;
}
.site-notifications-mark-all:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* ============================================================
 * 4. Body — scrollable content region.
 *    Holds the loading / empty / error states AND the list.
 *    Only one of those four is visible at any time (JS toggles
 *    `hidden` on the inactive ones).
 *
 *    Min-height keeps the panel from collapsing to a sliver
 *    during the first fetch (empty list + loading visible);
 *    max-height caps panel height at viewport-friendly size.
 *
 *    Fix pass: the visible-row cap (5 rows before the body
 *    scrolls) is applied by JS as an inline max-height computed
 *    from the first five rendered rows' real heights — rows
 *    vary (body text optional, 1–2 lines), so a static CSS
 *    value can't be accurate. The panel's own viewport
 *    max-height still wins when smaller.
 * ============================================================ */
.site-notifications-body {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 200px;
}

/* ============================================================
 * 5. Loading / empty / error states.
 *    All centred, padded, body-typography.
 * ============================================================ */
/* BUG FIX (fix pass): these three state elements declare
   `display: flex`, and any author `display` declaration beats the
   UA stylesheet's `[hidden] { display: none }` regardless of
   specificity origin. Result: once JS un-hid a state, re-adding the
   `hidden` attribute had NO visual effect — loading + empty + error
   + list all stacked in the panel simultaneously. The explicit
   `[hidden]` rules below restore the attribute's contract for every
   state element (list included, belt-and-braces — it currently has
   no author `display` but a future rule must not re-break this). */
.site-notifications-loading[hidden],
.site-notifications-empty[hidden],
.site-notifications-error[hidden],
.site-notifications-list[hidden] {
    display: none;
}

.site-notifications-loading,
.site-notifications-empty,
.site-notifications-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 24px;
    min-height: 200px;
}
.site-notifications-loading-text,
.site-notifications-empty-text,
.site-notifications-error-text {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-dim);
    margin: 0 0 8px 0;
}
.site-notifications-empty-icon {
    width: 40px;
    height: 40px;
    color: var(--text-mute);
    margin-bottom: 12px;
    opacity: 0.6;
}
.site-notifications-retry {
    appearance: none;
    border: 1.5px solid var(--text);
    background: transparent;
    color: var(--text);
    font-family: var(--font-head);
    font-weight: 700;
    font-size: 13px;
    letter-spacing: 0.04em;
    padding: 8px 16px;
    border-radius: var(--radius-btn);
    cursor: pointer;
    margin-top: 8px;
    transition: background 120ms ease-out, color 120ms ease-out;
}
.site-notifications-retry:hover {
    background: var(--text);
    color: var(--surface-2);
}
.site-notifications-retry:focus-visible {
    outline: 2px solid var(--orange);
    outline-offset: 2px;
}

/* ============================================================
 * 6. List — vertical stack of notification items.
 *    No bullets (role="list" + listStyle reset). Items are
 *    `<li>` for semantics; click delegation lives on the list.
 * ============================================================ */
.site-notifications-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

/* ============================================================
 * 6b. Item wrapper <li> + delete (bin) column — fix pass,
 *     reworked round 3: the bin is ALWAYS VISIBLE as a fixed-
 *     width right column spanning the full row height,
 *     separated from the row content by a vertical divider —
 *     one big obvious target on every device, no reveal
 *     gesture needed. The row itself renders as <a> or
 *     <button>, so the bin CANNOT live inside it (nested
 *     interactive elements are invalid HTML and break AT);
 *     it's a flex SIBLING inside the <li>.
 *
 *     Layout:  <li> = flex row
 *              ├─ .site-notifications-item     (flex: 1)
 *              └─ .site-notifications-item-delete
 *                 (fixed 48px column, border-left divider,
 *                  stretches to the row's full height)
 *
 *     The per-row bottom border moves from the row element to
 *     the <li> so the divider line runs under the bin column
 *     too.
 * ============================================================ */
.site-notifications-li {
    position: relative;
    list-style: none;
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid var(--line-2);
}
.site-notifications-li:last-child {
    border-bottom: 0;
}
.site-notifications-item-delete {
    flex: 0 0 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    appearance: none;
    border: 0;
    border-left: 1px solid var(--line-2);
    border-radius: 0;
    background: transparent;
    color: var(--text-mute);
    cursor: pointer;
    transition: background 120ms ease-out, color 120ms ease-out;
}
.site-notifications-item-delete svg {
    width: 16px;
    height: 16px;
}
.site-notifications-item-delete:hover,
.site-notifications-item-delete:focus-visible {
    background: color-mix(in srgb, var(--danger, #e5484d) 12%, transparent);
    color: var(--danger, #e5484d);
}
.site-notifications-item-delete:focus-visible {
    outline: 2px solid var(--danger, #e5484d);
    outline-offset: -2px;
}

/* ============================================================
 * 7. Item — single notification row.
 *    Row layout: title row (title + time-ago) + body. Unread
 *    rows get a left-orange-accent + faint orange tint to
 *    catch the eye.
 *
 *    Hover/focus highlight on interactive rows (which is all
 *    of them — every item is either an <a> with link_url or a
 *    <button>-like role; click marks read).
 * ============================================================ */
.site-notifications-item {
    /* Used by BOTH <a> (when link_url is set) and <button> (otherwise) —
       see notifications.js #render_item_html. The button-reset block
       normalises native <button> chrome so the two render identically:
       no inset border, no agent-supplied background, font inherits from
       container, full-width text-align:left so the layout matches the
       <a> branch. */
    appearance: none;
    -webkit-appearance: none;
    border: 0;
    background: none;
    font: inherit;
    color: var(--text);
    text-align: left;
    width: 100%;
    line-height: inherit;
    /* End reset — original row styling below. */
    display: block;
    padding: 14px 18px;
    /* Round 3: the per-row bottom border lives on the <li> wrapper
       (see §6b) so the divider runs under the bin column too; the
       row is a flex child (flex: 1) of the <li>. */
    flex: 1;
    min-width: 0;
    text-decoration: none;
    cursor: pointer;
    transition: background 120ms ease-out;
    position: relative;
}
.site-notifications-item:hover,
.site-notifications-item:focus-visible {
    background: var(--chip);
    outline: none;
}
.site-notifications-item:focus-visible {
    /* Keep keyboard focus visible — outline on inner content
       since the row itself has chip background. */
    box-shadow: inset 2px 0 0 var(--orange);
}

/* Unread tint + left-accent. The 3px orange bar sits flush
   left; padding-left is bumped so the title doesn't collide
   with the accent. */
.site-notifications-item.is-unread {
    padding-left: 18px;
    box-shadow: inset 3px 0 0 var(--orange);
    background: color-mix(in srgb, var(--orange) 6%, transparent);
}
.site-notifications-item.is-unread:hover,
.site-notifications-item.is-unread:focus-visible {
    background: color-mix(in srgb, var(--orange) 10%, transparent);
}

/* ============================================================
 * 8. Item — title + time-ago row.
 * ============================================================ */
.site-notifications-item-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
}
.site-notifications-item-title {
    font-family: var(--font-head);
    font-weight: 600;
    font-size: 14px;
    line-height: 1.3;
    color: var(--text);
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}
.site-notifications-item-time {
    font-family: var(--font-mono);
    font-weight: 500;
    font-size: 11px;
    letter-spacing: 0.04em;
    color: var(--text-mute);
    flex-shrink: 0;
    white-space: nowrap;
}

/* ============================================================
 * 9. Item — body text.
 *    Line-clamp at 2 — overflowing bodies truncate with
 *    ellipsis. Full body is in the notification, link click
 *    navigates to its link_url which has the full context.
 * ============================================================ */
.site-notifications-item-body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: 13px;
    line-height: 1.5;
    color: var(--text-dim);
    margin: 0;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ============================================================
 * 10. Hidden by drawer.
 *     Applied to .site-notifications root while a mobile
 *     drawer is open. Pulls the panel out of view so it
 *     never overlaps the drawer. Component subscribes to
 *     menus.opened / menus.closed.
 * ============================================================ */
.site-notifications.is-hidden-by-drawer .site-notifications-panel {
    display: none;
}

/* ============================================================
 * 11. Reduced motion — disable open/close animation.
 * ============================================================ */
@media (prefers-reduced-motion: reduce) {
    .site-notifications-panel,
    .site-notifications-item-delete {
        transition: none;
    }
}

/* ============================================================
 * 12. Small viewports — full-bleed panel.
 *     On narrow viewports a 380px panel doesn't fit alongside
 *     the page margins; switch to a near-full-width sheet
 *     anchored to the top-right with reduced offsets. The
 *     mobile menus take precedence (z-index) so collisions
 *     resolve correctly.
 * ============================================================ */
@media (max-width: 480px) {
    .site-notifications-panel {
        top: 66px;       /* mobile header height 58px + 8px gap */
        right: 12px;
        left: 12px;
        width: auto;
        max-width: none;
        max-height: calc(100vh - 80px);
    }
}
