.account .notice {
    padding: 12px 16px;
    border-radius: var(--border-radius-small);
    background: var(--color-surface-raised);
}

code.apiKey {
    display: block;
    padding: 10px 12px;
    border-radius: var(--border-radius-small);
    background: var(--color-surface-raised);
    color: var(--color-text-strong);
    font-family: var(--font-family-mono);
    word-break: break-all;
    user-select: all;
}

.meter {
    &.small {
        max-width: 240px;
        height: 6px;
        margin-top: 8px;
    }

    height: 8px;
    border-radius: 4px;
    background: var(--color-surface-raised);
    overflow: hidden;

    > div {
        height: 100%;
        background: var(--color-accent);
    }
}

/* Chart colors: the brand green and a magenta, checked apart for color-blind readers in both themes */
.statTiles,
.usageChart {
    --color-chart-succeeded: #0CA85F;
    --color-chart-failed: #D6409F;
}

[data-theme="dark"] .statTiles,
[data-theme="dark"] .usageChart {
    --color-chart-succeeded: #3DDC97;
    --color-chart-failed: #E8678F;
}

.usage {
    display: flex;
    flex-direction: column;
    gap: 14px;
    transition: opacity .15s;

    &.isLoading {
        opacity: .5;
        pointer-events: none;
    }
}

.usageHeader {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 10px;

    h2 {
        margin: 0;
    }
}

