/* Base styles. Every colour is a token from tokens.css; nothing here knows about light or dark. */

*, *::before, *::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
}

a {
    color: var(--link);
}

:focus-visible {
    outline: 2px solid var(--focus-ring);
    outline-offset: 2px;
}

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

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

[hidden] {
    display: none !important;
}

/* The admin frame: the client list down the left, the page beside it. */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    flex: 0 0 17rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    height: 100vh;
    padding: 1rem 0.75rem;
    overflow-y: auto;
    background: var(--surface);
    border-right: 1px solid var(--border);
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding-left: 0.5rem;
}

.site-title {
    color: var(--text);
    font-size: 1.125rem;
    font-weight: 700;
    text-decoration: none;
}

.sidebar-all {
    display: none;
    margin-right: auto;
}

.sidebar-find {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* A search field that narrows a list on the page (assets/js/filter.js). */
.filter-input {
    flex: 1;
    min-width: 0;
    min-height: 2.75rem;
    padding: 0 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: 0.35rem;
    background: var(--bg);
    color: var(--text);
    font: inherit;

    &::placeholder {
        color: var(--text-muted);
        opacity: 1;
    }
}

.icon-button {
    display: flex;
    align-items: center;
    justify-content: center;
    flex: none;
    width: 2.75rem;
    height: 2.75rem;
    border-radius: 0.4rem;
    color: var(--text-muted);

    &:hover {
        background: var(--surface-sunken);
        color: var(--text);
    }
}

.sidebar-clients {
    display: flex;
    flex-direction: column;
    gap: 2px;

    a {
        display: flex;
        align-items: center;
        min-height: 2.75rem;
        padding: 0.25rem 0.5rem;
        border-radius: 0.35rem;
        color: var(--text);
        text-decoration: none;

        &:hover,
        &[aria-current] {
            background: var(--surface-sunken);
        }

        &[aria-current] {
            font-weight: 600;
        }
    }
}

.sidebar-count {
    margin: 0;
    padding: 0.25rem 0.5rem;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

/* Narrow screens: the sidebar becomes a bar across the top, and the client list is one link away. */
@media (max-width: 48rem) {
    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        position: static;
        flex: none;
        height: auto;
        padding: 0.5rem 1rem;
        overflow: visible;
        border-right: 0;
        border-bottom: 1px solid var(--border);
    }

    .sidebar-head {
        gap: 1.5rem;
        padding-left: 0;
    }

    .sidebar-all {
        display: block;
    }

    .sidebar-find,
    .sidebar-clients {
        display: none;
    }
}

/* Gear and account menus: a <details> each, closed by assets/js/menus.js on an outside click or Escape. */
.site-tools {
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.menu {
    position: relative;

    > summary {
        list-style: none;

        &::-webkit-details-marker {
            display: none;
        }
    }
}

.menu-button {
    display: flex;
    align-items: center;
    padding: 0.4rem;
    border-radius: 0.4rem;
    color: var(--text-muted);
    cursor: pointer;

    &:hover,
    .menu[open] > &,
    &[data-current] {
        background: var(--surface-sunken);
        color: var(--text);
    }
}

.menu-panel {
    position: absolute;
    top: calc(100% + 0.35rem);
    right: 0;
    z-index: 20;
    min-width: 14rem;
    padding: 0.4rem;
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    background: var(--surface-raised);
    box-shadow: 0 6px 20px rgb(0 0 0 / 0.15);

    a,
    .menu-item {
        display: block;
        width: 100%;
        padding: 0.5rem 0.75rem;
        border: 0;
        border-radius: 0.35rem;
        background: none;
        color: var(--text);
        font: inherit;
        text-align: left;
        text-decoration: none;
        cursor: pointer;

        &:hover {
            background: var(--surface-sunken);
        }

        &[aria-current] {
            color: var(--link);
            font-weight: 600;
        }
    }

    form {
        margin: 0;
    }
}

.menu-who {
    display: flex;
    flex-direction: column;
    padding: 0.5rem 0.75rem 0.6rem;
    margin-bottom: 0.3rem;
    border-bottom: 1px solid var(--border);
}

.site-main {
    flex: 1;
    min-width: 0;
    max-width: 76rem;
    padding: 2rem 2.5rem;

    /* No sidebar (the sign-in page): centre what is there. */
    &:only-child {
        margin: 0 auto;
    }

    @media (max-width: 48rem) {
        padding: 1.5rem 1rem;
    }

    /* Pages with many columns, like the forecast grid, use the whole window. */
    &.is-wide {
        max-width: none;
    }
}

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

.button {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.6rem;
    padding: 0.6rem 1rem;
    border: 1px solid var(--border-strong);
    border-radius: 0.35rem;
    background: var(--bg);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;

    &:hover {
        border-color: var(--primary);
    }

    &.is-primary {
        border-color: var(--primary);
        background: var(--primary);
        color: var(--on-primary);

        &:hover {
            background: var(--primary-hover);
        }
    }
}

.flash {
    padding: 0.6rem 0.8rem;
    border: 1px solid var(--border);
    border-radius: 0.35rem;
    background: var(--surface);

    &.is-success {
        color: var(--success);
    }

    &.is-danger,
    &.is-error {
        color: var(--danger);
    }
}

.login-card {
    max-width: 24rem;
    margin: 4rem auto;
    padding: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.5rem;

    h1 {
        margin-top: 0;
    }
}

.login-sso-logo {
    width: 1.1rem;
    height: 1.1rem;
}

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;

    h1 {
        margin: 0;
    }
}

.data-table {
    width: 100%;
    border-collapse: collapse;

    th,
    td {
        padding: 0.5rem 0.75rem;
        border-bottom: 1px solid var(--border);
        text-align: left;
    }

    th {
        border-bottom-color: var(--border-strong);
        color: var(--text-muted);
        font-size: 0.85rem;
    }
}

.row-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
}

