/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    padding: 20px;
    color: #333;
}

.container {
    max-width: 95%;
    margin: 0 auto;
    background: white;
    border-radius: 15px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    overflow: hidden;
    padding: 25px;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px 0;
    border-bottom: 2px solid #eee;
    margin-bottom: 25px;
    flex-wrap: wrap;
    gap: 15px;
}

.header h1 {
    font-size: 28px;
    color: #2d3748;
    display: flex;
    align-items: center;
    gap: 15px;
}

.header h1 i {
    color: #667eea;
    font-size: 32px;
}

.header-info {
    display: flex;
    gap: 20px;
    align-items: center;
    flex-wrap: wrap;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
}

.status-dot.connected {
    background-color: #10b981;
    box-shadow: 0 0 10px #10b981;
    animation: pulse 2s infinite;
}

.status-dot.disconnected {
    background-color: #ef4444;
}

.status-indicator .connected {
    color: #10b981;
    font-weight: bold;
}

.status-indicator .disconnected {
    color: #ef4444;
    font-weight: bold;
}

.last-update {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #6b7280;
    font-size: 14px;
}

@keyframes pulse {
    0% { opacity: 1; }
    50% { opacity: 0.5; }
    100% { opacity: 1; }
}

/* Buttons */
.btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition: all 0.3s ease;
    font-size: 14px;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 10px 20px rgba(102, 126, 234, 0.3);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.btn i {
    font-size: 16px;
}

.btn-small {
    padding: 6px 12px;
    font-size: 13px;
    background: #667eea;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
}

.btn-small:hover {
    background: #5a67d8;
    transform: translateY(-1px);
}

.btn-small:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

/* Controls */
.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    flex-wrap: wrap;
    gap: 15px;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 300px;
}

.search-box input {
    width: 100%;
    padding: 12px 20px 12px 45px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 16px;
    transition: all 0.3s ease;
}

.search-box input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.search-box i {
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    color: #9ca3af;
}

.filters {
    display: flex;
    gap: 15px;
}

.filters select {
    padding: 10px 15px;
    border: 2px solid #e5e7eb;
    border-radius: 8px;
    font-size: 14px;
    background: white;
    min-width: 150px;
    cursor: pointer;
}

.filters select:focus {
    outline: none;
    border-color: #667eea;
}

/* Stats */
.stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: white;
    padding: 25px;
    border-radius: 12px;
    text-align: center;
    transition: transform 0.3s ease;
}

.stat-card:hover {
    transform: translateY(-5px);
}

.stat-card h3 {
    font-size: 16px;
    margin-bottom: 10px;
    opacity: 0.9;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
}

.stat-card p {
    font-size: 32px;
    font-weight: bold;
    text-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Table Container */
.table-container {
    background: white;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid #e5e7eb;
}

.table-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: #f9fafb;
    border-bottom: 1px solid #e5e7eb;
    flex-wrap: wrap;
    gap: 15px;
}

.table-header h2 {
    font-size: 20px;
    color: #2d3748;
    display: flex;
    align-items: center;
    gap: 10px;
}

.table-actions {
    display: flex;
    align-items: center;
    gap: 15px;
}

.items-count {
    color: #6b7280;
    font-size: 14px;
}

/* Table */
.table-responsive {
    overflow-x: auto;
    width: 100%;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1800px;
}

thead {
    background: #f3f4f6;
    position: sticky;
    top: 0;
    z-index: 10;
}

th {
    padding: 12px 8px;
    text-align: left;
    font-weight: 600;
    color: #374151;
    border-bottom: 2px solid #e5e7eb;
    white-space: nowrap;
    font-size: 13px;
    position: relative;
}

td {
    padding: 10px 8px;
    border-bottom: 1px solid #e5e7eb;
    font-size: 13px;
    vertical-align: middle;
}

tbody tr {
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background-color: #f9fafb;
}

/* Alignment */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

/* Small buttons */
.preview-btn, .download-btn-small {
    background: #667eea;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    text-decoration: none;
    height: 24px;
    width: 24px;
}

