/* =====================================================
   GLOBAL
   ===================================================== */
body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: #f4f6f9;
    color: #222;
}

.right {
    text-align: right;
}

input,
select,
textarea {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 5px;
    box-sizing: border-box;
    font-family: inherit;
    font-size: 14px;
}

textarea {
    resize: vertical;
}
input:required {
    border-left: 3px solid #dc3545;
}

input:invalid {
    border-color: #dc3545;
}

input:valid {
    border-color: #28a745;
}
button:disabled,
.btn:disabled {
    background: #c7c7c7 !important;
    color: #777 !important;
    cursor: not-allowed !important;
    opacity: 0.55;
    box-shadow: none !important;
    border-color: #bdbdbd !important;
}

button:disabled:hover,
.btn:disabled:hover {
    background: #c7c7c7 !important;
}

th.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

th.sortable:hover {
    background: #e9ecef;
}

.sort-arrow {
    margin-left: 4px;
}
.invoice-filter-row {
    margin-bottom: 15px;
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}
button:disabled,
.btn:disabled {
    background: #c7c7c7 !important;
    color: #777 !important;
    cursor: not-allowed !important;
    opacity: 0.55;
    box-shadow: none !important;
    border-color: #bdbdbd !important;
}

button:disabled:hover,
.btn:disabled:hover {
    background: #c7c7c7 !important;
}
.invoice-status-print {
    margin-top: 10px;
    font-weight: bold;
    font-size: 14px;
}

.invoice-status-print.paid {
    color: #28a745;
}

.invoice-status-print.unpaid {
    color: #dc3545;
}
.print-view {
    position: relative;
}

.paid-stamp {
    display: none;
    position: absolute;
    top: 40%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-20deg);
    font-size: 72px;
    font-weight: bold;
    color: rgba(40, 167, 69, 0.18);
    border: 6px solid rgba(40, 167, 69, 0.18);
    padding: 10px 30px;
    border-radius: 10px;
    text-transform: uppercase;
    letter-spacing: 6px;
    z-index: 999;
    pointer-events: none;
    white-space: nowrap;
}

@media print {
    .paid-stamp {
        display: block;
    }
}
/* =====================================================
   TOPBAR
   ===================================================== */
.topbar {
    height: 60px;
    background: #2f4050;
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
}

.topbar h1,
.topbar h2 {
    margin: 0;
    font-size: 20px;
}

.user {
    font-size: 14px;
}

/* =====================================================
   SIDEBAR
   ===================================================== */
.sidebar {
    width: 220px;
    height: 100vh;
    background: #2f4050;
    color: white;
    position: fixed;
    top: 60px;
    left: 0;
    padding-top: 20px;
    overflow-y: auto;
}

.sidebar a {
    display: block;
    color: white;
    padding: 12px 20px;
    text-decoration: none;
}

.sidebar a:hover,
.sidebar a.active {
    background: #1c2733;
    border-left: 4px solid #3c8dbc;
    padding-left: 16px;
}

/* =====================================================
   LAYOUT
   ===================================================== */
.main {
    margin-left: 220px;
    margin-top: 60px;
    padding: 20px;
    max-width: 1200px;
}

/* =====================================================
   BUTTONS
   ===================================================== */
.btn {
    background: #3c8dbc;
    color: white;
    border: none;
    padding: 8px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
}

.btn:hover {
    background: #337ab7;
}

.remove-row-btn {
    background: #dc3545;
    color: white;
    border: none;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 5px;
    font-size: 12px;
}

.remove-row-btn:hover {
    background: #b52a37;
}

/* =====================================================
   STATUS
   ===================================================== */
.status {
    display: inline-block;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: bold;
}

.status.paid {
    background: #28a745;
    color: white;
}

.status.unpaid {
    background: #dc3545;
    color: white;
}

.overdue {
    color: #dc3545;
    font-weight: bold;
}

.overdue-row {
    background: #fff5f5;
}

/* =====================================================
   CARDS
   ===================================================== */
