/* Modern CSS Variables for consistent theming */
:root {
    --primary-color: #6366f1;
    --primary-hover: #5b5ad6;
    --primary-light: #f0f0ff;
    --secondary-color: #8b5cf6;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --white: #ffffff;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
    --shadow-xl: 0 20px 25px -5px rgb(0 0 0 / 0.1), 0 8px 10px -6px rgb(0 0 0 / 0.1);
    --border-radius: 12px;
    --border-radius-lg: 16px;
    --border-radius-xl: 20px;
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
    --ease-out: cubic-bezier(0.4, 0, 0.2, 1); /* MED-001: Added missing variable */
    
    /* ========================================
     * HIGH-001: Centralized Z-Index Scale
     * ========================================
     * 
     * USAGE: Always use these CSS variables instead of hardcoded z-index values.
     * This ensures consistent layering and prevents z-index conflicts.
     * 
     * Z-INDEX HIERARCHY:
     * 
     * Layer 1 (0-99): Base elements
     * Layer 2 (100-199): UI Controls (header, dropdowns)
     * Layer 3 (200-999): Dropdowns & Popovers
     * Layer 4 (1000-1999): Camera/Webcam Overlays
     * Layer 5 (9000-9999): Content Modals
     * Layer 6 (10000+): Critical System Dialogs
     */
    
    /* Layer 1: Base Elements (0-99) */
    --z-index-base: 0;
    --z-index-connections-svg: 0;
    --z-index-sample-delete: 10;
    --z-index-card-header: 20;
    
    /* Layer 2: UI Controls (100-199) */
    --z-index-header: 100;
    --z-index-dropdown: 100;
    --z-index-footer: 100;
    --z-index-advanced-panel-mobile: 150;
    
    /* Layer 3: Dropdowns & Popovers (200-999) */
    --z-index-theme-dropdown: 200;
    --z-index-advanced-panel-desktop: 200;
    --z-index-tooltip: 300;
    --z-index-popover: 400;
    
    /* Layer 4: Camera/Webcam Overlays (1000-1999) */
    --z-index-webcam-modal: 1000;
    --z-index-webcam-content: 1001;
    --z-index-webcam-video: 1;          /* Relative within stacking context */
    --z-index-webcam-controls: 10;       /* Relative within stacking context */
    --z-index-webcam-close-btn: 15;      /* Relative within stacking context */
    --z-index-webcam-actions: 11;        /* Relative within stacking context */
    --z-index-prediction-bars: 1002;
    --z-index-mobile-actions: 1003;
    
    /* Layer 5: Content Modals (9000-9999) */
    --z-index-modal: 9000;
    --z-index-modal-backdrop: 8999;
    --z-index-privacy-modal: 9000;
    --z-index-training-insights: 9000;
    
    /* Layer 6: Critical System Dialogs (10000+) */
    --z-index-confirm-dialog: 10000;
    --z-index-alert-dialog: 10000;
    --z-index-toast: 10001;
    --z-index-tutorial-overlay: 10002;
}

.class-card.disabled {
    opacity: 0.5;
    filter: grayscale(100%);
    transform: scale(0.98);
    transition: var(--transition);
}

/* MED-001: Consolidated universal selectors */
* {
    box-sizing: border-box;
    /* Universal mobile app constraints - never allow horizontal overflow */
    max-width: 100%;
    overflow-wrap: break-word;
}

/* Reset max-width for elements that should expand */
html, body, .container, .header, .footer {
    max-width: none;
}

/* MED-002: Utility classes for icon spacing - replaces inline styles */
.icon-spacing-right {
    margin-right: 8px;
}

.icon-spacing-left {
    margin-left: 8px;
}

.btn-text-bold {
    font-weight: 600;
}

body {
    background: linear-gradient(135deg, #f0f2ff 0%, #e8f4fd 100%);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu', 'Cantarell', sans-serif;
    margin: 0;
    padding: 0;
    min-height: 100vh;
    font-size: 16px;
    line-height: 1.6;
    color: var(--gray-700);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    display: flex;
    flex-direction: column;
    overflow-x: hidden; /* Never allow horizontal scroll - app-like behavior */
    max-width: 100vw; /* Force content to stay within viewport */
}


/* Updated Header Styles */
.header {
    background: var(--gray-800);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--gray-700);
    padding: 16px 20px;
    position: sticky;
    top: 0;
    z-index: var(--z-index-header);
    transition: var(--transition);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo-section {
    display: flex;
    align-items: center;
    gap: 16px;
}

.header-logo-link {
    display: flex;
    align-items: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.header-logo-link:hover {
    opacity: 0.8;
}

.header-bil-logo {
    height: 50px;
    width: auto;
    display: block;
}

.title-section {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.app-title {
    color: var(--white);
    font-size: 24px;
    font-weight: 700;
    margin: 0;
    letter-spacing: -0.025em;
}

.app-subtitle {
    color: var(--gray-400);
    font-size: 13px;
    font-weight: 500;
    margin: 0;
    letter-spacing: -0.02em;
}

.container {
    max-width: 1200px;
    margin: 16px auto;
    padding: 0 16px;
    display: grid;
    grid-template-columns: 1fr;
    gap: 20px;
    position: relative;
    flex: 0 1 auto; /* Don't grow, allow shrink, natural size */
    overflow-x: hidden; /* Prevent horizontal overflow */
    width: 100%; /* Ensure container doesn't exceed parent */
    box-sizing: border-box; /* Include padding in width calculation */
    align-items: start; /* Align all grid items to the top */
    align-content: start; /* Align grid content to start (top) */
}

.left-column {
    display: flex;
    flex-direction: column;
    order: 1;
    padding-top: 4px; /* Small padding to prevent hover border from being cut off */
}

.class-card {
    background: var(--white);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 20px;
    margin-top: 4px; /* Small margin to prevent hover border from being cut off */
    overflow: visible; /* Changed from hidden to allow dropdown to be visible */
    border: 1px solid var(--gray-100);
    transition: var(--transition);
    position: relative;
}

.class-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary-color);
}

.class-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-100);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.class-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-800);
    display: flex;
    align-items: center;
    gap: 12px;
    flex: 1;
    min-width: 0;
}

.class-name {
    cursor: default;
    word-break: break-word;
    overflow: hidden;
    text-overflow: ellipsis;
    letter-spacing: -0.025em;
}

.class-icons {
    display: flex;
    gap: 8px;
    align-items: center;
}

.edit-icon {
    color: var(--gray-400);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: var(--transition);
    font-size: 16px;
}

.edit-icon:hover {
    color: var(--primary-color);
    background: var(--primary-light);
}

.menu-dots {
    color: var(--gray-400);
    cursor: pointer;
    position: relative;
    padding: 8px;
    border-radius: 8px;
    transition: var(--transition);
}

.menu-dots:hover {
    color: var(--gray-600);
    background: var(--gray-100);
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
    display: none;
    z-index: 150;
    width: 200px;
    border: 1px solid var(--gray-200);
    overflow: hidden;
}

/* Open upwards if near bottom of screen */
.dropdown-menu.open-upward {
    top: auto;
    bottom: 100%;
    margin-bottom: 4px;
}

.dropdown-menu.show {
    display: block;
    animation: fadeInDown 0.2s ease-out;
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.dropdown-item {
    padding: 12px 16px;
    cursor: pointer;
    color: var(--gray-700);
    display: block;
    text-decoration: none;
    white-space: normal;
    word-wrap: break-word;
    font-size: 14px;
    font-weight: 500;
    transition: var(--transition);
    border-bottom: 1px solid var(--gray-100);
    line-height: 1.4;
}

.dropdown-item:last-child {
    border-bottom: none;
}

.dropdown-item:hover {
    background: var(--gray-50);
    color: var(--primary-color);
}

.dropdown-item.delete-class-btn:hover {
    background: #fef2f2;
    color: var(--danger-color);
}

.class-content {
    padding: 12px;
}

.samples-label {
    margin-bottom: 16px;
    color: var(--gray-600);
    font-size: 15px;
    font-weight: 500;
    letter-spacing: -0.025em;
}

/* Sample interface container with border for visual separation */
.sample-interface {
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius);
    overflow: hidden;
    background: var(--white);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.sample-interface:hover {
    border-color: var(--gray-300);
    box-shadow: var(--shadow-md);
}

/* New tab-based sample interface */
.sample-tabs {
    display: flex;
    border-bottom: 1px solid var(--gray-200);
    margin-bottom: 0;
    background: var(--gray-50);
    border-radius: 0;
    overflow: hidden;
}

.sample-tab {
    flex: 1;
    padding: 12px 16px;
    background: none;
    border: none;
    color: var(--gray-600);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: var(--transition);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    letter-spacing: -0.025em;
}

.sample-tab::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-color);
    border-radius: 3px 3px 0 0;
    transform: scaleX(0);
    transition: var(--transition);
}

.sample-tab.active {
    background: var(--white);
    color: var(--primary-color);
}

.sample-tab.active::after {
    transform: scaleX(1);
}

.sample-tab:hover:not(.active) {
    background: var(--gray-100);
    color: var(--gray-700);
}

.sample-tab i {
    font-size: 16px;
    transition: var(--transition);
}

.sample-content {
    position: relative;
    min-height: 80px;
    margin-bottom: 0;
    padding: 16px;
    background: var(--white);
}

