* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #f8fafc;
    color: #2d3748;
    line-height: 1.6;
    min-height: 100vh;
}

header {
    background: linear-gradient(135deg, #00796B 0%, #004D40 100%);
    color: white;
    padding: 1rem 3rem;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    border-bottom: 3px solid #005b4f;
}

.header-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1400px;
    margin: 0 auto;
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.brand-logo {
    height: 60px;
    width: auto;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}

h1 {
    font-size: 2.2rem;
    font-weight: 300;
    letter-spacing: 0.5px;
}

nav {
    display: flex;
    gap: 0.8rem;
    flex-wrap: wrap;
}

nav button {
    background: rgba(255,255,255,0.12);
    color: white;
    border: 1px solid rgba(255,255,255,0.25);
    padding: 0.7rem 1.4rem;
    border-radius: 25px;
    cursor: pointer;
    transition: all 0.3s ease;
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 0.3px;
}

nav button:hover {
    background: rgba(255,255,255,0.2);
    transform: translateY(-2px);
    box-shadow: 0 6px 12px rgba(0,0,0,0.15);
}

/* Customer Ledger Button Style */
nav button.customer-ledger-btn {
    background: linear-gradient(135deg, #9C27B0 0%, #7B1FA2 100%) !important;
    box-shadow: 0 4px 6px rgba(156,39,176,0.2) !important;
}

nav button.customer-ledger-btn:hover {
    background: linear-gradient(135deg, #7B1FA2 0%, #6A1B9A 100%) !important;
}

main {
    max-width: 1400px;
    margin: 2.5rem auto;
    padding: 0 2rem;
}

section {
    display: none;
    background: white;
    padding: 2.5rem;
    border-radius: 12px;
    box-shadow: 0 8px 25px rgba(0,0,0,0.1);
    margin-bottom: 2.5rem;
    border: 1px solid #e2e8f0;
}

section.active {
    display: block;
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(25px); }
    to { opacity: 1; transform: translateY(0); }
}

h2 {
    color: #00796B;
    margin-bottom: 2rem;
    font-weight: 400;
    border-bottom: 3px solid #E0F2F1;
    padding-bottom: 0.75rem;
    font-size: 1.8rem;
    letter-spacing: 0.5px;
}

button {
    background: linear-gradient(135deg, #00796B 0%, #009688 100%);
    color: white;
    border: none;
    padding: 0.9rem 1.8rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 1rem;
    transition: all 0.3s ease;
    margin: 0.3rem;
    font-weight: 500;
    letter-spacing: 0.3px;
    box-shadow: 0 4px 6px rgba(0,121,107,0.2);
}

button:hover {
    background: linear-gradient(135deg, #00695C 0%, #00897B 100%);
    transform: translateY(-3px);
    box-shadow: 0 8px 15px rgba(0,0,0,0.2);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 2rem;
    margin: 2rem 0;
}

.card {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 6px 15px rgba(0,0,0,0.08);
    text-align: center;
    border-left: 5px solid #00796B;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, #00796B, #009688);
}

.card:hover {
    transform: translateY(-8px);
    box-shadow: 0 12px 25px rgba(0,0,0,0.15);
}

.card span {
    display: block;
    font-size: 2.2rem;
    font-weight: bold;
    color: #00796B;
    margin-top: 0.75rem;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

ul {
    list-style: none;
    margin-top: 1.5rem;
}

li {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    padding: 1.25rem;
    margin: 0.75rem 0;
    border-radius: 8px;
    box-shadow: 0 3px 8px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 4px solid #00796B;
    transition: all 0.3s ease;
}

li:hover {
    transform: translateX(5px);
    box-shadow: 0 5px 12px rgba(0,0,0,0.15);
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.6);
    backdrop-filter: blur(8px);
    /* Flex alignment for centering */
    justify-content: center;
    align-items: center;
}

.modal-content {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    /* Use 'auto' margin to work with flex centering */
    margin: auto;
    padding: 2.5rem;
    border-radius: 15px;
    
    /* UPDATED: Increased width to fit 8 columns comfortably */
    width: 95%; 
    max-width: 1200px; 
    
    position: relative;
    animation: modalSlideIn 0.4s ease-out;
    box-shadow: 0 20px 40px rgba(0,0,0,0.2);
    border: 1px solid #e2e8f0;
    /* Ensure scrolling if screen is too short vertically */
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes modalSlideIn {
    from { transform: translateY(-30px) scale(0.98); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.close {
    color: #94a3b8;
    float: right;
    font-size: 32px;
    font-weight: bold;
    cursor: pointer;
    position: absolute;
    right: 1.5rem;
    top: 1.5rem;
    transition: color 0.3s ease;
}

.close:hover {
    color: #64748b;
}

/* Form Styles */
label {
    display: block;
    margin-bottom: 1.2rem;
    font-weight: 500;
    color: #475569;
    font-size: 1.05rem;
}

input, select, textarea {
    width: 100%;
    padding: 0.9rem;
    border: 2px solid #e2e8f0;
    border-radius: 8px;
    font-size: 1rem;
    margin-top: 0.4rem;
    transition: all 0.3s ease;
    background: #ffffff;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: #00796B;
    box-shadow: 0 0 0 3px rgba(0,121,107,0.1);
    background: #f8fafc;
}

/* Table Styles */
table {
    width: 100%;
    border-collapse: collapse;
    margin: 1.5rem 0;
    background: white;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 6px 15px rgba(0,0,0,0.1);
}

th, td {
    padding: 1.2rem;
    text-align: left;
    border-bottom: 1px solid #f1f5f9;
}

th {
    background: linear-gradient(135deg, #f8fafc 0%, #e2e8f0 100%);
    font-weight: 600;
    color: #1e293b;
    font-size: 1.05rem;
    border-bottom: 2px solid #00796B;
}

tbody tr {
    transition: all 0.3s ease;
}

tbody tr:hover {
    background: #f1f5f9;
    transform: scale(1.01);
}

/* Loading States */
.loading {
    text-align: center;
    padding: 3rem;
    color: #64748b;
    font-size: 1.1rem;
}

.loading::after {
    content: '...';
    animation: dots 1.5s steps(4, end) infinite;
}

@keyframes dots {
    0%, 20% { color: rgba(0,0,0,0); text-shadow: .25em 0 0 rgba(0,0,0,0), .5em 0 0 rgba(0,0,0,0); }
    40% { color: #64748b; text-shadow: .25em 0 0 rgba(0,0,0,0), .5em 0 0 rgba(0,0,0,0); }
    60% { text-shadow: .25em 0 0 #64748b, .5em 0 0 rgba(0,0,0,0); }
    80%, 100% { text-shadow: .25em 0 0 #64748b, .5em 0 0 #64748b; }
}

/* Print Styles */
@media print {
    header, nav, button {
        display: none !important;
    }
    
    section {
        box-shadow: none !important;
        border: none !important;
    }
    
    .no-print {
        display: none !important;
    }
}

/* Utility Classes */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-1 { margin-top: 0.75rem; }
.mt-2 { margin-top: 1.5rem; }
.mb-1 { margin-bottom: 0.75rem; }
.mb-2 { margin-bottom: 1.5rem; }

/* Status Colors */
.status-paid { color: #10b981; font-weight: 600; }
.status-due { color: #ef4444; font-weight: 600; }
.status-pending { color: #f59e0b; font-weight: 600; }

/* Animation for new elements */
.fade-in {
    animation: fadeIn 0.5s ease-in;
}

.slide-in {
    animation: slideIn 0.5s ease-out;
}

@keyframes slideIn {
    from { transform: translateX(-100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* Custom Scrollbar */
::-webkit-scrollbar {
    width: 10px;
}

::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 5px;
}

::-webkit-scrollbar-thumb {
    background: linear-gradient(135deg, #00796B 0%, #009688 100%);
    border-radius: 5px;
}

::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(135deg, #00695C 0%, #00897B 100%);
}

/* Payment row styles for reports */
.payment-row {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%) !important;
    border-left: 4px solid #10b981 !important;
}

.payment-row:hover {
    background: linear-gradient(135deg, #dcfce7 0%, #bbf7d0 100%) !important;
}

.report-table .total-row {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    font-weight: bold;
    border-top: 2px solid #10b981;
}

/* Enhanced button variants */
.delete-btn {
    background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%) !important;
    box-shadow: 0 4px 6px rgba(239,68,68,0.2) !important;
}

.delete-btn:hover {
    background: linear-gradient(135deg, #dc2626 0%, #b91c1c 100%) !important;
}

.edit-btn {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%) !important;
    box-shadow: 0 4px 6px rgba(245,158,11,0.2) !important;
}

.edit-btn:hover {
    background: linear-gradient(135deg, #d97706 0%, #b45309 100%) !important;
}

.payment-btn {
    background: linear-gradient(135deg, #10b981 0%, #059669 100%) !important;
    box-shadow: 0 4px 6px rgba(16,185,129,0.2) !important;
}

.payment-btn:hover {
    background: linear-gradient(135deg, #059669 0%, #047857 100%) !important;
}

/* Search and filter containers */
.search-container {
    background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
    padding: 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    margin: 1.5rem 0;
    border: 1px solid #e2e8f0;
}

.search-fields {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    align-items: end;
}

.search-field label {
    font-weight: 600;
    color: #374151;
    margin-bottom: 0.5rem;
}

/* Summary cards enhancement */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 2rem;
    margin: 2rem 0;
}

.summary-cards .card {
    text-align: center;
    padding: 2rem;
    border-radius: 12px;
    box-shadow: 0 6px 15px rgba(0,0,0,0.1);
    position: relative;
    overflow: hidden;
}

.summary-cards .card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #00796B, #009688);
}

.summary-cards .card h3 {
    margin: 0 0 1rem 0;
    font-size: 1.1rem;
    color: #374151;
    font-weight: 600;
}

.summary-cards .card .amount {
    font-size: 2.5rem;
    font-weight: bold;
    color: #00796B;
    margin: 1rem 0;
    text-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.summary-cards .card .date {
    font-size: 0.95rem;
    color: #6b7280;
    font-style: italic;
}

/* Action buttons in tables */
.action-buttons {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: nowrap;
}

.action-buttons button {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    margin: 0;
    min-width: 80px;
}

/* Enhanced hover effects for interactive elements */
button, .card, li, tbody tr {
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Focus states for accessibility */
button:focus, input:focus, select:focus, textarea:focus {
    outline: 2px solid #00796B;
    outline-offset: 2px;
}

/* Custom selection color */
::selection {
    background: rgba(0,121,107,0.2);
    color: inherit;
}

::-moz-selection {
    background: rgba(0,121,107,0.2);
    color: inherit;
}

/* Customer List Styling */
#customerList li {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 15px;
    margin: 10px 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border-left: 4px solid #00796B;
    transition: all 0.3s ease;
}

#customerList li:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

#customerList li > div:first-child {
    flex: 1;
    min-width: 0;
    margin-right: 15px;
    cursor: pointer;
}

#customerList li > div:first-child:hover {
    color: #00796B;
}

#customerList li strong {
    display: block;
    margin-bottom: 5px;
    color: #333;
    font-size: 1.1em;
    word-wrap: break-word;
}

#customerList li span {
    color: #666;
    font-size: 0.9em;
    line-height: 1.4;
}

#customerList .action-buttons {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

#customerList .empty-state, 
#customerList .error-state, 
#customerList .loading-state {
    text-align: center;
    padding: 40px;
    margin: 20px 0;
    border-radius: 8px;
}

#customerList .empty-state {
    color: #666;
    background: #f5f5f5;
    border: 2px dashed #ddd;
}

#customerList .error-state {
    color: #d32f2f;
    background: #ffebee;
    border-left: 4px solid #f44336;
}

#customerList .loading-state {
    color: #666;
    font-style: italic;
}

/* Supplier List Styling */
#supplierList li {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 15px;
    margin: 10px 0;
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    border-left: 4px solid #00796B;
    transition: all 0.3s ease;
}

#supplierList li:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0,0,0,0.15);
}

#supplierList li > div:first-child {
    flex: 1;
    min-width: 0;
    margin-right: 15px;
}

#supplierList li strong {
    display: block;
    margin-bottom: 5px;
    color: #333;
    font-size: 1.1em;
    word-wrap: break-word;
}

#supplierList li span {
    color: #666;
    font-size: 0.9em;
    line-height: 1.4;
}

#supplierList .action-buttons {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

#supplierList .empty-state, 
#supplierList .error-state, 
#supplierList .loading-state {
    text-align: center;
    padding: 40px;
    margin: 20px 0;
    border-radius: 8px;
}

#supplierList .empty-state {
    color: #666;
    background: #f5f5f5;
    border: 2px dashed #ddd;
}

#supplierList .error-state {
    color: #d32f2f;
    background: #ffebee;
    border-left: 4px solid #f44336;
}

#supplierList .loading-state {
    color: #666;
    font-style: italic;
}

/* Products Table Styling */
#productsTable {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
    background: white;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#productsTable th,
#productsTable td {
    border: 1px solid #ddd;
    padding: 12px;
    text-align: left;
}

