/* Regal Diaper Invoice System - Custom Styles */

:root {
    --primary-color: #2563EB;
    --secondary-color: #0F172A;
    --success-color: #10B981;
    --warning-color: #F59E0B;
    --danger-color: #EF4444;
    --light-bg: #F8FAFC;
    --border-color: #E2E8F0;
    /* Professional table (header + zebra + grid lines) */
    --table-header-bg: #5a4fd6;
    --table-header-color: #ffffff;
    --table-stripe: #f8f8ff;
    --table-line: #e2e8f0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--light-bg);
    color: var(--secondary-color);
    overflow-x: hidden;
}

/* Sidebar Layout */
.wrapper {
    display: flex;
    width: 100%;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 260px;
    min-width: 260px;
    background: linear-gradient(180deg, var(--primary-color) 0%, #1D4ED8 100%);
    color: white;
    transition: all 0.3s;
    position: fixed;
    height: 100vh;
    left: 0;
    top: 0;
    z-index: 1000;
    overflow-y: auto;
    box-shadow: 2px 0 10px rgba(0, 0, 0, 0.1);
}

.sidebar-header {
    padding: 1.5rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    color: white;
    text-decoration: none;
    font-size: 1.25rem;
    font-weight: 600;
}

.sidebar-brand i {
    font-size: 1.5rem;
    margin-right: 0.5rem;
}

.sidebar-brand:hover {
    color: white;
    opacity: 0.9;
}

.sidebar-toggle {
    color: white;
    font-size: 1.25rem;
    padding: 0.25rem;
}

.sidebar-toggle:hover {
    color: white;
    opacity: 0.8;
}

.sidebar-menu {
    padding: 1rem 0;
    list-style: none;
}

.sidebar-menu li {
    margin: 0.25rem 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.75rem 1.5rem;
    color: rgba(255, 255, 255, 0.9);
    text-decoration: none;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}

.sidebar-link:hover {
    background-color: rgba(255, 255, 255, 0.1);
    color: white;
    border-left-color: white;
}

.sidebar-link.active {
    background-color: rgba(255, 255, 255, 0.15);
    color: white;
    border-left-color: white;
    font-weight: 600;
}

.sidebar-link i {
    width: 24px;
    margin-right: 0.75rem;
    font-size: 1.1rem;
}

.sidebar-divider {
    padding: 0.75rem 1.5rem;
    font-size: 0.75rem;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.6);
    font-weight: 600;
    letter-spacing: 0.5px;
    margin-top: 1rem;
}

.sidebar-footer {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    background-color: rgba(0, 0, 0, 0.1);
}

.sidebar-footer {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.sidebar-user-info {
    display: flex;
    align-items: center;
    padding: 0.75rem 1rem;
    color: rgba(255, 255, 255, 0.9);
    font-size: 0.9rem;
}

.sidebar-user-info i {
    font-size: 1.5rem;
    margin-right: 0.75rem;
}

.sidebar-user-name {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-logout-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    justify-content: flex-start;
    width: 100%;
    min-height: 44px;
    padding: 0.65rem 0.9rem;
    border-radius: 0.5rem;
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.95);
    text-decoration: none;
    border: 1px solid rgba(255, 255, 255, 0.15);
    transition: all 0.2s;
}

.sidebar-logout-btn i {
    font-size: 1rem;
    line-height: 1;
    color: rgba(255, 255, 255, 0.9);
}

.sidebar-logout-btn span {
    line-height: 1;
    color: rgba(255, 255, 255, 0.95);
}

.sidebar-logout-btn:hover {
    background: rgba(0, 255, 55, 0.18);
    color: #fff;
    border-color: rgba(255, 255, 255, 0.35);
}

.sidebar-logout-btn:hover i,
.sidebar-logout-btn:hover span {
    color: #fff;
}

.invoice-details-card .card-header .btn.btn-secondary.btn-sm {
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 0.25rem 0.6rem;
    border-radius: 0.5rem;
}

/* Content Area */
.content {
    flex: 1;
    margin-left: 260px;
    transition: margin-left 0.3s;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    width: calc(100% - 260px);
    max-width: calc(100% - 260px);
    overflow-x: hidden;
    box-sizing: border-box;
}

/* Top Bar */
.topbar {
    background: white;
    padding: 1rem 1.5rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar .sidebar-toggle {
    color: var(--secondary-color);
    font-size: 1.5rem;
    padding: 0.5rem;
    margin-right: 1rem;
}

.topbar .sidebar-toggle:hover {
    color: var(--primary-color);
}

.topbar-title h5 {
    color: var(--secondary-color);
    font-weight: 600;
}

.topbar-user .btn-link {
    color: var(--secondary-color);
    text-decoration: none;
    padding: 0.5rem 1rem;
}

.topbar-user .btn-link:hover {
    color: var(--primary-color);
}

/* App Footer */
.app-footer {
    background: #f1f5f9;
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 1.5rem;
    margin-top: auto;
}

.app-footer-inner {
    font-size: 0.8125rem;
    color: #64748b;
    text-align: center;
}

.app-footer-link {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
}

.app-footer-link:hover {
    color: #1d4ed8;
    text-decoration: underline;
}

.app-footer-sep {
    margin: 0 0.5rem;
    color: #cbd5e1;
}

/* Content Body */
.content-body {
    flex: 1;
    padding: 1.5rem;
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* Create Invoice: reduce left/right padding for wider form */
.content-body:has(#invoiceForm) {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

.content-body .row {
    margin-left: -0.75rem;
    margin-right: -0.75rem;
    width: calc(100% + 1.5rem);
    max-width: 100%;
    box-sizing: border-box;
}

.content-body .row > * {
    padding-left: 0.75rem;
    padding-right: 0.75rem;
    box-sizing: border-box;
}

/* Dashboard - Equal Height Cards */
.content-body .row {
    display: flex;
    flex-wrap: wrap;
}

.content-body .row > [class*="col-"] {
    display: flex;
    flex-direction: column;
}

.content-body .row > [class*="col-"] > .card:not(.stat-card) {
    flex: 1;
    min-height: 450px;
}

/* Dashboard specific - ensure all cards match (except stat cards) */
.content-body .row .card:not(.stat-card) {
    min-height: 450px;
}

@media (max-width: 991px) {
    .content-body .row > [class*="col-"] > .card {
        min-height: auto;
    }
    
    .content-body .row .card {
        min-height: auto;
    }
}

/* Mobile Sidebar */
@media (max-width: 991px) {
    .sidebar {
        margin-left: -260px;
        transition: margin-left 0.3s ease;
    }
    
    .sidebar.active {
        margin-left: 0;
    }
    
    .content {
        margin-left: 0;
        width: 100%;
        max-width: 100%;
    }
    
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        background-color: rgba(0, 0, 0, 0.5);
        z-index: 999;
        transition: opacity 0.3s ease;
    }
    
    .sidebar-overlay.active {
        display: block;
    }
}

/* Desktop - Sidebar always visible */
@media (min-width: 992px) {
    .sidebar {
        margin-left: 0 !important;
    }
    
    .sidebar.active {
        margin-left: 0 !important;
    }
    
    .sidebar-overlay {
        display: none !important;
    }
    
    #sidebarToggle {
        display: none !important;
    }
}

/* Mobile - Show toggle button */
@media (max-width: 991px) {
    #sidebarToggle {
        display: block;
    }
}

/* Navigation */
.navbar-brand {
    font-weight: 600;
    font-size: 1.25rem;
}

