/* Allgemeine Stile */
:root {
    --primary: #0d6efd;
    --success: #198754;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #0dcaf0;
}

body {
    background-color: #f8f9fa;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.navbar {
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 20px;
}

.card {
    border: none;
    margin-bottom: 20px;
}

.card-header {
    font-weight: 600;
    border-bottom: 2px solid rgba(255,255,255,0.1);
}

.table {
    font-size: 0.9rem;
}

.table tbody tr {
    transition: background-color 0.2s;
}

.table tbody tr:hover {
    background-color: #f5f5f5;
}

/* Select2 Customization */
.select2-container--bootstrap-5 .select2-selection {
    border-color: #dee2e6;
    border-radius: 4px;
    height: 38px;
}

.select2-container--bootstrap-5.select2-container--focus .select2-selection {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

.select2-container--bootstrap-5 .select2-selection__arrow {
    height: 36px;
}

/* Badge Styles */
.badge-buy {
    background-color: #198754;
    color: white;
}

.badge-sell {
    background-color: #dc3545;
    color: white;
}

/* Button Styles */
.btn-sm {
    padding: 0.4rem 0.6rem;
    font-size: 0.8rem;
}

.btn-edit {
    color: #0d6efd;
}

.btn-edit:hover {
    color: #0b5ed7;
}

.btn-delete {
    color: #dc3545;
}

.btn-delete:hover {
    color: #bb2d3b;
}

.btn-view {
    color: #0dcaf0;
}

.btn-view:hover {
    color: #0da5c8;
}

/* Form Styles */
.form-control:focus,
.form-select:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}

#tradeForm {
    max-height: 90vh;
    overflow-y: auto;
}

/* Sidebar */
@media (max-width: 991px) {
    .col-lg-3 {
        margin-bottom: 20px;
    }
}

/* Tabelle */
.table-responsive {
    max-height: 600px;
    overflow-y: auto;
}

#tradesTable {
    min-width: 100%;
}

/* Loading State */
.loading {
    opacity: 0.6;
    pointer-events: none;
}

/* Pagination */
.pagination {
    margin-top: 10px;
}

.page-link {
    color: #0d6efd;
}

.page-link:hover {
    color: #0b5ed7;
}

