body {
    font-family: 'Sarabun', sans-serif;
    margin: 0;
    padding: 0;
    background-color: #f4f7f6;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1400px;
    margin: 20px auto;
    background-color: #fff;
    padding: 30px;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
}

.header {
    text-align: center;
    margin-bottom: 30px;
    padding-bottom: 20px;
    border-bottom: 2px solid #eee;
}

.header h1 {
    color: #4a90e2;
    margin: 0;
    font-size: 2.5em;
}

.alert {
    padding: 15px;
    margin-bottom: 20px;
    border-radius: 8px;
    font-weight: bold;
    display: none;
    text-align: center;
    animation: fadeIn 0.5s;
}

.alert-success {
    background-color: #d4edda;
    color: #155724;
    border: 1px solid #c3e6cb;
}

.alert-danger {
    background-color: #f8d7da;
    color: #721c24;
    border: 1px solid #f5c6cb;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

.loading {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 1001;
}

.spinner {
    border: 8px solid #f3f3f3;
    border-top: 8px solid #4a90e2;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

.loading p {
    color: #fff;
    margin-top: 15px;
    font-size: 1.2em;
}

#companySelection {
    text-align: center;
    margin-bottom: 30px;
    background-color: #eaf3ff;
    padding: 20px;
    border-radius: 8px;
    border: 1px solid #cce0ff;
}

#companySelection h2 {
    color: #4a90e2;
    margin-top: 0;
}

#companySelect {
    padding: 10px 15px;
    font-size: 1.1em;
    border: 1px solid #ccc;
    border-radius: 5px;
    width: 80%;
    max-width: 400px;
    box-sizing: border-box;
}

.main-content {
    display: none;
    margin-top: 30px;
}

.btn-group {
    margin-top: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
}

.btn {
    padding: 12px 25px;
    font-size: 1em;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    background-color: #4CAF50;
    color: white;
    transition: background-color 0.3s ease, transform 0.2s ease;
    flex-grow: 1;
    text-align: center;
}

.btn:hover {
    background-color: #45a049;
    transform: translateY(-2px);
}

.btn-primary {
    background-color: #007bff;
}

.btn-primary:hover {
    background-color: #0056b3;
}

.btn-warning {
    background-color: #ffc107;
    color: #333;
}

.btn-warning:hover {
    background-color: #e0a800;
}

.btn-danger {
    background-color: #dc3545;
}

.btn-danger:hover {
    background-color: #c82333;
}

/* Form Styles */
#addProductContainer {
    background-color: #f9f9f9;
    padding: 25px;
    border-radius: 8px;
    border: 1px solid #eee;
    margin-bottom: 30px;
}

#addProductContainer h3 {
    text-align: center;
    color: #4a90e2;
    margin-top: 0;
    margin-bottom: 20px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: bold;
    color: #555;
}

.form-group input[type="text"],
.form-group input[type="number"],
.form-group input[type="file"] {
    width: calc(100% - 20px);
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 1em;
}

.button-row {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

.button-row .btn {
    flex-grow: 0;
    width: auto;
    min-width: 120px;
}

/* Table Styles */
.form-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 20px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
    background-color: #fff;
    border-radius: 8px;
    overflow: hidden;
}

.form-table thead th {
    background-color: #4a90e2;
    color: white;
    padding: 15px;
    text-align: left;
    font-weight: normal;
}

.form-table tbody td {
    padding: 12px 15px;
    border-bottom: 1px solid #eee;
    vertical-align: middle;
}

.form-table tbody tr:nth-child(even) {
    background-color: #f9f9f9;
}

.form-table tbody tr:hover {
    background-color: #f0f8ff;
}

.form-table input[type="text"],
.form-table input[type="number"] {
    width: calc(100% - 16px);
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9em;
}

.form-table input.highlight {
    border-color: #4a90e2;
    box-shadow: 0 0 5px rgba(74, 144, 226, 0.3);
}

.form-table .auto-field {
    background-color: #e9ecef;
    cursor: not-allowed;
}

.form-table .btn-sm {
    padding: 6px 12px;
    font-size: 0.8em;
    flex-grow: 0;
}