/* Cards */
.card {
    border: none;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    margin-bottom: 1.5rem;
    height: 100%;
    display: flex;
    flex-direction: column;
}

.card-body {
    flex: 1;
    display: flex;
    flex-direction: column;
}

/* Compact invoice form card body */
.card-body > form#invoiceForm {
    padding: 0;
}

.card-body:has(#invoiceForm) {
    padding: 0.75rem 0.5rem;
}

.card-header {
    background-color: white;
    border-bottom: 2px solid var(--border-color);
    font-weight: 600;
    padding: 1rem 1.5rem;
}

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

.btn-primary:hover {
    background-color: #1D4ED8;
    border-color: #1D4ED8;
}

/* Tables - Professional header + zebra striping + clear grid lines for easy reading */
.table {
    background-color: white;
    border-collapse: collapse;
    width: 100%;
    border: 1px solid var(--table-line);
}

.table thead th {
    background: var(--table-header-bg);
    color: var(--table-header-color);
    font-weight: 700;
    font-size: 0.9rem;
    text-align: center;
    padding: 1rem 0.75rem;
    border-bottom: 2px solid var(--table-line);
    border-right: 1px solid rgba(255, 255, 255, 0.25);
}

.table thead th:last-child {
    border-right: none;
}

.table thead tr th:first-child {
    border-top-left-radius: 8px;
}

.table thead tr th:last-child {
    border-top-right-radius: 8px;
}

/* Zebra striping: alternate white and pale lavender */
.table:not(.table-borderless) tbody tr:nth-child(even) {
    background-color: #ffffff;
}

.table:not(.table-borderless) tbody tr:nth-child(odd) {
    background-color: var(--table-stripe);
}

.table tbody td {
    padding: 1rem 0.75rem;
    vertical-align: middle;
    color: #333;
    border-bottom: 1px solid var(--table-line);
    border-right: 1px solid var(--table-line);
}

.table tbody td:last-child {
    border-right: none;
}

/* Table footer: same grid lines as body */
.table tfoot td {
    border-bottom: 1px solid var(--table-line);
    border-right: 1px solid var(--table-line);
    padding: 1rem 0.75rem;
    vertical-align: middle;
}

.table tfoot td:last-child {
    border-right: none;
}

.table tfoot tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover {
    background-color: #eef0ff !important;
}

/* table-borderless: no grid lines and no outer border (e.g. key-value layout) */
.table-borderless {
    border: none;
}

.table-borderless tbody td,
.table-borderless tfoot td,
.table-borderless thead th {
    border: none !important;
}

/* table-info: key-value layout with clear row and column lines (e.g. Customer Information) */
.table-info tbody tr:nth-child(odd),
.table-info tbody tr:nth-child(even) {
    background: #fff;
}

.table-info tbody th {
    border-bottom: 1px solid var(--table-line);
    border-right: 1px solid var(--table-line);
    padding: 1rem 0.75rem;
    vertical-align: middle;
    background: #f8fafc;
    font-weight: 600;
    color: var(--secondary-color);
}

.table-info tbody td {
    border-bottom: 1px solid var(--table-line);
    padding: 1rem 0.75rem;
    vertical-align: middle;
}

.table-info tbody tr:last-child th,
.table-info tbody tr:last-child td {
    border-bottom: none;
}

/* Compact tables */
.table.table-sm thead th,
.table.table-sm tbody td,
.table.table-sm tfoot td {
    padding: 0.65rem 0.5rem;
    font-size: 0.875rem;
}

.table.table-sm thead th {
    font-size: 0.8rem;
}

