/*
 * Variables
 *
 * The colours, fonts & the reset come from the corporate design theme
 * (https://assets.confirm.ch/theme.css), whose tokens are mapped here.
 */

:root {
    /* The theme's root font size is 1.1rem, but Glancelot's layout is made for 1rem. */
    --theme-font-size: 1rem;
    --background: var(--theme-background);
    --surface: var(--theme-surface);
    --surface-hover: var(--theme-surface-raised);
    --border: var(--theme-border);
    --text: var(--theme-text);

    /* The theme's muted text is hard to read on its (dark) surfaces, so it's brighter. */
    --text-muted: color-mix(in srgb, var(--theme-text) 50%, var(--theme-text-muted));
    --primary: var(--theme-primary);
    --primary-hover: var(--theme-primary-hover);

    /*
     * The height of the castle's wall (incl. its merlons), which is 70 of the
     * 240 units of the castle, scaled like the castle (i.e. covering its box).
     */
    --castle-wall: max(4.375vw, clamp(35px, 6.4167vh, 70px));
}

/* Reset (in addition to the theme's, which keeps the paddings) */

*, *::before, *::after {
    padding: 0;
}

/* Layout */

/*
 * Its own stacking context, so the layers behind the content are still above
 * (and clickable). It's hidden until here (see base.html): the browsers hide
 * it via display (overridden below), or via content-visibility (with support
 * for "until-found").
 */
body {
    isolation: isolate;
    content-visibility: visible;
    display: flex;
    flex-direction: column;
    background: var(--background);
    color: var(--text);
}

a {
    color: var(--primary);
    text-decoration: none;
}

a:hover {
    color: var(--primary-hover);
}

button {
    font: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
}

.main {
    flex: 1;
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/*
 * Sir Glancelot is behind the content, so its empty space (e.g. between the
 * groups) lets the clicks through to him.
 */
.main,
.groups {
    pointer-events: none;
}

.main > :not(.groups),
.groups > *,
.groups-column > * {
    pointer-events: auto;
}


.ui-icon {
    display: block;
    width: 1em;
    height: 1em;
    fill: currentcolor;
}

/* Header & footer */

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    border-bottom: 1px solid var(--border);
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text);
    font-weight: 600;
    font-size: 1.1rem;
}

.header-brand:hover {
    color: var(--text);
}

.header-logo {
    display: block;
    width: auto;
    height: 2rem;
}

.header-nav {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.85rem;
}

.header-updated {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.refresh-button {
    display: block;
    color: var(--text-muted);
    font-size: 1.25rem;
    transition: color 0.2s;
}

.refresh-button:hover,
.refresh-button:focus-visible {
    color: var(--primary-hover);
}

/* The button only contains the icon, so the whole button spins. */
.refresh-button.is-loading {
    color: var(--primary);
    cursor: progress;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.muted {
    color: var(--text-muted);
}

.header-button {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-muted);
    transition: color 0.2s;
}

.header-button:hover,
.header-button:focus-visible {
    color: var(--primary-hover);
}

.gitlab-account {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text-muted);
}

/* The GitLab logo is quite small for its box, so it's a bit bigger. */
.gitlab-account .ui-icon,
.gitlab-connect .ui-icon {
    font-size: 1.25rem;
}

/*
 * Not connected yet: orange, with a dot like an unread badge. The padding
 * reserves the room of the dot, so it keeps its distance to the divider.
 */
.gitlab-connect {
    position: relative;
    padding-right: 0.6rem;
    color: var(--primary);
}

.gitlab-connect:hover,
.gitlab-connect:focus-visible {
    color: var(--primary-hover);
}

/* The dot pulses (with a ring, which grows & fades), so it's hard to miss. */
.gitlab-connect::after {
    content: "";
    position: absolute;
    top: -2px;
    right: 0;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--primary);
    animation: pulse 1.8s ease-out infinite;
}

@keyframes pulse {
    from {
        box-shadow: 0 0 0 0 color-mix(in srgb, var(--primary) 70%, transparent);
    }

    to {
        box-shadow: 0 0 0 8px color-mix(in srgb, var(--primary) 0%, transparent);
    }
}

@media (prefers-reduced-motion: reduce) {
    .gitlab-connect::after {
        animation: none;
    }
}

