/**
 * Dog Box Finder - Mobile-First CSS
 * Clean, modern styling with responsive design
 */

/* CSS Custom Properties */
:root {
    /* Colors */
    --dbf-primary: #f9c500;
    --dbf-primary-dark: #e1b000;
    --dbf-primary-light: #fad44c;
    --dbf-secondary: #2c3e50;
    --dbf-text: #2c3e50;
    --dbf-text-light: #666;
    --dbf-text-muted: #999;
    --dbf-bg: #ffffff;
    --dbf-bg-light: #f8f9fa;
    --dbf-border: #e9ecef;
    --dbf-shadow: rgba(0, 0, 0, 0.1);
    --dbf-success: #28a745;
    --dbf-danger: #dc3545;
    
    /* Spacing */
    --dbf-space-xs: 0.5rem;
    --dbf-space-sm: 1rem;
    --dbf-space-md: 1.5rem;
    --dbf-space-lg: 2rem;
    --dbf-space-xl: 3rem;
    --dbf-space-xxl: 4rem;
    
    /* Typography */
    --dbf-font-size-sm: 0.875rem;
    --dbf-font-size-base: 1rem;
    --dbf-font-size-lg: 1.125rem;
    --dbf-font-size-xl: 1.25rem;
    --dbf-font-size-2xl: 1.5rem;
    --dbf-font-size-3xl: 2rem;
    
    /* Transitions */
    --dbf-transition: all 0.3s ease;
    --dbf-transition-fast: all 0.15s ease;
    
    /* Border radius */
    --dbf-radius: 0.5rem;
    --dbf-radius-sm: 0.25rem;
    --dbf-radius-lg: 1rem;
    
    /* Z-index */
    --dbf-z-progress: 100;
    --dbf-z-navigation: 200;
    --dbf-z-modal: 1000;
}

/* Base Styles */
.dog-box-finder {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    line-height: 1.6;
    color: var(--dbf-text);
    background: var(--dbf-bg);
    border-radius: var(--dbf-radius-lg);
    box-shadow: 0 4px 20px var(--dbf-shadow);
    overflow: hidden;
    position: relative;
    max-width: 100%;
    margin: 0 auto;
    width: 100%;
    contain: layout style paint;
}

.dog-box-finder *,
.dog-box-finder *::before,
.dog-box-finder *::after {
    box-sizing: border-box;
}

/* Progress Bar */
.dbf-progress-bar {
    position: sticky;
    top: 0;
    height: 15px;
    background: var(--dbf-bg-light);
    z-index: var(--dbf-z-progress);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
    border-radius: 0 0 var(--dbf-radius) var(--dbf-radius);
}

.dbf-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--dbf-primary), var(--dbf-primary-light));
    transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    width: 25%;
    box-shadow: 0 0 15px rgba(249, 197, 0, 0.35);
    position: relative;
    border-radius: 0 0 var(--dbf-radius) var(--dbf-radius);
}

.dbf-progress-fill::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 25px;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.4));
    animation: progress-shine 2s ease-in-out infinite;
    border-radius: 0 0 var(--dbf-radius) 0;
}

@keyframes progress-shine {
    0%, 100% {
        transform: translateX(0);
        opacity: 0;
    }
    50% {
        transform: translateX(-10px);
        opacity: 1;
    }
}

/* Steps Container */
.dbf-steps-container {
    min-height: 60vh;
    position: relative;
    overflow: hidden;
    width: 100%;
    contain: layout;
}

/* Individual Step */
.dbf-step {
    padding: var(--dbf-space-lg);
    min-height: 60vh;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    opacity: 0;
    transform: translateX(100%);
    transition: all 0.6s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    box-sizing: border-box;
}

.dbf-step.dbf-active {
    position: relative;
    opacity: 1;
    transform: translateX(0) !important;
    pointer-events: auto;
    left: 0;
    right: 0;
}

.dbf-step.dbf-sliding-out {
    opacity: 0;
    transform: translateX(-100%);
    position: absolute;
    left: 0;
    right: 0;
}

.dbf-step.dbf-sliding-in {
    opacity: 0;
    transform: translateX(100%);
    position: absolute;
    left: 0;
    right: 0;
}

