/* --- style.css --- */
/* Basic Reset & Font */
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    background-color: #f2f2f7; /* Light gray background, Apple-like */
    color: #1c1c1e; /* Dark text for contrast */
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    padding: 20px;
    box-sizing: border-box;
}

.app {
    background-color: #ffffff; /* White card background */
    border-radius: 12px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.08); /* Subtle shadow */
    width: 100%;
    max-width: 800px; /* Max width for a pleasant reading experience */
    padding: 30px;
    box-sizing: border-box;
}

/* Header */
.app-header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 1px solid #e0e0e0; /* Subtle separator */
}

.app-logo {
    height: 80px;
    margin-bottom: 15px;
}

.app-header h1 {
    font-size: 2em;
    color: #333;
    margin: 0;
    font-weight: 600;
}

.app-header h2 {
    font-size: 1.2em;
    color: #555;
    margin: 5px 0 0;
    font-weight: 400;
}

/* Main Content Sections */
.app-main section {
    margin-bottom: 25px;
    padding: 20px;
    background-color: #f9f9f9; /* Slightly darker background for sections */
    border-radius: 8px;
    border: 1px solid #e8e8e8;
}

/* Specific styling for product category sections */
.product-category-section {
    padding-bottom: 0; /* Adjust padding for categories */
    margin-bottom: 25px;
    padding-top: 10px; /* Smaller top padding */
}
.product-category-section h3 {
    padding-left: 5px; /* Indent header slightly */
    border-bottom: none; /* Remove border from section header */
    margin-bottom: 10px; /* Less margin bottom for category headers */
}

.app-main h3 { /* General section headers */
    font-size: 1.4em;
    color: #333;
    margin-top: 0;
    margin-bottom: 20px;
    font-weight: 500;
    border-bottom: 1px dashed #e0e0e0;
    padding-bottom: 10px;
}


/* Product List */
.product-list { /* Used for Sealer and Tools (single column) */
    display: flex;
    flex-direction: column;
    gap: 10px; /* Reduced gap */
    padding-bottom: 10px; /* Add some padding at the bottom of the list */
}

.product-grid { /* Used for Stucco Cement (two columns) */
    display: grid;
    grid-template-columns: 1fr 1fr; /* Two equal columns */
    gap: 15px; /* Gap between grid items */
    padding-bottom: 10px; /* Add some padding at the bottom of the grid */
}

.product-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px; /* Added padding to product item itself */
    background-color: #fff; /* White background for individual items */
    border: 1px solid #e0e0e0; /* Subtle border */
    border-radius: 8px; /* Rounded corners for items */
    box-shadow: 0 1px 3px rgba(0,0,0,0.05); /* Very subtle shadow */
}

/* Remove border-bottom from product-item as they are now boxed */
.product-item:last-child {
    border-bottom: 1px solid #e0e0e0; /* Add border back for consistency if not grid */
}
.product-list .product-item:last-child {
    border-bottom: 1px solid #e0e0e0; /* Ensures bottom border for last item in a non-grid list */
}


.product-info {
    display: flex;
    flex-direction: column;
    flex-grow: 1;
    padding-right: 10px; /* Space between info and controls */
}

.product-name {
    font-weight: 500;
    color: #333;
    font-size: 1em; /* Slightly smaller for compactness */
    white-space: nowrap; /* Prevent name from wrapping on narrow items */
    overflow: hidden;
    text-overflow: ellipsis; /* Add ellipsis if name is too long */
}

.product-price {
    font-size: 0.85em; /* Slightly smaller */
    color: #777;
}

.quantity-control {
    display: flex;
    align-items: center;
    /* Removed gap as buttons and input will be visually connected */
    border: 1px solid #ccc; /* Unified border around the control group */
    border-radius: 8px; /* Rounded corners for the whole control */
    overflow: hidden; /* Ensures buttons don't have square corners sticking out */
    box-shadow: 0 1px 3px rgba(0,0,0,0.08); /* Match example image */
}

.quantity-btn {
    background-color: #f0f0f0; /* Lighter background for buttons */
    color: #333; /* Darker text for buttons */
    border: none; /* No individual button borders */
    border-radius: 0; /* Remove individual button rounding */
    width: 35px; /* Slightly wider buttons */
    height: 35px; /* Consistent height */
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 1.2em;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out, color 0.2s ease-in-out;
    -webkit-appearance: none;
    flex-shrink: 0; /* Prevent buttons from shrinking */
}