.sample-content-area {
    display: none;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
}

.sample-content-area.active {
    display: flex;
    opacity: 1;
    justify-content: center;
    align-items: center;
}

.sample-action-button {
    background: linear-gradient(135deg, var(--primary-light) 0%, #f8faff 100%);
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    padding: 16px 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    color: var(--primary-color);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    letter-spacing: -0.025em;
    min-width: 180px;
    justify-content: center;
}

.sample-action-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
    transition: left 0.5s;
}

.sample-action-button:hover::before {
    left: 100%;
}

.sample-action-button:hover {
    transform: translateY(-2px);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: var(--white);
}

.sample-action-button:active {
    transform: translateY(0);
}

.sample-action-button i {
    font-size: 18px;
    transition: var(--transition);
}

.samples-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 8px;
    margin-top: 0;
    padding: 0 16px 16px 16px;
    background: var(--white);
}

/* Mobile touch feedback for tabs */
@media (max-width: 768px) {
    .sample-tab:active {
        transform: scale(0.98);
        background: var(--gray-200);
    }
    
    .sample-action-button:active {
        transform: scale(0.96);
        background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
        color: var(--white);
    }
    
    /* Disable hover effects on mobile - use active states instead */
    .sample-tab:hover:not(.active) {
        background: none;
        color: var(--gray-600);
    }
    
    .sample-action-button:hover {
        transform: none;
        background: linear-gradient(135deg, var(--primary-light) 0%, #f8faff 100%);
        color: var(--primary-color);
    }
}

.samples-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
    gap: 8px;
    margin-top: 12px;
}

.sample-image {
    width: 100%;
    height: 60px;
    object-fit: cover;
    border-radius: var(--border-radius);
    border: 2px solid var(--gray-200);
    transition: var(--transition);
    cursor: pointer;
    position: relative;
}

.sample-image:hover {
    transform: scale(1.05);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
}

.sample-image-container {
    position: relative;
    display: inline-block;
    width: 100%;
}

.sample-delete-btn {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(239, 68, 68, 0.8);
    color: var(--white);
    border: none;
    border-radius: var(--border-radius);
    width: 100%;
    height: 100%;
    font-size: 14px;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: var(--transition);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    flex-direction: column;
    gap: 4px;
}

/* Mobile-specific adjustments for delete button */
@media (max-width: 768px) {
    .sample-delete-btn {
        font-size: 12px;
        gap: 2px;
    }
    
    .sample-delete-btn span {
        font-size: 11px;
    }
    
    /* Show delete button on mobile touch - better UX */
    .sample-image-container:active .sample-delete-btn {
        display: flex;
    }
}

.sample-delete-btn:hover {
    background: rgba(220, 38, 38, 0.9);
    transform: scale(1.02);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
}

.sample-image-container:hover .sample-delete-btn {
    display: flex;
}

/* Container for the Add Class button inside training section */
.add-class-container {
    padding: 0;
    margin: 0;
    border-top: 1px solid var(--gray-100);
}

.add-class-btn {
    border: none;
    border-radius: 0;
    padding: 16px 24px;
    text-align: center;
    color: var(--primary-color);
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--gray-50);
    width: 100%;
    font-size: 15px;
    font-weight: 600;
    margin: 0;
    min-height: auto;
    transition: var(--transition);
    letter-spacing: -0.025em;
    border-radius: 0 0 var(--border-radius-lg) var(--border-radius-lg);
}

.add-class-btn:hover {
    border-color: transparent;
    color: var(--primary-color);
    background: var(--primary-light);
    transform: none;
    box-shadow: none;
}

.add-icon {
    margin-right: 8px;
    font-size: 18px;
}

.right-column {
    display: flex;
    flex-direction: column;
    gap: 20px;
    order: 2;
    align-items: flex-start; /* Align training and preview sections to the top */
    padding-top: 4px; /* Match left-column padding for consistent alignment */
    flex-grow: 0; /* Prevent column from growing to fill container */
    height: auto; /* Let height be determined by content */
}

.training-section, .preview-section {
    background: var(--white);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--gray-100);
    overflow: visible; /* Changed from hidden to visible to allow dropdown */
    transition: var(--transition);
    position: relative; /* Add position relative for proper dropdown positioning */
    width: 100%; /* Ensure both sections take full width on mobile */
    margin-top: 4px; /* Match class-card margin for consistent alignment */
}

/* Training section should be compact and auto-size */
.training-section {
    min-height: auto;
}

/* Preview section maintains consistent height */
.preview-section {
    min-height: 550px;
    max-height: 650px; /* Cap maximum height to prevent stretching on initial load */
    max-width: 100%;
    overflow: hidden; /* Never allow horizontal scroll - app-like experience */
    flex-grow: 0; /* Prevent section from growing to fill available space */
    flex-shrink: 0; /* Prevent section from shrinking */
    height: fit-content; /* Size to content, respecting min/max */
}


.training-section:hover, .preview-section:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-2px);
    border-color: var(--primary-color);
}

.section-title {
    padding: 16px 20px;
    font-weight: 600;
    color: var(--gray-800);
    font-size: 16px;
    border-bottom: 1px solid var(--gray-100);
    background: linear-gradient(135deg, var(--gray-50) 0%, var(--white) 100%);
    letter-spacing: -0.025em;
    border-radius: var(--border-radius-lg) var(--border-radius-lg) 0 0; /* Rounded top corners like class-header */
}

.train-button {
    display: block;
    width: 100%;
    padding: 16px 24px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    border: none;
    text-align: center;
    font-weight: 600;
    color: var(--white);
    cursor: pointer;
    font-size: 16px;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    letter-spacing: -0.025em;
}

.train-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.6s;
}

.train-button:hover::before {
    left: 100%;
}

.train-button:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.train-button:active {
    transform: translateY(0);
}

/* Enhanced mobile feedback for train button */
@media (max-width: 768px) {
    .train-button:active {
        transform: scale(0.96);
        box-shadow: var(--shadow-sm);
    }
}

.train-button:disabled {
    background: var(--gray-300);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Train button loading state for immediate feedback */
.train-button.loading {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    position: relative;
    overflow: hidden;
    pointer-events: none; /* Prevent any clicks during loading */
}

.train-button.loading::after {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    animation: loading-shimmer 1.5s infinite;
}

@keyframes loading-shimmer {
    0% { left: -100%; }
    100% { left: 100%; }
}

/* Model Action Button Styles */
.model-action-btn {
    background: linear-gradient(135deg, var(--primary-light) 0%, #f8faff 100%);
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    font-size: 15px;
    font-weight: 600;
    color: var(--primary-color);
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    text-decoration: none;
    letter-spacing: -0.025em;
    width: 100%;
}

.model-action-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.6), transparent);
    transition: left 0.5s;
}

.model-action-btn:hover::before {
    left: 100%;
}

.model-action-btn:hover {
    transform: translateY(-2px);
    border-color: var(--primary-color);
    box-shadow: var(--shadow-md);
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: var(--white);
}

.model-action-btn:active {
    transform: translateY(0);
}

/* Enhanced mobile feedback for model action buttons */
@media (max-width: 768px) {
    .model-action-btn:active {
        transform: scale(0.96);
        box-shadow: var(--shadow-sm);
        background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
        color: var(--white);
    }
    
    .model-action-btn:hover {
        transform: none; /* Disable hover effects on mobile */
    }
}

.model-action-btn:disabled {
    background: var(--gray-300);
    color: var(--gray-500);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
    border-color: transparent;
}

/* Disabled input field for share link */
#shareLinkInput:disabled,
#shareLinkInput.share-link-disabled {
    background: var(--gray-200) !important;
    color: var(--gray-500) !important;
    cursor: not-allowed !important;
    border-color: var(--gray-300) !important;
    opacity: 0.6;
}

.model-action-btn i {
    font-size: 16px;
    transition: var(--transition);
}

.training-status {
    padding: 12px 20px;
    text-align: center;
    color: var(--gray-700);
    font-weight: 500;
    font-size: 14px;
    background: linear-gradient(135deg, var(--gray-50) 0%, var(--white) 100%);
    border-radius: var(--border-radius);
    margin: 16px 20px;
    transition: var(--transition);
    border: 1px solid var(--gray-200);
    max-width: 100%;
    word-wrap: break-word;
    overflow-wrap: break-word;
    hyphens: auto;
}

.training-status:empty {
    opacity: 0;
    height: 0;
    padding: 0;
    margin: 0;
    border: none;
}

/* MED-002/003: Training status message types - replaces inline styles */
.training-status-message {
    font-weight: 500;
    padding: 4px 0;
}