.button.is-danger {
    border-color: var(--danger);
    color: var(--danger);
}

.confirm-dialog {
    max-width: 28rem;
    padding: 1.5rem;
    border: 1px solid var(--border-strong);
    border-radius: 0.5rem;
    background: var(--surface-raised);
    color: var(--text);

    &::backdrop {
        background: rgb(0 0 0 / 0.5);
    }
}

.upload-progress {
    width: 12rem;
}

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

.player {
    display: block;
    width: 100%;
    max-width: 60rem;
    background: var(--player-bg);
    border-radius: 0.35rem;
}

.player-frame {
    aspect-ratio: 16 / 9;
    height: auto;
    border: 0;
}

.inline-form {
    display: inline;
    margin: 0;
}

.snippet {
    width: 100%;
    max-width: 60rem;
    padding: 0.6rem 0.75rem;
    border: 1px solid var(--border-strong);
    border-radius: 0.35rem;
    background: var(--bg);
    color: var(--text);
    font: 0.85rem/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.player-options {
    margin: 0.5rem 0 1rem;

    dt {
        margin-top: 0.4rem;
    }

    dd {
        margin: 0 0 0 1.5rem;
        color: var(--text-muted);
    }
}

.hero-preview {
    max-height: 24rem;
    object-fit: cover;
}

.page-sub {
    margin: 0;
    font-size: 0.9rem;
}

.head-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.table-scroll {
    overflow-x: auto;
}

/* A client's videos: a field to narrow them, and the choice of grid or list. */
.toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;

    .filter-input {
        flex: 1 1 15rem;
        max-width: 22rem;
    }
}

.view-switch {
    display: flex;
    margin-left: auto;
    border: 1px solid var(--border-strong);
    border-radius: 0.35rem;

    a {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        padding: 0.55rem 0.9rem;
        color: var(--text);
        font-weight: 600;
        text-decoration: none;

        &[aria-current] {
            background: var(--primary);
            color: var(--on-primary);
        }
    }
}

.project-group {
    margin-bottom: 2rem;
}

.group-head {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 0.75rem;
    padding-bottom: 0.5rem;
    margin-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);

    h2 {
        margin: 0;
        font-size: 1.125rem;

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

    .row-actions {
        margin-left: auto;
    }
}

.video-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(12.5rem, 1fr));
    gap: 1.25rem 1rem;
}

.video-card {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    color: var(--text);
    text-decoration: none;

    strong {
        display: block;
    }

    &:hover .poster {
        border-color: var(--border-strong);
    }
}

/* A video's poster frame, or an empty box until the worker has made one. */
.poster {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    aspect-ratio: 16 / 9;
    border: 1px solid var(--border);
    border-radius: 0.35rem;
    background: var(--surface-sunken);
    color: var(--text-muted);

    overflow: hidden;

    img {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    &.is-small {
        flex: 0 0 4.5rem;
        border-radius: 0.25rem;
    }
}

.poster-length {
    position: absolute;
    right: 0.4rem;
    bottom: 0.4rem;
    padding: 0 0.4rem;
    border-radius: 0.25rem;
    background: var(--primary);
    color: var(--on-primary);
    font-size: 0.75rem;
    font-weight: 600;
}

.card-meta {
    color: var(--text-muted);
    font-size: 0.8125rem;
}

.video-row-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text);
    font-weight: 600;
    text-decoration: none;
}

/* The video page: the player and its versions, with embed and hero beside them. */
.video-layout {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 2rem;
}

.video-main {
    flex: 999 1 26rem;
    min-width: 0;
}

.video-side {
    flex: 1 1 20rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    min-width: 0;
}

.card {
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: 0.6rem;
    background: var(--surface);

    h2 {
        margin: 0 0 0.5rem;
        font-size: 1rem;
    }

    > :last-child {
        margin-bottom: 0;
    }
}
