* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: Arial, Helvetica, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    background: white;
    border-radius: 10px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    padding: 30px;
}

.page-nav {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 10px;
}

.nav-link {
    color: #667eea;
    text-decoration: none;
    font-weight: 600;
    font-size: 14px;
}

.nav-link:hover {
    text-decoration: underline;
}

.config-intro {
    text-align: center;
    color: #666;
    margin: -15px 0 25px;
    line-height: 1.5;
}

.config-form h2 {
    margin-top: 10px;
}

.config-form h2:first-of-type {
    margin-top: 0;
}

.config-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 20px;
}

.config-preview-box {
    margin-top: 20px;
}

.config-sample {
    background: #fff;
    border: 1px dashed #ccc;
    border-radius: 6px;
    padding: 16px;
}

.config-toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    background: #2d3748;
    color: #fff;
    padding: 12px 20px;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 1000;
}

h1 {
    text-align: center;
    color: #667eea;
    margin-bottom: 30px;
    font-size: 2.5em;
}

h2 {
    color: #764ba2;
    margin-bottom: 20px;
    font-size: 1.5em;
    border-bottom: 2px solid #667eea;
    padding-bottom: 10px;
}

.form-section {
    margin-bottom: 30px;
    padding: 20px;
    background: #f8f9fa;
    border-radius: 8px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 15px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 600;
    color: #555;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px;
    border: 2px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    transition: border-color 0.3s;
    font-family: Arial, Helvetica, sans-serif;
}

.form-group textarea {
    resize: vertical;
}

.input-uppercase {
    text-transform: uppercase;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
}

.products-header {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto;
    gap: 10px;
    padding: 12px 15px;
    background: #667eea;
    color: white;
    border-radius: 5px;
    font-weight: 600;
    margin-bottom: 10px;
}

.header-label {
    text-align: center;
    font-size: 14px;
}

.product-item {
    background: white;
    padding: 15px;
    margin-bottom: 15px;
    border-radius: 5px;
    border: 2px solid #e0e0e0;
    display: grid;
    grid-template-columns: 2fr 1fr 1fr 1fr 1fr auto;
    gap: 10px;
    align-items: center;
}

.product-item input,
.product-item select {
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 14px;
    font-family: Arial, Helvetica, sans-serif;
}

.btn-remove {
    background: #dc3545;
    color: white;
    border: none;
    padding: 8px 15px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.3s;
}

.btn-remove:hover {
    background: #c82333;
}

.btn {
    padding: 12px 24px;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    cursor: pointer;
    transition: all 0.3s;
    font-weight: 600;
}

.btn-add {
    background: #28a745;
    color: white;
    width: 100%;
    margin-top: 10px;
}

.btn-add:hover {
    background: #218838;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn-primary {
    background: #667eea;
    color: white;
}

.btn-primary:hover {
    background: #5568d3;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.btn-secondary {
    background: #6c757d;
    color: white;
    margin-left: 10px;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

.action-buttons {
    text-align: center;
    margin: 30px 0;
}

.form-actions {
    margin-top: 10px;
    margin-bottom: 15px;
    text-align: right;
}

.btn-sample {
    background: #17a2b8;
    color: white;
    padding: 10px 20px;
    font-size: 14px;
}

.btn-sample:hover {
    background: #138496;
    transform: translateY(-2px);
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}

/* Quote Preview Styles - Giống 100% PDF */
.quote-preview {
    margin-top: 40px;
    padding: 30px;
    background: white;
    box-shadow: 0 0 10px rgba(0,0,0,0.1);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 10pt;
    line-height: 1.5;
    color: #000;
}

.quote-preview.hidden {
    display: none;
}

.quote-header-wrapper {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 20px;
    padding-bottom: 10px;
    gap: 20px;
}

.quote-header-left {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    flex: 1;
    min-width: 0;
    padding-right: 15px;
}

.logo-placeholder {
    width: 50px;
    height: 50px;
    background: url('vietbox.png') no-repeat center center;
    background-size: contain;
    flex-shrink: 0;
}

.company-info {
    flex: 1;
    min-width: 0;
}

.company-info h2 {
    color: #000;
    font-size: 10.5pt;
    margin-bottom: 3px;
    border: none;
    padding: 0;
    font-weight: bold;
    text-transform: uppercase;
    line-height: 1.3;
}

.company-info .address {
    color: #000;
    font-size: 10pt;
    font-style: italic;
    margin-bottom: 0;
    line-height: 1.3;
}

.quote-header-right {
    flex-shrink: 0;
}

.quote-dates {
    display: flex;
    flex-direction: column;
    gap: 2px;
    white-space: nowrap;
}

.date-item {
    display: grid;
    grid-template-columns: 95px auto;
    gap: 5px;
    align-items: baseline;
    white-space: nowrap;
}

.date-label {
    font-weight: bold;
    font-size: 10pt;
    white-space: nowrap;
}

.date-value {
    font-size: 10pt;
    font-weight: normal;
    text-align: right;
    white-space: nowrap;
}

.contact-info-block {
    margin-top: 15px;
    font-size: 10pt;
    margin-bottom: 15px;
}

.contact-info-block div {
    margin-bottom: 2px;
}

.contact-info-block strong {
    font-weight: bold;
}

.quote-title {
    text-align: center;
    margin: 25px 0 20px 0;
}

.quote-title h3 {
    font-size: 12pt;
    font-weight: bold;
    color: #000;
    border: none;
    padding: 0;
    margin: 0;
    text-transform: uppercase;
}

.customer-info-grid {
    display: grid;
    grid-template-columns: 120px auto;
    gap: 8px 10px;
    margin-bottom: 25px;
}

.info-label {
    font-weight: bold;
    font-size: 10pt;
}

.info-value {
    font-size: 10pt;
}

.quote-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 25px;
    border: 1px solid #000;
}