#productsTable th {
    background: #f5f5f5;
    font-weight: bold;
    color: #333;
}

#productsTable tbody tr:hover {
    background: #f8f9fa;
}

#productsTable .action-buttons {
    display: flex;
    gap: 5px;
    justify-content: center;
    flex-wrap: wrap;
}

/* Responsive table */
@media (max-width: 768px) {
    #productsTable {
        font-size: 0.9rem;
    }
    
    #productsTable th,
    #productsTable td {
        padding: 8px;
    }
    
    #productsTable .action-buttons {
        flex-direction: column;
    }
}

/* Multi-product sale form styles - COMPACT VERSION */
.product-items-container {
    margin: 15px 0;
    border: 1px solid #e0e0e0;
    border-radius: 5px;
    padding: 10px;
    background: #f9f9f9;
    max-width: 100%;
    overflow-x: auto;
}

/* FIXED: Grid columns now have 8 values to match the 8 inputs/headers */
.product-item {
    display: grid;
    /* Product | Length | Width | Items | SFT | Rate | Amount | Action */
    grid-template-columns: 220px 90px 90px 70px 90px 90px 110px 50px;
    gap: 8px;
    margin-bottom: 10px;
    padding: 8px;
    background: white;
    border-radius: 4px;
    border: 1px solid #ddd;
    align-items: center;
    min-width: 900px; /* Ensure horizontal scroll on very small screens */
}