.dbf-step-header {
    text-align: center;
    margin-bottom: var(--dbf-space-xl);
}

.dbf-step-title {
    font-size: var(--dbf-font-size-2xl);
    font-weight: 700;
    margin: 0 0 var(--dbf-space-sm);
    color: var(--dbf-text);
}

.dbf-step-description {
    font-size: var(--dbf-font-size-lg);
    color: var(--dbf-text-light);
    margin: 0;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

/* Cards Grid */
.dbf-cards-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--dbf-space-md);
    max-width: 800px;
    margin: 0 auto;
}

/* Card Styles */
.dbf-card {
    background: var(--dbf-bg);
    border: 2px solid var(--dbf-border);
    border-radius: var(--dbf-radius);
    padding: var(--dbf-space-md);
    cursor: pointer;
    transition: var(--dbf-transition);
    position: relative;
    display: flex;
    align-items: center;
    gap: var(--dbf-space-md);
    min-height: 100px;
    touch-action: manipulation;
}

.dbf-card:hover {
    border-color: var(--dbf-primary-light);
    box-shadow: 0 2px 12px var(--dbf-shadow);
    transform: translateY(-1px);
}

.dbf-card.dbf-selected {
    border-color: var(--dbf-primary);
    background: var(--dbf-primary-light);
    color: var(--dbf-text);
    transform: scale(1.02);
    box-shadow: 0 4px 20px rgba(249, 197, 0, 0.3);
    animation: card-select-pulse 0.3s ease-out;
}

@keyframes card-select-pulse {
    0% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
    100% {
        transform: scale(1.02);
    }
}

.dbf-card-image {
    flex-shrink: 0;
    width: 72px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--dbf-bg-light);
    border-radius: var(--dbf-radius-sm);
}

.dbf-card-image img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    border-radius: var(--dbf-radius-sm);
}

.dbf-emoji {
    font-size: 2rem;
    line-height: 1;
}

.dbf-card-content {
    flex: 1;
    min-width: 0;
}

.dbf-card-title {
    font-size: var(--dbf-font-size-lg);
    font-weight: 600;
    margin: 0 0 var(--dbf-space-xs);
    color: inherit;
}

.dbf-card-description {
    font-size: var(--dbf-font-size-sm);
    color: var(--dbf-text-light);
    margin: 0;
    line-height: 1.4;
}

/* Multi-select checkbox */
.dbf-card-checkbox {
    flex-shrink: 0;
    width: 24px;
    height: 24px;
    border: 2px solid var(--dbf-border);
    border-radius: var(--dbf-radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--dbf-bg);
    transition: var(--dbf-transition-fast);
}

.dbf-card.dbf-selected .dbf-card-checkbox {
    background: var(--dbf-primary);
    border-color: var(--dbf-primary);
    color: white;
}

.dbf-checkmark {
    opacity: 0;
    transform: scale(0);
    transition: var(--dbf-transition-fast);
}

.dbf-card.dbf-selected .dbf-checkmark {
    opacity: 1;
    transform: scale(1);
}

/* Navigation */
.dbf-navigation {
    padding: var(--dbf-space-lg);
    background: var(--dbf-bg-light);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--dbf-space-md);
    position: sticky;
    bottom: 0;
    z-index: var(--dbf-z-navigation);
}

/* Buttons */
.dbf-btn {
    padding: var(--dbf-space-sm) var(--dbf-space-lg);
    border: none;
    border-radius: var(--dbf-radius);
    font-size: var(--dbf-font-size-base);
    font-weight: 600;
    cursor: pointer;
    transition: var(--dbf-transition);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--dbf-space-xs);
    min-height: 44px;
    touch-action: manipulation;
}

.dbf-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.dbf-btn-primary {
    background: var(--dbf-primary);
    color: var(--dbf-text);
}

.dbf-btn-primary:hover:not(:disabled) {
    background: var(--dbf-primary-dark);
    transform: translateY(-1px);
}

.dbf-btn-secondary {
    background: var(--dbf-bg);
    color: var(--dbf-text);
    border: 2px solid var(--dbf-border);
}

.dbf-btn-secondary:hover:not(:disabled) {
    border-color: var(--dbf-primary);
}

