/*
 * Small fixes and additions to Filament's own styles for both panels.
 */

/*
 * A single badge in a table column or infolist entry sits inside a
 * line-clamp box, which stretches it to the full width. A flex box keeps
 * it the size of its text, with or without a description under it.
 */
.fi-ta-text-item.fi-ta-text-has-badges,
.fi-in-text-item.fi-in-text-has-badges,
.fi-ta-text-has-badges > .fi-ta-text-item,
.fi-in-text-has-badges > .fi-in-text-item {
    display: flex;
}

/*
 * A vertical timeline for repeatable entries marked with the
 * "cm-timeline" class. Items run oldest first, so the last dot (the
 * latest step) is filled.
 */
.cm-timeline .fi-in-repeatable {
    row-gap: 0;
}

.cm-timeline .fi-in-repeatable-item {
    position: relative;
    padding-left: 1.75rem;
    padding-bottom: 1rem;
}

.cm-timeline .fi-in-repeatable-item:last-child {
    padding-bottom: 0;
}

.cm-timeline .fi-in-repeatable-item::before {
    content: '';
    position: absolute;
    left: 0.34375rem;
    top: 1.25rem;
    bottom: -0.25rem;
    width: 1px;
    background: var(--gray-200);
}

.cm-timeline .fi-in-repeatable-item:last-child::before {
    display: none;
}

.cm-timeline .fi-in-repeatable-item::after {
    content: '';
    position: absolute;
    left: 0;
    top: 0.3125rem;
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 9999px;
    border: 2px solid var(--gray-300);
    background: var(--color-white);
}

.cm-timeline .fi-in-repeatable-item:last-child::after {
    border-color: var(--primary-600);
    background: var(--primary-600);
}

.dark .cm-timeline .fi-in-repeatable-item::before {
    background: var(--gray-700);
}

.dark .cm-timeline .fi-in-repeatable-item::after {
    border-color: var(--gray-600);
    background: var(--gray-900);
}

.dark .cm-timeline .fi-in-repeatable-item:last-child::after {
    border-color: var(--primary-400);
    background: var(--primary-400);
}

/*
 * Status and capacity badges in columns and entries marked "cm-dot" start
 * with a small dot in the badge's own colour.
 */
.cm-dot .fi-badge::before {
    content: '';
    flex-shrink: 0;
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 9999px;
    background: currentColor;
}

/* A badge keeps its own width when a description below it wraps. */
.cm-dot.fi-wrapped .fi-badge {
    width: fit-content;
}

/*
 * The capacity choice (fields marked "cm-capacity") as a row of cards,
 * each with a dot in its traffic light colour. The chosen card gets a
 * dark outline.
 */
.cm-capacity .fi-fo-field-label-col + .fi-fo-field-content-col .fi-fo-radio {
    margin-top: 0.5rem;
}

.cm-capacity .fi-fo-radio {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
}

.cm-capacity .fi-fo-radio-label {
    position: relative;
    margin: 0;
    padding: 0.75rem 1rem;
    border: 1px solid var(--gray-200);
    border-radius: 0.5rem;
    background: var(--color-white);
    cursor: pointer;
}

.cm-capacity .fi-fo-radio-label .fi-radio-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.cm-capacity .fi-fo-radio-label-text {
    margin: 0;
}

.cm-capacity .fi-fo-radio-label-text > p:first-child {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-weight: 600;
}

.cm-capacity .fi-fo-radio-label-text > p:first-child::before {
    content: '';
    flex-shrink: 0;
    width: 0.625rem;
    height: 0.625rem;
    border-radius: 9999px;
}

.cm-capacity .fi-fo-radio-label:has(input[value='green']) .fi-fo-radio-label-text > p:first-child::before {
    background: var(--success-600);
}

.cm-capacity .fi-fo-radio-label:has(input[value='amber']) .fi-fo-radio-label-text > p:first-child::before {
    background: var(--warning-500);
}

.cm-capacity .fi-fo-radio-label:has(input[value='red']) .fi-fo-radio-label-text > p:first-child::before {
    background: var(--danger-600);
}

.cm-capacity .fi-fo-radio-label-description {
    margin-top: 0.125rem;
    padding-left: 1.125rem;
}

.cm-capacity .fi-fo-radio-label:has(input:checked) {
    border-color: var(--gray-950);
    box-shadow: 0 0 0 1px var(--gray-950);
}