.training-status-info {
    color: var(--primary, #007bff);
}

.training-status-success {
    color: var(--success, #28a745);
}

.training-status-error {
    color: var(--danger, #dc3545);
}

/* MED-002/003: Training progress bar - replaces inline styles */
.training-progress-bar {
    background: var(--gray-200, #e9ecef);
    border-radius: 4px;
    height: 8px;
    margin-top: 8px;
    overflow: hidden;
}

.training-progress-fill {
    background: var(--primary, #007bff);
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s ease;
}

.advanced-panel {
    background: var(--white);
    border-top: 1px solid var(--gray-200);
    padding: 16px 20px;
    border-radius: 0;
    margin: 0;
    width: 100%;
}

/* Desktop styling for advanced panel */
@media (min-width: 768px) {
    .advanced-panel {
        padding: 16px 20px;
        border-top: 1px solid var(--gray-200);
    }
}

.option-group {
    margin-bottom: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.option-group:last-child {
    margin-bottom: 0;
}

.option-group label {
    font-size: 14px;
    color: var(--gray-700);
    font-weight: 600;
    letter-spacing: -0.025em;
}

.option-group input {
    padding: 12px 16px;
    border: 2px solid var(--gray-200);
    border-radius: var(--border-radius);
    font-size: 15px;
    transition: var(--transition);
    background: var(--white);
    color: var(--gray-700);
}

.option-group input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.reset-defaults-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin-top: 12px;
    padding: 8px 12px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--border-radius);
    color: var(--gray-600);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    width: 100%;
    letter-spacing: -0.025em;
}

.reset-defaults-btn:hover {
    background: var(--gray-100);
    border-color: var(--gray-300);
    color: var(--gray-700);
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.reset-defaults-btn:active {
    transform: translateY(0);
}

.reset-defaults-btn i {
    font-size: 14px;
    transition: var(--transition);
}

.reset-defaults-btn:hover i {
    transform: rotate(-45deg);
}

.preview-tabs {
    display: flex;
    border-bottom: 1px solid var(--gray-200);
    background: var(--gray-50);
}

.preview-tab {
    padding: 16px 12px;
    flex: 1;
    text-align: center;
    background: none;
    border: none;
    font-weight: 600;
    color: var(--gray-600);
    cursor: pointer;
    font-size: 15px;
    transition: var(--transition);
    position: relative;
    letter-spacing: -0.025em;
}

.preview-tab::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary-color);
    border-radius: 3px 3px 0 0;
    transform: scaleX(0);
    transition: var(--transition);
}

.preview-tab.active {
    color: var(--primary-color);
    background: var(--white);
}

.preview-tab.active::after {
    transform: scaleX(1);
}

.preview-tab:hover:not(.active) {
    color: var(--gray-700);
    background: var(--gray-100);
}

.preview-content {
    padding: 24px 20px;
    text-align: center;
    color: var(--gray-500);
    font-size: 15px;
    line-height: 1.6;
    min-height: 450px; /* Increased to accommodate canvas + content */
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    transition: height 0.3s ease; /* Smooth transition when height changes */
}

.preview-content.preview-active {
    height: auto; /* Allow container to expand when prediction bars are present */
    min-height: 550px; /* Minimum height when preview is active */
}

#preview-webcam {
    width: 280px !important;
    height: 280px !important;
    max-width: 280px;
    margin: 0 auto 20px auto;
    border-radius: var(--border-radius-lg);
    border: 3px solid var(--gray-200);
    transition: var(--transition);
    display: block;
    object-fit: cover;
}

/* Removed hover border color change to eliminate second outer lila border */

#preview-canvas {
    width: 280px !important;
    height: 280px !important;
    max-width: 280px;
    margin: 0 auto 20px auto;
    border: 3px solid var(--gray-200);
    border-radius: var(--border-radius-lg);
    transition: var(--transition);
    background: var(--gray-50);
    display: block;
}

#preview-canvas.camera-disabled {
    filter: grayscale(100%);
    opacity: 0.8;
    border-color: var(--gray-300);
}

.prediction-bars {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
}

/* Mobile: Keep prediction bars below video in modal flow */
@media (max-width: 768px) {
    #expandedPreviewModal .prediction-bars {
        position: relative; /* Normal flow instead of absolute */
        bottom: auto;
        left: auto;
        right: auto;
        padding: 16px 0 0 0; /* Top padding only */
        max-width: 100%;
        margin-top: 16px; /* Space above prediction bars */
        background: none; /* No gradient needed */
        z-index: auto;
    }
    
    #expandedPreviewModal .prediction-bar {
        background: var(--gray-50); /* Normal background */
        backdrop-filter: none;
        -webkit-backdrop-filter: none;
        border: 1px solid var(--gray-200);
    }
    
    #expandedPreviewModal .prediction-bar .class-name {
        color: var(--gray-700); /* Normal text color */
    }
    
    #expandedPreviewModal .prediction-value {
        color: var(--gray-700); /* Normal text color */
    }
}

.prediction-bar {
    display: flex;
    align-items: center;
    margin-bottom: 12px;
    font-size: 13px;
    background: var(--gray-50);
    padding: 8px;
    border-radius: var(--border-radius);
    transition: var(--transition);
}

.prediction-bar:hover {
    background: var(--gray-100);
}

.prediction-bar .class-name {
    width: 80px;
    text-align: right;
    margin-right: 12px;
    font-size: 12px;
    font-weight: 600;
    word-break: break-word;
    color: var(--gray-700);
}

.bar-container {
    flex-grow: 1;
    height: 20px;
    background: var(--gray-200);
    border-radius: 10px;
    overflow: hidden;
    position: relative;
}

.bar {
    height: 100%;
    border-radius: 10px;
    position: relative;
    transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.bar::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    animation: shimmer 2s infinite;
}

@keyframes shimmer {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

.prediction-value {
    width: 50px;
    text-align: left;
    margin-left: 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--gray-600);
}

.prediction-paused, .prediction-switching {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: var(--gray-500);
    font-size: 14px;
    font-weight: 500;
    text-align: center;
    background: var(--gray-50);
    border-radius: var(--border-radius);
    border: 1px solid var(--gray-200);
}

.prediction-paused i, .prediction-switching i {
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--gray-400);
}

.prediction-switching {
    color: var(--primary-color);
}

.prediction-switching i {
    color: var(--primary-color);
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.class-name-edit {
    border: 2px solid var(--primary-color);
    border-radius: var(--border-radius);
    padding: 8px 12px;
    outline: none;
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-800);
    width: 100%;
    max-width: 250px;
    background: var(--white);
    transition: var(--transition);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.connections {
    position: absolute;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    display: none; /* Hidden on mobile by default */
}

.webcam-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(0);
    -webkit-backdrop-filter: blur(0);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: var(--z-index-webcam-modal);
    padding: 20px;
}

/* Mobile-first: Minimize padding on smartphones but don't go full screen */
@media (max-width: 768px) {
    .webcam-modal {
        padding: 8px; /* Small padding instead of 0 */
        background: rgba(0, 0, 0, 0.3); /* Light transparent grey - see through */
    }
}

.webcam-modal.show {
    display: flex;
}

.webcam-modal-content {
    background: var(--white);
    padding: 24px;
    border-radius: var(--border-radius-lg);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    box-shadow: var(--shadow-xl);
    max-width: 90vw;
    max-height: 90vh;
    overflow: visible;
    position: relative;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Desktop/Tablet: Simple, no expand logic */
@media (min-width: 769px) {
    .webcam-modal-content {
        height: auto;
        width: auto;
        max-width: 90vw;
        max-height: 90vh;
    }
}

/* Mobile: Larger modal with minimal gap, but keep rounded corners (no progressive expansion) */
@media (max-width: 768px) {
    .webcam-modal-content {
        background: var(--white);
        padding: 12px; /* Small padding instead of 0 */
        border-radius: var(--border-radius); /* Keep rounded corners but smaller */
        max-width: calc(100vw - 16px); /* 8px gap on each side */
        max-height: calc(100vh - 16px);
        width: auto; /* Let it size based on video container */
        height: auto; /* Auto height to fit content */
        box-shadow: var(--shadow-xl);
        justify-content: center;
        /* No transition or expansion on mobile */
        transition: none;
    }
}

/* Webcam Modal Specific Styles */
.webcam-video-container {
    position: relative;
    border-radius: var(--border-radius);
    overflow: visible; /* CRIT-001: Changed from hidden to visible to prevent clipping control buttons */
    background: var(--gray-900);
    border: 5px solid var(--gray-300);
    box-shadow: var(--shadow-md);
    margin: 0;
    transition: border-color 0.1s ease-out, box-shadow 0.1s ease-out;
    display: flex;
    align-items: center;
    justify-content: center;
    width: min(94vw, 900px);
    max-height: 85vh;
    isolation: isolate; /* CRIT-001: Create new stacking context for z-index hierarchy */
}

.webcam-video-container video {
    width: 100%;
    height: auto;
    max-height: inherit;
    display: block;
    object-fit: contain;
    border-radius: var(--border-radius); /* Match container for consistent clipping */
    background: var(--gray-900);
    position: relative; /* CRIT-001: Allow z-index control */
    z-index: 1; /* CRIT-001: Keep video below control buttons */
}

/* Tablet & small desktop adjustments */
@media (max-width: 1024px) {
    .webcam-video-container {
        width: min(94vw, 760px);
        max-height: 80vh;
    }
}

/* Mobile: nearly fullscreen but keep full frame visible */
@media (max-width: 767px) {
    .webcam-video-container {
        width: calc(100vw - 16px);
        max-width: calc(100vw - 16px);
        max-height: 78vh;
    }
}

/* Portrait rotation adjustments */
.webcam-portrait-rotation {
    width: min(80vw, 640px);
    max-height: 88vh;
}

@media (max-width: 1024px) {
    .webcam-portrait-rotation {
        width: min(84vw, 560px);
        max-height: 86vh;
    }
}

@media (max-width: 767px) {
    .webcam-portrait-rotation {
        width: calc(100vw - 16px);
        max-width: calc(100vw - 16px);
        max-height: 82vh;
    }
}

/* Expanded Preview Modal: prioritize large, stable aspect ratio */
#expandedPreviewModal .webcam-video-container {
    width: min(92vw, 960px);
    aspect-ratio: 4 / 3;
    max-height: 85vh;
}