.quote-table th {
    background: #fff;
    color: #000;
    padding: 6px 5px;
    text-align: center;
    font-weight: bold;
    font-size: 10pt;
    border-bottom: 1px solid #000;
}

/* Make inner vertical borders dashed */
.quote-table th:not(:last-child),
.quote-table td:not(:last-child) {
    border-right: 1px dashed #000;
}

.quote-table td {
    padding: 8px 5px;
    text-align: center;
    font-size: 10pt;
}

/* Thêm đường kẻ ngăn cách giữa các dòng sản phẩm */
.quote-table tbody tr {
    border-bottom: 1px solid #000;
}

.quote-table tbody tr:last-child {
    border-bottom: none;
}

.quote-table td:nth-child(2) {
    text-align: left; /* Tên sản phẩm căn trái */
}
.quote-table td:nth-child(5),
.quote-table td:nth-child(6) {
    text-align: right; /* Đơn giá và Thành tiền căn phải */
}

.quote-table tfoot {
    background: #fff;
    border-top: 1px solid #000;
}

.quote-table tfoot tr {
    border-bottom: 1px solid #000;
}

.quote-table tfoot td {
    font-size: 10pt;
    padding: 8px 5px;
    font-weight: normal;
}

.text-right {
    text-align: right !important;
}

.total-amount,
.vat-amount {
    color: #000;
    font-size: 10pt;
    font-weight: normal;
    text-align: right !important;
}

.quote-table tfoot th,
.quote-table tfoot td.label-col {
    text-align: left;
    font-weight: bold;
}

.grand-total {
    background: #fff !important;
}

.grand-total td {
    color: #000 !important;
    font-size: 10pt;
    font-weight: normal;
}

.grand-total-amount {
    font-size: 10pt !important;
    font-weight: normal;
    text-align: right !important;
}

.quote-notes {
    margin-top: 15px;
    margin-bottom: 15px;
    font-size: 10pt;
    line-height: 1.5;
}

.quote-notes h4 {
    font-size: 10pt;
    font-weight: bold;
    margin-bottom: 5px;
    border: none;
    padding: 0;
    text-decoration: underline;
}

.notes-content {
    font-size: 10pt;
    line-height: 1.5;
}

.notes-content ol {
    padding-left: 20px;
    margin: 0;
}

.notes-content li {
    margin-bottom: 2px;
    line-height: 1.4;
    font-size: 10pt;
}

.notes-content div {
    white-space: pre-line;
    font-size: 10pt;
    line-height: 1.5;
}

.quote-footer {
    margin-top: 15px;
}

.signature-section {
    display: flex;
    justify-content: space-around;
    margin-top: 15px;
}

.signature-box {
    text-align: center;
    width: 250px;
}

.signature-title {
    font-weight: bold;
    font-size: 10pt;
    margin-bottom: 2px;
}

.signature-subtitle {
    font-size: 10pt;
    margin-bottom: 60px; /* Chừa một khoảng lớn để dễ ký tên */
}

