/*
 * Rechnungstool – leichte, ruhige Anpassungen an Bootstrap 5.3 (Entwicklerhandbuch Kap. 11)
 */
:root {
    --app-primary: #1f2a6b;
    --app-primary-hover: #182155;
    --bs-primary: #1f2a6b;
    --bs-primary-rgb: 31, 42, 107;
    --bs-link-color: #1f2a6b;
    --bs-link-color-rgb: 31, 42, 107;
    --bs-link-hover-color: #182155;
    --bs-link-hover-color-rgb: 24, 33, 85;
    --bs-body-bg: #f8f9fa;
    --bs-body-font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

body {
    background-color: #f8f9fa;
}

.btn-primary {
    --bs-btn-bg: var(--app-primary);
    --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: var(--app-primary-hover);
    --bs-btn-hover-border-color: var(--app-primary-hover);
    --bs-btn-active-bg: var(--app-primary-hover);
    --bs-btn-active-border-color: var(--app-primary-hover);
    --bs-btn-disabled-bg: var(--app-primary);
    --bs-btn-disabled-border-color: var(--app-primary);
}

.btn-outline-primary {
    --bs-btn-color: var(--app-primary);
    --bs-btn-border-color: var(--app-primary);
    --bs-btn-hover-bg: var(--app-primary);
    --bs-btn-hover-border-color: var(--app-primary);
    --bs-btn-active-bg: var(--app-primary);
    --bs-btn-active-border-color: var(--app-primary);
}

.form-control:focus,
.form-select:focus {
    border-color: #8f95b5;
    box-shadow: 0 0 0 .2rem rgba(31, 42, 107, .15);
}

/* Navigation */
.app-navbar {
    background-color: #fff;
    border-bottom: 1px solid var(--bs-border-color);
}

.app-navbar .navbar-brand {
    color: var(--app-primary);
    font-weight: 600;
}

.app-navbar .nav-link {
    color: #495057;
}

.app-navbar .nav-link:hover,
.app-navbar .nav-link.active {
    color: var(--app-primary);
}

.app-navbar .nav-link.active {
    font-weight: 600;
}

/* Karten: weiß, dünner Rand, ohne Schatten */
.card {
    border: 1px solid var(--bs-border-color);
    box-shadow: none;
}

.table > :not(caption) > * > * {
    padding: .65rem .75rem;
}

.table thead th {
    font-weight: 600;
    font-size: .875rem;
    color: #6c757d;
    white-space: nowrap;
}

/* Gast-Seiten (Login) */
.guest-box {
    max-width: 24rem;
}

.guest-brand {
    color: var(--app-primary);
    font-size: 1.35rem;
    font-weight: 600;
    text-decoration: none;
}

.error-card {
    max-width: 32rem;
}

/* Formulare */
.form-card {
    max-width: 40rem;
}

.form-label .text-danger {
    font-weight: 600;
}

/* Firmen-Badge (Farbe per JS aus data-badge-color) */
.company-badge {
    background-color: #6c757d;
    color: #fff;
    font-weight: 500;
}

.company-tabs .nav-link {
    color: #495057;
}

.company-tabs .nav-link.active {
    color: var(--app-primary);
    font-weight: 600;
}

.logo-preview {
    display: inline-block;
    padding: .75rem 1rem;
    background: #fff;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
}

.logo-preview img {
    max-height: 4rem;
    max-width: 100%;
}

.secret-hidden {
    display: none;
}

.settings-nav .nav-link {
    color: #495057;
}

.settings-nav .nav-link.active {
    background-color: var(--app-primary);
    color: #fff;
}

.form-check-input:checked {
    background-color: var(--app-primary);
    border-color: var(--app-primary);
}

.form-check-input:focus {
    border-color: #8f95b5;
    box-shadow: 0 0 0 .2rem rgba(31, 42, 107, .15);
}

/* Adressblock-Vorschau (wie auf der Rechnung) */
.address-preview-box {
    font-size: .875rem;
}

.address-preview {
    background: #fff;
    border: 1px dashed var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    padding: .75rem 1rem;
    min-height: 6.5rem;
    color: #343a40;
    line-height: 1.35;
}

.collapse-chevron {
    display: inline-block;
    transition: transform .15s ease;
}

[aria-expanded="true"] > .collapse-chevron {
    transform: rotate(90deg);
}

@media (min-width: 992px) {
    .sticky-offset {
        top: 1rem;
    }
}

/* Kundenauswahl mit Vervollständigung */
.customer-picker {
    position: relative;
}

.customer-picker-results {
    position: absolute;
    z-index: 1060;
    left: 0;
    right: 0;
    max-height: 18rem;
    overflow-y: auto;
    box-shadow: 0 .5rem 1rem rgba(0, 0, 0, .1);
}

.customer-picker-results .list-group-item {
    cursor: pointer;
}

.customer-picker-results .list-group-item.active {
    background-color: var(--app-primary);
    border-color: var(--app-primary);
}

.customer-picker-results .list-group-item.active .text-secondary {
    color: rgba(255, 255, 255, .8) !important;
}

.customer-picker.is-invalid .invalid-feedback {
    display: block;
}

.customer-picker.is-invalid [data-picker-input] {
    border-color: var(--bs-form-invalid-border-color);
}

.customer-picker-address {
    line-height: 1.35;
}

/* Rechnungseditor: Positionen */
.item-head,
.item-row .item-grid {
    display: grid;
    grid-template-columns: 1.25rem 5rem 6rem minmax(12rem, 1fr) 9.75rem 6.75rem 6rem 4.25rem;
    gap: .375rem;
    align-items: start;
}

.item-head {
    font-size: .8125rem;
    font-weight: 600;
    color: #6c757d;
    padding: 0 0 .375rem;
    border-bottom: 1px solid var(--bs-border-color);
}

.item-row {
    padding: .5rem 0;
    border-bottom: 1px solid var(--bs-border-color-translucent);
    background: #fff;
}

.item-row-group .item-grid {
    grid-template-columns: 1.25rem minmax(10rem, 1fr) 4.5rem;
}

.item-row-group {
    background: #f8f9fa;
}

.item-row-group .group-title {
    background: transparent;
}

.item-description {
    margin: .375rem 0 0;
    /* von der Spalte Bezeichnung bis einschließlich USt. */
    padding-left: calc(1.25rem + 5rem + 6rem + 3 * .375rem);
    padding-right: calc(6rem + 4.25rem + 2 * .375rem);
}

.item-description textarea {
    color: #495057;
    resize: vertical;
}

.item-errors {
    color: var(--bs-form-invalid-color);
    font-size: .8125rem;
    padding-left: 1.625rem;
}

.item-errors:empty {
    display: none;
}

.drag-handle {
    cursor: grab;
    color: #adb5bd;
    padding-top: .3rem;
}

.drag-handle:hover {
    color: #495057;
}

.item-ghost {
    opacity: .4;
}

.item-sum {
    padding-top: .3rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.item-actions {
    display: flex;
    justify-content: flex-end;
}

.item-actions .btn {
    padding: .25rem .35rem;
}

.price-mode {
    min-width: 3.6rem;
    font-size: .75rem;
}

.price-mode.active {
    background-color: #fff3cd;
    border-color: #e0c060;
    color: #664d03;
}

.item-desc-toggle {
    flex-shrink: 0;
}

.item-desc-toggle.active {
    background-color: #e9ecef;
    color: #212529;
}

.net-hint {
    font-size: .75rem;
    min-height: 0;
}

/* Summenkasten */
.totals {
    display: grid;
    grid-template-columns: 1fr auto;
    row-gap: .375rem;
    column-gap: .75rem;
    font-variant-numeric: tabular-nums;
}

.totals dt {
    font-weight: 500;
}

.totals dd {
    margin: 0;
    text-align: right;
    white-space: nowrap;
}

.totals .total {
    border-top: 1px solid var(--bs-border-color);
    padding-top: .5rem;
    font-weight: 700;
    font-size: 1.05rem;
}

.save-status[data-state="dirty"] {
    color: #664d03;
}

.conflict-text {
    white-space: pre-wrap;
    background: #f8f9fa;
    border: 1px solid var(--bs-border-color);
    border-radius: var(--bs-border-radius);
    padding: .375rem .5rem;
    min-height: 2rem;
}

@media (max-width: 991.98px) {
    .item-head {
        display: none;
    }

    .item-row .item-grid {
        grid-template-columns: 1.25rem 1fr 1fr;
    }

    .item-row .item-grid > :nth-child(4),
    .item-row .item-grid > :nth-child(5) {
        grid-column: 2 / 4;
    }

    .item-row .item-grid > :nth-child(6) {
        grid-column: 2;
    }

    .item-row .item-grid > .item-actions {
        grid-column: 2 / 4;
    }

    .item-row-group .item-grid > .item-actions {
        grid-column: auto;
    }

    .item-row-group .item-grid {
        grid-template-columns: 1.25rem 1fr auto;
    }

    .item-description {
        padding: 0 0 0 1.625rem;
    }
}

/* Ansicht abgeschlossener Rechnungen */
.text-prewrap {
    white-space: pre-wrap;
}

.invoice-items-view td,
.invoice-items-view th {
    font-variant-numeric: tabular-nums;
}

/* Rechnungsliste */
.open-total {
    flex: 0 0 auto;
    min-width: 12rem;
    font-variant-numeric: tabular-nums;
}

.invoice-list td {
    font-variant-numeric: tabular-nums;
}

.invoice-list .teaser {
    max-width: 18rem;
}

/* Erlöskonten im Firmenformular (Tab DATEV, N5) */
.revenue-accounts .col-account { width: 7rem; }
.revenue-accounts .col-tax-rate { width: 12rem; }