/* FIXED: Grid columns for header match the items */
.product-item-header {
    display: grid;
    /* Product | Length | Width | Items | SFT | Rate | Amount | Action */
    grid-template-columns: 220px 90px 90px 70px 90px 90px 110px 50px;
    gap: 8px;
    margin-bottom: 5px;
    padding: 8px;
    font-weight: bold;
    color: #333;
    font-size: 12px;
    min-width: 900px;
    background: #e8f5e8;
    border-radius: 4px;
}

.product-item-header span {
    text-align: center;
}

.product-item select,
.product-item input {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 13px;
    width: 100%;
    box-sizing: border-box;
}

.product-item .size-inputs {
    display: flex;
    gap: 8px;
    align-items: center;
    justify-content: space-between;
}

.product-item .size-inputs input {
    width: 55px;
    text-align: center;
    font-size: 13px;
    padding: 6px;
}

.product-item .size-inputs span {
    font-size: 12px;
    color: #666;
    font-weight: bold;
}

.product-item .calculated-field {
    background: #f5f5f5;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    text-align: center;
    font-weight: bold;
    font-size: 13px;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 36px;
}

.product-item .remove-product {
    background: #ff4444;
    color: white;
    border: none;
    padding: 8px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.product-item .remove-product:hover {
    background: #cc0000;
}

.add-product-btn {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 10px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    margin-bottom: 10px;
}

.add-product-btn:hover {
    background: #45a049;
}

.total-summary {
    background: #e8f5e8;
    padding: 15px;
    border-radius: 5px;
    margin: 15px 0;
    border-left: 4px solid #4CAF50;
}

.total-summary h4 {
    margin: 0 0 10px 0;
    color: #2E7D32;
    font-size: 14px;
}

.total-summary .amount {
    font-size: 16px;
    font-weight: bold;
    color: #1B5E20;
}

/* Compact modal form layout */
.compact-form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
    margin-bottom: 15px;
}

