html, body {
    margin: 0;
    font-family: Roboto, "Segoe UI", Helvetica, Arial, sans-serif;
}

.app-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    height: 100vh;
    color: #0b4f8a;
    font-size: 1.1rem;
}

.app-loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid #d0dcea;
    border-top-color: #0b4f8a;
    border-radius: 50%;
    animation: app-spin 0.9s linear infinite;
}

@keyframes app-spin {
    to {
        transform: rotate(360deg);
    }
}

#blazor-error-ui {
    background: #fff4ce;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 2000;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 16px;
}

.page-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

/* Section heading inside a list (check positions, position photos). */
.section-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 12px;
    padding: 4px 0;
    border-bottom: 2px solid var(--mud-palette-primary);
}

/* One position in the check overview. */
.position-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 8px;
    padding: 6px 0;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.position-row-main {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex: 1 1 260px;
    min-width: 0;
    color: inherit;
    text-decoration: none;
}

.position-row-main:hover .position-title {
    text-decoration: underline;
}

.position-code {
    min-width: 2.6em;
    font-weight: 700;
    color: var(--mud-palette-primary);
}

.position-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.position-meta {
    font-size: 0.8rem;
    color: var(--mud-palette-text-secondary);
}

.position-row-tags {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
}

.position-photos {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 0.85rem;
    color: var(--mud-palette-text-secondary);
}

/* Sales total of a position in the check overview, links to its calculation. */
.position-amount {
    display: inline-flex;
    align-items: center;
    justify-content: flex-end;
    gap: 2px;
    min-width: 7.5em;
    font-variant-numeric: tabular-nums;
    color: inherit;
    text-decoration: none;
}

.position-amount:hover {
    text-decoration: underline;
}

.text-right {
    text-align: right !important;
}

/* Calculation */
.calc-totals {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 8px;
}

.calc-total {
    display: flex;
    flex-direction: column;
    padding: 6px 10px;
    border-radius: 6px;
    background: var(--mud-palette-background-gray);
    font-variant-numeric: tabular-nums;
}

.calc-total-main {
    background: var(--mud-palette-primary);
    color: var(--mud-palette-primary-text);
}

.calc-total-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    opacity: 0.8;
}

.calc-total-note {
    font-size: 0.75rem;
    opacity: 0.8;
}

.calc-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 12px 0 4px 0;
}

/*
 * Calculation lines share one grid, so every kind puts quantity, unit, the fields a/b/c, the amounts and the menu
 * into the same columns: material and free item use a = accuracy, b = price, c = factor; work uses a = work type,
 * b = place, c = time. Groups are marked by a bar on the left instead of an indent, so lines inside a group
 * have exactly the same columns as lines outside.
 * The layout follows the width of the editor (container query), not of the window.
 */
.calc-editor {
    container-type: inline-size;
}

.calc-line,
.calc-group-header {
    display: grid;
    grid-template-columns: 28px minmax(150px, 1fr) 92px 64px 190px 136px 136px 96px 60px;
    grid-template-areas: "icon main qty unit a b c amounts end";
    align-items: center;
    column-gap: 8px;
}