/* Selections Summary */
.dbf-selections-summary {
    display: flex;
    flex-wrap: wrap;
    gap: var(--dbf-space-xs);
    margin-bottom: var(--dbf-space-lg);
    justify-content: center;
}

.dbf-selection-tag {
    background: var(--dbf-primary-light);
    color: var(--dbf-text);
    padding: var(--dbf-space-xs) var(--dbf-space-sm);
    border-radius: var(--dbf-radius-lg);
    font-size: var(--dbf-font-size-sm);
    font-weight: 500;
}

.dbf-selection-clickable {
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.dbf-selection-clickable:hover {
    background: var(--dbf-primary);
    color: white;
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.dbf-selection-clickable:active {
    transform: translateY(0);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

/* Loading States */
.dbf-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--dbf-space-xl);
    min-height: 300px;
}

.dbf-loading-spinner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--dbf-space-xl);
    gap: var(--dbf-space-md);
}

.dbf-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--dbf-border);
    border-top: 3px solid var(--dbf-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Products Grid */
.dbf-products-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: var(--dbf-space-lg);
}

.dbf-product-card {
    background: var(--dbf-bg);
    border: 1px solid var(--dbf-border);
    border-radius: var(--dbf-radius);
    overflow: hidden;
    transition: var(--dbf-transition);
}

.dbf-product-card:hover {
    box-shadow: 0 4px 20px var(--dbf-shadow);
    transform: translateY(-2px);
}

.dbf-product-image {
    width: 100%;
    height: 200px;
    object-fit: cover;
    display: block;
}

.dbf-product-content {
    padding: var(--dbf-space-md);
}

.dbf-product-title {
    font-size: var(--dbf-font-size-lg);
    font-weight: 600;
    margin: 0 0 var(--dbf-space-sm);
    line-height: 1.3;
}

.dbf-product-excerpt {
    font-size: var(--dbf-font-size-sm);
    color: var(--dbf-text-light);
    margin: 0 0 var(--dbf-space-md);
    line-height: 1.4;
}

.dbf-product-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--dbf-space-md);
}

.dbf-product-price {
    font-size: var(--dbf-font-size-lg);
    font-weight: 700;
    color: var(--dbf-primary-dark);
}

.dbf-product-rating {
    color: var(--dbf-primary);
    font-size: var(--dbf-font-size-sm);
}

.dbf-product-link {
    width: 100%;
}

/* No Results */
.dbf-no-results {
    text-align: center;
    padding: var(--dbf-space-xxl);
    color: var(--dbf-text-light);
}

/* Fallback Notice */
.dbf-fallback-notice {
    grid-column: 1 / -1;
    background: #fff3cd;
    color: #856404;
    padding: var(--dbf-space-md);
    border-radius: var(--dbf-radius);
    border: 1px solid #ffeaa7;
    margin-bottom: var(--dbf-space-md);
    text-align: center;
}

.dbf-fallback-notice p {
    margin: 0;
}

/* Popular Products Section */
.dbf-popular-products-section {
    margin-top: var(--dbf-space-xxl);
    padding-top: var(--dbf-space-xl);
    border-top: 2px solid var(--dbf-border);
}

.dbf-popular-header {
    text-align: center;
    margin-bottom: var(--dbf-space-lg);
}

.dbf-popular-title {
    font-size: var(--dbf-font-size-xl);
    font-weight: 600;
    margin: 0 0 var(--dbf-space-xs);
    color: var(--dbf-text);
}

.dbf-popular-description {
    font-size: var(--dbf-font-size-base);
    color: var(--dbf-text-light);
    margin: 0;
}

.dbf-popular-loading {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: var(--dbf-space-lg);
}

.dbf-popular-products-scroll {
    position: relative;
    overflow-x: auto;
    overflow-y: hidden;
    padding: var(--dbf-space-sm) 0;
    scrollbar-width: thin;
    scrollbar-color: var(--dbf-primary-light) transparent;
}

.dbf-popular-products-scroll::-webkit-scrollbar {
    height: 6px;
}

.dbf-popular-products-scroll::-webkit-scrollbar-track {
    background: transparent;
}

.dbf-popular-products-scroll::-webkit-scrollbar-thumb {
    background: var(--dbf-primary-light);
    border-radius: 3px;
}