.cm-capacity .fi-fo-radio-label:has(input:focus-visible) {
    outline: 2px solid var(--primary-600);
    outline-offset: 2px;
}

.dark .cm-capacity .fi-fo-radio-label {
    border-color: var(--gray-700);
    background: var(--gray-900);
}

.dark .cm-capacity .fi-fo-radio-label:has(input:checked) {
    border-color: var(--color-white);
    box-shadow: 0 0 0 1px var(--color-white);
}

/*
 * A manual approval check: a checkbox and its label. The checkbox sits
 * in the same space as the icon on the other checks, so the labels line up.
 */
.cm-approval-check {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: calc(var(--spacing) * 0.5);
}

.cm-approval-check-label {
    display: flex;
    align-items: flex-start;
    gap: calc(var(--spacing) * 3);
    cursor: pointer;
}

.cm-approval-check-label:has(:disabled) {
    cursor: default;
}

.cm-approval-check-label .fi-checkbox-input {
    flex-shrink: 0;
    margin-top: 0.125rem;
    cursor: inherit;
}

/* A met check is green, whether or not this admin can change it. */
.cm-approval-check-label .fi-checkbox-input:checked,
.cm-approval-check-label .fi-checkbox-input:checked:disabled {
    background-color: var(--success-600);
}

.dark .cm-approval-check-label .fi-checkbox-input:checked,
.dark .cm-approval-check-label .fi-checkbox-input:checked:disabled {
    background-color: var(--success-500);
}

/* The document link sits under the label, in line with its text. */
.cm-approval-check .fi-link {
    margin-left: calc(1rem + var(--spacing) * 3);
    font-size: 0.8125rem;
}

/* The check's label, with who ticked it or its document's dates below. */
.cm-approval-check-text {
    display: flex;
    flex-direction: column;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--gray-950);
}

.cm-approval-check-detail {
    font-size: 0.8125rem;
    color: var(--gray-500);
}

.dark .cm-approval-check-text {
    color: var(--color-white);
}

.dark .cm-approval-check-detail {
    color: var(--gray-400);
}

/*
 * Badges marked "cm-pills" (reasons for referral, access needs) as
 * rounded pills, a little larger than a status badge.
 */
.cm-pills .fi-badge {
    border-radius: 9999px;
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
}

/*
 * The step still to come after a timeline (marked "cm-timeline-next"),
 * with a hollow dot in line with the timeline's dots.
 */
.cm-timeline-next {
    position: relative;
    padding-left: 1.75rem;
}

.cm-timeline-next::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.3125rem;
    width: 0.75rem;
    height: 0.75rem;
    border-radius: 9999px;
    border: 2px solid var(--gray-200);
}

.dark .cm-timeline-next::before {
    border-color: var(--gray-600);
}

/*
 * Report breakdowns drawn as labelled horizontal bars (BarList widgets).
 */
.cm-bars {
    display: grid;
    gap: 1rem;
}

.cm-bars-label {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    color: var(--gray-950);
}