.preview-btn:hover, .download-btn-small:hover {
    background: #5a67d8;
    transform: translateY(-1px);
}

.download-btn-small {
    background: #48bb78;
    margin-left: 4px;
}

.download-btn-small:hover {
    background: #38a169;
}

/* Document containers */
.doc-preview, .documents-container, .photos-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    flex-wrap: wrap;
}

.document-item {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin: 2px;
}

.doc-number {
    font-size: 10px;
    color: #6b7280;
    background: #f3f4f6;
    padding: 1px 4px;
    border-radius: 2px;
}

/* Photo viewer button */
.view-photos-btn {
    background: #4caf50;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    display: inline-flex;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
    margin-right: 5px;
    height: 28px;
}

.view-photos-btn:hover {
    background: #388e3c;
    transform: translateY(-1px);
}

/* Status badges */
.status-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    display: inline-block;
    min-width: 60px;
    text-align: center;
}

.status-open {
    background-color: #d1fae5;
    color: #065f46;
}

.status-closed {
    background-color: #fee2e2;
    color: #991b1b;
}

/* Remarks Container */
.remarks-container {
    max-width: 250px;
    word-wrap: break-word;
    white-space: normal;
}

.remarks-preview {
    max-height: 60px;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    line-height: 1.4;
    font-size: 13px;
    color: #374151;
    white-space: normal;
    word-wrap: break-word;
}

.view-remarks-btn {
    background: transparent;
    border: none;
    color: #667eea;
    cursor: pointer;
    font-size: 11px;
    padding: 2px 6px;
    margin-top: 3px;
    display: inline-flex;
    align-items: center;
    gap: 3px;
    transition: all 0.2s ease;
}

.view-remarks-btn:hover {
    color: #5a67d8;
    text-decoration: underline;
}

/* Loading */
.loading {
    padding: 40px;
    text-align: center;
    color: #6b7280;
    font-size: 16px;
}

.loading i {
    margin-right: 10px;
    font-size: 20px;
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    gap: 20px;
    border-top: 1px solid #e5e7eb;
    background: #f9fafb;
}

.page-info {
    color: #6b7280;
    font-size: 14px;
}

/* Notification */
.notification {
    position: fixed;
    bottom: 20px;
    right: 20px;
    padding: 15px 25px;
    border-radius: 8px;
    color: white;
    display: flex;
    align-items: center;
    gap: 10px;
    z-index: 1000;
    display: none;
    box-shadow: 0 5px 15px rgba(0,0,0,0.2);
    animation: slideIn 0.3s ease;
    max-width: 400px;
}

.notification.info {
    background: #2196f3;
}

.notification.success {
    background: #4caf50;
}

.notification.warning {
    background: #ff9800;
}

.notification.error {
    background: #f44336;
}

@keyframes slideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Image Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    z-index: 1000;
    overflow-y: auto;
}

.modal-content {
    background: white;
    margin: 50px auto;
    width: 90%;
    max-width: 1200px;
    border-radius: 12px;
    overflow: hidden;
    animation: modalFadeIn 0.3s ease;
}