.dbf-popular-products-scroll::-webkit-scrollbar-thumb:hover {
    background: var(--dbf-primary);
}

.dbf-popular-products-container {
    display: flex;
    gap: var(--dbf-space-md);
    padding: var(--dbf-space-xs) var(--dbf-space-sm);
    min-width: min-content;
}

.dbf-popular-product-card {
    flex: 0 0 280px;
    background: var(--dbf-bg);
    border: 1px solid var(--dbf-border);
    border-radius: var(--dbf-radius);
    overflow: hidden;
    transition: var(--dbf-transition);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}

.dbf-popular-product-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    border-color: var(--dbf-primary-light);
}

.dbf-popular-product-image {
    width: 100%;
    height: 160px;
    object-fit: cover;
    display: block;
}

.dbf-popular-product-placeholder {
    width: 100%;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--dbf-bg-light);
    font-size: 3rem;
    color: var(--dbf-text-muted);
}

.dbf-popular-product-content {
    padding: var(--dbf-space-md);
}

.dbf-popular-product-title {
    font-size: var(--dbf-font-size-base);
    font-weight: 600;
    margin: 0 0 var(--dbf-space-xs);
    line-height: 1.3;
    color: var(--dbf-text);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.dbf-popular-product-price {
    font-size: var(--dbf-font-size-lg);
    font-weight: 700;
    color: var(--dbf-primary-dark);
    margin-bottom: var(--dbf-space-xs);
}

.dbf-popular-product-rating {
    color: var(--dbf-primary);
    font-size: var(--dbf-font-size-sm);
    margin-bottom: var(--dbf-space-sm);
}

.dbf-popular-product-link {
    display: inline-block;
    background: var(--dbf-primary);
    color: var(--dbf-text);
    padding: var(--dbf-space-xs) var(--dbf-space-md);
    border-radius: var(--dbf-radius);
    text-decoration: none;
    font-size: var(--dbf-font-size-sm);
    font-weight: 600;
    transition: var(--dbf-transition-fast);
    text-align: center;
    min-width: 80px;
}

.dbf-popular-product-link:hover {
    background: var(--dbf-primary-dark);
    transform: translateY(-1px);
}

.dbf-no-popular {
    text-align: center;
    color: var(--dbf-text-light);
    font-style: italic;
    padding: var(--dbf-space-lg);
}

/* Mobile optimizations for popular products */
@media (max-width: 768px) {
    .dbf-popular-product-card {
        flex: 0 0 240px;
    }
    
    .dbf-popular-product-image,
    .dbf-popular-product-placeholder {
        height: 140px;
    }
    
    .dbf-popular-products-container {
        padding: var(--dbf-space-xs);
        gap: var(--dbf-space-sm);
    }
}

/* Error States */
.dbf-error {
    background: #fff5f5;
    color: var(--dbf-danger);
    padding: var(--dbf-space-lg);
    border-radius: var(--dbf-radius);
    text-align: center;
    margin: var(--dbf-space-md);
}

/* Theme Support */
.dog-box-finder.theme-dark {
    --dbf-bg: #1a1a1a;
    --dbf-bg-light: #2a2a2a;
    --dbf-text: #ffffff;
    --dbf-text-light: #cccccc;
    --dbf-text-muted: #999999;
    --dbf-border: #404040;
    --dbf-shadow: rgba(0, 0, 0, 0.3);
}

/* Responsive Design */
@media (max-width: 479px) {
    /* Ensure 3:2 aspect ratio for mobile card images */
    .dbf-card-image {
        width: 60px;
        height: 40px;
    }
}

@media (min-width: 480px) {
    .dbf-cards-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .dbf-products-grid {
        grid-template-columns: repeat(2, 1fr);
    }
    
    /* Slightly larger card images for small tablets */
    .dbf-card-image {
        width: 66px;
        height: 44px;
    }
}

@media (min-width: 768px) {
    .dog-box-finder {
        max-width: 900px;
    }
    
    .dbf-steps-container {
        min-height: 70vh;
    }
    
    .dbf-step {
        padding: var(--dbf-space-xl);
        min-height: 70vh;
        /* Ensure consistent sizing on larger screens */
        max-width: 100%;
        box-sizing: border-box;
    }
    
    .dbf-cards-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--dbf-space-lg);
    }
    
    .dbf-card {
        padding: var(--dbf-space-lg);
        flex-direction: column;
        text-align: center;
        min-height: 180px;
    }
    
    .dbf-card-image {
        width: 96px;
        height: 64px;
    }
    
    .dbf-products-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: var(--dbf-space-xl);
    }
    
    .dbf-step-title {
        font-size: var(--dbf-font-size-3xl);
    }
}

