:root {
    --nav-bg: #f8f9fa;
}

@media (prefers-color-scheme: dark) {
    :root {
        --nav-bg: #343a40;
    }
}

main {
    padding: 0.3em;
    padding-top: calc(1em + env(safe-area-inset-top, 0px));
    max-width: 560px;
    width: 96%;
}

label,
.helptext {
    display: block;
}

.helptext {
    font-size: 0.7em;
    margin-top: -12px;
}

.error {
    background-color: #ffc9c9;
    margin: 0;
    padding: 0.6em 1em;
    width: 100%;
}

.suggestion {
    /* match the submit button's vertical-align + margin-bottom so the
       text midlines land in the same place */
    display: inline-block;
    vertical-align: middle;
    margin-bottom: 0.5rem;
    padding-left: 1em;
}

table {
    margin-bottom: 1rem;
}

/* keep the gap above the submit button consistent across forms:
   grid items don't margin-collapse, so trapped margins inside .row
   would otherwise add to the row's height */
.row > p {
    margin-bottom: 0;
}

.row p > input:last-child {
    margin-bottom: 0;
}

/* race nutrition rows */
.nutrition-header {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.3rem;
}

.nutrition-header .when {
    flex: 0 0 8ch;
}

.nutrition-header .food {
    flex: 1 1 auto;
}

.nutrition-actions {
    display: flex;
    justify-content: space-between;
}

.nutrition-row {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.nutrition-row .when {
    flex: 0 0 8ch;
}

.nutrition-row .food {
    flex: 1 1 auto;
    min-width: 0;
}

.nutrition-row input,
.nutrition-row select {
    width: 100%;
    margin-bottom: 0;
}

.nutrition-row .controls {
    flex: 0 0 auto;
    display: flex;
    gap: 0.2rem;
}

.nutrition-row .controls button {
    min-width: 0;
    margin-bottom: 0;
    padding: 0;
    width: 1.5rem;
    background: transparent;
    border: none;
    font-size: 1rem;
    line-height: 1;
    cursor: pointer;
}

/* nav */
.nav-link {
    position: fixed;
    bottom: calc(0.5em + env(safe-area-inset-bottom, 0px));
    right: 1.5em;
    border: 2px solid var(--fg);
    background-color: var(--bg);
    padding: 0.4em;
    z-index: 10;
}

#calculator-nav {
    background-color: var(--nav-bg);
    position: absolute;
    width: 100%;
    right: 0;
    bottom: 0;
    padding: 1.5em;
    padding-bottom: calc(44px + 1em + env(safe-area-inset-bottom, 0px));
    margin: 0;
    display: none;
    flex-direction: column;
    align-items: flex-end;
    gap: 0.3rem;
}

#calculator-nav.open {
    display: flex;
}

/* desktop: nav becomes a fixed left sidebar */
@media (min-width: 768px) {
    .nav-link {
        display: none;
    }

    #calculator-nav {
        display: flex;
        position: fixed;
        top: 0;
        bottom: 0;
        left: 0;
        right: auto;
        width: 260px;
        padding: 1.5em;
        padding-top: calc(5.25em + env(safe-area-inset-top, 0px));
        align-items: flex-start;
        overflow-y: auto;
    }

    /* keep main centred in the space right of the sidebar */
    body {
        padding-left: 260px;
    }
}

/* hidden by default */
section {
    display: none;
}