@media (max-width: 1024px) {
    #expandedPreviewModal .webcam-video-container {
        width: min(94vw, 820px);
        max-height: 82vh;
    }
}

@media (max-width: 767px) {
    #expandedPreviewModal .webcam-video-container {
        width: calc(100vw - 20px);
        max-width: calc(100vw - 20px);
        max-height: 80vh;
    }
}

#expandedPreviewModal .webcam-video-container video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* Portrait rotation for expanded preview - match training modal dimensions */
#expandedPreviewModal .webcam-video-container.webcam-portrait-rotation {
    aspect-ratio: 3 / 4;
    width: min(80vw, 640px); /* Same as training modal .webcam-portrait-rotation */
    max-height: 88vh;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Video inside portrait container when rotated 90° or 270° */
#expandedPreviewModal .webcam-video-container.webcam-portrait-rotation video {
    width: auto;
    height: 100%;
    max-width: none;
    max-height: 100%;
    object-fit: contain;
}

@media (max-width: 1024px) {
    #expandedPreviewModal .webcam-video-container.webcam-portrait-rotation {
        width: min(84vw, 560px); /* Same as training modal */
        max-height: 86vh;
    }
}

@media (max-width: 767px) {
    #expandedPreviewModal .webcam-video-container.webcam-portrait-rotation {
        width: calc(100vw - 16px); /* Same as training modal */
        max-width: calc(100vw - 16px);
        max-height: 82vh;
    }
}

/* Photo capture flash effect */
.webcam-video-container.flash-effect,
#training-video-container.flash-effect {
    animation: photo-flash 0.3s ease-out;
}

/* Continuous recording border effect */
.webcam-video-container.recording-active,
#training-video-container.recording-active {
    border-color: var(--primary-color);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.6), 0 0 40px rgba(99, 102, 241, 0.3);
    animation: recording-pulse 1.5s ease-in-out infinite;
}

@keyframes recording-pulse {
    0% {
        box-shadow: 0 0 20px rgba(99, 102, 241, 0.6), 0 0 40px rgba(99, 102, 241, 0.3);
    }
    50% {
        box-shadow: 0 0 30px rgba(99, 102, 241, 0.8), 0 0 60px rgba(99, 102, 241, 0.5);
    }
    100% {
        box-shadow: 0 0 20px rgba(99, 102, 241, 0.6), 0 0 40px rgba(99, 102, 241, 0.3);
    }
}

@keyframes photo-flash {
    0% {
        border-color: var(--gray-300);
        box-shadow: var(--shadow-md);
    }
    50% {
        border-color: var(--primary-color);
        box-shadow: 0 0 25px rgba(99, 102, 241, 0.9), 0 0 50px rgba(99, 102, 241, 0.5);
    }
    100% {
        border-color: var(--gray-300);
        box-shadow: var(--shadow-md);
    }
}

.webcam-control-btn {
    position: absolute;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    z-index: 10; /* CRIT-001: Increased and using relative z-index within container stacking context */
    transition: var(--transition);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    background: rgba(0, 0, 0, 0.8);
    color: var(--white);
    border: 2px solid rgba(255, 255, 255, 0.2);
    /* iOS Safari fixes for perfect circles and centered icons */
    flex-shrink: 0;
    padding: 0;
    line-height: 1;
    text-align: center;
    aspect-ratio: 1 / 1;
    -webkit-appearance: none;
    appearance: none;
    pointer-events: auto; /* CRIT-001: Ensure buttons are always clickable */
}

.webcam-control-btn i {
    display: block;
    line-height: 1;
    transform: translateX(0);
}

.switch-camera-btn {
    bottom: 8px;
    right: 8px;
    width: 32px;
    height: 32px;
    font-size: 16px;
}

.switch-camera-btn:hover {
    background: rgba(0, 0, 0, 0.9);
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

.rotate-camera-btn {
    top: 8px;
    left: 8px;
    width: 32px;
    height: 32px;
    font-size: 16px;
}

.rotate-camera-btn:hover {
    background: rgba(0, 0, 0, 0.9);
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

.expand-preview-btn {
    top: 8px;
    right: 8px;
}

.expand-preview-btn:hover {
    background: rgba(0, 0, 0, 0.9);
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

.close-btn {
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.7);
    color: var(--white);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: var(--shadow-sm);
    width: 32px;
    height: 32px;
    font-size: 16px;
    z-index: 15; /* CRIT-001: Higher z-index to ensure close button is always accessible */
}

.close-btn:hover {
    background: var(--danger-color);
    color: var(--white);
    border-color: var(--danger-color);
    transform: scale(1.05);
    box-shadow: var(--shadow-md);
}

.webcam-action-overlay {
    position: relative;
    margin-top: 16px;
    display: flex;
    gap: 12px;
    z-index: 11; /* CRIT-001: Using relative z-index within container stacking context */
}

.webcam-action-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.3);
    color: var(--white);
    font-size: 20px;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    /* iOS Safari fixes for perfect circles and centered icons */
    flex-shrink: 0;
    padding: 0;
    line-height: 1;
    text-align: center;
    aspect-ratio: 1 / 1;
    -webkit-appearance: none;
    appearance: none;
}

.webcam-action-btn i {
    display: block;
    line-height: 1;
    transform: translateX(0);
}

.capture-btn {
    background: rgba(16, 185, 129, 0.8);
    touch-action: manipulation; /* Prevent iOS double-tap zoom */
}

.capture-btn:hover {
    background: var(--success-color);
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

.record-btn {
    background: rgba(239, 68, 68, 0.8);
}

.record-btn:hover {
    background: var(--danger-color);
    transform: scale(1.1);
    box-shadow: var(--shadow-lg);
}

.record-btn.recording {
    background: var(--warning-color);
    animation: pulse 1s infinite;
    border-color: var(--warning-color);
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.8; }
}

.record-status {
    margin-top: 8px;
    padding: 6px 12px;
    background: rgba(0, 0, 0, 0.8);
    color: var(--white);
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    white-space: nowrap;
    text-align: center;
}

.record-status:empty {
    display: none;
}