/* The toggle of the menu, only on small screens (see below). */
.header-toggle {
    display: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    transition: color 0.2s;
}

.header-toggle:hover,
.header-toggle:focus-visible,
.header-toggle[aria-expanded="true"] {
    color: var(--primary-hover);
}

/* On small screens, the nav is a column below the brand, which is toggled via the menu. */
@media (width <= 900px) {
    .header.is-collapsible {
        flex-wrap: wrap;
    }

    .is-collapsible .header-toggle {
        display: block;
    }

    .is-collapsible .header-nav {
        display: none;
        flex-basis: 100%;
        flex-direction: column;
        align-items: flex-start;
        padding-top: 1rem;
        font-size: 0.95rem;
    }

    .is-collapsible .header-nav.is-open {
        display: flex;
    }

    .is-collapsible .header-divider {
        align-self: stretch;
        height: 0;
        border-top: 1px solid var(--border);
        border-left: none;
    }
}

/* A border (instead of a background), as borders are snapped to whole pixels. */
.header-divider {
    flex-shrink: 0;
    height: 1.25rem;
    border-left: 1px solid var(--border);
}

.link-button {
    padding: 0;
    border: none;
    background: none;
    color: var(--primary);
    font: inherit;
    cursor: pointer;
}

.link-button:hover {
    color: var(--primary-hover);
}

.btn {
    display: inline-block;
    padding: 0.6rem 1.6rem;
    border-radius: 999px;
    background: var(--primary);
    color: var(--text);
    font-weight: 500;
    transition: background 0.2s;
}

.btn:hover {
    background: var(--primary-hover);
    color: var(--text);
}

/* A small button, e.g. in the modals (sized like the watchtower's actions). */
.btn-small {
    padding: 0.2rem 0.8rem;
    font-size: 0.8rem;
}

/* A secondary button, e.g. beside the login (filled like the actions, with an optional icon). */
.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--surface-hover);
}

.btn-secondary:hover {
    background: color-mix(in srgb, var(--surface-hover), var(--text) 10%);
}

.welcome-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
}

/* Toasts (flash messages) */

.toast-container {
    position: fixed;
    top: 5rem;
    right: 1rem;
    z-index: 20;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.5rem;
}

.toast {
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    background: var(--surface);
    box-shadow: 0 4px 12px color-mix(in srgb, var(--cd-black) 30%, transparent);
    font-size: 0.9rem;
    animation: toast 6s forwards;
}

.toast.error {
    background: var(--theme-error);
    color: var(--theme-error-contrast);
}

.toast.success {
    background: var(--theme-success);
    color: var(--theme-success-contrast);
}

@keyframes toast {
    0%, 85% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        visibility: hidden;
    }
}

/* Login page */

.welcome {
    display: flex;
    justify-content: center;
    padding: 4rem 0;
}

/* Rising embers (created by the JavaScript, as the CSP forbids inline styles). */

.embers {
    position: fixed;
    inset: 0;
    z-index: -2;
    overflow: hidden;
    pointer-events: none;
}

/* A faint glow of the fire, from which the embers rise. */
.embers::before {
    content: '';
    position: absolute;
    right: 0;
    bottom: -10rem;
    left: 0;
    height: 20rem;
    background: radial-gradient(ellipse at bottom, color-mix(in srgb, var(--cd-orange-60) 18%, transparent), transparent 70%);
    transform-origin: bottom;
    animation: haze 6s ease-in-out infinite;
}

/* The heat above the fire, which slowly shimmers. */
@keyframes haze {
    0%, 100% {
        opacity: 0.7;
        transform: scaleY(1);
    }

    50% {
        opacity: 1;
        transform: scaleY(1.2);
    }
}

@media (prefers-reduced-motion: reduce) {
    .embers::before {
        animation: none;
    }
}

.spark {
    position: absolute;
    top: var(--y);
    left: var(--x);
    width: var(--size);
    height: var(--size);
    border-radius: 50%;
    background: var(--cd-orange-80);
    box-shadow: 0 0 6px 2px color-mix(in srgb, var(--cd-orange-70) 70%, transparent);
    animation: spark var(--duration) ease-out forwards;
}

