/* Color scheme similar to classifications */
:root {
    --primary-color: #007bff;
    --success-color: #28a745;
    --info-color: #17a2b8;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --light-bg: #f8f9fa;
    --border-color: #dee2e6;
}

html {
    height: 100%;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--light-bg);
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    /* Better tap responsiveness on mobile */
    -webkit-tap-highlight-color: rgba(0,0,0,0.1);
}

/* Desktop only - prevent body scroll */
@media (min-width: 769px) {
    body {
        overflow: hidden;
    }
}

/* Touch-friendly buttons */
.btn {
    min-height: 44px;
    padding: 10px 16px;
    touch-action: manipulation;
}

.container-fluid {
    padding: 0;
}

.row {
    margin: 0;
}

/* Left and right panels */
.left-panel {
    height: 100%;
    overflow-y: auto;
    padding: 0 20px 20px 20px; /* No top padding */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.right-panel {
    height: 100%;
    overflow-y: auto;
    padding: 0 20px 20px 20px; /* No top padding */
    -webkit-overflow-scrolling: touch; /* Smooth scrolling on iOS */
}

.left-panel {
    background-color: white;
    border-right: 2px solid var(--border-color);
}

.right-panel {
    background-color: var(--light-bg);
}

/* Header section */
.header-section {
    position: sticky;
    top: 0;
    background-color: white;
    z-index: 100;
    padding-top: 20px;
    padding-bottom: 15px;
    border-bottom: 2px solid var(--border-color);
    margin-bottom: 10px;
}

h2 {
    color: var(--primary-color);
    font-weight: 600;
}

/* Statistics panel */
.statistics-panel {
    background: transparent;
    border-radius: 12px;
    padding: 0;
    box-shadow: none;
}

.stat-card {
    border: none;
    border-radius: 12px;
    padding: 20px;
    text-align: center;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    transition: all 0.3s ease;
    color: white;
}

.stat-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 20px rgba(0,0,0,0.25);
}

.stat-label {
    font-size: 11px;
    color: rgba(255,255,255,0.9);
    text-transform: uppercase;
    letter-spacing: 0.8px;
    font-weight: 500;
    margin-bottom: 8px;
}

.stat-value {
    font-size: 18px;
    font-weight: bold;
    color: white;
    text-shadow: 0 1px 2px rgba(0,0,0,0.2);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Gradient backgrounds for each stat card */
.stat-card.stat-invoices {
    background: linear-gradient(135deg, #3498db 0%, #2980b9 100%);
}

.stat-card.stat-paid {
    background: linear-gradient(135deg, #e74c3c 0%, #c0392b 100%);
}

.stat-card.stat-tax-base {
    background: linear-gradient(135deg, #27ae60 0%, #229954 100%);
}

.stat-card.stat-vat {
    background: linear-gradient(135deg, #e67e22 0%, #d35400 100%);
}

.stat-card.stat-total {
    background: linear-gradient(135deg, #28a745 0%, #218838 100%);
}

/* Financial stat columns - equal width for the 3 financial panels */
.financial-stat {
    flex: 1 1 0 !important;
    max-width: none !important;
}

@media (min-width: 768px) {
    .financial-stat {
        width: calc(26.66% - 8px) !important;
        flex: 0 0 auto !important;
    }
}

/* Search panel */
.search-panel {
    background-color: var(--light-bg);
    border-radius: 8px;
    padding: 20px;
    border: 1px solid var(--border-color);
}

.search-panel .form-label {
    font-weight: 500;
    color: #555;
    margin-bottom: 5px;
}

/* Invoice list table */
.invoice-list-container {
    margin-top: 0;
    background-color: white;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 0;
}

.table-responsive {
    overflow-x: auto;
}

#invoicesTable {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
    margin-bottom: 0;
}

#invoicesTable thead {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

#invoicesTable th {
    padding: 12px 10px;
    font-weight: 600;
    text-align: left;
    border: none;
    white-space: nowrap;
}

/* Sortable column headers */
#invoicesTable th.sortable {
    cursor: pointer;
    user-select: none;
    position: relative;
}

#invoicesTable th.sortable:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

#invoicesTable th.sortable i {
    font-size: 0.8em;
    margin-left: 5px;
    opacity: 0.6;
}

#invoicesTable th.sortable.sort-asc i::before {
    content: "\f145";
}

#invoicesTable th.sortable.sort-desc i::before {
    content: "\f144";
}