/* Table in card: rounded container with horizontal scroll when needed */
.table-responsive {
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Empty state when table has no data: centered in the box */
.table-empty-state {
    min-height: 220px;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 2rem;
}

.table-empty-state .bi {
    opacity: 0.6;
}

.table-empty-state p {
    font-size: 1rem;
}

/* Recent Invoices card: compact height (no empty space below table), table at top */
.recent-invoices-card {
    min-height: auto !important;
    flex: 0 0 auto !important;
}

.recent-invoices-card .card-body {
    flex: none;
}

.recent-invoices-card .card-body .table-responsive {
    flex: none;
    align-self: flex-start;
}

.recent-invoices-card .recent-invoices-table {
    flex: none;
    table-layout: fixed;
}

/* Recent Invoices: tighter table padding, same header styling as project tables */
.recent-invoices-card .recent-invoices-table thead th,
.recent-invoices-card .recent-invoices-table tbody td {
    padding: 0.5rem 0.65rem;
    font-size: 0.8125rem;
}

.recent-invoices-card .recent-invoices-table thead th {
    font-size: 0.8rem;
    background: var(--table-header-bg);
    color: var(--table-header-color);
    font-weight: 600;
    border-bottom: 2px solid var(--table-line);
    border-right: 1px solid rgba(255, 255, 255, 0.25);
}

.recent-invoices-card .recent-invoices-table thead th:last-child {
    border-right: none;
}

/* Recent Invoices: column widths (Invoice #, Date, Amount, Created By, Actions) */
.recent-invoices-card .recent-invoices-table thead th:nth-child(1),
.recent-invoices-card .recent-invoices-table tbody td:nth-child(1) { width: 16%; text-align: left; }   /* Invoice # */
.recent-invoices-card .recent-invoices-table thead th:nth-child(2),
.recent-invoices-card .recent-invoices-table tbody td:nth-child(2) { width: 12%; text-align: left; }  /* Date */
.recent-invoices-card .recent-invoices-table thead th:nth-child(3),
.recent-invoices-card .recent-invoices-table tbody td:nth-child(3) { width: 18%; text-align: right; }  /* Amount */
.recent-invoices-card .recent-invoices-table thead th:nth-child(4),
.recent-invoices-card .recent-invoices-table tbody td:nth-child(4) { width: 24%; text-align: left; }   /* Created By */
.recent-invoices-card .recent-invoices-table thead th:nth-child(5),
.recent-invoices-card .recent-invoices-table tbody td:nth-child(5) { width: 30%; text-align: center; } /* Actions */

/* Product-wise quantity & sale card: fix flex/layout, column widths, header */
.product-wise-card .card-body .table-responsive {
    flex: none;
    display: block;
}
.product-wise-card .card-body .table,
.product-wise-card .product-wise-table {
    flex: none;
    width: 100%;
    table-layout: fixed;
}
.product-wise-card .product-wise-table thead th {
    background: var(--table-header-bg);
    color: var(--table-header-color);
    font-weight: 600;
    padding: 0.6rem 0.65rem;
    font-size: 0.85rem;
}
.product-wise-card .product-wise-table tbody td,
.product-wise-card .product-wise-table tfoot td {
    padding: 0.6rem 0.65rem;
    vertical-align: middle;
}
.product-wise-card .product-wise-table thead th:nth-child(1),
.product-wise-card .product-wise-table tbody td:nth-child(1) { width: 6%; }   /* # */
.product-wise-card .product-wise-table thead th:nth-child(2),
.product-wise-card .product-wise-table tbody td:nth-child(2) { width: 48%; }   /* Product */
.product-wise-card .product-wise-table thead th:nth-child(3),
.product-wise-card .product-wise-table tbody td:nth-child(3) { width: 18%; }   /* Total qty */
.product-wise-card .product-wise-table thead th:nth-child(4),
.product-wise-card .product-wise-table tbody td:nth-child(4) { width: 28%; }   /* Total amount */

/* Forms */
.form-label {
    font-weight: 500;
    margin-bottom: 0.5rem;
    color: var(--secondary-color);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 0.2rem rgba(37, 99, 235, 0.25);
}

/* Form Container */
.col-lg-12.col-xl-11 {
    max-width: 1400px;
}

@media (min-width: 1400px) {
    .col-lg-12.col-xl-11 {
        max-width: 1600px;
    }
}

/* Invoice Items Table */
.invoice-items-table {
    margin-top: 1rem;
}

.invoice-items-table .form-control {
    border: 1px solid var(--border-color);
}

/* Sticky Save Button (Mobile) */
.sticky-save-btn {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    padding: 1rem;
    box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    z-index: 1000;
}

@media (min-width: 768px) {
    .sticky-save-btn {
        position: static;
        box-shadow: none;
        padding: 0;
    }
}

/* Dashboard Cards */
.stat-card {
    border-left: 4px solid var(--primary-color);
    transition: transform 0.2s;
    min-height: auto !important;
    height: auto !important;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.stat-card .card-body {
    min-height: auto !important;
    height: auto !important;
    flex: none !important;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-color);
}

.stat-card .stat-label {
    color: #64748B;
    font-size: 0.875rem;
    text-transform: uppercase;
    margin-top: 0.5rem;
}

/* Report summary cards: same-size boxes (Financial Summary, Sales report) */
.report-summary-cards .card,
.report-summary-cards .stat-card {
    min-height: 140px !important;
    height: 140px !important;
}
.report-summary-cards .stat-card .card-body {
    min-height: 140px !important;
    flex: 1 1 auto !important;
}
.report-summary-cards .card .card-body {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    min-height: 140px !important;
    padding: 0.75rem !important;
}
/* Slightly smaller value in report cards so long amounts fit in one line where possible */
.report-summary-cards .stat-value,
.report-summary-cards .fs-5.fw-bold {
    font-size: 1.15rem !important;
    line-height: 1.3;
}
.report-summary-cards .stat-label,
.report-summary-cards .small.text-muted {
    font-size: 0.8rem !important;
    margin-top: 0.25rem;
}

/* Summary report: all cards in one row */
.report-summary-row {
    display: flex !important;
    flex-wrap: nowrap !important;
    width: 100%;
    margin-left: 0;
    margin-right: 0;
}

.report-summary-row > .report-summary-col {
    flex: 1 1 0 !important;
    min-width: 0;
    max-width: none;
    padding-left: 0.5rem;
    padding-right: 0.5rem;
}

.report-summary-cards .card .card-body .small.text-muted {
    font-weight: 500;
    margin-bottom: 0.5rem;
    margin-top: 0;
    line-height: 1.2;
    white-space: nowrap;
}

.report-summary-cards .card .card-body .fs-5.fw-bold {
    line-height: 1.2;
    word-break: break-word;
    overflow-wrap: break-word;
}

/* Responsive: allow wrapping on smaller screens */
@media (max-width: 1400px) {
    .report-summary-row {
        flex-wrap: wrap !important;
    }
    .report-summary-row > .report-summary-col {
        flex: 0 0 auto !important;
        width: calc(33.333% - 1rem);
        margin-bottom: 0.5rem;
    }
}

@media (max-width: 992px) {
    .report-summary-row > .report-summary-col {
        width: calc(50% - 1rem);
    }
}

@media (max-width: 768px) {
    .report-summary-row > .report-summary-col {
        width: 100%;
    }
}

/* Summary report table - horizontal layout (one row) */
.report-summary-table {
    width: 100%;
    margin: 0 auto;
    table-layout: fixed;
}

.report-summary-table thead th {
    background-color: var(--table-header-bg);
    color: var(--table-header-color);
    font-weight: 600;
    border: 1px solid var(--table-line);
    padding: 0.75rem 0.5rem;
    font-size: 0.875rem;
    white-space: nowrap;
    vertical-align: middle;
}

.report-summary-table thead th.table-success {
    background-color: #198754;
    color: white;
}

.report-summary-table thead th.table-danger {
    background-color: #dc3545;
    color: white;
}

.report-summary-table tbody td {
    padding: 1rem 0.5rem;
    vertical-align: middle;
    border: 1px solid var(--table-line);
    font-size: 1rem;
    word-break: break-word;
}

.report-summary-table tbody tr:hover {
    background-color: #f0f0f5;
}

.report-summary-table tbody td.table-success {
    background-color: #d1e7dd;
}

.report-summary-table tbody tr:hover td.table-success {
    background-color: #b8dfc8;
}

.report-summary-table tbody td.table-danger {
    background-color: #f8d7da;
}

.report-summary-table tbody tr:hover td.table-danger {
    background-color: #f5c2c7;
}

.report-summary-table tbody td strong {
    font-size: 1.1rem;
    font-weight: 600;
}

/* Responsive: allow horizontal scroll on smaller screens */
@media (max-width: 1200px) {
    .report-summary-table {
        min-width: 900px;
    }
    .report-summary-table thead th,
    .report-summary-table tbody td {
        padding: 0.75rem 0.375rem;
        font-size: 0.9rem;
    }
}

@media (max-width: 768px) {
    .report-summary-table {
        min-width: 800px;
    }
    .report-summary-table thead th {
        font-size: 0.8rem;
        padding: 0.5rem 0.25rem;
    }
    .report-summary-table tbody td {
        font-size: 0.85rem;
        padding: 0.75rem 0.25rem;
    }
    .report-summary-table tbody td strong {
        font-size: 0.95rem;
    }
}

/* Sales report table spacing */
.report-sales-table {
    table-layout: auto;
    min-width: 1000px;
    width: 100%;
    margin: 0;
}
.report-sales-table th,
.report-sales-table td {
    padding-left: 0.5rem;
    padding-right: 0.5rem;
    vertical-align: middle;
    font-size: 0.875rem;
}
.report-sales-table .invoice-col {
    min-width: 100px;
    max-width: 120px;
    white-space: nowrap;
}
.report-sales-table .date-col {
    min-width: 90px;
    max-width: 100px;
    white-space: nowrap;
}
.report-sales-table .customer-col {
    min-width: 150px;
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.report-sales-table .product-col {
    min-width: 140px;
    white-space: normal;
    word-break: break-word;
}
.report-sales-table .qty-col,
.report-sales-table .unit-col {
    min-width: 60px;
    max-width: 80px;
    white-space: nowrap;
}
.report-sales-table .amount-col {
    min-width: 85px;
    max-width: 100px;
    white-space: nowrap;
}
.report-sales-table .actions-col {
    min-width: 60px;
    max-width: 70px;
    white-space: nowrap;
}

/* Sales report table wrapper: only the table scrolls, controls stay fixed */
.report-sales-table-wrapper {
    display: block !important;
    flex: 0 0 auto !important;
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    position: relative;
}

/* DataTables wrapper - controls stay outside, only table area scrolls */
#DataTables_Table_0_wrapper {
    width: 100%;
    position: relative;
    overflow: visible !important;
}

/* DataTables controls rows - keep them fixed, don't scroll */
#DataTables_Table_0_wrapper > .row:first-child {
    position: relative !important;
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding: 0.5rem 0 !important;
    overflow: visible !important;
}

#DataTables_Table_0_wrapper > .row:last-child {
    position: relative !important;
    width: 100% !important;
    margin-left: 0 !important;
    margin-right: 0 !important;
    padding: 0.5rem 0 !important;
    overflow: visible !important;
}