@media (min-width: 1024px) {
    .dbf-cards-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .dbf-products-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    /* Ensure animations work smoothly on larger screens */
    .dbf-step {
        transform-origin: center center;
    }
}

@media (min-width: 1200px) {
    .dog-box-finder {
        max-width: 1100px;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* Focus states for keyboard navigation */
.dbf-card:focus,
.dbf-btn:focus {
    outline: 2px solid var(--dbf-primary);
    outline-offset: 2px;
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .dog-box-finder {
        --dbf-border: #000000;
        --dbf-shadow: rgba(0, 0, 0, 0.5);
    }
}

/* Debug Panel Styles */
.dbf-debug-panel {
    margin-top: var(--dbf-space-lg);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    font-size: 13px;
    line-height: 1.4;
}

.dbf-debug-container {
    background: #1e1e1e;
    color: #ffffff;
    border: 1px solid #333;
    border-radius: var(--dbf-radius);
    overflow: hidden;
}

.dbf-debug-header {
    background: #2d2d2d;
    padding: var(--dbf-space-sm) var(--dbf-space-md);
    border-bottom: 1px solid #333;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dbf-debug-header h3 {
    margin: 0;
    color: #f9c500;
    font-size: 16px;
}

.dbf-debug-toggle {
    background: #444;
    border: 1px solid #666;
    color: #fff;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

.dbf-debug-toggle:hover {
    background: #555;
}

.dbf-debug-content {
    max-height: 500px;
    overflow-y: auto;
}

.dbf-debug-section {
    border-bottom: 1px solid #333;
    padding: var(--dbf-space-md);
}

.dbf-debug-section:last-child {
    border-bottom: none;
}

.dbf-debug-section h4 {
    margin: 0 0 var(--dbf-space-sm) 0;
    color: #f9c500;
    font-size: 14px;
    font-weight: 600;
}

.dbf-debug-data {
    background: #252525;
    padding: var(--dbf-space-sm);
    border-radius: 4px;
    font-family: 'Courier New', monospace;
    max-height: 200px;
    overflow-y: auto;
}

.dbf-debug-item {
    margin-bottom: 4px;
    padding: 2px 0;
    border-bottom: 1px solid #333;
}

.dbf-debug-item:last-child {
    border-bottom: none;
}

.dbf-debug-item strong {
    color: #4fc3f7;
    min-width: 120px;
    display: inline-block;
}

.dbf-debug-taxonomy-group {
    margin-bottom: var(--dbf-space-sm);
    padding: var(--dbf-space-xs);
    background: #2a2a2a;
    border-radius: 4px;
}

.dbf-debug-taxonomy-group strong {
    color: #81c784;
}

.dbf-debug-log-container {
    background: #1a1a1a;
    padding: var(--dbf-space-sm);
    border-radius: 4px;
    max-height: 150px;
    overflow-y: auto;
    margin-bottom: var(--dbf-space-sm);
    font-family: 'Courier New', monospace;
    font-size: 11px;
}

.dbf-debug-log-log {
    color: #ffffff;
    margin-bottom: 2px;
}

.dbf-debug-log-error {
    color: #ff6b6b;
    margin-bottom: 2px;
}

.dbf-debug-log-warn {
    color: #feca57;
    margin-bottom: 2px;
}

.dbf-debug-clear-logs {
    background: #dc3545;
    border: none;
    color: white;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 11px;
}

.dbf-debug-clear-logs:hover {
    background: #c82333;
}

/* Responsive debug panel */
@media (max-width: 768px) {
    .dbf-debug-panel {
        font-size: 12px;
    }
    
    .dbf-debug-content {
        max-height: 300px;
    }
    
    .dbf-debug-data {
        max-height: 120px;
    }
    
    .dbf-debug-log-container {
        max-height: 100px;
    }
}