.summary-section {
    text-align: right;
    margin-top: 20px;
    padding: 15px 20px;
    background-color: #eaf3ff;
    border-radius: 8px;
    border: 1px solid #cce0ff;
}

.summary-section p {
    margin: 0;
    font-size: 1.4em;
    color: #2c3e50;
}

.summary-section strong {
    color: #4a90e2;
}

#grandTotal {
    font-weight: bold;
    color: #e74c3c;
}

.process-diagram {
    margin-top: 40px;
    text-align: center;
    background-color: #f0f0f0;
    padding: 20px;
    border-radius: 8px;
}

.process-diagram h3 {
    color: #4a90e2;
    margin-bottom: 20px;
}

.process-step {
    display: inline-block;
    background-color: #4a90e2;
    color: white;
    padding: 10px 20px;
    border-radius: 25px;
    margin: 0 10px;
    font-weight: bold;
    font-size: 0.9em;
    white-space: nowrap;
}

.arrow {
    display: inline-block;
    font-size: 1.5em;
    color: #777;
    vertical-align: middle;
    margin: 0 5px;
}

.calculation-area {
    margin-top: 30px;
    background-color: #f9f9f9;
    padding: 25px;
    border-radius: 8px;
    border: 1px solid #eee;
}

.calculation-area h3 {
    color: #4a90e2;
    margin-top: 0;
    margin-bottom: 20px;
    text-align: center;
}

.calc-row {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 15px;
    align-items: center;
}

.calc-row span {
    font-weight: bold;
    color: #555;
    flex-basis: 150px;
    /* Adjust as needed */
    text-align: right;
}

.calc-input {
    flex-grow: 1;
    padding: 10px;
    border: 1px solid #ccc;
    border-radius: 5px;
    font-size: 1em;
    max-width: 300px;
}

/* Quotations List */
#quotationsList {
    margin-top: 30px;
    background-color: #f9f9f9;
    padding: 25px;
    border-radius: 8px;
    border: 1px solid #eee;
}

#quotationsList h3 {
    color: #4a90e2;
    margin-top: 0;
    margin-bottom: 20px;
    text-align: center;
}

/* Product Image Display */
.product-image-display {
    max-width: 50px;
    height: auto;
    vertical-align: middle;
    margin-right: 5px;
    border-radius: 3px;
    border: 1px solid #eee;
}

/* Receipt/Printable Area Styles */
#quotationPrintableArea {
    display: none;
    /* Hidden by default, shown when print function is called */
    width: 210mm;
    /* A4 width */
    min-height: 297mm;
    /* A4 height */
    padding: 20mm;
    margin: 0 auto;
    background: #fff;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    font-family: 'Sarabun', sans-serif;
    color: #333;
    box-sizing: border-box;
}

.receipt-container {
    padding: 20px;
    border: 1px solid #eee;
    background-color: #fff;
}

.receipt-header {
    text-align: center;
    margin-bottom: 30px;
    border-bottom: 2px solid #eee;
    padding-bottom: 15px;
}

.receipt-header h1 {
    color: #4a90e2;
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 2.2em;
}

.receipt-header p {
    margin: 5px 0;
    font-size: 0.95em;
}

.receipt-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}

.receipt-detail-box {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    background-color: #f9f9f9;
}

.receipt-detail-box h3 {
    color: #4a90e2;
    margin-top: 0;
    font-size: 1.2em;
    border-bottom: 1px solid #eee;
    padding-bottom: 8px;
    margin-bottom: 10px;
}

.receipt-detail-box p {
    margin: 5px 0;
    font-size: 0.9em;
}

.receipt-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 30px;
}

.receipt-table th,
.receipt-table td {
    border: 1px solid #ddd;
    padding: 10px 12px;
    text-align: left;
    font-size: 0.9em;
}

.receipt-table thead th {
    background-color: #f2f2f2;
    font-weight: bold;
    color: #555;
}

.receipt-total-section {
    text-align: right;
    margin-top: 20px;
    border-top: 2px solid #eee;
    padding-top: 15px;
}

