/* =============================================================================
   Rechnungstracker - Modern UI Styles
   TeDaCo GmbH
============================================================================= */

:root {
    /* Colors - Dark Theme */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: #1a1a25;
    --bg-card-hover: #22222f;
    --bg-glass: rgba(26, 26, 37, 0.8);

    --text-primary: #ffffff;
    --text-secondary: #a0a0b0;
    --text-muted: #6b6b7b;

    --accent-primary: #6366f1;
    --accent-primary-hover: #818cf8;
    --accent-success: #10b981;
    --accent-warning: #f59e0b;
    --accent-danger: #ef4444;
    --accent-info: #3b82f6;

    --border-color: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(99, 102, 241, 0.3);

    /* Gradients */
    --gradient-primary: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
    --gradient-success: linear-gradient(135deg, #10b981 0%, #34d399 100%);
    --gradient-warning: linear-gradient(135deg, #f59e0b 0%, #fbbf24 100%);
    --gradient-danger: linear-gradient(135deg, #ef4444 0%, #f87171 100%);
    --gradient-glass: linear-gradient(135deg, rgba(255, 255, 255, 0.1) 0%, rgba(255, 255, 255, 0.05) 100%);

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-2xl: 3rem;

    /* Border Radius */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-xl: 24px;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 30px rgba(99, 102, 241, 0.2);

    /* Transitions */
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-slow: 0.4s ease;
}

/* Reset & Base */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    overflow-x: hidden;
}

/* Background Pattern */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(circle at 20% 20%, rgba(99, 102, 241, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 80% 80%, rgba(139, 92, 246, 0.08) 0%, transparent 40%);
    pointer-events: none;
    z-index: -1;
}

/* =============================================================================
   Header
============================================================================= */

.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-xl);
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.logo-icon {
    font-size: 1.5rem;
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.nav-tabs {
    display: flex;
    gap: var(--space-xs);
    background: var(--bg-secondary);
    padding: var(--space-xs);
    border-radius: var(--radius-lg);
}

.nav-tab {
    padding: var(--space-sm) var(--space-lg);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all var(--transition-normal);
}

.nav-tab:hover {
    color: var(--text-primary);
    background: var(--bg-card);
}

.nav-tab.active {
    color: var(--text-primary);
    background: var(--gradient-primary);
}

/* =============================================================================
   Buttons
============================================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-sm) var(--space-lg);
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-normal);
}

.btn-primary {
    background: var(--gradient-primary);
    color: white;
    box-shadow: var(--shadow-sm), 0 0 20px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md), 0 0 30px rgba(99, 102, 241, 0.4);
}

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
}

.btn-ghost:hover {
    color: var(--text-primary);
    background: var(--bg-card);
}

.btn-success {
    background: var(--gradient-success);
    color: white;
}

.btn-danger {
    background: var(--gradient-danger);
    color: white;
}

.btn-sm {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.75rem;
}

/* =============================================================================
   Main Content
============================================================================= */

.main-content {
    padding: var(--space-xl);
    max-width: 1600px;
    margin: 0 auto;
}

.view {
    display: none;
    animation: fadeIn 0.3s ease;
}

.view.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* =============================================================================
   Dashboard
============================================================================= */

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-lg);
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    border: 1px solid var(--border-color);
    transition: all var(--transition-normal);
    position: relative;
    overflow: hidden;
}

.stat-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--gradient-primary);
}

.stat-card.primary::before {
    background: var(--gradient-primary);
}

.stat-card.success::before {
    background: var(--gradient-success);
}

.stat-card.warning::before {
    background: var(--gradient-warning);
}

.stat-card.danger::before {
    background: var(--gradient-danger);
}

.stat-card.accent::before {
    background: linear-gradient(90deg, #6366f1, #8b5cf6, #a855f7);
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
    border-color: var(--border-glow);
}

.stat-card.wide {
    grid-column: span 2;
}

.stat-icon {
    font-size: 2rem;
    opacity: 0.9;
}

.stat-content {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.stat-value {
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.stat-sublabel {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.ust-breakdown {
    display: flex;
    gap: var(--space-md);
    margin-left: auto;
    flex-wrap: wrap;
}

.ust-q {
    text-align: center;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}

.ust-q-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: block;
}

.ust-q-value {
    font-size: 0.9rem;
    font-weight: 600;
}

/* =============================================================================
   Cards
============================================================================= */

.card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.card.wide {
    grid-column: span 2;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-color);
}

.card-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

/* =============================================================================
   Invoice List
============================================================================= */

.invoice-list {
    max-height: 400px;
    overflow-y: auto;
}

.invoice-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    border-bottom: 1px solid var(--border-color);
    transition: background var(--transition-fast);
}

.invoice-item:last-child {
    border-bottom: none;
}

.invoice-item:hover {
    background: var(--bg-card-hover);
}

.invoice-info {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.invoice-nr {
    font-weight: 600;
    color: var(--text-primary);
}

.invoice-meta {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.invoice-amount {
    font-weight: 600;
    font-size: 1.1rem;
}

/* =============================================================================
   Status Badges
============================================================================= */

.status {
    display: inline-flex;
    align-items: center;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.status-offen {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
}

.status-bezahlt {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
}

.status-ueberfaellig {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
}

.status-teilweise {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
}

.status-storniert {
    background: rgba(107, 107, 123, 0.2);
    color: #a0a0b0;
}

/* =============================================================================
   View Header & Search
============================================================================= */

.view-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-md);
    flex-wrap: wrap;
    gap: var(--space-md);
}

/* Quick Filter Buttons */
.quick-filters {
    display: flex;
    gap: var(--space-sm);
    flex-wrap: wrap;
}

.quick-filter-btn {
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.quick-filter-btn:hover {
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.quick-filter-btn.active {
    background: var(--gradient-primary);
    border-color: transparent;
    color: white;
}

/* Filter Row */
.filter-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--space-lg);
    flex-wrap: wrap;
    gap: var(--space-md);
}

.filter-summary {
    font-size: 0.875rem;
    color: var(--text-muted);
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}

.view-header h2 {
    font-size: 1.5rem;
    font-weight: 700;
}

.search-bar {
    display: flex;
    gap: var(--space-sm);
}

.search-bar input,
.search-bar select {
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
    transition: all var(--transition-fast);
}

.search-bar input {
    min-width: 280px;
}

.search-bar input:focus,
.search-bar select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

/* =============================================================================
   Data Table
============================================================================= */

.table-container {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th,
.data-table td {
    padding: var(--space-md) var(--space-lg);
    text-align: left;
}

.data-table th {
    background: var(--bg-secondary);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.data-table td {
    border-bottom: 1px solid var(--border-color);
    font-size: 0.875rem;
}

.data-table tr:last-child td {
    border-bottom: none;
}

.data-table tr:hover td {
    background: var(--bg-card-hover);
}

.data-table .actions {
    display: flex;
    gap: var(--space-xs);
}

#invoices-table .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-width: 190px;
    align-content: center;
}

#rechnungen-view .table-container {
    overflow-x: auto;
}

.main-wrapper:has(#rechnungen-view.active) .main-content,
#rechnungen-view.active {
    min-width: 0;
    width: 100%;
}

#invoices-table {
    min-width: 1100px;
}

#invoices-table th:nth-child(8),
#invoices-table td:nth-child(8) {
    min-width: 150px;
}

#invoices-table .status {
    white-space: nowrap;
}

#invoices-table .status-zu_pruefen {
    background: rgba(245, 158, 11, 0.14);
    color: #fbbf24;
}

#invoices-table .invoice-skonto-status {
    align-items: flex-start;
    display: inline-flex;
    flex-direction: column;
    gap: 2px;
    line-height: 1.25;
    letter-spacing: 0;
    text-transform: none;
}

#invoices-table .invoice-skonto-status small {
    font-size: 0.7rem;
    font-weight: 500;
}

#invoices-table .actions .btn {
    justify-content: center;
    min-height: 30px;
    white-space: nowrap;
}

#invoices-table .actions [data-invoice-action="edit"] {
    grid-column: 1 / -1;
}

#invoices-table .actions [data-invoice-action="payment"]:first-child {
    grid-column: 1 / -1;
}

#invoices-table .actions .btn:focus-visible {
    outline: 2px solid #a5b4fc;
    outline-offset: 2px;
}

#invoice-modal .modal-close:focus-visible {
    outline: 2px solid #a5b4fc;
    outline-offset: 2px;
}

#invoices-table .actions .btn-ghost {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
}

#rechnungen-view .view-header > div:first-child {
    flex-wrap: wrap;
    gap: var(--space-md);
}

#rechnungen-view .quick-filters {
    flex: 1 1 760px;
    min-width: 0;
}

#rechnungen-view .invoice-duplicate-note,
#rechnungen-view .invoice-offset-note {
    flex: 1 0 100%;
}

@media (max-width: 640px) {
    #invoice-modal {
        padding: var(--space-sm);
    }

    #invoice-modal-content {
        max-height: calc(100% - var(--space-md));
    }

    #invoice-modal .modal-header {
        background: var(--bg-card);
        position: sticky;
        top: 0;
        z-index: 2;
    }

    #invoice-edit-split {
        flex-direction: column;
    }

    #invoice-edit-pdf-panel {
        border-right: 0 !important;
        border-bottom: 1px solid var(--border-color);
        flex: none !important;
        width: 100%;
    }

    #invoice-edit-pdf-viewer {
        height: min(30vh, 180px) !important;
    }

    #invoice-edit-form-panel {
        flex: none !important;
        max-height: none !important;
        overflow: visible !important;
        width: 100%;
    }

    #invoice-form {
        padding: var(--space-md);
    }

    #invoice-modal .form-actions {
        flex-wrap: wrap;
    }

    #invoice-modal .form-actions .btn {
        flex: 1 1 100%;
    }
}


/* =============================================================================
   Customers Grid
============================================================================= */

.customers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--space-lg);
}

.customer-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    padding: var(--space-lg);
    border: 1px solid var(--border-color);
    transition: all var(--transition-normal);
}

.customer-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.customer-name {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: var(--space-sm);
}

.customer-stats {
    display: flex;
    gap: var(--space-lg);
    margin-top: var(--space-md);
    padding-top: var(--space-md);
    border-top: 1px solid var(--border-color);
}

.customer-stat {
    display: flex;
    flex-direction: column;
}

