/* Responsive Design */

/* ============================================
   MOBILE FIRST - Base Styles (up to 767px)
   ============================================ */
@media (max-width: 767px) {
    /* Typography adjustments */
    body {
        font-size: 16px;
        line-height: 1.5;
    }
    
    .container {
        padding: 0 var(--spacing-xs);
        max-width: 100%;
    }
    
    /* Header mobile optimization */
    .header {
        padding: var(--spacing-xs) 0;
    }
    
    .header-content {
        padding: 0 var(--spacing-xs);
        flex-wrap: wrap;
    }
    
    .logo {
        font-size: 1.25rem;
        flex: 1;
        min-width: 0;
    }
    
    .header-actions {
        gap: var(--spacing-xs);
    }
    
    .help-btn {
        width: 2.25rem;
        height: 2.25rem;
        min-width: 44px;
        min-height: 44px;
    }
    
    /* Progress bar mobile layout - compact horizontal */
    .progress-container {
        padding: var(--spacing-sm) var(--spacing-xs) 0;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }
    
    .progress-bar {
        flex-direction: row;
        justify-content: space-between;
        align-items: flex-start;
        gap: 0.25rem;
        min-width: min-content;
        padding-bottom: var(--spacing-xs);
    }
    
    .progress-step {
        flex-direction: column;
        align-items: center;
        flex: 1;
        min-width: 0;
        position: relative;
        padding: 0;
    }
    
    .progress-step:not(:last-child)::after {
        display: block;
        position: absolute;
        top: 0.875rem;
        left: calc(50% + 0.875rem);
        right: calc(-50% + 0.875rem);
        height: 2px;
        background: var(--border);
        z-index: 1;
    }
    
    .progress-step.active:not(:last-child)::after,
    .progress-step.completed:not(:last-child)::after {
        background: var(--primary);
    }
    
    .progress-circle {
        width: 1.75rem;
        height: 1.75rem;
        font-size: 0.75rem;
        flex-shrink: 0;
        margin: 0;
        position: relative;
        z-index: 2;
    }
    
    .progress-label {
        font-size: 0.6875rem;
        margin-top: 0.375rem;
        text-align: center;
        line-height: 1.2;
        word-break: break-word;
        hyphens: auto;
        max-width: 100%;
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
    }
    
    /* Show full label on active step */
    .progress-step.active .progress-label {
        font-size: 0.75rem;
        font-weight: 600;
        -webkit-line-clamp: 3;
    }
    
    /* Abbreviated labels for very small screens */
    @media (max-width: 480px) {
        .progress-label {
            font-size: 0.625rem;
            -webkit-line-clamp: 1;
        }
        
        .progress-step.active .progress-label {
            font-size: 0.6875rem;
            -webkit-line-clamp: 2;
        }
        
        /* Make circles slightly smaller on very small screens */
        .progress-circle {
            width: 1.5rem;
            height: 1.5rem;
            font-size: 0.6875rem;
        }
        
        .progress-step:not(:last-child)::after {
            top: 0.75rem;
        }
    }
    
    /* Step cards */
    .step-card {
        padding: var(--spacing-md);
        margin-bottom: var(--spacing-md);
        border-radius: var(--border-radius);
    }
    
    .step-title {
        font-size: 1.5rem;
        line-height: 1.3;
        margin-bottom: var(--spacing-sm);
    }
    
    .step-intro {
        font-size: 1rem;
        margin-bottom: var(--spacing-md);
    }
    
    /* Form grids - stack vertically on mobile */
    .form-grid {
        grid-template-columns: 1fr;
        gap: var(--spacing-md);
    }
    
    /* Form groups */
    .form-group {
        width: 100%;
    }
    
    label {
        font-size: 0.9375rem;
        margin-bottom: 0.5rem;
    }
    
    input:not([type="checkbox"]):not([type="radio"]),
    select,
    textarea {
        font-size: 16px; /* Prevents zoom on iOS */
        padding: 0.875rem;
        min-height: 44px; /* Touch target size */
    }
    
    textarea {
        min-height: 100px;
    }
    
    /* Fieldsets */
    fieldset {
        padding: var(--spacing-sm);
        margin-bottom: var(--spacing-md);
    }
    
    legend {
        font-size: 1rem;
        padding: 0 var(--spacing-xs);
    }
    
    /* Checkbox and radio items */
    .checkbox-item,
    .radio-item {
        gap: 0.75rem;
        padding: 0.5rem 0;
    }
    
    .checkbox-item label,
    .radio-item label {
        font-size: 0.9375rem;
        line-height: 1.5;
    }
    
    input[type="checkbox"],
    input[type="radio"] {
        min-width: 20px;
        min-height: 20px;
        flex-shrink: 0;
    }
    
    /* Navigation */
    .navigation {
        padding: var(--spacing-sm) 0;
    }
    
    .nav-content {
        flex-direction: column;
        gap: var(--spacing-sm);
        padding: 0 var(--spacing-xs);
    }
    
    .nav-btn {
        width: 100%;
        padding: 0.875rem 1.5rem;
        font-size: 1rem;
        min-height: 44px; /* Touch target */
    }
    
    .save-later {
        font-size: 0.875rem;
        padding: var(--spacing-xs);
        min-height: 44px;
    }
    
    /* Tables - convert to stacked layout */
    .table-header,
    .retailer-row,
    .product-row,
    .dist-table-header,
    .dist-row {
        grid-template-columns: 1fr;
        gap: 0.75rem;
        padding: var(--spacing-sm);
    }
    
    .table-header {
        display: none; /* Hide header, use labels instead */
    }
    
    .retailer-row,
    .product-row,
    .dist-row {
        border: 1px solid var(--border);
        border-radius: var(--spacing-xs);
        margin-bottom: var(--spacing-sm);
        background: white;
    }
    
    /* Table cells stack vertically on mobile */
    .retailer-row > div,
    .product-row > div,
    .dist-row > div {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }
    
    /* Month grid */
    .month-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.5rem;
    }
    
    .month-checkbox {
        padding: 0.625rem;
        font-size: 0.875rem;
    }
    
    /* Distribution panels */
    .live-count-system {
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
        padding: var(--spacing-sm);
    }
    
    .distribution-header {
        flex-direction: column;
        gap: var(--spacing-sm);
        align-items: stretch;
    }
    
    .strategy-control {
        flex-direction: column;
        gap: var(--spacing-xs);
    }
    
    /* File upload areas */
    .file-upload-area {
        padding: var(--spacing-md);
        min-height: 120px;
    }
    
    .file-upload-content {
        gap: var(--spacing-xs);
    }
    
    .upload-icon {
        width: 32px;
        height: 32px;
    }
    
    /* Modals */
    .modal {
        padding: var(--spacing-sm);
        align-items: flex-start;
        overflow-y: auto;
    }
    
    .modal-content {
        width: 100%;
        max-width: 100%;
        max-height: 95vh;
        margin: auto;
        border-radius: var(--border-radius);
    }
    
    .modal-header {
        padding: var(--spacing-sm);
        position: sticky;
        top: 0;
        background: white;
        z-index: 10;
        border-bottom: 1px solid var(--border);
    }
    
    .modal-header h3 {
        font-size: 1.25rem;
    }
    
    .modal-body {
        padding: var(--spacing-sm);
        max-height: calc(95vh - 120px);
        overflow-y: auto;
    }
    
    .modal-footer {
        padding: var(--spacing-sm);
        flex-direction: column;
        gap: var(--spacing-xs);
        position: sticky;
        bottom: 0;
        background: white;
        border-top: 1px solid var(--border);
    }
    
    .modal-footer .btn-primary,
    .modal-footer .btn-secondary {
        width: 100%;
        min-height: 44px;
    }
    
    /* Buttons - ensure touch targets */
    button,
    .btn-primary,
    .btn-secondary,
    .add-retailer-btn,
    .add-product-btn,
    .add-product-line-btn {
        min-height: 44px;
        padding: 0.75rem 1.25rem;
    }
    
    .delete-retailer-btn,
    .delete-product-btn,
    .delete-line-btn {
        min-width: 44px;
        min-height: 44px;
        padding: 0.5rem;
    }
    
    /* Helper text */
    .helper-text,
    .help-text {
        font-size: 0.8125rem;
        margin-top: 0.25rem;
    }
    
    /* Error messages */
    .error-message {
        font-size: 0.8125rem;
        margin-top: 0.5rem;
    }
}

