/* Custom styles for Quotation System */
body {
    background: #f0f2f5;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    min-height: 100vh;
}

.navbar {
    border-bottom: 1px solid #e0e0e0;
}

.navbar-brand {
    font-weight: bold;
    font-size: 1.5rem;
}

.card {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    background: #ffffff;
    margin-bottom: 1.5rem;
}

.card-header {
    background-color: #ffffff;
    border-bottom: 2px solid #0d6efd;
    font-weight: 600;
    color: #0d6efd;
    padding: 1rem 1.25rem;
}

.table th {
    background-color: #343a40;
    color: white;
    border: none;
    font-weight: 600;
    text-align: center;
    vertical-align: middle;
}

.table td {
    vertical-align: middle;
    border: 1px solid #dee2e6;
}

.table input, .table textarea, .table select {
    border: none;
    background: transparent;
    width: 100%;
    padding: 0.375rem;
}

.table input:focus, .table textarea:focus, .table select:focus {
    outline: 2px solid #0d6efd;
    outline-offset: -2px;
    background: white;
}

.form-control {
    border: 2px solid #e0e0e0;
    border-radius: 6px;
    padding: 0.6rem 0.75rem;
    font-size: 0.95rem;
    transition: all 0.2s ease;
}

.form-control:focus {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
    background-color: #ffffff;
}

.form-control[readonly] {
    background-color: #f8f9fa;
    border-color: #dee2e6;
    color: #6c757d;
    cursor: not-allowed;
}

.form-label {
    font-weight: 600;
    color: #495057;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.quotation-card {
    transition: all 0.2s ease-in-out;
    cursor: pointer;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #e0e0e0;
}

.quotation-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.12);
    border-color: #0d6efd;
}

.quotation-preview {
    background: white;
    padding: 1.5rem;
    font-family: 'Times New Roman', serif;
    line-height: 1.6;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    width: 1280px; /* mô phỏng bề ngang A4 landscape */
    max-width: 100%;
    margin: 0 auto;
}

/* Preview modal full-width để hiển thị ngang */
#previewModal .modal-dialog {
    max-width: 100vw;
    width: 100vw;
    margin: 10px auto;
}

#previewModal .modal-content {
    width: 100%;
}

#previewModal .modal-body {
    overflow-x: auto;
}

#previewContent {
    display: flex;
    justify-content: center;
}

/* Khi xuất PDF, ép khổ ngang rộng hơn để canvas to hơn */
#previewContent.pdf-export .quotation-preview {
    width: 2200px;        /* rộng hơn cho ảnh PDF */
    max-width: none;
    padding: 8px 12px;    /* thu nhỏ padding để ăn hết bề ngang */
}

.quotation-header {
    text-align: center;
    margin-bottom: 3rem;
    padding: 2rem;
    background: #f8f9fa;
    border-radius: 8px;
    border: 1px solid #e0e0e0;
}

.quotation-title {
    font-size: 1.6rem;
    font-weight: bold;
    color: #2c3e50;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.quotation-subtitle {
    font-size: 1.2rem;
    color: #34495e;
    font-weight: 500;
}

.quotation-meta {
    margin-top: 6px;
    color: #6c757d;
    font-style: italic;
}

.quotation-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 2rem;
}

.quotation-info .info-section {
    flex: 1;
    margin: 0 1rem;
}

.quotation-info h6 {
    font-weight: bold;
    margin-bottom: 0.5rem;
    color: #333;
}

.quotation-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 2rem;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    table-layout: fixed; /* Force fixed column widths */
}

.quotation-table th,
.quotation-table td {
    border: 1px solid #dee2e6;
    padding: 0.75rem;
    text-align: center;
}

.quotation-table th {
    background: #0d6efd;
    color: white;
    font-weight: bold;
    font-size: 0.9rem;
}

.quotation-table .text-left {
    text-align: left;
    padding-left: 0.75rem;
}

.quotation-table td:nth-child(8) {
    text-align: left;
    padding-left: 0.75rem;
}

/* Column width adjustments for preview/PDF/print */
.quotation-table th:nth-child(1),
.quotation-table td:nth-child(1) {
    width: 4% !important;
    max-width: 4% !important;
}

.quotation-table th:nth-child(2),
.quotation-table td:nth-child(2) {
    width: 38% !important;
    max-width: 38% !important;
}

.quotation-table th:nth-child(3),
.quotation-table td:nth-child(3) {
    width: 17% !important;
    max-width: 17% !important;
}

.quotation-table th:nth-child(4),
.quotation-table td:nth-child(4) {
    width: 6% !important;
    max-width: 6% !important;
}