.quantity-btn:hover {
    background-color: #e0e0e0; /* Darker grey on hover */
    color: #007aff; /* Apple blue on hover for interaction */
}

.quantity-btn:active {
    background-color: #d0d0d0;
}

/* Specific border-radius for outer buttons */
.quantity-btn.minus-btn {
    border-top-left-radius: 7px; /* Slightly less than parent for visual effect */
    border-bottom-left-radius: 7px;
}

.quantity-btn.plus-btn {
    border-top-right-radius: 7px;
    border-bottom-right-radius: 7px;
}

.quantity-input {
    width: 45px; /* Adjusted width */
    padding: 8px 0; /* Adjusted padding */
    text-align: center;
    border: none; /* No individual border */
    border-left: 1px solid #ccc; /* Separator border */
    border-right: 1px solid #ccc; /* Separator border */
    border-radius: 0; /* No individual rounding */
    font-size: 1em;
    color: #1c1c1e;
    background-color: #fff; /* White background for input */
    -moz-appearance: textfield;
    appearance: textfield;
}

/* Hide spin buttons for number inputs */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}


/* Discount Section */
.discount-options, .vat-options, .customer-inputs { /* Applied to discount, VAT, and customer inputs */
    display: flex;
    flex-wrap: wrap; /* Allow wrapping on smaller screens */
    gap: 20px;
}

.discount-input-group, .vat-input-group, .input-group { /* Applied to discount, VAT, and customer input groups */
    display: flex;
    flex-direction: column;
    flex: 1; /* Allow items to grow */
    min-width: 180px; /* Ensure minimum width */
}

.discount-input-group label, .vat-input-group label, .input-group label { /* Applied to discount, VAT, and customer labels */
    margin-bottom: 8px;
    font-weight: 500;
    color: #333;
    font-size: 0.95em;
}

.discount-input, .discount-select, .customer-input { /* Applied to discount inputs, selects, and customer inputs */
    padding: 10px 12px;
    border: 1px solid #ccc;
    border-radius: 6px;
    font-size: 1em;
    color: #333;
    background-color: #fff;
    -webkit-appearance: none; /* Remove default styling for selects */
    -moz-appearance: none;
    appearance: none;
}

.discount-select {
    padding-right: 30px; /* Make space for custom arrow if needed */
    background-image: url('data:image/svg+xml;charset=US-ASCII,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20292.362%20292.362%22%3E%3Cpath%20fill%3D%22%23000%22%20d%3D%22M287.41 74.004L146.181 215.232 4.952 74.004z%22%2F%3E%3C%2Fsvg%3E');
    background-repeat: no-repeat;
    background-position: right 12px center;
    background-size: 10px;
}

/* New VAT section styling */
.vat-charges-section {
    margin-top: 25px; /* Spacing from previous section */
}

/* New Customer Information Section Styling */
.customer-info-section {
    margin-top: 25px; /* Spacing from previous section */
}
.customer-inputs .input-group {
    flex: 1 1 100%; /* Make each input group take full width on smaller screens */
    min-width: unset; /* Remove min-width for better responsiveness */
}
.customer-inputs {
    flex-direction: column; /* Stack inputs vertically by default */
}


/* Order Summary */
.empty-cart-message {
    text-align: center;
    color: #888;
    font-style: italic;
    padding: 20px;
}