/* ============================================
   TABLET STYLES (768px - 1023px)
   ============================================ */
@media (min-width: 768px) and (max-width: 1023px) {
    .container {
        padding: 0 var(--spacing-sm);
    }
    
    .step-card {
        padding: var(--spacing-lg);
    }
    
    .form-grid {
        grid-template-columns: 1fr 1fr;
        gap: var(--spacing-md);
    }
    
    .progress-bar {
        flex-direction: row;
        justify-content: center;
        gap: var(--spacing-sm);
    }
    
    .progress-step:not(:last-child)::after {
        display: block;
    }
    
    .progress-circle {
        width: 2rem;
        height: 2rem;
    }
    
    .table-header,
    .retailer-row {
        grid-template-columns: 2fr 1fr 1fr 80px;
    }
    
    .month-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .modal-content {
        max-width: 90%;
    }
}

/* ============================================
   DESKTOP STYLES (1024px+)
   ============================================ */
@media (min-width: 1024px) {
    .form-grid {
        grid-template-columns: 1fr 1fr;
    }
    
    .progress-bar {
        flex-direction: row;
        justify-content: center;
    }
    
    .progress-step:not(:last-child)::after {
        display: block;
    }
    
    .checkbox-group {
        display: flex;
        flex-direction: row;
        gap: 2rem;
    }
}

/* ============================================
   LARGE DESKTOP STYLES (1200px+)
   ============================================ */
@media (min-width: 1200px) {
    .container {
        padding: 0 var(--spacing-md);
    }
    
    .step-card {
        padding: var(--spacing-xl);
    }
}

/* ============================================
   PRINT STYLES
   ============================================ */
@media print {
    .header,
    .navigation,
    .progress-container {
        display: none;
    }
    
    .step-card {
        border: 1px solid #000;
        box-shadow: none;
        margin-bottom: 1rem;
    }
    
    body {
        background: white;
        color: black;
    }
}