/* Mobile adjustments for webcam buttons */
@media (max-width: 480px) {
    .webcam-action-overlay {
        bottom: auto; /* Normal flow instead of absolute */
        gap: 12px;
        position: relative; /* Normal flow */
        left: auto;
        transform: none; /* Remove centering transform */
        z-index: auto;
        margin-top: 16px; /* Space above buttons */
        justify-content: center; /* Center within container */
    }
    
    .webcam-action-btn {
        width: 50px;
        height: 50px;
        font-size: 18px;
        /* Ensure perfect circles on iOS */
        min-width: 50px;
        min-height: 50px;
        max-width: 50px;
        max-height: 50px;
    }
    
    .webcam-control-btn {
        width: 32px;
        height: 32px;
        font-size: 16px;
        /* Ensure perfect circles on iOS */
        min-width: 32px;
        min-height: 32px;
        max-width: 32px;
        max-height: 32px;
    }

    /* Close button - keep it inside the modal but in top-right corner */
    .close-btn {
        top: 8px;
        right: 8px;
        width: 32px;
        height: 32px;
        font-size: 16px;
        background: rgba(0, 0, 0, 0.8);
        border: 2px solid rgba(255, 255, 255, 0.3);
    }

    /* Switch camera button - bottom-right */
    .switch-camera-btn {
        bottom: 8px;
        right: 8px;
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    /* Rotate camera button - top-left */
    .rotate-camera-btn {
        top: 8px;
        left: 8px;
        width: 32px;
        height: 32px;
        font-size: 16px;
    }

    /* Full screen adjustments - remove padding constraints */
    .webcam-modal {
        padding: 8px; /* Small consistent padding */
    }
    
    .webcam-modal-content {
        padding: 12px; /* Small padding for controls */
        max-width: calc(100vw - 16px);
        max-height: calc(100vh - 16px);
        border-radius: var(--border-radius);
    }
    
    .webcam-video-container {
        margin: 0;
        max-width: 100%;
        border-radius: var(--border-radius);
        overflow: visible; /* Ensure buttons are visible */
    }

    /* Better touch targets and mobile feedback */
    .webcam-control-btn:active,
    .rotate-camera-btn:active,
    .switch-camera-btn:active {
        transform: scale(0.9);
        background: rgba(0, 0, 0, 0.9);
    }

    .webcam-action-btn:active {
        transform: scale(0.9);
    }

    /* Disable hover effects on mobile - use active states instead */
    .webcam-control-btn:hover,
    .webcam-action-btn:hover,
    .rotate-camera-btn:hover,
    .switch-camera-btn:hover {
        transform: none;
        background: rgba(0, 0, 0, 0.8);
    }
}

/* Desktop styles - applied when screen is wider than 768px */
@media (min-width: 768px) {
    .container {
        grid-template-columns: 1fr 2fr;
        gap: 24px;
        padding: 0 24px;
        margin: 24px auto;
    }
    
    .header {
        padding: 16px 24px;
    }
    
    .logo {
        font-size: 20px;
    }
    
    .right-column {
        flex-direction: row;
        align-items: flex-start; /* Keep flex-start for horizontal layout */
    }
    
    .training-section, .preview-section {
        transition: var(--transition);
    }
    
    /* Training section should be compact and take only its natural width */
    .training-section {
        min-height: auto;
        flex: 0 0 auto; /* Don't grow or shrink, use natural size */
        width: auto; /* Allow natural width based on content */
        min-width: 300px; /* Minimum width for usability */
        max-width: 400px; /* Maximum width to keep it compact */
    }
    
    /* Preview section takes remaining space */
    .preview-section {
        min-height: 550px;
        flex: 1; /* Take remaining space */
    }
    
    .class-header {
        padding: 20px 24px;
    }
    
    .class-title {
        font-size: 18px;
    }
    
    .class-content {
        padding: 16px;
    }
    
    .samples-label {
        margin-bottom: 20px;
        font-size: 16px;
    }
    
    .sample-interface {
        border-radius: var(--border-radius-lg);
    }
    
    .sample-tabs {
        margin-bottom: 0;
    }
    
    .sample-tab {
        padding: 18px 20px;
        font-size: 16px;
    }
    
    .sample-tab i {
        font-size: 18px;
    }
    
    .sample-content {
        min-height: 100px;
        margin-bottom: 0;
        padding: 20px;
    }
    
    .sample-action-button {
        padding: 18px 28px;
        font-size: 16px;
        min-width: 200px;
        gap: 14px;
    }
    
    .sample-action-button i {
        font-size: 20px;
    }
    
    .samples-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 12px;
        margin-top: 0;
        padding: 0 20px 20px 20px;
    }
    
    .samples-grid {
        grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
        gap: 12px;
        margin-top: 16px;
    }
    
    .sample-image {
        height: 80px;
    }
    
    .add-class-btn {
        padding: 18px 24px;
        font-size: 16px;
        margin: 0;
        min-height: auto;
    }
    
    .section-title {
        padding: 20px 24px;
        font-size: 18px;
    }
    
    .train-button {
        padding: 18px 24px;
        font-size: 16px;
    }
    
    .training-status {
        padding: 16px 20px;
        font-size: 15px;
        margin: 20px 24px;
    }
    
    .advanced-panel {
        padding: 16px 20px;
    }
    
    .option-group {
        margin-bottom: 16px;
        flex-direction: row;
        align-items: center;
        gap: 16px;
    }
    
    .option-group label {
        margin-right: 16px;
        margin-bottom: 0;
        font-size: 15px;
        min-width: 120px;
    }
    
    .option-group input {
        padding: 12px 16px;
        font-size: 15px;
    }
    
    .preview-tab {
        padding: 18px 16px;
        font-size: 16px;
    }
    
    .preview-content {
        padding: 32px 24px;
        font-size: 16px;
    }
    
    .prediction-bar {
        margin-bottom: 16px;
        font-size: 14px;
        padding: 12px;
    }
    
    .prediction-bar .class-name {
        width: 120px;
        margin-right: 16px;
        font-size: 14px;
    }
    
    .bar-container {
        height: 24px;
        border-radius: 12px;
    }
    
    .bar {
        border-radius: 12px;
    }
    
    .prediction-value {
        width: 60px;
        margin-left: 16px;
        font-size: 14px;
    }
    
    .class-name-edit {
        font-size: 18px;
        padding: 12px 16px;
        width: auto;
        max-width: none;
    }
    
    .connections {
        display: block; /* Show connections on desktop only when side-by-side */
    }
    
    .webcam-video-container {
        max-width: 600px;
    }
}

/* Large desktop styles - ensure connections are visible on larger screens */
@media (min-width: 1200px) {
    .container {
        margin: 40px auto;
        padding: 0 32px;
    }
    
    .connections {
        display: block; /* Ensure connections are visible on large screens */
    }
    
    .class-card {
        margin-bottom: 24px;
    }
    
    .right-column {
        gap: 24px;
    }
}

/* Touch-friendly adjustments for mobile */
@media (max-width: 767px) {
    /* Header mobile adjustments */
    .header {
        padding: 12px 16px;
    }
    
    .logo-section {
        gap: 12px;
    }
    
    .header-bil-logo {
        height: 36px;
    }
    
    .app-title {
        font-size: 18px;
    }
    
    .app-subtitle {
        font-size: 11px;
    }
    
    .edit-icon, .delete-icon, .menu-dots {
        padding: 12px;
        margin: -12px;
        border-radius: 8px;
    }
    
    .dropdown-item {
        padding: 16px 20px;
        font-size: 16px;
    }
    
    /* Advanced panel mobile adjustments */
    .training-section {
        overflow: visible; /* Allow overflow for dropdown */
        position: relative;
        z-index: 1; /* Below header but above base content */
        margin-bottom: 20px; /* Add space after training section */
        min-height: auto; /* Remove fixed height when advanced panel is always visible */
    }
    
    .advanced-panel {
        position: static; /* Make it part of normal flow */
        display: block !important; /* Always visible */
        border-radius: 0; /* Remove border radius since add-class-btn is below */
        margin: 0;
        animation: none;
        box-shadow: none;
        z-index: auto; /* Inherit from parent */
        width: 100%;
        left: auto;
        right: auto;
        top: auto;
        border: none;
        border-top: 1px solid var(--gray-200);
        padding: 12px 20px; /* Consistent with other mobile padding */
    }

    /* Make advanced panel content more compact on mobile */
    .advanced-panel .option-group {
        margin-bottom: 12px; /* Reduce margin between option groups */
    }

    .advanced-panel .option-group label {
        font-size: 13px; /* Smaller font for labels */
        margin-bottom: 4px; /* Reduce margin */
        min-width: auto; /* Allow labels to be narrower */
    }

    .advanced-panel .option-group input {
        padding: 8px 12px; /* Reduce input padding */
        font-size: 14px; /* Smaller font */
    }

    /* Make reset button compact on mobile */
    .reset-defaults-btn {
        padding: 7px 10px;
        font-size: 12px;
        margin-top: 10px;
    }

    .reset-defaults-btn i {
        font-size: 13px;
    }

    /* Make section title more compact on mobile */
    .training-section .section-title {
        padding: 16px 20px; /* Reduce padding */
        font-size: 16px; /* Smaller font size */
    }

    /* Make train button more compact on mobile */
    .training-section .train-button {
        padding: 14px 20px; /* Reduce padding */
        font-size: 15px; /* Smaller font size */
        margin: 16px 0; /* Remove horizontal margins, keep vertical spacing */
        width: calc(100% - 40px); /* Adjust width to account for container padding */
        margin-left: 20px;
        margin-right: 20px;
    }

    /* Make training status more compact on mobile */
    .training-section .training-status {
        padding: 10px 16px; /* Reduce padding */
        font-size: 13px; /* Smaller font size */
        margin: 12px 16px; /* Reduce margins */
    }

    /* Make add class button compact on mobile */
    .add-class-btn {
        padding: 14px 20px; /* Reduce padding */
        font-size: 14px; /* Smaller font size */
    }
    
    .add-icon {
        font-size: 14px; /* Smaller icon */
    }
    
    /* Ensure proper spacing in right column */
    .right-column {
        gap: 20px; /* Reset gap to normal */
    }
    
    /* Add proper spacing for preview section */
    .preview-section {
        margin-top: 0; /* Reset margin since we have proper gap now */
    }
    
    .sample-interface {
        border-radius: var(--border-radius);
        margin-bottom: 20px;
    }
    
    .sample-tabs {
        margin-bottom: 0;
    }
    
    .sample-tab {
        padding: 10px 12px;
        font-size: 13px;
        gap: 6px;
        touch-action: manipulation;
    }
    
    .sample-tab span {
        font-size: 12px;
    }
    
    .sample-tab i {
        font-size: 14px;
    }
    
    .sample-content {
        min-height: 70px;
        margin-bottom: 0;
        padding: 14px;
    }
    
    .sample-action-button {
        padding: 14px 20px;
        font-size: 14px;
        min-width: 160px;
        gap: 10px;
        touch-action: manipulation;
    }
    
    .sample-action-button i {
        font-size: 16px;
    }
    
    .samples-grid {
        padding: 0 14px 14px 14px;
    }
    
    .train-button {
        touch-action: manipulation;
        padding: 18px 24px;
    }
    
    .model-action-btn {
        padding: 14px 20px;
        font-size: 16px;
    }
    
    /* Better mobile spacing */
    .container {
        margin: 12px auto;
        padding: 0 12px;
    }
    
    .class-content {
        padding: 16px;
    }
    
    .preview-content {
        padding: 20px 16px;
    }

    .preview-content.preview-active {
        min-height: 500px; /* Slightly smaller on mobile to fit better */
    }
}

