/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Wiki-side additions to the UI Library stylesheet.
 *
 * assets/ui-library/index.css is a byte-for-byte copy of the published
 * @IntelligentPlant/react-ui-library package (see tools/ui-library/). It is
 * never edited by hand, so it can be replaced cleanly on every library bump.
 * Everything the wiki needs on top of the library lives here instead.
 *
 * Load this file AFTER assets/ui-library/index.css and BEFORE assets/css/wiki.css.
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/**------------------------------------------------Font sizes
 * The library sets `font-size: 13pt` on :root and sizes its components in em.
 * A percentage of the browser default keeps the user's own font-size setting
 * working (108.333% of 16px is 13pt), and exposes the sizes as rem tokens so
 * wiki.css and app pages can use them without nesting em.
 */
:root {
    font-size: 108.333%;

    --fontSizeXSmall: 0.6923rem; /* 12px at the default root size */
    --fontSizeSmall: 0.875rem;
    --fontSizeBase: 1rem;
    --fontSizeMedium: 1.125rem;
    --fontSizeTitle: 1.3rem;
    --fontSizeLarge: 1.5rem;
    --fontSizeXLarge: 1.875rem;
    --fontSizeHeader: 2rem;

    /* kept for apps that already use it, prefer --fontSizeBase */
    --font-size: var(--fontSizeBase);
}

/* The library uses 100vw, which includes the scrollbar and causes a horizontal
   scroll. On mobile browsers 100vh is taller than the visible area (address
   bar), so 100dvh is used where supported. */
html,
body {
    width: 100%;
    height: 100vh;
    height: 100dvh;
}

/* The library sizes these in em, which follows the parent's font size. In rem
   they are stable wherever a heading is placed, e.g. inside a nested panel. */
.header {
    font-size: var(--fontSizeHeader);
}

.title {
    font-size: var(--fontSizeTitle);
}

.subtitle,
.item {
    font-size: var(--fontSizeBase);
}

/**------------------------------------------------Hover and touch
 * Hover colours are applied only on devices that can actually hover, so they do
 * not stick to an element after a tap. The library applies them unconditionally.
 */
.clickable {
    cursor: pointer;
}

@media (hover: hover) {
    .clickable:hover {
        color: var(--successColour);
    }

    .ipButton:hover {
        box-shadow: 0 0 4px 0 var(--fontColour);
        color: var(--fontColour);
    }

    .ipButton.success:hover {
        color: var(--primaryOutlineColour);
    }

    .ipButton.danger:hover {
        background-color: var(--dangerColour);
        color: var(--primaryColour);
    }

    .ipButton.warning:hover {
        color: var(--titleColour);
    }

    .ipIconButton:hover,
    .ipIconButton.active {
        color: var(--successColour);
    }

    .ipIconTextButton:hover {
        color: var(--fontColour);
    }
}

/* The library applies the hover colour to .clickable unconditionally, which
   makes it stick after a tap. Undo it where there is no hover. */
@media (hover: none) {
    .clickable:hover {
        color: inherit;
    }
}

/**------------------------------------------------Overflow guards
 * Fixed sizes in the library can exceed a phone screen.
 */
.alertWrapper {
    max-width: calc(100vw - 20px);
}

.popUpWrapper {
    position: fixed;
}

.dropDownMenu.menuContainer {
    max-width: calc(100vw - 2rem);
}

.card.wrapper {
    max-width: 100%;
}

.tagsBox {
    max-width: 100%;
}

/**------------------------------------------------Responsive
 * Breakpoints: phone up to 640px, tablet up to 1024px. CSS variables cannot be
 * used in media queries, so the values are repeated in each query.
 */
@media (max-width: 640px) {
    .hide-mobile {
        display: none !important;
    }

    .mobile-flex-column {
        flex-direction: column;
    }

    .mobile-full-width {
        width: 100%;
    }

    .mobile-wrap {
        flex-wrap: wrap;
    }

    .popUpBox {
        width: calc(100% - 2rem);
        height: auto;
        max-height: 90vh;
        max-height: 90dvh;
        overflow: auto;
    }

    .tagsBox {
        height: min(500px, 70vh);
        height: min(500px, 70dvh);
    }
}

@media (min-width: 641px) {
    .show-mobile {
        display: none !important;
    }
}

@media (max-width: 1024px) {
    .hide-tablet {
        display: none !important;
    }
}

/**------------------------------------------------Touch screens
 * An invisible area of at least 44px around small controls so they are easy to
 * tap, without changing how they look. It goes on the element that has the click
 * handler, so it never covers a clickable child.
 */
@media (pointer: coarse) {
    .ipButton,
    .ipIconButton,
    .ipIconTextButton a,
    .dropDownMenu.header {
        position: relative;
    }

    .ipButton::after,
    .ipIconButton::after,
    .ipIconTextButton a::after,
    .dropDownMenu.header::after,
    .ipToggle.background::after {
        content: "";
        position: absolute;
        top: 50%;
        left: 50%;
        width: max(100%, 44px);
        height: max(100%, 44px);
        transform: translate(-50%, -50%);
    }

    /* Pseudo-elements do not work on checkbox inputs in every browser. */
    .ipCheckBox {
        height: 1.25rem;
        width: 1.25rem;
    }

    /* iOS zooms the page when an input with text smaller than 16px is focused.
       That limit is in px, so it is the one font size in px; max() still lets a
       larger user setting win. */
    .ipTextInput,
    .ipTextInput.small,
    .ipTextInput.medium,
    .ipSelectBox,
    .ipSelectBox.small,
    .ipSelectBox.medium {
        font-size: max(16px, var(--fontSizeSmall));
    }
}