.cm-bars-value {
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.cm-bars-track {
    margin-top: 0.375rem;
    height: 0.5rem;
    border-radius: 9999px;
    background: var(--gray-100);
    overflow: hidden;
}

.cm-bars-fill {
    height: 100%;
    border-radius: 9999px;
    background: var(--primary-600);
}

.cm-bars-empty {
    font-size: 0.875rem;
    color: var(--gray-500);
}

.dark .cm-bars-label {
    color: var(--color-white);
}

.dark .cm-bars-track {
    background: var(--gray-800);
}

.dark .cm-bars-fill {
    background: var(--primary-400);
}

/*
 * A timeline step written as one line of HTML: the step in bold, then
 * who or what, then when in small grey text underneath.
 */
.cm-timeline .fi-in-text-item.fi-in-text {
    display: block;
}

.cm-timeline-when {
    display: block;
    margin-top: 0.125rem;
    font-size: 0.75rem;
    line-height: 1rem;
    color: var(--gray-500);
}

.dark .cm-timeline-when {
    color: var(--gray-400);
}

/*
 * The stored copy of a Joy page on D16, in a sandboxed frame.
 */
.cm-joy-listing {
    max-height: clamp(24rem, calc(100vh - 20rem), 48rem);
    overflow-y: auto;
    padding: 1rem;
    border: 1px solid var(--gray-200);
    border-radius: 0.5rem;
    font-size: 0.875rem;
    line-height: 1.5;
}

.dark .cm-joy-listing {
    border-color: var(--gray-700);
}

.cm-joy-listing-title {
    margin-bottom: 0.75rem;
    font-size: 1rem;
    font-weight: 600;
}

.cm-joy-listing-details {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 0.25rem 1rem;
    margin-bottom: 1rem;
}

.cm-joy-listing-details dt {
    color: var(--gray-500);
}

.cm-joy-listing-details dd {
    overflow-wrap: anywhere;
}

.cm-joy-listing-description {
    white-space: pre-line;
}

.cm-joy-page-empty {
    padding: 2rem 1rem;
    border: 1px dashed var(--gray-300);
    border-radius: 0.5rem;
    color: var(--gray-500);
    font-size: 0.875rem;
    text-align: center;
}

/*
 * The Joy side of D16 stays in view while the listing form scrolls.
 */
@media (min-width: 80rem) {
    .cm-sticky {
        position: sticky;
        top: 5rem;
        align-self: start;
    }
}

/*
 * The prototype look (C and D screens). A smaller base brings everything
 * set in rem down to the prototype's scale: table and menu text 13.5px,
 * badges 11.5px.
 */
html {
    font-size: 15.5px;
}

/*
 * On a desktop the sidebar runs the full height with the brand at its
 * top, and the top bar sits beside it.
 */
@media (min-width: 64rem) {
    .fi-body-has-topbar .fi-topbar-ctn {
        margin-inline-start: var(--sidebar-width);
    }

    .fi-body-has-topbar .fi-topbar-start {
        display: none;
    }

    .fi-body-has-topbar .fi-layout > div:has(> .fi-main-sidebar) {
        flex-shrink: 0;
        width: var(--sidebar-width);
    }

    .fi-body-has-topbar .fi-main-sidebar {
        position: fixed;
        inset-block-start: 0;
        inset-inline-start: 0;
        height: 100dvh;
        border-inline-end: 1px solid var(--gray-200);
        background-color: var(--color-white);
    }

    .fi-body-has-topbar .fi-sidebar-header {
        display: flex;
        justify-content: flex-start;
        height: var(--cm-topbar-height);
        padding-inline: 1.25rem;
        background-color: transparent;
        box-shadow: none;
    }

    .fi-body-has-topbar .fi-sidebar-header .fi-logo {
        margin-inline-start: 0;
    }

    /* Breadcrumbs sit in the top bar, beside the sidebar. */
    .fi-body-has-topbar .fi-header .fi-breadcrumbs {
        position: fixed;
        z-index: 30;
        inset-block-start: 0;
        inset-inline-start: calc(var(--sidebar-width) + 2rem);
        display: flex;
        align-items: center;
        height: var(--cm-topbar-height);
        max-width: calc(100vw - var(--sidebar-width) - 34rem);
        overflow: hidden;
    }

    .dark.fi-body-has-topbar .fi-main-sidebar,
    .dark .fi-body-has-topbar .fi-main-sidebar {
        border-color: var(--gray-800);
        background-color: var(--gray-900);
    }
}

:root {
    --cm-topbar-height: 4rem;
}

.fi-main {
    margin-inline: 0;
}

.fi-header-heading {
    font-size: 1.625rem;
    line-height: 2rem;
}

/* Sidebar: small uppercase group labels and a tinted active item. */
.fi-sidebar-group-label {
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--gray-400);
}

.fi-sidebar-nav {
    row-gap: 1.25rem;
    padding-inline: 1.25rem 1rem;
}

.fi-sidebar-nav-groups {
    row-gap: 1rem;
}

/* The menu still scrolls on short screens, without a visible bar. */
.fi-sidebar-nav {
    scrollbar-width: none;
}

.fi-sidebar-nav::-webkit-scrollbar {
    display: none;
}

/* The brand: a tile with the initials, then the name. */
.cm-brand {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    font-size: 1rem;
    font-weight: 700;
    color: var(--gray-950);
}

.cm-brand-mark {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.5rem;
    background-color: var(--primary-600);
    color: var(--color-white);
    font-size: 0.8rem;
}

.dark .cm-brand {
    color: var(--color-white);
}