/* Extra small devices */
@media (max-width: 480px) {
    .sample-interface {
        margin-bottom: 16px;
    }
    
    .sample-tabs {
        margin-bottom: 0;
    }
    
    .sample-tab {
        padding: 8px 10px;
        font-size: 12px;
        gap: 4px;
    }
    
    .sample-tab span {
        font-size: 11px;
    }
    
    .sample-tab i {
        font-size: 13px;
    }
    
    .sample-content {
        min-height: 60px;
        margin-bottom: 0;
        padding: 12px;
    }
    
    .sample-action-button {
        padding: 12px 16px;
        font-size: 13px;
        min-width: 140px;
        gap: 8px;
    }
    
    .sample-action-button i {
        font-size: 15px;
    }
    
    .sample-action-button span {
        font-size: 13px;
    }
    
    .samples-grid {
        padding: 0 12px 12px 12px;
    }
    
    /* Responsive independent controls for mobile */
    .preview-controls {
        gap: 8px;
        flex-direction: row; /* Keep side by side on mobile */
        justify-content: center;
    }
    
    .control-button {
        padding: 10px 12px;
        font-size: 13px;
        flex: 1;
        max-width: 140px; /* Limit width but allow side by side */
        min-width: 0;
    }
    
    .control-button i {
        font-size: 14px;
    }
    
    .control-button span {
        font-size: 13px;
    }
    
    .webcam-modal {
        padding: 16px;
    }
    
    .webcam-modal-content {
        padding: 16px;
    }
    
    .webcam-video-container {
        margin: 0;
        max-width: calc(100vw - 64px);
    }
}

/* Footer Styles */
.footer {
    background: var(--gray-800);
    color: var(--white);
    padding: 20px 0;
    border-top: 1px solid var(--gray-200);
}

/* Floating footer on tablets and desktops */
@media (min-width: 768px) {
    .footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        z-index: 100;
        box-shadow: 0 -2px 10px rgba(0, 0, 0, 0.1);
    }
    
    /* Add bottom padding to the body/container so content isn't hidden behind footer */
    body {
        padding-bottom: 100px;
    }
}

.footer-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
}

.footer-links {
    display: flex;
    gap: 20px;
    position: relative;
}

.partner-logos {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    order: 1;
}

.partner-logo {
    height: 36px;
    width: auto;
    opacity: 0.7;
    transition: var(--transition);
    filter: brightness(0.9);
}

.partner-logo:hover {
    opacity: 1;
    filter: brightness(1);
}

.partner-logos a {
    display: inline-block;
    transition: var(--transition);
}

.mdz-logo {
    background: white;
    padding: 6px 12px;
    border-radius: 8px;
}

.bil-logo {
    height: 44px !important;
}

.footer-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    background: transparent;
    border: 1px solid var(--gray-400);
    border-radius: 6px;
    color: var(--gray-300);
    text-decoration: none;
    font-size: 14px;
    transition: var(--transition);
    cursor: pointer;
    min-width: 36px;
    min-height: 36px;
    white-space: nowrap;
}

.footer-link:hover {
    color: var(--white);
    border-color: var(--primary-color);
    background: rgba(99, 102, 241, 0.1);
    transform: translateY(-1px);
    text-decoration: none;
}

.footer-link.active,
.theme-toggle.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: var(--white);
}

.footer-link i {
    font-size: 16px;
    transition: var(--transition);
}

/* Mobile footer adjustments */
@media (max-width: 767px) {
    .footer-content {
        flex-direction: column;
        text-align: center;
        gap: 12px;
    }
    
    .partner-logos {
        order: 0;
        gap: 12px;
    }
    
    .partner-logo {
        height: 24px; /* Smaller logos on mobile */
    }
    
    .bil-logo {
        height: 28px !important; /* Smaller BIL logo on mobile */
    }
    
    .footer-links {
        order: 1;
        gap: 16px;
        flex-wrap: wrap;
        justify-content: center;
    }
    
    .footer-credit {
        order: 2;
        font-size: 11px;
    }

    .footer-link {
        padding: 6px 8px;
        min-width: 32px;
        min-height: 32px;
        font-size: 12px;
    }
    
    .footer-link-text {
        display: none;
    }
}

/* Footer link text visibility */
.footer-link-text {
    margin-left: 4px;
}

@media (max-width: 640px) {
    .footer-link-text {
        display: none;
    }
}

/* Theme Dropdown Styles */
.theme-dropdown {
    position: absolute;
    bottom: 100%;
    right: 0;
    margin-bottom: 8px;
    z-index: 200; /* Above normal UI but below overlays and modals */
}

.theme-dropdown-content {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    padding: 8px 0;
    min-width: 180px;
    animation: fadeInUp 0.2s ease-out;
}

.theme-option {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 12px 16px;
    background: none;
    border: none;
    color: var(--gray-700);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

.theme-option:hover {
    background: var(--gray-50);
    color: var(--primary-color);
}

.theme-option.active {
    background: var(--primary-light);
    color: var(--primary-color);
}

.theme-option i {
    font-size: 16px;
    width: 20px;
    text-align: center;
}

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Position theme dropdown relative to footer links */
.footer-links {
    position: relative;
}

.challenge-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 4px;
    transition: var(--transition);
    opacity: 0.7;
}

.challenge-toggle:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
    text-decoration: none;
}

.challenge-toggle.active {
    opacity: 1;
    background: rgba(255, 215, 0, 0.2); /* Golden background for active state */
    color: #ffd700; /* Golden color */
}

.challenge-toggle.active:hover {
    background: rgba(255, 215, 0, 0.3);
}

.challenge-toggle i {
    font-size: 14px;
}

.tutorial-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 4px;
    transition: var(--transition);
    opacity: 0.7;
}

.tutorial-toggle:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
    text-decoration: none;
}

.tutorial-toggle.active {
    opacity: 1;
    background: rgba(74, 144, 226, 0.2); /* Blue background for active state */
    color: #4a90e2; /* Blue color */
}

.tutorial-toggle.active:hover {
    background: rgba(74, 144, 226, 0.3);
}

.tutorial-toggle i {
    font-size: 14px;
}

.preview-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    border-radius: 4px;
    transition: var(--transition);
    opacity: 0.7;
}

.preview-toggle:hover {
    opacity: 1;
    background: rgba(255, 255, 255, 0.1);
    text-decoration: none;
}

.preview-toggle i {
    font-size: 14px;
}

.footer-credit {
    font-size: 12px;
    color: var(--gray-400);
}

.credit-link {
    color: var(--primary-color);
    text-decoration: none;
    transition: var(--transition);
}

.credit-link:hover {
    text-decoration: underline;
}

/* Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: var(--z-index-modal);
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.modal-content {
    background-color: var(--white);
    margin: 5% auto;
    border-radius: var(--border-radius-lg);
    width: 90%;
    max-width: 600px;
    max-height: 80vh;
    box-shadow: var(--shadow-xl);
    overflow: hidden;
}

.modal-header {
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    color: var(--white);
    padding: 20px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    margin: 0;
    font-size: 20px;
    font-weight: 600;
}

.close {
    color: var(--white);
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 1;
    transition: var(--transition);
}

.close:hover {
    opacity: 0.7;
}

.modal-body {
    padding: 24px;
    max-height: 60vh;
    overflow-y: auto;
    line-height: 1.6;
}

.modal-body h3 {
    color: var(--gray-800);
    font-size: 18px;
    font-weight: 600;
    margin: 24px 0 12px 0;
}

.modal-body h3:first-child {
    margin-top: 0;
}

.modal-body h4 {
    color: var(--gray-700);
    font-size: 16px;
    font-weight: 600;
    margin: 20px 0 8px 0;
}

.modal-body p {
    color: var(--gray-600);
    margin: 0 0 16px 0;
}

/* Camera Controls and 3-State Switch */
.camera-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    padding: 20px;
}

/* Independent Preview Controls */
.preview-controls {
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: center;
    margin-bottom: 20px;
}

.control-button {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    background: var(--gray-100);
    border: 2px solid var(--gray-200);
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    color: var(--gray-600);
    transition: var(--transition);
    min-width: 0;
    white-space: nowrap;
}

.control-button:hover {
    background: var(--gray-50);
    border-color: var(--primary-color);
    color: var(--primary-color);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.control-button i {
    font-size: 16px;
    flex-shrink: 0;
}

.control-button span {
    font-size: 14px;
}

/* Camera toggle states */
.camera-toggle.active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: white;
}

.camera-toggle.active:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
    color: white;
}

/* Upload button styling */
.upload-button {
    background: var(--success-color);
    border-color: var(--success-color);
    color: white;
}

.upload-button:hover {
    background: #059669;
    border-color: #059669;
    color: white;
}

.preview-mode-option::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.4), transparent);
    transition: left 0.5s;
}

.preview-mode-option:hover::before {
    left: 100%;
}

.preview-mode-option:hover {
    color: var(--gray-800);
    transform: translateY(-1px);
}

.preview-mode-option.active {
    color: var(--primary-color);
    background: var(--white);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--primary-color);
}

.preview-mode-option.active::before {
    display: none;
}

.preview-mode-option i {
    font-size: 16px;
}

.preview-content-area {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    min-height: 250px;
    width: 100%;
}

.preview-video-container {
    position: relative;
    display: inline-block;
    border-radius: var(--border-radius);
    overflow: hidden; /* Clip content to prevent corner gaps */
    transition: var(--transition);
    background: transparent; /* No background color needed */
    /* Allow flexible sizing for rotation adjustments */
    max-width: 100%;
    width: auto;
    height: auto;
}

.preview-video-container.active {
    box-shadow: var(--shadow-md);
}

.preview-video-container.active #preview-webcam {
    border-color: var(--primary-color); /* Make webcam border purple when active */
}

.preview-video-container.active #preview-canvas {
    border-color: var(--gray-200); /* Keep canvas border gray when container is active */
}