@keyframes modalFadeIn {
    from {
        opacity: 0;
        transform: translateY(-50px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    background: #f3f4f6;
    border-bottom: 1px solid #e5e7eb;
}

.modal-header h2 {
    font-size: 24px;
    color: #2d3748;
}

.close-modal, .close-doc-modal, .close-remarks-modal, .close-single-image-modal {
    background: none;
    border: none;
    font-size: 28px;
    color: #6b7280;
    cursor: pointer;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: all 0.2s ease;
}

.close-modal:hover, .close-doc-modal:hover, .close-remarks-modal:hover, .close-single-image-modal:hover {
    background: #e5e7eb;
    color: #374151;
}

/* Image gallery */
.image-gallery {
    display: flex;
    flex-wrap: wrap;
    padding: 20px;
    gap: 20px;
    justify-content: center;
}

.image-item {
    border: 1px solid #ddd;
    border-radius: 8px;
    overflow: hidden;
    background: white;
    width: 250px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.1);
    transition: transform 0.3s ease;
}

.image-item:hover {
    transform: translateY(-5px);
    box-shadow: 0 8px 15px rgba(0,0,0,0.2);
}

.image-item img {
    width: 100%;
    height: 200px;
    display: block;
    object-fit: cover;
    background: #f5f5f5;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.image-item img:hover {
    transform: scale(1.05);
}

.image-info {
    padding: 10px;
    background: #f9fafb;
    border-bottom: 1px solid #eee;
    font-size: 12px;
    display: flex;
    justify-content: space-between;
    color: #6b7280;
}

.image-actions {
    display: flex;
    justify-content: space-around;
    padding: 12px;
    background: #f9fafb;
    gap: 10px;
}

.download-btn, .view-btn {
    padding: 8px 16px;
    text-decoration: none;
    color: white;
    border-radius: 4px;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    flex: 1;
    text-align: center;
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
}

.download-btn {
    background: #2196f3;
}

.download-btn:hover {
    background: #1976d2;
    transform: translateY(-1px);
}

.view-btn {
    background: #4caf50;
}

.view-btn:hover {
    background: #388e3c;
    transform: translateY(-1px);
}

/* Modal actions */
.modal-actions {
    display: flex;
    gap: 15px;
    align-items: center;
}

/* Remarks Modal */
.remarks-viewer {
    max-width: 600px;
}

.remarks-content {
    padding: 25px;
    max-height: 400px;
    overflow-y: auto;
    font-size: 15px;
    line-height: 1.6;
    color: #374151;
    background: #f9fafb;
    border-radius: 8px;
    margin: 15px;
    white-space: pre-wrap;
    word-wrap: break-word;
}

.remarks-info {
    padding: 15px 25px;
    border-top: 1px solid #e5e7eb;
    background: #f3f4f6;
}

.remarks-contract-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 10px;
    font-size: 14px;
}

.remarks-contract-info div {
    padding: 5px 0;
}

.remarks-contract-info strong {
    color: #374151;
    min-width: 100px;
    display: inline-block;
}

/* Single Image Modal */
.single-image-viewer {
    max-width: 900px;
}

.image-preview-container {
    text-align: center;
    padding: 20px;
    background: #000;
    min-height: 400px;
    display: flex;
    align-items: center;
    justify-content: center;
}

#singleImageView {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
}

.single-image-info {
    padding: 15px 25px;
    background: #f3f4f6;
    border-top: 1px solid #e5e7eb;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.single-image-info div {
    font-size: 14px;
    color: #374151;
}

.single-image-info strong {
    color: #4b5563;
    margin-right: 5px;
}

.image-navigation {
    display: flex;
    align-items: center;
    gap: 15px;
}

#imageCounter {
    font-weight: bold;
    color: #374151;
    min-width: 50px;
    text-align: center;
}

/* Quick Images in Table - Thumbnail Display */
.quick-images {
    display: flex;
    align-items: center;
    gap: 5px;
    margin-left: 5px;
    vertical-align: middle;
    flex-wrap: wrap;
}

.quick-image-item {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    margin: 2px;
}

.image-thumbnail {
    width: 40px;
    height: 40px;
    border-radius: 4px;
    object-fit: cover;
    border: 2px solid #e5e7eb;
    cursor: pointer;
    transition: all 0.2s ease;
    background: #f5f5f5;
}

.image-thumbnail:hover {
    border-color: #667eea;
    transform: scale(1.1);
    box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.preview-image-btn {
    background: #9f7aea;
    color: white;
    border: none;
    padding: 3px 6px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 11px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    margin-top: 2px;
}

.preview-image-btn:hover {
    background: #805ad5;
    transform: translateY(-1px);
}

.more-count {
    font-size: 11px;
    color: #6b7280;
    background: #f3f4f6;
    padding: 2px 5px;
    border-radius: 3px;
    margin-left: 3px;
    align-self: center;
}

/* Document Viewer */
.document-viewer {
    max-width: 90%;
    height: 90vh;
    display: flex;
    flex-direction: column;
}

.document-viewer .modal-body {
    flex: 1;
    padding: 0;
}

#documentFrame {
    width: 100%;
    height: 100%;
    border: none;
}