/* Only the table-responsive wrapper inside DataTables should scroll */
#DataTables_Table_0_wrapper .report-sales-table-wrapper {
    overflow-x: auto !important;
    overflow-y: visible !important;
    -webkit-overflow-scrolling: touch;
    margin: 0;
}

/* Ensure DataTables doesn't add its own scroll to wrapper */
#DataTables_Table_0_wrapper .dataTables_scroll {
    overflow: visible !important;
}

#DataTables_Table_0_wrapper .dataTables_scrollHead,
#DataTables_Table_0_wrapper .dataTables_scrollBody {
    overflow: visible !important;
}

/* Ensure controls are positioned correctly */
#DataTables_Table_0_length,
#DataTables_Table_0_filter,
#DataTables_Table_0_info,
#DataTables_Table_0_paginate {
    position: relative !important;
    overflow: visible !important;
}

/* Ensure reports page and card-body don't overflow */
.reports .card-body,
.reports.index .card-body,
div[class*="reports"] .card-body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* Ensure card doesn't overflow */
.card {
    width: 100%;
    max-width: 100%;
    box-sizing: border-box;
}

/* Ensure col-md-12 and other columns don't overflow */
[class*="col-"] {
    box-sizing: border-box;
    max-width: 100%;
}

/* Ensure main content area doesn't overflow */
.main-content {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden;
    box-sizing: border-box;
}

/* Responsive adjustments for sales report table */
@media (max-width: 1200px) {
    .report-sales-table {
        min-width: 900px;
    }
    .report-sales-table .customer-col {
        min-width: 120px;
        max-width: 150px;
    }
    .report-sales-table .amount-col {
        min-width: 75px;
        max-width: 90px;
    }
}

@media (max-width: 768px) {
    .report-sales-table {
        min-width: 800px;
    }
    .report-sales-table th,
    .report-sales-table td {
        padding-left: 0.375rem;
        padding-right: 0.375rem;
        font-size: 0.8125rem;
    }
    .report-sales-table .invoice-col {
        min-width: 90px;
    }
    .report-sales-table .date-col {
        min-width: 80px;
    }
    .report-sales-table .customer-col {
        min-width: 100px;
        max-width: 120px;
    }
    .report-sales-table .qty-col,
    .report-sales-table .unit-col {
        min-width: 50px;
    }
    .report-sales-table .amount-col {
        min-width: 70px;
        max-width: 85px;
    }
}

/* Badges */
.badge {
    padding: 0.5em 0.75em;
    font-weight: 500;
}

/* Bill To | Proforma Details: one row side-by-side like PDF (table = reliable in print) */
.invoice-details-card .invoice-bill-proforma-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
    table-layout: fixed;
}
.invoice-details-card .invoice-bill-proforma-table td {
    vertical-align: top;
    padding: 0 0.75rem 0 0;
}
.invoice-details-card .invoice-bill-proforma-table td:last-child {
    padding: 0 0 0 0.75rem;
}
.invoice-details-card .invoice-bill-to-cell {
    width: 50%;
    text-align: left;
}
.invoice-details-card .invoice-proforma-cell {
    width: 50%;
    text-align: right;
}

