/* =============================================================
   Wiki Toolbar — vertical action rail (right edge), light theme

   Matches the site's look: white surface, Montserrat, brand-blue
   accent, rounded corners, soft shadow, hover lift.

   Structure (top → bottom):
     • Step-by-step toggle  — primary blue tile (styled in StepMode.css),
                              injected as the first child, with a divider.
     • Utility icons        — report / security / history / status / pdf /
                              share. Icon-only ghost buttons; the label is a
                              tooltip on hover/focus.

   Icons render via CSS mask so they inherit `currentColor` (clean recolor,
   no image hacks). Adding an item never reflows page width — the rail just
   grows downward.
   ============================================================= */

:root {
    --toolbar-width:       5.5rem;
    --toolbar-bg:          var(--behnke-white, #ffffff);
    --toolbar-border:      var(--behnke-light-gray, #e5e7eb);
    --toolbar-icon-color:  var(--behnke-medium-black, #4b5563);   /* resting icon */
    --toolbar-accent:      var(--behnke-design, #0066cc);         /* hover / active */
    --toolbar-hover-bg:    rgba(0, 170, 255, 0.12);
    --toolbar-tip-bg:      #1f2937;   /* dark tooltip on the light rail */
    --toolbar-tip-text:    #ffffff;
}

.wiki-toolbar {
    position: fixed;
    z-index: 900;
    top: 50%;
    right: 0;
    transform: translateY(-50%);

    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 3px;

    box-sizing: border-box;
    width: var(--toolbar-width);
    padding: 8px 7px;
    max-height: 90vh;
    overflow-y: auto;

    background-color: var(--toolbar-bg);
    border: 1px solid var(--toolbar-border);
    border-right: none;
    border-radius: 14px 0 0 14px;
    box-shadow: 0 6px 22px rgba(0, 0, 0, 0.12);
    font-family: var(--font-family, 'Montserrat', sans-serif);

    transition: width 0.24s ease, padding 0.24s ease;
}

/* ── Collapse handle ───────────────────────────────────────────────────────
   Folds the rail down to a slim tab at the screen edge. The handle stays put;
   everything else in the rail is hidden while collapsed. State persists in
   localStorage (see WikiToolbar.js). */

.wiki-toolbar .wiki-toolbar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    height: 24px;
    margin-bottom: 2px;
    padding: 0;

    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--toolbar-icon-color);
    cursor: pointer;
    transition: background-color 0.14s ease, color 0.14s ease;
}

.wiki-toolbar .wiki-toolbar-toggle:hover,
.wiki-toolbar .wiki-toolbar-toggle:focus-visible {
    background-color: var(--toolbar-hover-bg);
    color: var(--toolbar-accent);
    outline: none;
}

.wiki-toolbar .wiki-toolbar-toggle:focus-visible {
    box-shadow: 0 0 0 2px var(--toolbar-accent);
}

/* Chevron drawn from two borders — points right (›) to "fold away" */
.wiki-toolbar .wiki-toolbar-chevron {
    width: 8px;
    height: 8px;
    border-right: 2px solid currentColor;
    border-bottom: 2px solid currentColor;
    transform: rotate(-45deg);
    transition: transform 0.2s ease;
}

/* Collapsed: shrink to a tab and hide every child except the handle */
.wiki-toolbar.is-collapsed {
    width: 40px;
    padding: 6px;
    gap: 0;
    overflow: visible;
}

.wiki-toolbar.is-collapsed > *:not(.wiki-toolbar-toggle) {
    display: none;
}

.wiki-toolbar.is-collapsed .wiki-toolbar-toggle {
    height: 44px;
    margin-bottom: 0;
}

/* Chevron points left (‹) to "open" */
.wiki-toolbar.is-collapsed .wiki-toolbar-chevron {
    transform: rotate(135deg);
}

/* ── Utility icon buttons ──────────────────────────────────────────────────── */

.wiki-toolbar .toolbar-item {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    height: calc(2.4 * var(--behnke-basic));
    padding: 0;

    border: none;
    border-radius: 9px;
    background: transparent;
    color: var(--toolbar-icon-color);   /* icon picks this up via currentColor */
    font: inherit;
    cursor: pointer;
    transition: background-color 0.14s ease, color 0.14s ease, transform 0.1s ease;
}

.wiki-toolbar .toolbar-item:hover,
.wiki-toolbar .toolbar-item:focus-visible {
    background-color: var(--toolbar-hover-bg);
    color: var(--toolbar-accent);
    outline: none;
}

.wiki-toolbar .toolbar-item:active {
    transform: scale(0.92);
}

/* Current page is on the reading list — tint the bookmark button accent. */
.wiki-toolbar .toolbar-item.is-bookmarked {
    color: var(--toolbar-accent);
}

.wiki-toolbar .toolbar-item:focus-visible {
    box-shadow: 0 0 0 2px var(--toolbar-accent);
}

/* Icon as a mask so it adopts the button's text colour */
.wiki-toolbar .toolbar-item .toolbar-icon {
    width: calc(1.3 * var(--behnke-basic));
    height: calc(1.3 * var(--behnke-basic));
    background-color: currentColor;
    -webkit-mask: var(--toolbar-icon) center / contain no-repeat;
            mask: var(--toolbar-icon) center / contain no-repeat;
}

/* ── Tooltip label (to the left of the button) ─────────────────────────────── */

.wiki-toolbar .toolbar-item .toolbar-label {
    position: absolute;
    right: calc(100% + 10px);
    top: 50%;
    transform: translateY(-50%) translateX(4px);

    white-space: nowrap;
    padding: 5px 10px;
    border-radius: 6px;

    background-color: var(--toolbar-tip-bg);
    color: var(--toolbar-tip-text);
    font-size: var(--behnke-smaller-font-size, 0.85rem);
    font-weight: 500;
    line-height: 1.2;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.28);

    opacity: 0;
    pointer-events: none;
    transition: opacity 0.14s ease, transform 0.14s ease;
}

/* Arrow pointing at the button */
.wiki-toolbar .toolbar-item .toolbar-label::after {
    content: "";
    position: absolute;
    left: 100%;
    top: 50%;
    transform: translateY(-50%);
    border: 5px solid transparent;
    border-left-color: var(--toolbar-tip-bg);
}

.wiki-toolbar .toolbar-item:hover .toolbar-label,
.wiki-toolbar .toolbar-item:focus-visible .toolbar-label {
    opacity: 1;
    transform: translateY(-50%) translateX(0);
}

/* -----------------------------
   ENOUGH SPACE — show the label under each icon (stacked, like the step tile)

   Gated on viewport height (the rail grows downward): when there is room, the
   labels become permanent captions under the icons; otherwise the rail stays
   icon-only and the label shows as a tooltip on hover (rules above).
   ----------------------------- */

@media (min-width: 701px) and (min-height: 760px) {

    .wiki-toolbar {
        --toolbar-width: 6rem;
    }

    .wiki-toolbar .toolbar-item {
        flex-direction: column;
        gap: 3px;
        height: auto;
        padding: 7px 4px;
    }

    /* Label moves from tooltip to a static caption under the icon */
    .wiki-toolbar .toolbar-item .toolbar-label {
        position: static;
        transform: none;
        opacity: 1;
        pointer-events: auto;

        white-space: normal;
        text-align: center;
        max-width: 100%;

        background: none;
        box-shadow: none;
        color: inherit;          /* recolours with the button (grey → blue) */
        padding: 0;
        font-size: calc(0.72 * var(--behnke-smaller-font-size, 0.85rem));
        font-weight: 500;
        line-height: 1.15;
    }

    .wiki-toolbar .toolbar-item .toolbar-label::after {
        display: none;           /* no tooltip arrow when shown inline */
    }

    /* Neutralise the tooltip's hover transform so the inline caption stays put */
    .wiki-toolbar .toolbar-item:hover .toolbar-label,
    .wiki-toolbar .toolbar-item:focus-visible .toolbar-label {
        transform: none;
    }
}

/* -----------------------------
   MOBILE — collapse to a narrow icon-only rail
   ----------------------------- */

@media (max-width: 700px) {

    .wiki-toolbar {
        --toolbar-width: 3.25rem;
        padding: 6px 5px;
        gap: 2px;
    }

    .wiki-toolbar .toolbar-item {
        height: 42px;
    }

    .wiki-toolbar .toolbar-item .toolbar-icon {
        width: 22px;
        height: 22px;
    }
}