#preview-webcam {
    display: block;
    max-width: 100%;
    max-height: 500px; /* Prevent overly large videos */
    height: auto;
    width: auto;
    border-radius: var(--border-radius);
    border: 3px solid var(--gray-200);
    overflow: hidden; /* Keep video clipped within its border */
    transition: transform 0.3s ease; /* Smooth rotation transition */
    background: var(--gray-900); /* Dark background to fill any gaps */
}

/* Portrait rotation adjustments for preview video container */
.preview-video-container.webcam-portrait-rotation {
    /* Clear any inline styles that might interfere */
    width: auto !important;
    height: auto !important;
}

.preview-video-container.webcam-portrait-rotation #preview-webcam {
    /* For portrait rotation (90°/270°), the rotated video will have swapped dimensions */
    max-width: 500px;
    max-height: 100%;
}

#preview-canvas {
    display: none;
    max-width: 100%;
    height: auto;
    border-radius: var(--border-radius);
    border: 3px solid var(--gray-200);
}

.preview-upload-area {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 250px;
    border: 2px dashed var(--gray-300);
    border-radius: var(--border-radius-lg);
    padding: 40px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: linear-gradient(135deg, var(--gray-50) 0%, var(--white) 100%);
    width: 100%;
    max-width: 400px;
}

.preview-upload-area:hover {
    border-color: var(--primary-color);
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--white) 100%);
    color: var(--primary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.preview-upload-area.active {
    display: flex;
}

.preview-upload-icon {
    font-size: 48px;
    color: var(--gray-400);
    margin-bottom: 15px;
    transition: var(--transition);
}

.preview-upload-area:hover .preview-upload-icon {
    color: var(--primary-color);
    transform: scale(1.1);
}

.preview-upload-text {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 8px;
    transition: var(--transition);
}

.preview-upload-subtext {
    font-size: 14px;
    color: var(--gray-500);
    transition: var(--transition);
}

.preview-upload-area:hover .preview-upload-text {
    color: var(--primary-color);
}

.preview-upload-area:hover .preview-upload-subtext {
    color: var(--primary-hover);
}

.preview-off-state {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 250px;
    color: var(--gray-500);
    text-align: center;
    background: linear-gradient(135deg, var(--gray-50) 0%, var(--white) 100%);
    border-radius: var(--border-radius-lg);
    padding: 40px;
    border: 1px solid var(--gray-200);
}

.preview-off-state.active {
    display: flex;
}

.preview-off-icon {
    font-size: 64px;
    color: var(--gray-300);
    margin-bottom: 20px;
}

.preview-off-text {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--gray-600);
}

.preview-off-subtext {
    font-size: 14px;
    color: var(--gray-500);
}

.preview-uploaded-image {
    max-width: 100%;
    max-height: 300px;
    border-radius: var(--border-radius);
    border: 2px solid var(--gray-200);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
}

.preview-uploaded-image:hover {
    transform: scale(1.02);
    box-shadow: var(--shadow-md);
}

.uploaded-image-actions {
    margin-top: 15px;
    display: flex;
    gap: 10px;
    align-items: center;
}

.clear-image-btn {
    padding: 8px 16px;
    background: var(--danger-color);
    color: white;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    transition: var(--transition);
}

.clear-image-btn:hover {
    background: #dc2626;
    transform: translateY(-1px);
    box-shadow: var(--shadow-sm);
}

.preview-mode-content {
    display: none;
    width: 100%;
}

.preview-mode-content.active {
    display: flex;
    flex-direction: column;
    align-items: center;
}

/* Challenge Tab Specific Styles */
#challengeContent {
    padding: 24px 20px;
    height: 450px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    overflow-y: auto;
}

.challenge-section {
    width: 100%;
    max-width: 400px;
    margin: 0 auto;
}

.challenge-header {
    text-align: center;
    margin-bottom: 24px;
}

.challenge-header h4 {
    color: var(--gray-800);
    font-weight: 600;
    margin: 0 0 8px 0;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.challenge-header p {
    color: var(--gray-600);
    font-size: 14px;
    margin: 0;
    line-height: 1.4;
}

.team-info {
    background: var(--primary-light);
    color: var(--primary-color);
    padding: 8px 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    margin-top: 8px;
}

.challenge-form {
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-weight: 500;
    color: var(--gray-700);
    font-size: 14px;
}

.form-input {
    padding: 12px;
    border: 1px solid var(--gray-300);
    border-radius: 8px;
    font-size: 14px;
    background: var(--white);
    color: var(--gray-700);
    transition: var(--transition);
    font-family: inherit;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.form-input::placeholder {
    color: var(--gray-400);
}

.form-help {
    font-size: 12px;
    color: var(--gray-500);
    margin: 0;
}

.challenge-btn {
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    font-family: inherit;
}

.challenge-btn.primary {
    background: var(--primary-color);
    color: white;
}

.challenge-btn.primary:hover:not(:disabled) {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.challenge-btn.secondary {
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}

.challenge-btn.secondary:hover:not(:disabled) {
    background: var(--gray-200);
}

.challenge-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none !important;
}

.submission-info {
    margin-bottom: 24px;
}

.model-status {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
}

.status-icon {
    font-size: 24px;
    min-width: 24px;
}

.status-text {
    flex: 1;
}

.status-text div {
    font-weight: 500;
    color: var(--gray-800);
    margin: 0 0 4px 0;
}

.status-text small {
    color: var(--gray-600);
    font-size: 12px;
}

.challenge-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.submission-status {
    margin-top: 16px;
    padding: 12px;
    border-radius: 6px;
    font-size: 13px;
    font-weight: 500;
    text-align: center;
    border: 1px solid transparent;
}

.submission-status.loading {
    background: var(--gray-50);
    color: var(--gray-700);
    border-color: var(--gray-200);
}

.submission-status.success {
    background: #f0fdf4;
    color: #166534;
    border-color: #bbf7d0;
}

.submission-status.error {
    background: #fef2f2;
    color: #dc2626;
    border-color: #fecaca;
}

/* Model status states */
.model-status.ready .status-icon {
    color: var(--success-color);
}

.model-status.ready .status-text div {
    color: var(--success-color);
}

.model-status.not-ready .status-icon {
    color: var(--warning-color);
}

/* Mobile responsive */
@media (max-width: 768px) {
    .challenge-section {
        max-width: 100%;
        padding: 0 8px;
    }
    
    .challenge-form {
        gap: 16px;
    }
    
    .form-input {
        padding: 10px;
    }
    
    .challenge-btn {
        padding: 10px 16px;
    }
}

/* Preview Page Styles */

.preview-content-section {
    width: 100%;
    max-width: none;
    margin: 0;
    padding: 0;
}


.model-loading-section {
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    overflow: hidden;
}

.model-load-options {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.load-option {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 20px;
    background: var(--gray-50);
    border-radius: 8px;
    border: 1px solid var(--gray-200);
}

.option-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    color: var(--gray-700);
    min-width: 120px;
}

.option-controls {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
}

.url-input {
    flex: 1;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    background: var(--white);
    color: var(--gray-900);
}

.url-input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(66, 133, 244, 0.1);
}

.load-btn {
    padding: 10px 16px;
    background: linear-gradient(135deg, var(--primary-color) 0%, var(--secondary-color) 100%);
    border: none;
    border-radius: 6px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--white);
    position: relative;
    overflow: hidden;
    letter-spacing: -0.025em;
}

.load-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.3), transparent);
    transition: left 0.6s;
}

.load-btn:hover::before {
    left: 100%;
}

.load-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.load-btn:active {
    transform: translateY(0);
}

/* Enhanced mobile feedback for load buttons */
@media (max-width: 768px) {
    .load-btn:active {
        transform: scale(0.96);
        box-shadow: var(--shadow-sm);
    }
}

.load-btn:disabled {
    background: var(--gray-400);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.loading-status {
    padding: 12px 24px;
    background: var(--gray-50);
    border-top: 1px solid var(--gray-200);
    font-size: 14px;
    color: var(--gray-600);
    display: none;
}

.model-metadata {
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
    overflow: hidden;
}

.metadata-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    padding: 24px;
}

.metadata-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.metadata-label {
    font-weight: 600;
    color: var(--gray-700);
    font-size: 14px;
}

.metadata-value {
    color: var(--gray-900);
    font-size: 16px;
    font-weight: 500;
}

.model-classes-list {
    padding: 0 24px 24px 24px;
    border-top: 1px solid var(--gray-100);
}

.classes-list-header {
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 12px;
    font-size: 14px;
}

.classes-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.class-label {
    background: var(--primary-light);
    color: var(--primary-dark);
    padding: 4px 8px;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
}

.preview-uploaded-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.uploaded-image-actions {
    margin-top: 12px;
    text-align: center;
}

.clear-image-btn {
    padding: 6px 12px;
    background: var(--danger-color);
    color: var(--white);
    border: none;
    border-radius: 4px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 4px;
    margin: 0 auto;
}

.clear-image-btn:hover {
    background: var(--danger-dark);
}

/* Responsive adjustments for preview page */
@media (max-width: 768px) {
    .header-content {
        flex-direction: column;
        gap: 12px;
        text-align: center;
    }

    .model-load-options {
        padding: 16px;
    }

    .load-option {
        flex-direction: column;
        align-items: stretch;
        gap: 12px;
    }

    .option-controls {
        flex-direction: column;
        gap: 8px;
    }

    .metadata-grid {
        grid-template-columns: 1fr;
        padding: 16px;
    }
}

