/* The month grid of the hours (Views/Timesheet): the arrows of the month in the bar, a narrow cell per day and the totals on
   the right and at the foot. On a computer the whole month fits the page; on a narrower screen the delete and the project
   stay on the left while the days scroll sideways. The colours are apollo.css's tokens, so the dark appearance follows. */
.atlas-timesheet-bar {
    flex-wrap: wrap;
    gap: var(--apollo-space-2);
}

.atlas-month-nav {
    display: flex;
    align-items: center;
    gap: var(--apollo-space-2);
}

.atlas-month-label {
    min-width: 9.5rem;
    margin: 0;
    font-size: var(--apollo-text-md);
    font-weight: 600;
    text-align: center;
}

.atlas-timesheet-person .form-select {
    min-width: 12rem;
}

.atlas-timesheet-empty {
    padding: var(--apollo-space-4);
}

.atlas-timesheet .apollo-table {
    /* With the field's 1 px side padding, 12,75 fits in the page's letter. */
    --atlas-day-width: 2.25rem;
    --atlas-actions-width: 2.25rem;
    --atlas-project-width: 9.5rem;
    --atlas-total-width: 4rem;
    width: auto;
}

.atlas-timesheet .apollo-table th,
.atlas-timesheet .apollo-table td {
    padding: 2px 0;
    text-align: center;
}

.atlas-timesheet .apollo-table thead th {
    line-height: 1.1;
}

/* A day's header is as wide as its field, also in a month without rows. */
.atlas-timesheet .apollo-table thead th:not(.apollo-row-actions, .atlas-timesheet-project, .atlas-timesheet-total) {
    min-width: var(--atlas-day-width);
}

.atlas-timesheet-day,
.atlas-timesheet-weekday {
    display: block;
}

.atlas-timesheet-weekday {
    font-size: var(--apollo-text-xs);
    font-weight: 400;
}

.atlas-timesheet .apollo-table .apollo-row-actions {
    position: sticky;
    left: 0;
    z-index: 1;
    width: var(--atlas-actions-width);
    min-width: var(--atlas-actions-width);
    padding: 2px 4px;
    background: var(--apollo-surface);
}

.atlas-timesheet .apollo-row-actions .btn {
    padding: 1px 6px;
}

.atlas-timesheet .apollo-table .atlas-timesheet-project {
    position: sticky;
    left: var(--atlas-actions-width);
    z-index: 1;
    min-width: var(--atlas-project-width);
    max-width: 12rem;
    padding: 2px 8px;
    overflow: hidden;
    text-align: left;
    text-overflow: ellipsis;
    white-space: nowrap;
    background: var(--apollo-surface);
}

/* A message of the grid's page keeps its lines, what happened and then what to do; atlas-timesheet.js, which only this page
   loads, trims the space around it. */
body:has(.atlas-timesheet) [data-apollo-toast] > span {
    white-space: pre-line;
}

/* The two fixed columns stay over the days in the header too. */
.atlas-timesheet .apollo-table thead .apollo-row-actions,
.atlas-timesheet .apollo-table thead .atlas-timesheet-project {
    z-index: 2;
    background: var(--apollo-accent-soft);
}

.atlas-timesheet .apollo-table td .form-control {
    width: var(--atlas-day-width);
    min-height: 0;
    margin: 0 auto;
    padding: 3px 1px;
    border-color: var(--apollo-line);
    border-radius: 4px;
    background-image: none;
    font-size: inherit;
    text-align: center;
}

.atlas-timesheet .apollo-table td .form-select {
    min-height: 0;
    padding-top: 2px;
    padding-bottom: 2px;
    font-size: inherit;
}

.atlas-timesheet .atlas-weekend {
    background: var(--apollo-off-bg);
}

.atlas-timesheet .atlas-holiday {
    background: var(--apollo-warn-bg);
}

/* A marked day keeps its colour in the empty cells too. */
.atlas-timesheet td.atlas-weekend .form-control,
.atlas-timesheet td.atlas-holiday .form-control {
    background: transparent;
}

.atlas-timesheet .apollo-table .form-control.atlas-changed {
    border-color: var(--apollo-brand);
    background: var(--apollo-accent-soft);
}

.atlas-timesheet .apollo-table .form-control.is-invalid {
    border-color: var(--apollo-err);
    background: var(--apollo-err-bg);
}

/* A day's error shows under it only while the cell is in use, over the next row, so the row keeps its height and no two
   errors cover each other; the mouse reads it in the field's title. */
.atlas-timesheet .apollo-table td:focus-within:has(> .is-invalid):not(.atlas-timesheet-project) {
    position: relative;
    z-index: 3;
}

.atlas-timesheet .apollo-table td:not(.atlas-timesheet-project) > .invalid-feedback {
    display: none;
}

.atlas-timesheet .apollo-table td:focus-within:not(.atlas-timesheet-project) > .is-invalid + .invalid-feedback {
    position: absolute;
    top: 100%;
    left: 0;
    z-index: 3;
    display: block;
    width: max-content;
    max-width: 16rem;
    margin: 0;
    padding: 1px 4px;
    border-radius: 4px;
    background: var(--apollo-err);
    color: var(--apollo-on-brand);
    font-size: var(--apollo-text-xs);
    white-space: normal;
}

.atlas-timesheet .atlas-timesheet-project > .invalid-feedback {
    display: block;
    margin: 0;
    white-space: normal;
}

/* A row marked to delete, struck through until the save removes it. */
.atlas-timesheet .apollo-table tr.atlas-deleted > td:not(.apollo-row-actions) {
    color: var(--apollo-ink-2);
    text-decoration: line-through;
}

