/* ===== სტილები sales_history.php ფაილისთვის ===== */

/* ===== მთავარი ცხრილის სექცია - გასწორებული ===== */
.table-section {
    background: white;
    border-radius: 15px;
    padding: 30px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
    margin-bottom: 30px;
    width: 100%;
    max-width: 100%;
    overflow-x: visible !important; /* მნიშვნელოვანი: გამორთე სქროლი */
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 25px;
    padding-bottom: 20px;
    border-bottom: 2px solid #f0f0f0;
    flex-wrap: wrap;
    gap: 20px;
    width: 100%;
}

.table-header h2 {
    margin: 0;
    color: #333;
    font-size: 1.8em;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 15px;
    white-space: nowrap; /* სათაური არ დაიშლება */
    overflow: hidden;
    text-overflow: ellipsis;
}

.table-header h2 .icon {
    color: #007bff;
    font-size: 1.3em;
}

.table-actions {
    display: flex;
    gap: 15px;
    align-items: center;
    flex-wrap: wrap;
}

.bulk-actions {
    display: flex;
    gap: 10px;
    align-items: center;
    background: #f8f9fa;
    padding: 10px 15px;
    border-radius: 10px;
    margin-bottom: 15px;
    width: 100%;
    flex-wrap: wrap;
}

.selected-count {
    font-weight: 600;
    color: #007bff;
    margin-right: 10px;
}

/* ===== ცხრილის მთავარი კონტეინერი - გასწორებული ===== */
.table-container {
    background: white;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.05);
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    overflow-x: visible !important; /* მნიშვნელოვანი: გამორთე სქროლი */
}

/* ===== DataTables ცხრილის გასწორება ===== */
#salesHistoryTable_wrapper {
    width: 100% !important;
    max-width: 100% !important;
    overflow-x: visible !important;
    margin-top: 10px;
}

#salesHistoryTable {
    width: 100% !important;
    max-width: 100% !important;
    border-collapse: collapse;
    table-layout: fixed; /* ფიქსირებული განლაგება */
    word-wrap: break-word; /* სიტყვების გატეხვა */
}

/* თავსართის სტილები */
#salesHistoryTable thead {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

#salesHistoryTable thead th {
    padding: 15px 12px;
    text-align: left;
    font-weight: 600;
    color: #495057;
    border-bottom: 3px solid #dee2e6;
    white-space: nowrap; /* თავსართები არ დაიშლება */
    position: relative;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Checkbox სვეტი */
#salesHistoryTable th.checkbox-column,
#salesHistoryTable td.checkbox-column {
    width: 50px !important;
    min-width: 50px !important;
    max-width: 50px !important;
    text-align: center;
    padding: 15px 5px !important;
}

/* სვეტების ფიქსირებული სიგანე */
#salesHistoryTable th:nth-child(2), /* ID */
#salesHistoryTable td:nth-child(2) {
    width: 80px;
    min-width: 80px;
    max-width: 80px;
}

#salesHistoryTable th:nth-child(3), /* თარიღი */
#salesHistoryTable td:nth-child(3) {
    width: 150px;
    min-width: 150px;
    max-width: 150px;
}

#salesHistoryTable th:nth-child(4), /* კერძი */
#salesHistoryTable td:nth-child(4) {
    width: 200px;
    min-width: 200px;
    max-width: 200px;
    word-break: break-word;
}

#salesHistoryTable th:nth-child(5), /* რაოდენობა */
#salesHistoryTable td:nth-child(5) {
    width: 80px;
    min-width: 80px;
    max-width: 80px;
    text-align: center;
}

/* ფინანსური სვეტები - გაანაწილე ნაწილებად */
#salesHistoryTable th:nth-child(6), /* თვითღირ. (დღგ-თი) */
#salesHistoryTable td:nth-child(6),
#salesHistoryTable th:nth-child(7), /* თვითღირ. (Ex.VAT) */
#salesHistoryTable td:nth-child(7) {
    width: 130px;
    min-width: 130px;
    max-width: 130px;
    text-align: right;
}