.summary-items {
    border-bottom: 1px dotted #e8e8e8;
    padding-bottom: 15px;
    margin-bottom: 15px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.summary-item {
    display: flex;
    justify-content: space-between;
    font-size: 0.95em;
    color: #555;
}

.summary-totals .summary-line {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    font-size: 1.1em;
}

.summary-totals .discount-line {
    color: #007aff; /* Highlight discount with Apple blue */
    font-weight: 500;
}

.summary-totals .vat-line { /* New style for VAT line */
    color: #555;
    font-weight: 500;
    border-top: 1px dashed #e8e8e8; /* Separator for VAT */
    padding-top: 10px;
    margin-top: 5px;
}

.summary-totals .total-line {
    border-top: 1px solid #ccc;
    padding-top: 15px;
    margin-top: 10px;
    font-size: 1.4em;
    font-weight: 600;
    color: #1c1c1e;
}

.summary-totals .final-total {
    color: #007aff; /* Apple Blue for final total */
}

/* Actions Buttons */
.actions {
    text-align: center;
    margin-top: 30px;
    display: flex;
    justify-content: center;
    gap: 15px; /* Space between buttons */
}

.clear-btn, .preview-btn {
    border: none;
    padding: 12px 25px;
    border-radius: 8px;
    font-size: 1.1em;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out, box-shadow 0.2s ease-in-out;
    font-weight: 500;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.clear-btn {
    background-color: #ff3b30; /* Apple Red for destructive action */
    color: white;
}

.clear-btn:hover {
    background-color: #cc0000;
}

.clear-btn:active {
    background-color: #990000;
}

.preview-btn {
    background-color: #34c759; /* Apple Green */
    color: white;
}

.preview-btn:hover {
    background-color: #2c9d4a;
}

.preview-btn:active {
    background-color: #217838;
}

/* --- Preview Modal Styles --- */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5); /* Semi-transparent black overlay */
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000; /* Ensure it's on top */
    visibility: hidden; /* Hidden by default */
    opacity: 0;
    transition: visibility 0.3s, opacity 0.3s;
}

.modal-overlay.visible {
    visibility: visible;
    opacity: 1;
}

.modal-content {
    background-color: #ffffff;
    border-radius: 12px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
    width: 90%;
    max-width: 600px;
    max-height: 90vh; /* Limit height for scrollability */
    display: flex;
    flex-direction: column;
    overflow: hidden; /* Hide overflowing content before scroll */
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 25px;
    border-bottom: 1px solid #e0e0e0;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5em;
    color: #333;
    font-weight: 600;
}

.close-btn {
    font-size: 2em;
    color: #888;
    cursor: pointer;
    line-height: 1;
    padding: 0 5px;
    transition: color 0.2s;
}

.close-btn:hover {
    color: #333;
}

.modal-body {
    padding: 25px;
    flex-grow: 1;
    overflow-y: auto; /* Enable scrolling for long content */
    font-size: 1em;
    color: #333;
}

.modal-body .summary-items,
.modal-body .summary-totals {
    border: none; /* Remove section borders from main app */
    padding: 0;
    margin: 0;
}

.modal-body .summary-item,
.modal-body .summary-line {
    padding: 8px 0;
    font-size: 1.05em; /* Slightly larger for readability in print */
}

.modal-footer {
    padding: 15px 25px;
    border-top: 1px solid #e0e0e0;
    text-align: center;
}

.print-btn {
    background-color: #007aff; /* Apple Blue */
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 1.0em;
    cursor: pointer;
    transition: background-color 0.2s ease-in-out;
    font-weight: 500;
}

.print-btn:hover {
    background-color: #005bb5;
}

/* Specific styles for summary items inside the modal body */
.modal-body .summary-item {
    display: flex; /* Ensure flexbox for column layout */
    justify-content: space-between;
    align-items: center;
    font-size: 1.05em; /* Already set, just a reminder */
    padding: 8px 0;
    /* Remove any border-bottom that might interfere with cleaner lines */
    border-bottom: none;
}

/* Header row for modal summary */
.modal-body .summary-item.header {
    font-weight: 600;
    border-bottom: 1px solid #ddd; /* Subtle separator for header */
    padding-bottom: 10px;
    margin-bottom: 10px;
    color: #333;
}

/* Column distribution and alignment for summary items in modal */
.modal-body .summary-item span:nth-child(1) { /* Product Name */
    flex: 2; /* Allow more space for product name */
    text-align: left;
    padding-right: 10px; /* Space from next column */
}

.modal-body .summary-item span:nth-child(2) { /* Quantity */
    flex: 0 0 auto; /* Don't grow, don't shrink */
    width: 60px; /* Fixed width for quantity */
    text-align: center;
    white-space: nowrap; /* Prevent wrapping */
    padding: 0 5px; /* Small padding */
}

.modal-body .summary-item span:nth-child(3) { /* Total */
    flex: 0 0 auto; /* Don't grow, don't shrink */
    min-width: 90px; /* Minimum width for total to prevent squishing */
    text-align: right;
    white-space: nowrap; /* Prevent wrapping */
}

