/*
 * The watchtower (on top of style.css): the page intro (with Sir Glancelot),
 * the status summary, the groups & checks, their stats &
 * heartbeats, and the details modal.
 */

/* Page intro (title & description, e.g. of the watchtower) */

.page-intro {
    max-width: 44rem;
    margin: 2rem auto 3.5rem;
    text-align: center;
}

/* A torch-like glow behind Sir Glancelot. */
.page-avatar-glow {
    width: max-content;
    margin: 0 auto 1.75rem;
    border-radius: 50%;
    background: radial-gradient(closest-side, color-mix(in srgb, var(--primary) 35%, transparent), transparent);
}

.page-avatar {
    display: block;
    width: 12rem;
    height: 12rem;
}

.page-kicker {
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 500;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.page-title {
    margin-top: 0.5rem;
    font-size: 2.5rem;
    font-weight: 300;
    letter-spacing: 0.04em;
}

.page-description {
    margin-top: 1.25rem;
    color: var(--text-muted);
    font-size: 0.95rem;
    font-style: italic;
    text-wrap: balance;
}

/* A thin divider with crossed swords. */
.page-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    max-width: 16rem;
    margin: 2.75rem auto 0;
    color: var(--text-muted);
}

.page-divider span {
    font-size: 1.5rem;
    line-height: 1;
}

/* The divider after the maintenance banners (before the checks). */
.page-divider-banners {
    margin: 0 auto 2.75rem;
}

.page-divider::before,
.page-divider::after {
    content: "";
    flex: 1;
    border-top: 1px solid var(--border);
}

/* The status summary, which also filters by status. */
.watchtower-summary {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem 1.5rem;
    margin-top: 2.25rem;
}

.watchtower-summary-item {
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    color: var(--text-muted);
    transition: background 0.2s;
}

.watchtower-summary-item strong {
    font-weight: 600;
}

.watchtower-summary-item:hover,
.watchtower-summary-item[aria-pressed="true"] {
    background: var(--surface-hover);
}

.status-text-ok strong,
.status-text-failing strong,
.status-text-failed strong,
.status-text-maintenance strong {
    color: var(--status-text);
}

/* The checks (one card per category, one row per check or group, all vertical) */

.watchtower-groups {
    grid-template-columns: 1fr;
    max-width: 80rem;
    margin: 0 auto;
}

/* Projects (a single check is one row, several are collapsed into a panel) */

.watchtower-line + .watchtower-line {
    border-top: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
}

.watchtower-row {
    display: grid;
    grid-template-columns: 0.75rem 0.6rem minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
        "toggle pill name    stats"
        ".      .    actions heartbeats";
    align-items: center;
    gap: 0.15rem 0.75rem;
    padding: 0.6rem 0.75rem;
    border-radius: 10px;
    transition: background 0.6s;
}

/* A linked check or group (e.g. from its badges), highlighted briefly. */
.watchtower-row.is-target {
    background: color-mix(in srgb, var(--primary) 20%, transparent);
}

summary.watchtower-row {
    list-style: none;
    cursor: pointer;
}

summary.watchtower-row::-webkit-details-marker {
    display: none;
}

/* The chevron of the collapsible projects, which turns when open. */
.watchtower-toggle {
    grid-area: toggle;
    color: var(--text-muted);
    line-height: 1;
    text-align: center;
    transition: transform 0.2s;
}

summary .watchtower-toggle::before {
    content: "›";
    font-size: 1.2rem;
}

.watchtower-line[open] > summary .watchtower-toggle {
    transform: rotate(90deg);
}

.watchtower-actions {
    grid-area: actions;
    display: flex;
    gap: 0.5rem;
}

/* The buttons of the projects start under their status pill (not indented). */
.watchtower-line-head > .watchtower-actions {
    grid-column: 2 / 4;
}

.watchtower-action {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    background: var(--surface-hover);
    color: var(--text);
    font-size: 0.75rem;
    transition: background 0.2s;
}

.watchtower-action:hover,
.watchtower-action:focus-visible {
    background: color-mix(in srgb, var(--surface-hover), var(--text) 10%);
    color: var(--text); /* not the link colour (e.g. of GitLab) */
}