@keyframes spark {
    0% {
        opacity: 1;
        transform: translate(0, 0) scale(1);
    }

    100% {
        opacity: 0;
        transform: translate(var(--drift), var(--rise)) scale(0.2);
    }
}

.ember {
    position: absolute;
    bottom: -10px;
    left: var(--x);
    width: var(--size);
    height: var(--size);
    opacity: 0;
    animation: rise var(--duration) linear var(--delay) infinite;
}

/* The visible dot, so the cursor can push it without fighting the rise animation. */
.ember::after {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: 50%;
    background: var(--cd-yellow-80);
    box-shadow: 0 0 6px 2px color-mix(in srgb, var(--cd-orange-70) 70%, transparent), 0 0 14px 4px color-mix(in srgb, var(--cd-orange-60) 35%, transparent);
    transform: translate(var(--push-x, 0), var(--push-y, 0));
    transition: transform 0.3s ease-out;
}

/* The back layer is also blurred, like out of focus. */
.ember-back::after {
    filter: blur(1.5px);
}

/*
 * A rare shooting ember, streaking across the sky. It follows its curved path
 * (with the bright head in front), which is in viewport pixels, so the element
 * starts in the top left corner.
 */

.shooting-ember {
    position: absolute;
    top: 0;
    left: 0;
    width: 7rem;
    height: 2px;
    border-radius: 999px;
    background: linear-gradient(to left, var(--cd-orange-80), color-mix(in srgb, var(--cd-orange-70) 40%, transparent), transparent);
    box-shadow: 0 0 8px 1px color-mix(in srgb, var(--cd-orange-70) 40%, transparent);
    offset-path: var(--path);
    offset-anchor: right center;
    offset-rotate: auto;
    animation: shoot var(--duration) ease-out forwards;
}

@keyframes shoot {
    0% {
        opacity: 0;
        offset-distance: 0%;
    }

    15% {
        opacity: 1;
    }

    100% {
        opacity: 0;
        offset-distance: 100%;
    }
}

@keyframes rise {
    0% {
        opacity: 0;
        transform: translate(0, 0) scale(1);
    }

    10% {
        opacity: var(--opacity);
    }

    50% {
        transform: translate(var(--drift), -55vh) scale(0.8);
    }

    80% {
        opacity: calc(var(--opacity) * 0.6);
    }

    100% {
        opacity: 0;
        transform: translate(calc(var(--drift) * -0.5), -110vh) scale(0.3);
    }
}

.welcome-card {
    display: flex;
    align-items: center;
    gap: 2.5rem;
    max-width: 100%;
    padding: 2rem 3rem 2rem 1.5rem;
    background: color-mix(in srgb, var(--surface) 50%, transparent);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 24px 60px color-mix(in srgb, var(--cd-black) 45%, transparent);
}

.welcome-avatar {
    flex: none;
    display: block;
    width: 256px;
    height: 256px;
}

.welcome-title {
    margin-bottom: 0.75rem;
    font-size: 1.6rem;
    font-weight: 400;
}

.welcome-title strong {
    color: var(--primary);
    font-weight: 700;
}

.welcome-tagline {
    margin-bottom: 2rem;
    color: var(--text-muted);
    font-weight: 300;
}

/* The paragraphs of the claim are closer to each other than to the buttons. */
.welcome-tagline:not(:last-of-type) {
    margin-bottom: 1rem;
}

/* The card grows with the claim, so it's never wrapped on large screens. */
@media (width >= 1000px) {
    .welcome-tagline {
        white-space: nowrap;
    }
}

/* In front of the castle wall, but without hiding Sir Glancelot from the cursor. */
.footer {
    position: relative;
    z-index: 17;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 2rem;
    font-size: 0.8rem;
    font-weight: 300;
    opacity: 0.5;
    pointer-events: none;
}

.footer a {
    pointer-events: auto;
}

.footer > div {
    margin-left: auto;
    text-align: right;
}

.footer-logo {
    display: block;
    height: 1.5rem;
}

/* Toolbar (search) */

.toolbar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-bottom: 2rem;
}

.search {
    position: relative;
    display: flex;
    align-items: center;
    width: 100%;
    max-width: 40rem;
    color: var(--text-muted);
    font-size: 1.25rem;
}