.fi-sidebar-item.fi-active > .fi-sidebar-item-btn {
    background-color: var(--primary-50);
}

.fi-sidebar-item.fi-active > .fi-sidebar-item-btn .fi-sidebar-item-label {
    font-weight: 600;
}

.fi-sidebar-item-btn .fi-badge {
    background-color: var(--gray-100);
    color: var(--gray-600);
    box-shadow: none;
    border-radius: 9999px;
}

.fi-sidebar-item.fi-active > .fi-sidebar-item-btn .fi-badge {
    background-color: var(--primary-100);
    color: var(--primary-700);
}

/* List tabs: a left aligned row with an underline, not a centred box. */
.fi-tabs:not(.fi-contained) {
    margin-inline: 0;
    padding: 0;
    border-radius: 0;
    background: none;
    box-shadow: none;
    border-bottom: 1px solid var(--gray-200);
}

.fi-tabs:not(.fi-contained) .fi-tabs-item {
    border-radius: 0;
    background: none;
}

.fi-tabs:not(.fi-contained) .fi-tabs-item.fi-active {
    box-shadow: inset 0 -2px 0 var(--primary-600);
}

.fi-tabs:not(.fi-contained) .fi-tabs-item.fi-active .fi-tabs-item-label {
    font-weight: 600;
}

.fi-tabs-item .fi-badge {
    background-color: var(--gray-100);
    color: var(--gray-600);
    box-shadow: none;
    border-radius: 9999px;
}

.fi-tabs-item.fi-active .fi-badge {
    background-color: var(--primary-100);
    color: var(--primary-700);
}

/* Table search and filters start on the left. */
.fi-ta-header-toolbar {
    justify-content: flex-start;
}

.fi-ta-header-toolbar > .fi-ta-actions:empty,
.fi-ta-header-toolbar > .fi-ta-actions:not(:has(*)) {
    display: none;
}

.fi-ta-header-toolbar > div:last-child {
    margin-inline: 0 auto;
}

/* Quiet column headings, the first column in bold. */
.fi-ta-header-cell {
    font-size: 0.857rem;
    color: var(--gray-500);
}

.fi-ta-cell:first-child > .fi-ta-col .fi-ta-text-item {
    font-weight: 600;
    color: var(--gray-950);
}

/* Text that needs attention: amber soon, red now (see AwaitingUrgency). */
.cm-text-warning {
    color: var(--warning-600);
}

.dark .cm-text-warning {
    color: var(--warning-400);
}

.cm-text-danger {
    color: var(--danger-600);
}

.dark .cm-text-danger {
    color: var(--danger-400);
}

/* Every digit the same width, so numbers in a column line up. */
.fi-ta-cell {
    font-variant-numeric: tabular-nums;
}

/* Flat badges, as in the prototype. */
.fi-badge {
    box-shadow: none;
    font-weight: 600;
}

.fi-badge:not(.fi-color) {
    background-color: var(--gray-100);
    color: var(--gray-600);
}

.dark .fi-sidebar-item.fi-active > .fi-sidebar-item-btn {
    background-color: color-mix(in oklab, var(--primary-500) 15%, transparent);
}

.dark .fi-tabs:not(.fi-contained) {
    border-color: var(--gray-700);
}

.dark .fi-ta-cell:first-child > .fi-ta-col .fi-ta-text-item {
    color: var(--color-white);
}

/* The role pill in the top bar needs the room on a phone. */
@media (max-width: 40rem) {
    .cm-role {
        display: none;
    }
}

/* Choices such as categories and age bands: outlined rounded pills, tinted with a tick when chosen. */
.fi-fo-toggle-buttons:not(.fi-btn-group) {
    gap: 0.5rem;
}

.fi-fo-toggle-buttons-btn-ctn > .fi-btn.fi-btn {
    border-radius: 9999px;
    padding: 0.3125rem 0.875rem;
    font-size: 0.857rem;
    font-weight: 500;
    background-color: var(--color-white);
    color: var(--gray-700);
    box-shadow: inset 0 0 0 1px var(--gray-300);
}

.fi-fo-toggle-buttons-btn-ctn > .fi-btn.fi-btn:hover {
    background-color: var(--gray-50);
}

