/* Base styles */
:root {
    --primary-color: #4a90e2;
    --secondary-color: #5cb85c;
    --error-color: #d9534f;
    --text-color: #ffffff;
    --bg-color: #1a2b45;  /* Dark blue background */
    --card-bg-color: #2a3b55;  /* Slightly lighter blue for cards/containers */
    --border-color: #3a4b65;
    --header-bg: #0f1a2e;  /* Darker blue for header */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--bg-color);
    padding-bottom: 30px;
    /* Add top padding since we removed the header */
    padding-top: 20px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px;
}

.hidden {
    display: none !important;
}

/* Button styles */
.btn {
    background-color: var(--primary-color);
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 1rem;
    transition: background-color 0.2s;
}

.btn:hover {
    background-color: #3a7bc8;
}

.auth-btn {
    background-color: #567;
}

.auth-btn:hover {
    background-color: #456;
}

.login-btn {
    background-color: var(--primary-color);
    width: 100%;
    padding: 10px;
    margin-top: 10px;
}

.process-btn {
    background-color: var(--secondary-color);
}

.process-btn:hover {
    background-color: #4a9d4a;
}

/* Sample Image Constant Size styles */
.sample-image-item {
    cursor: pointer;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
    /* Set fixed dimensions for consistent sizing */
    height: 120px;
    width: 100%;
}

.sample-image-item:hover {
    transform: scale(1.03);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
}

.sample-image-item img {
    width: 100%;
    height: 100%;
    display: block;
    border: 1px solid var(--border-color);
    object-fit: cover; /* Maintain aspect ratio while covering the container */
}

/* Form styles */
.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--text-color);
}

.form-group input {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background-color: rgba(255, 255, 255, 0.9);
    color: #333;
}

/* Login section */
#login-section {
    max-width: 400px;
    margin: 30px auto;
    padding: 20px;
    background-color: var(--card-bg-color);
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

#login-section h2 {
    margin-bottom: 20px;
    text-align: center;
    color: var(--primary-color);
}

.error-text {
    color: var(--error-color);
    margin-top: 10px;
    text-align: center;
}

/* Upload section */
.upload-section {
    margin-top: 20px;
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: 5px;
    padding: 30px;
    text-align: center;
    background-color: var(--card-bg-color);
    transition: border-color 0.2s, background-color 0.2s;
}

.upload-area.active {
    border-color: var(--primary-color);
    background-color: rgba(74, 144, 226, 0.1);
}

#drop-message {
    color: #ccc;
}

.upload-btn {
    display: inline-block;
    background-color: var(--primary-color);
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    margin-top: 10px;
    cursor: pointer;
}

.upload-btn:hover {
    background-color: #3a7bc8;
}

/* Preview container */
#preview-container {
    text-align: center;
    margin-top: 20px;
    background-color: var(--card-bg-color);
    padding: 15px;
    border-radius: 5px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
}

#image-preview {
    max-width: 100%;
    max-height: 500px;
    border-radius: 5px;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.preview-actions {
    margin-top: 15px;
    display: flex;
    justify-content: center;
    gap: 20px; /* Increased from 10px for better separation */
}

.preview-actions button {
    min-width: 120px; /* Ensure buttons have minimum width */
}

/* Loading spinner */
.spinner {
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top: 4px solid var(--primary-color);
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#loading {
    text-align: center;
    padding: 20px;
    color: var(--text-color);
}

/* Error section */
#error-section {
    margin-top: 20px;
    padding: 15px;
    background-color: rgba(217, 83, 79, 0.2);
    border: 1px solid var(--error-color);
    border-radius: 5px;
    color: #ffcccc;
}

#error-section h2 {
    margin-bottom: 10px;
    font-size: 1.2rem;
    color: var(--error-color);
}

/* Detection container */
.detection-container {
    margin: 15px auto;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    border-radius: 5px;
    overflow: hidden;
}

/* Defect count display */
.defect-count-container {
    margin-top: 15px;
    text-align: center;
}

.defect-count-box {
    display: inline-block;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.defect-count-box i {
    color: var(--error-color);
    margin-right: 8px;
}

#defect-count {
    font-size: 1.4rem;
    margin: 0 5px;
    color: var(--error-color);
}

/* Three-column layout */
.three-column-layout {
    display: flex;
    gap: 20px;
    max-width: 100%;
    margin-top: 20px;
    height: 600px;
}

.left-column, .right-column {
    width: 20%;
    max-width: 300px;
    min-width: 220px;
}

.middle-column {
    flex: 1;
    min-width: 300px;
}

/* Sample Images Section */
.sample-images-container {
    background-color: var(--card-bg-color);
    border-radius: 5px;
    padding: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.sample-images-container h3 {
    margin-bottom: 15px;
    color: var(--primary-color);
    font-size: 1.1rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.sample-images {
    overflow-y: auto;
    overflow-x: hidden; /* Prevent horizontal scrolling */
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Loading spinner */
.spinner {
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-radius: 50%;
    border-top: 4px solid var(--primary-color);
    width: 30px;
    height: 30px;
    animation: spin 1s linear infinite;
    margin: 0 auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

#loading {
    text-align: center;
    padding: 20px;
    color: var(--text-color);
}

/* Error section */
#error-section {
    margin-top: 20px;
    padding: 15px;
    background-color: rgba(217, 83, 79, 0.2);
    border: 1px solid var(--error-color);
    border-radius: 5px;
    color: #ffcccc;
}

#error-section h2 {
    margin-bottom: 10px;
    font-size: 1.2rem;
    color: var(--error-color);
}

/* Detection container */
.detection-container {
    margin: 15px auto;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
    border-radius: 5px;
    overflow: hidden;
}

/* Defect count display */
.defect-count-container {
    margin-top: 15px;
    text-align: center;
}

.defect-count-box {
    display: inline-block;
    background-color: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 10px 20px;
    font-size: 1.2rem;
    font-weight: bold;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
}

.defect-count-box i {
    color: var(--error-color);
    margin-right: 8px;
}

#defect-count {
    font-size: 1.4rem;
    margin: 0 5px;
    color: var(--error-color);
}