#invoicesTable th.sortable.sort-asc i,
#invoicesTable th.sortable.sort-desc i {
    opacity: 1;
}

#invoicesTable tbody tr {
    cursor: pointer;
    transition: background-color 0.2s;
    border-bottom: 1px solid #e9ecef;
    /* Touch-friendly tap targets */
    min-height: 44px;
}

#invoicesTable tbody tr:hover {
    background-color: #f8f9fa;
}

#invoicesTable tbody tr.selected {
    background-color: #e3f2fd;
    border-left: 3px solid #007bff;
}

/* Selected row styling for payment and invoice search tables */
#missingInvoicesTable tbody tr.row-selected,
#searchResultsBody tr.row-selected {
    background-color: #fff3cd !important;
    border-left: 4px solid #ffc107;
}

#missingInvoicesTable tbody tr:hover,
#searchResultsBody tr:hover {
    background-color: #f8f9fa;
    cursor: pointer;
}

#invoicesTable td {
    padding: 6px 10px;
    border: none;
    vertical-align: middle;
}

#invoicesTable td.text-end {
    text-align: right;
}

#invoicesTable td.text-center {
    text-align: center;
}

.badge {
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
}

.badge-info {
    background-color: var(--info-color);
    color: white;
}

.badge-success {
    background-color: var(--success-color);
    color: white;
}

/* Pagination */
#paginationContainer {
    padding: 15px;
    background-color: white;
    border-radius: 0 0 8px 8px;
}

.pagination {
    margin-bottom: 0;
}

.pagination .page-link {
    color: #667eea;
    border: 1px solid #dee2e6;
    padding: 8px 12px;
    margin: 0 2px;
    border-radius: 4px;
    transition: all 0.2s;
}

/* Hover само за устройства с мишка (не мобилни) */
@media (hover: hover) and (pointer: fine) {
    .pagination .page-link:hover {
        background-color: #667eea;
        color: white;
        border-color: #667eea;
    }
}

.pagination .page-item.active .page-link {
    background-color: #667eea;
    border-color: #667eea;
    color: white;
}

.pagination .page-item.disabled .page-link {
    color: #6c757d;
    pointer-events: none;
    background-color: #fff;
    border-color: #dee2e6;
}

/* Invoice details */
.invoice-header {
    background-color: white;
    border-radius: 8px;
    padding: 20px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#invoiceTitle {
    color: var(--primary-color);
    font-weight: 600;
    margin-bottom: 15px;
}

