/* CSS Variables for theming */
:root {
    --bg-color: #f5f5f5;
    --container-bg: white;
    --text-color: #333;
    --h2-color: #2d3748;
    --item-label-color: #2d3748;
    --border-color: #e2e8f0;
    --header-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --header-text: white;
    --card-bg: #f8fafc;
    --card-hover-bg: #f0f4ff;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    --button-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --button-text: #ffffff;
    --button-disabled-bg: #cbd5e0;
    --button-disabled-text: #4a5568;
    --selected-border: #22c55e;
    --selected-bg: #f0fdf4;
}

[data-theme="dark"] {
    --bg-color: #1a1a1a;
    --container-bg: #2d2d2d;
    --text-color: #e2e8f0;
    --h2-color: #cbd5e0;
    --item-label-color: #cbd5e0;
    --border-color: #4a5568;
    --header-bg: linear-gradient(135deg, #4c51bf 0%, #553c9a 100%);
    --header-text: #e2e8f0;
    --card-bg: #374151;
    --card-hover-bg: #4a5568;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.3);
    --button-bg: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    --button-text: #ffffff;
    --button-disabled-bg: #4a5568;
    --button-disabled-text: #a0aec0;
    --selected-border: #22c55e;
    --selected-bg: #064e3b;
}

/* Reset and base styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--text-color);
    background-color: var(--bg-color);
    padding: 20px;
    transition: background-color 0.3s ease, color 0.3s ease;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    background: var(--container-bg);
    border-radius: 12px;
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
}

/* Theme toggle button */
.theme-toggle {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.3s ease;
    z-index: 10;
    backdrop-filter: blur(10px);
}

.theme-toggle:hover {
    background: rgba(255, 255, 255, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
    transform: scale(1.1);
}

.theme-toggle:focus {
    outline: 3px solid rgba(255, 255, 255, 0.5);
    outline-offset: 2px;
}

.theme-icon {
    font-size: 1.5rem;
    transition: transform 0.3s ease;
}

[data-theme="dark"] .theme-toggle {
    background: rgba(0, 0, 0, 0.2);
    border-color: rgba(255, 255, 255, 0.3);
}

[data-theme="dark"] .theme-toggle:hover {
    background: rgba(0, 0, 0, 0.3);
    border-color: rgba(255, 255, 255, 0.5);
}

.header {
    background: var(--header-bg);
    color: var(--header-text);
    padding: 2rem;
    text-align: center;
    transition: background 0.3s ease, color 0.3s ease;
}

.header h1 {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
    font-weight: 600;
}

.header p {
    font-size: 1.1rem;
    opacity: 0.9;
}

.content {
    padding: 2rem;
}

/* Category section styles */
.category-section {
    margin-bottom: 3rem;
}

.category-section h2 {
    font-size: 1.8rem;
    margin-bottom: 1.5rem;
    color: var(--h2-color);
    border-bottom: 3px solid #667eea;
    padding-bottom: 0.5rem;
    text-align: center;
}

.categories-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.category-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 1.5rem;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    background: var(--card-bg);
    transition: all 0.3s ease;
    cursor: pointer;
    text-align: center;
}

.category-option:hover {
    border-color: #667eea;
    background: var(--card-hover-bg);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

.category-option:focus {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

.category-name {
    font-size: 1.2rem;
    font-weight: 600;
    color: #4a5d7e;
    margin-bottom: 0.5rem;
}

.category-count {
    font-size: 0.9rem;
    color: #718096;
    font-weight: 500;
}

/* Selection form styles */
.selection-section {
    margin-bottom: 3rem;
    display: none; /* Hidden by default, shown when category is selected */
}

.selection-header {
    display: flex;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.back-btn {
    background: #e2e8f0;
    color: #4a5568;
    border: none;
    padding: 0.75rem 1.5rem;
    font-size: 1rem;
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.3s ease;
    white-space: nowrap;
}

.back-btn:hover {
    background: #cbd5e0;
    color: #2d3748;
}

.back-btn:focus {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

.selection-section h2 {
    font-size: 1.8rem;
    margin: 0;
    color: var(--h2-color);
    border-bottom: 3px solid #667eea;
    padding-bottom: 0.5rem;
    flex: 1;
}

.items-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

.item-option {
    display: flex;
    align-items: center;
    padding: 1rem;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    background: var(--card-bg);
    transition: all 0.3s ease;
    cursor: pointer;
}

.item-option:hover {
    border-color: #667eea;
    background: var(--card-hover-bg);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.15);
}

.item-option:focus-within {
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.item-checkbox {
    margin-right: 1rem;
    width: 20px;
    height: 20px;
    accent-color: #667eea;
    cursor: pointer;
}

.item-label {
    font-size: 1.1rem;
    font-weight: 500;
    color: #2d3748;
    cursor: pointer;
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.item-preview-image {
    width: 32px;
    height: 32px;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid #e2e8f0;
    background: #f8fafc;
}

.item-label-text {
    flex: 1;
    color: var(--item-label-color);
}

/* Submit button */
.submit-btn {
    background: var(--button-bg);
    color: var(--button-text);
    border: none;
    padding: 1rem 2rem;
    font-size: 1.2rem;
    font-weight: 600;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
    width: 100%;
    max-width: 300px;
    margin: 0 auto;
    display: block;
}

.submit-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.3);
}

.submit-btn:active:not(:disabled) {
    transform: translateY(0);
}

.submit-btn:disabled {
    background: var(--button-disabled-bg);
    color: var(--button-disabled-text);
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

/* Results section */
.results-section {
    display: none;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 2px solid #e2e8f0;
}

.results-header {
    display: flex;
    align-items: center;
    margin-bottom: 1.5rem;
    gap: 1rem;
}

.results-section h2 {
    font-size: 1.8rem;
    margin: 0;
    color: var(--h2-color);
    border-bottom: 3px solid #667eea;
    padding-bottom: 0.5rem;
    flex: 1;
}

.selected-items {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
    gap: 1.5rem;
}

.selected-item {
    background: var(--container-bg);
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    transition: all 0.3s ease;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.selected-item:hover {
    transform: translateY(-4px);
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.1);
    border-color: #667eea;
}

.item-image {
    width: 100%;
    height: auto;
    max-height: 300px;
    object-fit: contain;
    border-radius: 8px;
    margin-bottom: 1rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
}

.item-name {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--item-label-color);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.checkmark-icon {
    color: #22c55e;
    font-size: 1.2rem;
    font-weight: bold;
    display: none;
}

.selected-item.selected .item-name {
    font-weight: 700 !important;
}

.selected-item.selected .checkmark-icon {
    display: inline !important;
}

/* Responsive design */
@media (max-width: 1200px) {
    .selected-items {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
        gap: 1.25rem;
    }
}

@media (max-width: 768px) {
    body {
        padding: 10px;
    }

    .header {
        padding: 1.5rem;
    }

    .header h1 {
        font-size: 2rem;
    }

    .content {
        padding: 1.5rem;
    }

    .categories-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 0.75rem;
    }

    .category-option {
        padding: 1rem;
    }

    .category-name {
        font-size: 1.1rem;
    }

    .category-count {
        font-size: 0.8rem;
    }

    .selection-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .results-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }

    .back-btn {
        align-self: flex-start;
    }

    .item-preview-image {
        width: 28px;
        height: 28px;
    }

    .items-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .item-option {
        padding: 0.75rem;
    }

    .selected-items {
        grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
        gap: 1rem;
    }

    .item-image {
        max-height: 200px;
    }
}

@media (max-width: 480px) {
    .header h1 {
        font-size: 1.5rem;
    }

    .header p {
        font-size: 1rem;
    }

    .categories-grid {
        grid-template-columns: 1fr;
    }

    .selected-items {
        grid-template-columns: 1fr;
    }
}

/* Accessibility improvements */
.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;
}

/* Focus styles for keyboard navigation */
.item-option:focus,
.submit-btn:focus {
    outline: 3px solid #667eea;
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .item-option {
        border-width: 3px;
    }
    
    .submit-btn {
        border: 2px solid #000;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}