/* Visible keyboard focus (accessibility package P1-4, WCAG 2.4.7 and 1.4.11).

   One rule set for every page that links this file: today the public shells, through
   templates/inc_landmarks_head.html, which each of them includes after its theme CSS. The staff
   shells take the same file when Phase 3 reaches them.

   The ring has two bands: a 2px white band right outside the element (box-shadow) and a 2px
   black band outside that (outline, 2px offset). Black and white are 21:1 apart, so whatever
   the color behind the element, one of the two bands has at least 4.5:1 against it (WCAG
   technique C40). That matters here, because the bars and buttons take each city's own colors.

   The vendored theme (Remark, Bootstrap, Select2) removes the outline in many :focus rules,
   some of them more specific than this one, so the ring is !important. It only applies while an
   element matches :focus-visible, which the browser sets for keyboard focus and for text
   fields, not when a button or link is clicked with the mouse. Elements with tabindex="-1" are
   left out: they're focused by scripts, not by Tab (dialogs, for example), and Bootstrap's
   reboot already takes their outline off with !important. */
:focus-visible:not([tabindex="-1"]) {
    outline: 2px solid #000 !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 2px #fff !important;
}

/* Browsers without :focus-visible (Safari before 15.4) ignore the rule above. Those that
   understand @supports selector() (Safari 14.1 to 15.3) get the ring on every focus instead. */
@supports not selector(:focus-visible) {
    :focus:not([tabindex="-1"]) {
        outline: 2px solid #000 !important;
        outline-offset: 2px !important;
        box-shadow: 0 0 0 2px #fff !important;
    }

    .site-menubar a:focus:not([tabindex="-1"]),
    .mobile-nav a:focus:not([tabindex="-1"]),
    .list-group-item:focus:not([tabindex="-1"]),
    .focus-ring-inset:focus:not([tabindex="-1"]) {
        outline-offset: -5px !important;
        box-shadow: inset 0 0 0 3px #fff !important;
    }
}

/* Items that fill a bar or touch their neighbours: a ring outside them would be partly covered
   by the fixed bar above them (the portal's menu bar below its logo bar, the bar under it on
   phones) or by the next item of the list, and scrolling regions that touch the window's edge
   (class focus-ring-inset: /iframe6's request list, beside the map). These get the two bands
   inside their edges instead:
   white at the edge, black inside it. An inset box-shadow starts inside the border and the
   outline offset counts from outside it, so the white band is 3px and the black one 5px in: with
   no border or a 1px one, white still shows at least 2px wide and touches the black. */
.site-menubar a:focus-visible:not([tabindex="-1"]),
.mobile-nav a:focus-visible:not([tabindex="-1"]),
.list-group-item:focus-visible:not([tabindex="-1"]),
.focus-ring-inset:focus-visible:not([tabindex="-1"]) {
    outline-offset: -5px !important;
    box-shadow: inset 0 0 0 3px #fff !important;
}

/* File fields that are a transparent <input> laid over a drop area (Dropify on the request
   forms, .tk-drop on the case page): a ring on the input itself can't be seen, so the drop area
   gets it while the field has focus. :focus-within has no keyboard-only form, so it also shows
   after a mouse click opens the file dialog. */
.dropify-wrapper:focus-within,
.tk-drop:focus-within {
    outline: 2px solid #000 !important;
    outline-offset: 2px !important;
    box-shadow: 0 0 0 2px #fff !important;
}

/* Once a file is chosen, Dropify shows its Remove button and the file's name only on hover. A
   keyboard user gets them while the field or the button has focus, so the button's own ring is
   seen when Tab reaches it. */
.dropify-wrapper:focus-within .dropify-clear,
.dropify-wrapper:focus-within .dropify-preview .dropify-infos {
    opacity: 1;
}

/* The skip link's target. skip-link.js gives <main> tabindex="-1" and focuses it when the skip
   link is used, so the rules above leave it out, and an outline on <main> would be painted under
   Remark's positioned .page anyway. After a keyboard skip, skip-link.js lays this ring over
   <main>'s box instead, two bands just inside its edges (outside them they would fall off the
   screen or under the fixed bars), until focus moves on. <main> isn't a control, so the ring is a
   courtesy for sighted keyboard users, not a 2.4.7 requirement. Its z-index puts it above the
   page's own layers (Remark's page header and aside are at 1100, the forms' loaders at 999) and
   below the fixed bars (Remark's at 1400 and 1500, the portal's phone bar at 1350 in
   templates/base_notification.html), dialogs and the toolbar, so once the page is scrolled its
   top band passes under the bars instead of across them. It isn't printed. */
main#main:focus {
    outline: none;
}

.skip-target-ring {
    position: absolute;
    z-index: 1300;
    box-sizing: border-box;
    border: 2px solid #000;
    box-shadow: inset 0 0 0 2px #fff;
    pointer-events: none;
}

@media print {
    .skip-target-ring {
        display: none;
    }
}

/* Focus order on phones (accessibility package P1-4b, WCAG 2.4.3 and 2.4.7). Below 768px the
   portal's menubar (#portal-menu, templates/base_notification.html) is Remark's off-canvas panel,
   moved 260px off the left edge until Site.js puts site-menubar-open on <body> (the hamburger
   button). Moved off-screen, its links still took Tab: 4 to 7 stops that can't be seen. Hidden,
   they leave the Tab order and the accessibility tree while the panel is closed, and come back the
   moment it opens, from the same class that slides it in, so the two can't disagree. Opening shows
   it at once (the open state's transition list leaves visibility out); closing keeps it shown
   until its 0.25s slide-out has ended. With no script, or before Site.js runs, <body> has neither
   class and the panel stays hidden, as it was already off-screen. At 768px and wider the menubar
   is a bar that is always shown, and none of this applies. Scoped to the portal: the knowledge
   base's menubar holds its search field and stays on-screen at every width, with no button. */
@media (max-width: 767.98px) {
    body:not(.site-menubar-open) #portal-menu {
        visibility: hidden;
    }

    body.site-menubar-hide #portal-menu {
        transition: transform .25s, top .35s, height .35s, visibility 0s linear .25s;
    }
}