.quotation-table th:nth-child(5),
.quotation-table td:nth-child(5) {
    width: 6% !important;
    max-width: 6% !important;
}

.quotation-table th:nth-child(6),
.quotation-table td:nth-child(6) {
    width: 9% !important;
    max-width: 9% !important;
}

.quotation-table th:nth-child(7),
.quotation-table td:nth-child(7) {
    width: 9% !important;
    max-width: 9% !important;
}

.quotation-table th:nth-child(8),
.quotation-table td:nth-child(8) {
    width: 17% !important;
    max-width: 17% !important;
}

/* Column width adjustments for FORM (editing table) */
#productsTable th:nth-child(1),
#productsTable td:nth-child(1) {
    width: 4% !important;
}

#productsTable th:nth-child(2),
#productsTable td:nth-child(2) {
    width: 35% !important; /* Wider for description */
}

#productsTable th:nth-child(3),
#productsTable td:nth-child(3) {
    width: 10% !important;
}

#productsTable th:nth-child(4),
#productsTable td:nth-child(4) {
    width: 6% !important;
}

#productsTable th:nth-child(5),
#productsTable td:nth-child(5) {
    width: 7% !important;
}

#productsTable th:nth-child(6),
#productsTable td:nth-child(6) {
    width: 9% !important;
}

#productsTable th:nth-child(7),
#productsTable td:nth-child(7) {
    width: 9% !important;
}

#productsTable th:nth-child(8),
#productsTable td:nth-child(8) {
    width: 20% !important; /* Wider for notes */
}

.total-row {
    background-color: #f8f9fa;
    font-weight: bold;
    border-top: 2px solid #2c3e50;
}

.total-row td {
    padding: 1rem 0.75rem;
    font-size: 1.1rem;
}

.quotation-notes {
    margin-top: 2rem;
    padding-top: 1rem;
    border-top: 1px solid #ccc;
}

.quotation-signature {
    margin-top: 1rem; /* move up ~2 lines */
    padding: 0.5rem 0 0.5rem 0;
    background: transparent; /* remove background */
    border-radius: 0;
    border: none; /* remove outline border */
}

.quotation-signature .col-6:first-child {
    display: flex;
    align-items: center;
    font-weight: bold;
    color: #2c3e50;
}

.signature-right {
    display: flex;
    justify-content: flex-end; /* push to far right */
    padding-right: 0;
}

.signature-block {
    width: 320px; /* compact block */
    margin-right: 0;
    margin-top: 0; /* reduce top space */
}

.signature-block {
    font-style: italic;
    line-height: 1.8;
    margin: 0;
}

.total-words-row {
    background-color: #f8f9fa;
    font-style: italic;
    border-top: 1px solid #dee2e6;
}

.total-words-row td {
    padding: 0.75rem;
    font-size: 0.9rem;
    color: #2c3e50;
}

.amount-in-words {
    font-size: 0.95rem; /* increase by one step */
    color: #495057;
}

.signature-line {
    width: 300px;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, #2c3e50 50%, transparent 100%);
    margin: 30px auto;
    position: relative;
}

.signature-line::after {
    content: '';
    position: absolute;
    top: -8px;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent 0%, #2c3e50 50%, transparent 100%);
}

.signature-name {
    font-weight: bold;
    margin-top: 10px;
    font-size: 1.1rem;
}

.btn-group .btn {
    margin-right: 0.5rem;
}

.btn-group .btn:last-child {
    margin-right: 0;
}

/* Print styles */
@media print {
    body {
        background: white;
        margin: 10px;
    }
    
    .navbar, .btn, .modal, .card-header {
        display: none !important;
    }
    
    .quotation-preview {
        padding: 0;
        box-shadow: none;
        border: none;
    }
    
    .container {
        max-width: none;
        padding: 0;
    }
    
    .quotation-header {
        padding: 1rem;
    }
}