/* Three-column layout */
.three-column-layout {
    display: flex;
    gap: 20px;
    max-width: 100%;
    margin-top: 20px;
    height: 600px;
}

.left-column, .right-column {
    width: 20%;
    max-width: 300px;
    min-width: 220px;
}

.middle-column {
    flex: 1;
    min-width: 300px;
}

/* Sample Images Section */
.sample-images-container {
    background-color: var(--card-bg-color);
    border-radius: 5px;
    padding: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.sample-images-container h3 {
    margin-bottom: 15px;
    color: var(--primary-color);
    font-size: 1.1rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.sample-images {
    overflow-y: auto;
    overflow-x: hidden; /* Prevent horizontal scrolling */
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

/* Detection History Section */
.detection-history-container {
    background-color: var(--card-bg-color);
    border-radius: 5px;
    padding: 15px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.detection-history-container h3 {
    margin-bottom: 15px;
    color: var(--primary-color);
    font-size: 1.1rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 10px;
}

.detection-history {
    overflow-y: auto;
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.history-item {
    display: flex;
    padding: 10px;
    background-color: rgba(255, 255, 255, 0.05);
    border-radius: 4px;
    gap: 10px;
    align-items: center;
    border-left: 3px solid var(--primary-color);
}

.history-item .history-image {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 3px;
    border: 1px solid var(--border-color);
}

.history-item .history-details {
    flex-grow: 1;
}

.history-item .history-timestamp {
    font-size: 0.8rem;
    opacity: 0.7;
    margin-bottom: 5px;
}

.history-item .history-count {
    font-weight: bold;
    display: flex;
    align-items: center;
    gap: 5px;
}

.history-item .history-count.has-defects {
    color: var(--error-color);
}

.history-item .history-count.no-defects {
    color: var(--secondary-color);
}

.no-history {
    text-align: center;
    opacity: 0.7;
    font-style: italic;
    padding: 20px 0;
}

/* Mobile responsive styles */
@media (max-width: 768px) {
    .container {
        padding: 15px;
    }
    
    .main-header {
        flex-direction: column;
        padding: 15px;
        gap: 15px;
    }
    
    .logo {
        justify-content: center;
        text-align: center;
        width: 100%;
    }
    
    .logo h1 {
        font-size: 1.2rem;
    }
    
    #auth-buttons {
        width: 100%;
        justify-content: center;
    }
    
    .user-info {
        flex-direction: column;
        gap: 8px;
    }
    
    .upload-area {
        padding: 20px 10px;
    }
    
    .preview-actions {
        flex-direction: column;
        gap: 15px; /* Increased from 10px */
        padding: 0 10px;
    }
    
    .preview-actions button {
        width: 100%;
        padding: 12px 8px; /* Larger touch target */
        margin: 0;
        font-size: 1.1rem; /* Slightly larger font */
    }
    
    /* Make process and change buttons visually distinct */
    #process-btn {
        background-color: var(--secondary-color);
        border: 2px solid #4a9d4a;
    }
    
    #change-image-btn {
        background-color: var(--primary-color);
        border: 2px solid #3a7bc8;
    }
    
    #image-preview, 
    .detection-container {
        max-width: 100%;
        max-height: 400px;
    }
    
    .defect-count-box {
        padding: 8px 15px;
        font-size: 1rem;
    }
    
    #defect-count {
        font-size: 1.2rem;
    }
    
    .three-column-layout {
        flex-direction: column;
    }
    
    .left-column, .right-column {
        width: 100%;
        max-width: 100%;
        min-width: 100%;
    }
    
    .sample-images {
        display: grid;
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 10px;
    }
    
    .detection-history {
        max-height: 300px;
    }
}

/* Small mobile screens */
@media (max-width: 480px) {
    .main-header {
        padding: 10px;
    }
    
    .logo img {
        height: 30px;
    }
    
    .logo h1 {
        font-size: 1rem;
    }
    
    #login-section {
        padding: 15px;
    }
    
    .upload-area {
        padding: 15px 10px;
    }
    
    .btn {
        padding: 8px 12px;
        font-size: 0.9rem;
    }
    
    #image-preview, 
    .detection-container {
        max-height: 300px;
    }
    
    .defect-count-box {
        width: 100%;
        padding: 8px;
        font-size: 0.9rem;
    }
}

/* Fix for labels in detection canvas when on mobile screens */
@media (max-width: 768px) {
    .detection-container canvas text {
        font-size: 10px !important;
    }
}

/* Button hover effects */
.btn:hover {
    box-shadow: 0 0 8px rgba(255, 255, 255, 0.3);
}

/* Focus styles for accessibility */
.btn:focus, input:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--primary-color);
}

/* Nice hover effect for upload area */
.upload-area:hover {
    border-color: var(--primary-color);
    background-color: rgba(74, 144, 226, 0.05);
}

/* Add subtle transitions for smoother UI experience */
.btn, .upload-area, input {
    transition: all 0.2s ease-in-out;
}