.invoice-info {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.info-item {
    display: flex;
    flex-direction: column;
}

.info-label {
    font-size: 0.85rem;
    color: #666;
    font-weight: 500;
}

.info-value {
    font-size: 1rem;
    color: #333;
    font-weight: 600;
}

/* Items section */
.items-section {
    background-color: white;
    border-radius: 8px;
    padding: 15px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 10px;
}

.items-sum {
    background-color: #e8f4f8;
    padding: 10px;
    border-radius: 6px;
    border-left: 4px solid var(--info-color);
}

.items-table {
    font-size: 0.9rem;
    table-layout: auto;
    width: 100%;
}

.items-table thead {
    background-color: var(--primary-color);
    color: white;
}

.items-table th {
    font-weight: 600;
    text-align: center;
    vertical-align: middle;
    padding: 12px 8px;
    white-space: nowrap;
}

.items-table td {
    padding: 10px 8px;
    vertical-align: middle;
}

/* Column widths for 5 columns (without Разпределения) */
.items-table th:nth-child(1) { width: 5%; min-width: 40px; }     /* № */
.items-table th:nth-child(2) { width: 45%; min-width: 200px; }   /* Описание */
.items-table th:nth-child(3) { width: 15%; min-width: 100px; }   /* Количество */
.items-table th:nth-child(4) { width: 17.5%; min-width: 110px; } /* Ед. цена */
.items-table th:nth-child(5) { width: 17.5%; min-width: 110px; } /* Данъчна основа */

.items-table td:nth-child(2) { 
    word-wrap: break-word;
    overflow-wrap: break-word;
}

/* Row for item data */
.item-row {
    background-color: white;
}

.item-row:hover {
    background-color: #f8f9fa;
}

/* Row for allocations */
.allocations-row {
    background-color: #f0f8ff;
    border-top: none !important;
}

.allocations-cell {
    padding: 15px 20px !important;
    border-top: none !important;
}

.allocations-container {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: flex-start;
}

.allocations-container > strong {
    width: 100%;
    color: var(--primary-color);
    margin-bottom: 5px;
    font-size: 0.95rem;
}

.allocation-item {
    background-color: white;
    border-left: 3px solid var(--success-color);
    padding: 10px 12px;
    margin-right: 10px;
    margin-bottom: 5px;
    border-radius: 4px;
    font-size: 0.85rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    min-width: 200px;
    flex: 0 1 auto;
}

.allocation-field {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
    gap: 10px;
}

.allocation-field:last-child {
    margin-bottom: 0;
}

.allocation-label {
    color: #666;
    font-weight: 500;
    font-size: 0.8rem;
    white-space: nowrap;
}

.allocation-value {
    color: #333;
    font-weight: normal;
    text-align: right;
    word-break: break-word;
}

/* PDF section */
.pdf-section {
    background-color: white;
    border-radius: 8px;
    padding: 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.pdf-viewer {
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}

/* Buttons */
.btn {
    border-radius: 6px;
    font-weight: 500;
    padding: 8px 20px;
    transition: all 0.2s;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-secondary {
    background-color: #6c757d;
    border-color: #6c757d;
}

/* Scrollbar styling */
.left-panel::-webkit-scrollbar,
.right-panel::-webkit-scrollbar {
    width: 8px;
}

.left-panel::-webkit-scrollbar-track,
.right-panel::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.left-panel::-webkit-scrollbar-thumb,
.right-panel::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.left-panel::-webkit-scrollbar-thumb:hover,
.right-panel::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* New record highlight */
.new-record-row {
    background-color: #e0e0e0 !important;
}

.new-record-row:hover {
    background-color: #d0d0d0 !important;
}

/* Preserve ID cell allocation status colors */
.new-record-row td:first-child {
    background-color: white !important;
}

.new-record-row td:first-child[style*="background-color: #d4edda"] {
    background-color: #d4edda !important;
}

.new-record-row td:first-child[style*="background-color: #fff3cd"] {
    background-color: #fff3cd !important;
}

/* Main container with flex layout */
.main-container {
    display: flex;
    height: 100%;
    overflow: hidden;
    width: 100%;
    min-width: 0;
}

.left-column {
    flex: 2;
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-width: 0;
    overflow: hidden;
    max-height: 100%;
}

.right-column {
    flex: 1;
    min-width: 400px;
    max-width: none;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    max-height: 100%;
}

.right-column .panel-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    min-height: 0;
}

.main-container > .column-resizer {
    width: 3px;
    background: #bbb;
    cursor: col-resize;
    user-select: none;
    transition: background-color 0.2s;
    z-index: 10;
    position: relative;
}

.main-container > .column-resizer:hover {
    background: #667eea;
}

.main-container > .column-resizer.dragging {
    background: #667eea;
}

/* Responsive */
@media (max-width: 992px) {
    /* Tablets */
    .left-column {
        width: 100% !important;
    }
    
    .right-column {
        width: 100% !important;
        margin-top: 20px;
    }
    
    .main-container {
        flex-direction: column;
        height: auto;
    }
    
    .column-resizer {
        display: none;
    }
}

@media (max-width: 768px) {
    /* Mobile phones */
    body {
        font-size: 14px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .left-panel, .right-panel {
        height: auto;
        min-height: 100vh;
        padding: 10px;
        overflow-y: visible;
    }
    
    .main-container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
    }
    
    .left-column {
        width: 100% !important;
        flex: none !important;
    }
    
    .right-column {
        width: 100% !important;
        margin-top: 20px;
    }
    
    .column-resizer {
        display: none;
    }
    
    .main-container > .column-resizer {
        display: none;
    }
    
    /* Items table - make it scrollable horizontally */
    .items-table {
        table-layout: auto !important;
        font-size: 0.8rem;
        min-width: 800px;
    }
    
    .items-table th,
    .items-table td {
        padding: 8px 4px;
        white-space: nowrap;
    }
    
    .items-table th:nth-child(2),
    .items-table td:nth-child(2) {
        white-space: normal !important;
        min-width: 150px;
    }
    
    .items-table th:nth-child(6),
    .items-table td:nth-child(6) {
        white-space: normal !important;
        min-width: 250px;
    }
    
    /* Disable resizer on mobile */
    .items-table th:nth-child(5)::after {
        display: none;
    }
    
    .table-responsive {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Header */
    .header-section h2 {
        font-size: 1.5rem;
    }
    
    /* Statistics - stack vertically on mobile */
    .statistics-panel .row {
        flex-direction: column;
        gap: 10px;
    }
    
    .statistics-panel .col-md-3 {
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
    }
    
    .stat-card {
        padding: 15px;
    }
    
    .stat-value {
        font-size: 22px;
    }
    
    .stat-label {
        font-size: 10px;
    }
    
    /* Search panel - stack inputs */
    .search-panel .row {
        flex-direction: column;
        gap: 10px;
    }
    
    .search-panel .col-md-4,
    .search-panel .col-md-12 {
        width: 100%;
        max-width: 100%;
        flex: 0 0 100%;
    }
    
    .search-panel .btn {
        width: 100%;
        margin-bottom: 10px;
    }
    
    /* Table - horizontal scroll */
    .invoice-list-container {
        overflow-x: auto;
    }
    
    .table {
        font-size: 12px;
        min-width: 800px;
    }
    
    .table th,
    .table td {
        padding: 8px 4px;
        white-space: nowrap;
    }
    
    /* Invoice info */
    .invoice-info {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    /* PDF viewer */
    .pdf-viewer {
        height: 600px;
        max-height: 70vh;
        min-height: 400px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Items table */
    .items-section .table-responsive {
        overflow-x: auto;
    }
    
    .items-section .table {
        font-size: 11px;
        min-width: 600px;
    }
    
    .items-section .table th,
    .items-section .table td {
        padding: 6px 3px;
    }
    
    /* Allocation items - stack */
    .allocation-item {
        padding: 8px;
        margin-bottom: 8px;
    }
    
    .allocation-field {
        font-size: 11px;
    }
    
    /* Pagination for mobile */
    #paginationContainer {
        padding: 10px;
    }
    
    .pagination .page-link {
        padding: 10px 14px;
        min-width: 44px;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
        font-size: 14px;
    }
    
    .pagination .page-item {
        margin: 0 1px;
    }
}

@media (max-width: 480px) {
    /* Extra small phones */
    body {
        font-size: 13px;
    }
    
    .header-section h2 {
        font-size: 1.3rem;
    }
    
    .stat-value {
        font-size: 20px;
    }
    
    .stat-label {
        font-size: 9px;
    }
    
    .table {
        font-size: 11px;
    }
    
    .pdf-viewer {
        height: 500px;
        max-height: 60vh;
        min-height: 300px;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    /* Pagination for extra small screens */
    .pagination .page-link {
        padding: 8px 10px;
        min-width: 40px;
        min-height: 40px;
        font-size: 13px;
    }
}

/* Partial payment button - pink/magenta color */
.partial-payment-btn.btn-danger {
    background-color: #ff69b4 !important; /* Hot pink */
    border-color: #ff1493 !important; /* Deep pink */
    color: white !important;
}

.partial-payment-btn.btn-danger:hover {
    background-color: #ff1493 !important; /* Darker on hover */
    border-color: #c71585 !important;
}

.partial-payment-btn.btn-danger:focus,
.partial-payment-btn.btn-danger:active {
    background-color: #c71585 !important;
    border-color: #8b0a50 !important;
}

/* Overpayment button - light green color */
.overpayment-btn.btn-success {
    background-color: #90ee90 !important; /* Light green */
    border-color: #7cda7c !important;
    color: #155724 !important; /* Dark green text */
}

.overpayment-btn.btn-success:hover {
    background-color: #7cda7c !important; /* Darker on hover */
    border-color: #5fc05f !important;
}

.overpayment-btn.btn-success:focus,
.overpayment-btn.btn-success:active {
    background-color: #5fc05f !important;
    border-color: #4da64d !important;
}

/* Fully paid button - dark green color (for multi-invoice payments) */
.btn-success:not(.overpayment-btn) {
    background-color: #28a745 !important; /* Dark green - Bootstrap default but enforced */
    border-color: #28a745 !important;
    color: #ffffff !important;
}

.btn-success:not(.overpayment-btn):hover {
    background-color: #218838 !important; /* Darker on hover */
    border-color: #1e7e34 !important;
}

.btn-success:not(.overpayment-btn):focus,
.btn-success:not(.overpayment-btn):active {
    background-color: #1e7e34 !important;
    border-color: #1c7430 !important;
}

/* Modal scrolling fixes for mobile */
.modal {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
}

.modal-dialog {
    margin: 1.75rem auto;
}

.modal-body {
    max-height: calc(100vh - 200px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* Ensure modals work on mobile */
@media (max-width: 768px) {
    .modal-dialog {
        margin: 0.5rem;
        max-width: calc(100% - 1rem);
    }
    
    .modal-body {
        max-height: calc(100vh - 150px);
    }
    
    .modal.show {
        overflow-y: auto !important;
    }
}

/* Resizable modal for missing invoices */
#missingInvoicesModal .modal-dialog {
    max-width: 95vw !important;
    width: 90vw;
    margin: 1.75rem auto;
    position: relative;
}

#missingInvoicesModal .modal-content {
    height: 85vh;
    min-height: 500px;
    max-height: 95vh;
    display: flex;
    flex-direction: column;
    position: relative;
    resize: both;
    overflow: auto;
}

#missingInvoicesModal .modal-body {
    flex: 1;
    overflow-y: auto;
    max-height: none;
}

/* Resize handle indicator - visible resize grip */
#missingInvoicesModal .modal-content::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, transparent 50%, #6c757d 50%);
    cursor: nwse-resize;
    z-index: 1000;
}

/* Resize icon in corner */
#missingInvoicesModal .modal-content::before {
    content: '⋰';
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 18px;
    color: #fff;
    pointer-events: none;
    z-index: 1001;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

/* Make header draggable cursor */
#missingInvoicesModal .modal-header {
    cursor: move;
    user-select: none;
}

#missingInvoicesModal .modal-header:active {
    cursor: grabbing;
}

/* Resizable modal for payment info */
#paymentInfoModal .modal-content {
    position: relative;
    resize: both;
    overflow: auto;
    min-width: 300px;
    min-height: 200px;
}

/* Resize handle indicator for payment info modal */
#paymentInfoModal .modal-content::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 20px;
    height: 20px;
    background: linear-gradient(135deg, transparent 50%, #6c757d 50%);
    cursor: nwse-resize;
    z-index: 1000;
}

/* Resize icon in corner for payment info modal */
#paymentInfoModal .modal-content::before {
    content: '⋰';
    position: absolute;
    bottom: 2px;
    right: 2px;
    font-size: 18px;
    color: #fff;
    pointer-events: none;
    z-index: 1001;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.3);
}

/* Make header draggable cursor for payment info modal */
#paymentInfoModal .modal-header {
    cursor: move;
    user-select: none;
}

#paymentInfoModal .modal-header:active {
    cursor: grabbing;
}

/* Spin animation for loading spinner */
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}

/* Marked payment rows styling */
.payment-mark-checkbox {
    cursor: pointer;
    width: 18px;
    height: 18px;
}
