.invoice-container {
    background-color: #f2f3f5;
    padding: 40px 0;
    min-height: 100vh;
}

.invoice-wrapper {
    display: flex;
    gap: 30px;
    max-width: 1140px;
    margin: 0 auto;
    padding: 0 15px;
}

.invoice-main {
    flex: 1;
    background: #fff;
    border: 1px solid #e4e4e4;
    border-radius: 4px;
    padding: 40px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    position: relative;
}

.invoice-sidebar {
    width: 300px;
    flex-shrink: 0;
}

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

.invoice-title {
    font-size: 36px;
    font-weight: 700;
    /* Bold */
    text-transform: uppercase;
    color: #333;
    margin: 0;
    line-height: 1;
    text-align: center;
    /* Centered */
    width: 100%;
}

.invoice-header-left {
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex: 1;
}

.invoice-logo-box {
    width: 200px;
    height: 100px;
    background-color: #f8f9fa;
    border: 1px dashed #ccc;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    overflow: hidden;
}

.invoice-logo-box:hover {
    background-color: #f1f1f1;
}

.invoice-logo-box img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.invoice-logo-box span {
    color: #999;
    font-size: 14px;
}

.invoice-logo-remove {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(255, 255, 255, 0.9);
    border-radius: 50%;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: #dc3545;
    font-weight: bold;
    line-height: 1;
    font-size: 16px;
    z-index: 10;
    display: none;
    border: 1px solid #ddd;
}

.invoice-logo-remove:hover {
    background: #dc3545;
    color: #fff;
}

.form-control-plaintext {
    display: block;
    width: 100%;
    padding: 0.375rem 0;
    margin-bottom: 0;
    line-height: 1.5;
    color: #212529;
    background-color: transparent;
    border: solid transparent;
    border-width: 1px 0;
    resize: none;
    /* Disable manual resize */
    overflow: hidden;
    /* Hide scrollbar */
    min-height: 40px;
}

.form-control-plaintext:focus {
    outline: 0;
}

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

.invoice-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 10px;
}

.meta-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.meta-row input {
    text-align: right;
    border: 1px solid #ddd;
    padding: 5px 10px;
    border-radius: 3px;
    width: 150px;
}

.items-table {
    width: 100%;
    margin-bottom: 20px;
    border-collapse: collapse;
    min-width: 600px;
    /* Force scroll if container is small */
}

.table-responsive {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.items-table th {
    background: #222;
    color: #fff;
    padding: 10px;
    text-align: left;
    font-weight: 500;
}

.items-table td {
    padding: 10px;
    border-bottom: 1px solid #eee;
    vertical-align: top;
}

.items-table input {
    width: 100%;
    border: 1px solid #ddd;
    padding: 8px;
    border-radius: 3px;
}

.items-table .item-desc {
    width: 50%;
}

.items-table .item-qty,
.items-table .item-rate {
    width: 15%;
}

.items-table .item-amount {
    width: 15%;
    text-align: right;
    padding-right: 10px;
    font-weight: bold;
}

.items-table .item-action {
    width: 5%;
    text-align: center;
}

.amount-input {
    width: 100%;
    border: none;
    background: transparent;
    text-align: right;
    color: #333;
    font-weight: bold;
    padding: 8px 0;
}

.amount-input:disabled {
    background: transparent;
    color: #333;
    cursor: default;
}

.btn-add-line {
    background: #397bed;
    color: #fff;
    border: none;
    padding: 8px 15px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
}

.btn-remove {
    color: #dc3545;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px;
}

.invoice-totals {
    display: flex;
    justify-content: flex-end;
    margin-top: 20px;
    padding-right: calc(5% + 10px);
    /* Align with Amount column (Action col is 5% + 10px padding) */
}

.totals-box {
    width: 350px;
    /* Increased width for new fields */
}

.total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    padding-bottom: 10px;
    border-bottom: 1px solid #eee;
}

.total-row.final {
    border-bottom: none;
    font-size: 18px;
    font-weight: bold;
    color: #222;
    margin-top: 10px;
    border-top: 2px solid #eee;
    padding-top: 10px;
}

.tax-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.btn-add-tax {
    color: #397bed;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 12px;
    padding: 0;
    margin-top: 5px;
}

.btn-download {
    display: block;
    width: 100%;
    background: #007bff;
    color: #fff;
    text-align: center;
    padding: 15px;
    border-radius: 4px;
    text-decoration: none;
    font-weight: bold;
    margin-bottom: 15px;
    border: none;
    cursor: pointer;
    font-size: 16px;
}

.btn-download:hover {
    background: #0056b3;
    color: #fff;
}

.btn-reset {
    display: block;
    width: 100%;
    background: #fff;
    color: #dc3545;
    text-align: center;
    padding: 15px;
    border-radius: 4px;
    text-decoration: none;
    font-weight: bold;
    margin-bottom: 15px;
    border: 1px solid #dc3545;
    cursor: pointer;
    font-size: 16px;
    transition: all 0.3s;
}