/* Alert Messages */
.alert {
    position: fixed;
    top: 80px;
    right: 20px;
    max-width: 400px;
    z-index: 1000;
    animation: slideIn 0.3s ease-out;
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Detail Modal */
.detail-item {
    padding: 12px 0;
    border-bottom: 1px solid #e0e0e0;
}

.detail-item:last-child {
    border-bottom: none;
}

.detail-label {
    font-weight: 600;
    color: #666;
    font-size: 0.9rem;
}

.detail-value {
    color: #333;
    margin-top: 4px;
}

/* Status Badge */
.status-badge {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 500;
}

.status-buy {
    background-color: #d4edda;
    color: #155724;
}

.status-sell {
    background-color: #f8d7da;
    color: #721c24;
}

/* Tooltip */
.tooltip-inner {
    background-color: #333;
    border-radius: 4px;
}

/* Responsive */
@media (max-width: 768px) {
    .table {
        font-size: 0.8rem;
    }
    
    .btn-sm {
        padding: 0.3rem 0.5rem;
        font-size: 0.7rem;
    }
    
    .card {
        margin-bottom: 15px;
    }
    
    .alert {
        max-width: 90vw;
        right: 5vw;
    }
    
    .select2-container--bootstrap-5 .select2-selection {
        height: auto;
    }
}

/* Print Styles */
@media print {
    .navbar, .card-header, .btn, .form-control, .form-select {
        display: none !important;
    }
    
    .table {
        font-size: 1rem;
    }
}

/* ProjectPlaningSystem: fachliche Erweiterungen */
:root {
    --primary: #0d6efd;
    --success: #198754;
    --danger: #dc3545;
    --warning: #ffc107;
    --info: #0dcaf0;
    --surface: #ffffff;
    --background: #f4f6f9;
    --muted: #6c757d;
}

body {
    background: var(--background);
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
}

.navbar {
    box-shadow: 0 2px 8px rgba(0,0,0,.16);
}

.navbar-brand {
    font-weight: 650;
    letter-spacing: .1px;
}

.card {
    border: 0;
    box-shadow: 0 2px 10px rgba(33,37,41,.08);
    margin-bottom: 1.25rem;
}

.card-header {
    font-weight: 650;
}

.kpi-card {
    border-left: 4px solid var(--primary);
}

.kpi-value {
    font-size: 1.65rem;
    line-height: 1.1;
    font-weight: 700;
}

.table {
    font-size: .9rem;
}

.table > :not(caption) > * > * {
    vertical-align: middle;
}

.table tbody tr {
    transition: background-color .15s ease;
}

.table tbody tr:hover {
    background: rgba(13,110,253,.04);
}

.category-row {
    background: #eef3f8 !important;
    font-weight: 700;
}

.child-row td:first-child {
    padding-left: 2rem;
}

.child-row {
    color: #495057;
    background: #fbfcfd;
}

.money {
    text-align: right;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.sticky-summary {
    position: sticky;
    top: 76px;
    z-index: 20;
}

.total-box {
    background: linear-gradient(135deg, #0d6efd, #0b5ed7);
    color: #fff;
    border-radius: .75rem;
    padding: 1rem 1.25rem;
}

.total-box .value {
    font-size: 1.8rem;
    font-weight: 750;
}

.link-list a {
    display: block;
    overflow-wrap: anywhere;
}

.drop-zone {
    border: 2px dashed #b8c2cc;
    border-radius: .75rem;
    padding: 1.25rem;
    text-align: center;
    background: #fafbfc;
}

.badge-status {
    font-weight: 550;
}

.modal-header {
    background: #212529;
    color: #fff;
}

.modal-header .btn-close {
    filter: invert(1);
}

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

.alert-floating {
    position: fixed;
    right: 1.25rem;
    top: 5rem;
    max-width: min(440px, 90vw);
    z-index: 2000;
}

.ai-result {
    white-space: pre-wrap;
    min-height: 9rem;
    background: #f8f9fa;
    border: 1px solid #dee2e6;
    border-radius: .5rem;
    padding: 1rem;
}

.document-thumb {
    width: 44px;
    height: 44px;
    object-fit: cover;
    border-radius: .35rem;
    background: #eef1f4;
}

@media (max-width: 991px) {
    .sticky-summary { position: static; }
    .navbar .btn { margin-top: .3rem; }
}

@media print {
    .navbar, .btn, .modal, .no-print { display: none !important; }
    body { background: #fff; }
    .card { box-shadow: none; }
}


/* Beschaffungs- und Dokumentfunktionen */
.action-menu { min-width: 270px; }
.action-menu .dropdown-item { display: flex; align-items: center; gap: .65rem; padding: .55rem 1rem; }
.action-menu .dropdown-item i { width: 1.2rem; text-align: center; }
.document-choice-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: .5rem;
    max-height: 220px;
    overflow: auto;
    padding: .25rem;
}
.document-choice-grid .form-check { margin: 0; background: #fbfcfd; }
.offer-meta-box {
    display: flex;
    flex-direction: column;
    min-height: 94px;
    padding: .85rem 1rem;
    border: 1px solid #dee2e6;
    border-radius: .6rem;
    background: #f8f9fa;
}
.offer-meta-box small { color: #6c757d; text-transform: uppercase; letter-spacing: .04em; }
.offer-meta-box strong { font-size: 1.05rem; margin: .15rem 0; }
.offer-meta-box span { color: #6c757d; font-size: .85rem; }
#itemSupplierList .table-success td { background-color: rgba(25,135,84,.1); }
#quoteBody { min-height: 280px; }
#offerLines select { min-width: 190px; }
#securitySummary .badge { font-size: .85rem; }
@media (max-width: 767px) {
    .action-menu { min-width: 235px; }
    .document-choice-grid { grid-template-columns: 1fr; }
}

/* Hintergrundaufträge und Diagnosen */
.global-job-widget{position:fixed;right:1rem;bottom:1rem;z-index:1090;max-width:calc(100vw - 2rem)}
.job-widget-panel{width:min(390px,calc(100vw - 2rem));max-height:55vh;overflow:auto;background:#fff;border:1px solid #cfd6df;border-radius:.75rem;box-shadow:0 1rem 2.5rem rgba(0,0,0,.24)}
.job-widget-header{position:sticky;top:0;display:flex;justify-content:space-between;align-items:center;padding:.7rem .85rem;background:#20252a;color:#fff;border-radius:.7rem .7rem 0 0;z-index:1}
.job-widget-compact{display:none;position:relative;width:3.25rem;height:3.25rem;border:0;border-radius:50%;background:#20252a;color:#fff;box-shadow:0 .65rem 1.5rem rgba(0,0,0,.3);font-size:1.25rem;align-items:center;justify-content:center}
.job-widget-compact:hover,.job-widget-compact:focus{background:#343a40;outline:3px solid rgba(13,110,253,.25);outline-offset:2px}
.job-widget-count{position:absolute;right:-.2rem;top:-.3rem;display:flex;align-items:center;justify-content:center;min-width:1.35rem;height:1.35rem;padding:0 .28rem;border-radius:999px;background:#0d6efd;color:#fff;border:2px solid #fff;font-size:.7rem;font-weight:700}
.global-job-widget.is-collapsed .job-widget-panel{display:none}
.global-job-widget.is-collapsed .job-widget-compact{display:flex}
.global-job-widget.has-failed .job-widget-compact{background:#dc3545}
.global-job-widget.has-failed .job-widget-count{background:#842029}
.global-job-widget.has-review .job-widget-compact{background:#ffc107;color:#212529}
.global-job-widget.has-review .job-widget-count{background:#664d03}
.job-widget-row{display:block;padding:.65rem .85rem;color:#212529;text-decoration:none;border-top:1px solid #edf0f2}
.job-widget-row:hover{background:#f6f8fa}.job-widget-row .progress{height:6px;margin:.35rem 0}.job-widget-row small{display:block;color:#6c757d}.job-spin{display:inline-block;animation:job-spin 1.3s linear infinite}@keyframes job-spin{to{transform:rotate(360deg)}}
.app-help-message{position:relative;padding-right:3rem}
.ai-default-summary{background:#f8f9fa;border-bottom:1px solid #dee2e6;padding:.8rem 1rem}
.ai-default-summary strong{display:block;margin-top:.15rem}
.ai-profile-sidebar .card-footer{background:#fff}
@media (max-width:575.98px){.global-job-widget{right:.65rem;bottom:.65rem}.job-widget-panel{width:calc(100vw - 1.3rem);max-height:62vh}}
.diagnostic-list{display:grid;gap:.65rem}.diagnostic-step{display:flex;gap:.7rem;padding:.75rem;border:1px solid #dce1e6;border-radius:.5rem;background:#f8f9fa}.diagnostic-step.ok{border-left:4px solid #198754}.diagnostic-step.failed{border-left:4px solid #dc3545}.diagnostic-step i{font-size:1.15rem}.diagnostic-step.ok i{color:#198754}.diagnostic-step.failed i{color:#dc3545}.diagnostic-step pre{white-space:pre-wrap;margin:.35rem 0 0;font-size:.78rem;background:#fff;padding:.4rem;border-radius:.3rem}
.log-pre{max-height:360px;overflow:auto;white-space:pre-wrap;background:#111827;color:#e5e7eb;border-radius:.5rem;padding:.8rem;font-size:.8rem}.log-message{max-width:520px;white-space:normal}.job-info{height:100%;padding:.75rem;border:1px solid #dee2e6;border-radius:.5rem;background:#f8f9fa}.job-info small,.job-info span{display:block;color:#6c757d}.job-timeline{border-left:2px solid #dee2e6;margin-left:.5rem;padding-left:1rem}.job-timeline>div{padding:.35rem 0}.job-timeline small{color:#6c757d;margin-left:.5rem}
.ai-progress-panel{border:1px solid #9ec5fe;background:#e7f1ff;border-radius:.5rem;padding:.75rem}.ai-progress-panel .progress{height:8px}.charset-warning{border-left:4px solid #ffc107}

/* Projektbezogene Hintergrundaktivität und IMAP-Postfach */
.project-job-entry{display:block;text-decoration:none;color:inherit;padding:.65rem 0;border-bottom:1px solid var(--bs-border-color)}
.project-job-entry:last-child{border-bottom:0;padding-bottom:0}.project-job-entry:first-child{padding-top:0}.project-job-entry:hover strong{text-decoration:underline}
.mail-body{white-space:pre-wrap;max-height:460px;overflow:auto;background:#f8f9fa;border:1px solid #dee2e6;border-radius:.5rem;padding:1rem;font-family:inherit;font-size:.92rem}
#projectJobList .progress,.global-job-widget .progress{height:6px}
#aiResult{max-height:55vh;overflow:auto;white-space:pre-wrap}
.health-check-card{height:100%;padding:.8rem;border:1px solid #d9e0e7;border-radius:.6rem;background:#fff;transition:box-shadow .15s ease,border-color .15s ease}.health-check-card:hover{border-color:#86b7fe;box-shadow:0 .3rem .8rem rgba(13,110,253,.12)}.health-check-card:focus{outline:3px solid rgba(13,110,253,.2);outline-offset:2px}

/* KI-Profilverwaltung */
.ai-profile-sidebar { top: 5.5rem; }
.ai-profile-list-item { border-left: 4px solid transparent !important; }
.ai-profile-list-item.active { border-left-color: #ffc107 !important; }
.model-card {
    display: block;
    border: 1px solid #dee2e6;
    border-radius: .65rem;
    background: #fff;
    padding: 1rem;
    transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.model-card:hover,
.model-card.selected {
    border-color: #0d6efd;
    box-shadow: 0 .3rem .9rem rgba(13, 110, 253, .14);
    transform: translateY(-1px);
}
@media (max-width: 1199.98px) {
    .ai-profile-sidebar { position: static !important; }
}

/* Positionssortierung und Drag-and-drop */
.item-drag-handle{display:inline-flex;align-items:center;justify-content:center;width:1.35rem;height:1.7rem;margin-right:.2rem;color:#6c757d;cursor:grab;border-radius:.25rem;vertical-align:middle}
.item-drag-handle:hover,.item-drag-handle:focus{color:#0d6efd;background:#e7f1ff;outline:none}
.item-drag-handle:active{cursor:grabbing}
.draggable-child.is-dragging{opacity:.45}
.root-drop-target{transition:box-shadow .12s ease,background-color .12s ease}
.root-drop-target.drag-over>td{background:#e7f1ff!important;box-shadow:inset 0 2px 0 #0d6efd,inset 0 -2px 0 #0d6efd}
.root-drop-target.drag-over>td:first-child{box-shadow:inset 3px 0 0 #0d6efd,inset 0 2px 0 #0d6efd,inset 0 -2px 0 #0d6efd}
.root-drop-target.drag-over>td:last-child{box-shadow:inset -3px 0 0 #0d6efd,inset 0 2px 0 #0d6efd,inset 0 -2px 0 #0d6efd}
#aiSupplierReviewCard .form-label{font-size:.85rem;margin-bottom:.2rem}

/* Einklappbare Projektübersicht */
.project-sidebar-column,.project-main-column{transition:flex-basis .18s ease,max-width .18s ease}
.total-box{position:relative}
.total-box>.small:first-of-type{padding-right:2.5rem}
.project-sidebar-collapse-button{position:absolute;top:.55rem;right:.55rem;line-height:1}
.sidebar-restore-button{display:none;position:sticky;top:76px;width:2.65rem;height:2.65rem;align-items:center;justify-content:center;margin-left:auto;padding:0;font-size:1.15rem;box-shadow:0 .25rem .7rem rgba(0,0,0,.14)}
@media (min-width:1200px){
    .project-main-column.sidebar-collapsed{flex:0 0 calc(100% - 4rem);max-width:calc(100% - 4rem)}
    .project-sidebar-column.is-collapsed{flex:0 0 4rem;max-width:4rem}
    .project-sidebar-column.is-collapsed .sidebar-summary-content{display:none}
    .project-sidebar-column.is-collapsed .sidebar-restore-button{display:flex}
}
@media (max-width:1199.98px){
    .sidebar-restore-button{position:static;margin:0 0 .75rem auto}
    .project-sidebar-column.is-collapsed .sidebar-summary-content{display:none}
    .project-sidebar-column.is-collapsed .sidebar-restore-button{display:flex}
}

/* Kostenaufschlüsselung Haupt-/Unterpositionen */
.cost-breakdown{display:block!important;margin-top:.25rem;font-size:.75rem;font-weight:400;color:#6c757d;white-space:normal}
.cost-breakdown-line{display:flex!important;justify-content:flex-end;align-items:baseline;gap:.35rem;line-height:1.25;white-space:nowrap}
.cost-breakdown-line+.cost-breakdown-line{margin-top:.12rem}
.root-item-row .cost-breakdown .child-cost-line{color:#0d6efd}
#latexExportModal .form-check{background:#f8f9fa}
#latexExportModal .form-check:has(.form-check-input:checked){border-color:#0d6efd!important;background:#e7f1ff}

/* Patch 16: kompakte Positionsdarstellung, Hierarchie und Mehrfachzuordnung */
.item-summary-clamp,.category-summary-clamp,.document-assignment-clamp{
    display:-webkit-box;
    -webkit-box-orient:vertical;
    -webkit-line-clamp:2;
    overflow:hidden;
    line-height:1.25;
    max-height:2.5em;
    overflow-wrap:anywhere;
}
.category-summary-clamp{font-size:.78rem;font-weight:400;color:#6c757d;margin:.15rem 0 0 2rem;max-width:75rem}
.hierarchy-toggle{border:0;background:transparent;color:#495057;padding:0 .25rem 0 0;line-height:1;vertical-align:middle}
.hierarchy-toggle:hover,.hierarchy-toggle:focus{color:#0d6efd;outline:none}
.hierarchy-toggle-placeholder{display:inline-block;width:1.15rem}
.item-detail-row>td{background:#f8f9fa!important;border-top:0;padding-top:.25rem;padding-bottom:.5rem}
.item-detail-panel{font-size:.82rem;color:#495057;border-left:3px solid #dee2e6;padding:.35rem .65rem;display:grid;gap:.2rem}
.draggable-root.is-dragging,.draggable-child.is-dragging{opacity:.42}
.root-drop-target.drag-before>td{box-shadow:inset 0 3px 0 #0d6efd!important}
.root-drop-target.drag-after>td{box-shadow:inset 0 -3px 0 #0d6efd!important}
.compact-choice-grid{max-height:18rem;overflow:auto;border:1px solid #dee2e6;border-radius:.5rem;padding:.5rem;background:#fff}
.document-choice-category{border:0;margin:0 0 .65rem;padding:0}
.document-choice-category:last-child{margin-bottom:0}
.document-choice-category legend{float:none;width:auto;font-size:.78rem;font-weight:700;color:#6c757d;margin:0 0 .25rem;padding:0}
.document-choice-item{display:flex;align-items:flex-start;gap:.35rem;padding:.22rem .35rem;border-radius:.25rem;font-size:.84rem;cursor:pointer}
.document-choice-item:hover{background:#f0f6ff}
.document-choice-item.is-child{padding-left:1.35rem;color:#495057}
.document-choice-item input{margin-top:.2rem;flex:0 0 auto}
@media (min-width:992px){.border-start-lg{border-left:1px solid #dee2e6;padding-left:1.5rem}}

/* Patch 19: kompakter Angebotsdialog mit Registerkarten */
#uploadModal .modal-body { padding-top: .85rem; }
#uploadModal .nav-tabs .nav-link { font-weight: 600; }
#uploadModal .tab-content { background: #fff; }
.assigned-document-details {
    border: 1px solid #dee2e6;
    border-radius: .5rem;
    background: #f8f9fa;
    padding: .55rem .75rem;
}
.assigned-document-details > summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}
.assigned-document-details > summary::-webkit-details-marker { display: none; }
.assigned-document-details > summary::before {
    content: '+';
    display: inline-grid;
    place-items: center;
    width: 1.25rem;
    height: 1.25rem;
    border: 1px solid #adb5bd;
    border-radius: .25rem;
    background: #fff;
    font-weight: 700;
    flex: 0 0 auto;
}
.assigned-document-details[open] > summary::before { content: '−'; }
.assigned-document-details > summary strong { margin-right: auto; }
#uploadExistingDocuments .list-group-item { padding: .55rem .2rem; background: transparent; }
#uploadModal .compact-choice-grid { max-height: 14rem; }

/* Patch 21: durchsuchbare Lieferanten-/Herstellerauswahl */
.supplier-picker {
    position: relative;
}
.supplier-search-input {
    background-image: none;
}
.supplier-picker select {
    min-height: 2.4rem;
}