#salesHistoryTable th:nth-child(8), /* გაყიდვა (დღგ-თი) */
#salesHistoryTable td:nth-child(8),
#salesHistoryTable th:nth-child(9), /* გაყიდვა (Ex.VAT) */
#salesHistoryTable td:nth-child(9) {
    width: 130px;
    min-width: 130px;
    max-width: 130px;
    text-align: right;
}

#salesHistoryTable th:nth-child(10), /* დღგ */
#salesHistoryTable td:nth-child(10),
#salesHistoryTable th:nth-child(11), /* მოგება */
#salesHistoryTable td:nth-child(11) {
    width: 110px;
    min-width: 110px;
    max-width: 110px;
    text-align: right;
}

#salesHistoryTable th:nth-child(12), /* მარჟა % */
#salesHistoryTable td:nth-child(12) {
    width: 100px;
    min-width: 100px;
    max-width: 100px;
    text-align: center;
}

#salesHistoryTable th:nth-child(13), /* მოქმედება */
#salesHistoryTable td:nth-child(13) {
    width: 100px;
    min-width: 100px;
    max-width: 100px;
    text-align: center;
}

/* მონაცემთა უჯრები */
#salesHistoryTable tbody td {
    padding: 12px 10px;
    border-bottom: 1px solid #eee;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* მწკრივის ეფექტები */
#salesHistoryTable tbody tr:hover {
    background-color: #f8f9fa;
}

/* ფინანსური მონაცემების სტილები */
.text-cost {
    color: #dc3545 !important;
    font-weight: 600 !important;
}

.text-revenue {
    color: #17a2b8 !important;
    font-weight: 600 !important;
}

.text-vat {
    color: #6f42c1 !important;
    font-weight: 600 !important;
}

.text-profit {
    color: #28a745 !important;
    font-weight: 700 !important;
}

.text-loss {
    color: #dc3545 !important;
    font-weight: 700 !important;
}

/* მარჟის ბეიჯები */
.margin-badge {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.margin-badge.high {
    background: rgba(40, 167, 69, 0.15);
    color: #28a745;
}

.margin-badge.medium {
    background: rgba(255, 193, 7, 0.15);
    color: #e0a800;
}

.margin-badge.low {
    background: rgba(220, 53, 69, 0.15);
    color: #dc3545;
}

/* ===== რესპონსიული დიზაინი ===== */

/* ტაბლეტები (992px-მდე) */
@media (max-width: 992px) {
    .table-section {
        padding: 20px;
    }
    
    .table-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 15px;
    }
    
    .table-header h2 {
        font-size: 1.6em;
        white-space: normal; /* დაშვებულია ხაზების გატეხვა */
    }
    
    /* შეამცირე სვეტების სიგანე */
    #salesHistoryTable th:nth-child(4), /* კერძი */
    #salesHistoryTable td:nth-child(4) {
        width: 180px;
        min-width: 180px;
        max-width: 180px;
    }
    
    #salesHistoryTable th:nth-child(6),
    #salesHistoryTable td:nth-child(6),
    #salesHistoryTable th:nth-child(7),
    #salesHistoryTable td:nth-child(7),
    #salesHistoryTable th:nth-child(8),
    #salesHistoryTable td:nth-child(8),
    #salesHistoryTable th:nth-child(9),
    #salesHistoryTable td:nth-child(9) {
        width: 110px;
        min-width: 110px;
        max-width: 110px;
    }
}

/* დიდი მობილურები (768px-მდე) */
@media (max-width: 768px) {
    .table-section {
        padding: 15px;
        border-radius: 10px;
    }
    
    #salesHistoryTable_wrapper {
        overflow-x: auto; /* დაუბრუნე სქროლი ძალიან პატარა ეკრანებისთვის */
    }
    
    #salesHistoryTable {
        min-width: 1000px; /* მინიმალური სიგანე სქროლისთვის */
        font-size: 13px;
    }
    
    /* შეამცირე ფონტები და padding */
    #salesHistoryTable th,
    #salesHistoryTable td {
        padding: 8px 6px;
        font-size: 12px;
    }
    
    .bulk-actions {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    
    /* დამალე ზედმეტი სვეტები */
    #salesHistoryTable th:nth-child(10), /* დღგ */
    #salesHistoryTable td:nth-child(10) {
        display: none;
    }
}