.receipt-total-section p {
    font-size: 1.5em;
    font-weight: bold;
    color: #e74c3c;
}

.receipt-signature-area {
    display: flex;
    justify-content: space-around;
    margin-top: 60px;
    text-align: center;
}

.receipt-signature-box {
    width: 45%;
    border-top: 1px solid #ccc;
    padding-top: 10px;
    font-size: 0.9em;
}

/* General Modal Styles (for edit and product management) */
.modal {
    display: none;
    /* Hidden by default */
    position: fixed;
    /* Stay in place */
    z-index: 1000;
    /* Sit on top */
    left: 0;
    top: 0;
    width: 100%;
    /* Full width */
    height: 100%;
    /* Full height */
    overflow: auto;
    /* Enable scroll if needed */
    background-color: rgba(0, 0, 0, 0.4);
    /* Black w/ opacity */
    justify-content: center;
    /* Center horizontally */
    align-items: center;
    /* Center vertically */
    padding: 20px;
    /* Padding around modal content */
    box-sizing: border-box;
}

.modal-content {
    background-color: #fefefe;
    margin: auto;
    /* For vertical centering */
    padding: 30px;
    border: 1px solid #888;
    width: 90%;
    /* Adjust width as needed */
    max-width: 1200px;
    /* Max width for larger screens */
    border-radius: 8px;
    box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    position: relative;
    animation-name: animatetop;
    animation-duration: 0.4s;
    max-height: 90vh;
    /* Max height to allow scrolling */
    overflow-y: auto;
    /* Enable scrolling for content */
}

/* Animation for modal */
@keyframes animatetop {
    from {
        top: -300px;
        opacity: 0
    }

    to {
        top: 0;
        opacity: 1
    }
}

.close-modal-btn {
    color: #aaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
    position: absolute;
    right: 15px;
    top: 10px;
    cursor: pointer;
}

.close-modal-btn:hover,
.close-modal-btn:focus {
    color: black;
    text-decoration: none;
    cursor: pointer;
}

/* Product Grid for Management (inside modal) */
.product-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    /* Responsive grid */
    gap: 20px;
    margin-top: 20px;
}

.product-card {
    border: 1px solid #ddd;
    border-radius: 8px;
    padding: 15px;
    text-align: center;
    background-color: #fff;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    /* Space out content vertically */
    transition: transform 0.2s ease-in-out;
}

.product-card:hover {
    transform: translateY(-5px);
}

.product-card img {
    max-width: 100%;
    height: 150px;
    /* Fixed height for consistency */
    object-fit: cover;
    /* Cover the area, crop if needed */
    border-radius: 4px;
    margin-bottom: 10px;
}

.product-card h4 {
    margin: 10px 0;
    font-size: 1.1em;
    color: #333;
    white-space: nowrap;
    /* Prevent wrapping */
    overflow: hidden;
    /* Hide overflow */
    text-overflow: ellipsis;
    /* Add ellipsis */
}

.product-card p {
    font-size: 0.9em;
    color: #666;
    margin: 5px 0;
}

.product-actions {
    margin-top: 15px;
    display: flex;
    justify-content: space-around;
    /* Space buttons evenly */
    gap: 10px;
}

.product-actions .btn {
    flex: 1;
    /* Make buttons take equal width */
    padding: 8px 12px;
    font-size: 0.9em;
}

/* No products message in modal */
.modal-no-products {
    /* Changed from .no-products to .modal-no-products for modal specific styling */
    text-align: center;
    padding: 50px;
    font-size: 1.2em;
    color: #777;
    background-color: #f5f5f5;
    border-radius: 8px;
    margin-top: 20px;
}

/* Adjustments for print view (optional, if you want product images larger) */
.product-image-display-receipt {
    max-width: 80px;
    /* Make images slightly larger in print */
    height: auto;
    vertical-align: middle;
    margin-right: 5px;
    border-radius: 3px;
    border: 1px solid #eee;
}

