/* =====================================================
   ROZLICZENIA MODULE - CSS
   Styl zgodny z resztą CRM (agreements-module pattern)
   ===================================================== */

/* Tabs bar */
.rozl-tabs-bar {
    display: flex;
    gap: 4px;
    padding: 12px 16px 0;
    border-bottom: 2px solid #e0e0e0;
    overflow-x: auto;
    flex-wrap: nowrap;
}

.rozl-tab {
    padding: 10px 18px;
    border: none;
    background: transparent;
    color: #666;
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    border-bottom: 3px solid transparent;
    transition: all 0.2s;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.rozl-tab:hover {
    color: #333;
    background: #f5f5f5;
    border-radius: 6px 6px 0 0;
}

.rozl-tab.active {
    color: #2c7be5;
    border-bottom-color: #2c7be5;
    font-weight: 600;
}

.rozl-tab i {
    font-size: 12px;
}

/* Filters area */
.rozl-filters-area {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding: 16px;
    background: #f8f9fa;
    border-bottom: 1px solid #e0e0e0;
    align-items: flex-start;
}

/* Mode toggle */
.rozl-mode-toggle {
    display: flex;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #dee2e6;
    flex-shrink: 0;
}

.rozl-mode-btn {
    padding: 8px 16px;
    border: none;
    background: #fff;
    color: #555;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.rozl-mode-btn:first-child {
    border-right: 1px solid #dee2e6;
}

.rozl-mode-btn.active {
    background: #2c7be5;
    color: #fff;
}

.rozl-mode-btn:hover:not(.active) {
    background: #e9ecef;
}

/* Date picker */
.rozl-date-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
    flex: 1;
    min-width: 400px;
}

.rozl-date-year {
    display: flex;
    align-items: center;
    gap: 6px;
}

.rozl-year-btn {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 1px solid #dee2e6;
    background: #fff;
    color: #555;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.rozl-year-btn:hover {
    background: #2c7be5;
    color: #fff;
    border-color: #2c7be5;
}

.rozl-year-label {
    font-weight: 700;
    font-size: 16px;
    min-width: 48px;
    text-align: center;
}

.rozl-date-quarters, .rozl-date-months {
    display: flex;
    gap: 3px;
    flex-wrap: nowrap;
}

.rozl-q-btn, .rozl-m-btn {
    padding: 5px 10px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    background: #fff;
    color: #555;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.rozl-q-btn:hover, .rozl-m-btn:hover {
    background: #e9ecef;
    border-color: #adb5bd;
}

.rozl-q-btn.selected, .rozl-m-btn.selected {
    background: #2c7be5;
    color: #fff;
    border-color: #2c7be5;
}

.rozl-date-range {
    display: flex;
    gap: 8px;
    align-items: center;
}

.rozl-date-input {
    padding: 5px 8px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    font-size: 12px;
    color: #333;
    max-width: 140px;
}

.rozl-date-input:focus {
    border-color: #2c7be5;
    outline: none;
    box-shadow: 0 0 0 2px rgba(44,123,229,0.15);
}

.rozl-date-sync {
    display: flex;
    align-items: center;
}

.rozl-date-sync label {
    font-size: 11px;
    color: #666;
    white-space: nowrap;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Multi-select filter */
.rozl-multi-filter {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-width: 180px;
}

.rozl-multi-filter > label {
    font-size: 11px;
    font-weight: 600;
    color: #555;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.rozl-multi-select {
    position: relative;
}

.rozl-multi-display {
    min-height: 34px;
    padding: 4px 8px;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    background: #fff;
    cursor: pointer;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}

.rozl-multi-display:hover {
    border-color: #adb5bd;
}

.rozl-placeholder {
    color: #999;
    font-size: 12px;
}

.rozl-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    background: #e3edf7;
    color: #2c7be5;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.rozl-chip i {
    cursor: pointer;
    font-size: 10px;
    opacity: 0.7;
}