.cards {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.card {
    flex: 1;
    min-width: 200px;
    background: white;
    padding: 20px;
    border-radius: 10px;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.card h3 {
    margin: 0;
    color: #777;
}

.card h1 {
    margin: 10px 0 0;
}

/* =====================================================
   FORMS
   ===================================================== */
.form-grid {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 10px 20px;
    max-width: 1000px;
    margin-bottom: 30px;
}

.form-grid label {
    align-self: center;
    font-weight: bold;
}

.form-grid input,
.form-grid select,
.form-grid textarea {
    width: 100%;
}

.row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.row input {
    width: 120px;
}

.row .desc {
    width: 250px;
}

.row .sum {
    background: #eee;
}

/* =====================================================
   GENERAL TABLES
   ===================================================== */
table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    margin-top: 20px;
}

th,
td {
    padding: 12px;
    border-bottom: 1px solid #ddd;
    text-align: left;
}

th {
    background: #f2f2f2;
}

tr:hover {
    background: #f9f9f9;
}

/* =====================================================
   PREVIEW
   ===================================================== */
#preview {
    margin-top: 20px;
}

#preview table {
    margin-top: 10px;
}

/* =====================================================
   INVOICE SCREEN
   ===================================================== */
.invoice-card {
    background: white;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}

.invoice-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 25px;
}

.invoice-header h1 {
    margin: 0;
    font-size: 28px;
    color: #2f4050;
}

.invoice-number,
.invoice-date {
    margin-top: 6px;
    color: #666;
    font-size: 14px;
}

.invoice-status {
    text-align: right;
}

.invoice-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 25px;
}

.invoice-box {
    background: #f9fafc;
    border: 1px solid #e3e7ee;
    border-radius: 8px;
    padding: 15px;
}

.invoice-box h3 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 16px;
    color: #2f4050;
}

.invoice-box p {
    margin: 0;
    line-height: 1.6;
}

.invoice-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    background: white;
}

.invoice-table th,
.invoice-table td {
    padding: 12px;
    border-bottom: 1px solid #ddd;
}

.invoice-table th {
    background: #f2f2f2;
    text-align: left;
}

.invoice-table .right {
    text-align: right;
}

.invoice-totals {
    margin-top: 20px;
    max-width: 320px;
    margin-left: auto;
    background: #f9fafc;
    border: 1px solid #e3e7ee;
    border-radius: 8px;
    padding: 15px;
}

.total-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}

.total-final {
    font-size: 18px;
    font-weight: bold;
    border-top: 1px solid #ddd;
    padding-top: 10px;
    margin-top: 10px;
}

/* =====================================================
   PRINT / SCREEN TOGGLE
   ===================================================== */
.print-view {
    display: none;
}

.screen-view {
    display: block;
}

/* =====================================================
   PRINT INVOICE
   ===================================================== */