/* Responsive adjustments for Tablets (e.g., iPad in portrait) */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        margin: 20px auto;
        padding: 25px;
    }

    .header h1 {
        font-size: 2.2em;
    }

    #companySelect {
        width: 70%;
        max-width: 350px;
    }

    .btn-group {
        justify-content: center;
        gap: 15px;
    }

    .btn {
        padding: 10px 20px;
        font-size: 0.95em;
        flex-basis: auto;
        /* Allow buttons to size based on content, but maintain gap */
        min-width: 100px;
    }

    .form-table thead th {
        padding: 12px;
    }

    .form-table tbody td {
        padding: 10px 12px;
    }

    .form-table input[type="text"],
    .form-table input[type="number"] {
        font-size: 0.9em;
    }

    .summary-section p {
        font-size: 1.3em;
    }

    .receipt-header h1 {
        font-size: 2em;
    }

    .receipt-detail-grid {
        grid-template-columns: 1fr 1fr;
        /* Keep 2 columns for wider screens */
        gap: 15px;
    }

    .modal-content {
        width: 80%;
        max-width: 1000px;
        padding: 25px;
    }

    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    }
}


/* Responsive adjustments for Mobile (screens up to 768px) */
@media (max-width: 768px) {
    .container {
        margin: 10px auto;
        padding: 15px;
    }

    .header h1 {
        font-size: 1.8em;
    }

    .alert {
        padding: 10px;
        font-size: 0.9em;
    }

    #companySelect {
        width: 90%;
        font-size: 1em;
    }

    .btn-group {
        flex-direction: column;
        gap: 8px;
    }

    .btn {
        width: 100%;
        padding: 10px 15px;
        font-size: 0.9em;
        margin-bottom: 0;
        /* Removed margin-bottom as gap handles it */
    }

    /* Table responsive styling for small screens */
    .form-table {
        border: none;
        box-shadow: none;
    }

    .form-table thead {
        display: none;
        /* Hide table header */
    }

    .form-table tbody,
    .form-table tr,
    .form-table td {
        display: block;
        width: 100%;
    }

    .form-table tr {
        margin-bottom: 15px;
        border: 1px solid #eee;
        border-radius: 8px;
        padding: 10px;
        box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
    }

    .form-table td {
        text-align: right;
        padding-left: 50%;
        position: relative;
        font-size: 0.9em;
    }

    .form-table td::before {
        content: attr(data-label);
        /* Use data-label for pseudo-element content */
        position: absolute;
        left: 10px;
        width: calc(50% - 20px);
        text-align: left;
        font-weight: bold;
        color: #555;
    }

    .form-table input[type="text"],
    .form-table input[type="number"] {
        width: calc(100% - 10px);
        font-size: 0.9em;
    }

    .button-row {
        flex-direction: column;
        align-items: stretch;
        /* Stretch buttons to full width */
    }

    .button-row .btn {
        width: 100%;
        min-width: unset;
    }

    .calc-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }

    .calc-row span {
        text-align: left;
        width: 100%;
        flex-basis: auto;
    }

    .calc-input {
        max-width: 100%;
        width: 100%;
    }

    .receipt-detail-grid {
        grid-template-columns: 1fr;
        /* Single column for receipt details */
    }

    .receipt-signature-area {
        flex-direction: column;
        gap: 20px;
        margin-top: 40px;
    }

    .receipt-signature-box {
        width: 90%;
        margin: 0 auto;
    }

    .modal-content {
        width: 95%;
        padding: 15px;
    }

    .product-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        /* Smaller cards for mobile */
        gap: 10px;
    }

    .product-card img {
        height: 100px;
    }

    .product-card h4 {
        font-size: 1em;
    }

    .product-card p {
        font-size: 0.8em;
    }

    .product-actions .btn {
        padding: 6px 10px;
        font-size: 0.8em;
    }
}

@media print {
    body * {
        visibility: hidden;
    }

    #quotationPrintableArea,
    #quotationPrintableArea * {
        visibility: visible;
    }

    #quotationPrintableArea {
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        margin: 0;
        padding: 0;
        box-shadow: none;
    }

    .btn,
    .button-row {
        display: none !important;
    }

    /* Ensure buttons are hidden in print */
}