.atlas-timesheet .apollo-table tr.atlas-deleted .form-control {
    text-decoration: line-through;
    opacity: 0.6;
}

.atlas-timesheet .apollo-row-actions .btn[aria-pressed="true"] {
    background: var(--apollo-err-bg);
}

.atlas-timesheet .atlas-timesheet-total {
    min-width: 3.5rem;
    padding: 2px 8px;
    font-weight: 600;
    text-align: right;
}

/* A day whose hours pass the limit, told while typing, as the save will refuse it. */
.atlas-timesheet tfoot td.atlas-over {
    background: var(--apollo-err-bg);
    color: var(--apollo-err);
}

/* The row and the day of the cell in use: a tint over the cell's own colour, so a weekend or a holiday still shows. */
.atlas-timesheet .apollo-table tr.atlas-current > td,
.atlas-timesheet .apollo-table th.atlas-current,
.atlas-timesheet .apollo-table td.atlas-current {
    box-shadow: inset 0 0 0 100vmax rgb(var(--apollo-brand-tint) / 0.1);
}

/* The block selected: a stronger tint, on the field where there is one, so a changed day still shows and a see-through
   weekend field is not tinted twice; the cell in use stays clear, as in a spreadsheet. */
.atlas-timesheet .apollo-table tbody td.atlas-selected:not(:has(> .form-control)),
.atlas-timesheet .apollo-table td.atlas-selected > .form-control:not(:focus) {
    box-shadow: inset 0 0 0 100vmax rgb(var(--apollo-brand-tint) / 0.25);
}

.atlas-timesheet-sum {
    margin-left: auto;
    font-weight: 600;
}

.atlas-timesheet-status {
    margin: 0;
    padding: var(--apollo-space-2) var(--apollo-space-3);
    color: var(--apollo-warn);
    background: var(--apollo-warn-bg);
}

.atlas-timesheet tfoot th,
.atlas-timesheet tfoot td {
    border-top: 2px solid var(--apollo-line);
    font-weight: 600;
}

.atlas-timesheet-legend {
    display: inline-flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

/* The legend's colours, the same as the cells'. */
.atlas-timesheet-legend > i {
    display: inline-block;
    width: 12px;
    height: 12px;
    margin-left: var(--apollo-space-3);
    border: 1px solid var(--apollo-line);
    border-radius: 3px;
}

.atlas-timesheet-legend > i.atlas-weekend {
    background: var(--apollo-off-bg);
}

.atlas-timesheet-legend > i.atlas-holiday {
    background: var(--apollo-warn-bg);
}

.atlas-timesheet-legend > i.atlas-changed {
    border-color: var(--apollo-brand);
    background: var(--apollo-accent-soft);
}

/* From 1200 px the month fits the page with no sideways scroll: the delete, the project and the total keep their width and
   the days share the rest. A narrow day writes smaller, so 12,75 always fits; around 33 px a day keeps the page's letter. */
@media (min-width: 1200px) {
    .atlas-timesheet .apollo-table-wrap {
        container-type: inline-size;
    }

    .atlas-timesheet .apollo-table {
        --atlas-day-width: calc((100cqi - var(--atlas-actions-width) - var(--atlas-project-width) - var(--atlas-total-width)) / var(--atlas-days));
        width: 100%;
        table-layout: fixed;
    }

    .atlas-timesheet .apollo-table.atlas-days-28 {
        --atlas-days: 28;
    }

    .atlas-timesheet .apollo-table.atlas-days-29 {
        --atlas-days: 29;
    }

    .atlas-timesheet .apollo-table.atlas-days-30 {
        --atlas-days: 30;
    }

    .atlas-timesheet .apollo-table.atlas-days-31 {
        --atlas-days: 31;
    }

    .atlas-timesheet .apollo-table .atlas-timesheet-project {
        width: var(--atlas-project-width);
    }

    .atlas-timesheet .apollo-table .atlas-timesheet-total {
        width: var(--atlas-total-width);
    }

    .atlas-timesheet .apollo-table th:not(.apollo-row-actions, .atlas-timesheet-project, .atlas-timesheet-total),
    .atlas-timesheet .apollo-table td:not(.apollo-row-actions, .atlas-timesheet-project, .atlas-timesheet-total) {
        min-width: 0;
        font-size: clamp(8px, calc(var(--atlas-day-width) * 0.42 - 1px), 1em);
    }

    /* No side padding, so 12,75 keeps the page's letter down to 33 px. */
    .atlas-timesheet .apollo-table td .form-control {
        width: 100%;
        padding-right: 0;
        padding-left: 0;
    }
}

/* Below 576 px only the project stays on the left, in a narrow column whose name takes two lines, so more days show beside
   it. The fields keep 16 px, below which a phone zooms in on a tap, and are large enough for a finger. */
@media (max-width: 575.98px) {
    /* The phone's 16 px letter needs a wider day for 12,75. */
    .atlas-timesheet .apollo-table {
        --atlas-day-width: 2.75rem;
    }

    .atlas-timesheet .apollo-table .apollo-row-actions {
        position: static;
    }

    .atlas-timesheet .apollo-table .atlas-timesheet-project {
        left: 0;
        min-width: 6rem;
        max-width: 6rem;
        padding: 2px 4px;
        font-size: var(--apollo-text-sm);
        line-height: 1.2;
        white-space: normal;
    }

    .atlas-timesheet-name {
        display: -webkit-box;
        overflow: hidden;
        overflow-wrap: anywhere;
        -webkit-box-orient: vertical;
        -webkit-line-clamp: 2;
    }

    .atlas-timesheet .apollo-table td .form-control {
        padding: 8px 1px;
        font-size: 16px;
    }
}