/* =============================================================================
   CONFIRMATION DIALOG STYLES
   ============================================================================= */
.confirm-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-index-confirm-dialog);
}

.confirm-dialog {
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
    max-width: 400px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
}

.confirm-dialog-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--gray-200);
}

.confirm-dialog-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--gray-900);
}

.confirm-dialog-body {
    padding: 16px 24px;
    color: var(--gray-600);
    line-height: 1.5;
}

.confirm-dialog-body p {
    margin: 0;
}

.confirm-dialog-footer {
    padding: 16px 24px 20px;
    display: flex;
    gap: 12px;
    justify-content: flex-end;
    border-top: 1px solid var(--gray-200);
}

.confirm-dialog-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid;
    min-width: 80px;
}

.confirm-dialog-cancel {
    background: var(--white);
    color: var(--gray-700);
    border-color: var(--gray-300);
}

.confirm-dialog-cancel:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
}

.confirm-dialog-confirm {
    background: var(--danger-color);
    color: var(--white);
    border-color: var(--danger-color);
}

.confirm-dialog-confirm:hover {
    background: #dc2626;
    border-color: #dc2626;
}

/* Alert Dialog Styles */
.alert-dialog-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-index-alert-dialog);
}

.alert-dialog {
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
    max-width: 400px;
    width: 90%;
    max-height: 90vh;
    overflow: hidden;
}

.alert-dialog-header {
    padding: 20px 24px 16px;
    border-bottom: 1px solid var(--gray-200);
}

.alert-dialog-header h3 {
    margin: 0;
    font-size: 18px;
    font-weight: 600;
    color: var(--gray-900);
}

.alert-dialog-body {
    padding: 16px 24px;
    color: var(--gray-600);
    line-height: 1.5;
}

.alert-dialog-body p {
    margin: 0;
    white-space: pre-line;
}

.alert-dialog-footer {
    padding: 16px 24px 20px;
    display: flex;
    justify-content: flex-end;
    border-top: 1px solid var(--gray-200);
}

.alert-dialog-btn {
    padding: 8px 16px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid;
    min-width: 80px;
}

.alert-dialog-ok {
    background: var(--primary-color);
    color: var(--white);
    border-color: var(--primary-color);
}

.alert-dialog-ok:hover {
    background: var(--primary-hover);
    border-color: var(--primary-hover);
}

/* =============================================================================
   TOAST NOTIFICATION STYLES
   ============================================================================= */
.toast-notification {
    position: fixed;
    top: 20px;
    right: 20px;
    max-width: 400px;
    width: calc(100vw - 40px);
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-xl);
    z-index: var(--z-index-toast);
    transform: translateY(-100px);
    opacity: 0;
    transition: all 0.3s var(--ease-out);
    border-left: 4px solid var(--primary-color);
}

.toast-notification.toast-show {
    transform: translateY(0);
    opacity: 1;
}

.toast-content {
    display: flex;
    align-items: center;
    padding: 16px;
    gap: 12px;
}

.toast-content i {
    font-size: 18px;
    flex-shrink: 0;
}

.toast-content span {
    flex: 1;
    font-size: 14px;
    line-height: 1.4;
    color: var(--gray-800);
}

.toast-close {
    background: none;
    border: none;
    color: var(--gray-400);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    transition: var(--transition);
    flex-shrink: 0;
}

.toast-close:hover {
    background: var(--gray-100);
    color: var(--gray-600);
}

.toast-close i {
    font-size: 16px;
}

/* Toast variants */
.toast-success {
    border-left-color: var(--success-color);
}

.toast-success .toast-content i {
    color: var(--success-color);
}

.toast-error {
    border-left-color: var(--danger-color);
}

.toast-error .toast-content i {
    color: var(--danger-color);
}

.toast-warning {
    border-left-color: var(--warning-color);
}

.toast-warning .toast-content i {
    color: var(--warning-color);
}

.toast-info {
    border-left-color: var(--info-color);
}

.toast-info .toast-content i {
    color: var(--info-color);
}

/* Mobile-specific improvements for dialogs */
@media (max-width: 480px) {
    .alert-dialog, .confirm-dialog {
        width: 95%;
        margin: 0 10px;
    }
    
    .alert-dialog-header, .confirm-dialog-header {
        padding: 16px 20px 12px;
    }
    
    .alert-dialog-body, .confirm-dialog-body {
        padding: 12px 20px;
        font-size: 15px;
    }
    
    .alert-dialog-footer, .confirm-dialog-footer {
        padding: 12px 20px 16px;
    }
    
    .alert-dialog-btn, .confirm-dialog-btn {
        padding: 12px 20px;
        font-size: 16px;
        min-height: 44px;
        min-width: 90px;
        border-radius: 8px;
    }
    
    .confirm-dialog-footer {
        flex-direction: column-reverse;
        gap: 8px;
    }
    
    .confirm-dialog-btn {
        width: 100%;
    }
    
    .toast-notification {
        top: 10px;
        right: 10px;
        left: 10px;
        width: auto;
        max-width: none;
    }
}

/* =============================================================================
   CAMERA FEEDBACK NOTIFICATION (HIGH-003)
   Styles extracted from inline JS for maintainability
   ============================================================================= */
.camera-feedback {
    position: fixed;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.85);
    color: white;
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    z-index: var(--z-index-toast);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    text-align: center;
    max-width: 90vw;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 8px;
    opacity: 0;
    transform: translateY(-20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.camera-feedback.show {
    opacity: 1;
    transform: translateY(0);
}

.camera-feedback i {
    font-size: 16px;
}

/* Mobile: center the camera feedback */
@media (max-width: 768px) {
    .camera-feedback {
        right: auto;
        left: 50%;
        transform: translateX(-50%) translateY(-20px);
    }
    
    .camera-feedback.show {
        transform: translateX(-50%) translateY(0);
    }
}

/* =============================================================================
   MED-002: INLINE STYLES EXTRACTION
   CSS classes to replace inline styles in HTML
   ============================================================================= */

/* Preview canvas container */
.preview-canvas-container {
    margin-bottom: 20px;
}

/* Preview canvas */
#preview-canvas {
    width: 280px;
    height: 280px;
    border: 3px solid var(--gray-200);
    border-radius: var(--border-radius-lg);
    background: var(--gray-50);
    display: block;
    margin: 0 auto 20px auto;
}

/* Preview placeholder text */
.preview-placeholder {
    color: var(--gray-500);
    font-size: 15px;
}

/* Export section heading */
.export-heading {
    margin-bottom: 15px;
    color: var(--gray-800);
}

/* Export buttons container */
.export-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Share section */
#shareSection {
    margin-top: 15px;
}

/* Share link label */
.share-link-label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
    color: var(--gray-800);
    font-size: 14px;
}

/* Share link input container */
.share-link-container {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* Share link input */
#shareLinkInput {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    font-size: 12px;
    background: var(--gray-50);
    color: var(--gray-800);
}

#shareLinkInput:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

/* Copy button */
#copyLinkBtn {
    padding: 8px 12px;
    min-width: auto;
    font-size: 12px;
}

/* Copy status message */
#copyStatus {
    margin-top: 5px;
    font-size: 12px;
    color: var(--success-color);
}

/* Share info text */
.share-info {
    margin-top: 8px;
    font-size: 11px;
    color: var(--gray-500);
}

/* Hidden file input */
.hidden-input {
    display: none;
}

/* =============================================================================
   MED-007: ACCESSIBILITY IMPROVEMENTS
   Focus states, screen reader support, keyboard navigation
   ============================================================================= */

/* Focus visible for keyboard navigation */
:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Skip link for keyboard users */
.skip-link {
    position: absolute;
    top: -100px;
    left: 0;
    background: var(--primary-color);
    color: white;
    padding: 8px 16px;
    z-index: 10003;
    text-decoration: none;
    border-radius: 0 0 4px 0;
    transition: top 0.3s;
    opacity: 0;
}

.skip-link:focus {
    top: 0;
    opacity: 1;
}

/* Screen reader only content */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Ensure buttons and interactive elements are keyboard accessible */
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --primary-color: #0000ff;
        --success-color: #008000;
        --danger-color: #ff0000;
        --warning-color: #ff8c00;
    }
    
    .class-card,
    .modal-content,
    .webcam-modal-content {
        border: 2px solid currentColor;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* =============================================================================
   MED-005: INPUT VALIDATION STYLES
   Visual feedback for invalid inputs
   ============================================================================= */

/* Invalid input state */
input:invalid,
input.invalid {
    border-color: var(--danger-color);
    background-color: rgba(239, 68, 68, 0.05);
}

/* Validation error message */
.validation-error {
    color: var(--danger-color);
    font-size: 12px;
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.validation-error i {
    font-size: 14px;
}

/* Training parameters input styling */
#epochs,
#batchSize,
#learningRate {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

#epochs:focus,
#batchSize:focus,
#learningRate:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

/* =============================================================================
   HIDE THEME CONTROLS
   Hide the theme selection and dark mode toggle buttons
   ============================================================================= */
#darkModeToggle,
#themeSelector,
#themeDropdown {
    display: none !important;
}