.search > .ui-icon {
    position: absolute;
    left: 1rem;
    pointer-events: none;
}

.search-input {
    width: 100%;
    padding: 0.75rem 3rem;
    background: color-mix(in srgb, var(--surface) 50%, transparent);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text);
    font: inherit;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: var(--primary);
}

.search-input::-webkit-search-cancel-button {
    display: none;
}

.search-hint {
    position: absolute;
    right: 1rem;
    padding: 0 0.45rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.75rem;
    pointer-events: none;
}

.search-input:focus ~ .search-hint {
    display: none;
}

/*
 * Groups: the cards are in a grid (without JavaScript), or distributed into
 * columns by masonry.js, so they stay in their column when one of them grows
 * (e.g. when a group is expanded), instead of reflowing all of them.
 */

.groups {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(22rem, 100%), 1fr));
    align-items: start;
    gap: 1.5rem;
}

.groups.is-masonry {
    display: flex;
    align-items: flex-start;
}

.groups-column {
    display: flex;
    flex: 1 1 0;
    flex-direction: column;
    gap: 1.5rem;
    min-width: 0;
}

/* The columns are transparent to clicks (like the container, see above). */
.groups > .groups-column {
    pointer-events: none;
}

.group {
    position: relative;
    padding: 1rem 0.5rem 0.5rem;
    background: color-mix(in srgb, var(--surface) 50%, transparent);
    border: 1px solid var(--border);
    border-radius: 16px;
}

/*
 * Frosted glass, which blurs the castle & Sir Glancelot behind the cards. It's a
 * layer behind the card (instead of a backdrop filter on the card itself), so
 * the card creates no stacking context (e.g. a shining bookmark of a spell must
 * still rise above the dark overlay).
 */
.group::before {
    content: "";
    position: absolute;
    inset: 0;
    z-index: -1;
    border-radius: inherit;
    backdrop-filter: blur(3px);
}

.group-title {
    margin: 0 0.75rem 0.5rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

/* The title of a collapsible group (with a chevron, which turns when it's collapsed). */
summary.group-title {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    list-style: none;
    user-select: none;
}

summary.group-title::-webkit-details-marker {
    display: none;
}

.group-title > h2 {
    font: inherit;
}

summary.group-title .ui-icon {
    flex-shrink: 0;
    margin: 0;
    transition: transform 0.2s;
}

summary.group-title:hover {
    color: var(--text);
}

/* As much space below the title as above it (centred). */
.group:not([open]) {
    padding-bottom: 1rem;
}

.group:not([open]) .group-title {
    margin-bottom: 0;
}

.group:not([open]) summary.group-title .ui-icon {
    transform: rotate(-90deg);
}

.bookmarks {
    list-style: none;
}

/* Status pills (of the checks) */

.status-pill {
    display: inline-block;
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 999px;
    background: var(--status, var(--text-muted));
    vertical-align: middle;
}

/*
 * More specific than the .badge of the bookmarks (which is a block). It's a bit
 * wider than the pill, like the icons of the other badges are wider than their
 * glyphs, so the spaces between the badges look the same.
 */
.badge.badge-status {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 0.8rem;

    /* As high as the icons of the other badges (1em of their 0.95rem), so it's centred like them. */
    height: 0.95rem;
}

/*
 * The colours of the statuses, which their pills, texts & heartbeats use (via
 * --status & --status-text, so they're only defined here).
 */
.status-ok,
.status-text-ok,
.heartbeat-ok {
    --status: var(--theme-success);
    --status-text: var(--theme-success-text);
}

.status-failing,
.status-text-failing,
.heartbeat-failing {
    --status: var(--theme-primary);
    --status-text: var(--theme-primary-text);
}

.status-failed,
.status-text-failed,
.heartbeat-failed {
    --status: var(--theme-error);
    --status-text: var(--theme-error-text);
}

/* The theme has no token for maintenance, so it's the palette's violet. */
.status-maintenance,
.status-text-maintenance,
.heartbeat-maintenance {
    --status: var(--cd-violet-60);
    --status-text: var(--cd-violet-70);
}

.status-pill.status-failed {
    box-shadow: 0 0 0 3px var(--theme-error-subtle);
}

/* The pills of failing & failed rows on the watchtower (& of the bookmarks) pulsate. */
.watchtower-row > .status-pill.status-failing,
.badge-status .status-pill.status-failing {
    animation: pill-pulse 1.8s ease-in-out infinite;
}

.watchtower-row > .status-pill.status-failed,
.badge-status .status-pill.status-failed {
    animation: pill-pulse 1.2s ease-in-out infinite;
}

@keyframes pill-pulse {
    50% {
        opacity: 0.35;
    }
}

@media (prefers-reduced-motion: reduce) {
    .watchtower-row > .status-pill,
    .badge-status .status-pill {
        animation: none;
    }
}

/* Dialogs */

.dialog {
    width: min(56rem, calc(100% - 2rem));
    margin: auto;
    padding: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 24px 60px color-mix(in srgb, var(--cd-black) 45%, transparent);
    color: var(--text);
}

/* A small dialog, e.g. to assign a letter. */
.dialog.dialog-small {
    width: min(30rem, calc(100% - 2rem));
}

.letter-bookmark {
    font-weight: var(--theme-font-weight-semibold);
}

.letter-error {
    color: var(--theme-error-text);
}

.dialog::backdrop {
    background: color-mix(in srgb, var(--cd-black) 60%, transparent);
}

.dialog-body {
    padding: 1.5rem;
}

.dialog-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
}