.watchtower-public {
    align-self: center;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.watchtower-count {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.watchtower-dots {
    display: flex;
    gap: 3px;
}

.watchtower-dots .status-pill {
    width: 0.4rem;
    height: 0.4rem;
}

/* The checks of a project, in a recessed panel. */
.watchtower-checks {
    margin-bottom: 0.5rem;
    border-radius: 10px;
    background: color-mix(in srgb, var(--background) 70%, transparent);
    list-style: none;
}

.watchtower-checks .watchtower-check + .watchtower-check {
    border-top: 1px solid color-mix(in srgb, var(--border) 50%, transparent);
}

.watchtower-row:hover {
    background: color-mix(in srgb, var(--surface-hover) 50%, transparent);
}

.watchtower-row > .status-pill {
    grid-area: pill;
}

.watchtower-check-name {
    grid-area: name;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.5rem;
    min-width: 0;
}

.watchtower-check-name strong {
    font-weight: 500;
}

/* Only the pills & names of the checks are indented, so the stats line up. */
.watchtower-checks .watchtower-row > .status-pill {
    transform: translateX(1.25rem);
}

.watchtower-checks .watchtower-check-name {
    padding-left: 1.25rem;
}

.watchtower-stats {
    grid-area: stats;
    display: flex;
    justify-content: flex-end;
    gap: 1.25rem;
}

/*
 * A value with its label below, right-aligned & with a fixed width, so the
 * stats line up like a table across the rows.
 */
.stat {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 4.75rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.stat strong {
    font-size: 0.9rem;
    font-weight: 500;
}

.stat small {
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.latency-slow strong {
    color: var(--theme-primary-text);
}

.latency-very-slow strong {
    color: var(--theme-error-text);
}

@media (width <= 640px) {
    .watchtower-row {
        grid-template-columns: 0.75rem 0.6rem minmax(0, 1fr);
        grid-template-areas:
            "toggle pill name"
            ".      .    stats"
            ".      .    heartbeats"
            ".      .    actions";
    }
}

/* Heartbeats (the last probes of a check, the oldest first) */

.heartbeats {
    display: block;
    width: 100%;
}

.watchtower-row .heartbeats {
    grid-area: heartbeats;
}

/* Until the heartbeats are drawn (their space is reserved, against layout shifts). */
.heartbeats-pending {
    visibility: hidden;
}

.heartbeat {
    fill: var(--status, var(--border));
}

.heartbeat:hover {
    opacity: 0.7;
}

/* The tooltip of the heartbeats (like the ones of the badges). */
.heartbeat-tip {
    position: absolute;
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    max-width: 20rem;
    padding: 0.55rem 0.75rem;
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 10px;
    box-shadow: 0 8px 24px color-mix(in srgb, var(--cd-black) 45%, transparent);
    color: var(--text-muted);
    font-size: 0.75rem;
    line-height: 1.5;
    pointer-events: none;
}

.heartbeat-tip[hidden] {
    display: none;
}

.heartbeat-tip-time {
    color: var(--text);
    font-weight: 500;
}

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

.heartbeat-tip-error:empty {
    display: none;
}

/*
 * The details in the modal: the project (aligned with the title after its
 * icon, i.e. 1em of the title & the gap), the status, the stats, a list & chips.
 */
.details-meta {
    margin-top: -0.5rem;
    padding-left: 1.6rem;
    font-size: 0.8rem;
}

.details-status {
    margin-bottom: 0.75rem;
}

.details-status-pill {
    margin: -0.1rem 0.4rem 0 0;
}

.dialog .watchtower-stats {
    justify-content: flex-start;
}

.dialog .stat {
    align-items: flex-start;
    min-width: auto;
}

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

.details-list {
    margin-left: 1.1rem;
    font-size: 0.85rem;
}

.details-list li + li {
    margin-top: 0.25rem;
}

.details-checks {
    margin-left: 0;
    list-style: none;
}

.code + .code {
    margin-top: 0.5rem;
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.chip {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.15rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text-muted);
    font-size: 0.75rem;
}

.badge-preview {
    display: block;
    margin-bottom: 0.5rem;
}

/* The format of the badges' code (URL, Markdown or reST), switched via radios. */
.badge-formats {
    display: flex;
    gap: 0.25rem;
    margin: 1rem 0 0.5rem;
}

.badge-format {
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.2s;
}

.badge-format:hover,
.badge-format:has(:checked) {
    background: var(--surface-hover);
    color: var(--text);
}

.badge-format:has(:focus-visible) {
    outline: 2px solid var(--primary);
}

.badge-format input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.badge-codes .code {
    display: none;
}

/* The badges of the check or group, or of the whole project (switched via radios). */
.badges:has([value="project"]:checked) .badge-scope[data-scope="row"],
.badges:not(:has([value="project"]:checked)) .badge-scope[data-scope="project"] {
    display: none;
}

.badges:has([value="url"]:checked) .code[data-format="url"],
.badges:has([value="markdown"]:checked) .code[data-format="markdown"],
.badges:has([value="rst"]:checked) .code[data-format="rst"] {
    display: flex;
}

/* The code keeps its line breaks (e.g. reST), and wraps instead of scrolling. */
.badge-codes code {
    overflow-x: visible;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

.badge-hint {
    margin: 0.5rem 0 0;
    font-size: 0.85rem;
}

/* Sir Glancelot in the title of a page (e.g. the watchtower), with his bubble beside. */
.page-peeker {
    position: relative;
    cursor: pointer;
}

.page-peeker .peeker-bubble {
    right: auto;
    left: 85%;
    border-radius: 10px 10px 10px 0;
}

.page-peeker:hover .peeker-avatar {
    animation: wave 0.9s ease-in-out;
}

.page-peeker:hover .peeker-bubble {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0.25s;
}

.page-peeker.is-somersaulting .peeker-avatar {
    transform-origin: center;
    animation: somersault 0.9s ease-in-out;
}

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

/* Maintenance: the banners on top (current ones highlighted), and the button to plan one. */
.maintenance-banners {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-width: 80rem;
    margin: 0 auto 2rem;
}

.maintenance-banner {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: color-mix(in srgb, var(--surface) 70%, transparent);
}

.maintenance-banner.is-active {
    border-color: var(--cd-violet-60);
    background: color-mix(in srgb, var(--cd-violet-60) 12%, transparent);
}

.maintenance-banner > .ui-icon {
    flex: none;
    margin-top: 0.2rem;
    color: var(--cd-violet-70);
}

.maintenance-banner-text {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 0.15rem;
    font-size: 0.9rem;
}

.maintenance-banner-text strong {
    font-weight: 500;
}

.maintenance-banner-text p {
    margin-top: 0.25rem;
    color: var(--text-muted);
}

/* The admin actions in the head of the details (next to each other). */
.details-admin {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

/* The empty state (to plan maintenance), and the plus below the banners. */
.maintenance-empty {
    padding: 0.75rem 1rem;
    border: 1px dashed var(--border);
    border-radius: 12px;
    color: var(--text-muted);
    text-align: center;
    transition: border-color 0.2s, color 0.2s;
}

.maintenance-empty span {
    text-decoration: underline;
    text-underline-offset: 0.2em;
}

.maintenance-add {
    display: inline-flex;
    align-self: center;
    padding: 0.25rem;
    border-radius: 50%;
    color: var(--text-muted);
    transition: background 0.2s, color 0.2s;
}

.maintenance-empty:hover,
.maintenance-empty:focus-visible {
    border-color: var(--cd-violet-60);
    color: var(--text);
}

.maintenance-add:hover,
.maintenance-add:focus-visible {
    background: var(--surface-hover);
    color: var(--cd-violet-60);
}

/* The wrench of a row in maintenance, with the windows in its tooltip. */
.watchtower-wrench {
    position: relative;
    align-self: center;
    color: var(--cd-violet-70);
    font-size: 0.85rem;
    outline: none;
}

.watchtower-tip {
    position: absolute;
    bottom: calc(100% + 0.5rem);
    left: -0.5rem;
    z-index: 10;
    display: none;
    flex-direction: column;
    width: max-content;
    max-width: 20rem;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--background);
    box-shadow: 0 8px 24px color-mix(in srgb, var(--cd-black) 45%, transparent);
    color: var(--text-muted);
    font-size: 0.75rem;
    line-height: 1.5;
}

.watchtower-wrench:hover .watchtower-tip,
.watchtower-wrench:focus-visible .watchtower-tip {
    display: flex;
}

.watchtower-tip strong {
    color: var(--text);
    font-weight: 500;
}

/* The form to plan a maintenance window (in the modal). */
.maintenance-form {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    font-size: 0.85rem;
}

.maintenance-form label {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.maintenance-form input[type="text"],
.maintenance-form input[type="datetime-local"],
.maintenance-form textarea {
    padding: 0.45rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--background);
    color: var(--text);
    font: inherit;
}

.maintenance-form-times {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
}

.maintenance-form fieldset {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    border: none;
}

/* The legend isn't part of the fieldset's flex layout (so without its gap). */
.maintenance-form legend {
    margin-bottom: 0.6rem;
}

.maintenance-form fieldset label {
    flex-direction: row;
    align-items: center;
    gap: 0.4rem;
}

/* The checks covered by a selected group. */
.maintenance-form fieldset label:has(input:disabled) {
    color: var(--text-muted);
}

.maintenance-form-choices {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem 1rem;
    max-height: 12rem;
    overflow-y: auto;
}

.maintenance-form-search {
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--background);
    color: var(--text);
    font: inherit;
}

.maintenance-form-choices > [hidden] {
    display: none;
}

.maintenance-form .btn {
    align-self: flex-start;
    margin-top: 0.75rem;
}

/* The incidents in the details (with a delete button for admins). */
.details-incidents {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    font-size: 0.85rem;
    list-style: none;
}

/* The older incidents (collapsed). */
.details-more summary {
    margin-top: 0.5rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    cursor: pointer;
}

.details-more summary:hover {
    color: var(--text);
}

.details-incident {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.25rem 0.6rem;
}

.details-incidents form {
    margin-left: auto;
}

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

.details-delete:hover {
    color: var(--theme-error-text);
}
