/*
 * chota overrides
 */
:root {
    --color-error: #b32424;
    --color-primary: #417690;
    --color-primary-dark: #205067;
}

textarea {
    resize: vertical;
}

label {
    cursor: pointer;
}

fieldset {
    margin-block: 2rem;
}

input[readonly],
input[readonly]:hover {
    background-color: var(--color-lightGrey);
    border-color: var(--color-lightGrey);
}

/* chota gives an outline to primary, secondary and dark, but not to error. */
.button.outline.error {
    border-color: var(--color-error);
    color: var(--color-error);
}

/*
 * app styles
 */

.icon {
    width: 1.2em;
    height: 1.2em;
    fill: currentColor;
    vertical-align: -0.125em;
}

header {
    border-bottom: 1px solid var(--color-primary);

    .nav-left {
        a {
            padding-inline: 0;

            .icon {
                width: 128px;
                height: 128px;
                fill: #000;
                vertical-align: baseline;
            }
        }
    }
}

/*
 * chota's container class carries a margin and a padding of its own, so this
 * selector names the class and outweighs it.
 */
footer.container {
    margin-top: 4rem;
    padding-top: 1rem;
    border-top: 1px solid var(--color-primary);
}

/* The payout method decides which set of bank details is asked for. */
form:has(#banktype-eu:checked) #bank-noneu,
form:has(#banktype-noneu:checked) #bank-eu {
    display: none;
}

/*
 * Required fields carry a marker. Its empty alternative text keeps it out of
 * the field's accessible name, which states the requirement already.
 */
p:has(:required, [aria-required="true"]) label::after,
receipt-upload:has([aria-required="true"]) label::after {
    content: "*" / "";
    color: var(--color-error);
}

.help {
    color: var(--color-grey);
    font-size: 0.9em;
}

/* The space above is the line the label takes, so the text starts at the input. */
.row > .help {
    padding-top: calc(var(--font-size) * 1.6);
}

/* Below the width where chota stacks the columns, no field stands beside the text. */
@media screen and (max-width: 599px) {
    .row > .help {
        order: -1;
        padding-top: 0;
    }
}

/* A noscript holds a whole message, so it is a block like the message itself. */
noscript {
    display: block;
}

/*
 * A field that still needs attention is found by the message it holds, so the
 * markup carries no class of its own. The message is the mark and the colour
 * repeats it, so that colour alone never has to carry the meaning.
 */
form p:has(strong) label,
form p:has(strong) strong,
#errors strong,
noscript strong {
    color: var(--color-error);
}

/*
 * The field itself is framed in the same colour. chota's field selectors test
 * an attribute, so this one tests one too and outweighs them. It leaves out the
 * checkbox, which has no frame to colour. It names the hover state, because
 * chota's hover rule would turn the frame grey again.
 */
form p:has(strong) :is(input, textarea):not([type="checkbox"]),
form p:has(strong) :is(input, textarea):not([type="checkbox"]):hover {
    border-color: var(--color-error);
}

/* The fields of an expense stand beside the button that drops the row. */
expense-row {
    display: grid;
    /* a zero minimum keeps a long file name from widening the row */
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    margin-bottom: var(--grid-gutter);

    > .row {
        grid-column: 1;
        margin-right: 0;
    }

    /*
     * The tracks follow the turned text and run downwards. The icon takes the
     * head, the text the middle. The empty track at the end balances the first.
     */
    > [data-remove] {
        display: grid;
        grid-column: 2;
        grid-row: 1 / -1;
        grid-template-columns: 1fr auto 1fr;
        align-items: center;
        margin-bottom: calc(var(--grid-gutter) / 2);
        padding: 1rem 0.75rem;
        writing-mode: vertical-rl;

        .icon {
            /* turned letters sit right of the middle of their line */
            translate: 0.0625em 0;
        }
    }
}

/* Below the width where chota stacks the columns, no button stands beside the row. */
@media screen and (max-width: 599px) {
    expense-row {
        grid-template-columns: minmax(0, 1fr);

        > [data-remove] {
            grid-column: 1;
            grid-row: auto;
            writing-mode: horizontal-tb;

            .icon {
                translate: none;
            }
        }
    }
}

/*
 * Invisible field that is used only to show a validation error when no expense
  rows are present.
 */
expense-rows [data-empty] {
    display: inline-block;
    width: 1px;
    height: 1px;
    padding: 0;
    border: 0;
    opacity: 0;
    vertical-align: middle;
}

claim-total output {
    font-weight: bold;
}

/**
 * Custom component that handles the file uploads
 */
receipt-upload {
    /* file list */
    ul {
        margin-top: 0.5em;
        margin-bottom: 1em;
        padding-left: 0;
        &:not(:has(li)) {
            display: none;
            margin-bottom: 0;
        }

        /* a receipt keeps to one line */
        li {
            display: flex;
            align-items: baseline;
            gap: 0.5em;
            padding-block: 0.25em;
            list-style: none;

            /* every part but the name keeps the room it asks for */
            > :not([data-name]) {
                flex: none;
            }

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

        /* a long name is cut short */
        [data-name] {
            flex: 1;
            overflow: hidden;
            text-overflow: ellipsis;
            white-space: nowrap;
        }
    }

    /* a receipt is removed through an icon, which needs no button frame */
    [data-receipt-delete] {
        padding: 0 0.5em;
        background: none;
        color: var(--color-error);
    }

    /* dropzone wraps a native file select button */
    .dropzone {
        position: relative;
        display: block;
        padding: 1.5rem;
        border: 1px dashed var(--color-primary);
        border-radius: 4px;
        color: var(--color-primary);
        text-align: center;
        cursor: pointer;

        /* fills the whole dropzone, but stays invisible */
        input[type="file"] {
            position: absolute;
            inset: 0;
            width: 100%;
            height: 100%;
            opacity: 0;
            cursor: inherit;
        }

        /* files held over the zone mark it, like the pointer and the keyboard do */
        &:hover,
        &:has(input:focus-visible),
        &:has(input[data-over]) {
            border-color: var(--color-primary-dark);
            background-color: var(--color-lightGrey);
        }

        /* an upload turns the picker off, so nothing can be picked or dropped */
        &:has(input:disabled) {
            border-color: var(--color-grey);
            background-color: transparent;
            color: var(--color-grey);
            cursor: default;
        }
    }
}