.dialog-head h2 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 0;
    font-size: 1.15rem;
    font-weight: 500;
}

/* The actions in the head (e.g. of admins), left of the close button. */
.dialog-actions {
    display: flex;
    flex-shrink: 0;
    align-items: center;
    gap: 0.75rem;
}

.dialog-close {
    color: var(--text-muted);
    font-size: 1.25rem;
}

.dialog-close:hover {
    color: var(--text);
}

.dialog h3 {
    margin: 1.5rem 0 0.5rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.dialog p {
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.code {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.75rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 8px;
}

.code code {
    flex: 1;
    overflow-x: auto;
    font-size: 0.8rem;
    white-space: nowrap;
}

/* Code, which wraps instead of scrolling (e.g. the badges' Markdown). */
.code-wrap code {
    overflow-x: visible;
    white-space: normal;
    overflow-wrap: anywhere;
}

.code-copy {
    flex: none;
    color: var(--text-muted);
    transition: color 0.2s;
}

.code-copy:hover {
    color: var(--primary-hover);
}

.code-copy.copied {
    color: var(--theme-success-text);
}

/* Empty state */

.empty {
    margin-top: 3rem;
    color: var(--text-muted);
    font-weight: 300;
    text-align: center;
}

.empty-avatar {
    display: block;
    width: 160px;
    height: 160px;
    margin: 0 auto 1rem;
    animation: bob 3s ease-in-out infinite;
}

/* Sir Glancelot gently bobs up & down, while waiting. */
@keyframes bob {
    0%, 100% {
        transform: translateY(0);
    }

    50% {
        transform: translateY(-8px);
    }
}

@media (prefers-reduced-motion: reduce) {
    .empty-avatar {
        animation: none;
    }
}

/*
 * The castle in the dark, in front of the fire glow & behind the content. The
 * embers rise from behind its walls.
 */

.castle {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: -2;
    width: 100%;
    height: clamp(120px, 22vh, 240px);
    object-fit: cover;
    object-position: center bottom;
    pointer-events: none;
}

/*
 * A segment of the castle wall in front of Sir Glancelot. Like him, it's behind
 * the content & the blur of the cards (the order of the layers with the same
 * z-index is the order in the HTML).
 */
.castle-wall {
    position: fixed;
    right: 0;
    bottom: 0;
    z-index: -2;
    width: auto;
    height: var(--castle-wall);
    pointer-events: none;
}

/* Small screens */

@media (width <= 640px) {
    .peeker,
    .castle-wall {
        display: none;
    }

    .header,
    .footer {
        padding: 1rem;
    }

    .footer {
        flex-direction: column;
    }

    .footer > div {
        margin-left: 0;
        text-align: center;
    }

    .welcome-card {
        flex-direction: column;
        gap: 1rem;
        padding: 1.5rem;
        text-align: center;
    }

    .welcome-avatar {
        width: 192px;
        height: 192px;
    }
}