.signature-position {
    font-size: 10pt;
    margin-top: 8px;
    font-weight: normal;
    margin-bottom: 2px;
}

.signature-name {
    font-size: 10pt;
    font-weight: normal;
}

.signature-preview {
    margin-top: 10px;
}

.signature-preview img {
    max-width: 200px;
    max-height: 80px;
    border: 1px solid #ddd;
    padding: 5px;
    background: white;
    border-radius: 4px;
}

.signature-image-container {
    margin: 15px 0;
    min-height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    height: 70px;
}

.signature-image-container .signature-img {
    max-width: 200px;
    max-height: 70px;
    width: auto;
    height: auto;
    object-fit: contain;
}

/* Print Styles */
@media print {
    @page {
        size: A4;
        margin: 10mm 15mm;
    }

    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }

    body {
        background: white !important;
        padding: 0;
        margin: 0;
    }

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

    .form-section,
    .action-buttons,
    .products-header,
    .page-nav,
    .btn,
    h1 {
        display: none !important;
    }

    .quote-preview.hidden {
        display: none !important;
    }

    .quote-preview:not(.hidden) {
        display: block !important;
        box-shadow: none !important;
        border: none !important;
        padding: 0 !important;
        margin: 0 !important;
        page-break-inside: avoid;
        width: 100% !important;
        max-width: 100% !important;
    }

    /* Legacy block kept for specificity below */
    .quote-preview {
        box-shadow: none !important;
        border: none !important;
    }

    /* Đảm bảo hình ảnh chữ ký in được */
    .signature-image-container img,
    .signature-img {
        max-width: 180px !important;
        max-height: 70px !important;
        page-break-inside: avoid;
    }

    .signature-section {
        page-break-inside: avoid;
    }

    .signature-box {
        page-break-inside: avoid;
    }

    /* Tránh page break trong các phần quan trọng */
    .quote-header-wrapper,
    .quote-table {
        page-break-inside: avoid;
    }

    /* Cho phép phần ghi chú có thể bị cắt nếu cần, nhưng ưu tiên phần chữ ký */
    .quote-notes {
        page-break-inside: auto;
        margin-top: 10px !important;
        margin-bottom: 10px !important;
    }

    /* Đảm bảo phần chữ ký hiển thị đầy đủ và không rớt sang trang 2 */
    .quote-footer {
        page-break-inside: avoid !important;
        page-break-before: auto !important;
        break-inside: avoid !important;
        margin-top: 10px !important;
        width: 100% !important;
        min-height: 120px !important;
    }

    .signature-section {
        display: flex !important;
        flex-direction: row !important;
        justify-content: space-around !important;
        align-items: flex-start !important;
        margin-top: 10px !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
        visibility: visible !important;
        width: 100% !important;
    }

    .signature-box {
        display: block !important;
        visibility: visible !important;
        width: 250px !important;
        page-break-inside: avoid !important;
        break-inside: avoid !important;
    }

    .signature-title,
    .signature-subtitle,
    .signature-position,
    .signature-name {
        display: block !important;
        visibility: visible !important;
    }

    .signature-image-container {
        display: flex !important;
        visibility: visible !important;
        width: 100% !important;
        min-height: 50px !important;
        height: 70px !important;
        justify-content: center !important;
        align-items: center !important;
    }

    /* Đảm bảo bảng không bị cắt */
    .quote-table {
        page-break-inside: auto;
    }

    .quote-table tr {
        page-break-inside: avoid;
        page-break-after: auto;
    }

    .quote-table thead {
        display: table-header-group;
    }

    .quote-table tfoot {
        display: table-footer-group;
    }
}

/* Responsive */
@media (max-width: 768px) {
    .form-row {
        grid-template-columns: 1fr;
    }

    .products-header {
        grid-template-columns: 1fr;
        gap: 5px;
    }
    
    .product-item {
        grid-template-columns: 1fr;
    }

    .quote-dates {
        flex-direction: column;
        gap: 10px;
    }

    .contact-info {
        flex-direction: column;
        gap: 5px;
    }

    .info-row {
        flex-direction: column;
    }

    .signature-section {
        flex-direction: column;
        align-items: center;
    }

    .action-buttons {
        display: flex;
        flex-direction: column;
        gap: 10px;
    }

    .btn-secondary {
        margin-left: 0;
    }
}