/* Loading animation */
.loading {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid #3498db;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Responsive adjustments */
@media (max-width: 768px) {
    .quotation-info {
        flex-direction: column;
    }
    
    .quotation-info .info-section {
        margin: 0.5rem 0;
    }
    
    .table-responsive {
        font-size: 0.875rem;
    }
    
    .btn-group {
        flex-direction: column;
    }
    
    .btn-group .btn {
        margin-bottom: 0.5rem;
        margin-right: 0;
    }
}

/* Login screen */
.login-screen {
    position: fixed;
    inset: 0;
    background: linear-gradient(135deg, #e9f0ff 0%, #f7f9fc 100%);
    z-index: 2000;
}

.login-box {
    background: #fff;
    border-radius: 12px;
    padding: 24px;
    width: 360px;
    max-width: 90%;
}

.mobile-full {
    width: 100%;
}

@media (max-width: 768px) {
    .search-box {
        width: 100%;
    }

    .search-box input {
        width: 100%;
    }

    .quotation-card {
        margin-bottom: 0.75rem;
    }

    .modal-dialog {
        margin: 0.5rem;
    }

    .modal-content {
        border-radius: 10px;
    }

    .quotation-info {
        flex-direction: column;
    }
    
    .quotation-info .info-section {
        margin: 0.5rem 0;
    }
    
    .table-responsive {
        font-size: 0.875rem;
    }
    
    .btn-group {
        flex-direction: column;
    }
    
    .btn-group .btn {
        margin-bottom: 0.5rem;
        margin-right: 0;
    }

    .navbar .btn {
        width: 100%;
        margin-top: 8px;
    }

    .navbar .container {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }

    .login-box {
        width: 92%;
        padding: 20px 16px;
    }

    .card {
        margin-bottom: 1rem;
    }

    .table-responsive {
        font-size: 0.9rem;
        overflow-x: auto;
    }

    .quotation-table th,
    .quotation-table td {
        padding: 0.4rem 0.35rem;
        font-size: 12px;
    }

    .quotation-header {
        padding: 1rem 0.5rem;
    }

    .quotation-title {
        font-size: 1.2rem;
    }

    .quotation-subtitle {
        font-size: 1rem;
    }

    .quotation-info .info-section {
        margin: 0.25rem 0;
    }

    #productsTable th,
    #productsTable td {
        padding: 0.35rem 0.3rem;
        font-size: 12px;
    }

    .d-flex.justify-content-between.mb-4,
    .d-flex.justify-content-between.align-items-center.mb-4 {
        flex-direction: column;
        gap: 8px;
        align-items: stretch !important;
    }

    .d-flex.justify-content-between.mb-4 .btn,
    .d-flex.justify-content-between.align-items-center.mb-4 .btn {
        width: 100%;
    }

    .btn-group.w-100 {
        display: grid;
        grid-template-columns: repeat(2, 1fr);
        gap: 6px;
    }
}

/* Mobile/tablet stacked layout for product rows */
@media (max-width: 992px) {
    #productsTable,
    #productsTable thead,
    #productsTable tbody,
    #productsTable th,
    #productsTable td,
    #productsTable tr {
        display: block;
        width: 100% !important;
    }

    #productsTable thead {
        display: none;
    }

    #productsTable tbody tr {
        margin-bottom: 12px;
        border: 1px solid #dee2e6;
        border-radius: 10px;
        padding: 12px;
        background: #fff;
        box-shadow: 0 1px 4px rgba(0,0,0,0.08);
    }

    #productsTable tbody tr td {
        display: block;
        width: 100%;
        padding: 12px 8px;
        border: none;
        font-size: 13px;
    }

    #productsTable tbody tr td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #495057;
        display: inline-block;
        white-space: nowrap;
        margin-bottom: 6px;
    }

    #productsTable tbody tr td:first-child {
        display: flex;
        align-items: center;
        gap: 8px;
    }

    #productsTable tbody tr td:first-child::before {
        margin-bottom: 0;
    }

#productsTable tbody tr td .form-control,
    #productsTable tbody tr td input {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
        display: block !important;
        box-sizing: border-box;
        background: #fff;
        border: 1px solid #b8bec6;
        border-radius: 10px;
        padding: 14px;
        font-size: 15px;
        min-height: 44px;
        box-shadow: none;
    }

    #productsTable tbody tr td input.product-name,
    #productsTable tbody tr td:nth-child(3) input,
    #productsTable tbody tr td:nth-child(8) input {
        text-align: left;
    }

    #productsTable tbody tr td input.price,
    #productsTable tbody tr td input.quantity {
        text-align: right;
    }
}

/* Strong override: mobile/tablet product inputs full width */
@media (max-width: 1200px) {
    #productsTable tbody tr td {
        display: flex !important;
        flex-direction: column !important;
        align-items: stretch !important;
    }

    #productsTable tbody tr td::before {
        margin-bottom: 8px !important;
        white-space: normal !important;
    }

    #productsTable tbody tr td .form-control,
    #productsTable tbody tr td input {
        width: 100% !important;
        max-width: 100% !important;
        min-width: 100% !important;
        display: block !important;
        box-sizing: border-box !important;
        padding: 16px 16px !important;
        font-size: 16px !important;
        min-height: 52px !important;
        border-radius: 12px !important;
    }
}