.fi-fo-toggle-buttons-input:checked + .fi-btn.fi-btn,
.fi-fo-toggle-buttons-btn-ctn > .fi-btn.fi-btn[aria-pressed="true"] {
    background-color: var(--primary-50);
    color: var(--primary-700);
    box-shadow: inset 0 0 0 1px var(--primary-400);
}

.fi-fo-toggle-buttons-input:checked + .fi-btn.fi-btn::before,
.fi-fo-toggle-buttons-btn-ctn > .fi-btn.fi-btn[aria-pressed="true"]::before {
    content: "✓";
    font-weight: 700;
}

.fi-fo-toggle-buttons-input:focus-visible + .fi-btn.fi-btn {
    outline: 2px solid var(--primary-600);
    outline-offset: 2px;
}

.dark .fi-fo-toggle-buttons-btn-ctn > .fi-btn.fi-btn {
    background-color: transparent;
    color: var(--gray-200);
    box-shadow: inset 0 0 0 1px var(--gray-600);
}

.dark .fi-fo-toggle-buttons-input:checked + .fi-btn.fi-btn,
.dark .fi-fo-toggle-buttons-btn-ctn > .fi-btn.fi-btn[aria-pressed="true"] {
    background-color: color-mix(in oklab, var(--primary-500) 20%, transparent);
    color: var(--primary-200);
    box-shadow: inset 0 0 0 1px var(--primary-500);
}

/* An unboxed group of fields reads as one labelled field. */
.fi-fieldset.fi-fieldset-not-contained {
    padding-top: 0;
}

.fi-fieldset.fi-fieldset-not-contained > legend {
    margin-inline-start: 0;
    padding-inline: 0;
    padding-bottom: 0.5rem;
}

/* Get started (C11): numbered step cards, the current one outlined. */
.cm-step .fi-section-header-heading {
    display: flex;
    align-items: flex-start;
    gap: 0.625rem;
}

.cm-step-number {
    display: inline-flex;
    flex: none;
    align-items: center;
    justify-content: center;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 9999px;
    background-color: var(--gray-100);
    color: var(--gray-600);
    font-size: 0.75rem;
    font-weight: 700;
}

.cm-step .fi-section-header-description {
    padding-inline-start: 2.125rem;
}

.cm-step,
.cm-step > .fi-section {
    height: 100%;
}

.cm-step .fi-section-content-ctn,
.cm-step .fi-section-footer {
    border-top: 0;
}

.cm-step .fi-section-footer {
    padding-block: 0 1rem;
    padding-inline: calc(2.125rem + 1rem) 1rem;
}

.cm-step-done .cm-step-number {
    background-color: var(--success-100);
    color: var(--success-700);
}

.cm-step-current > .fi-section {
    box-shadow: 0 0 0 2px var(--primary-600);
}

.cm-step-current .cm-step-number {
    background-color: var(--primary-600);
    color: var(--color-white);
}

/* The crop dialog for a listing photo. */
.cm-photo-crop-dialog {
    width: min(42rem, calc(100vw - 2rem));
    margin: auto;
    padding: 1.5rem;
    border: 0;
    border-radius: 0.75rem;
    background-color: var(--color-white);
    box-shadow: var(--shadow-xl);
}

.cm-photo-crop-dialog::backdrop {
    background-color: rgb(3 7 18 / 0.5);
}

.dark .cm-photo-crop-dialog {
    background-color: var(--gray-900);
}

/* Header actions stay top right beside a long subheading. */
@media (min-width: 64rem) {
    .fi-header {
        flex-wrap: nowrap;
        align-items: flex-start;
    }

    .fi-header > div:first-child:not(.fi-header-actions-ctn) {
        flex: 1;
        width: auto;
        min-width: 0;
    }

    .fi-header .fi-header-actions-ctn {
        flex-shrink: 0;
    }
}

/*
 * The organisation panel shows the signed-in user's organisation at the top
 * of the sidebar. It replaces Filament's tenant menu, which is a dropdown
 * with nothing in it because each user belongs to one organisation.
 */
.cm-current-organisation {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-top: -1rem;
    padding: 0.5rem;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--gray-950);
}

.cm-current-organisation .fi-tenant-avatar {
    max-width: none;
    flex-shrink: 0;
}

.cm-current-organisation-name {
    min-width: 0;
    overflow-wrap: anywhere;
}

.dark .cm-current-organisation {
    color: var(--color-white);
}
