/* Navigation - Categories, article menu, and navigation components */

.article-categories {
    margin-block-start: var(--space-l);
    padding-block-start: var(--space-s);
    border-block-start: 1px solid var(--color-border);
}

.categories-label {
    margin: 0 0 var(--space-2xs);
    color: var(--color-muted);
    font-family: var(--font-family-san-serif);
    font-size: var(--step--2);
    font-weight: 600;
    letter-spacing: 0.15em;
    text-transform: uppercase;
}

.categories-disclosure {
    margin-block-start: var(--space-2xs);

    & > .categories {
        margin-block-start: var(--space-2xs);
    }
}

.categories-toggle {
    display: inline-flex;
    max-inline-size: 100%;
    box-sizing: border-box;
    min-block-size: 2.25rem;
    align-items: center;
    padding: 0.45rem 1rem;
    border: 1px dashed var(--color-border);
    border-radius: 999px;
    color: var(--color-muted);
    font-family: var(--font-family-san-serif);
    font-size: var(--step--2);
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    list-style: none;
    cursor: pointer;


    &:hover {
        background: var(--uchu-green-1);
        color: var(--uchu-green-8);
    }

    &:focus-visible {
        outline: 2px solid var(--color-primary);
        outline-offset: 3px;
    }
}

.categories-show-fewer,
.categories-disclosure[open] .categories-show-more {
    display: none;
}

.categories-disclosure[open] .categories-show-fewer {
    display: inline;
}

.categories {
    padding: 0;
    margin: 0;
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-2xs);
    list-style: none;
}

.categories li a {
    color: var(--uchu-green-8);
    background-color: var(--uchu-green-1);
    border: none;
    text-transform: uppercase;
    text-decoration: none;
    font-family: var(--font-family-san-serif);
}

ul.categories a {
    font-size: 1rem;
}

.article-actions {
    --action-height: clamp(2.25rem, 2.05rem + 0.45vw, 2.45rem);
    --action-border-color: #e2dfd7;
    --action-border-hover: #cfc9bc;
    --action-surface: #ffffff;
    --action-surface-hover: #f5f3ee;
    --action-fg: var(--color-foreground);

    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-block-start: 0;
    margin-block-end: calc(var(--step-6) * 0.24);
    font-family: var(--font-family-san-serif);
    font-size: var(--step--1);
}

/* Compact labels as the row narrows, before the buttons have to wrap: "Edit article" becomes
   "Edit", then Bookmark becomes icon-only, then the talk button ("Discuss" or the thread count).
   Hidden words stay in the accessibility tree (same technique as .visually-hidden), so every
   button keeps its full name.
   These are viewport queries on purpose: a container query would need containment on the row,
   and containment traps the menu's full-screen click-away layer (position: fixed) inside it.
   Breakpoints are measured with the signed-in bookmark split button (chevron and badge) and the
   longest labels ("Bookmarked", "12 Threads"): the full row fits from ~535px, the short-Edit row
   from ~485px, the icon-bookmark row from ~390px, and with the talk icon too it fits to ~306px. */
@media (width < 34rem) {
    .article-actions .action-label-extra {
        position: absolute;
        inline-size: 1px;
        block-size: 1px;
        margin: -1px;
        overflow: hidden;
        clip-path: inset(50%);
        white-space: nowrap;
    }
}

@media (width < 30.5rem) {
    .article-actions .article-action-bookmark {
        inline-size: var(--action-height);
        padding: 0;

        & .action-label {
            position: absolute;
            inline-size: 1px;
            block-size: 1px;
            margin: -1px;
            overflow: hidden;
            clip-path: inset(50%);
            white-space: nowrap;
        }
    }
}

@media (width < 24.5rem) {
    .article-actions .article-action-talk {
        inline-size: var(--action-height);
        padding: 0;

        & .action-label {
            position: absolute;
            inline-size: 1px;
            block-size: 1px;
            margin: -1px;
            overflow: hidden;
            clip-path: inset(50%);
            white-space: nowrap;
        }
    }
}

.article-action-form {
    position: relative;
    margin: 0;
    display: inline-flex;
}

/* Bookmark status (errors, sign-in prompt) floats under the button instead of pushing the row apart.
   Kept below the open menu (z-index 100) so it never covers the list. */