/* პატარა მობილურები (576px-მდე) */
@media (max-width: 576px) {
    .table-section {
        padding: 10px;
        margin: 10px 0;
    }
    
    .table-header h2 {
        font-size: 1.4em;
    }
    
    #salesHistoryTable {
        min-width: 800px; /* კიდევ უფრო მცირე მინიმალური სიგანე */
        font-size: 12px;
    }
    
    /* დამალე მეტი სვეტები */
    #salesHistoryTable th:nth-child(6), /* თვითღირ. (დღგ-თი) */
    #salesHistoryTable td:nth-child(6),
    #salesHistoryTable th:nth-child(8), /* გაყიდვა (დღგ-თი) */
    #salesHistoryTable td:nth-child(8) {
        display: none;
    }
    
    /* გაზარდე მნიშვნელოვანი სვეტები */
    #salesHistoryTable th:nth-child(4), /* კერძი */
    #salesHistoryTable td:nth-child(4) {
        width: 150px;
        min-width: 150px;
        max-width: 150px;
    }
    
    #salesHistoryTable th:nth-child(11), /* მოგება */
    #salesHistoryTable td:nth-child(11) {
        width: 120px;
        min-width: 120px;
        max-width: 120px;
    }
}

/* ძალიან პატარა ეკრანები (480px-მდე) */
@media (max-width: 480px) {
    .table-container {
        padding: 15px;
    }
    
    #salesHistoryTable {
        min-width: 700px;
    }
    
    /* დამალე კიდევ მეტი სვეტები */
    #salesHistoryTable th:nth-child(7), /* თვითღირ. (Ex.VAT) */
    #salesHistoryTable td:nth-child(7),
    #salesHistoryTable th:nth-child(9), /* გაყიდვა (Ex.VAT) */
    #salesHistoryTable td:nth-child(9) {
        display: none;
    }
    
    /* ძირითადი სვეტების გაზრდა */
    #salesHistoryTable th:nth-child(2), /* ID */
    #salesHistoryTable td:nth-child(2) {
        width: 60px;
        min-width: 60px;
        max-width: 60px;
    }
    
    #salesHistoryTable th:nth-child(3), /* თარიღი */
    #salesHistoryTable td:nth-child(3) {
        width: 120px;
        min-width: 120px;
        max-width: 120px;
    }
}

/* ===== დამატებითი გასწორებები ===== */

/* Checkbox ელემენტების სტილი */
#salesHistoryTable input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
    margin: 0;
    accent-color: #007bff; /* თანამედროვე ბრაუზერები */
}

/* ერთეულის ფასის სტილი */
.per-unit {
    display: block;
    font-size: 11px;
    color: #888;
    margin-top: 2px;
}

/* ქმედების ღილაკები */
.action-buttons {
    display: flex;
    gap: 5px;
    justify-content: center;
}

/* DataTables პაგინაცია */
.dataTables_paginate {
    margin-top: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 5px;
    flex-wrap: wrap;
}

/* ფუტერის სტილი */
#salesHistoryTable tfoot tr {
    background: #f8f9fa !important;
    font-weight: bold;
    border-top: 3px solid #ddd !important;
}

#salesHistoryTable tfoot td {
    padding: 12px !important;
    font-size: 14px !important;
}

/* სათაური კონკრეტულად "📈 გაყიდვების ისტორია"-სთვის */
h2:has(.icon:contains("📈")) {
    color: #007bff;
    font-size: 1.8em;
    margin-bottom: 20px;
    padding-bottom: 10px;
    border-bottom: 3px solid #007bff;
    display: flex;
    align-items: center;
    gap: 10px;
}

/* უზრუნველყავი, რომ მთელი გვერდი იყოს სრული სიგანის */
body > .container {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 auto !important;
    padding: 0 10px !important;
}

/* თუ გამოიყენებთ .sales-history-page კლასი */
.sales-history-page .container,
.sales-history-page .table-container,
.sales-history-page .table-section {
    width: 100% !important;
    max-width: 100% !important;
    margin: 0 !important;
    padding: 0 10px !important;
}