.rozl-chip i:hover {
    opacity: 1;
    color: #e74c3c;
}

.rozl-multi-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 1000;
    background: #fff;
    border: 1px solid #dee2e6;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.1);
    margin-top: 4px;
    max-height: 280px;
    overflow-y: auto;
}

.rozl-multi-search {
    width: 100%;
    padding: 8px 10px;
    border: none;
    border-bottom: 1px solid #eee;
    font-size: 12px;
    outline: none;
    box-sizing: border-box;
}

.rozl-multi-options {
    padding: 4px;
}

.rozl-multi-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    font-size: 12px;
    cursor: pointer;
    border-radius: 4px;
}

.rozl-multi-option:hover {
    background: #f5f5f5;
}

.rozl-multi-option input[type="checkbox"] {
    accent-color: #2c7be5;
}

/* Content area */
.rozl-content {
    padding: 16px;
}

/* Loading & Empty states */
.rozl-loading, .rozl-empty, .rozl-error {
    text-align: center;
    padding: 48px 24px;
    color: #888;
    font-size: 14px;
}

.rozl-loading i {
    font-size: 24px;
    color: #2c7be5;
    display: block;
    margin-bottom: 12px;
}

.rozl-error {
    color: #e74c3c;
}

.rozl-error i {
    font-size: 24px;
    display: block;
    margin-bottom: 12px;
}

.rozl-empty {
    color: #999;
}

/* Tables */
.rozl-table-wrapper {
    overflow-x: auto;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.rozl-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.rozl-table thead th {
    background: #f8f9fa;
    color: #555;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 10px 12px;
    border-bottom: 2px solid #e0e0e0;
    text-align: left;
    white-space: nowrap;
}

.rozl-table thead th.num {
    text-align: right;
}

.rozl-table tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid #f0f0f0;
    vertical-align: middle;
}

.rozl-table tbody tr:hover {
    background: #f8f9fa;
}

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

.rozl-table .bold {
    font-weight: 600;
}

.rozl-table .name-cell {
    font-weight: 500;
    color: #333;
}

.rozl-table tfoot td {
    padding: 12px;
    border-top: 2px solid #e0e0e0;
    background: #f8f9fa;
}

.total-row {
    background: #f0f4f8 !important;
}