.customer-stat-label {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.customer-stat-value {
    font-size: 1rem;
    font-weight: 600;
}

/* =============================================================================
   Modal
============================================================================= */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: var(--space-lg);
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    animation: modalIn 0.3s ease;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: scale(0.95);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg);
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    transition: color var(--transition-fast);
}

.modal-close:hover {
    color: var(--text-primary);
}

/* =============================================================================
   Form
============================================================================= */

#invoice-form {
    padding: var(--space-lg);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.form-group.full-width {
    grid-column: span 2;
}

.form-group label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-family: inherit;
    transition: all var(--transition-fast);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: var(--space-md);
    margin-top: var(--space-lg);
    padding-top: var(--space-lg);
    border-top: 1px solid var(--border-color);
}

/* =============================================================================
   Toggle Switch
============================================================================= */

.toggle-switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 24px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    transition: var(--transition-normal);
}

.toggle-switch .slider.round {
    border-radius: 24px;
}

.toggle-switch .slider.round::before {
    border-radius: 50%;
}

.toggle-switch .slider::before {
    position: absolute;
    content: '';
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background: var(--text-muted);
    transition: var(--transition-normal);
}

.toggle-switch input:checked+.slider {
    background: var(--accent-success);
    border-color: var(--accent-success);
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.4);
}

.toggle-switch input:checked+.slider::before {
    transform: translateX(18px);
    background: white;
}

/* =============================================================================
   Upload Dropzone
============================================================================= */

.upload-section {
    padding: 0 var(--space-lg);
    padding-top: var(--space-lg);
}

.upload-dropzone {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: var(--space-xl);
    text-align: center;
    cursor: pointer;
    transition: all var(--transition-normal);
    background: var(--bg-secondary);
}

.upload-dropzone:hover,
.upload-dropzone.dragover {
    border-color: var(--accent-primary);
    background: rgba(99, 102, 241, 0.1);
}

.upload-dropzone.uploading {
    border-color: var(--accent-warning);
    background: rgba(245, 158, 11, 0.1);
    pointer-events: none;
}

.upload-dropzone.success {
    border-color: var(--accent-success);
    background: rgba(16, 185, 129, 0.1);
}

.dropzone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-sm);
}

.dropzone-icon {
    font-size: 3rem;
    opacity: 0.7;
}

.dropzone-text {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-primary);
    margin: 0;
}

.dropzone-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin: 0;
}

.upload-status {
    margin-top: var(--space-md);
    text-align: center;
}

.upload-status.loading {
    color: var(--accent-warning);
}

.upload-status.success {
    color: var(--accent-success);
}

.upload-status.error {
    color: var(--accent-danger);
}

.upload-divider {
    display: flex;
    align-items: center;
    margin: var(--space-lg) 0;
    gap: var(--space-md);
}

.upload-divider::before,
.upload-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.upload-divider span {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* =============================================================================
   ELLIE Chat Widget
============================================================================= */

.ellie-widget {
    position: fixed;
    bottom: var(--space-xl);
    right: var(--space-xl);
    z-index: 500;
}

.ellie-toggle {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-md) var(--space-lg);
    background: var(--gradient-primary);
    border: none;
    border-radius: var(--radius-xl);
    color: white;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-lg), var(--shadow-glow);
    transition: all var(--transition-normal);
}

.ellie-toggle:hover {
    transform: scale(1.05);
}

.ellie-avatar {
    font-size: 1.25rem;
}

.ellie-chat {
    position: absolute;
    bottom: 70px;
    right: 0;
    width: 380px;
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: slideUp 0.3s ease;
}

.ellie-chat.active {
    display: flex;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.ellie-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    background: var(--gradient-primary);
    color: white;
}