@media print {
    body {
        background: white !important;
        margin: 0 !important;
        padding: 0 !important;
        font-size: 11px !important;
        color: #000 !important;
    }

    .topbar,
    .sidebar,
    .no-print,
    .invoice-status,
    .screen-view {
        display: none !important;
    }

    .print-view {
        display: block !important;
        width: 100% !important;
    }

    .main {
        margin: 0 !important;
        padding: 0 !important;
        max-width: none !important;
        width: 100% !important;
    }

    .invoice-card {
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
        border-radius: 0 !important;
    }

    /* ===== PRINT HEADER ===== */
    .print-header {
        display: flex;
        justify-content: space-between;
        align-items: flex-start;
        margin-bottom: 18px;
    }

    .print-logo img {
        max-width: 220px;
        max-height: 80px;
        width: auto;
        height: auto;
        object-fit: contain;
        display: block;
    }

    .print-title {
        text-align: right;
    }

    .print-title h1 {
        margin: 0;
        font-size: 24px;
        font-weight: bold;
    }

    .print-title .invoice-number {
        margin-top: 6px;
        font-size: 12px;
    }

    /* ===== TOP INFO ===== */
    .print-top-info {
        display: flex;
        justify-content: space-between;
        gap: 18px;
        margin-bottom: 16px;
        align-items: flex-start;
    }

    .print-info-left,
    .print-recipient-box {
        width: 48%;
        border: 1px solid #000;
        padding: 10px;
        min-height: 90px;
        font-size: 11px;
        box-sizing: border-box;
        background: #fff;
    }

    .print-info-left {
        line-height: 1.45;
    }

    .print-info-grid {
        display: flex;
        gap: 30px;
        margin-bottom: 18px;
    }

    .print-box {
        width: 48%;
        border: 1px solid #000;
        padding: 10px;
        min-height: 90px;
        box-sizing: border-box;
        font-size: 11px;
        background: #fff;
    }

    .print-box h3 {
        margin: 0 0 8px 0;
        font-size: 12px;
    }

    /* ===== PRINT TABLE ===== */
    .print-items-table {
        width: 100%;
        border-collapse: collapse;
        border: 1px solid #000;
        margin-top: 14px;
        margin-bottom: 18px;
        font-size: 11px;
    }

    .print-items-table th,
    .print-items-table td {
        border: 1px solid #000;
        padding: 7px 8px;
        line-height: 1.35;
        vertical-align: top;
    }

    .print-items-table thead th {
        background: #f5f5f5;
        font-weight: bold;
        border-bottom: 2px solid #000;
    }

    .payment-box {
        margin-left: 14px;
    }
    /* ===== PRINT BOTTOM AREA ===== */
    .print-bottom-area {
        display: grid;
        grid-template-columns: 0.95fr 1.05fr;
        gap: 18px;
        margin-top: 18px;
        align-items: start;
    }

    .print-payment-left,
    .print-payment-right {
        border: 1px solid #000;
        padding: 15px;
        min-height: 170px;
        box-sizing: border-box;
        background: #fff;
        font-size: 11px;
    }
    .print-payment-right {
    margin-left: 20px;
    }

    .print-payment-left {
        display: flex;
        flex-direction: column;
    }

    .print-payment-left .payment-row,
    .print-payment-right .total-row {
        display: flex;
        justify-content: space-between;
        margin-bottom: 6px;
        line-height: 1.35;
    }

    .print-payment-left .invoice-qr {
        margin-top: auto;
        padding-top: 10px;
        display: flex;
        justify-content: flex-start;
        align-items: flex-start;
    }

    #invoiceQrPrint canvas,
    #invoiceQrPrint img {
        width: 60px !important;
        height: 60px !important;
        max-width: 60px !important;
        max-height: 60px !important;
        display: block;
    }

    .print-payment-right {
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
    }

    .print-payment-right .total-final {
        margin-top: auto;
        padding-top: 10px;
        border-top: 2px solid #000;
        font-size: 14px;
        font-weight: bold;
    }

    .print-payment-right .total-final span:last-child {
        font-size: 15px;
        font-weight: bold;
    }

    /* ===== PRINT FOOTER ===== */
    .print-footer {
        margin-top: 18px;
        padding-top: 8px;
        border-top: 1px solid #000;
        font-size: 10px;
        line-height: 1.4;
        color: #333;
        display: flex;
        justify-content: space-between;
        gap: 12px;
        flex-wrap: wrap;
    }

    .print-footer div {
        white-space: nowrap;
    }

    .invoice-footer-title {
        margin-top: 12px;
        font-size: 10px;
        font-weight: bold;
        color: #000;
        border-top: 1px solid #000;
        padding-top: 6px;
        margin-bottom: 4px;
    }

    .invoice-footer-text {
        margin-top: 6px;
        font-size: 10px;
        color: #444;
        line-height: 1.4;
    }

    .invoice-footer-text.small {
        font-size: 9px;
        color: #666;
        margin-top: 6px;
    }

    @page {
        size: A4;
        margin: 12mm;
    }
}

/* =====================================================
   LOGO / QR / OTHER
   ===================================================== */
.logo-preview {
    margin-top: 10px;
    max-width: 180px;
    max-height: 80px;
    object-fit: contain;
    border: none;
}

.logo-preview-print {
    max-width: 160px;
    max-height: 60px;
    object-fit: contain;
}

#invoiceQrPrint {
    margin-top: 6px;
    margin-left: -5px;
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
}
/* =====================================================
   E-Post modal
   ===================================================== */
.email-modal {
    position: fixed;
    z-index: 9999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
}

.email-modal-content {
    background: white;
    width: 800px;
    max-width: 95%;
    margin: 60px auto;
    border-radius: 10px;
    padding: 20px;
    box-shadow: 0 4px 18px rgba(0,0,0,0.25);
}

.email-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.email-preview-row {
    margin-bottom: 10px;
    font-size: 14px;
}

.email-preview-body {
    border: 1px solid #ddd;
    background: #fafafa;
    padding: 15px;
    min-height: 220px;
    line-height: 1.5;
    font-size: 14px;
}
/* =====================================================
   OVERDUE
   ===================================================== */
.overdue {
    color: #dc3545;
    font-weight: bold;
}

.overdue-row {
    background: #fff5f5;
}