/* Invoice PDF Styles – A4 like Download PDF; print matches PDF layout */
@media print {
    @page {
        size: A4;
        margin: 12mm 6mm 15mm 6mm; /* minimal top, left, right – more content on page */
    }
    body {
        background: white;
        margin: 0 !important;
        padding: 0 !important;
    }
    .no-print {
        display: none !important;
    }
    #sidebar,
    .sidebar-overlay,
    .topbar,
    .app-footer {
        display: none !important;
    }
    .content {
        margin-left: 0 !important;
        padding: 0 !important;
    }
    .content-body {
        padding: 0 !important;
    }
    /* Force backgrounds and colors to print (purple header, light blue rows, green badge/amounts) */
    .invoice-details-card {
        box-shadow: none !important;
        border: none !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .invoice-details-card .card-body {
        padding: 0.4rem !important; /* minimal – less padding in print */
    }
    /* Blue line under FROM – matches PDF */
    .invoice-details-card .invoice-company {
        border-bottom: 1px solid #2563eb !important;
    }
    /* Bill To | Proforma Details: table keeps them one row side-by-side in print */
    .invoice-details-card .invoice-bill-proforma-table td {
        padding: 0 0.5rem 0 0 !important;
    }
    .invoice-details-card .invoice-bill-proforma-table td:last-child {
        padding: 0 0 0 0.5rem !important;
    }
    /* Grey line above footer – matches PDF */
    .invoice-details-card .invoice-footer {
        border-top: 1px solid #e2e8f0 !important;
    }
    /* Table: purple header, light blue item rows, light blue Net Amount – all must print */
    .invoice-details-card .table thead th {
        background: #5a4fd6 !important;
        color: #fff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .invoice-details-card .table tbody tr {
        background: #eff6ff !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    .invoice-details-card .invoice-net-amount-row,
    .invoice-details-card .invoice-net-amount-row td {
        background: #e3f2fd !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    /* Status badge and Paid/Balance Due green */
    .invoice-details-card .badge.bg-success,
    .invoice-details-card .text-success {
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }
    /* Payment receipt – print friendly */
    .payment-receipt-card {
        box-shadow: none !important;
        border: 1px solid #dee2e6 !important;
    }
    .payment-receipt-body { padding: 0.5rem 0 !important; }
    .payment-receipt-table th { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

/* Payment receipt (screen) */
.payment-receipt-card { max-width: 480px; }
.payment-receipt-table { font-size: 0.95rem; }
.payment-receipt-table th { width: 38%; }

/* Mobile Responsive */
@media (max-width: 768px) {
    .content-body {
        padding: 1rem;
    }
    
    .card {
        margin-bottom: 1rem;
    }
    
    .table-responsive {
        font-size: 0.875rem;
    }
    
    .btn {
        padding: 0.5rem 1rem;
        font-size: 0.875rem;
    }
    
    .stat-card .stat-value {
        font-size: 1.5rem;
    }
    
    .topbar {
        padding: 0.75rem 1rem;
    }
    
    .topbar-title h5 {
        font-size: 1rem;
    }
}

/* Loading Spinner */
.spinner-border-sm {
    width: 1rem;
    height: 1rem;
}

/* Alert Styles */
.alert {
    border: none;
    border-left: 4px solid;
}

.alert-success {
    border-left-color: var(--success-color);
}

.alert-danger {
    border-left-color: var(--danger-color);
}

.alert-warning {
    border-left-color: var(--warning-color);
}

/* ========== App Notifications (top-right, professional) ========== */
@keyframes toastSlideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.app-notifications {
    position: fixed;
    top: 4rem;
    right: 1.25rem;
    left: auto;
    z-index: 1060;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-width: 380px;
    pointer-events: none;
}
.app-notifications .app-toast {
    pointer-events: auto;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.12), 0 4px 12px rgba(0, 0, 0, 0.08);
    border: 1px solid rgba(0, 0, 0, 0.06);
    border-radius: 10px;
    padding: 0.9rem 1rem 0.9rem 1.1rem;
    border-left-width: 4px;
    font-size: 0.9rem;
    line-height: 1.45;
    animation: toastSlideInRight 0.35s ease-out;
    animation-fill-mode: both;
}
.app-notifications .app-toast.alert-success {
    border-left-color: var(--success-color);
    background: linear-gradient(135deg, #ffffff 0%, #f0fdf4 100%);
}
.app-notifications .app-toast.alert-danger {
    border-left-color: var(--danger-color);
    background: linear-gradient(135deg, #ffffff 0%, #fef2f2 100%);
}
.app-notifications .app-toast .btn-close {
    padding: 0.35rem;
    font-size: 0.75rem;
    opacity: 0.6;
}
.app-notifications .app-toast .btn-close:hover {
    opacity: 1;
}
@media (max-width: 575px) {
    .app-notifications {
        top: 0.75rem;
        right: 0.75rem;
        left: 0.75rem;
        max-width: none;
    }
}

/* Ledger Table */
.ledger-debit {
    color: var(--danger-color);
    font-weight: 600;
}

.ledger-credit {
    color: var(--success-color);
    font-weight: 600;
}

.ledger-balance {
    font-weight: 700;
    color: var(--secondary-color);
}

/* Top Labels (Mobile) */
.top-label {
    font-size: 0.75rem;
    text-transform: uppercase;
    color: #64748B;
    margin-bottom: 0.25rem;
    font-weight: 600;
}

/* Action Buttons */
.action-buttons .btn {
    margin: 0.25rem;
}

/* Chart Container */
.chart-container {
    position: relative;
    height: 300px;
    margin: 1rem 0;
    flex: 1;
    min-height: 250px;
}

@media (max-width: 768px) {
    .chart-container {
        height: 250px;
        min-height: 200px;
    }
}

/* Dashboard Page */
.dashboard-page .row > [class*="col-"] {
    display: flex;
    flex-direction: column;
}

.dashboard-page .row > [class*="col-"] > .card {
    flex: 1 1 auto;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.dashboard-page .card {
    min-height: auto !important;
    height: auto !important;
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    transition: box-shadow 0.2s, transform 0.2s;
}

/* Let h-100 work: override height:auto so paired cards in a row match height */
.dashboard-page .card.h-100 {
    height: 100% !important;
}

.dashboard-page .card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* Dashboard Stat Cards - uniform size and height */
.dashboard-stat-card {
    border: none !important;
    border-left: none !important;
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    width: 100%;
    min-height: 120px;
}

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

.dashboard-stat-card .card-body {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.75rem;
    padding: 1rem 1.25rem !important;
    flex: 1;
    min-height: 120px;
}

.dashboard-stat-card .stat-icon {
    width: 38px;
    height: 38px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.dashboard-stat-card .stat-content {
    flex: 0 1 auto;
    min-width: 0;
    text-align: center;
}

.dashboard-stat-card .stat-value {
    font-size: 1.35rem;
    font-weight: 700;
    line-height: 1.2;
    margin: 0;
    display: block;
    white-space: nowrap;
}

.dashboard-stat-card .stat-label {
    font-size: 0.8rem;
    text-transform: uppercase;
    margin-bottom: 0.35rem;
    letter-spacing: 0.5px;
    margin: 0.25rem 0 0 0;
    opacity: 0.85;
    display: block;
}

.dashboard-stat-sales {
    background: linear-gradient(135deg, #EFF6FF 0%, #DBEAFE 100%);
    color: #1D4ED8;
}

.dashboard-stat-sales .stat-icon {
    background: rgba(37, 99, 235, 0.15);
    color: #2563EB;
}

.dashboard-stat-sales .stat-value { color: #1D4ED8; }

.dashboard-stat-outstanding {
    background: linear-gradient(135deg, #FEF2F2 0%, #FEE2E2 100%);
    color: #B91C1C;
}

.dashboard-stat-outstanding .stat-icon {
    background: rgba(239, 68, 68, 0.15);
    color: #EF4444;
}

.dashboard-stat-outstanding .stat-value { color: #B91C1C; }

.dashboard-stat-customers {
    background: linear-gradient(135deg, #ECFDF5 0%, #D1FAE5 100%);
    color: #047857;
}

.dashboard-stat-customers .stat-icon {
    background: rgba(16, 185, 129, 0.15);
    color: #10B981;
}

.dashboard-stat-customers .stat-value { color: #047857; }

.dashboard-stat-invoices {
    background: linear-gradient(135deg, #FFFBEB 0%, #FEF3C7 100%);
    color: #B45309;
}

.dashboard-stat-invoices .stat-icon {
    background: rgba(245, 158, 11, 0.15);
    color: #F59E0B;
}

.dashboard-stat-invoices .stat-value { color: #B45309; }

.dashboard-stat-recovery {
    background: linear-gradient(135deg, #ECFDF5 0%, #A7F3D0 100%);
    color: #047857;
}
.dashboard-stat-recovery .stat-icon {
    background: rgba(16, 185, 129, 0.2);
    color: #059669;
}
.dashboard-stat-recovery .stat-value { color: #047857; }

.dashboard-stat-returns {
    background: linear-gradient(135deg, #FFF7ED 0%, #FFEDD5 100%);
    color: #C2410C;
}
.dashboard-stat-returns .stat-icon {
    background: rgba(234, 88, 12, 0.15);
    color: #EA580C;
}
.dashboard-stat-returns .stat-value { color: #C2410C; }
.dashboard-stat-returns .stat-sub { color: #9A3412 !important; }
.dashboard-stat-returns .stat-content a { color: #9A3412; }
.dashboard-stat-returns .stat-content a:hover { color: #C2410C; text-decoration: underline; }

/* Dashboard Chart Cards */
.dashboard-chart-card .card-header {
    font-size: 0.95rem;
    padding: 1rem 1.25rem;
}

.dashboard-chart-card .card-header i {
    margin-right: 0.5rem;
    opacity: 0.8;
}

.dashboard-chart-card .card-body {
    padding: 1rem 1.25rem !important;
}

.dashboard-chart-card .chart-container {
    margin: 0;
    flex: none;
}

.dashboard-chart-card .chart-trend {
    height: 300px;
    min-height: 280px;
}

.dashboard-chart-card .chart-bar {
    height: 300px;
    min-height: 280px;
}

.dashboard-chart-card .chart-doughnut {
    height: 300px;
    min-height: 260px;
    max-width: 340px;
    margin-left: auto;
    margin-right: auto;
}

/* Dashboard List Cards - uniform height when in a row (with h-100) */
.dashboard-list-card {
    min-height: 360px;
}

/* Override .dashboard-page .card { min-height: auto !important } so list cards keep 360px */
.dashboard-page .card.dashboard-list-card {
    min-height: 360px !important;
}

.dashboard-list-card .card-header {
    padding: 1rem 1.25rem;
    font-size: 0.95rem;
}

.dashboard-list-card .card-header i {
    margin-right: 0.5rem;
    opacity: 0.8;
}

.dashboard-list-card .card-body {
    padding: 1rem 1.25rem !important;
    flex: 1 1 auto !important;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.dashboard-list-card .card-body .table-responsive,
.dashboard-list-card .card-body .list-group {
    flex: 1 1 auto;
    min-height: 0;
    overflow: auto;
}

.dashboard-list-card .card-body .dashboard-empty {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
}

.dashboard-list-card .list-group-item {
    padding: 0.75rem 0;
}

.dashboard-list-card .table thead th {
    background: var(--table-header-bg);
    color: var(--table-header-color);
    font-size: 0.85rem;
    font-weight: 700;
}

.dashboard-empty {
    padding: 1.5rem;
    text-align: center;
}

@media (max-width: 768px) {
    .dashboard-stat-card .stat-value {
        font-size: 1.15rem;
    }
    
    .dashboard-stat-card,
    .dashboard-stat-card .card-body {
        min-height: 100px;
    }
    
    .dashboard-chart-card .chart-trend,
    .dashboard-chart-card .chart-bar {
        height: 260px;
        min-height: 240px;
    }
    
    .dashboard-chart-card .chart-doughnut {
        height: 260px;
        min-height: 220px;
    }
    
    .dashboard-page .card.dashboard-list-card {
        min-height: 280px !important;
    }
}

/* Dashboard List Groups */
.card-body .list-group {
    flex: 1;
}

.card-body .table-responsive {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.card-body .table {
    flex: 1;
}

/* Invoice view: card and card-body size to content, prevent unnecessary stretch */
.invoice-details-card.card {
    height: auto;
}
.invoice-details-card .card-body {
    flex: none;
    height: auto;
    min-height: 0;
}
.invoice-details-card .proforma-title h4 {
    letter-spacing: 0.08em;
    color: var(--secondary-color);
}
.invoice-details-card .invoice-company {
    border-bottom-color: #2563eb;
}
.invoice-details-card .card-body .table-responsive {
    flex: none;
    display: block;
    height: auto;
}
.invoice-details-card .card-body .table {
    flex: none;
    height: auto;
}
/* Invoice footer: Created by | computer-generated | Generated on – one row, left | center | right (like PDF) */
.invoice-details-card .invoice-footer-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: fixed;
}
.invoice-details-card .invoice-footer-table td {
    vertical-align: top;
    padding: 0.15rem 0.5rem 0 0;
}
.invoice-details-card .invoice-footer-table td:last-child {
    padding: 0.15rem 0 0 0.5rem;
}
.invoice-details-card .invoice-footer-created {
    width: 28%;
    text-align: left;
}
.invoice-details-card .invoice-footer-legal {
    width: 44%;
    text-align: center;
    padding: 0.15rem 0.5rem 0 0.5rem !important;
}
.invoice-details-card .invoice-footer-generated {
    width: 28%;
    text-align: right;
}
.invoice-details-card .table thead th,
.invoice-details-card .table tbody td,
.invoice-details-card .table tfoot td {
    padding: 0.5rem 0.75rem;
}
.invoice-details-card .table tbody tr {
    background: #eff6ff;
}
.invoice-details-card .table tbody td {
    vertical-align: middle;
}

/* Net Amount row: light blue like PDF #e3f2fd */
.invoice-details-card .invoice-net-amount-row,
.invoice-details-card .invoice-net-amount-row td {
    background: #e3f2fd !important;
}

/* Total Products/Quantity row: remove column (vertical) lines from empty cells */
.invoice-details-card .invoice-total-summary-row td.invoice-total-empty {
    border-left: none;
    border-right: none;
}

/* Invoice Items card: use content height, don't stretch */
form#invoiceForm .card.mb-3,
form#returnForm .card.mb-3 {
    height: auto;
    flex: none;
    display: block;
}

form#invoiceForm .card.mb-3 .card-body,
form#returnForm .card.mb-3 .card-body {
    flex: none;
    height: auto;
    display: block;
    min-height: 0;
}

form#invoiceForm .card.mb-3 .table-responsive,
form#returnForm .card.mb-3 .table-responsive {
    flex: none;
    display: block;
}

form#invoiceForm .card.mb-3 .table,
form#returnForm .card.mb-3 .table,
#invoice-items {
    flex: none;
    height: auto;
    table-layout: auto;
}

#invoice-items tbody tr.invoice-item-row {
    height: auto;
}

#invoice-items tbody tr.invoice-item-row td {
    vertical-align: middle !important;
    height: auto;
    padding: 0.5rem;
}

#invoice-items tbody tr.invoice-item-row td .form-control,
#invoice-items tbody tr.invoice-item-row td .form-select {
    height: calc(1.5em + 0.75rem + 2px);
    min-height: 38px;
    width: 100%;
    box-sizing: border-box;
}

/* Compact Invoice Form */
form#invoiceForm,
form#returnForm {
    padding: 0;
}

/* Reduce main card body padding for invoice form */
div.card-body > form#invoiceForm,
div.card-body > form#returnForm {
    padding: 0;
}

form#invoiceForm .row.mb-3,
form#returnForm .row.mb-3 {
    margin-bottom: 1rem !important;
}

/* Customer Select2: full width and min-width for placeholder/selection */
form#invoiceForm .invoice-customer-select-wrap .select2-container {
    width: 100% !important;
    min-width: 280px;
}

form#invoiceForm .card.mb-3,
form#returnForm .card.mb-3 {
    margin-bottom: 1rem !important;
}

form#invoiceForm .card.mb-3 .card-header,
form#returnForm .card.mb-3 .card-header {
    padding: 0.5rem 1rem;
}

form#invoiceForm .card.mb-3 .card-header h6,
form#returnForm .card.mb-3 .card-header h6 {
    font-size: 0.9rem;
    margin-bottom: 0;
}

form#invoiceForm .card.mb-3 .card-body,
form#returnForm .card.mb-3 .card-body {
    padding: 0.75rem 0.5rem;
}

form#invoiceForm .mb-2,
form#returnForm .mb-2 {
    margin-bottom: 0.5rem !important;
}

form#invoiceForm .mb-3,
form#returnForm .mb-3 {
    margin-bottom: 0.75rem !important;
}

form#invoiceForm .form-label,
form#returnForm .form-label {
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

form#invoiceForm textarea[name="notes"],
form#returnForm textarea[name="notes"] {
    min-height: 60px;
    max-height: 80px;
}

form#invoiceForm .card .card-body,
form#returnForm .card .card-body {
    padding: 0.75rem;
}

form#invoiceForm .card .card-body .mb-2,
form#returnForm .card .card-body .mb-2 {
    margin-bottom: 0.5rem !important;
}

form#invoiceForm .card .card-body .mb-0,
form#returnForm .card .card-body .mb-0 {
    margin-bottom: 0;
}

form#invoiceForm #net_amount_display,
form#returnForm #net_amount_display {
    font-size: 1.1rem;
    font-weight: 600;
}

/* Invoice Amount & Payment Summary – POS-style */
.invoice-summary-card {
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
}

form#invoiceForm .invoice-summary-card .card-body,
form#returnForm .invoice-summary-card .card-body {
    padding-left: 0;
    padding-right: 0;
}

.invoice-summary-card .card-header {
    background: linear-gradient(135deg, #F8FAFC 0%, #F1F5F9 100%);
    border-bottom: 1px solid var(--border-color);
    font-weight: 600;
    color: var(--secondary-color);
}

/* Invoice summary – one row, equal-width fields */
.invoice-summary-one-row {
    display: flex;
    flex-wrap: wrap;
    --bs-gutter-x: 0.4rem;
    --bs-gutter-y: 0.4rem;
}

/* Equal flex for all summary columns from md up; min-width so none collapse to 59px */
@media (min-width: 768px) {
    .invoice-summary-one-row .invoice-summary-col {
        flex: 1 1 0;
        min-width: 90px;
    }
}

.invoice-summary-one-row .summary-field {
    min-width: 0;
}

.invoice-summary-one-row .summary-field .form-label {
    font-size: 0.75rem;
    color: #64748B;
    margin-bottom: 0.2rem;
    font-weight: 500;
}

.invoice-summary-one-row .summary-field .form-control,
.invoice-summary-one-row .summary-field .form-select {
    font-size: 0.875rem;
    padding: 0.35rem 0.5rem;
}

.invoice-summary-one-row .summary-field .summary-value {
    background: #F8FAFC;
    font-weight: 500;
}

.invoice-summary-one-row .summary-net-field .form-label {
    font-weight: 700;
    color: var(--secondary-color);
    margin-bottom: 0.2rem;
}

/* Net Amount value: same height/padding as other summary inputs, with highlight */
.invoice-summary-one-row .summary-net-field .summary-net-value {
    display: flex;
    align-items: center;
    padding: 0.35rem 0.5rem;
    min-height: 2rem;
    background: linear-gradient(135deg, #EFF6FF 0%, #DBEAFE 100%);
    border-radius: 6px;
    border: 1px solid rgba(37, 99, 235, 0.2);
}

.summary-net-value,
#net_amount_display {
    font-size: 1.15rem;
    font-weight: 700;
    color: #1D4ED8;
    letter-spacing: 0.02em;
}

/* Remaining Amount: red when paid exceeds net (overpaid) */
#remaining_amount_display.remaining-overpaid {
    color: var(--danger-color) !important;
    font-weight: 600;
}

@media (max-width: 576px) {
    .invoice-summary-one-row .summary-field .form-label {
        font-size: 0.7rem;
    }
    
    .summary-net-value,
    #net_amount_display {
        font-size: 1rem;
    }
}