.positive { color: #27ae60; }
.negative { color: #e74c3c; }
.muted { color: #ccc; }

/* Matrix */
.rozl-matrix th.matrix-corner {
    background: #eef;
    font-size: 10px;
    min-width: 140px;
}

.rozl-matrix th.matrix-header {
    text-align: center;
    min-width: 100px;
}

.matrix-cell {
    text-align: center !important;
    padding: 8px !important;
    min-width: 100px;
}

.matrix-cell.diagonal {
    background: #f0f4f8;
}

.matrix-cell.empty {
    color: #ddd;
}

.matrix-cell.total-cell {
    background: #f0f4f8;
}

.matrix-tony {
    font-size: 12px;
    color: #333;
}

.matrix-marza {
    font-size: 11px;
    margin-top: 2px;
}

/* Cards grid */
.rozl-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 16px;
}

/* Handler cards */
.rozl-handler-card {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.rozl-handler-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: linear-gradient(135deg, #f8f9fa, #eef2f7);
    border-bottom: 1px solid #e0e0e0;
}

.rozl-handler-name {
    font-weight: 600;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
}

.rozl-handler-name i {
    color: #2c7be5;
}

.rozl-handler-total {
    font-size: 12px;
    color: #555;
}

.rozl-compact {
    font-size: 12px;
}

.rozl-compact thead th {
    font-size: 10px;
    padding: 6px 10px;
}

.rozl-compact tbody td {
    padding: 6px 10px;
}

/* Contractor cards */
.rozl-contractor-card {
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}

.rozl-contractor-header {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #f8f9fa, #eef2f7);
    border-bottom: 1px solid #e0e0e0;
}

.rozl-contractor-name {
    font-weight: 600;
    color: #333;
    display: flex;
    align-items: center;
    gap: 8px;
}

.rozl-contractor-name i {
    color: #666;
}

.rozl-contractor-total {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.rozl-badge {
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.rozl-badge.kupione {
    background: #fde8e8;
    color: #e74c3c;
}

.rozl-badge.sprzedane {
    background: #e8f5e9;
    color: #27ae60;
}

.rozl-badge.marza {
    background: #e3edf7;
    color: #2c7be5;
}

.rozl-badge.marza.positive {
    background: #e8f5e9;
    color: #27ae60;
}

.rozl-badge.marza.negative {
    background: #fde8e8;
    color: #e74c3c;
}

.rozl-contractor-body {
    padding: 10px 16px;
}

.rozl-contractor-section {
    margin-bottom: 8px;
}

.rozl-contractor-section h4 {
    font-size: 11px;
    font-weight: 600;
    color: #555;
    margin: 0 0 4px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}

.rozl-product-line {
    display: flex;
    justify-content: space-between;
    padding: 3px 0;
    font-size: 12px;
    color: #444;
    border-bottom: 1px solid #f5f5f5;
}

.rozl-product-line:last-child {
    border-bottom: none;
}

/* Responsive */
@media (max-width: 768px) {
    .rozl-tabs-bar {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .rozl-filters-area {
        flex-direction: column;
    }
    
    .rozl-date-picker {
        min-width: unset;
    }
    
    .rozl-cards-grid {
        grid-template-columns: 1fr;
    }
}


/* Warehouse location badge */
.rozl-wh-location {
    font-size: 13px;
    color: #2c7be5;
    display: flex;
    align-items: center;
    gap: 6px;
    margin: 2px 0;
}

.rozl-wh-location i {
    color: #6c757d;
    font-size: 12px;
}

.rozl-badge i {
    margin-right: 3px;
    font-size: 10px;
}


/* Pozycje otwarte */
.rozl-pozycje-section {
    margin-top: 20px;
    border: 2px dashed #ffc107;
    border-radius: 8px;
    overflow: hidden;
    background: #fffdf0;
}

.rozl-pozycje-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: linear-gradient(135deg, #fff8e1, #fff3cd);
    border-bottom: 1px solid #ffe082;
    font-weight: 600;
    font-size: 13px;
    color: #856404;
}

.rozl-pozycje-header i {
    color: #ffc107;
    font-size: 16px;
}

.rozl-pozycje-summary {
    margin-left: auto;
    font-size: 12px;
    color: #555;
}

.rozl-pozycja-row {
    background: #fffdf5 !important;
}

.rozl-pozycja-row:hover {
    background: #fff8e1 !important;
}

.rozl-pozycja-card {
    border-color: #ffc107 !important;
}

.rozl-pozycja-card-header {
    background: linear-gradient(135deg, #fff8e1, #fff3cd) !important;
    border-bottom-color: #ffe082 !important;
}

.rozl-pozycja-card-header .rozl-handler-name i {
    color: #ffc107 !important;
}

/* Product line with multi-value columns */
.rozl-prod-name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.rozl-prod-nums {
    display: flex;
    gap: 10px;
    flex-shrink: 0;
    align-items: center;
}
.rozl-prod-nums .num {
    min-width: 72px;
    text-align: right;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}
.rozl-prod-nums .muted {
    font-size: 11px;
    color: #999;
    min-width: 60px;
}

/* MATRIX CELL POPUP */

.matrix-cell.clickable { cursor: pointer; transition: all 0.15s ease; position: relative; }
.matrix-cell.clickable:hover { background: rgba(59,130,246,0.08) !important; box-shadow: inset 0 0 0 2px rgba(59,130,246,0.3); }
.matrix-cell.clickable:active { transform: scale(0.97); }

.matrix-popup-overlay {
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.45); backdrop-filter: blur(3px);
    z-index: 10000; display: flex; align-items: center; justify-content: center;
    animation: mpFadeIn 0.15s ease;
}
@keyframes mpFadeIn { from { opacity: 0; } to { opacity: 1; } }

.matrix-popup {
    background: #fff; border-radius: 14px;
    box-shadow: 0 25px 60px rgba(0,0,0,0.2), 0 0 0 1px rgba(0,0,0,0.05);
    max-width: 90vw; max-height: 80vh; min-width: 640px;
    display: flex; flex-direction: column;
    animation: mpSlideIn 0.2s ease; overflow: hidden;
}
@keyframes mpSlideIn { from { opacity:0; transform: translateY(20px) scale(0.97); } to { opacity:1; transform: translateY(0) scale(1); } }

.matrix-popup-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 16px 20px; background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
    color: #fff; gap: 16px; flex-wrap: wrap;
}
.mp-title-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.matrix-popup-header strong { font-size: 14px; }
.mp-label { font-size: 11px; opacity: 0.7; text-transform: uppercase; letter-spacing: 0.5px; }
.mp-arrow { margin: 0 8px; font-size: 16px; opacity: 0.5; }
.mp-summary { display: flex; gap: 8px; align-items: center; }
.mp-badge { background: rgba(255,255,255,0.15); padding: 4px 10px; border-radius: 6px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.mp-badge.positive { background: rgba(16,185,129,0.25); color: #a7f3d0; }
.mp-badge.negative { background: rgba(239,68,68,0.25); color: #fca5a5; }

.mp-close {
    background: rgba(255,255,255,0.15); border: none; color: #fff;
    font-size: 22px; width: 36px; height: 36px; border-radius: 8px;
    cursor: pointer; display: flex; align-items: center; justify-content: center;
    transition: background 0.15s; flex-shrink: 0; line-height: 1;
}
.mp-close:hover { background: rgba(255,255,255,0.3); }

.matrix-popup-body { overflow: auto; max-height: 60vh; padding: 0; }

.mp-table { width: 100%; border-collapse: collapse; font-size: 12px; }
.mp-table thead { position: sticky; top: 0; z-index: 1; }
.mp-table thead th {
    background: #f8fafc; border-bottom: 2px solid #e2e8f0; padding: 10px 8px;
    font-weight: 600; color: #475569; text-align: left; font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.3px; white-space: nowrap;
}
.mp-table tbody tr { border-bottom: 1px solid #f1f5f9; transition: background 0.1s; }
.mp-table tbody tr:hover { background: #f8fafc; }
.mp-table tbody tr:last-child { border-bottom: none; }
.mp-table td { padding: 8px 8px; vertical-align: middle; }

.mp-idx { color: #94a3b8; font-size: 10px; width: 24px; text-align: center; }
.mp-id { font-weight: 600; color: #3b82f6; font-size: 11px; white-space: nowrap; }
.mp-towar { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; color: #1e293b; }
.mp-kont { max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #64748b; font-size: 11px; }
.mp-um { font-size: 10px; color: #94a3b8; max-width: 100px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mp-num { text-align: right; white-space: nowrap; font-weight: 500; font-variant-numeric: tabular-nums; }
.mp-num.positive { color: #059669; }
.mp-num.negative { color: #dc2626; }

@media (max-width: 768px) {
    .matrix-popup { min-width: unset; max-width: 98vw; max-height: 90vh; border-radius: 10px; }
    .matrix-popup-header { padding: 12px 14px; flex-direction: column; align-items: flex-start; }
    .mp-table { font-size: 11px; }
    .mp-table td, .mp-table th { padding: 6px 4px; }
}

/* Matrix popup row click */
.mp-row-link { cursor: pointer; }
.mp-row-link:hover { background: #eff6ff !important; }
.mp-row-link:active { background: #dbeafe !important; }