.ellie-title {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

.ellie-title small {
    display: block;
    font-size: 0.7rem;
    opacity: 0.8;
}

.ellie-minimize {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background var(--transition-fast);
}

.ellie-minimize:hover {
    background: rgba(255, 255, 255, 0.3);
}

.ellie-messages {
    flex: 1;
    padding: var(--space-md);
    max-height: 350px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.message {
    padding: var(--space-md);
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    line-height: 1.5;
    max-width: 90%;
}

.message.bot {
    background: var(--bg-secondary);
    align-self: flex-start;
}

.message.user {
    background: var(--gradient-primary);
    color: white;
    align-self: flex-end;
}

.message ul {
    margin: var(--space-sm) 0;
    padding-left: var(--space-lg);
}

.message li {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.ellie-input {
    display: flex;
    gap: var(--space-sm);
    padding: var(--space-md);
    border-top: 1px solid var(--border-color);
}

.ellie-input input {
    flex: 1;
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.ellie-input input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.ellie-input button {
    width: 40px;
    height: 40px;
    background: var(--gradient-primary);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    transition: transform var(--transition-fast);
}

.ellie-input button:hover {
    transform: scale(1.05);
}

/* =============================================================================
   Scrollbar
============================================================================= */

::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-card-hover);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* =============================================================================
   Responsive
============================================================================= */

@media (max-width: 1200px) {
    .dashboard-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .header {
        flex-direction: column;
        gap: var(--space-md);
    }

    .nav-tabs {
        order: 3;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .stat-card.wide,
    .card.wide {
        grid-column: span 1;
    }

    .search-bar {
        flex-direction: column;
    }

    .search-bar input {
        min-width: auto;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .form-group.full-width {
        grid-column: span 1;
    }

    .ellie-chat {
        width: calc(100vw - 40px);
        right: -10px;
    }
}

/* =============================================================================
   Customer Accordion & Projects View
============================================================================= */

.customers-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.customer-accordion {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    overflow: hidden;
}

.customer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-md) var(--space-lg);
    cursor: pointer;
    transition: background var(--transition-fast);
}

.customer-header:hover {
    background: var(--bg-card-hover);
}

.customer-info {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.customer-info .customer-name {
    font-weight: 600;
    font-size: 1.1rem;
    margin: 0;
}

.customer-nr {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.customer-stats-row {
    display: flex;
    align-items: center;
    gap: var(--space-lg);
}

.customer-stats-row .stat {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.customer-stats-row .stat.warning {
    color: var(--accent-warning);
}

.customer-stats-row .stat.success {
    color: var(--accent-success);
}

.expand-icon {
    font-size: 0.9rem;
    color: var(--text-muted);
    transition: transform var(--transition-fast);
}

.customer-projects {
    background: var(--bg-secondary);
    padding: var(--space-md) var(--space-lg);
    border-top: 1px solid var(--border-color);
}

.project-group {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    margin-bottom: var(--space-sm);
    overflow: hidden;
}

.project-group:last-child {
    margin-bottom: 0;
}

.project-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: background var(--transition-fast);
}

.project-header:hover {
    background: var(--bg-card-hover);
}

.project-header.no-project {
    color: var(--text-muted);
    font-style: italic;
}

.project-stats {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.expand-icon-sm {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.project-invoices {
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
}

.mini-table {
    width: 100%;
    border-collapse: collapse;
}

.mini-table td {
    padding: var(--space-xs) var(--space-sm);
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border-color);
}

.mini-table tr:last-child td {
    border-bottom: none;
}

.mini-table strong {
    color: var(--text-primary);
}

.loading {
    padding: var(--space-md);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.no-data {
    padding: var(--space-md);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-style: italic;
}

.status-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}

.status-badge.status-offen {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
}

.status-badge.status-bezahlt {
    background: rgba(16, 185, 129, 0.2);
    color: #34d399;
}

.status-badge.status-ueberfaellig {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
}

.status-badge.status-teilweise {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
}

.status-badge.status-storniert {
    background: rgba(107, 107, 123, 0.2);
    color: #a0a0b0;
}

/* =============================================================================
   FiBu Rechnungspruefung
============================================================================= */

.studio-tabs {
    align-items: flex-end;
    display: flex;
    gap: 2px;
    min-height: 42px;
    overflow-x: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(99, 102, 241, 0.65) transparent;
}

.studio-tab {
    align-items: center;
    background: transparent;
    border: 0;
    border-bottom: 2px solid transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-size: 0.82rem;
    font-weight: 700;
    min-height: 40px;
    padding: 0 var(--space-md);
    white-space: nowrap;
}

.studio-tab:hover {
    background: rgba(255, 255, 255, 0.045);
    color: var(--text-primary);
}

.studio-tab.active {
    background: rgba(124, 92, 255, 0.13);
    border-bottom-color: var(--accent-primary);
    color: #ddd6fe;
}

.fibu-content,
.fibu-tab-content {
    max-width: none;
    width: 100%;
}

.fibu-period-toolbar {
    align-items: flex-end;
    display: flex;
    gap: var(--space-lg);
    justify-content: space-between;
    margin-bottom: var(--space-lg);
}

.fibu-period-toolbar h3 {
    font-size: 1.05rem;
    margin: 0 0 var(--space-xs);
}

.fibu-period-toolbar p,
.fibu-bwa-basis {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 0;
}

.fibu-bwa-basis {
    margin-bottom: var(--space-lg);
}

.fibu-period-year {
    display: grid;
    gap: 6px;
}

.fibu-period-year span {
    color: var(--text-secondary);
    font-size: 0.76rem;
    font-weight: 700;
}

.fibu-period-year select {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    min-height: 38px;
    padding: 0 var(--space-lg) 0 var(--space-md);
}

.fibu-period-summary {
    background: rgba(255, 255, 255, 0.03);
    border-bottom: 1px solid var(--border-color);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    margin-bottom: var(--space-lg);
}

.fibu-period-state {
    color: var(--text-secondary);
    margin: 0;
    padding: var(--space-md) var(--space-lg);
}

.fibu-period-state[data-state="error"] {
    color: var(--accent-danger);
}

.fibu-period-summary > .fibu-period-state {
    grid-column: 1 / -1;
    width: 100%;
}

@media (max-width: 640px) {
    .fibu-period-summary > .fibu-period-state {
        padding: var(--space-sm) var(--space-md);
    }
}

.fibu-period-summary > div {
    align-items: baseline;
    display: flex;
    gap: var(--space-sm);
    min-width: 190px;
    padding: var(--space-md) var(--space-lg);
}

.fibu-period-summary > div + div {
    border-left: 1px solid var(--border-color);
}

.fibu-period-summary strong {
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 1.15rem;
}

.fibu-period-summary span {
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.fibu-period-table-wrap {
    max-width: 100%;
    overflow-x: auto;
}

.fibu-period-table {
    min-width: 1260px;
}

.fibu-period-table th,
.fibu-period-table td {
    padding: 12px 14px;
    vertical-align: top;
}

.fibu-period-table th:nth-child(1) {
    width: 110px;
}

.fibu-period-table th:nth-child(2) {
    width: 165px;
}

.fibu-period-table th:nth-child(3) {
    width: 275px;
}

.fibu-period-table th:nth-child(4) {
    width: 165px;
}

.fibu-period-table th:nth-child(5) {
    width: 245px;
}

.fibu-period-table th:nth-child(7) {
    width: 190px;
}

.fibu-period-has-work td {
    background: rgba(99, 102, 241, 0.035);
}

.fibu-period-status {
    border-radius: 999px;
    display: inline-flex;
    font-size: 0.72rem;
    font-weight: 750;
    line-height: 1;
    padding: 7px 9px;
}

.fibu-period-status-offen {
    background: rgba(148, 163, 184, 0.14);
    color: #cbd5e1;
}

.fibu-period-status-in_arbeit,
.fibu-period-status-wiedereroeffnet {
    background: rgba(59, 130, 246, 0.18);
    color: #93c5fd;
}

.fibu-period-status-pruefbereit {
    background: rgba(245, 158, 11, 0.18);
    color: #fcd34d;
}

.fibu-period-status-vorlaeufig_abgeschlossen {
    background: rgba(139, 92, 246, 0.2);
    color: #c4b5fd;
}

.fibu-period-status-festgeschrieben {
    background: rgba(16, 185, 129, 0.18);
    color: #6ee7b7;
}

.fibu-period-metrics {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 12px;
}

.fibu-period-metrics span {
    color: var(--text-secondary);
    font-size: 0.76rem;
}

.fibu-period-metrics strong {
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.fibu-period-metrics .fibu-period-open,
.fibu-period-metrics .fibu-period-open strong {
    color: #fca5a5;
}

.fibu-shareholder-flow {
    display: grid;
    gap: 7px;
    min-width: 220px;
}

.fibu-shareholder-pair {
    display: flex;
    flex-wrap: wrap;
    gap: 5px 12px;
}

.fibu-shareholder-pair span,
.fibu-shareholder-net span {
    color: var(--text-secondary);
    font-size: 0.74rem;
}

.fibu-shareholder-pair strong,
.fibu-shareholder-net strong {
    display: block;
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

.fibu-shareholder-in strong,
.fibu-shareholder-net.is-positive strong {
    color: #6ee7b7;
}

.fibu-shareholder-out strong,
.fibu-shareholder-net.is-negative strong {
    color: #fca5a5;
}

.fibu-shareholder-net {
    align-items: baseline;
    border-bottom: 1px solid var(--border-color);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    gap: 4px 8px;
    padding: 6px 0;
}

.fibu-shareholder-detail {
    line-height: 1.45;
}

.fibu-shareholder-position {
    display: grid;
    gap: 2px;
    padding-top: 7px;
    border-top: 1px solid color-mix(in srgb, var(--border-color) 70%, transparent);
}

.fibu-shareholder-position > span,
.fibu-shareholder-position > small {
    color: var(--text-muted);
    font-size: 0.72rem;
}

.fibu-shareholder-position > strong {
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.76rem;
    font-variant-numeric: tabular-nums;
}

.fibu-shareholder-opening {
    color: var(--warning-color, #d7a84b);
    line-height: 1.45;
}

.fibu-gate-list {
    color: #fca5a5;
    font-size: 0.74rem;
    margin: 0;
    max-width: 46ch;
    padding-left: 1rem;
}

.fibu-gate-list li + li {
    margin-top: 3px;
}

.fibu-gate-ok {
    color: #6ee7b7;
    font-size: 0.76rem;
    font-weight: 700;
}

.fibu-action-blocked {
    color: var(--text-secondary);
    display: inline-block;
    font-size: 0.74rem;
    max-width: 20ch;
}

.fibu-review-workbench {
    border-top: 1px solid var(--border-color);
    margin-top: var(--space-xl);
    padding-top: var(--space-lg);
}

.fibu-period-tools {
    align-items: flex-end;
    display: flex;
    gap: var(--space-md);
}

.fibu-review-workbench[hidden] {
    display: none;
}

.fibu-review-head,
.fibu-review-filters {
    align-items: flex-end;
    display: flex;
    gap: var(--space-md);
    justify-content: space-between;
}

.fibu-review-head h3 {
    font-size: 1.05rem;
    margin: 0 0 var(--space-xs);
}

.fibu-review-head p {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin: 0;
}

.fibu-review-summary {
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm) var(--space-xl);
    margin: var(--space-lg) 0;
    padding: var(--space-md) 0;
}

.fibu-review-summary span {
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.fibu-review-summary strong {
    color: var(--text-primary);
    font-family: var(--font-mono);
    margin-right: 4px;
}

.fibu-review-filters {
    justify-content: flex-start;
    margin-bottom: var(--space-md);
}

.fibu-review-filters input,
.fibu-review-filters select {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    min-height: 38px;
    padding: 0 var(--space-md);
}

.fibu-review-filters input {
    min-width: 280px;
}

.fibu-review-table-wrap {
    max-height: 620px;
    overflow: auto;
}

.fibu-review-table {
    min-width: 1080px;
}

.fibu-review-table th {
    background: var(--bg-secondary);
    position: sticky;
    top: 0;
    z-index: 1;
}

.fibu-review-state {
    border-radius: 999px;
    display: inline-flex;
    font-size: 0.7rem;
    font-weight: 750;
    line-height: 1;
    padding: 7px 9px;
    white-space: nowrap;
}

.fibu-review-state-ready {
    background: rgba(16, 185, 129, 0.18);
    color: #6ee7b7;
}

.fibu-review-state-source {
    background: rgba(245, 158, 11, 0.18);
    color: #fcd34d;
}

.fibu-review-state-classification_confirmed {
    background: rgba(16, 185, 129, 0.18);
    color: #6ee7b7;
}

.fibu-review-state-source_required,
.fibu-review-state-deferred {
    background: rgba(245, 158, 11, 0.18);
    color: #fcd34d;
}

.fibu-review-state-excluded {
    background: rgba(148, 163, 184, 0.18);
    color: #cbd5e1;
}

.fibu-review-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 8px;
    min-width: 150px;
}

.fibu-review-note {
    margin-top: 6px;
    max-width: 32ch;
}

.fibu-money {
    font-family: var(--font-mono);
    text-align: right;
    white-space: nowrap;
}

.fibu-journal-table {
    min-width: 1520px;
}

.fibu-journal-table th:nth-child(2),
.fibu-journal-table td:nth-child(2) {
    min-width: 270px;
    width: 270px;
}

.fibu-journal-table th:nth-child(3),
.fibu-journal-table td:nth-child(3) {
    min-width: 250px;
    width: 250px;
}

.fibu-journal-table th:nth-child(5),
.fibu-journal-table td:nth-child(5),
.fibu-journal-table th:nth-child(6),
.fibu-journal-table td:nth-child(6),
.fibu-journal-table th:nth-child(7),
.fibu-journal-table td:nth-child(7) {
    min-width: 170px;
    width: 170px;
}

.fibu-journal-summary {
    align-items: center;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    display: flex;
    flex-wrap: wrap;
    gap: 10px 24px;
    margin-bottom: var(--space-md);
    padding: 12px 16px;
}

.fibu-journal-summary span {
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.fibu-journal-summary strong {
    color: var(--text-primary);
    font-family: var(--font-mono);
}

.fibu-journal-summary .is-warning { color: #fcd34d; }
.fibu-journal-summary .is-danger { color: #fca5a5; }

.fibu-journal-unassigned {
    color: #fca5a5;
    font-size: 0.76rem;
    width: 100%;
}

.fibu-journal-unassigned summary { cursor: pointer; font-weight: 700; }
.fibu-journal-unassigned div { border-left: 2px solid rgba(248, 113, 113, 0.45); margin-top: 8px; padding-left: 10px; }
.fibu-journal-unassigned p { color: var(--text-secondary); margin: 5px 0; }

.fibu-journal-business strong,
.fibu-journal-business small {
    display: block;
}

.fibu-journal-business strong {
    line-height: 1.45;
}

.fibu-journal-business small {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.62rem;
    margin-top: 5px;
    overflow-wrap: anywhere;
}

.fibu-booking-path summary {
    color: #c7d2fe;
    cursor: pointer;
    font-size: 0.76rem;
    font-weight: 700;
}

.fibu-booking-path > div {
    border-left: 2px solid rgba(129, 140, 248, 0.35);
    margin-top: 9px;
    padding-left: 10px;
}

.fibu-booking-path p {
    display: grid;
    font-size: 0.69rem;
    gap: 4px;
    grid-template-columns: 1fr auto 1fr;
    line-height: 1.35;
    margin: 0 0 9px;
}

.fibu-booking-path p > strong {
    color: var(--text-muted);
    font-family: var(--font-mono);
    font-size: 0.64rem;
    grid-column: 1 / -1;
}

.fibu-booking-path i { color: var(--text-muted); }

.fibu-loan-summary {
    align-items: stretch;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    margin-bottom: var(--space-xl);
}

.fibu-loan-summary > div {
    display: grid;
    gap: 5px;
    min-width: 170px;
    padding: 14px 20px;
}

.fibu-loan-summary > div + div { border-left: 1px solid var(--border-color); }
.fibu-loan-summary span { color: var(--text-secondary); font-size: 0.72rem; }
.fibu-loan-summary strong { font-family: var(--font-mono); font-size: 1rem; }
.fibu-loan-summary .is-positive, .fibu-money.is-positive { color: #6ee7b7; }
.fibu-loan-summary .is-negative, .fibu-money.is-negative { color: #fca5a5; }
.fibu-loan-summary .is-warning { color: #fcd34d; }

.fibu-loan-parties { margin-bottom: var(--space-xl); }
.fibu-loan-section-head { align-items: flex-end; display: flex; gap: var(--space-lg); justify-content: space-between; margin-bottom: var(--space-md); }
.fibu-loan-section-head h3 { font-size: 1rem; margin: 0 0 5px; }
.fibu-loan-section-head p { color: var(--text-secondary); font-size: 0.78rem; margin: 0; max-width: 72ch; }

.fibu-loan-filters { display: flex; flex-wrap: wrap; gap: 8px; }
.fibu-loan-filters input, .fibu-loan-filters select {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font: inherit;
    font-size: 0.78rem;
    min-height: 36px;
    padding: 6px 10px;
}
.fibu-loan-filters input { min-width: 230px; }
.fibu-loan-filters input:focus-visible, .fibu-loan-filters select:focus-visible { border-color: #818cf8; outline: 2px solid rgba(129, 140, 248, 0.32); outline-offset: 1px; }

.fibu-loan-party-table { min-width: 820px; }
.fibu-loan-table { min-width: 1500px; }
.fibu-loan-table th:nth-child(2), .fibu-loan-table td:nth-child(2) { min-width: 200px; }
.fibu-loan-table th:nth-child(5), .fibu-loan-table td:nth-child(5),
.fibu-loan-table th:nth-child(6), .fibu-loan-table td:nth-child(6),
.fibu-loan-table th:nth-child(7), .fibu-loan-table td:nth-child(7) { min-width: 170px; }

.fibu-loan-direction {
    border-radius: 999px;
    display: inline-flex;
    font-size: 0.7rem;
    font-weight: 750;
    padding: 6px 8px;
    white-space: nowrap;
}
.fibu-loan-einzahlung { background: rgba(16, 185, 129, 0.13); color: #6ee7b7; }
.fibu-loan-rueckzahlung { background: rgba(245, 158, 11, 0.13); color: #fcd34d; }
.fibu-loan-sonstige { background: rgba(148, 163, 184, 0.13); color: #cbd5e1; }

@media (max-width: 900px) {
    .fibu-loan-section-head { align-items: stretch; flex-direction: column; }
    .fibu-loan-filters input, .fibu-loan-filters select { flex: 1 1 100%; width: 100%; }
    .fibu-loan-summary > div { flex: 1 1 50%; }
}

.fibu-evidence-links {
    align-items: flex-start;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.fibu-evidence-links small {
    color: var(--text-muted);
    font-size: 0.68rem;
    line-height: 1.3;
}

.fibu-evidence-link {
    align-items: center;
    background: rgba(99, 102, 241, 0.12);
    border: 1px solid rgba(129, 140, 248, 0.42);
    border-radius: var(--radius-sm);
    color: #c7d2fe;
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-size: 0.76rem;
    font-weight: 650;
    gap: 7px;
    min-height: 32px;
    padding: 5px 9px;
    text-align: left;
    transition: background-color 160ms ease-out, border-color 160ms ease-out, color 160ms ease-out;
}

.fibu-evidence-link span {
    color: #818cf8;
    font-family: var(--font-mono);
    font-size: 0.62rem;
    font-weight: 700;
}

.fibu-evidence-link:hover {
    background: rgba(99, 102, 241, 0.2);
    border-color: #818cf8;
    color: #eef2ff;
}

.fibu-evidence-link:focus-visible {
    outline: 2px solid #a5b4fc;
    outline-offset: 2px;
}

.fibu-evidence-link:disabled {
    cursor: wait;
    opacity: 0.62;
}

.fibu-evidence-state {
    border-radius: var(--radius-sm);
    display: inline-flex;
    font-size: 0.72rem;
    font-weight: 700;
    line-height: 1.25;
    padding: 6px 8px;
}

.fibu-asset-head {
    align-items: flex-end;
    display: flex;
    gap: var(--space-lg);
    justify-content: space-between;
    margin-bottom: var(--space-md);
}
.fibu-asset-head h3 { margin: 0 0 6px; }
.fibu-asset-head p { color: var(--text-secondary); margin: 0; max-width: 72ch; }
.fibu-asset-filters { display: flex; flex-wrap: wrap; gap: 8px; }
.fibu-asset-filters input,
.fibu-asset-filters select {
    background: var(--surface-2, #181824);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    min-height: 38px;
    padding: 8px 10px;
}
.fibu-asset-filters input { min-width: 300px; }
.fibu-asset-warning {
    background: rgba(245, 158, 11, 0.09);
    border: 1px solid rgba(245, 158, 11, 0.34);
    border-radius: 10px;
    color: #fde68a;
    font-size: 0.8rem;
    line-height: 1.55;
    margin-bottom: var(--space-md);
    padding: 10px 13px;
}
.fibu-asset-table { min-width: 1450px; }
.fibu-asset-table th:nth-child(1) { min-width: 230px; }
.fibu-asset-table th:nth-child(5) { min-width: 270px; }
.fibu-asset-table th:nth-child(6) { min-width: 280px; }
.fibu-asset-review td:first-child { border-left: 3px solid #f59e0b; }
.fibu-asset-event { border-left: 2px solid rgba(129, 140, 248, 0.45); display: grid; gap: 2px; margin: 5px 0; padding-left: 9px; }
.fibu-asset-event span,
.fibu-asset-event small { color: var(--text-secondary); font-size: 0.72rem; }
.fibu-asset-event-pruefung,
.fibu-asset-event-offen { border-left-color: #f59e0b; }
.fibu-asset-evidence-missing { color: #fca5a5; font-size: 0.74rem; line-height: 1.45; margin: 4px 0; }
@media (max-width: 920px) {
    .fibu-asset-head { align-items: stretch; flex-direction: column; }
    .fibu-asset-filters input, .fibu-asset-filters select { flex: 1 1 100%; min-width: 0; width: 100%; }
}

.fibu-evidence-unresolved {
    background: rgba(245, 158, 11, 0.14);
    color: #fcd34d;
}

.fibu-evidence-missing {
    background: rgba(239, 68, 68, 0.13);
    color: #fca5a5;
}

.fibu-evidence-neutral {
    background: rgba(148, 163, 184, 0.1);
    color: var(--text-muted);
}

.fibu-evidence-complete {
    background: rgba(16, 185, 129, 0.12);
    color: #6ee7b7;
}

.fibu-open-requests {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.fibu-open-requests > div {
    border-left: 3px solid currentColor;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    display: grid;
    gap: 3px;
    padding: 7px 9px;
}

.fibu-open-requests .is-warning {
    background: rgba(245, 158, 11, 0.1);
    color: #fcd34d;
}

.fibu-open-requests .is-danger {
    background: rgba(239, 68, 68, 0.1);
    color: #fca5a5;
}

.fibu-open-requests span {
    font-family: var(--font-mono);
    font-size: 0.58rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.fibu-open-requests strong { font-size: 0.72rem; }
.fibu-open-requests small { color: var(--text-secondary); font-size: 0.66rem; }

@media (prefers-reduced-motion: reduce) {
    .fibu-evidence-link {
        transition: none;
    }
}

.fibu-audit-toolbar {
    display: flex;
    justify-content: space-between;
    gap: var(--space-lg);
    align-items: flex-end;
    margin-bottom: var(--space-lg);
}

.fibu-audit-toolbar h3 {
    margin: 0 0 var(--space-xs);
    font-size: 1.05rem;
}

.fibu-audit-toolbar p {
    margin: 0;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.fibu-audit-filters {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    justify-content: flex-end;
}

.fibu-audit-filters input,
.fibu-audit-filters select {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    min-height: 38px;
    padding: 0 var(--space-md);
}

.fibu-audit-filters input {
    min-width: 280px;
}

.fibu-audit-guide {
    align-items: center;
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm) var(--space-lg);
    margin-bottom: var(--space-lg);
    padding: var(--space-md);
}

.fibu-audit-guide span {
    color: var(--text-secondary);
    font-size: 0.84rem;
}

.fibu-audit-guide strong {
    color: var(--text-primary);
}

.fibu-audit-guide .guide-danger {
    color: #f87171;
}

.fibu-audit-guide .guide-warning {
    color: #fbbf24;
}

.fibu-audit-summary {
    margin-bottom: var(--space-lg);
}

.fibu-audit-summary.dashboard-grid {
    grid-template-columns: repeat(4, minmax(150px, 1fr));
}

.fibu-audit-stat {
    border-radius: var(--radius-md);
    min-height: 92px;
}

.fibu-audit-stat-danger {
    border-color: rgba(239, 68, 68, 0.45);
}

.fibu-audit-stat-danger .stat-value {
    color: #f87171;
}

.fibu-audit-stat-warning {
    border-color: rgba(245, 158, 11, 0.45);
}

.fibu-audit-stat-warning .stat-value {
    color: #fbbf24;
}

.fibu-audit-table-wrap {
    max-width: 100%;
    overflow-x: auto;
    scrollbar-color: rgba(99, 102, 241, 0.8) rgba(255, 255, 255, 0.05);
}

.fibu-audit-table {
    min-width: 1040px;
}

.fibu-audit-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.fibu-audit-table th,
.fibu-audit-table td {
    padding-left: 14px;
    padding-right: 14px;
}

.fibu-audit-table th:nth-child(1),
.fibu-audit-table td:nth-child(1) {
    width: 72px;
}

.fibu-audit-table th:nth-child(2),
.fibu-audit-table td:nth-child(2) {
    width: 118px;
}

.fibu-audit-table th:nth-child(3),
.fibu-audit-table td:nth-child(3) {
    min-width: 170px;
}

.fibu-audit-table th:nth-child(4),
.fibu-audit-table td:nth-child(4),
.fibu-audit-table th:nth-child(5),
.fibu-audit-table td:nth-child(5),
.fibu-audit-table th:nth-child(6),
.fibu-audit-table td:nth-child(6) {
    width: 150px;
}

.fibu-audit-table th:nth-child(7),
.fibu-audit-table td:nth-child(7) {
    min-width: 190px;
}

.fibu-dup-table {
    min-width: 980px;
    table-layout: fixed;
    width: 100%;
}

#fibu-tab-duplikate2022 .fibu-audit-summary.dashboard-grid {
    grid-template-columns: repeat(4, minmax(180px, 1fr));
    width: 100%;
}

#fibu-tab-duplikate2022 .fibu-audit-table-wrap {
    width: 100%;
}

.fibu-dup-table th,
.fibu-dup-table td {
    overflow-wrap: anywhere;
    vertical-align: top;
}

.fibu-dup-table th:nth-child(1),
.fibu-dup-table td:nth-child(1) {
    width: 118px;
}

.fibu-dup-table th:nth-child(2),
.fibu-dup-table td:nth-child(2),
.fibu-dup-table th:nth-child(3),
.fibu-dup-table td:nth-child(3) {
    width: 190px;
}

.fibu-dup-table th:nth-child(4),
.fibu-dup-table td:nth-child(4) {
    width: 210px;
}

.fibu-dup-table th:nth-child(5),
.fibu-dup-table td:nth-child(5) {
    width: 120px;
}

.dup-visual-list {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

.dup-visual-chip {
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    display: inline-flex;
    font-size: 0.68rem;
    font-weight: 700;
    line-height: 1.2;
    padding: 4px 6px;
    text-decoration: none;
}

.dup-visual-ok {
    background: rgba(16, 185, 129, 0.14);
    border-color: rgba(16, 185, 129, 0.35);
    color: #34d399;
}

.dup-visual-warnung {
    background: rgba(245, 158, 11, 0.16);
    border-color: rgba(245, 158, 11, 0.38);
    color: #fbbf24;
}

.dup-visual-fehlt {
    background: rgba(239, 68, 68, 0.16);
    border-color: rgba(239, 68, 68, 0.38);
    color: #f87171;
}

.fibu-audit-row-fehlt td {
    background: rgba(127, 29, 29, 0.16);
}

.fibu-audit-row-warnung td {
    background: rgba(120, 53, 15, 0.14);
}

.audit-pill {
    align-items: center;
    border-radius: 999px;
    display: inline-flex;
    font-size: 0.72rem;
    font-weight: 800;
    height: 28px;
    justify-content: center;
    min-width: 28px;
    padding: 0 9px;
}

.audit-pill-ok {
    background: rgba(16, 185, 129, 0.18);
    color: #34d399;
}

.audit-pill-warnung {
    background: rgba(245, 158, 11, 0.2);
    color: #fbbf24;
}

.audit-pill-fehlt {
    background: rgba(239, 68, 68, 0.22);
    color: #f87171;
}

.audit-evidence {
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    display: grid;
    gap: 2px;
    min-width: 130px;
    padding: 8px 10px;
}

.audit-evidence span {
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.04em;
}

.audit-evidence-ok {
    background: rgba(16, 185, 129, 0.1);
    border-color: rgba(16, 185, 129, 0.35);
}

.audit-evidence-ok span {
    color: #34d399;
}

.audit-evidence-missing {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.42);
}

.audit-evidence-missing span {
    color: #f87171;
}

.audit-issues {
    margin: 0;
    padding-left: 1rem;
}

.audit-issues li {
    margin: 0 0 4px;
}

.fibu-audit-cards {
    display: none;
}

.fibu-audit-card,
.audit-empty-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: var(--space-md);
}

.fibu-audit-card-fehlt {
    background: rgba(127, 29, 29, 0.18);
    border-color: rgba(239, 68, 68, 0.38);
}

.fibu-audit-card-warnung {
    background: rgba(120, 53, 15, 0.16);
    border-color: rgba(245, 158, 11, 0.4);
}

.audit-card-head {
    align-items: flex-start;
    display: flex;
    gap: var(--space-md);
    justify-content: space-between;
}

.audit-card-head strong {
    display: block;
    font-size: 0.98rem;
}

.audit-card-head span,
.audit-card-customer {
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.audit-card-customer {
    margin-top: var(--space-xs);
}

.audit-card-chain {
    display: grid;
    gap: var(--space-sm);
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: var(--space-md);
}

.audit-card-issues {
    margin-top: var(--space-md);
}

.muted-small {
    color: var(--text-muted);
    font-size: 0.76rem;
}

.main-wrapper:has(#fibu-studio-view.active) .ellie-widget {
    display: none;
}

.main-wrapper:has(#fibu-studio-view.active) .main-content {
    margin: 0;
    max-width: none;
    width: 100%;
}

#fibu-studio-view.active {
    width: 100%;
}

@media (max-width: 900px) {
    .fibu-period-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .fibu-period-year {
        max-width: 220px;
    }

    .fibu-period-summary > div {
        flex: 1 1 45%;
    }

    .fibu-period-summary > div:nth-child(3) {
        border-left: 0;
    }

    .fibu-audit-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .fibu-review-head,
    .fibu-review-filters {
        align-items: stretch;
        flex-direction: column;
    }

    .fibu-review-filters input,
    .fibu-review-filters select {
        min-width: 0;
        width: 100%;
    }

    .fibu-audit-filters {
        justify-content: flex-start;
    }

    .fibu-audit-filters input,
    .fibu-audit-filters select {
        flex: 1 1 180px;
    }

    .fibu-audit-summary.dashboard-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 640px) {
    #fibu-studio-view .view-header > div:first-child {
        flex-wrap: wrap;
        gap: var(--space-md);
    }

    #fibu-studio-view .view-header > div:first-child .button-group,
    #fibu-studio-view .view-header > div:first-child .button-group .btn {
        width: 100%;
    }

    .fibu-period-tools {
        align-items: stretch;
        flex-direction: column;
    }

    .fibu-period-year {
        max-width: none;
        width: 100%;
    }

    .fibu-period-summary {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .fibu-period-summary > div {
        min-width: 0;
        padding: var(--space-md);
    }

    .fibu-period-summary > div:nth-child(3) {
        border-left: 0;
    }

    .fibu-period-summary > div:nth-child(n + 3) {
        border-top: 1px solid var(--border-color);
    }

    .fibu-audit-toolbar {
        margin-bottom: var(--space-md);
    }

    .fibu-audit-toolbar h3 {
        font-size: 0.98rem;
    }

    .fibu-audit-guide {
        align-items: flex-start;
        flex-direction: column;
        gap: var(--space-xs);
    }

    .fibu-audit-filters input,
    .fibu-audit-filters select {
        min-width: 0;
        width: 100%;
    }

    .fibu-audit-summary.dashboard-grid {
        gap: var(--space-sm);
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .fibu-audit-stat {
        min-height: 76px;
        padding: var(--space-md);
    }

    .fibu-audit-stat .stat-value {
        font-size: 1.35rem;
    }

    .fibu-audit-table-wrap {
        display: none;
    }

    .fibu-audit-cards {
        display: grid;
        gap: var(--space-md);
    }

    .audit-card-chain {
        grid-template-columns: 1fr;
    }

    .audit-evidence {
        min-width: 0;
    }
}

/* =============================================================================
   Project Budget Progress Bar
============================================================================= */

.project-title {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    flex: 1;
    cursor: pointer;
}

.project-actions {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.project-budget {
    padding: var(--space-sm) var(--space-md);
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    gap: var(--space-md);
    flex-wrap: wrap;
}

.budget-bar {
    flex: 1;
    min-width: 150px;
    height: 8px;
    background: var(--bg-card);
    border-radius: 4px;
    overflow: hidden;
}

.budget-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.budget-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.budget-remaining {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--accent-success);
}

.budget-remaining:has(⚠️) {
    color: var(--accent-warning);
}

/* Warning status for upload duplicate detection */
.upload-status.warning {
    color: var(--accent-warning);
    background: rgba(245, 158, 11, 0.1);
    padding: var(--space-sm) var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid rgba(245, 158, 11, 0.3);
}

/* =============================================================================
   Review Studio
============================================================================= */

/* --- Experimental: Remove padding/max-width when Review Studio is active --- */
.main-wrapper:has(#review-studio-view.active) .main-content {
    padding: 0;
    max-width: none;
    margin: 0;
    overflow: hidden;
    /* Prevent double scrollbars in Review Studio */
}

#review-studio-view {
    height: calc(100vh - var(--topbar-height));
    overflow: hidden;
    padding: 0;
    max-width: 100%;
}

.review-studio-container {
    display: flex;
    height: 100%;
    gap: 0;
}

.review-sidebar {
    width: 320px;
    flex-shrink: 0;
    border-right: 1px solid var(--border-color);
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
}

.review-sidebar-header {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.review-list {
    flex: 1;
    overflow-y: auto;
}

.review-mail-import-panel {
    border-top: 1px solid var(--border-color);
    margin-top: var(--space-sm);
    min-height: 0;
    padding-top: var(--space-sm);
}

.review-mail-header {
    border-bottom: 0;
    padding-bottom: var(--space-sm);
    padding-top: 0;
}

.review-mail-summary {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.35rem;
    padding: 0 var(--space-md) var(--space-sm);
}

.review-mail-chip {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 0.76rem;
    font-weight: 700;
    line-height: 1;
    padding: 0.45rem 0.25rem;
    text-align: center;
}

.review-mail-chip.danger {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.35);
    color: #f87171;
}

.review-mail-chip.warning {
    background: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.35);
    color: #fbbf24;
}

.review-mail-chip.ok {
    background: rgba(16, 185, 129, 0.12);
    border-color: rgba(16, 185, 129, 0.35);
    color: #34d399;
}

.review-mail-chip.muted {
    color: var(--text-muted);
}

.review-mail-list {
    flex: 0 1 auto;
    max-height: 38vh;
    padding: 0 var(--space-md) var(--space-md);
}

.review-mail-item {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    margin-bottom: 0.45rem;
    padding: 0.55rem;
}

.review-mail-item-top {
    align-items: center;
    display: flex;
    gap: 0.5rem;
    justify-content: space-between;
    margin-bottom: 0.35rem;
}

.review-mail-status {
    border-radius: 999px;
    font-size: 0.66rem;
    font-weight: 700;
    padding: 0.12rem 0.42rem;
    text-transform: uppercase;
}

.review-mail-status.danger {
    background: rgba(239, 68, 68, 0.16);
    color: #f87171;
}

.review-mail-status.warning {
    background: rgba(245, 158, 11, 0.16);
    color: #fbbf24;
}

.review-mail-date {
    color: var(--text-muted);
    font-size: 0.68rem;
    white-space: nowrap;
}

.review-mail-file {
    color: var(--text-color);
    font-size: 0.78rem;
    font-weight: 700;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.review-mail-meta {
    color: var(--text-muted);
    font-size: 0.72rem;
    line-height: 1.25;
    margin-top: 0.18rem;
    overflow-wrap: anywhere;
}

.review-empty-note {
    color: var(--text-muted);
    font-size: 0.82rem;
    padding: var(--space-md);
    text-align: center;
}

.review-item {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: all var(--transition-fast);
}

.review-item:hover {
    background: var(--bg-card);
}

.review-item.active {
    background: var(--bg-card-hover);
    border-left: 3px solid var(--accent-primary);
}

.review-main {
    flex: 1;
    background: #1e1e26;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border-color);
}

.pdf-viewer-container {
    flex: 1;
    position: relative;
    background: #000;
}

#review-pdf-viewer {
    width: 100%;
    height: 100%;
    border: none;
}

.pdf-placeholder {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-muted);
}

.review-actions {
    width: 450px;
    flex-shrink: 0;
    background: var(--bg-card);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

.review-actions-header {
    padding: var(--space-md);
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 10;
}

.review-form {
    padding: var(--space-md);
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.review-form[hidden],
.review-selection-status[hidden] {
    display: none;
}

.review-selection-status,
.review-correction-note {
    margin: 0;
    padding: 0.7rem var(--space-md);
    color: var(--text-secondary);
    font-size: 0.82rem;
}

.review-correction-note {
    border-bottom: 1px solid var(--border-color);
}

.review-item:focus-visible {
    outline: 2px solid var(--accent-primary);
    outline-offset: -2px;
}

#btn-approve-review:disabled {
    opacity: 0.45;
    cursor: not-allowed;
    filter: grayscale(0.4);
}

.invoice-duplicate-note, .invoice-offset-note {
    align-self: center;
    color: var(--text-secondary);
    font-size: 0.82rem;
}

.review-history {
    padding: var(--space-md);
    border-top: 1px solid var(--border-color);
}

.review-history h4 {
    margin-bottom: var(--space-sm);
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.review-history-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
    max-height: 400px;
    overflow-y: auto;
    padding-right: 4px;
}

.history-item {
    padding: var(--space-sm);
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    display: flex;
    justify-content: space-between;
}

.badge {
    background: var(--accent-primary);
    color: white;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 700;
}

/* Toggle Switch Wrapper */
.toggle-switch {
    position: relative;
    display: inline-block;
    width: 36px;
    height: 20px;
}

/* Hide default HTML checkbox */
.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

/* The slider */
.slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .3s;
    border: 1px solid var(--border-color);
}

.slider:before {
    position: absolute;
    content: "";
    height: 14px;
    width: 14px;
    left: 2px;
    bottom: 2px;
    background-color: white;
    transition: .3s;
}

input:checked+.slider {
    background-color: var(--accent-success);
    border-color: var(--accent-success);
    box-shadow: 0 0 10px rgba(16, 185, 129, 0.4);
}

input:focus+.slider {
    box-shadow: 0 0 1px var(--accent-success);
}

input:checked+.slider:before {
    transform: translateX(16px);
}

/* Rounded sliders */
.slider.round {
    border-radius: 20px;
}

.slider.round:before {
    border-radius: 50%;
}

/* =============================================================================
   GAEB Studio — Phase Tabs
============================================================================= */

.gaeb-phase-tab {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 10px 16px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    color: var(--text-muted);
    font-size: 0.82rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition-normal);
    white-space: nowrap;
    position: relative;
    bottom: -2px;
}

.gaeb-phase-tab:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.03);
}

.gaeb-phase-tab.active {
    color: var(--text-primary);
    border-bottom-color: var(--accent-primary);
    font-weight: 600;
}

.gaeb-phase-tab .phase-icon {
    font-size: 1em;
}

.gaeb-phase-tab .phase-label {
    font-size: inherit;
}

.gaeb-phase-panel {
    display: none;
    animation: fadeIn 0.25s ease;
}

.gaeb-phase-panel.active {
    display: block;
}

/* Phase tab bar scrolling on small screens */
#gaeb-phase-tabs {
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

#gaeb-phase-tabs::-webkit-scrollbar {
    height: 4px;
}

#gaeb-phase-tabs::-webkit-scrollbar-track {
    background: transparent;
}

#gaeb-phase-tabs::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

/* =============================================================================
   GAEB Studio — Offer workflow
============================================================================= */

.gaeb-offer-workspace {
    margin-top: 0;
    border-top-left-radius: 0;
    border-top-right-radius: 0;
}

/* GAEB actions and fields remain legible and keyboard-visible at narrow widths. */
/* Keyboard focus must be visible immediately, including above the bottom nav. */
html:has(#gaeb-view.active, #gaeb-langtext-modal.active, #manual-position-overlay, #aufmass-studio-modal.active) {
    scroll-behavior: auto;
    scroll-padding-block: 5rem;
}
:is(#gaeb-view, #gaeb-langtext-modal, #manual-position-overlay, #aufmass-studio-modal) {
    --text-muted: var(--text-secondary);
}
:is(#gaeb-view, #gaeb-langtext-modal, #manual-position-overlay, #aufmass-studio-modal) .btn {
    min-height: 44px;
    max-width: 100%;
    padding: 0.55rem 0.75rem;
    justify-content: center;
    white-space: normal;
    overflow-wrap: anywhere;
    line-height: 1.35;
    border: 1px solid var(--text-secondary);
    transition: background-color 0.15s ease, border-color 0.15s ease;
}
:is(#gaeb-view, #gaeb-langtext-modal, #manual-position-overlay, #aufmass-studio-modal) .btn-secondary {
    color: var(--text-primary);
    background: var(--bg-secondary);
}
:is(#gaeb-view, #gaeb-langtext-modal, #manual-position-overlay, #aufmass-studio-modal) .btn-primary {
    color: #fff;
    background: #4f46e5;
    box-shadow: none;
}
:is(#gaeb-view, #gaeb-langtext-modal, #manual-position-overlay, #aufmass-studio-modal) .btn-primary:hover {
    background: #4338ca;
    transform: none;
    box-shadow: none;
}
:is(#gaeb-view, #gaeb-langtext-modal, #manual-position-overlay, #aufmass-studio-modal) .btn:disabled {
    color: var(--text-secondary);
    background: var(--bg-secondary);
    opacity: 1;
    filter: none;
    cursor: not-allowed;
    border-style: dashed;
}
:is(#gaeb-view, #gaeb-langtext-modal, #manual-position-overlay, #aufmass-studio-modal) :is(button, input, select, textarea, summary, [tabindex]):focus-visible {
    outline: 3px solid var(--accent-primary-hover);
    outline-offset: 3px;
}
:is(#gaeb-view, #gaeb-langtext-modal, #manual-position-overlay, #aufmass-studio-modal) :is(button, input, select, textarea, summary, [tabindex]) {
    scroll-margin-block: 5rem;
    scroll-margin-inline: 0.5rem;
}
:is(#gaeb-view, #gaeb-langtext-modal, #manual-position-overlay, #aufmass-studio-modal) :is(input:not([type=checkbox]):not([type=radio]), select, textarea) {
    min-width: 0;
    max-width: 100%;
    min-height: 44px;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--text-secondary);
}
:is(#gaeb-view, #gaeb-langtext-modal, #manual-position-overlay, #aufmass-studio-modal) input::placeholder,
:is(#gaeb-view, #gaeb-langtext-modal, #manual-position-overlay, #aufmass-studio-modal) textarea::placeholder {
    color: var(--text-secondary);
    opacity: 1;
}
#gaeb-view :is(input[type=checkbox], input[type=radio]),
#manual-position-overlay input[type=checkbox] { accent-color: #4f46e5; }
#gaeb-view #gaeb-phase-tabs {
    padding: 7px;
    scroll-padding-inline: 7px;
}
#gaeb-view .gaeb-phase-tab {
    bottom: 0;
    min-height: 44px;
    transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}
#gaeb-list-container { max-width: 100%; overflow-x: auto; }
#gaeb-source-profile,
#gaeb-detail-title { overflow-wrap: anywhere; }
#gaeb-detail-container .gaeb-detail-heading > div { min-width: 0; }
#manual-position-overlay .modal-mini-header { gap: 0.75rem; }
#manual-position-overlay .modal-mini-header h3 { min-width: 0; overflow-wrap: anywhere; }
#manual-position-overlay .btn-close,
#gaeb-langtext-modal .modal-close,
#aufmass-studio-modal .modal-close { flex-shrink: 0; min-width: 44px; min-height: 44px; }
#aufmass-studio-modal .modal-content { scroll-padding-block: 6rem 1rem; }
#aufmass-position-list > div { flex-wrap: wrap; }
#aufmass-position-list > div > div { min-width: 0; max-width: 100%; }
#aufmass-current-az { min-width: 0 !important; width: 100%; }
#aufmass-studio-modal .aufmass-positions-scroll { max-width: 100%; overflow-x: auto; padding: 7px; scroll-padding-inline: 7px; }
#aufmass-studio-modal .gaeb-table { min-width: 960px; }
#aufmass-studio-modal .gaeb-table .btn { flex-shrink: 0; min-width: 44px; white-space: nowrap; overflow-wrap: normal; }
#gaeb-langtext-modal #gaeb-langtext-body { min-height: min(350px, max(88px, calc(85vh - 16rem))) !important; }
#manual-position-overlay .modal-mini-footer { flex-wrap: wrap; }
#manual-position-overlay .modal-mini-footer > div { min-width: 0; max-width: 100%; }
@media (max-width: 620px) {
    #gaeb-view #gaeb-detail-container .gaeb-positions-table { font-size: 0.9rem; }
    #gaeb-detail-container .gaeb-price-fields :is(input, select) { font-size: 1rem; }
    #gaeb-view .gaeb-positions-scroll { scroll-padding-inline: 0.5rem; }
    #manual-position-overlay .modal-mini-card { border-radius: var(--radius-sm); }
    #manual-position-overlay .manual-position-fields { grid-template-columns: minmax(0, 1fr) !important; }
    #manual-position-overlay :is(input, select, textarea) { font-size: 1rem; }
    #manual-position-overlay .modal-mini-footer > div:last-child { flex: 1 1 100%; }
    #manual-position-overlay .modal-mini-footer > div:last-child .btn { flex: 1 1 100%; }
    #gaeb-langtext-modal .modal-content { width: 100%; }
    #gaeb-langtext-modal .modal-body { padding: 0.75rem !important; }
    #gaeb-langtext-modal .form-actions { flex-wrap: wrap; padding: 0.75rem !important; }
}
@media (prefers-reduced-motion: reduce) {
    :is(#gaeb-view, #gaeb-langtext-modal, #manual-position-overlay, #aufmass-studio-modal) .btn,
    #gaeb-view .gaeb-phase-tab { transition: none; }
    #manual-position-overlay,
    #manual-position-overlay .modal-mini-card { animation: none; }
}

/* GAEB detail, canonical readiness and inline price review. */
#gaeb-detail-container .gaeb-detail-heading,
#gaeb-detail-container .gaeb-detail-actions,
#gaeb-detail-container .gaeb-x84-status-heading {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: var(--space-sm);
}
#gaeb-detail-container .gaeb-detail-heading { justify-content: space-between; margin-bottom: var(--space-md); }
#gaeb-detail-container .gaeb-x84-status,
#gaeb-detail-container .gaeb-return-workspace,
#gaeb-detail-container .gaeb-draft-recovery {
    padding: var(--space-md);
    margin-bottom: var(--space-md);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-secondary);
    color: var(--text-secondary);
    overflow-wrap: anywhere;
}
#gaeb-detail-container .gaeb-x84-status p,
#gaeb-detail-container .gaeb-return-workspace p { margin: var(--space-sm) 0; max-width: 70ch; }
#gaeb-detail-container .gaeb-workflow-inventory { margin-bottom: var(--space-md); color: var(--text-secondary); }
#gaeb-detail-container .gaeb-workflow-inventory summary { padding: var(--space-sm) 0; color: var(--text-primary); cursor: pointer; font-weight: 600; }
#gaeb-detail-container .gaeb-x84-status-heading strong { color: var(--text-primary); margin-right: auto; }
#gaeb-detail-container .gaeb-return-basis-choice { display: flex; align-items: flex-start; gap: var(--space-sm); margin: var(--space-md) 0; }
#gaeb-detail-container .gaeb-return-file-label { display: block; margin-bottom: var(--space-xs); }
#gaeb-detail-container #gaeb-return-file { max-width: 100%; margin-bottom: var(--space-md); }
#gaeb-detail-container #gaeb-return-feedback { margin: var(--space-md) 0; white-space: pre-wrap; }
#gaeb-detail-container .gaeb-positions-scroll { max-width: 100%; overflow-x: auto; overscroll-behavior-inline: contain; padding: 7px; scroll-padding-inline: 0.5rem; }
#gaeb-detail-container .gaeb-positions-table { font-size: 0.82rem; min-width: 660px; }
#gaeb-detail-container .gaeb-positions-table th:first-child { width: 90px; }
#gaeb-detail-container .gaeb-positions-table th:nth-child(2) { min-width: 260px; }
#gaeb-detail-container .gaeb-number { text-align: right; font-variant-numeric: tabular-nums; }
#gaeb-detail-container .gaeb-position-title { font-weight: 600; color: var(--text-primary); }
#gaeb-detail-container .gaeb-position-text { color: var(--text-secondary); max-height: 3em; overflow: hidden; margin: 4px 0; }
#gaeb-detail-container .gaeb-price-editor { margin-top: var(--space-sm); }
#gaeb-detail-container .gaeb-price-editor summary { cursor: pointer; color: var(--text-primary); padding: 6px 0; font-weight: 600; }
#gaeb-detail-container .gaeb-price-fields { display: flex; flex-wrap: wrap; gap: var(--space-sm); padding: var(--space-sm) 0; }
#gaeb-detail-container .gaeb-price-fields label { display: flex; flex-direction: column; gap: 4px; font-size: 0.78rem; color: var(--text-secondary); }
#gaeb-detail-container .gaeb-price-fields input,
#gaeb-detail-container .gaeb-price-fields select { width: 150px; max-width: 100%; padding: 7px; color: var(--text-primary); background: var(--bg-primary); border: 1px solid var(--text-secondary); border-radius: 4px; }
#gaeb-detail-container .gaeb-price-fields input { text-align: right; }
#gaeb-detail-container .gaeb-price-fields input::placeholder { color: var(--text-secondary); }
#gaeb-detail-container .gaeb-price-origin,
#gaeb-detail-container .gaeb-price-feedback { display: block; margin-top: 6px; max-width: 65ch; color: var(--text-secondary); white-space: normal; }
#gaeb-detail-container :is(button,input,select,summary,.gaeb-positions-scroll):focus-visible { outline: 3px solid var(--accent-primary-hover); outline-offset: 3px; }
#gaeb-detail-container [hidden] { display: none !important; }
@media (max-width: 620px) {
    #gaeb-detail-container .gaeb-detail-heading { align-items: flex-start; }
    #gaeb-detail-container .gaeb-detail-heading > div { max-width: 100%; flex-wrap: wrap; }
    #gaeb-detail-container .gaeb-x84-status-heading > strong { flex-basis: 100%; }
    #gaeb-detail-container .gaeb-price-fields label { flex: 1 1 140px; }
}

.gaeb-offer-heading,
.gaeb-offer-section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: var(--space-lg);
}

.gaeb-offer-heading {
    padding-bottom: var(--space-lg);
    border-bottom: 1px solid var(--border-color);
}

.gaeb-offer-heading h4,
.gaeb-offer-section-heading h5 {
    margin: 0;
    color: var(--text-primary);
}

.gaeb-offer-heading h4 {
    font-size: 1.05rem;
}

.gaeb-offer-section-heading h5 {
    font-size: 0.9rem;
}

.gaeb-offer-heading p,
.gaeb-offer-section-heading p {
    margin: var(--space-xs) 0 0;
    color: var(--text-muted);
    font-size: 0.8rem;
    line-height: 1.5;
    max-width: 70ch;
}

.gaeb-offer-loading {
    padding: var(--space-xl) 0;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.gaeb-offer-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 1px;
    margin: var(--space-lg) 0 0;
    overflow: hidden;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--border-color);
}

.gaeb-offer-summary > div {
    flex: 1 1 150px;
    min-width: 0;
    padding: var(--space-md);
    background: var(--bg-secondary);
}

.gaeb-offer-summary span {
    display: block;
    margin-bottom: var(--space-xs);
    color: var(--text-muted);
    font-size: 0.7rem;
}

.gaeb-offer-summary strong {
    display: block;
    color: var(--text-primary);
    font-size: 0.88rem;
    overflow-wrap: anywhere;
}

.gaeb-offer-section {
    padding: var(--space-lg) 0;
    border-bottom: 1px solid var(--border-color);
}

.gaeb-readiness-badge {
    flex-shrink: 0;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 600;
}

.gaeb-readiness-badge.is-ready {
    color: var(--badge-success-text);
    background: var(--badge-success-bg);
}

.gaeb-readiness-badge.is-blocked {
    color: var(--badge-danger-text);
    background: var(--badge-danger-bg);
}

.gaeb-offer-issues {
    display: grid;
    gap: var(--space-sm);
    margin-top: var(--space-md);
}

.gaeb-offer-issue {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    line-height: 1.45;
}

.gaeb-offer-issue.is-blocker {
    color: var(--badge-danger-text);
    background: var(--badge-danger-bg);
}

.gaeb-offer-issue.is-warning {
    color: var(--badge-warning-text);
    background: var(--badge-warning-bg);
}

.gaeb-offer-issue.is-success {
    color: var(--badge-success-text);
    background: var(--badge-success-bg);
}

.gaeb-offer-actions {
    display: flex;
    flex-wrap: wrap;
    gap: var(--space-sm);
    margin-top: var(--space-md);
}

#gaeb-offer-finalize-btn:disabled {
    cursor: not-allowed;
    filter: saturate(0.55);
    opacity: 0.68;
}

.gaeb-send-form {
    display: grid;
    grid-template-columns: minmax(130px, 0.7fr) minmax(220px, 1.3fr) minmax(220px, 1.4fr) auto;
    gap: var(--space-sm);
    align-items: end;
    margin-top: var(--space-md);
}

.gaeb-send-form label {
    display: grid;
    gap: 5px;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
}

.gaeb-send-form input,
.gaeb-send-form select {
    min-height: 38px;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 7px 9px;
}

.gaeb-send-form input:focus,
.gaeb-send-form select:focus {
    border-color: var(--accent-primary);
    outline: 2px solid color-mix(in srgb, var(--accent-primary) 28%, transparent);
    outline-offset: 1px;
}

.gaeb-offer-history {
    margin-top: var(--space-md);
}

.gaeb-offer-history-empty {
    padding: var(--space-lg);
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
    background: var(--bg-secondary);
    border-radius: var(--radius-sm);
}

.filter-summary[data-state="error"] {
    color: var(--accent-danger);
}

.invoice-list-state {
    color: var(--text-secondary);
    padding: var(--space-lg);
    text-align: center;
}

.invoice-list-state .btn {
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    margin-left: var(--space-md);
}

.gaeb-offer-history-row {
    display: grid;
    grid-template-columns: minmax(130px, 0.8fr) minmax(120px, 0.7fr) minmax(200px, 1.5fr);
    gap: var(--space-md);
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-secondary);
    font-size: 0.78rem;
}

.gaeb-offer-history-row:last-child {
    border-bottom: 0;
}

.gaeb-offer-history-row time {
    color: var(--text-muted);
}

.gaeb-offer-utilities {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: var(--space-sm);
    padding-top: var(--space-lg);
}

.gaeb-offer-utilities > span {
    margin-right: auto;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
}

@media (max-width: 920px) {
    .gaeb-send-form {
        grid-template-columns: 1fr 1fr;
    }

    .gaeb-send-note {
        grid-column: 1 / -1;
    }
}

@media (max-width: 620px) {
    .gaeb-offer-heading,
    .gaeb-offer-section-heading {
        align-items: stretch;
        flex-direction: column;
        gap: var(--space-sm);
    }

    .gaeb-readiness-badge {
        align-self: flex-start;
    }

    .gaeb-send-form {
        grid-template-columns: 1fr;
    }

    .gaeb-send-note {
        grid-column: auto;
    }

    .gaeb-offer-history-row {
        grid-template-columns: 1fr;
        gap: 3px;
    }
}

@media (prefers-reduced-motion: reduce) {
    .gaeb-phase-panel {
        animation: none;
    }
}
/* Retry is actionable only after an unconfirmed upload. Button display rules
   must not override its native hidden state. */
#upload-retry[hidden] {
    display: none;
}

/* Keep the advisor session controls inside narrow and magnified topbars. */
@media (max-width: 900px) {
    body.advisor-session .topbar { min-width: 0; }
    body.advisor-session #user-badge { box-sizing: border-box; min-width: 0; max-width: 100%; }
    body.advisor-session #user-badge > div:nth-child(2) { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    body.advisor-session #user-badge > div:first-child,
    body.advisor-session #user-badge > button { flex-shrink: 0; }
}

.erp-notification {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 3000;
    display: flex;
    align-items: flex-start;
    gap: .75rem;
    width: max-content;
    max-width: min(28rem, calc(100vw - 2rem));
    padding: .8rem 1rem;
    color: #f4f4fa;
    background: #20202c;
    border: 1px solid #66667b;
    border-radius: 8px;
    overflow-wrap: anywhere;
}
.erp-notification-error { border-color: #a16272; background: #361f28; }
.erp-notification-success { border-color: #5f987b; background: #1c3029; }
.erp-notification > span { flex: 1 1 auto; }
.erp-notification > button {
    flex: 0 0 auto;
    min-width: 44px;
    min-height: 44px;
    border: 0;
    background: transparent;
    color: inherit;
    font: inherit;
    font-size: 1.4rem;
    cursor: pointer;
}
.erp-notification > button:hover { background: rgb(255 255 255 / 8%); }
.erp-notification > button:focus-visible { outline: 2px solid #a5b4fc; outline-offset: 2px; }
@media (max-width: 768px) { .erp-notification { bottom: calc(60px + 1rem); } }
.fibu-manual-note { margin: .25rem 0 0; color: var(--text-secondary); font-size: .875rem; }

/* The assistant takes one reserved slot of the mobile navigation instead of
   floating over invoice actions. Its open panel stays inside the viewport. */
@media (max-width: 768px) {
    .sidebar .sidebar-nav { width: calc(100% - 56px); flex: 0 1 auto; }

    .ellie-widget,
    .main-wrapper:has(#fibu-studio-view.active) .ellie-widget {
        display: flex;
        align-items: center;
        justify-content: center;
        inset: auto 0 0 auto;
        width: 56px;
        height: 60px;
        background: var(--sidebar-bg);
        border-top: 1px solid var(--border-color);
        border-left: 1px solid var(--border-color);
    }

    .ellie-toggle {
        width: 44px;
        height: 44px;
        min-width: 44px;
        padding: 0;
        justify-content: center;
        border-radius: var(--radius-md);
        transition: background var(--transition-normal), transform var(--transition-normal);
    }
    .ellie-toggle .ellie-label { display: none; }
    .ellie-toggle:focus-visible,
    .ellie-minimize:focus-visible,
    .ellie-input button:focus-visible { outline: 2px solid #a5b4fc; outline-offset: 2px; }

    .ellie-chat {
        position: fixed;
        inset: 8px 8px calc(60px + 8px) 8px;
        width: auto;
        height: auto;
        max-height: none;
        min-width: 0;
        animation: none;
        overscroll-behavior: contain;
    }
    .ellie-header { min-width: 0; gap: 8px; }
    .ellie-header .ellie-avatar,
    .ellie-title small { display: none; }
    .ellie-title { min-width: 0; }
    .ellie-messages { min-height: 0; max-height: none; }
    .ellie-input { min-width: 0; }
    .ellie-input input { min-width: 0; }
    .ellie-input button { min-width: 44px; min-height: 44px; }
    .ellie-minimize { flex: 0 0 44px; min-height: 44px; }
}

/* Bank accounts must reflow inside the small layout viewport at 200% zoom. */
#bankkonten-view .customers-grid {
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 300px), 1fr));
}

#bankkonten-view .bank-card {
    min-width: 0;
    overflow-wrap: anywhere;
}

#bankkonten-view .bank-actions {
    flex-wrap: wrap;
}

#bankkonten-grid .bank-load-state {
    grid-column: 1 / -1;
    padding: var(--space-lg);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    color: var(--text-secondary);
    background: var(--bg-card);
}

#bankkonten-grid .bank-load-error {
    border-color: var(--accent-danger);
}

#bankkonten-grid .bank-load-state .btn {
    margin-top: var(--space-md);
    min-height: 44px;
}

@media (max-width: 640px) {
    #fibu-studio-view .view-header h2,
    #rechnungen-view .view-header h2 {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    #fibu-studio-view .studio-tabs,
    #rechnungen-view .studio-tabs {
        min-width: 0;
        max-width: 100%;
    }

    #fibu-studio-view .studio-tab,
    #rechnungen-view .studio-tab {
        flex: 0 0 auto;
        min-width: 0;
        max-width: 100%;
        overflow-wrap: anywhere;
        text-align: center;
        white-space: normal;
    }

    #bankkonten-view .view-header,
    #bankkonten-view .view-header h2 {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    #bankkonten-view .view-header h2 {
        font-size: 1.35rem;
    }

    #bankkonten-view .view-header > .btn {
        min-width: 0;
        max-width: 100%;
        text-align: center;
        white-space: normal;
    }

    #bank-modal {
        padding: var(--space-sm);
    }

    #bank-modal .modal-content {
        min-width: 0;
        max-height: 100%;
    }

    #bank-modal .modal-header {
        gap: var(--space-sm);
        padding: var(--space-md);
    }

    #bank-modal .modal-header h3 {
        min-width: 0;
        overflow-wrap: anywhere;
    }

    #bank-modal .modal-close {
        flex: 0 0 44px;
        min-height: 44px;
    }

    #bank-modal .form-grid {
        grid-template-columns: minmax(0, 1fr);
        min-width: 0;
        padding: var(--space-md);
    }

    #bank-modal .form-group {
        grid-column: 1 / -1;
        min-width: 0;
    }

    #bank-modal .form-group input {
        min-width: 0;
        width: 100%;
    }

    #bank-modal .form-actions {
        flex-wrap: wrap;
        gap: var(--space-sm);
        margin: 0;
        padding: var(--space-md);
    }

    #bank-modal .form-actions .btn {
        flex: 1 1 100%;
        justify-content: center;
        min-width: 0;
        white-space: normal;
    }
}