form#invoiceForm .table thead th,
form#returnForm .table thead th {
    padding: 0.5rem;
    font-size: 0.8rem;
}

form#invoiceForm .table tbody td,
form#returnForm .table tbody td {
    padding: 0.5rem;
}

form#invoiceForm .mt-4,
form#returnForm .mt-4 {
    margin-top: 1rem !important;
}

/* Create Invoice – mobile responsive */
@media (max-width: 991px) {
    form#invoiceForm .card.mb-3 .card-header,
    form#returnForm .card.mb-3 .card-header {
        flex-wrap: wrap;
        gap: 0.5rem;
    }
    
    form#invoiceForm .card.mb-3 .card-header .btn,
    form#returnForm .card.mb-3 .card-header .btn {
        flex: 1 1 auto;
        min-width: 0;
    }
}

@media (max-width: 768px) {
    form#invoiceForm .row.g-2,
    form#returnForm .row.g-2 {
        --bs-gutter-x: 0.5rem;
        --bs-gutter-y: 0.5rem;
    }
    
    form#invoiceForm .invoice-summary-card .summary-field .form-label,
    form#returnForm .invoice-summary-card .summary-field .form-label {
        font-size: 0.7rem;
    }
    
    form#invoiceForm .invoice-summary-card .form-control,
    form#invoiceForm .invoice-summary-card .form-select,
    form#returnForm .invoice-summary-card .form-control,
    form#returnForm .invoice-summary-card .form-select {
        font-size: 0.875rem;
        padding: 0.35rem 0.5rem;
    }
    
    form#invoiceForm #net_amount_display,
    form#returnForm #net_amount_display {
        font-size: 1.1rem;
    }
    
    form#invoiceForm .invoice-form-actions .btn,
    form#returnForm .invoice-form-actions .btn {
        width: 100%;
    }
    
    form#invoiceForm .invoice-form-actions,
    form#returnForm .invoice-form-actions {
        margin-top: 1rem !important;
    }
}