/* --- Print Styles --- */
@media print {
    body {
        background-color: #fff; /* Ensure white background for print */
        margin: 0;
        padding: 0;
        /* Adjusted for A4/Letter sizing */
        width: 210mm; /* A4 width */
        min-height: 297mm; /* A4 height */
        box-sizing: border-box; /* Include padding/border in the width/height */
    }

    /* Hide everything that's not the modal when printing */
    .app, .actions, .modal-overlay .modal-header, .modal-overlay .modal-footer {
        display: none;
    }

    /* Make the modal content visible and full page for printing */
    .modal-overlay.visible {
        visibility: visible;
        opacity: 1;
        position: static; /* Remove fixed positioning for print */
        background-color: transparent; /* No overlay background */
        display: block; /* Take up full space */
        width: auto;
        height: auto;
        margin: 0; /* Remove margin, control via modal-content padding */
        padding: 20mm; /* A4 standard margins */
        box-sizing: border-box;
    }

    .modal-content {
        box-shadow: none; /* No shadow in print */
        border: none; /* No border in print */
        border-radius: 0;
        max-width: 100%;
        width: 100%; /* Take full width of parent (modal-overlay) */
        height: auto;
        max-height: none;
        padding: 0; /* No padding from modal-content, handle in modal-overlay */
    }

    .modal-body {
        padding: 0; /* Let print style handle margins */
        overflow: visible; /* Ensure all content is visible, no scrolling */
        border: none;
    }

    /* Adjust font size for print if necessary */
    .modal-body .summary-item,
    .modal-body .summary-line {
        font-size: 10pt; /* Smaller font for compactness on print */
    }
    .modal-body h2 {
        font-size: 14pt;
        text-align: center;
        margin-bottom: 20px;
    }
    .modal-body .app-logo {
        display: block;
        margin: 0 auto 20px auto;
        height: 60px; /* Slightly smaller logo for print */
    }
    .modal-body .summary-totals .final-total {
        color: #000; /* Ensure black for print */
    }

    .modal-print-header {
        text-align: center;
        margin-bottom: 15pt;
    }
    .modal-print-header h2 {
        font-size: 14pt;
        margin-top: 5pt;
        margin-bottom: 0;
    }
    .modal-print-header h3 {
        font-size: 12pt;
        margin-top: 5pt;
        margin-bottom: 0;
    }
    .modal-print-header hr {
        margin: 10pt 0;
    }

    .modal-body .summary-totals .total-line {
        font-size: 13pt; /* Larger total for prominence */
        padding-top: 10pt;
        margin-top: 8pt;
    }

    /* Customer Info in Print */
    .modal-body .customer-info-print {
        text-align: left;
        margin-bottom: 15pt;
        font-size: 10pt;
    }
    .modal-body .customer-info-print p {
        margin: 2pt 0;
    }
}


/* Responsive adjustments */
@media (max-width: 600px) {
    .app {
        padding: 15px;
    }

    .app-header h1 {
        font-size: 1.6em;
    }

    .app-header h2 {
        font-size: 1em;
    }

    .app-main section {
        padding: 15px;
    }

    .app-main h3 {
        font-size: 1.2em;
        margin-bottom: 15px;
    }

    /* Responsive adjustments for product grid */
    .product-grid {
        grid-template-columns: 1fr; /* Single column on small screens */
        gap: 10px;
    }

    .product-item {
        flex-direction: row; /* Keep as row */
        flex-wrap: wrap; /* Allow wrapping */
        justify-content: space-between; /* Space out items */
        align-items: center; /* Vertically align items */
    }
    .product-info {
        flex-grow: 1;
        flex-basis: 60%; /* Allow info to take more space */
        padding-right: 5px;
    }
    .quantity-control {
        flex-grow: 1;
        max-width: 150px; /* Limit width of controls */
        justify-content: flex-end; /* Push to the right */
    }


    .discount-options, .vat-options, .customer-inputs {
        flex-direction: column;
    }

    .discount-input-group, .vat-input-group, .input-group {
        width: 100%;
        min-width: unset;
    }

    .summary-totals .total-line {
        font-size: 1.2em;
    }

    /* Modal responsiveness */
    .modal-content {
        width: 95%;
        margin: 10px;
    }
    .modal-header, .modal-footer {
        padding: 15px 20px;
    }
    .modal-body {
        padding: 20px;
    }
}