.btn-reset:hover {
    background: #dc3545;
    color: #fff;
}

/* Modal Styles */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s ease;
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal-content {
    background: #fff;
    padding: 30px;
    border-radius: 8px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    transform: translateY(-20px);
    transition: all 0.3s ease;
}

.modal-overlay.active .modal-content {
    transform: translateY(0);
}

.modal-title {
    font-size: 24px;
    font-weight: bold;
    margin-bottom: 10px;
    color: #333;
}

.modal-text {
    color: #666;
    margin-bottom: 25px;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 15px;
    justify-content: center;
}

.btn-modal-cancel {
    background: #f8f9fa;
    border: 1px solid #ddd;
    padding: 10px 25px;
    border-radius: 4px;
    cursor: pointer;
    color: #333;
    font-weight: 500;
    transition: all 0.2s;
}

.btn-modal-cancel:hover {
    background: #e2e6ea;
}

.btn-modal-confirm {
    background: #dc3545;
    color: #fff;
    border: none;
    padding: 10px 25px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.2s;
    box-shadow: 0 2px 5px rgba(220, 53, 69, 0.3);
}

.btn-modal-confirm:hover {
    background: #c82333;
    transform: translateY(-1px);
    box-shadow: 0 4px 8px rgba(220, 53, 69, 0.4);
}

@media print {
    body * {
        visibility: hidden;
    }

    .invoice-main,
    .invoice-main * {
        visibility: visible;
    }

    .invoice-main {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        margin: 0;
        padding: 0;
        border: none;
        box-shadow: none;
    }

    .invoice-sidebar,
    .btn-add-line,
    .btn-remove,
    .invoice-logo-box span,
    .invoice-logo-remove,
    .btn-add-tax,
    .btn-reset,
    .btn-download {
        /* Hide all buttons in print */
        display: none !important;
    }

    /* Remove borders from inputs for print */
    input,
    select,
    textarea,
    .amount-input {
        border: none !important;
        background: transparent !important;
        resize: none;
        padding: 0 !important;
    }

    /* Hide placeholders */
    ::placeholder {
        color: transparent;
    }

    .items-table input,
    .meta-row input,
    textarea,
    .total-row input,
    .total-row select {
        border: none !important;
        padding: 0 !important;
        resize: none;
        background: transparent !important;
        -webkit-appearance: none;
        appearance: none;
    }

    /* Hide select arrow in print */
    select {
        text-align-last: right;
    }

    /* Ensure inputs show their values */
    input[type="text"],
    input[type="number"],
    input[type="date"] {
        background: transparent;
    }
}

/* Responsive Styles */
@media (max-width: 992px) {
    .invoice-wrapper {
        flex-direction: column;
        padding: 0 10px;
    }

    .invoice-sidebar {
        width: 100%;
        order: -1;
        /* Show download button on top for easier access or keep at bottom? Let's keep standard flow or maybe top is better for "Actions" */
        margin-bottom: 20px;
    }

    /* If we want sidebar at bottom, remove order: -1. Let's keep it at bottom as per standard flow, but maybe make it more compact */
    .invoice-sidebar {
        order: 0;
    }
}

@media (max-width: 768px) {
    .invoice-main {
        padding: 20px;
    }

    .invoice-header {
        flex-direction: column;
        gap: 20px;
    }

    .invoice-header-left {
        width: 100%;
        align-items: center;
        text-align: center;
    }

    .invoice-meta {
        width: 100%;
        align-items: stretch;
    }

    .meta-row {
        justify-content: space-between;
    }

    .meta-row input {
        width: 60%;
    }

    .invoice-details-grid {
        grid-template-columns: 1fr;
        gap: 20px;
    }



    .invoice-totals {
        justify-content: flex-start;
    }

    .totals-box {
        width: 100%;
    }
}

@media (max-width: 480px) {
    .invoice-title {
        font-size: 28px;
    }

    .invoice-logo-box {
        width: 100%;
        max-width: 200px;
    }

    .items-table th,
    .items-table td {
        padding: 8px 5px;
        font-size: 14px;
    }

    .btn-add-line {
        width: 100%;
    }
}

/* Force desktop width ONLY during PDF generation */
.pdf-mode .invoice-wrapper {
    max-width: 1140px !important;
    width: 1140px !important;
}

.pdf-mode .invoice-main {
    width: 100% !important;
}

.pdf-mode .invoice-sidebar {
    display: none !important;
}

input[type=number]::-webkit-outer-spin-button,
input[type=number]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    appearance: none;
    /* Standard property for future compatibility */
    margin: 0;
}

input[type=number] {
    -moz-appearance: textfield;
    /* Firefox */
    appearance: none;
    /* Standard property for future compatibility */
}