@media (max-width: 576px) {
    form#invoiceForm .invoice-summary-card .summary-field .form-control,
    form#invoiceForm .invoice-summary-card .summary-field .form-select {
        font-size: 0.8125rem;
    }
    
    #invoice-items {
        font-size: 0.8125rem;
        min-width: 480px;
    }
    
    #invoice-items tbody tr.invoice-item-row td {
        padding: 0.35rem;
    }
    
    #invoice-items tbody tr.invoice-item-row td .form-control,
    #invoice-items tbody tr.invoice-item-row td .form-select {
        min-height: 34px;
        height: 34px;
        font-size: 0.8125rem;
    }
    
    form#invoiceForm .card.mb-3 .card-body {
        padding: 0.5rem;
    }
    
    form#invoiceForm .table-responsive {
        margin-left: -0.5rem;
        margin-right: -0.5rem;
        padding-left: 0.5rem;
        padding-right: 0.5rem;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
}

/* Empty State */
.empty-state {
    padding: 4rem 2rem;
    text-align: center;
}

.empty-state i {
    display: block;
    font-size: 3rem;
    color: #ccc;
    margin: 0 auto 1.5rem;
    opacity: 0.6;
}

.empty-state p {
    font-size: 1.1rem;
    color: #64748B;
    margin: 0;
}

/* DataTables Empty State */
.dataTables_empty {
    text-align: center !important;
    padding: 4rem 2rem !important;
    font-size: 1.1rem;
    color: #64748B;
    height: 270px;
}

/* Ensure wide tables inside cards can scroll horizontally */
.table-responsive {
    border-radius: 8px;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* ========== Payments Page ========== */
.payment-page .payment-receive-card {
    border: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border-radius: 12px;
    overflow: hidden;
}

.payment-page .payment-receive-card .card-body {
    padding: 0.75rem 1.25rem 1rem;
}

.payment-page .payment-receive-card .card-body .form-label {
    font-size: 0.875rem;
    margin-bottom: 0.2rem;
}

.payment-page .payment-receive-card .card-body .form-control:not(.form-control-sm),
.payment-page .payment-receive-card .card-body .form-select:not(.form-select-sm) {
    padding: 0.35rem 0.65rem;
    font-size: 0.9rem;
}

/* Select2 customer dropdown: match form-control height (like Payment Amount, Date, etc.) */
.payment-page .payment-receive-card .select2-container .select2-selection--single {
    min-height: 2.25rem !important;
    height: auto !important;
    padding: 0.35rem 2rem 0.35rem 0.65rem !important;
    font-size: 0.9rem;
}

.payment-page .payment-receive-card .select2-container .select2-selection__rendered {
    font-size: 0.9rem;
    line-height: 1.4;
    padding: 0;
}

/* Customer section: more compact like a single input row */
.payment-page .payment-receive-card .payment-section:first-of-type {
    padding: 0.5rem 0;
}

.payment-page .payment-receive-card .payment-section:first-of-type .payment-section-title {
    margin-bottom: 0.35rem;
}

.payment-page .payment-receive-card .card-body .payment-details-grid textarea {
    min-height: 2.25rem;
    resize: vertical;
}

.payment-page .payment-receive-card .card-body form .border-top {
    margin-top: 0.75rem !important;
    padding-top: 0.75rem !important;
}

.payment-page .payment-receive-card .card-header {
    background: linear-gradient(135deg, var(--table-header-bg) 0%, #4c3ec9 100%);
    color: var(--table-header-color);
    padding: 1rem 1.25rem;
    border: none;
}

.payment-page .payment-receive-card .card-header h5 {
    font-weight: 600;
    margin-bottom: 0.35rem;
}

.payment-page .payment-receive-card .card-header .payment-subtitle {
    font-size: 0.9rem;
    opacity: 0.95;
}

.payment-page .payment-steps {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem 1.25rem;
    margin-bottom: 1rem;
    padding: 0.5rem 0.75rem;
    background: var(--table-stripe);
    border-radius: 8px;
    border: 1px solid var(--table-line);
    font-size: 0.85rem;
    color: var(--secondary-color);
}

.payment-page .payment-steps .step {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
}

.payment-page .payment-steps .step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    background: var(--table-header-bg);
    color: var(--table-header-color);
    border-radius: 50%;
    font-size: 0.7rem;
    font-weight: 700;
}

.payment-page .payment-section {
    padding: 0.875rem 0;
    border-bottom: 1px solid var(--border-color);
}

.payment-page .payment-section:last-of-type {
    border-bottom: none;
    padding-bottom: 0;
}

.payment-page .payment-section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--secondary-color);
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.payment-page .payment-section-title i {
    color: var(--table-header-bg);
}