/* Focus must use the final mobile layout, including enlarged text. An outer
   hidden overflow box can itself be scrolled by focus and shift the entire view;
   only the explicit table/tab scrollers own horizontal movement here. */
@media (max-width: 768px) {
    .main-wrapper:has(#rechnungen-view.active, #fibu-studio-view.active, #bankkonten-view.active) {
        transition: none;
        overflow-x: clip;
        overflow-y: visible;
    }

    .main-wrapper:has(#rechnungen-view.active, #fibu-studio-view.active, #bankkonten-view.active) .main-content {
        min-width: 0;
        width: 100%;
    }

    #rechnungen-view .table-container {
        container-type: inline-size;
    }

    #invoices-table .actions {
        min-width: min(190px, calc(100cqi - 8px));
        padding-inline: min(24px, 4cqi);
    }

    #invoices-table .actions .btn {
        min-width: 0;
        max-width: 100%;
        white-space: normal;
        overflow-wrap: anywhere;
    }
}

:is(#rechnungen-view, #fibu-studio-view, #bankkonten-view) :is(button, a, input, select) {
    scroll-margin: 8px;
}

@media (max-width: 768px) {
    #fibu-studio-view .studio-tab:focus-visible {
        outline: 2px solid #a5b4fc;
        outline-offset: -2px;
    }
}