.calc-line {
    padding: 2px 0;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.calc-group-header {
    grid-template-areas: "icon name comp comp comp add add amounts end";
    background: var(--mud-palette-background-gray);
}

.calc-cell {
    min-width: 0;
}

.calc-cell .mud-input-control {
    margin-top: 4px;
    margin-bottom: 4px;
}

.calc-cell-icon { grid-area: icon; display: flex; align-items: center; }
.calc-cell-main { grid-area: main; }
.calc-cell-qty { grid-area: qty; }
.calc-cell-unit { grid-area: unit; }
.calc-cell-a { grid-area: a; }
.calc-cell-b { grid-area: b; }
.calc-cell-c { grid-area: c; }
.calc-cell-name { grid-area: name; }
.calc-cell-comp { grid-area: comp; }
.calc-cell-add { grid-area: add; display: flex; align-items: center; }

.calc-cell-amounts {
    grid-area: amounts;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    font-size: 0.85rem;
    line-height: 1.2;
    font-variant-numeric: tabular-nums;
}

.calc-cell-end {
    grid-area: end;
    display: flex;
    align-items: center;
    justify-content: flex-end;
}

/* The unit of material (from the article) and of work (hours) is shown as text in the unit column. */
.calc-unit-text {
    padding-top: 4px;
    padding-left: 4px;
    color: var(--mud-palette-text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.calc-number input {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.calc-group-lines {
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
}

.calc-group {
    margin-top: 12px;
}

.calc-group .calc-line,
.calc-group .calc-group-header {
    box-shadow: inset 3px 0 0 var(--mud-palette-primary);
}

.calc-group .calc-line .calc-cell-icon {
    padding-left: 6px;
}

/* Medium width (laptop with menu): the main field gets its own row. */
@container (max-width: 1080px) {
    .calc-line,
    .calc-group-header {
        grid-template-columns: 28px 92px 64px minmax(120px, 1fr) 136px 136px 96px 60px;
        grid-template-areas:
            "icon main main main main main amounts end"
            ".    qty  unit a    b    c    .       .";
    }

    .calc-group-header {
        grid-template-areas:
            "icon name name name name name amounts end"
            ".    comp comp comp add  add  .       .";
    }
}

/* Phone and narrow windows: main field and menu; quantity, unit and amounts; accuracy or work type; price and factor or place and time. */
@container (max-width: 820px) {
    .calc-line,
    .calc-group-header {
        grid-template-columns: 28px repeat(4, minmax(0, 1fr)) 48px;
        grid-template-areas:
            "icon main main main main end"
            ".    qty  qty  unit amounts amounts"
            ".    a    a    a    a    a"
            ".    b    b    c    c    c";
    }

    .calc-group-header {
        grid-template-areas:
            "icon name name name name end"
            ".    comp comp comp comp comp"
            ".    add  add  amounts amounts amounts";
    }
}

/* Report and offers */
.report-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 16px;
    margin-top: 12px;
}

.report-picture-body {
    display: flex;
    gap: 12px;
    align-items: flex-start;
}

.report-picture-body .photo-thumbnail {
    width: 160px;
    height: 120px;
    object-fit: cover;
    flex: 0 0 auto;
}

.report-picture-actions {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    min-width: 0;
    overflow-wrap: anywhere;
}

.issued-documents {
    display: flex;
    flex-direction: column;
}

.issued-document {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 4px;
    border-bottom: 1px solid var(--mud-palette-lines-default);
    color: inherit;
    text-decoration: none;
}

.issued-document:hover {
    background: var(--mud-palette-action-default-hover);
}

.issued-document-text {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.issued-document-row {
    display: flex;
    align-items: center;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.issued-document-row > .issued-document {
    flex: 1;
    min-width: 0;
    border-bottom: none;
}

.issued-document .mud-chip {
    margin: 0 0 0 auto;
}

.offer-item {
    border-bottom: 1px solid var(--mud-palette-lines-default);
    padding: 4px 0;
}

.offer-item-group {
    box-shadow: inset 3px 0 0 var(--mud-palette-primary);
    padding-left: 8px;
}

.offer-item-optional .offer-item-main {
    opacity: 0.75;
}

.offer-item-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px 12px;
}

.offer-item-main {
    flex: 1 1 320px;
    min-width: 0;
}

.offer-item-position {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 10px;
}

.offer-item-price {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    width: 170px;
}

.offer-item-calculated {
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
    font-variant-numeric: tabular-nums;
}

.offer-item-difference {
    font-size: 0.75rem;
    color: var(--mud-palette-success);
}

.offer-item-difference-down {
    color: var(--mud-palette-warning);
}

.offer-item-issued {
    font-size: 0.75rem;
    color: var(--mud-palette-info);
}

.offer-subtitle {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.offer-subtitle .mud-chip {
    margin: 0;
}

/* One payment of an offer: share, when due, payment period. On a phone the text gets its own row. */
.payment-row {
    display: grid;
    grid-template-columns: 110px minmax(160px, 1fr) 110px 36px;
    grid-template-areas: "percent text days remove";
    gap: 8px;
    align-items: start;
}

.payment-percent {
    grid-area: percent;
}

.payment-text {
    grid-area: text;
}

.payment-days {
    grid-area: days;
}

.payment-row > .mud-icon-button {
    grid-area: remove;
    margin-top: 8px;
}

.bexio-status {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
}

.bexio-status > div {
    flex: 1;
    min-width: 200px;
}

.bexio-contact {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 4px 10px;
    margin: 8px 0;
}

.bexio-contact-text {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 160px;
}

.bexio-token {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 720px;
}

.bexio-steps {
    margin: 4px 0 8px 20px;
}

.payment-row-template {
    grid-template-columns: 110px minmax(140px, 1fr) minmax(140px, 1fr) 110px 36px;
    grid-template-areas: "percent text text-en days remove";
}

.payment-text-en {
    grid-area: text-en;
}

.payment-plan-header {
    display: flex;
    align-items: center;
    gap: 8px;
    max-width: 520px;
}

@media (max-width: 900px) {
    .payment-row-template {
        grid-template-columns: 1fr 1fr 36px;
        grid-template-areas:
            "text text text"
            "text-en text-en text-en"
            "percent days remove";
        padding-bottom: 8px;
        border-bottom: 1px solid var(--mud-palette-lines-default);
    }
}

@media (max-width: 600px) {
    .payment-row:not(.payment-row-template) {
        grid-template-columns: 1fr 1fr 36px;
        grid-template-areas:
            "text text text"
            "percent days remove";
        padding-bottom: 8px;
        border-bottom: 1px solid var(--mud-palette-lines-default);
    }
}

.offer-item-switch {
    flex: 0 0 auto;
}

.offer-group-children {
    margin: 2px 0 4px 16px;
}

.offer-child {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 2px 10px;
    padding: 2px 0;
}

.offer-child-title {
    flex: 1 1 160px;
    min-width: 0;
    overflow-wrap: anywhere;
}

.offer-position-choices {
    max-height: 55vh;
    overflow-y: auto;
}

.offer-position-choice {
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.offer-position-choice-title {
    flex: 1 1 auto;
    min-width: 0;
}

.article-select {
    display: flex;
    align-items: center;
    gap: 2px;
}

.article-select > :first-child {
    flex: 1 1 auto;
    min-width: 0;
}

.article-option {
    display: flex;
    flex-direction: column;
    line-height: 1.25;
}

.article-option-meta {
    font-size: 0.75rem;
    color: var(--mud-palette-text-secondary);
}

.parameter-group {
    height: 100%;
}

.work-type-rate {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0 8px;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.work-type-rate-name {
    display: flex;
    flex-direction: column;
    flex: 2 1 220px;
}

.work-type-rate .mud-input-control {
    flex: 1 1 140px;
}

/* On a phone two figures per row, the total across. */
@media (max-width: 600px) {
    .calc-totals {
        grid-template-columns: 1fr 1fr;
    }

    .calc-total-main {
        grid-column: 1 / -1;
    }
}

.nowrap {
    white-space: nowrap;
}

.import-changes {
    max-height: 45vh;
    overflow-y: auto;
}

/* Photos */
.photo-input-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
    overflow: hidden;
    pointer-events: none;
}

.capture-buttons {
    display: grid;
    gap: 8px;
    margin-top: 8px;
}

.photo-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 10px;
}

.photo-tile {
    position: relative;
    border: 1px solid var(--mud-palette-lines-default);
    border-radius: 6px;
    padding: 4px;
    cursor: pointer;
    background: var(--mud-palette-surface);
}

.photo-tile-selected {
    outline: 3px solid var(--mud-palette-primary);
}

.photo-tile-check {
    position: absolute;
    top: 8px;
    right: 8px;
    background: white;
    border-radius: 50%;
}

.photo-thumbnail {
    display: block;
    width: 100%;
    aspect-ratio: 4 / 3;
    object-fit: cover;
    border-radius: 4px;
    background: #eef1f5;
}

.photo-thumbnail-missing {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--mud-palette-text-secondary);
}

.photo-tile-caption {
    font-size: 0.75rem;
    margin-top: 4px;
    word-break: break-all;
}

.photo-tile-tags,
.photo-tile-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    margin-top: 2px;
}

.photo-tile-actions {
    justify-content: flex-end;
}

.photo-dialog-image img {
    display: block;
    max-width: 100%;
    max-height: 45vh;
    margin: 0 auto;
    border-radius: 4px;
}

.drop-zone {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 18px;
    border: 2px dashed var(--mud-palette-lines-default);
    border-radius: 8px;
    color: var(--mud-palette-text-secondary);
    text-align: center;
}

.drop-zone:hover {
    border-color: var(--mud-palette-primary);
}

.drop-zone-disabled {
    opacity: 0.6;
}

.drop-zone-input {
    position: absolute;
    inset: 0;
    opacity: 0;
    cursor: pointer;
}

.drop-zone-disabled .drop-zone-input {
    cursor: not-allowed;
}

/* Structure editor: one row per component, fields wrap on small screens. */
.structure-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    column-gap: 8px;
    padding: 2px 0;
    border-bottom: 1px solid var(--mud-palette-lines-default);
}

.structure-row .structure-name {
    flex: 2 1 180px;
}

.structure-row .structure-token {
    flex: 1 1 140px;
}

.structure-letter {
    display: inline-block;
    min-width: 1.6em;
    font-weight: 600;
    color: var(--mud-palette-primary);
}

.structure-spacer {
    display: inline-block;
    width: 34px;
}

/* Machine data of a component on its own line, aligned with the name field. */
.structure-machine-data {
    flex-basis: 100%;
    padding-left: 68px;
    margin: -4px 0 4px 0;
}

/* Check page tabs: compact on a phone, so more tabs fit next to each other. MudTabs sets the minimum width inline. */
@media (max-width: 600px) {
    .check-tabs .mud-tab {
        min-width: 0 !important;
        padding: 6px 12px;
    }

    .check-tabs .mud-tab .mud-icon-root {
        display: none;
    }
}