.compact-form-row label {
    margin-bottom: 0;
}

@media (max-width: 768px) {
    .compact-form-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }
}

/* Better input focus styles */
.product-item input:focus,
.product-item select:focus {
    border-color: #4CAF50;
    outline: none;
    box-shadow: 0 0 5px rgba(76, 175, 80, 0.3);
}

/* Size inputs specific styling */
.product-item .size-inputs {
    background: #f8f9fa;
    padding: 5px;
    border-radius: 4px;
    border: 1px solid #e9ecef;
}

.product-item .size-inputs input {
    background: white;
    border: 1px solid #ced4da;
    font-weight: 500;
}

.product-item .size-inputs input:focus {
    border-color: #4CAF50;
    background: #f8fff8;
}

/* Sale Modal Specific Styles - REMOVED redundant grid definitions here to avoid conflicts */
/* The main product-item and product-item-header classes above handle this now */

/* Manual Invoice Section */
.manual-invoice-section {
    background: #fff3cd;
    padding: 15px;
    border-radius: 5px;
    border-left: 4px solid #ffc107;
    margin-bottom: 15px;
}

.manual-invoice-section label {
    display: block;
    margin-bottom: 10px;
    font-weight: bold;
    color: #856404;
}

.manual-invoice-section input[type="checkbox"] {
    margin-right: 8px;
}