/* Keep full action labels readable when zoom leaves a very narrow table window. */
@container (max-width: 180px) {
    #invoices-table .actions {
        grid-template-columns: minmax(0, 1fr);
    }
}

/* Scoped measurement entry form: readable fields independent of history columns. */
#aufmass-entry-overlay { --text-muted: var(--text-secondary); }
#aufmass-entry-overlay[hidden] { display: none; }
#aufmass-entry-overlay .aufmass-entry-card {
    width: 700px;
    max-width: calc(100vw - 2rem);
    max-height: calc(100dvh - 2rem);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
#aufmass-entry-overlay :is(.modal-mini-header, .modal-mini-footer) { flex-shrink: 0; gap: 0.75rem; }
#aufmass-entry-overlay .modal-mini-header > div { min-width: 0; overflow-wrap: anywhere; }
#aufmass-entry-overlay .modal-mini-footer { flex-wrap: wrap; }
#aufmass-entry-overlay .aufmass-entry-body { min-height: 0; overflow-y: auto; padding: 1rem; }
#aufmass-entry-overlay .aufmass-entry-history { min-width: 0; max-width: 100%; overflow-x: auto; padding: 7px; scroll-padding-inline: 7px; }
#aufmass-entry-overlay .aufmass-entry-history table { min-width: 540px; }
#aufmass-entry-overlay .aufmass-entry-history .btn { white-space: nowrap; }
#aufmass-entry-overlay .aufmass-entry-new { margin-top: 1rem; }
#aufmass-entry-overlay .aufmass-entry-new h4 { margin: 0 0 0.75rem; }
#aufmass-entry-overlay .aufmass-entry-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
#aufmass-entry-overlay .aufmass-entry-fields label { display: flex; flex-direction: column; gap: 0.4rem; min-width: 0; font-weight: 600; }
#aufmass-entry-overlay :is(input, button) {
    box-sizing: border-box;
    min-width: 0;
    min-height: 44px;
    max-width: 100%;
    font: inherit;
    scroll-margin-block: 1rem;
    scroll-margin-inline: 0.5rem;
}
#aufmass-entry-overlay input {
    width: 100%;
    padding: 0.65rem 0.75rem;
    font-size: 1rem;
    font-weight: 400;
    color: var(--text-primary);
    background: var(--bg-primary);
    border: 1px solid var(--text-secondary);
    border-radius: var(--radius-sm);
}
#aufmass-entry-overlay input::placeholder { color: var(--text-secondary); opacity: 1; }
#aufmass-entry-overlay :is(.btn, .btn-close) { padding: 0.6rem 0.8rem; border: 1px solid var(--text-secondary); }
#aufmass-entry-overlay .btn-close { min-width: 44px; flex-shrink: 0; }
#aufmass-entry-overlay #aufmass-entry-save { margin-top: 1rem; color: #fff; background: #4f46e5; }
#aufmass-entry-overlay #aufmass-entry-save:disabled { color: var(--text-secondary); background: var(--bg-secondary); opacity: 1; cursor: not-allowed; }
#aufmass-entry-overlay :is(input, button, [tabindex]):focus-visible { outline: 3px solid var(--accent-primary-hover); outline-offset: 3px; }
@media (max-width: 900px) {
    #aufmass-entry-overlay .aufmass-entry-fields { grid-template-columns: minmax(0, 1fr); }
    #aufmass-entry-overlay #aufmass-entry-save { width: 100%; }
}