.payment-page #invoices-section,
.payment-page .invoices-display-box {
    background: #fafafa;
    border-radius: 8px;
    padding: 1rem;
    border: 1px solid #e5e7eb;
    margin-bottom: 0.75rem;
}

.payment-page #invoices-section .payment-section-title,
.payment-page .invoices-display-box .payment-section-title {
    margin-bottom: 0.5rem;
}

.payment-page .invoices-display-box > p.text-muted {
    margin-bottom: 0.35rem;
}

.payment-page .invoices-display-box .invoices-empty-msg {
    padding: 1rem 1.25rem;
    text-align: center;
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    font-size: 0.9rem;
    color: #64748b;
}

.payment-page .invoices-display-box .invoices-empty-msg i {
    font-size: 2rem;
    color: #94a3b8;
    display: block;
    margin-bottom: 0.5rem;
}

.payment-page #invoices-section > p.text-muted {
    margin-bottom: 0.35rem;
}

.payment-page #invoices-table {
    font-size: 0.9rem;
    border-radius: 8px;
    overflow: hidden;
}

.payment-page #invoices-table thead th {
    background: var(--table-header-bg);
    color: var(--table-header-color);
    font-weight: 600;
    padding: 0.65rem 0.75rem;
    border-bottom: 2px solid var(--table-line);
    border-right: 1px solid rgba(255, 255, 255, 0.25);
    white-space: nowrap;
}

.payment-page #invoices-table thead th:last-child {
    border-right: none;
}

.payment-page #invoices-table tbody tr:nth-child(even) {
    background: #ffffff;
}

.payment-page #invoices-table tbody tr:nth-child(odd) {
    background: var(--table-stripe);
}

.payment-page #invoices-table tbody tr:hover {
    background: #eef0ff !important;
}

.payment-page #invoices-table tbody td {
    padding: 0.6rem 0.75rem;
    vertical-align: middle;
}

.payment-page #invoices-table .allocate-inp {
    max-width: 100px;
    display: inline-block;
}

.payment-page .btn-pay-full {
    font-size: 0.75rem;
    padding: 0.2rem 0.5rem;
    background: #0d9488;
    color: #fff !important;
    border-radius: 6px;
    text-decoration: none !important;
    white-space: nowrap;
    border: none;
    cursor: pointer;
    font-weight: 500;
}

.payment-page .btn-pay-full:hover {
    background: #0f766e;
    color: #fff !important;
}

.payment-page .alloc-total-box {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    margin-top: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: #ecfdf5;
    border: 1px solid #a7f3d0;
    border-radius: 6px;
    font-size: 0.9rem;
    font-weight: 600;
    color: #047857;
}

.payment-page .alloc-total-box #alloc-total {
    font-size: 1rem;
}

.payment-page #invoices-empty {
    padding: 1rem 1.25rem;
    text-align: center;
    background: #f8fafc;
    border: 1px dashed #cbd5e1;
    border-radius: 8px;
    font-size: 0.9rem;
    color: #64748b;
}

.payment-page #invoices-empty i {
    font-size: 2rem;
    color: #94a3b8;
    display: block;
    margin-bottom: 0.5rem;
}

.payment-page #invoices-loading {
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 0.75rem;
    background: #f8fafc;
    border-radius: 6px;
    border: 1px solid #e2e8f0;
    font-size: 0.9rem;
}

.payment-page #invoices-loading.loading-visible {
    display: flex !important;
}

.payment-page .payment-details-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
}

.payment-page .payment-details-grid .field-notes {
    grid-column: 1 / -1;
}

.payment-page .btn-record-payment {
    padding: 0.65rem 1.5rem;
    font-weight: 600;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(13, 148, 136, 0.3);
}

.payment-page .btn-record-payment:hover {
    box-shadow: 0 4px 8px rgba(13, 148, 136, 0.35);
}

/* Recent Payments card */
.payment-page .payment-recent-card {
    border: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border-radius: 12px;
    overflow: hidden;
}

.payment-page .payment-recent-card .card-header {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: 1rem 1.25rem;
    font-weight: 600;
    color: var(--secondary-color);
}

.payment-page .payment-recent-card .table {
    font-size: 0.9rem;
}

.payment-page .payment-recent-card .table thead th {
    background: var(--table-header-bg);
    color: var(--table-header-color);
    font-weight: 600;
    padding: 0.65rem 0.75rem;
    border-bottom: 2px solid var(--table-line);
    border-right: 1px solid rgba(255, 255, 255, 0.25);
}

.payment-page .payment-recent-card .table thead th:last-child {
    border-right: none;
}

.payment-page .payment-recent-card .table tbody tr:nth-child(even) {
    background: #ffffff;
}

.payment-page .payment-recent-card .table tbody tr:nth-child(odd) {
    background: var(--table-stripe);
}

.payment-page .payment-recent-card .table tbody tr:hover {
    background: #eef0ff !important;
}

/* All Payments list card */
.payment-page .payment-list-card {
    border: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border-radius: 12px;
    overflow: hidden;
}

.payment-page .payment-list-card .card-header {
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: 1rem 1.25rem;
    font-weight: 600;
    color: var(--secondary-color);
}

.payment-page .payment-list-card .card-header .badge.bg-teal {
    background-color: var(--table-header-bg);
    color: var(--table-header-color);
    font-weight: 500;
}

.payment-page .payment-list-table {
    font-size: 0.9rem;
}

.payment-page .payment-list-table thead th {
    background: var(--table-header-bg);
    color: var(--table-header-color);
    font-weight: 600;
    padding: 0.6rem 0.75rem;
    border-bottom: 2px solid var(--table-line);
    border-right: 1px solid rgba(255, 255, 255, 0.25);
    white-space: nowrap;
}

.payment-page .payment-list-table thead th:last-child {
    border-right: none;
}

.payment-page .payment-list-table tbody tr:nth-child(even) {
    background: #ffffff;
}

.payment-page .payment-list-table tbody tr:nth-child(odd) {
    background: var(--table-stripe);
}

.payment-page .payment-list-table tbody tr:hover {
    background: #eef0ff !important;
}

.payment-page .payment-list-table tbody td {
    padding: 0.6rem 0.75rem;
    vertical-align: middle;
}

.payment-page .payment-list-table .invoices-cell,
.payment-page .payment-list-table .notes-cell {
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: inline-block;
}

.payment-page .payment-list-empty {
    text-align: center;
    padding: 2.5rem 1.5rem;
    color: #64748b;
}

.payment-page .payment-list-empty i {
    font-size: 2.5rem;
    color: #94a3b8;
    display: block;
    margin-bottom: 0.75rem;
}

.payment-page .payment-list-empty p {
    font-size: 1rem;
    margin: 0;
}

.payment-page .spin {
    animation: payment-spin 0.8s linear infinite;
}

@keyframes payment-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}