#article-bookmark-status:not(:empty) {
    position: absolute;
    inset-block-start: calc(100% + 0.4rem);
    inset-inline-start: 0;
    z-index: 50;
    inline-size: max-content;
    max-inline-size: min(22rem, calc(100vw - 2rem));
    padding: 0.45rem 0.75rem;
    border-radius: 0.6rem;
    background: var(--color-foreground);
    color: #ffffff;
    font-size: 0.85em;
    line-height: 1.35;
    white-space: normal;
}

.article-actions .article-action-pill,
.article-actions .m3-split-button__leading,
.article-actions .m3-split-button__trailing > .menu-trigger {
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: var(--action-height);
    background: var(--action-surface);
    color: var(--action-fg);
    border: 1px solid var(--action-border-color);
    font-family: var(--font-family-san-serif);
    font-size: 0.92em;
    font-weight: 500;
    letter-spacing: -0.01em;
    line-height: 1;
    text-decoration: none;
    text-box-trim: none;
    white-space: nowrap;
    cursor: pointer;
    user-select: none;
    transition:
        background-color 0.15s ease,
        border-color 0.15s ease,
        color 0.15s ease,
        border-radius 0.2s cubic-bezier(0.2, 0, 0, 1),
        transform 0.12s ease;

    &:hover {
        background: var(--action-surface-hover);
        border-color: var(--action-border-hover);
        color: var(--action-fg);
    }

    &:focus-visible {
        outline: 2px solid var(--color-primary);
        outline-offset: 2px;
    }

    &:active {
        transform: scale(0.98);
    }
}

.article-actions .article-action-pill {
    gap: 0.48rem;
    padding: 0 1.1rem;
    border-radius: 9999px;
}

.article-actions .action-icon {
    width: 1.05em;
    height: 1.05em;
    flex-shrink: 0;
}