.manual-invoice-field {
    margin-top: 10px;
    padding: 10px;
    background: #fff;
    border-radius: 4px;
    border: 1px solid #ffeaa7;
}

.manual-invoice-field small {
    color: #666;
    font-style: italic;
    display: block;
    margin-top: 5px;
}

/* Responsive adjustments for sale modal */
@media (max-width: 1200px) {
    .product-item-header,
    .product-item {
        /* Slightly smaller but still 8 columns */
        grid-template-columns: 180px 80px 80px 60px 80px 80px 100px 50px;
        gap: 6px;
        min-width: 800px;
    }
}

@media (max-width: 768px) {
    #modalForm .compact-form-row {
        grid-template-columns: 1fr;
        gap: 10px;
    }
    
    #modalForm .product-items-container {
        overflow-x: auto;
    }
    
    .product-item-header,
    .product-item {
        /* Same as 1200px but container scrolls */
        grid-template-columns: 180px 80px 80px 60px 80px 80px 100px 50px;
        min-width: 800px;
    }
}

/* Due Receive History Styles */
#historyPagination {
    margin-top: 20px;
    text-align: center;
}

#historyPagination button {
    padding: 8px 16px;
    margin: 0 5px;
    border: 1px solid #ddd;
    background: white;
    cursor: pointer;
    border-radius: 4px;
}

#historyPagination button:disabled {
    background: #f5f5f5;
    color: #999;
    cursor: not-allowed;
}

#historyPagination button:hover:not(:disabled) {
    background: #00796B;
    color: white;
}

.payment-row {
    background-color: #e8f5e8 !important;
    border-left: 4px solid #4CAF50 !important;
}

.payment-row:hover {
    background-color: #d4edda !important;
}

.opening-row {
    background-color: #fff3cd !important;
    border-left: 4px solid #ffc107 !important;
}