/* The site's selects are native ones; this one gets the look of the account area's small buttons */
.usageRange select {
    appearance: none;
    padding: 8px 34px 8px 14px;
    border: solid var(--color-border-strong) 1px;
    border-radius: 20px;
    background: var(--color-surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236A6A72' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 13px center;
    color: var(--color-text);
    font: inherit;
    font-size: var(--font-size-small);
    cursor: pointer;

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

.statTiles {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;

    @media (max-width: 960px) {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .statTile {
        display: flex;
        flex-direction: column;
        gap: 2px;
        padding: 14px 16px;
        border: solid var(--color-border) 1px;
        border-radius: var(--border-radius-big);
        background: var(--color-surface);
    }

    .label {
        font-size: var(--font-size-small);
        color: var(--color-text-faint);
    }

    .value {
        font-size: 1.9em;
        font-weight: 600;
        line-height: 1.2;
        color: var(--color-text-strong);
        font-variant-numeric: tabular-nums;
    }

    .detail {
        font-size: var(--font-size-small);
        color: var(--color-text-muted);
    }

    .meter > div {
        background: var(--color-chart-succeeded);
    }
}

.usageChart {
    margin: 0;
    padding: 20px 20px 14px;
    border: solid var(--color-border) 1px;
    border-radius: var(--border-radius-big);
    background: var(--color-surface);

    i {
        display: inline-block;
        width: 10px;
        height: 10px;
        border-radius: 3px;

        &.succeeded { background: var(--color-chart-succeeded); }
        &.failed { background: var(--color-chart-failed); }
    }

    .title {
        font-weight: 600;
        color: var(--color-text-strong);
    }

    /* The left margin holds the y-axis values, the bottom one the dates */
    .plot {
        position: relative;
        height: 220px;
        margin: 8px 0 28px 36px;
    }

    .gridLine {
        position: absolute;
        left: 0;
        right: 0;
        border-top: solid var(--color-border-subtle) 1px;

        &.baseline {
            border-top-color: var(--color-border-strong);
        }

        span {
            position: absolute;
            right: calc(100% + 8px);
            transform: translateY(-50%);
            font-size: 11px;
            color: var(--color-text-faint);
            font-variant-numeric: tabular-nums;
        }
    }

    .bars {
        position: absolute;
        inset: 0;
        display: flex;
        margin: 0;
        padding: 0;
        list-style: none;
    }

    /* Each period is a full-height column and a link to its conversions, so the whole column is the hover and click
       target, not just the bar */
    li {
        position: relative;
        flex: 1;
        display: flex;
    }

    li > a {
        flex: 1;
        display: flex;
        flex-direction: column;
        justify-content: flex-end;
        align-items: center;
        border-radius: 4px;
        color: inherit;
        text-decoration: none;
        outline: none;

        &:hover,
        &:focus-visible {
            background: var(--color-accent-tint);
        }

        &:focus-visible {
            box-shadow: inset 0 0 0 2px var(--color-accent);
        }

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

    .stack {
        display: flex;
        flex-direction: column;
        gap: 2px;
        width: 64%;
        max-width: 22px;
        min-height: 2px;
        border-radius: 4px 4px 0 0;
        overflow: hidden;

        span {
            min-height: 2px;
        }

        .succeeded { background: var(--color-chart-succeeded); }
        .failed { background: var(--color-chart-failed); }
    }

    .bars:hover li:not(:hover) .stack {
        opacity: .55;
    }

    .xLabel {
        position: absolute;
        top: calc(100% + 8px);
        font-size: 11px;
        white-space: nowrap;
        color: var(--color-text-faint);
    }

    li.current .xLabel {
        right: 0;
        color: var(--color-text-strong);
        font-weight: 600;
    }

    .tip {
        display: none;
        flex-direction: column;
        gap: 3px;
        position: absolute;
        top: 0;
        left: calc(100% + 6px);
        z-index: 2;
        width: max-content;
        min-width: 150px;
        padding: 10px 12px;
        border: solid var(--color-border) 1px;
        border-radius: var(--border-radius-small);
        background: var(--color-surface);
        box-shadow: 0 6px 20px var(--color-shadow);
        font-size: var(--font-size-small);
        color: var(--color-text);
        pointer-events: none;

        b {
            color: var(--color-text-strong);
            margin-bottom: 2px;
        }

        span {
            display: flex;
            align-items: center;
            gap: 8px;
        }

        small {
            margin-top: 3px;
            font-size: 12px;
            color: var(--color-text-faint);
        }

        em {
            margin-left: auto;
            font-style: normal;
            font-weight: 600;
            font-variant-numeric: tabular-nums;
            color: var(--color-text-strong);
        }
    }

    /* Tooltips open beside the day, towards the middle of the chart, so they never cover its bar or leave the card */
    li.tipLeft .tip {
        left: auto;
        right: calc(100% + 6px);
    }

    .empty {
        position: absolute;
        inset: 0;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0 20px;
        text-align: center;
        color: var(--color-text-muted);
    }

    .legend {
        display: flex;
        flex-wrap: wrap;
        gap: 18px;
        font-size: var(--font-size-small);
        color: var(--color-text-muted);

        span {
            display: inline-flex;
            align-items: center;
            gap: 7px;
        }
    }
}

.dangerZone h2 {
    color: var(--color-error);
}

.Button.danger {
    color: var(--color-error);

    &:hover {
        background: var(--color-error);
        color: var(--color-on-error);
    }
}

.accountContent .accountEmail {
    color: var(--color-text-faint);
}

.accountLayout {
    display: grid;
    grid-template-columns: 210px minmax(0, 1fr);
    gap: 40px;
    align-items: start;

    @media (max-width: 720px) {
        grid-template-columns: minmax(0, 1fr);
        gap: 20px;
    }
}

.accountMenu {
    display: flex;
    flex-direction: column;
    gap: 2px;
    position: sticky;
    top: 20px;

    @media (max-width: 720px) {
        position: static;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 6px;
    }

    form {
        margin: 0;
    }

    a, button {
        display: flex;
        align-items: center;
        width: 100%;
        background: none;
        border: 0;
        font: inherit;
        text-align: left;
        cursor: pointer;
        gap: 10px;
        padding: 9px 12px;
        border-radius: var(--border-radius-small);
        color: var(--color-text);
        text-decoration: none;

        svg {
            width: 18px;
            height: 18px;
            flex: none;
        }

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

        &.selected {
            background: var(--color-surface-raised);
            font-weight: 600;
        }

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

.accountContent {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;

    h2 {
        margin: 10px 0 0;
    }

    h2:first-child {
        margin-top: 0;
    }

    p {
        margin: 0;
    }
}

.apiKeyBox {
    display: flex;
    gap: 10px;
    align-items: stretch;

    code.apiKey {
        flex: 1;
        min-width: 0;
    }
}

code.apiKey.hint {
    display: inline-block;
    letter-spacing: 1px;
}

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

    th, td {
        text-align: left;
        vertical-align: top;
        padding: 9px 12px 9px 0;
        border-bottom: solid var(--color-border-subtle) 1px;
    }

    th {
        width: 200px;
        font-weight: 600;
        color: var(--color-text-faint);
    }

    &.invoices th {
        width: auto;
    }

    .status {
        text-transform: capitalize;
    }
}

.accountConvertForm {
    padding: 20px;
    border: solid var(--color-border) 1px;
    border-radius: var(--border-radius-big);
    background: var(--color-surface);
}

.tableScroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Format and file name badges, in the Conversions list and in a conversion's details */
.accountContent {
    .badge {
        display: inline-block;
        margin: 1px 3px 1px 0;
        padding: 2px 7px;
        border-radius: 20px;
        font-size: .78em;
        line-height: 1.5;
        white-space: nowrap;
    }

    .formatBadge {
        background: var(--color-surface-raised);
        color: var(--color-text-strong);
        font-weight: 600;
        letter-spacing: .3px;
    }
}

table.conversionsTable {
    th {
        width: auto;
        white-space: nowrap;
    }

    td.nowrap {
        white-space: nowrap;
    }

    /* Long names are cut with an ellipsis; the whole name is in the tooltip */
    .fileBadge {
        background: var(--color-accent-tint);
        color: var(--color-accent-text);
        max-width: 14em;
        overflow: hidden;
        text-overflow: ellipsis;
        vertical-align: middle;
    }

    .conversionStatus {
        &.done { color: var(--color-accent-text); }
        &.failed { color: var(--color-error); }
    }

    .Button.small {
        --padding-base: 5px;
        display: inline-flex;
    }
}

.historyFilters {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 0;
    padding: 16px;
    border: solid var(--color-border) 1px;
    border-radius: var(--border-radius-big);
    background: var(--color-surface);

    .presets {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }

    .preset {
        padding: 5px 12px;
        border: solid var(--color-border) 1px;
        border-radius: 20px;
        font-size: var(--font-size-small);
        color: var(--color-text-soft);
        text-decoration: none;

        &:hover {
            border-color: var(--color-border-strong);
            background: var(--color-surface-raised);
        }

        &.selected {
            border-color: var(--color-accent);
            background: var(--color-accent-tint);
            color: var(--color-accent-text);
            font-weight: 600;
        }
    }

    .fields {
        display: flex;
        flex-wrap: wrap;
        align-items: flex-end;
        gap: 10px 14px;
    }

    label {
        display: flex;
        flex-direction: column;
        gap: 4px;
        font-size: var(--font-size-small);
        color: var(--color-text-faint);
    }

    input,
    select {
        box-sizing: border-box;
        height: 40px;
        padding: 0 10px;
        border: solid var(--color-border-strong) 1px;
        border-radius: var(--border-radius-small);
        background: var(--color-surface);
        color: var(--color-text);
        font: inherit;
        font-size: var(--font-size-small);
    }

    .Button.small {
        --padding-base: 7px;
        display: inline-flex;
    }
}

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

.pagination {
    display: flex;
    justify-content: flex-end;
    gap: 8px;

    .Button.small {
        --padding-base: 6px;
        display: inline-flex;
    }
}

/* A conversion's details: a page of its own, and the Conversions list's dialog */
.conversionDetails {
    --color-tint-failed: color-mix(in srgb, var(--color-error) 10%, transparent);
    display: flex;
    flex-direction: column;
    gap: 20px;
    color: var(--color-text);

    h3 {
        margin: 0 0 10px;
        font-size: var(--font-size-small);
        font-weight: 600;
        letter-spacing: .04em;
        text-transform: uppercase;
        color: var(--color-text-faint);
    }

    .cdHeader {
        display: flex;
        align-items: center;
        gap: 14px;
        min-width: 0;
    }

    /* The image's average color, behind an image icon */
    .cdSwatch {
        flex: none;
        display: grid;
        place-items: center;
        width: 52px;
        height: 52px;
        border-radius: 14px;
        background: var(--color-surface-raised);
        box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08);

        svg {
            width: 22px;
            height: 22px;
            color: #FFFFFF;
            filter: drop-shadow(0 1px 2px rgba(0, 0, 0, .5));
        }
    }

    .cdHeading {
        min-width: 0;
    }

    .cdTitle {
        margin: 0 0 6px;
        font-size: 1.35em;
        line-height: 1.2;
        overflow-wrap: anywhere;
    }

    .cdMeta {
        display: flex;
        flex-wrap: wrap;
        align-items: center;
        gap: 6px 10px;
        font-size: var(--font-size-small);
        color: var(--color-text-muted);
    }

    .cdPill,
    .cdChip {
        display: inline-flex;
        align-items: center;
        padding: 2px 10px;
        border-radius: 20px;
        font-size: 13px;
        line-height: 1.6;
        white-space: nowrap;
    }

    .cdPill {
        font-weight: 600;

        &::before {
            content: '';
            width: 7px;
            height: 7px;
            margin-right: 6px;
            border-radius: 50%;
            background: currentColor;
        }

        &.done { background: var(--color-accent-tint); color: var(--color-accent-text); }
        &.failed { background: var(--color-tint-failed); color: var(--color-error); }
        &.progress { background: var(--color-surface-raised); color: var(--color-text-strong); }
        &.neutral { background: var(--color-surface-raised); color: var(--color-text-muted); }
    }

    .cdChip {
        border: solid var(--color-border) 1px;
        color: var(--color-text-soft);
    }

    .cdId {
        display: flex;
        align-items: center;
        flex-wrap: wrap;
        gap: 8px 12px;
        padding: 10px 12px;
        border-radius: var(--border-radius-small);
        background: var(--color-surface-raised);

        /* Plain text, not the article's dark code block */
        /* Its own line when the label and button leave it too little room */
        code {
            flex: 1 1 19em;
            min-width: 0;
            display: block;
            padding: 0;
            border: 0;
            border-radius: 0;
            background: none;
            line-height: 1.5;
            font-family: var(--font-family-mono);
            font-size: 14px;
            color: var(--color-text-strong);
            word-break: break-all;
            user-select: all;
        }

        .Button.small {
            --padding-base: 5px;
            display: inline-flex;
        }
    }

    .cdLabel {
        font-size: var(--font-size-small);
        color: var(--color-text-faint);
    }

    .cdAlert {
        display: flex;
        gap: 12px;
        padding: 14px 16px;
        border-radius: var(--border-radius-small);

        > svg {
            flex: none;
            width: 20px;
            height: 20px;
            margin-top: 2px;
        }

        &.error {
            background: var(--color-tint-failed);
            border: solid color-mix(in srgb, var(--color-error) 30%, transparent) 1px;

            > svg, b { color: var(--color-error); }
        }

        ul {
            margin: 6px 0 0;
            padding: 0;
            list-style: none;
            display: flex;
            flex-direction: column;
            gap: 6px;
        }

        li .badge {
            margin-right: 8px;
        }

        p {
            margin: 8px 0 0;
            font-size: var(--font-size-small);
            color: var(--color-text-muted);
        }
    }

    /* Tiles that grow to fill their row, so a short last row leaves no empty cell; the 1px gaps show the
       background as dividers */
    .cdFacts {
        display: flex;
        flex-wrap: wrap;
        gap: 1px;
        margin: 0;
        border: solid var(--color-border) 1px;
        border-radius: var(--border-radius-small);
        background: var(--color-border);
        overflow: hidden;

        > div {
            flex: 1 1 96px;
            padding: 10px 14px;
            background: var(--color-surface);
        }

        dt {
            font-size: 13px;
            color: var(--color-text-faint);
        }

        dd {
            margin: 2px 0 0;
            font-weight: 600;
            color: var(--color-text-strong);
            font-variant-numeric: tabular-nums;

            small {
                display: block;
                font-weight: 400;
                font-size: 12px;
                color: var(--color-text-muted);
            }
        }
    }

    /* Each event is a dot on a line: its name, its time, and how long after the conversion was received */
    .cdTimeline {
        margin: 0;
        padding: 0;
        list-style: none;

        li {
            position: relative;
            display: grid;
            grid-template-columns: 18px 1fr auto auto;
            align-items: baseline;
            gap: 12px;
            padding-bottom: 14px;
            font-size: var(--font-size-small);

            &:not(:last-child)::after {
                content: '';
                position: absolute;
                left: 5px;
                top: 14px;
                bottom: -2px;
                width: 2px;
                background: var(--color-border);
            }

            &:last-child {
                padding-bottom: 0;
            }
        }

        .cdDot {
            align-self: center;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: var(--color-accent);
            box-shadow: 0 0 0 3px var(--color-accent-tint);
        }

        li.failed .cdDot {
            background: var(--color-error);
            box-shadow: 0 0 0 3px var(--color-tint-failed);
        }

        li.upcoming .cdDot,
        li.current .cdDot {
            background: var(--color-surface);
            border: solid var(--color-border-strong) 2px;
            box-shadow: none;
            box-sizing: border-box;
        }

        .cdEvent {
            font-weight: 600;
            color: var(--color-text-strong);

            small {
                font-weight: 400;
                color: var(--color-text-faint);
            }
        }

        li.failed .cdEvent {
            color: var(--color-error);
        }

        time {
            color: var(--color-text-soft);
            font-variant-numeric: tabular-nums;
        }

        .cdOffset {
            min-width: 4.5em;
            text-align: right;
            color: var(--color-text-faint);
            font-variant-numeric: tabular-nums;
        }
    }

    .cdVariants {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
        gap: 12px;
    }

    .cdVariant {
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 14px;
        border: solid var(--color-border) 1px;
        border-radius: var(--border-radius-small);
        background: var(--color-surface);

        header {
            display: flex;
            align-items: center;
            flex-wrap: wrap;
            gap: 6px;
        }
    }

    .cdVariantTime {
        display: inline-flex;
        align-items: center;
        gap: 4px;
        margin-left: auto;
        font-size: 13px;
        color: var(--color-text-faint);
        font-variant-numeric: tabular-nums;

        svg {
            width: 14px;
            height: 14px;
        }
    }

    .cdMetrics {
        display: flex;
        flex-wrap: wrap;
        gap: 8px 22px;
        margin: 0;

        dt {
            font-size: 12px;
            color: var(--color-text-faint);
        }

        dd {
            margin: 0;
            font-weight: 600;
            color: var(--color-text-strong);
            font-variant-numeric: tabular-nums;
            white-space: nowrap;
        }
    }

    .cdNote {
        display: flex;
        gap: 8px;
        margin: 0;
        font-size: var(--font-size-small);

        svg {
            flex: none;
            width: 16px;
            height: 16px;
            margin-top: 3px;
        }

        &.error svg { color: var(--color-error); }
        &.warning svg { color: var(--color-text-muted); }
    }

    .cdParameters {
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
        margin: 0;
        padding: 0;
        list-style: none;

        li {
            padding: 2px 8px;
            border-radius: 6px;
            background: var(--color-surface-raised);
            font-size: 12px;
            color: var(--color-text-muted);
        }

        b {
            font-weight: 600;
            color: var(--color-text-strong);
        }
    }

    .cdFileName {
        margin: 0;
        font-family: var(--font-family-mono);
        font-size: 12px;
        color: var(--color-text-faint);
        word-break: break-all;
    }

    .cdActions {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
    }
}

/* Only its content scrolls: not the dialog (the browser's own height limit is lifted) and not the panel, which keeps
   the close button in place */
dialog.conversionDialog {
    width: min(780px, 100vw);
    max-height: 100dvh;
    overflow: hidden;

    > .Panel {
        position: relative;
        display: flex;
        flex-direction: column;
        max-height: calc(100dvh - 40px);
        padding: 0;
        overflow: hidden;
        border-radius: var(--border-radius-big);
    }

    .cdBody {
        min-height: 0;
        padding: 28px;
        overflow-y: auto;
        overscroll-behavior: contain;

        @media (max-width: 600px) {
            padding: 20px;
        }
    }

    /* In the dialog the list is right behind it: no link back to it */
    .cdBack {
        display: none;
    }

    .cdActions:not(:has(> :not(.cdBack))) {
        display: none;
    }

    .cdHeader {
        padding-right: 40px;
    }

    .cdBody.isLoading {
        min-height: 300px;
    }
}

.cdClose {
    position: absolute;
    top: 16px;
    right: 16px;
    z-index: 1;
    display: grid;
    place-items: center;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 50%;
    background: var(--color-surface-raised);
    color: var(--color-text);
    cursor: pointer;

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

    svg {
        width: 18px;
        height: 18px;
    }
}