/* Material 3 Expressive Split Button */
.m3-split-button {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.article-actions .m3-split-button__leading {
    gap: 0.48rem;
    padding: 0 0.95rem 0 1.1rem;
    border-radius: 9999px 4px 4px 9999px;

    &:active {
        border-radius: 9999px 8px 8px 9999px;
    }
}

.dropdown-menu {
    position: relative;
    display: inline-flex;
    align-items: center;
    flex-shrink: 0;
    margin: 0;
}

.article-actions .m3-split-button__trailing > .menu-trigger {
    width: calc(var(--action-height) * 1.05);
    padding: 0;
    border-radius: 4px 9999px 9999px 4px;
    list-style: none;

    &:active {
        border-radius: 8px 9999px 9999px 8px;
    }
}


/* M3 Expressive Checked/Open state on trailing menu button */
.article-actions .m3-split-button__trailing[open] > .menu-trigger {
    background: var(--color-foreground);
    border-color: var(--color-foreground);
    color: #ffffff;
    border-radius: 9999px;
}

.dropdown-menu .menu-content {
    display: none;
    position: absolute;
    top: calc(100% + 0.45rem);
    right: 0;
    background-color: #ffffff;
    min-width: 14.5rem;
    padding: 0.4rem 0;
    border-radius: 0.9rem;
    border: 1px solid #e6e4dd;
    box-shadow:
        0 10px 28px rgb(0 0 0 / 0.1),
        0 2px 6px rgb(0 0 0 / 0.05);
    z-index: 100;
}

.dropdown-menu .menu-content a {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.62rem 1.05rem;
    color: var(--color-foreground);
    font-family: var(--font-family-san-serif);
    font-size: 0.92em;
    font-weight: 450;
    line-height: 1.25;
    text-decoration: none;
    white-space: nowrap;
    transition: background-color 0.12s ease;

    &:hover {
        background-color: #f5f3ee;
    }
}

.dropdown-menu .menu-content .menu-item-icon {
    width: 1.1em;
    height: 1.1em;
    flex-shrink: 0;
    color: #3a3d42;
}

.dropdown-menu .menu-content .menu-divider {
    margin: 0.35rem 0.85rem;
    border: 0;
    border-top: 1px solid #eceae3;
}

.dropdown-menu .menu-content a.menu-item-danger {
    color: #c83a2a;

    & .menu-item-icon {
        color: #c83a2a;
    }

    &:hover {
        background-color: rgb(200 58 42 / 0.07);
    }
}

.dropdown-menu[open] .menu-content {
    display: block;
}

/* Bookmark split button: leading half toggles the default list, chevron opens the list menu.
   The saved state is shown by the filled icon and "Bookmarked" label only; the warm tint is kept for hover. */
.article-actions .m3-split-button__leading:disabled {
    cursor: default;
}

.article-bookmark-split {
    position: relative;
}

/* Anchor the menu to the whole split button's start edge rather than the chevron's end edge: the bookmark
   button sits first in the row, so a right-anchored menu would run off the left of narrow screens. */
.article-bookmark-menu {
    position: static;
}

.article-bookmark-menu .menu-content {
    inset-inline: 0 auto;
    max-inline-size: calc(100vw - 2rem);
}

.article-bookmark-menu .menu-trigger {
    position: relative;
}

.article-bookmark-menu .menu-chevron {
    transition: rotate 0.2s cubic-bezier(0.2, 0, 0, 1);
}

.article-bookmark-menu[open] .menu-chevron {
    rotate: 180deg;
}

.bookmark-menu-badge {
    position: absolute;
    inset-block-start: -0.35rem;
    inset-inline-end: -0.3rem;
    min-inline-size: 1.05rem;
    block-size: 1.05rem;
    padding-inline: 0.25rem;
    box-sizing: border-box;
    border-radius: 9999px;
    background: var(--color-foreground);
    color: #ffffff;
    font-size: 0.68rem;
    font-weight: 600;
    line-height: 1.05rem;
    text-align: center;
}

.article-bookmark-menu[open] .bookmark-menu-badge {
    background: #ffffff;
    color: var(--color-foreground);
    box-shadow: 0 0 0 1px var(--color-foreground);
}

.bookmark-lists {
    max-block-size: min(20rem, 55vh);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.dropdown-menu .menu-content .menu-item-button {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    inline-size: 100%;
    margin: 0;
    padding: 0.62rem 1.05rem;
    border: 0;
    background: none;
    color: var(--color-foreground);
    font-family: var(--font-family-san-serif);
    font-size: 0.92em;
    font-weight: 450;
    line-height: 1.25;
    text-align: start;
    cursor: pointer;
    transition: background-color 0.12s ease;

    &:hover {
        background-color: #f5f3ee;
    }

    &:focus-visible {
        outline: 2px solid var(--color-primary);
        outline-offset: -2px;
    }

    &:disabled {
        cursor: progress;
    }
}

.bookmark-list-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dropdown-menu .menu-content .bookmark-list-check {
    visibility: hidden;
}

.dropdown-menu .menu-content .bookmark-list-item.is-checked {
    font-weight: 550;

    & .bookmark-list-check {
        visibility: visible;
    }
}

/* "New list…" name field, revealed under its toggle row. */
.bookmark-new-list-field {
    display: flex;
    gap: 0.5rem;
    padding: 0.2rem 0.85rem 0.55rem;

    &[hidden] {
        display: none;
    }

    & input {
        flex: 1;
        min-inline-size: 0;
        block-size: 2.2rem;
        padding: 0 0.7rem;
        border: 1px solid var(--action-border-color, #e2dfd7);
        border-radius: 0.55rem;
        background: #ffffff;
        color: var(--color-foreground);
        font: inherit;
        font-size: 0.92em;
    }

    & input:focus-visible {
        outline: 2px solid var(--color-primary);
        outline-offset: 1px;
    }

    & .bookmark-new-list-create {
        flex-shrink: 0;
        block-size: 2.2rem;
        padding: 0 0.9rem;
        border: 0;
        border-radius: 9999px;
        background: var(--color-foreground);
        color: #ffffff;
        font: inherit;
        font-size: 0.88em;
        font-weight: 550;
        cursor: pointer;
    }

    & .bookmark-new-list-create:focus-visible {
        outline: 2px solid var(--color-primary);
        outline-offset: 2px;
    }

    & .bookmark-new-list-create:disabled {
        cursor: progress;
        opacity: 0.7;
    }
}

/* No press-scale on an open trigger: a transform makes the trigger the containing block of its fixed
   ::before, so pressing the click-away layer would shrink it to the button and the mouseup would land
   outside, cancelling the click that closes the menu. */
.article-actions .dropdown-menu[open] > .menu-trigger:active {
    transform: none;
}

.dropdown-menu[open] .menu-trigger::before {
    content: " ";
    cursor: default;
    display: block;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    z-index: 99;
    background: transparent;
}


/* Shared disclosure triggers retain native keyboard and no-script activation. */
.dropdown-menu > .menu-trigger {
    list-style: none;
    cursor: pointer;
}

.dropdown-menu > .menu-trigger:focus-visible,
.dropdown-menu .menu-content a:focus-visible {
    outline: 2px solid var(--color-foreground);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    .dropdown-menu .menu-content a,
    .dropdown-menu .menu-content .menu-item-button {
        transition: none;
    }
}