/* Column specific styles */
td:nth-child(1) { /* Contract No */
    font-weight: bold;
    color: #667eea;
}

td:nth-child(7), /* Days */
td:nth-child(8), /* Balance */
td:nth-child(11), /* Mileage */
td:nth-child(13), /* Day Price */
td:nth-child(14), /* Deposit */
td:nth-child(15) { /* VAT */
    font-family: 'Courier New', monospace;
    font-weight: bold;
}

/* Table cell adjustments for remarks */
td.remarks-cell {
    max-width: 250px;
    min-width: 200px;
    white-space: normal;
}

/* Custom scrollbar for remarks */
.remarks-content::-webkit-scrollbar {
    width: 8px;
}

.remarks-content::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.remarks-content::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.remarks-content::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* Statistics styling */
#avgMileage, #carsOut {
    font-size: 32px;
    font-weight: bold;
    color: white;
    text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

/* Responsive */
@media (max-width: 1600px) {
    .table-responsive {
        overflow-x: auto;
    }
}

@media (max-width: 1200px) {
    .image-item {
        width: 200px;
    }
}

@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    .header {
        flex-direction: column;
        text-align: center;
    }
    
    .header-info {
        justify-content: center;
    }
    
    .controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .search-box {
        min-width: 100%;
    }
    
    .filters {
        width: 100%;
        flex-direction: column;
    }
    
    .filters select {
        width: 100%;
    }
    
    .stats {
        grid-template-columns: 1fr;
    }
    
    .table-header {
        flex-direction: column;
        text-align: center;
    }
    
    .modal-content {
        width: 95%;
        margin: 20px auto;
    }
    
    .image-item {
        width: 100%;
        max-width: 300px;
    }
    
    .single-image-viewer {
        width: 95%;
        margin: 10px auto;
    }
    
    .image-preview-container {
        min-height: 300px;
        padding: 10px;
    }
    
    .single-image-info {
        flex-direction: column;
        text-align: center;
        gap: 10px;
    }
    
    .remarks-viewer {
        width: 95%;
        margin: 10px auto;
    }
    
    .remarks-content {
        padding: 15px;
        max-height: 300px;
    }
    
    .remarks-contract-info {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .container {
        padding: 10px;
        margin: 5px;
    }
    
    .header h1 {
        font-size: 22px;
        flex-direction: column;
        gap: 10px;
    }
    
    .stat-card {
        padding: 20px;
    }
    
    .stat-card p {
        font-size: 24px;
    }
    
    th, td {
        padding: 8px 6px;
        font-size: 12px;
    }
    
    .image-thumbnail {
        width: 30px;
        height: 30px;
    }
}

/* Scrollbar Styling */
.table-responsive::-webkit-scrollbar {
    height: 8px;
}

.table-responsive::-webkit-scrollbar-track {
    background: #f1f1f1;
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb {
    background: #c1c1c1;
    border-radius: 4px;
}

.table-responsive::-webkit-scrollbar-thumb:hover {
    background: #a1a1a1;
}

/* Fallback for image thumbnails */
.image-thumbnail[src*="placeholder"] {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e5e7eb;
    color: #9ca3af;
    font-size: 10px;
}

.image-thumbnail[src*="placeholder"]:before {
    content: "No Image";
    font-size: 8px;
}

/* Thumbnail container for multiple images */
.thumbnails-container {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}

.thumbnail-wrapper {
    position: relative;
    display: inline-block;
}

.thumbnail-wrapper:hover .thumbnail-overlay {
    opacity: 1;
}

.thumbnail-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.3s ease;
    border-radius: 4px;
}

.thumbnail-overlay i {
    color: white;
    font-size: 16px;
}