/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f6fa;
    color: #333;
    line-height: 1.6;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1rem 0;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

.header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.header h1 {
    font-size: 1.8rem;
    font-weight: 600;
}

.header h1 i {
    margin-right: 0.5rem;
    color: #ffd700;
}

/* Buttons */
.btn {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    transition: all 0.3s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.btn-primary {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4);
}

.btn-secondary {
    background: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background: #5a6268;
    transform: translateY(-2px);
}

.btn-danger {
    background: #dc3545;
    color: white;
}

.btn-danger:hover {
    background: #c82333;
    transform: translateY(-2px);
}

.btn-success {
    background: #28a745;
    color: white;
}

.btn-success:hover {
    background: #218838;
    transform: translateY(-2px);
}

.btn-sm {
    padding: 8px 12px;
    font-size: 12px;
    min-width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    transition: all 0.2s ease;
    font-weight: 500;
}

.btn-sm:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* Search Section */
.search-section {
    background: white;
    padding: 1.5rem 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    margin-bottom: 2rem;
}

.search-controls {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 250px;
}

.search-box i {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: #6c757d;
}

.search-box input {
    width: 100%;
    padding: 12px 12px 12px 40px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s ease;
}

.search-box input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.filter-group {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.filter-group select {
    padding: 10px 15px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    background: white;
    color: #333;
    min-width: 120px;
    font-size: 14px;
    cursor: pointer;
    transition: border-color 0.3s ease;
}

.filter-group select:focus {
    outline: none;
    border-color: #667eea;
}

/* Products Section */
.products-section {
    margin-bottom: 2rem;
}

.table-container {
    background: white;
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 4px 20px rgba(0,0,0,0.08);
    overflow-x: auto;
    border: 1px solid #e8ecef;
    margin-bottom: 2rem;
}

.products-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 1000px;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

.products-table th {
    background: #f8f9fa;
    color: #6c757d;
    padding: 16px 15px;
    text-align: left;
    font-weight: 600;
    font-size: 14px;
    white-space: nowrap;
    border-bottom: 1px solid #dee2e6;
    position: sticky;
    top: 0;
    z-index: 10;
}

.products-table td {
    padding: 14px 15px;
    border-bottom: 1px solid #dee2e6;
    vertical-align: middle;
    font-size: 14px;
    line-height: 1.5;
    color: #495057;
    transition: background-color 0.2s ease;
}

.products-table tbody tr {
    transition: background-color 0.2s ease;
}

.products-table tbody tr:hover {
    background-color: #f8f9fa;
}

.products-table tbody tr:nth-child(even) {
    background-color: #ffffff;
}

.products-table tbody tr:nth-child(even):hover {
    background-color: #f8f9fa;
}

.product-image {
    width: 55px;
    height: 55px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid #e2e8f0;
    transition: transform 0.2s ease;
}

.product-image:hover {
    transform: scale(1.05);
    border-color: #4299e1;
}

.product-code {
    font-weight: 600;
    color: #495057;
    font-size: 14px;
    font-family: "Monaco", "Menlo", "Ubuntu Mono", monospace;
    background: transparent;
    padding: 0;
    border-radius: 0;
    border: none;
    display: inline-block;
    transition: all 0.2s ease;
}

.product-code:hover {
    color: #343a40;
}

.status-badge {
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: inline-block;
    min-width: 75px;
    text-align: center;
    transition: transform 0.2s ease;
}

.status-badge:hover {
    transform: translateY(-1px);
}

.status-active {
    background: #28a745;
    color: white;
    border: none;
}

.status-inactive {
    background: #ffc107;
    color: white;
    border: none;
}

.status-out_of_stock {
    background: #dc3545;
    color: white;
    border: none;
}

.status-discontinued {
    background: #6c757d;
    color: white;
    border: none;
}

.action-buttons {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    justify-content: center;
}

.location-info {
    font-size: 13px;
    color: #6c757d;
    line-height: 1.4;
    background: transparent;
    padding: 0;
    border-radius: 0;
    border: none;
    font-weight: 400;
    transition: all 0.2s ease;
}

.location-info:hover {
    color: #495057;
}

/* Loading and No Data */
.loading, .no-data {
    text-align: center;
    padding: 3rem;
    color: #6c757d;
}

.loading i {
    font-size: 2rem;
    margin-bottom: 1rem;
}

.no-data i {
    font-size: 4rem;
    margin-bottom: 1rem;
    color: #dee2e6;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    backdrop-filter: blur(5px);
}

.modal-content {
    background-color: white;
    margin: 2% auto;
    padding: 0;
    border-radius: 12px;
    width: 90%;
    max-width: 800px;
    max-height: 95vh;
    overflow-y: auto;
    box-shadow: 0 10px 30px rgba(0,0,0,0.3);
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from { opacity: 0; transform: translateY(-50px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
}

.close-btn {
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 30px;
    height: 30px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.3s ease;
}

.close-btn:hover {
    background-color: rgba(255,255,255,0.2);
}

/* Form Styles */
#productForm {
    padding: 2rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.form-group {
    display: flex;
    flex-direction: column;
}

.form-group.full-width {
    grid-column: 1 / -1;
}

.form-group label {
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #333;
}

.form-group input,
.form-group select,
.form-group textarea {
    padding: 12px;
    border: 2px solid #e9ecef;
    border-radius: 8px;
    font-size: 14px;
    transition: border-color 0.3s ease;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.location-section,
.dimensions-section,
.images-section {
    margin-bottom: 2rem;
    padding: 1.5rem;
    background: #f8f9fa;
    border-radius: 8px;
    border-left: 4px solid #667eea;
}

.location-section h3,
.dimensions-section h3,
.images-section h3 {
    margin-bottom: 1rem;
    color: #667eea;
    font-size: 1.2rem;
}

/* Image Upload */
.image-upload {
    margin-bottom: 1rem;
}

.image-upload input[type="file"] {
    display: none;
}

.upload-label {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    border: 2px dashed #dee2e6;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    background: #fafbfc;
}

.upload-label:hover {
    border-color: #667eea;
    background: #f0f2ff;
}

.upload-label i {
    font-size: 2rem;
    color: #6c757d;
    margin-bottom: 0.5rem;
}

.image-preview {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.image-preview-item {
    position: relative;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #e9ecef;
}

.image-preview-item img {
    width: 100%;
    height: 100px;
    object-fit: cover;
}

.image-preview-item .remove-image {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(220, 53, 69, 0.8);
    color: white;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    cursor: pointer;
    font-size: 12px;
}

/* Styles for existing vs new images */
.image-preview-item.existing-image {
    border-color: #28a745;
}

.image-preview-item.existing-image::before {
    content: "มีอยู่แล้ว";
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(40, 167, 69, 0.9);
    color: white;
    font-size: 10px;
    text-align: center;
    padding: 2px;
}

.image-preview-item.new-image-preview {
    border-color: #667eea;
}

.image-preview-item.new-image-preview::before {
    content: "ใหม่";
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(102, 126, 234, 0.9);
    color: white;
    font-size: 10px;
    text-align: center;
    padding: 2px;
}

/* Form Actions */
.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    padding-top: 2rem;
    border-top: 1px solid #e9ecef;
}

/* Product Details */
.product-details {
    padding: 2rem;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.detail-item {
    display: flex;
    flex-direction: column;
}

.detail-label {
    font-weight: 600;
    color: #6c757d;
    margin-bottom: 0.25rem;
    font-size: 0.9rem;
}

.detail-value {
    font-size: 1rem;
    color: #333;
}

.product-images-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.product-images-gallery img {
    width: 100%;
    height: 150px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid #e9ecef;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.product-images-gallery img:hover {
    transform: scale(1.05);
}

/* Toast Notification */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 2000;
    background: white;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transform: translateX(400px);
    transition: transform 0.3s ease;
    max-width: 300px;
}

.toast.show {
    transform: translateX(0);
}

.toast-content {
    padding: 1rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toast-icon {
    font-size: 1.2rem;
}

.toast.success .toast-icon { color: #28a745; }
.toast.error .toast-icon { color: #dc3545; }
.toast.warning .toast-icon { color: #ffc107; }
.toast.info .toast-icon { color: #17a2b8; }

.toast-message {
    font-size: 14px;
    color: #333;
}

/* Table Styling */
.products-table td strong {
    color: #495057;
    font-weight: 600;
}

.products-table td:nth-child(6) strong {
    color: #007bff;
    font-weight: 700;
}

.products-table td:nth-child(7),
.products-table td:nth-child(8) {
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', monospace;
    font-weight: 600;
    color: #495057;
}

/* Enhanced spacing and alignment */
.products-table th:first-child,
.products-table th:nth-child(6),
.products-table th:nth-child(7),
.products-table th:nth-child(8),
.products-table th:nth-child(11) {
    text-align: center;
}

.products-table td:first-child,
.products-table td:nth-child(6),
.products-table td:nth-child(7),
.products-table td:nth-child(8),
.products-table td:nth-child(11) {
    text-align: center;
}

/* Make all numbers blue like in the image */
.products-table td:nth-child(6),
.products-table td:nth-child(7), 
.products-table td:nth-child(8) {
    color: #007bff;
    font-weight: 600;
}

/* Product name styling */
.products-table td:nth-child(3) strong {
    color: #495057;
    font-size: 15px;
    font-weight: 600;
}

/* Clean borders */
.products-table thead tr th:first-child {
    border-top-left-radius: 16px;
}

.products-table thead tr th:last-child {
    border-top-right-radius: 16px;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 0 15px;
    }
    
    .header h1 {
        font-size: 1.5rem;
    }
    
    .btn-text {
        display: none;
    }
    
    .search-controls {
        flex-direction: column;
    }
    
    .search-box {
        min-width: 100%;
    }
    
    .filter-group {
        width: 100%;
        justify-content: space-between;
    }
    
    .filter-group select {
        flex: 1;
        min-width: auto;
    }
    
    .hide-mobile {
        display: none;
    }
    
    .products-table td {
        padding: 12px 8px;
        font-size: 13px;
    }
    
    .products-table th {
        padding: 15px 8px;
        font-size: 13px;
    }
    
    .product-image {
        width: 45px;
        height: 45px;
    }
    
    .action-buttons {
        flex-direction: column;
    }
    
    .btn-sm {
        padding: 8px 12px;
        width: 100%;
        justify-content: center;
    }
    
    .modal-content {
        width: 95%;
        margin: 5% auto;
        max-height: 90vh;
    }
    
    #productForm {
        padding: 1rem;
    }
    
    .form-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }
    
    .location-section,
    .dimensions-section,
    .images-section {
        padding: 1rem;
    }
    
    .form-actions {
        flex-direction: column-reverse;
    }
    
    .form-actions .btn {
        width: 100%;
        justify-content: center;
    }
    
    .toast {
        right: 10px;
        left: 10px;
        max-width: none;
        transform: translateX(0) translateY(-100px);
    }
    
    .toast.show {
        transform: translateX(0) translateY(0);
    }
}

@media (max-width: 480px) {
    .header .container {
        flex-direction: column;
        text-align: center;
    }
    
    .products-table {
        min-width: 600px;
    }
    
    .image-preview {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    }
    
    .image-preview-item img {
        height: 80px;
    }
    
    .product-images-gallery {
        grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
    }
    
    .product-images-gallery img {
        height: 120px;
    }
}

/* iPad and Tablet Optimizations */
@media (min-width: 768px) and (max-width: 1024px) {
    .form-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .products-table {
        font-size: 14px;
    }
    
    .modal-content {
        width: 85%;
    }
    
    .search-controls {
        flex-wrap: nowrap;
    }
    
    .filter-group {
        gap: 0.5rem;
    }
    
    .filter-group select {
        min-width: 100px;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    body {
        background-color: #1a1a1a;
        color: #f0f0f0;
    }
    
    .table-container,
    .modal-content,
    .search-section {
        background: #2d2d2d;
    }
    
    .products-table td {
        border-bottom-color: #404040;
    }
    
    .products-table tbody tr:hover {
        background-color: #404040;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        background: #404040;
        border-color: #555;
        color: #f0f0f0;
    }
    
    .location-section,
    .dimensions-section,
    .images-section {
        background: #404040;
    }
}
/* Incomplete Data Indicator */
.incomplete-data-indicator {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    width: 50px;
    height: 50px;
    margin-right: 10px;
    animation: pulse 2s infinite;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(220, 53, 69, 0.3);
    transition: transform 0.2s ease;
}

.incomplete-data-indicator:hover {
    transform: scale(1.05);
}

.incomplete-data-indicator i {
    font-size: 16px;
    margin-right: 5px;
}

.incomplete-data-indicator span {
    font-weight: bold;
    font-size: 14px;
}

.indicator-tooltip {
    position: absolute;
    bottom: -35px;
    left: 50%;
    transform: translateX(-50%);
    background: #333;
    color: white;
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease;
    z-index: 1000;
}

.incomplete-data-indicator:hover .indicator-tooltip {
    opacity: 1;
    visibility: visible;
}

.indicator-tooltip::before {
    content: '';
    position: absolute;
    top: -5px;
    left: 50%;
    transform: translateX(-50%);
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid #333;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7);
    }
    70% {
        box-shadow: 0 0 0 10px rgba(220, 53, 69, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(220, 53, 69, 0);
    }
}

/* Incomplete Data Row Warning */
.products-table tbody tr.incomplete-data {
    border: 2px solid #dc3545 !important;
    background-color: #fff5f5 !important;
    position: relative;
}

.products-table tbody tr.incomplete-data:hover {
    background-color: #fee !important;
}

.products-table tbody tr.incomplete-data::before {
    content: '';
    position: absolute;
    top: -2px;
    right: -2px;
    width: 0;
    height: 0;
    border-left: 20px solid transparent;
    border-top: 20px solid #dc3545;
    z-index: 10;
}

.products-table tbody tr.incomplete-data::after {
    content: '!';
    position: absolute;
    top: 2px;
    right: 2px;
    color: white;
    font-size: 12px;
    font-weight: bold;
    z-index: 11;
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Required fields indicator in table */
.required-field-missing {
    color: #dc3545 !important;
    font-style: italic;
    opacity: 0.7;
}

.required-field-missing::after {
    content: ' (ต้องระบุ)';
    font-size: 11px;
    color: #dc3545;
}

/* Row Missing Fields Indicator - มุมขวาบน */
/* Row Missing Fields Indicator - วงกลมแดงมุมขวาบนของ cell รูปภาพ */
.row-missing-indicator {
    position: absolute;
    top: 5px;
    right: 5px;
    background: #dc3545;
    color: white;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: bold;
    z-index: 10;
    cursor: help;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
    border: 1px solid white;
    line-height: 1;
    pointer-events: auto;
}

.row-missing-indicator:hover {
    transform: scale(1.1);
    box-shadow: 0 2px 6px rgba(220, 53, 69, 0.6);
    z-index: 11;
}

.row-missing-indicator .missing-count {
    color: white;
    font-size: 9px;
    font-weight: bold;
    text-shadow: none;
}


/* Enhanced Incomplete Data Indicator in Header */
.incomplete-data-indicator {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #dc3545, #c82333);
    color: white;
    border-radius: 25px;
    padding: 8px 16px;
    margin-right: 10px;
    animation: pulse 2s infinite;
    cursor: pointer;
    box-shadow: 0 2px 10px rgba(220, 53, 69, 0.3);
    transition: all 0.3s ease;
    border: 2px solid rgba(255, 255, 255, 0.2);
    min-width: 70px;
    font-size: 12px;
    font-weight: bold;
}

.incomplete-data-indicator:hover {
    background: linear-gradient(135deg, #c82333, #bd2130);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(220, 53, 69, 0.5);
}

.incomplete-data-indicator i {
    margin-right: 6px;
    font-size: 14px;
}

.incomplete-data-indicator #incompleteDataCount {
    font-size: 12px;
    font-weight: bold;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* Responsive adjustments for row indicators */
@media (max-width: 768px) {
    .row-missing-indicator {
        width: 24px;
        height: 24px;
        font-size: 10px;
        top: -8px;
        right: -8px;
    }

    .incomplete-data-indicator {
        padding: 6px 12px;
        font-size: 11px;
        min-width: 60px;
    }
}

@media (max-width: 480px) {
    .row-missing-indicator {
        width: 22px;
        height: 22px;
        font-size: 9px;
        top: -6px;
        right: -6px;
    }

    .incomplete-data-indicator {
        padding: 4px 8px;
        font-size: 10px;
        min-width: 50px;
    }

    .incomplete-data-indicator i {
        display: none;
    }
}
/* แก้ไขการตั้งค่าแถวให้รองรับ indicator โดยไม่เพี้ยนตาราง */
.products-table tbody tr {
    position: relative;
}

/* ลบ styling เดิมที่ทำให้ตารางเพี้ยน */
.products-table tbody tr.incomplete-data::before,
.products-table tbody tr.incomplete-data::after {
    display: none !important;
}

/* ปรับปรุง incomplete data row ให้ไม่มี border ที่รบกวน */
.products-table tbody tr.incomplete-data {
    background-color: #fff5f5 !important;
    border: none !important;
}

.products-table tbody tr.incomplete-data:hover {
    background-color: #fee !important;
}